C:/Users/Dennis/src/lang/russell.orig/src/utilities/fixstrings.c

Go to the documentation of this file.
00001 # include <stdio.h>
00002 
00003 /*  Compress whitespace and comments out of strings in a C program,
00004  *  turning all underscores in strings into blanks.
00005  *  Note comments outside of strings with double quotes inside of
00006  *  them are not handled correctly.
00007  */
00008 main()
00009 {
00010 register int c;
00011 int instr = 0;         /* true if we are inside a string  */
00012 int incmt = 0;         /* true if we are inside a comment */
00013                        /* which is itself inside a string */
00014 
00015     
00016     while( (c = getchar()) != EOF ) {
00017         if( instr ) {
00018             switch(c) {
00019 
00020                 case '"': 
00021                     instr = !instr;
00022                     break;
00023 
00024                 case ' ':       /* white space, ignore */
00025                 case '\t':
00026                 case '\n':
00027                     continue;
00028 
00029                 case '_':
00030                     c = ' ';
00031                     break;
00032 
00033                 case '/':       /* comment, ignore */
00034                     { register int lastc;
00035                         c = getchar();
00036                         if( c != '*' ) {
00037                             putchar('/');
00038                             break;
00039                         }
00040                         c = getchar();
00041                         do {
00042                           lastc = c;
00043                           c = getchar();
00044                         } while( (c != EOF) && ((lastc != '*') || (c != '/')) );
00045                         continue;
00046                     }
00047 
00048                 default:
00049                     break;
00050             }
00051         } else {
00052             switch(c) {
00053                 case '"':
00054                     instr = !instr;
00055                     break;
00056 
00057                 default:
00058                     break;
00059             }
00060         }
00061         putchar(c);
00062     }
00063     fflush(stdout);
00064 }

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