3月16日(水) 2011 11:00 以下の修正を scpp-0.1.tgz に加えるパッチ ・新しいflexに対応(多分:-) ・C99のコメント // に対応 ・"defined MACRO" 型のdefined文に対応 ・行頭に空白文字が含まれる前処理制御文に対応 ・バッファを大きくした(巨大なコメント用) ・整数定数の接尾辞u,Uに対応 ・include可能なファイル数を10→100に変更 ・-i,-Iで指定できるディレクトリを100→600に変更し、 制限を超えたときにエラーになるようにした enjoy!! 4b59f7c3-fd21-11e0-bc38-001cc04b15f5 diff -Nrc scpp-0.1.orig/Makefile scpp-0.1/Makefile *** scpp-0.1.orig/Makefile Wed Jul 15 13:31:54 1998 --- scpp-0.1/Makefile Mon Jan 17 17:28:14 2011 *************** *** 8,15 **** # reproduction and use of this program, provided that this # notice and all copyright notices are included in any copy. ! DEFS= ! CFLAGS= -g $(DEFS) HDRS= scpp.h SOURCES= ctrl.c io.c lex.l parse.y scpp.c --- 8,15 ---- # reproduction and use of this program, provided that this # notice and all copyright notices are included in any copy. ! DEFS=-DYYDEBUG=0 ! CFLAGS= -g -O2 $(DEFS) HDRS= scpp.h SOURCES= ctrl.c io.c lex.l parse.y scpp.c *************** *** 17,23 **** all: scpp scpp.cat scpp: $(OBJECTS) ! $(CC) $(CFLAGS) -o scpp $(OBJECTS) -lfl scpp.cat: scpp.1 nroff -man scpp.1 >scpp.cat --- 17,23 ---- all: scpp scpp.cat scpp: $(OBJECTS) ! $(CC) $(CFLAGS) -o scpp $(OBJECTS) scpp.cat: scpp.1 nroff -man scpp.1 >scpp.cat *************** *** 28,43 **** parse.o: parse.c scpp.h lex.c: lex.l ! lex -l -S./flex.skl lex.l ! sed -e '/yylex/s//xxlex/g' lex.c rm lex.yy.c y.tab.h parse.c: parse.y ! yacc -d parse.y mv y.tab.c parse.c clean: -rm -f lex.yy.c lex.c y.tab.c y.tab.h y.output parse.c ! -rm -f $(OBJECTS) tags: $(SOURCES) ctags $(SOURCES) --- 28,45 ---- parse.o: parse.c scpp.h lex.c: lex.l ! flex lex.l ! sed -e /yylex/s//xxlex/g lex.c ! # perl -pe s/yylex/xxlex/g lex.yy.c > lex.c rm lex.yy.c y.tab.h parse.c: parse.y ! kmyacc -d parse.y ! # bison --yacc -d parse.y mv y.tab.c parse.c clean: -rm -f lex.yy.c lex.c y.tab.c y.tab.h y.output parse.c ! -rm -f $(OBJECTS) scpp tags: $(SOURCES) ctags $(SOURCES) diff -Nrc scpp-0.1.orig/ctrl.c scpp-0.1/ctrl.c *** scpp-0.1.orig/ctrl.c Thu Jul 23 08:10:54 1998 --- scpp-0.1/ctrl.c Thu Jan 13 17:03:50 2011 *************** *** 72,78 **** {"ifdef", do_ifdef, 0}, {"ifndef", do_ifndef, 0}, {"if", do_if, 0}, ! {"elif", do_elif, 0}, {"else", do_else, 0}, {"endif", do_endif, 0}, {0,0,0} /* a zero ak_name marks the end of the list */ --- 72,78 ---- {"ifdef", do_ifdef, 0}, {"ifndef", do_ifndef, 0}, {"if", do_if, 0}, ! {"elif", do_elif, 0}, {"else", do_else, 0}, {"endif", do_endif, 0}, {0,0,0} /* a zero ak_name marks the end of the list */ diff -Nrc scpp-0.1.orig/io.c scpp-0.1/io.c *** scpp-0.1.orig/io.c Wed Jul 15 14:33:03 1998 --- scpp-0.1/io.c Thu Jan 13 17:03:50 2011 *************** *** 153,158 **** --- 153,159 ---- pushmac(v) char *v; /* points to a null-terminator or other ignored byte */ { + #if 0 if (curfile->af_raw) { unc(AT_EPUSH); unc(ATTN); *************** *** 164,169 **** --- 165,175 ---- } *nxtin = *v; } + #else + while (*--v != '\0' && *v != ATTN) { + pyyunput(*v); + } + #endif return(v); } *************** *** 181,187 **** char *cp; char **dp; struct afile *ip; ! char *rindex(); char *malloc(); --- 187,193 ---- char *cp; char **dp; struct afile *ip; ! char *strrchr(); char *malloc(); *************** *** 208,214 **** curfile->af_fd = -1; if (itype == PF_DOT) { (void) strcpy(pname, (curfile - 1)->af_name); ! if ((cp = rindex(pname, '/'))) { ++cp; } else { cp = &pname[0]; --- 214,220 ---- curfile->af_fd = -1; if (itype == PF_DOT) { (void) strcpy(pname, (curfile - 1)->af_name); ! if ((cp = strrchr(pname, '/'))) { ++cp; } else { cp = &pname[0]; diff -Nrc scpp-0.1.orig/lex.l scpp-0.1/lex.l *** scpp-0.1.orig/lex.l Wed Jul 15 14:33:40 1998 --- scpp-0.1/lex.l Thu Jan 27 16:23:22 2011 *************** *** 14,22 **** --- 14,28 ---- # include + # define YY_NO_INPUT + + #if 0 # undef input # undef unput # define input() (*nxtin == ATTN ? nxtc() : *nxtin++) + # define unput(c) unc(c) + #endif + # define YY_INPUT(buf,result,max_size) \ { \ int c; \ *************** *** 31,37 **** result = 1; \ } \ } - # define unput(c) unc(c) # include "scpp.h" # include "y.tab.h" --- 37,42 ---- *************** *** 47,52 **** --- 52,62 ---- * calls xxlex()). */ + int yywrap(void) + { + return 1; + } + %} %% *************** *** 89,96 **** } yield(NL); } ! 0x[0-9a-fA-F]+[Ll]? {yield(INT); /* hex constant */} ! [0-9]+[Ll]? {yield(INT); /* decimal or octal constant */} [0-9]+[Ee]([+-][0-9])?[0-9]* | \.[0-9]+([Ee]([+-][0-9])?[0-9]*)? | [0-9]+\.[0-9]*([Ee]([+-][0-9])?[0-9]*)? {yield(FLOAT); /* floating constant */} --- 99,106 ---- } yield(NL); } ! 0x[0-9a-fA-F]+[LlUu]* {yield(INT); /* hex constant */} ! [0-9]+[LlUu]* {yield(INT); /* decimal or octal constant */} [0-9]+[Ee]([+-][0-9])?[0-9]* | \.[0-9]+([Ee]([+-][0-9])?[0-9]*)? | [0-9]+\.[0-9]*([Ee]([+-][0-9])?[0-9]*)? {yield(FLOAT); /* floating constant */} *************** *** 100,105 **** --- 110,117 ---- \\ {yield(BACKS);} "/*" {yield(OPENC); /* start (open) comment */} "*/" {yield(CLOSEC);/* finish (close) comment */} + \/\/.*$ {yield(COMM);/* comment (C99) */} + ^[ \t]*# {yield(POUNDLINE);} # {/* * a control line if preceeded immediately by a newline, * even if that newline was the result of macro interpretation. *************** *** 112,114 **** --- 124,131 ---- . {yield(OTHER);} %% + + void pyyunput(int c) + { + unput(c); + } diff -Nrc scpp-0.1.orig/parse.y scpp-0.1/parse.y *** scpp-0.1.orig/parse.y Wed Dec 13 07:36:51 1989 --- scpp-0.1/parse.y Thu Jan 13 17:03:50 2011 *************** *** 43,48 **** --- 43,49 ---- %term BACKS /* \ (backslash) */ %term OPENC /* open comment sequence */ %term CLOSEC /* close comment sequence */ + %term COMM /* comment (C99) */ %term WHITE /* whitespace */ %term NL /* newline */ %term QNL /* escaped (quoted) newline */ *************** *** 80,86 **** %type MUL DIV MOD PLUS MINUS LS RS AND OR ER LT LE GT GE EQ NE ANDAND OROR CM QUEST COLON NOT COMPL LP RP INT FLOAT IDENT QUOTE DQUOTE BACKS OPENC CLOSEC WHITE NL QNL COMMENT OTHER ! STRING CHARS POUNDLINE DEFMAC %{ # include "scpp.h" --- 81,87 ---- %type MUL DIV MOD PLUS MINUS LS RS AND OR ER LT LE GT GE EQ NE ANDAND OROR CM QUEST COLON NOT COMPL LP RP INT FLOAT IDENT QUOTE DQUOTE BACKS OPENC CLOSEC WHITE NL QNL COMMENT OTHER ! STRING CHARS POUNDLINE DEFMAC COMM %{ # include "scpp.h" diff -Nrc scpp-0.1.orig/scpp.c scpp-0.1/scpp.c *** scpp-0.1.orig/scpp.c Thu Jul 23 07:56:19 1998 --- scpp-0.1/scpp.c Wed Mar 16 11:25:06 2011 *************** *** 85,93 **** --- 85,101 ---- break; case 'i': *ip++ = cp + 1; + if (ilist +DLSIZ <= ip) { + warn("too many include file"); + exit(1); + } break; case 'I': *dp++ = cp + 1; + if (dirlist +DLSIZ -2 <= dp) { + warn("too many include path"); + exit(1); + } break; case 'M': /* *************** *** 290,304 **** } else { defident = (char *) 0; } ! ! if ((tok = nonwhite(gtok)) != LP) { ! warnf("missing parenthesis in macro '%s'", mac->am_name); parmgripe = TRUE; /* pushback the erroneous token */ untok(); } else { do { /* collect one parameter */ --- 298,331 ---- } else { defident = (char *) 0; } ! ! tok = nonwhite(gtok); ! if (tok != LP && tok != IDENT) { ! warnf("missing parenthesis or macro name in macro '%s'", mac->am_name); parmgripe = TRUE; /* pushback the erroneous token */ untok(); + } else if (tok == IDENT) { + if (defident == &magicval) { + /* for magic macro "defined MACRO" */ + defident = savtok(curtext, nxtout); + actp->aa_val = defident; + actp->aa_mem = 0; + ++actp; + } else { + warnf("missing parenthesis in macro '%s'", + mac->am_name); + parmgripe = TRUE; + + /* pushback the erroneous token */ + untok(); + } } else { + /* normal macro with parameters + * OR magic macro "defined()" + */ do { /* collect one parameter */ *************** *** 451,456 **** --- 478,485 ---- } } tok = COMMENT; + } else if (tok == COMM) { + tok = COMMENT; } return(tok); } diff -Nrc scpp-0.1.orig/scpp.h scpp-0.1/scpp.h *** scpp-0.1.orig/scpp.h Thu Jul 23 07:57:55 1998 --- scpp-0.1/scpp.h Wed Mar 16 10:36:05 2011 *************** *** 55,61 **** * ATTN bytes.) */ ! # define PENDSIZ 8000 # define PENDHIGH 512 /* highwater mark for flushing pend[] */ #ifdef VARS char pend[PENDSIZ]; --- 55,61 ---- * ATTN bytes.) */ ! # define PENDSIZ 64000 # define PENDHIGH 512 /* highwater mark for flushing pend[] */ #ifdef VARS char pend[PENDSIZ]; *************** *** 93,99 **** */ }; ! #define FILESIZ 11 /* max # of include files + 1 (the original file) */ #ifdef VARS struct afile filestk[FILESIZ]; struct afile *curfile; /* the current file. Initially = &filestk[-1] */ --- 93,99 ---- */ }; ! #define FILESIZ 101 /* max # of include files + 1 (the original file) */ #ifdef VARS struct afile filestk[FILESIZ]; struct afile *curfile; /* the current file. Initially = &filestk[-1] */ *************** *** 126,131 **** --- 126,133 ---- extern char *pushmac(); #define unc(c) (nxtin-- < &istk[0] ? over() : (*nxtin = c)) + extern void pyyunput(int c); + /* * ATTN appears in the input stack to notify nxtc() of some condition, * in the output queue to notify dispose() or outpend() of some condition, *************** *** 271,277 **** * ilist - list of included files to be processed (-M option for #include). */ ! #define DLSIZ 100 #ifdef VARS char *dirlist[DLSIZ]; char *ilist[DLSIZ]; --- 273,279 ---- * ilist - list of included files to be processed (-M option for #include). */ ! #define DLSIZ 600 #ifdef VARS char *dirlist[DLSIZ]; char *ilist[DLSIZ]; diff -Nrc scpp-0.1.orig/vc-patch scpp-0.1/vc-patch *** scpp-0.1.orig/vc-patch Thu Jan 1 09:00:00 1970 --- scpp-0.1/vc-patch Thu Jan 27 16:47:38 2011 *************** *** 0 **** --- 1,61 ---- + *** Makefile Mon Jan 17 17:28:14 2011 + --- Makefile.vc Thu Jan 27 16:47:08 2011 + *************** + *** 13,19 **** + HDRS= scpp.h + + SOURCES= ctrl.c io.c lex.l parse.y scpp.c + ! OBJECTS= ctrl.o io.o lex.o parse.o scpp.o + + all: scpp scpp.cat + scpp: $(OBJECTS) + --- 13,19 ---- + HDRS= scpp.h + + SOURCES= ctrl.c io.c lex.l parse.y scpp.c + ! OBJECTS= ctrl.obj io.obj lex.obj parse.obj scpp.obj + + all: scpp scpp.cat + scpp: $(OBJECTS) + *************** + *** 21,31 **** + scpp.cat: scpp.1 + nroff -man scpp.1 >scpp.cat + + ! scpp.o: scpp.c y.tab.h scpp.h + ! ctrl.o: ctrl.c y.tab.h scpp.h + ! io.o: io.c scpp.h + ! lex.o: lex.c y.tab.h scpp.h + ! parse.o: parse.c scpp.h + + lex.c: lex.l + flex lex.l + --- 21,31 ---- + scpp.cat: scpp.1 + nroff -man scpp.1 >scpp.cat + + ! scpp.obj: scpp.c y.tab.h scpp.h + ! ctrl.obj: ctrl.c y.tab.h scpp.h + ! io.obj: io.c scpp.h + ! lex.obj: lex.c y.tab.h scpp.h + ! parse.obj: parse.c scpp.h + + lex.c: lex.l + flex lex.l + *************** + *** 39,45 **** + + clean: + -rm -f lex.yy.c lex.c y.tab.c y.tab.h y.output parse.c + ! -rm -f $(OBJECTS) scpp + + tags: $(SOURCES) + ctags $(SOURCES) + --- 39,45 ---- + + clean: + -rm -f lex.yy.c lex.c y.tab.c y.tab.h y.output parse.c + ! -rm -f $(OBJECTS) scpp.exe + + tags: $(SOURCES) + ctags $(SOURCES)