C:/Users/Dennis/src/lang/russell.orig/src/stree/fixmacros.c

Go to the documentation of this file.
00001 # include <stdio.h>
00002 
00003 /* Replace "@" by "\n#" and remove any blank lines in the result. */
00004 /* Replace "@@" by a newline.                                     */
00005 /* Delete lines starting with "#"                                 */
00006 /* Delete ^ characters.                                           */
00007 main()
00008 {
00009     char cline[50000];      /* Current line */
00010     register int cpos = 0;  /* Position of next character in line */
00011     register int c;         /* Last read character */
00012     int non_blank = -1;     /* Position of last non-blank character in line. */
00013     int i;
00014 
00015     while ((c = getchar()) != EOF) {
00016         switch(c) {
00017             case '\n':
00018             case '@':
00019                 if (cline[0] == '#' && cpos == 1) {
00020                     putchar('\n');
00021                     cpos = 0;
00022                     non_blank = -1;
00023                     break;
00024                 }
00025                 if (non_blank >= 0) {
00026                     for (i = 0; i <= non_blank; i++) {
00027                         putchar(cline[i]);
00028                     }
00029                     putchar('\n');
00030                 }
00031                 if (c != '@') {
00032                     cpos = 0;
00033                     non_blank = -1;
00034                 } else {
00035                     cline[0] = '#';
00036                     cpos = 1;
00037                     non_blank = 0;
00038                 }
00039                 break;
00040 
00041             case ' ':
00042             case '\t':
00043                 cline[cpos++] = c;
00044                 break;
00045 
00046             case '#':
00047                 if (cpos == 0) {
00048                     /* Discard line */
00049                       while ((c = getchar()) != '\n');
00050                     break;
00051                 }
00052                 /* Otherwise treat it like a normal character:  */
00053 
00054             case '^':
00055                 break;
00056                 
00057             default:
00058                 non_blank = cpos;
00059                 cline[cpos++] = c;
00060         }
00061     }
00062     if (non_blank >= 0) {
00063         fprintf(stderr, "Dropped partial line at end\n");
00064         exit(1);
00065     }
00066     exit(0);
00067 }

Generated on Fri Jan 25 10:39:48 2008 for russell by  doxygen 1.5.4