/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "decom.p" */ #include /* decom: remove comment starts from within a comment Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu http://www.lecb.ncifcrf.gov/~toms/ */ /* begin module version */ #define version 1.07 /* of decom.p 2000 Oct 24 2000 Oct 24, 1.06: upgrade documentation 1996 Feb 19, 1.05: previous version rebuilt to handle all cases 1996 Feb 19 origin 1988 jan 6 */ /* end module version */ /* begin module describe.decom */ /* name decom: remove comments from within a comment synopsis decom(input: in; output: out) files input: a program having comments within comments. output: the same program with internal comments neutralized. description In Pascal there are two kinds of comments, brace and two-character. On occasion one will have one of these inside the other (eg, this was originally generated by the module.p program). Some compilers cannot handle this situation. This program destroys the comments inside other comments by replacing their parts with other characters. It is smart enough not to destroy comments inside quote strings. see also {Program mentioned in the description above: } module.p {Other comment manipulation programs: } nocom.p codecomments.p {The gpc Gnu Pascal Compiler} http://agnes.dida.physik.uni-essen.de/~gnu-pascal/home.html {can handle embeded comments by using the --no-mixed-comments flag. See:} ftp://ftp.ncifcrf.gov/pub/delila/gpcc author Thomas Dana Schneider bugs technical notes The program defines several characters that are used to replace comment characters. If the ones provided do not work on your system, you can use different ones. The most convenient one is one which rarely occurs in a program and yet is easily found by a search in your editor. In Unix for the vi editor the pound sign '#' is a reasonable choice. */ /* end module describe.decom */ #define debug false /* turn on to see states changing */ #define zap '#' /* general replacement character */ #define zap2begin zap /* character to replace brace comment begin */ #define zap2end zap /* character to replace brace comment end */ #define zap3begin zap /* character to replace two-char comment begin */ #define zap3end zap /* character to replace two-char comment end */ /* state of the program. The program moves between four states depending on the characters it sees: 0: outside comments and quotes 1: inside quotes 2: inside brace comment 3: inside two-character comment */ main(argc, argv) int argc; Char *argv[]; { Char c = ' '; /* the current character just read */ Char o; /* the output character */ Char p; /* the character previous to c */ long state = 0; PASCAL_MAIN(argc, argv); /* start outside the comments */ /* previous character is neutral */ while (!P_eof(stdin)) { while (!P_eoln(stdin)) { p = c; c = getchar(); if (c == '\n') c = ' '; o = c; /* presume we will output this, subject to below */ switch (state) { case 0: /* outside comments and quotes */ if (c == '\'') state = 1; if (c == '{') state = 2; if (p == '(' && c == '*') state = 3; if (debug) o = '0'; break; case 1: /* inside quotes */ if (c == '\'') state = 0; if (debug) o = '1'; break; case 2: /* inside brace comment */ if (p == '(' && c == '*') o = zap2begin; if (p == '*' && c == ')') o = zap2end; if (c == '}') state = 0; if (debug) o = '2'; break; case 3: /* inside two-character type comment */ if (c == '{') o = zap3begin; if (c == '}') o = zap3end; if (p == '*' && c == ')') state = 0; if (debug) o = '3'; break; } putchar(o); } scanf("%*[^\n]"); getchar(); putchar('\n'); p = ' '; /* ignore last character on previous line */ } exit(EXIT_SUCCESS); } /* End. */