hwpfilter/source/hwpeq.cxx | 58 - rsc/source/rscpp/cpp.h | 167 ++-- rsc/source/rscpp/cpp2.c | 742 ++++++++++---------- rsc/source/rscpp/cpp3.c | 489 ++++++------- rsc/source/rscpp/cpp4.c | 735 ++++++++++---------- rsc/source/rscpp/cpp5.c | 562 ++++++++------- rsc/source/rscpp/cpp6.c | 1416 ++++++++++++++++++++------------------- sc/source/core/tool/compiler.cxx | 1 sc/source/core/tool/interpr3.cxx | 1 sc/source/ui/view/output.cxx | 3 soltools/mkdepend/include.c | 29 11 files changed, 2236 insertions(+), 1967 deletions(-)
New commits: commit 99ae57a92dd4f218efe8dbc04cce519efd9d6d5e Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Sat Oct 4 00:51:45 2014 -0500 hwfilter: fix misuse of strncpy Change-Id: Ia52d6cd32aa3e3838d31ea2a994117e6820a503d diff --git a/hwpfilter/source/hwpeq.cxx b/hwpfilter/source/hwpeq.cxx index 41c2f3e..2cc6ec2 100644 --- a/hwpfilter/source/hwpeq.cxx +++ b/hwpfilter/source/hwpeq.cxx @@ -404,35 +404,43 @@ static const hwpeq *lookup_eqn(char *str) /* 첫ìë§ ë문ìì´ê±°ë ì ë¶ ë문ìë©´ ì문ìë¡ ë°ê¾¼ë¤. */ void make_keyword( char *keyword, const char *token) { - assert(keyword); - char *ptr; - bool result = true; - int len = strlen(token); + char* ptr; + bool result = true; + int len = strlen(token); + assert(keyword); - if( 255 < len ) - strncpy(keyword, token, 255); - else - strcpy(keyword, token); + if( 255 < len ) + { + len = 255; + } + memcpy(keyword, token, len); + keyword[len] = 0; - if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 ) - return; + if( (token[0] & 0x80) || islower(token[0]) || strlen(token) < 2 ) + return; + + int capital = isupper(keyword[1]); + for( ptr = keyword + 2; *ptr && result; ptr++ ) + { + if( (*ptr & 0x80) || + (!capital && isupper(*ptr)) || + (capital && islower(*ptr)) ) + { + result = false; + } + } - int capital = isupper(keyword[1]); - for( ptr = keyword + 2; *ptr && result; ptr++ ) - if( (*ptr & 0x80) || - (!capital && isupper(*ptr)) || - (capital && islower(*ptr)) ) - result = false; - - if( result ) { - ptr = keyword; - while( *ptr ) { - if( isupper(*ptr) ) - *ptr = sal::static_int_cast<char>(tolower(*ptr)); - ptr++; + if( result ) + { + ptr = keyword; + while( *ptr ) + { + if( isupper(*ptr) ) + *ptr = sal::static_int_cast<char>(tolower(*ptr)); + ptr++; + } } - } - return; + return; } // token reading function commit cb5eb3e7e79f612f036d5f0dd54f12a907f35ea7 Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Sat Oct 4 00:36:34 2014 -0500 coverity#706152 Copy into fixed size buffer Change-Id: Ib347f650d060e7762a367133a1218c2d34c9ce73 diff --git a/rsc/source/rscpp/cpp.h b/rsc/source/rscpp/cpp.h index 1a9f5c6..e12ec0b 100644 --- a/rsc/source/rscpp/cpp.h +++ b/rsc/source/rscpp/cpp.h @@ -293,7 +293,7 @@ void doinclude( void ); void dodefine( void ); void doif( int hash ); int openinclude( char*, int ); -int hasdirectory( char*, char* ); +int hasdirectory( char*, char*, int ); int openfile( char* ); /* cpp3.c */ diff --git a/rsc/source/rscpp/cpp2.c b/rsc/source/rscpp/cpp2.c index 4a564da..f082275 100644 --- a/rsc/source/rscpp/cpp2.c +++ b/rsc/source/rscpp/cpp2.c @@ -415,6 +415,8 @@ FILE_LOCAL int openinclude(char* filename, int searchlocal) { char** incptr; char tmpname[NFWORK]; /* Filename work area */ + int len; + int len2; if (searchlocal) { @@ -427,17 +429,36 @@ FILE_LOCAL int openinclude(char* filename, int searchlocal) * source file (as opposed to the current directory). (ARF, SCK). */ if (filename[0] != '/' && - hasdirectory(infile->filename, tmpname)) + hasdirectory(infile->filename, tmpname, NFWORK)) { - strcat(tmpname, filename); + len = strlen(tmpname); + len2 = strlen(filename); + if(len + len2 < NFWORK) + { + memcpy(tmpname + len, filename, len2); + tmpname[len + len2] = 0; + } + else + { + cfatal("Filename work buffer overflow", NULLST); + } } else { - strcpy(tmpname, filename); + len = strlen(filename); + if(len < NFWORK) + { + memcpy(tmpname, filename, len); + tmpname[len] = 0; + } + else + { + cfatal("Filename work buffer overflow", NULLST); + } } #else - if (!hasdirectory(filename, tmpname) && - hasdirectory(infile->filename, tmpname)) + if (!hasdirectory(filename, tmpname, NFWORK) && + hasdirectory(infile->filename, tmpname, NFWORK)) { strcat(tmpname, filename); } @@ -471,7 +492,7 @@ FILE_LOCAL int openinclude(char* filename, int searchlocal) else sprintf(tmpname, "%s\\%s", *incptr, filename); #else - if (!hasdirectory(filename, tmpname)) + if (!hasdirectory(filename, tmpname, NFWORK)) sprintf(tmpname, "%s%s", *incptr, filename); #endif if (openfile(tmpname)) @@ -486,7 +507,7 @@ FILE_LOCAL int openinclude(char* filename, int searchlocal) * node/device/directory part of the string is copied to result and * hasdirectory returns TRUE. Else, nothing is copied and it returns FALSE. */ -FILE_LOCAL int hasdirectory(char* source, char* result) +FILE_LOCAL int hasdirectory(char* source, char* result, int max) { #if HOST == SYS_UNIX char* tp; @@ -495,8 +516,16 @@ FILE_LOCAL int hasdirectory(char* source, char* result) return (FALSE); else { - strncpy(result, source, tp - source + 1); - result[tp - source + 1] = EOS; + int len = (int)(tp - source); + if(len < max) + { + memcpy(result, source, len); + result[len] = 0; + } + else + { + cfatal("Filename work buffer overflow", NULLST); + } return (TRUE); } #else commit 0091f937116550a9f5e30bf200f536701cc0b068 Author: Norbert Thiebaud <nthieb...@gmail.com> Date: Sat Oct 4 00:20:18 2014 -0500 cosmetic: start bringing rscpp in this century c-wise Change-Id: I469bc4c518c3ac299a18559cdd3e1b49d34b5ace diff --git a/rsc/source/rscpp/cpp.h b/rsc/source/rscpp/cpp.h index 7f45375..1a9f5c6 100644 --- a/rsc/source/rscpp/cpp.h +++ b/rsc/source/rscpp/cpp.h @@ -26,10 +26,10 @@ #endif /* in cpp1.c: file-pointer auf stdout oder file */ -extern FILE *pCppOut; /* BP */ +extern FILE* pCppOut; /* BP */ #define PUTCHAR( d ) fprintf( pCppOut, "%c", (d) ) /* BP */ #if OSL_DEBUG_LEVEL > 1 -extern FILE *pDefOut; /* ER */ +extern FILE* pDefOut; /* ER */ #ifdef EVALDEFS #define NEVALBUF 2048 #endif @@ -164,12 +164,13 @@ extern FILE *pDefOut; /* ER */ * in malloc storage. */ -typedef struct defbuf { - struct defbuf *link; /* Next define in chain */ - char *repl; /* -> replacement */ - int hash; /* Symbol table hash */ - int nargs; /* For define(args) */ - char name[1]; /* #define name */ +typedef struct defbuf +{ + struct defbuf* link; /* Next define in chain */ + char* repl; /* -> replacement */ + int hash; /* Symbol table hash */ + int nargs; /* For define(args) */ + char name[1]; /* #define name */ } DEFBUF; /* @@ -177,22 +178,24 @@ typedef struct defbuf { * and macros being expanded. */ -typedef struct fileinfo { - char *bptr; /* Buffer pointer */ - int line; /* for include or macro */ - FILE *fp; /* File if non-null */ - struct fileinfo *parent; /* Link to includer */ - char *filename; /* File/macro name */ - char *progname; /* From #line statement */ - unsigned int unrecur; /* For macro recursion */ - char buffer[1]; /* current input line */ +typedef struct fileinfo +{ + char* bptr; /* Buffer pointer */ + int line; /* for include or macro */ + FILE* fp; /* File if non-null */ + struct fileinfo* parent; /* Link to includer */ + char* filename; /* File/macro name */ + char* progname; /* From #line statement */ + unsigned int unrecur; /* For macro recursion */ + char buffer[1]; /* current input line */ } FILEINFO; /* * The SIZES structure is used to store the values for #if sizeof */ -typedef struct sizes { +typedef struct sizes +{ short bits; /* If this bit is set, */ int size; /* this is the datum size value */ int psize; /* this is the pointer size */ @@ -204,8 +207,8 @@ typedef struct sizes { /* * Error codes. */ -#define IO_NORMAL 0 -#define IO_ERROR 1 +#define IO_NORMAL 0 +#define IO_ERROR 1 /* * Externs @@ -221,18 +224,18 @@ extern int errors; /* Error counter */ extern int recursion; /* Macro depth counter */ extern char ifstack[BLK_NEST]; /* #if information */ #define compiling ifstack[0] -extern char *ifptr; /* -> current ifstack item */ -extern char *incdir[NINCLUDE]; /* -i directories */ -extern char **incend; /* -> active end of incdir */ +extern char* ifptr; /* -> current ifstack item */ +extern char* incdir[NINCLUDE]; /* -i directories */ +extern char** incend; /* -> active end of incdir */ extern int cflag; /* -C option (keep comments) */ extern int eflag; /* -E option (ignore errors) */ extern int nflag; /* -N option (no pre-defines) */ extern int rec_recover; /* unwind recursive macros */ -extern char *preset[]; /* Standard predefined symbols */ -extern char *magic[]; /* Magic predefined symbols */ -extern FILEINFO *infile; /* Current input file */ +extern char* preset[]; /* Standard predefined symbols */ +extern char* magic[]; /* Magic predefined symbols */ +extern FILEINFO* infile; /* Current input file */ extern char work[NWORK + 1]; /* #define scratch */ -extern char *workp; /* Free space in work */ +extern char* workp; /* Free space in work */ #if OSL_DEBUG_LEVEL > 1 extern int debug; /* Debug level */ /* ER dump & evaluate #define's */ @@ -260,12 +263,12 @@ int rscpp_main( int argc, char **argv ); #endif -void InitCpp1(void); -void InitCpp2(void); -void InitCpp3(void); -void InitCpp4(void); -void InitCpp5(void); -void InitCpp6(void); +void InitCpp1( void ); +void InitCpp2( void ); +void InitCpp3( void ); +void InitCpp4( void ); +void InitCpp5( void ); +void InitCpp6( void ); #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ ) @@ -275,8 +278,8 @@ void InitCpp6(void); /* cpp1.c */ void output( int c ); -void sharp(void); -void cppmain(void); +void sharp( void ); +void cppmain( void ); #if OSL_DEBUG_LEVEL > 1 #ifdef EVALDEFS int outputEval( int c ); @@ -286,79 +289,79 @@ int outputEval( int c ); /* cpp2.c */ int control( int counter ); -void doinclude(void); -void dodefine(void); +void doinclude( void ); +void dodefine( void ); void doif( int hash ); -int openinclude( char *, int ); -int hasdirectory(char *, char * ); -int openfile( char * ); +int openinclude( char*, int ); +int hasdirectory( char*, char* ); +int openfile( char* ); /* cpp3.c */ -int openfiles( char *filename ); -void addfile( FILE *fp, char *filename ); -void setincdirs(void); -int AddInclude( char *pIncStr ); -int getredirection( int argc, char **argv ); -void zap_uc( char *ap ); +int openfiles( char* filename ); +void addfile( FILE* fp, char* filename ); +void setincdirs( void ); +int AddInclude( char* pIncStr ); +int getredirection( int argc, char** argv ); +void zap_uc( char* ap ); -void initdefines(void); -int dooptions( int argc, char *argv[] ); -int readoptions(char* filename, char*** pfargv); +void initdefines( void ); +int dooptions( int argc, char* argv[] ); +int readoptions( char* filename, char*** pfargv ); /* cpp4.c */ -void dodefines(void); -void checkparm( int c, DEFBUF *dp ); -int expcollect(void); -void expstuff( DEFBUF *dp ); +void dodefines( void ); +void checkparm( int c, DEFBUF* dp ); +int expcollect( void ); +void expstuff( DEFBUF* dp ); -void stparmscan( int delim); +void stparmscan( int delim ); #if OSL_DEBUG_LEVEL > 1 -void dumpparm( char *why ); +void dumpparm( char* why ); #endif -void doundef(void); -void textput( char *text ); +void doundef( void ); +void textput( char* text ); void charput( int c ); -void expand( DEFBUF *tokenp ); +void expand( DEFBUF* tokenp ); /* cpp5.c */ -int eval(void); -int evallex(int); -int *evaleval(int *, int, int ); -int evalchar(int); -int dosizeof(void); +int eval( void ); +int evallex( int ); +int *evaleval( int*, int, int ); +int evalchar( int ); +int dosizeof( void ); int evalnum( int c ); int bittest( int ); /* cpp6.c */ -void skipnl(void); -int skipws(void); +void skipnl( void ); +int skipws( void ); void scanid( int c ); int macroid( int c ); int catenate(void); int scanstring( int c, void (*outfun)( int c ) ); void scannumber( int c, void (*outfun)( int c ) ); void save( int c ); -char *savestring( char *text ); -FILEINFO *getfile( int bufsize, char *name); +char* savestring( char* text ); +FILEINFO* getfile( int bufsize, char* name ); char *getmem( int size ); -DEFBUF *lookid( int c ); -DEFBUF *defendel( char *name, int delete ); -void dunpdef( char *why ); -void dumpadef( char *why, DEFBUF *dp); -int get(void); -int cget(void); -void unget(void); -void ungetstring( char *text ); -void cerror( char *format, char *sarg); -void cwarn( char *format, char *sarg); -void cfatal( char *format, char *sarg); -void cierror( char *format, int n); -void ciwarn( char *format, int n); +DEFBUF* lookid( int c ); +DEFBUF* defendel( char* name, int delete ); +void dunpdef( char* why ); +void dumpadef( char* why, DEFBUF* dp ); +int get( void ); +int cget( void ); +void unget( void ); +void ungetstring( char* text ); +void cerror( char* format, char* sarg ); +void cwarn( char* format, char* sarg ); +void cfatal( char* format, char* sarg ); +void cierror( char* format, int n ); +void ciwarn( char* format, int n ); #if OSL_DEBUG_LEVEL > 1 -void dumpdef( char *why ); -void dumpadef( char *why, DEFBUF *dp ); +void dumpdef( char* why ); +void dumpadef( char* why, DEFBUF *dp ); #endif #endif // INCLUDED_RSC_SOURCE_RSCPP_CPP_H diff --git a/rsc/source/rscpp/cpp2.c b/rsc/source/rscpp/cpp2.c index 71db0c3..4a564da 100644 --- a/rsc/source/rscpp/cpp2.c +++ b/rsc/source/rscpp/cpp2.c @@ -53,9 +53,6 @@ void InitCpp2() } - -int -control(int counter) /* * Process #control lines. Simple commands are processed inline, * while complex commands have their own subroutines. @@ -64,232 +61,247 @@ control(int counter) * #pragma commands. This prevents these commands from ending up at * the end of the previous line if cpp is invoked with the -C option. */ +int control(int counter) { - int c; - char *tp; - int hash; - char *ep; + int c; + char* tp; + int hash; + char* ep; - c = skipws(); - if (c == '\n' || c == EOF_CHAR) - return (counter + 1); - if (!isdigit(c)) - scanid(c); /* Get #word to token[] */ - else { - unget(); /* Hack -- allow #123 as a */ - strcpy(token, "line"); /* synonym for #line 123 */ - } - hash = (token[1] == EOS) ? L_nogood : (token[0] + (token[2] << 1)); - switch (hash) { - case L_assert: tp = "assert"; break; - case L_define: tp = "define"; break; - case L_elif: tp = "elif"; break; - case L_else: tp = "else"; break; - case L_endif: tp = "endif"; break; - case L_if: tp = "if"; break; - case L_ifdef: tp = "ifdef"; break; - case L_ifndef: tp = "ifndef"; break; - case L_include: tp = "include"; break; - case L_line: tp = "line"; break; - case L_pragma: tp = "pragma"; break; - case L_undef: tp = "undef"; break; - case L_error: tp = "error"; break; + c = skipws(); + if (c == '\n' || c == EOF_CHAR) + return (counter + 1); + if (!isdigit(c)) + scanid(c); /* Get #word to token[] */ + else + { + unget(); /* Hack -- allow #123 as a */ + strcpy(token, "line"); /* synonym for #line 123 */ + } + hash = (token[1] == EOS) ? L_nogood : (token[0] + (token[2] << 1)); + switch (hash) + { + case L_assert: tp = "assert"; break; + case L_define: tp = "define"; break; + case L_elif: tp = "elif"; break; + case L_else: tp = "else"; break; + case L_endif: tp = "endif"; break; + case L_if: tp = "if"; break; + case L_ifdef: tp = "ifdef"; break; + case L_ifndef: tp = "ifndef"; break; + case L_include: tp = "include"; break; + case L_line: tp = "line"; break; + case L_pragma: tp = "pragma"; break; + case L_undef: tp = "undef"; break; + case L_error: tp = "error"; break; #if OSL_DEBUG_LEVEL > 1 - case L_debug: tp = "debug"; break; - case L_nodebug: tp = "nodebug"; break; + case L_debug: tp = "debug"; break; + case L_nodebug: tp = "nodebug"; break; #endif - default: hash = L_nogood; + default: hash = L_nogood; /*fall-through*/ - case L_nogood: tp = ""; break; - } - if (!streq(tp, token)) - hash = L_nogood; - /* - * hash is set to a unique value corresponding to the - * control keyword (or L_nogood if we think it's nonsense). - */ - if (infile->fp == NULL) - cwarn("Control line \"%s\" within macro expansion", token); - if (!compiling) { /* Not compiling now */ - switch (hash) { - case L_if: /* These can't turn */ - case L_ifdef: /* compilation on, but */ - case L_ifndef: /* we must nest #if's */ - if (++ifptr >= &ifstack[BLK_NEST]) - goto if_nest_err; - *ifptr = 0; /* !WAS_COMPILING */ - case L_line: /* Many */ + case L_nogood: tp = ""; break; + } + if (!streq(tp, token)) + hash = L_nogood; + /* + * hash is set to a unique value corresponding to the + * control keyword (or L_nogood if we think it's nonsense). + */ + if (infile->fp == NULL) + cwarn("Control line \"%s\" within macro expansion", token); + if (!compiling) + { /* Not compiling now */ + switch (hash) + { + case L_if: /* These can't turn */ + case L_ifdef: /* compilation on, but */ + case L_ifndef: /* we must nest #if's */ + if (++ifptr >= &ifstack[BLK_NEST]) + goto if_nest_err; + *ifptr = 0; /* !WAS_COMPILING */ + case L_line: /* Many */ /* * Are pragma's always processed? */ - case L_pragma: /* options */ - case L_include: /* are uninteresting */ - case L_define: /* if we */ - case L_undef: /* aren't */ - case L_assert: /* compiling. */ - case L_error: /* BP 5.3.92, #error */ -dump_line: skipnl(); /* Ignore rest of line */ - return (counter + 1); - } + case L_pragma: /* options */ + case L_include: /* are uninteresting */ + case L_define: /* if we */ + case L_undef: /* aren't */ + case L_assert: /* compiling. */ + case L_error: /* BP 5.3.92, #error */ + dump_line: skipnl(); /* Ignore rest of line */ + return (counter + 1); } + } + /* + * Make sure that #line and #pragma are output on a fresh line. + */ + if (counter > 0 && (hash == L_line || hash == L_pragma)) + { + PUTCHAR('\n'); + counter--; + } + + switch (hash) + { + case L_line: /* - * Make sure that #line and #pragma are output on a fresh line. + * Parse the line to update the line number and "progname" + * field and line number for the next input line. + * Set wrongline to force it out later. */ - if (counter > 0 && (hash == L_line || hash == L_pragma)) { - PUTCHAR('\n'); - counter--; + c = skipws(); + workp = work; /* Save name in work */ + while (c != '\n' && c != EOF_CHAR) + { + save(c); + c = get(); } - switch (hash) { - case L_line: - /* - * Parse the line to update the line number and "progname" - * field and line number for the next input line. - * Set wrongline to force it out later. - */ - c = skipws(); - workp = work; /* Save name in work */ - while (c != '\n' && c != EOF_CHAR) { - save(c); - c = get(); - } - unget(); - save(EOS); - /* - * Split #line argument into <line-number> and <name> - * We subtract 1 as we want the number of the next line. - */ - line = atoi(work) - 1; /* Reset line number */ - for (tp = work; isdigit(*tp) || type[(int)*tp] == SPA; tp++) - ; /* Skip over digits */ - if (*tp != EOS) { /* Got a filename, so: */ - if (*tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL) { - tp++; /* Skip over left quote */ - *ep = EOS; /* And ignore right one */ - } - if (infile->progname != NULL) /* Give up the old name */ - free(infile->progname); /* if it's allocated. */ - infile->progname = savestring(tp); - } - wrongline = TRUE; /* Force output later */ - break; - - case L_include: - doinclude(); - break; - - case L_define: - dodefine(); - break; - - case L_undef: - doundef(); - break; - - case L_else: - if (ifptr == &ifstack[0]) - goto nest_err; - else if ((*ifptr & ELSE_SEEN) != 0) - goto else_seen_err; - *ifptr |= ELSE_SEEN; - if ((*ifptr & WAS_COMPILING) != 0) { - if (compiling || (*ifptr & TRUE_SEEN) != 0) - compiling = FALSE; - else { - compiling = TRUE; - } - } - break; - - case L_elif: - if (ifptr == &ifstack[0]) - goto nest_err; - else if ((*ifptr & ELSE_SEEN) != 0) { -else_seen_err: cerror("#%s may not follow #else", token); - goto dump_line; + unget(); + save(EOS); + /* + * Split #line argument into <line-number> and <name> + * We subtract 1 as we want the number of the next line. + */ + line = atoi(work) - 1; /* Reset line number */ + for (tp = work; isdigit(*tp) || type[(int)*tp] == SPA; tp++) + ; /* Skip over digits */ + if (*tp != EOS) /* Got a filename, so: */ + { + if (*tp == '"' && (ep = strrchr(tp + 1, '"')) != NULL) + { + tp++; /* Skip over left quote */ + *ep = EOS; /* And ignore right one */ } - if ((*ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING) { - compiling = FALSE; /* Done compiling stuff */ - goto dump_line; /* Skip this clause */ + if (infile->progname != NULL) /* Give up the old name */ + free(infile->progname); /* if it's allocated. */ + infile->progname = savestring(tp); + } + wrongline = TRUE; /* Force output later */ + break; + + case L_include: + doinclude(); + break; + + case L_define: + dodefine(); + break; + + case L_undef: + doundef(); + break; + + case L_else: + if (ifptr == &ifstack[0]) + goto nest_err; + else if ((*ifptr & ELSE_SEEN) != 0) + goto else_seen_err; + *ifptr |= ELSE_SEEN; + if ((*ifptr & WAS_COMPILING) != 0) + { + if (compiling || (*ifptr & TRUE_SEEN) != 0) + compiling = FALSE; + else + { + compiling = TRUE; } - doif(L_if); - break; + } + break; - case L_if: - case L_ifdef: - case L_ifndef: - if (++ifptr >= &ifstack[BLK_NEST]) -if_nest_err: cfatal("Too many nested #%s statements", token); - *ifptr = WAS_COMPILING; - doif(hash); - break; - - case L_endif: - if (ifptr == &ifstack[0]) { -nest_err: cerror("#%s must be in an #if", token); - goto dump_line; - } - if (!compiling && (*ifptr & WAS_COMPILING) != 0) - wrongline = TRUE; - compiling = ((*ifptr & WAS_COMPILING) != 0); - --ifptr; - break; - - case L_assert: - if (eval() == 0) - cerror("Preprocessor assertion failure", NULLST); - break; - - case L_pragma: - /* - * #pragma is provided to pass "options" to later - * passes of the compiler. cpp doesn't have any yet. - */ - fprintf( pCppOut, "#pragma "); - while ((c = get()) != '\n' && c != EOF_CHAR) - cput(c); - unget(); - break; + case L_elif: + if (ifptr == &ifstack[0]) + goto nest_err; + else if ((*ifptr & ELSE_SEEN) != 0) + { + else_seen_err: cerror("#%s may not follow #else", token); + goto dump_line; + } + if ((*ifptr & (WAS_COMPILING | TRUE_SEEN)) != WAS_COMPILING) + { + compiling = FALSE; /* Done compiling stuff */ + goto dump_line; /* Skip this clause */ + } + doif(L_if); + break; + + case L_if: + case L_ifdef: + case L_ifndef: + if (++ifptr >= &ifstack[BLK_NEST]) + if_nest_err: cfatal("Too many nested #%s statements", token); + *ifptr = WAS_COMPILING; + doif(hash); + break; + + case L_endif: + if (ifptr == &ifstack[0]) + { + nest_err: cerror("#%s must be in an #if", token); + goto dump_line; + } + if (!compiling && (*ifptr & WAS_COMPILING) != 0) + wrongline = TRUE; + compiling = ((*ifptr & WAS_COMPILING) != 0); + --ifptr; + break; + + case L_assert: + if (eval() == 0) + cerror("Preprocessor assertion failure", NULLST); + break; + + case L_pragma: + /* + * #pragma is provided to pass "options" to later + * passes of the compiler. cpp doesn't have any yet. + */ + fprintf( pCppOut, "#pragma "); + while ((c = get()) != '\n' && c != EOF_CHAR) + cput(c); + unget(); + break; #if OSL_DEBUG_LEVEL > 1 - case L_debug: - if (debug == 0) - dumpdef("debug set on"); - debug++; - break; - - case L_nodebug: - debug--; - break; + case L_debug: + if (debug == 0) + dumpdef("debug set on"); + debug++; + break; + + case L_nodebug: + debug--; + break; #endif - case L_error: /* BP 5.3.92, #error */ + case L_error: /* BP 5.3.92, #error */ + fprintf( pCppOut, "cpp: line %u, Error directive: ", line ); + while ((c = get()) != '\n' && c != EOF_CHAR) + cput(c); + fprintf( pCppOut, "\n" ); + exit( 1 ); + + default: + /* + * Undefined #control keyword. + * Note: the correct behavior may be to warn and + * pass the line to a subsequent compiler pass. + * This would allow #asm or similar extensions. + */ + cerror("Illegal # command \"%s\"", token); + break; + } + if (hash != L_include) + { + if (skipws() != '\n') { - fprintf( pCppOut, "cpp: line %u, Error directive: ", line ); - while ((c = get()) != '\n' && c != EOF_CHAR) - cput(c); - fprintf( pCppOut, "\n" ); - exit( 1 ); - } - default: - /* - * Undefined #control keyword. - * Note: the correct behavior may be to warn and - * pass the line to a subsequent compiler pass. - * This would allow #asm or similar extensions. - */ - cerror("Illegal # command \"%s\"", token); - break; + cwarn("Unexpected text in #control line ignored", NULLST); + skipnl(); } - if (hash != L_include) { - if (skipws() != '\n') { - cwarn("Unexpected text in #control line ignored", NULLST); - skipnl(); - } - } - return (counter + 1); + } + return (counter + 1); } -FILE_LOCAL -void doif(int hash) /* * Process an #if, #ifdef, or #ifndef. The latter two are straightforward, * while #if needs a subroutine of its own to evaluate the expression. @@ -298,41 +310,45 @@ void doif(int hash) * is always suppressed, so we don't need to evaluate anything. This * suppresses unnecessary warnings. */ +FILE_LOCAL void doif(int hash) { - int c; - int found; - - if ((c = skipws()) == '\n' || c == EOF_CHAR) { - unget(); - goto badif; - } - if (hash == L_if) { - unget(); - found = (eval() != 0); /* Evaluate expr, != 0 is TRUE */ - hash = L_ifdef; /* #if is now like #ifdef */ - } - else { - if (type[c] != LET) /* Next non-blank isn't letter */ - goto badif; /* ... is an error */ - found = (lookid(c) != NULL); /* Look for it in symbol table */ - } - if (found == (hash == L_ifdef)) { - compiling = TRUE; - *ifptr |= TRUE_SEEN; - } - else { - compiling = FALSE; - } - return; - -badif: cerror("#if, #ifdef, or #ifndef without an argument", NULLST); - skipnl(); /* Prevent an extra */ - unget(); /* Error message */ - return; + int c; + int found; + + if ((c = skipws()) == '\n' || c == EOF_CHAR) + { + unget(); + goto badif; + } + if (hash == L_if) + { + unget(); + found = (eval() != 0); /* Evaluate expr, != 0 is TRUE */ + hash = L_ifdef; /* #if is now like #ifdef */ + } + else + { + if (type[c] != LET) /* Next non-blank isn't letter */ + goto badif; /* ... is an error */ + found = (lookid(c) != NULL); /* Look for it in symbol table */ + } + if (found == (hash == L_ifdef)) + { + compiling = TRUE; + *ifptr |= TRUE_SEEN; + } + else + { + compiling = FALSE; + } + return; + + badif: cerror("#if, #ifdef, or #ifndef without an argument", NULLST); + skipnl(); /* Prevent an extra */ + unget(); /* Error message */ + return; } -FILE_LOCAL -void doinclude() /* * Process the #include control line. * There are three variations: @@ -347,47 +363,46 @@ void doinclude() * Note: the November 12 draft forbids '>' in the #include <file> format. * This restriction is unnecessary and not implemented. */ +FILE_LOCAL void doinclude() { - int c; - int delim; - - delim = macroid(skipws()); - if (delim != '<' && delim != '"') - goto incerr; - if (delim == '<') - delim = '>'; - workp = work; - instring = TRUE; /* Accept all characters */ + int c; + int delim; + + delim = macroid(skipws()); + if (delim != '<' && delim != '"') + goto incerr; + if (delim == '<') + delim = '>'; + workp = work; + instring = TRUE; /* Accept all characters */ #ifdef CONTROL_COMMENTS_NOT_ALLOWED - while ((c = get()) != '\n' && c != EOF_CHAR) - save(c); /* Put it away. */ - unget(); /* Force nl after includee */ - /* - * The draft is unclear if the following should be done. - */ - while (--workp >= work && *workp == ' ') - ; /* Trim blanks from filename */ - if (*workp != delim) - goto incerr; + while ((c = get()) != '\n' && c != EOF_CHAR) + save(c); /* Put it away. */ + unget(); /* Force nl after includee */ + /* + * The draft is unclear if the following should be done. + */ + while (--workp >= work && *workp == ' ') + ; /* Trim blanks from filename */ + if (*workp != delim) + goto incerr; #else - while ((c = get()) != delim && c != EOF_CHAR) - save(c); + while ((c = get()) != delim && c != EOF_CHAR) + save(c); #endif - *workp = EOS; /* Terminate filename */ - instring = FALSE; - if (openinclude(work, (delim == '"'))) - return; - /* - * No sense continuing if #include file isn't there. - */ - cfatal("Cannot open include file \"%s\"", work); - -incerr: cerror("#include syntax error", NULLST); + *workp = EOS; /* Terminate filename */ + instring = FALSE; + if (openinclude(work, (delim == '"'))) return; + /* + * No sense continuing if #include file isn't there. + */ + cfatal("Cannot open include file \"%s\"", work); + + incerr: cerror("#include syntax error", NULLST); + return; } -FILE_LOCAL int -openinclude(char* filename, int searchlocal) /* * Actually open an include file. This routine is only called from * doinclude() above, but was written as a separate subroutine for @@ -396,102 +411,112 @@ openinclude(char* filename, int searchlocal) * active files. Returns TRUE if the file was opened, FALSE * if openinclude() fails. No error message is printed. */ +FILE_LOCAL int openinclude(char* filename, int searchlocal) { - char **incptr; - char tmpname[NFWORK]; /* Filename work area */ + char** incptr; + char tmpname[NFWORK]; /* Filename work area */ - if (searchlocal) { - /* - * Look in local directory first - */ + if (searchlocal) + { + /* + * Look in local directory first + */ #if HOST == SYS_UNIX - /* - * Try to open filename relative to the directory of the current - * source file (as opposed to the current directory). (ARF, SCK). - */ - if (filename[0] != '/' - && hasdirectory(infile->filename, tmpname)) - strcat(tmpname, filename); - else { - strcpy(tmpname, filename); - } -#else - if (!hasdirectory(filename, tmpname) - && hasdirectory(infile->filename, tmpname)) - strcat(tmpname, filename); - else { - strcpy(tmpname, filename); - } -#endif - if (openfile(tmpname)) - return (TRUE); - } /* - * Look in any directories specified by -I command line - * arguments, then in the builtin search list. + * Try to open filename relative to the directory of the current + * source file (as opposed to the current directory). (ARF, SCK). */ - for (incptr = incdir; incptr < incend; incptr++) { - if (strlen(*incptr) + strlen(filename) >= (NFWORK - 1)) - cfatal("Filename work buffer overflow", NULLST); - else { + if (filename[0] != '/' && + hasdirectory(infile->filename, tmpname)) + { + strcat(tmpname, filename); + } + else + { + strcpy(tmpname, filename); + } +#else + if (!hasdirectory(filename, tmpname) && + hasdirectory(infile->filename, tmpname)) + { + strcat(tmpname, filename); + } + else + { + strcpy(tmpname, filename); + } +#endif + if (openfile(tmpname)) + return (TRUE); + } + /* + * Look in any directories specified by -I command line + * arguments, then in the builtin search list. + */ + for (incptr = incdir; incptr < incend; incptr++) + { + if (strlen(*incptr) + strlen(filename) >= (NFWORK - 1)) + cfatal("Filename work buffer overflow", NULLST); + else + { #if HOST == SYS_UNIX - if (filename[0] == '/') - strcpy(tmpname, filename); - else { - sprintf(tmpname, "%s/%s", *incptr, filename); - } + if (filename[0] == '/') + strcpy(tmpname, filename); + else + sprintf(tmpname, "%s/%s", *incptr, filename); + #elif HOST == SYS_UNKNOWN - if (filename[0] == '\\') - strcpy(tmpname, filename); - else { - sprintf(tmpname, "%s\\%s", *incptr, filename); - } + if (filename[0] == '\\') + strcpy(tmpname, filename); + else + sprintf(tmpname, "%s\\%s", *incptr, filename); #else - if (!hasdirectory(filename, tmpname)) - sprintf(tmpname, "%s%s", *incptr, filename); + if (!hasdirectory(filename, tmpname)) + sprintf(tmpname, "%s%s", *incptr, filename); #endif - if (openfile(tmpname)) - return (TRUE); - } + if (openfile(tmpname)) + return (TRUE); } - return (FALSE); + } + return (FALSE); } -FILE_LOCAL int -hasdirectory(char* source, char* result) /* * If a device or directory is found in the source filename string, the * node/device/directory part of the string is copied to result and * hasdirectory returns TRUE. Else, nothing is copied and it returns FALSE. */ +FILE_LOCAL int hasdirectory(char* source, char* result) { #if HOST == SYS_UNIX - char *tp; + char* tp; - if ((tp = strrchr(source, '/')) == NULL) - return (FALSE); - else { - strncpy(result, source, tp - source + 1); - result[tp - source + 1] = EOS; - return (TRUE); - } + if ((tp = strrchr(source, '/')) == NULL) + return (FALSE); + else + { + strncpy(result, source, tp - source + 1); + result[tp - source + 1] = EOS; + return (TRUE); + } #else - /* - * Random DEC operating system (RSTS/E) - */ - char *tp; - - if ((tp = strrchr(source, ']')) == NULL - && (tp = strrchr(source, ':')) == NULL) - return (FALSE); - else { - strncpy(result, source, tp - source + 1); - result[tp - source + 1] = EOS; - return (TRUE); - } + /* + * Random DEC operating system (RSTS/E) + */ + char* tp; + + if ((tp = strrchr(source, ']')) == NULL && + (tp = strrchr(source, ':')) == NULL) + { + return (FALSE); + } + else + { + strncpy(result, source, tp - source + 1); + result[tp - source + 1] = EOS; + return (TRUE); + } #endif } - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/rsc/source/rscpp/cpp3.c b/rsc/source/rscpp/cpp3.c index 124215d..f663a9f 100644 --- a/rsc/source/rscpp/cpp3.c +++ b/rsc/source/rscpp/cpp3.c @@ -37,31 +37,30 @@ void InitCpp3() } -int -openfile(char* filename) /* * Open a file, add it to the linked list of open files. * This is called only from openfile() above. */ +int openfile(char* filename) { - FILE *fp; + FILE* fp; - if ((fp = fopen(filename, "r")) == NULL) { + if ((fp = fopen(filename, "r")) == NULL) + { #if OSL_DEBUG_LEVEL > 1 - if ( debug || !bDumpDefs ) - perror(filename); + if ( debug || !bDumpDefs ) + perror(filename); #endif - return (FALSE); - } + return (FALSE); + } #if OSL_DEBUG_LEVEL > 1 - if (debug) - fprintf(stderr, "Reading from \"%s\"\n", filename); + if (debug) + fprintf(stderr, "Reading from \"%s\"\n", filename); #endif - addfile(fp, filename); - return (TRUE); + addfile(fp, filename); + return (TRUE); } -void addfile(FILE* fp, char* filename) /* * Initialize tables for this open file. This is called from openfile() * above (for #include files), and from the entry to cpp to open the main @@ -69,31 +68,33 @@ void addfile(FILE* fp, char* filename) * structure which is used to read characters. (getfile() is also called * to setup a macro replacement.) */ +void addfile(FILE* fp, char* filename) { - FILEINFO *file; - file = getfile(NBUFF, filename); - file->fp = fp; /* Better remember FILE * */ - file->buffer[0] = EOS; /* Initialize for first read */ - line = 1; /* Working on line 1 now */ - wrongline = TRUE; /* Force out initial #line */ + FILEINFO* file; + + file = getfile(NBUFF, filename); + file->fp = fp; /* Better remember FILE * */ + file->buffer[0] = EOS; /* Initialize for first read */ + line = 1; /* Working on line 1 now */ + wrongline = TRUE; /* Force out initial #line */ } -void setincdirs() /* * Append system-specific directories to the include directory list. * Called only when cpp is started. */ +void setincdirs() { #ifdef CPP_INCLUDE - *incend++ = CPP_INCLUDE; + *incend++ = CPP_INCLUDE; #define IS_INCLUDE 1 #else #define IS_INCLUDE 0 #endif #if HOST == SYS_UNIX - *incend++ = "/usr/include"; + *incend++ = "/usr/include"; #define MAXINCLUDE (NINCLUDE - 1 - IS_INCLUDE) #endif @@ -112,17 +113,16 @@ void setincdirs() */ #if !defined( WNT ) && ! defined UNX - extern char *getenv( char *pStr ); /* BP */ + extern char* getenv( char *pStr ); /* BP */ #endif - char *pIncGetEnv = NULL; /* Pointer auf INCLUDE */ + char* pIncGetEnv = NULL; /* Pointer auf INCLUDE */ - if ( ( pIncGetEnv = getenv("INCLUDE") ) != NULL ) - AddInclude( pIncGetEnv ); + if ( ( pIncGetEnv = getenv("INCLUDE") ) != NULL ) + AddInclude( pIncGetEnv ); #define MAXINCLUDE (NINCLUDE - 3 - IS_INCLUDE) #endif - } /* Kontext: Erweiterung des INCLUDE-Services @@ -135,8 +135,8 @@ void setincdirs() int AddInclude( char* pIncStr ) { - char *pIncEnv = NULL; /* Kopie des INCLUDE */ - char *pIncPos; /* wandert zum naechsten */ + char* pIncEnv = NULL; /* Kopie des INCLUDE */ + char* pIncPos; /* wandert zum naechsten */ pIncEnv = savestring( pIncStr ); pIncPos = strtok( pIncEnv, ";" ); @@ -151,125 +151,131 @@ int AddInclude( char* pIncStr ) return( 1 ); } -int -dooptions(int argc, char** argv) /* * dooptions is called to process command line arguments (-Detc). * It is called only at cpp startup. */ +int dooptions(int argc, char** argv) { - char *ap; - DEFBUF *dp; - int c; - int i, j; - char *arg; - SIZES *sizp; /* For -S */ - int size; /* For -S */ - int isdatum; /* FALSE for -S* */ - int endtest; /* For -S */ - - for (i = j = 1; i < argc; i++) { - arg = ap = argv[i]; - - if (*ap++ != '-' || *ap == EOS) + char* ap; + DEFBUF* dp; + int c; + int i, j; + char* arg; + SIZES* sizp; /* For -S */ + int size; /* For -S */ + int isdatum; /* FALSE for -S* */ + int endtest; /* For -S */ + + for (i = j = 1; i < argc; i++) + { + arg = ap = argv[i]; + + if (*ap++ != '-' || *ap == EOS) + { + argv[j++] = argv[i]; + } + else + { + c = *ap++; /* Option byte */ + if (islower(c)) /* Normalize case */ + c = toupper(c); + switch (c) /* Command character */ { - argv[j++] = argv[i]; - } - else { - c = *ap++; /* Option byte */ - if (islower(c)) /* Normalize case */ - c = toupper(c); - switch (c) { /* Command character */ - case 'C': /* Keep comments */ - cflag = TRUE; - keepcomments = TRUE; - break; - - case 'D': /* Define symbol */ - /* - * If the option is just "-Dfoo", make it -Dfoo=1 - */ - while (*ap != EOS && *ap != '=') + case 'C': /* Keep comments */ + cflag = TRUE; + keepcomments = TRUE; + break; + + case 'D': /* Define symbol */ + /* + * If the option is just "-Dfoo", make it -Dfoo=1 + */ + while (*ap != EOS && *ap != '=') + ap++; + if (*ap == EOS) + ap = "1"; + else + *ap++ = EOS; + /* + * Now, save the word and its definition. + */ + dp = defendel(argv[i] + 2, FALSE); + dp->repl = savestring(ap); + dp->nargs = DEF_NOARGS; + break; + + case 'E': /* Ignore non-fatal */ + eflag = TRUE; /* errors. */ + break; + + case 'I': /* Include directory */ + AddInclude( ap ); /* BP, 11.09.91 */ + break; + + case 'N': /* No predefineds */ + nflag++; /* Repeat to undefine */ + break; /* __LINE__, etc. */ + + case 'S': + sizp = size_table; + if (0 != (isdatum = (*ap != '*'))) /* If it's just -S, */ + endtest = T_FPTR; /* Stop here */ + else /* But if it's -S* */ + { + ap++; /* Step over '*' */ + endtest = 0; /* Stop at end marker */ + } + while (sizp->bits != endtest && *ap != EOS) + { + if (!isdigit(*ap)) /* Skip to next digit */ + { ap++; - if (*ap == EOS) - ap = "1"; - else - *ap++ = EOS; - /* - * Now, save the word and its definition. - */ - dp = defendel(argv[i] + 2, FALSE); - dp->repl = savestring(ap); - dp->nargs = DEF_NOARGS; - break; - - case 'E': /* Ignore non-fatal */ - eflag = TRUE; /* errors. */ - break; - - case 'I': /* Include directory */ - AddInclude( ap ); /* BP, 11.09.91 */ - break; - - case 'N': /* No predefineds */ - nflag++; /* Repeat to undefine */ - break; /* __LINE__, etc. */ - - case 'S': - sizp = size_table; - if (0 != (isdatum = (*ap != '*'))) /* If it's just -S, */ - endtest = T_FPTR; /* Stop here */ - else { /* But if it's -S* */ - ap++; /* Step over '*' */ - endtest = 0; /* Stop at end marker */ + continue; } - while (sizp->bits != endtest && *ap != EOS) { - if (!isdigit(*ap)) { /* Skip to next digit */ - ap++; - continue; - } - size = 0; /* Compile the value */ - while (isdigit(*ap)) { - size *= 10; - size += (*ap++ - '0'); - } - if (isdatum) - sizp->size = size; /* Datum size */ - else - sizp->psize = size; /* Pointer size */ - sizp++; + size = 0; /* Compile the value */ + while (isdigit(*ap)) + { + size *= 10; + size += (*ap++ - '0'); } - if (sizp->bits != endtest) - cwarn("-S, too few values specified in %s", argv[i]); - else if (*ap != EOS) - cwarn("-S, too many values, \"%s\" unused", ap); - break; + if (isdatum) + sizp->size = size; /* Datum size */ + else + sizp->psize = size; /* Pointer size */ + sizp++; + } + if (sizp->bits != endtest) + cwarn("-S, too few values specified in %s", argv[i]); + else if (*ap != EOS) + cwarn("-S, too many values, \"%s\" unused", ap); + break; - case 'U': /* Undefine symbol */ - if (defendel(ap, TRUE) == NULL) - cwarn("\"%s\" wasn't defined", ap); - break; + case 'U': /* Undefine symbol */ + if (defendel(ap, TRUE) == NULL) + cwarn("\"%s\" wasn't defined", ap); + break; #if OSL_DEBUG_LEVEL > 1 - case 'X': /* Debug */ - debug = (isdigit(*ap)) ? atoi(ap) : 1; + case 'X': /* Debug */ + debug = (isdigit(*ap)) ? atoi(ap) : 1; #if (HOST == SYS_UNIX) - signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */ + signal(SIGINT, (void (*)(int)) abort); /* Trap "interrupt" */ #endif - fprintf(stderr, "Debug set to %d\n", debug); - break; + fprintf(stderr, "Debug set to %d\n", debug); + break; #endif #if OSL_DEBUG_LEVEL > 1 - case 'P': /* #define's dump */ - bDumpDefs = 1; - fprintf(stderr, "Dump #define's is on\n"); - break; + case 'P': /* #define's dump */ + bDumpDefs = 1; + fprintf(stderr, "Dump #define's is on\n"); + break; #endif - default: /* What is this one? */ - cwarn("Unknown option \"%s\"", arg); - fprintf(stderr, "The following options are valid:\n\ + default: /* What is this one? */ + cwarn("Unknown option \"%s\"", arg); + fprintf(stderr, "The following options are valid:\n\ -C\t\t\tWrite source file comments to output\n\ -Dsymbol=value\tDefine a symbol with the given (optional) value\n\ -Idirectory\t\tAdd a directory to the #include search list\n\ @@ -277,107 +283,110 @@ dooptions(int argc, char** argv) -Stext\t\tSpecify sizes for #if sizeof\n\ -Usymbol\t\tUndefine symbol\n"); #if OSL_DEBUG_LEVEL > 1 - fprintf(stderr, " -Xvalue\t\tSet internal debug flag\n"); - fprintf(stderr, " -P\t\t\tdump #define's\n"); + fprintf(stderr, " -Xvalue\t\tSet internal debug flag\n"); + fprintf(stderr, " -P\t\t\tdump #define's\n"); #endif - break; - } /* Switch on all options */ - } /* If it's a -option */ - } /* For all arguments */ + break; + } /* Switch on all options */ + } /* If it's a -option */ + } /* For all arguments */ #if OSL_DEBUG_LEVEL > 1 - if ( (bDumpDefs ? j > 4 : j > 3) ) { + if ( (bDumpDefs ? j > 4 : j > 3) ) #else - if (j > 3) { + if (j > 3) #endif - cerror( - "Too many file arguments. Usage: cpp [input [output]]", + { + cerror( "Too many file arguments. Usage: cpp [input [output]]", NULLST); - } - return (j); /* Return new argc */ + } + return (j); /* Return new argc */ } -int -readoptions(char* filename, char*** pfargv) +int readoptions(char* filename, char*** pfargv) { - FILE *fp; - int c; - int bInQuotes = 0; - char optbuff[1024], *poptbuff; - int fargc=0, back; - char *fargv[PARALIMIT], **pfa; - - pfa=*pfargv=malloc(sizeof(fargv)); - - poptbuff=&optbuff[0]; - filename++; - if ((fp = fopen(filename, "r")) == NULL) { + FILE* fp; + int c; + int bInQuotes = 0; + char optbuff[1024]; + char* poptbuff; + int fargc=0; + int back; + char* fargv[PARALIMIT]; + char** pfa; + + pfa = *pfargv = malloc(sizeof(fargv)); + + poptbuff = &optbuff[0]; + filename++; + if ((fp = fopen(filename, "r")) == NULL) + { #if OSL_DEBUG_LEVEL > 1 - if ( debug || !bDumpDefs ) - perror(filename); + if ( debug || !bDumpDefs ) + perror(filename); #endif - return (FALSE); + return (FALSE); + } + do + { + /* + * #i27914# double ticks '"' now have a duplicate function: + * 1. they define a string ( e.g. -DFOO="baz" ) + * 2. a string can contain spaces, so -DFOO="baz zum" defines one + * argument no two ! + */ + c = fgetc(fp); + if ( c != ' ' && c != CR && c != NL && c != HT && c != EOF) + { + *poptbuff++ = (char)c; + if( c == '"' ) + bInQuotes = ~bInQuotes; } - do + else { - /* - * #i27914# double ticks '"' now have a duplicate function: - * 1. they define a string ( e.g. -DFOO="baz" ) - * 2. a string can contain spaces, so -DFOO="baz zum" defines one - * argument no two ! - */ - c=fgetc(fp); - if ( c != ' ' && c != CR && c != NL && c != HT && c != EOF) - { - *poptbuff++=(char)c; - if( c == '"' ) - bInQuotes = ~bInQuotes; - } + if( c != EOF && bInQuotes ) + *poptbuff++ = (char)c; else { - if( c != EOF && bInQuotes ) - *poptbuff++=(char)c; - else + *poptbuff = EOS; + if (strlen(optbuff)>0) { - *poptbuff=EOS; - if (strlen(optbuff)>0) - { - pfa[fargc+1]=strdup(optbuff); - fargc++; - pfa[fargc+1]=0; - poptbuff=&optbuff[0]; - } + pfa[fargc + 1] = strdup(optbuff); + fargc++; + pfa[fargc + 1] = 0; + poptbuff = &optbuff[0]; } } } - while ( c != EOF ); + } + while ( c != EOF ); - fclose(fp); - back=dooptions(fargc+1,pfa); + fclose(fp); + back=dooptions(fargc+1,pfa); - return (back); + return (back); } #if HOST != SYS_UNIX -FILE_LOCAL void -zap_uc(char* ap) + /* * Dec operating systems mangle upper-lower case in command lines. * This routine forces the -D and -U arguments to uppercase. * It is called only on cpp startup by dooptions(). */ +FILE_LOCAL void zap_uc(char* ap) { - while (*ap != EOS) { - /* - * Don't use islower() here so it works with Multinational - */ - if (*ap >= 'a' && *ap <= 'z') - *ap = (char)toupper(*ap); - ap++; - } + while (*ap != EOS) + { + /* + * Don't use islower() here so it works with Multinational + */ + if (*ap >= 'a' && *ap <= 'z') + *ap = (char)toupper(*ap); + ap++; + } } #endif -void initdefines() /* * Initialize the built-in #define's. There are two flavors: * #define decus 1 (static definitions) @@ -387,51 +396,57 @@ void initdefines() * Note: the built-in static definitions are suppressed by the -N option. * __LINE__, __FILE__, and __DATE__ are always present. */ +void initdefines() { - char **pp; - char *tp; - DEFBUF *dp; - int i; - time_t tvec; - - /* - * Predefine the built-in symbols. Allow the - * implementor to pre-define a symbol as "" to - * eliminate it. - */ - if (nflag == 0) { - for (pp = preset; *pp != NULL; pp++) { - if (*pp[0] != EOS) { - dp = defendel(*pp, FALSE); - dp->repl = savestring("1"); - dp->nargs = DEF_NOARGS; - } + char** pp; + char* tp; + DEFBUF* dp; + int i; + time_t tvec; + + /* + * Predefine the built-in symbols. Allow the + * implementor to pre-define a symbol as "" to + * eliminate it. + */ + if (nflag == 0) + { + for (pp = preset; *pp != NULL; pp++) + { + if (*pp[0] != EOS) + { + dp = defendel(*pp, FALSE); + dp->repl = savestring("1"); + dp->nargs = DEF_NOARGS; } } + } + /* + * The magic pre-defines (__FILE__ and __LINE__ are + * initialized with negative argument counts. expand() + * notices this and calls the appropriate routine. + * DEF_NOARGS is one greater than the first "magic" definition. + */ + if (nflag < 2) + { + for (pp = magic, i = DEF_NOARGS; *pp != NULL; pp++) + { + dp = defendel(*pp, FALSE); + dp->nargs = --i; + } +#if OK_DATE /* - * The magic pre-defines (__FILE__ and __LINE__ are - * initialized with negative argument counts. expand() - * notices this and calls the appropriate routine. - * DEF_NOARGS is one greater than the first "magic" definition. + * Define __DATE__ as today's date. */ - if (nflag < 2) { - for (pp = magic, i = DEF_NOARGS; *pp != NULL; pp++) { - dp = defendel(*pp, FALSE); - dp->nargs = --i; - } -#if OK_DATE - /* - * Define __DATE__ as today's date. - */ - dp = defendel("__DATE__", FALSE); - dp->repl = tp = getmem(27); - dp->nargs = DEF_NOARGS; - time( &tvec); - *tp++ = '"'; - strcpy(tp, ctime(&tvec)); - tp[24] = '"'; /* Overwrite newline */ + dp = defendel("__DATE__", FALSE); + dp->repl = tp = getmem(27); + dp->nargs = DEF_NOARGS; + time( &tvec); + *tp++ = '"'; + strcpy(tp, ctime(&tvec)); + tp[24] = '"'; /* Overwrite newline */ #endif - } + } } diff --git a/rsc/source/rscpp/cpp4.c b/rsc/source/rscpp/cpp4.c index 0925caf..6240c1b 100644 --- a/rsc/source/rscpp/cpp4.c +++ b/rsc/source/rscpp/cpp4.c @@ -26,10 +26,10 @@ * parm[], parmp, and parlist[] are used to store #define() argument * lists. nargs contains the actual number of parameters stored. */ -static char parm[NPARMWORK + 1]; /* define param work buffer */ -static char *parmp; /* Free space in parm */ -static char *parlist[LASTPARM]; /* -> start of each parameter */ -static int nargs; /* Parameters for this macro */ +static char parm[NPARMWORK + 1]; /* define param work buffer */ +static char* parmp; /* Free space in parm */ +static char* parlist[LASTPARM]; /* -> start of each parameter */ +static int nargs; /* Parameters for this macro */ void InitCpp4() { @@ -43,7 +43,6 @@ void InitCpp4() } -void dodefine() /* * Called from control when a #define is scanned. This module * parses formal parameters and the replacement string. When @@ -81,142 +80,155 @@ void dodefine() * charput puts a single character in the macro work area (parm[]) * in a manner analogous to textput(). */ +void dodefine() { - int c; - DEFBUF *dp; /* -> new definition */ - int isredefine; /* TRUE if redefined */ - char *old = 0; /* Remember redefined */ - - if (type[(c = skipws())] != LET) - goto bad_define; - isredefine = FALSE; /* Set if redefining */ - if ((dp = lookid(c)) == NULL) /* If not known now */ - dp = defendel(token, FALSE); /* Save the name */ - else { /* It's known: */ - isredefine = TRUE; /* Remember this fact */ - old = dp->repl; /* Remember replacement */ - dp->repl = NULL; /* No replacement now */ - } - parlist[0] = parmp = parm; /* Setup parm buffer */ - if ((c = get()) == '(') { /* With arguments? */ - nargs = 0; /* Init formals counter */ - do { /* Collect formal parms */ - if (nargs >= LASTPARM) - cfatal("Too many arguments for macro", NULLST); - else if ((c = skipws()) == ')') - break; /* Got them all */ - else if (type[c] != LET) /* Bad formal syntax */ - goto bad_define; - scanid(c); /* Get the formal param */ - parlist[nargs++] = parmp; /* Save its start */ - textput(token); /* Save text in parm[] */ - } while ((c = skipws()) == ','); /* Get another argument */ - if (c != ')') /* Must end at ) */ + int c; + DEFBUF* dp; /* -> new definition */ + int isredefine; /* TRUE if redefined */ + char* old = 0; /* Remember redefined */ + + if (type[(c = skipws())] != LET) + goto bad_define; + isredefine = FALSE; /* Set if redefining */ + if ((dp = lookid(c)) == NULL) /* If not known now */ + dp = defendel(token, FALSE); /* Save the name */ + else /* It's known: */ + { + isredefine = TRUE; /* Remember this fact */ + old = dp->repl; /* Remember replacement */ + dp->repl = NULL; /* No replacement now */ + } + parlist[0] = parmp = parm; /* Setup parm buffer */ + if ((c = get()) == '(') /* With arguments? */ + { + nargs = 0; /* Init formals counter */ + do /* Collect formal parms */ + { + if (nargs >= LASTPARM) + cfatal("Too many arguments for macro", NULLST); + else if ((c = skipws()) == ')') + break; /* Got them all */ + else if (type[c] != LET) /* Bad formal syntax */ goto bad_define; - c = ' '; /* Will skip to body */ - } - else { - /* - * DEF_NOARGS is needed to distinguish between - * "#define foo" and "#define foo()". - */ - nargs = DEF_NOARGS; /* No () parameters */ + scanid(c); /* Get the formal param */ + parlist[nargs++] = parmp; /* Save its start */ + textput(token); /* Save text in parm[] */ } - if (type[c] == SPA) /* At whitespace? */ - c = skipws(); /* Not any more. */ - workp = work; /* Replacement put here */ - inmacro = TRUE; /* Keep \<newline> now */ - while (c != EOF_CHAR && c != '\n') { /* Compile macro body */ - if (c == '#') { /* Token concatenation? */ - while (workp > work && type[(int)workp[-1]] == SPA) - --workp; /* Erase leading spaces */ - save(TOK_SEP); /* Stuff a delimiter */ - c = skipws(); /* Eat whitespace */ - if (type[c] == LET) /* Another token here? */ - ; /* Stuff it normally */ - else if (type[c] == DIG) { /* Digit string after? */ - while (type[c] == DIG) { /* Stuff the digits */ - save(c); - c = get(); - } - save(TOK_SEP); /* Delimit 2nd token */ - } - else { - ciwarn("Strange character after # (%d.)", c); + while ((c = skipws()) == ','); /* Get another argument */ + if (c != ')') /* Must end at ) */ + goto bad_define; + c = ' '; /* Will skip to body */ + } + else + { + /* + * DEF_NOARGS is needed to distinguish between + * "#define foo" and "#define foo()". + */ + nargs = DEF_NOARGS; /* No () parameters */ + } + if (type[c] == SPA) /* At whitespace? */ + c = skipws(); /* Not any more. */ + workp = work; /* Replacement put here */ + inmacro = TRUE; /* Keep \<newline> now */ + while (c != EOF_CHAR && c != '\n') /* Compile macro body */ + { + if (c == '#') /* Token concatenation? */ + { + while (workp > work && type[(int)workp[-1]] == SPA) + --workp; /* Erase leading spaces */ + save(TOK_SEP); /* Stuff a delimiter */ + c = skipws(); /* Eat whitespace */ + if (type[c] == LET) /* Another token here? */ + ; /* Stuff it normally */ + else if (type[c] == DIG) /* Digit string after? */ + { + while (type[c] == DIG) /* Stuff the digits */ + { + save(c); + c = get(); } - continue; + save(TOK_SEP); /* Delimit 2nd token */ } - switch (type[c]) { - case LET: - checkparm(c, dp); /* Might be a formal */ - break; + else + { + ciwarn("Strange character after # (%d.)", c); + } + continue; + } + switch (type[c]) + { + case LET: + checkparm(c, dp); /* Might be a formal */ + break; - case DIG: /* Number in mac. body */ - case DOT: /* Maybe a float number */ - scannumber(c, save); /* Scan it off */ - break; + case DIG: /* Number in mac. body */ + case DOT: /* Maybe a float number */ + scannumber(c, save); /* Scan it off */ + break; - case QUO: /* String in mac. body */ - stparmscan(c); - break; + case QUO: /* String in mac. body */ + stparmscan(c); + break; - case BSH: /* Backslash */ - save('\\'); - if ((c = get()) == '\n') - wrongline = TRUE; - save(c); - break; + case BSH: /* Backslash */ + save('\\'); + if ((c = get()) == '\n') + wrongline = TRUE; + save(c); + break; - case SPA: /* Absorb whitespace */ - /* - * Note: the "end of comment" marker is passed on - * to allow comments to separate tokens. - */ - if (workp[-1] == ' ') /* Absorb multiple */ - break; /* spaces */ - else if (c == '\t') - c = ' '; /* Normalize tabs */ - /* Fall through to store character */ - default: /* Other character */ - save(c); - break; - } - c = get(); + case SPA: /* Absorb whitespace */ + /* + * Note: the "end of comment" marker is passed on + * to allow comments to separate tokens. + */ + if (workp[-1] == ' ') /* Absorb multiple */ + break; /* spaces */ + else if (c == '\t') + c = ' '; /* Normalize tabs */ + /* Fall through to store character */ + default: /* Other character */ + save(c); + break; } - inmacro = FALSE; /* Stop newline hack */ - unget(); /* For control check */ - if (workp > work && workp[-1] == ' ') /* Drop trailing blank */ - workp--; - *workp = EOS; /* Terminate work */ - dp->repl = savestring(work); /* Save the string */ - dp->nargs = nargs; /* Save arg count */ + c = get(); + } + inmacro = FALSE; /* Stop newline hack */ + unget(); /* For control check */ + if (workp > work && workp[-1] == ' ') /* Drop trailing blank */ + workp--; + *workp = EOS; /* Terminate work */ + dp->repl = savestring(work); /* Save the string */ + dp->nargs = nargs; /* Save arg count */ #if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpadef("macro definition", dp); - else if (bDumpDefs) - dumpadef(NULL, dp); + if (debug) + dumpadef("macro definition", dp); + else if (bDumpDefs) + dumpadef(NULL, dp); #endif - if (isredefine) { /* Error if redefined */ - if ((old != NULL && dp->repl != NULL && !streq(old, dp->repl)) - || (old == NULL && dp->repl != NULL) - || (old != NULL && dp->repl == NULL)) { + if (isredefine) /* Error if redefined */ + { + if ((old != NULL && dp->repl != NULL && !streq(old, dp->repl)) || + (old == NULL && dp->repl != NULL) || + (old != NULL && dp->repl == NULL)) + { #ifdef STRICT_UNDEF - cerror("Redefining defined variable \"%s\"", dp->name); + cerror("Redefining defined variable \"%s\"", dp->name); #else - cwarn("Redefining defined variable \"%s\"", dp->name); + cwarn("Redefining defined variable \"%s\"", dp->name); #endif - } - if (old != NULL) /* We don't need the */ - free(old); /* old definition now. */ } - return; - -bad_define: - cerror("#define syntax error", NULLST); - inmacro = FALSE; /* Stop <newline> hack */ + if (old != NULL) /* We don't need the */ + free(old); /* old definition now. */ + } + return; + + bad_define: + cerror("#define syntax error", NULLST); + inmacro = FALSE; /* Stop <newline> hack */ } -void checkparm(int c, DEFBUF* dp) /* * Replace this param if it's defined. Note that the macro name is a * possible replacement token. We stuff DEF_MAGIC in front of the token @@ -224,114 +236,122 @@ void checkparm(int c, DEFBUF* dp) * the output routine. This prevents the macro expander from * looping if someone writes "#define foo foo". */ +void checkparm(int c, DEFBUF* dp) { - int i; - char *cp; + int i; + char* cp; - scanid(c); /* Get parm to token[] */ - for (i = 0; i < nargs; i++) { /* For each argument */ - if (streq(parlist[i], token)) { /* If it's known */ + scanid(c); /* Get parm to token[] */ + for (i = 0; i < nargs; i++) /* For each argument */ + { + if (streq(parlist[i], token)) /* If it's known */ + { #ifdef SOLAR - save(DEL); + save(DEL); #endif - save(i + MAC_PARM); /* Save a magic cookie */ - return; /* And exit the search */ - } + save(i + MAC_PARM); /* Save a magic cookie */ + return; /* And exit the search */ } - if (streq(dp->name, token)) /* Macro name in body? */ - save(DEF_MAGIC); /* Save magic marker */ - for (cp = token; *cp != EOS;) /* And save */ - save(*cp++); /* The token itself */ + } + if (streq(dp->name, token)) /* Macro name in body? */ + save(DEF_MAGIC); /* Save magic marker */ + for (cp = token; *cp != EOS;) /* And save */ + save(*cp++); /* The token itself */ } -void stparmscan(int delim) /* * Normal string parameter scan. */ +void stparmscan(int delim) { - char *wp; - int i; - - wp = workp; /* Here's where it starts */ - if (!scanstring(delim, save)) - return; /* Exit on scanstring error */ - workp[-1] = EOS; /* Erase trailing quote */ - wp++; /* -> first string content byte */ - for (i = 0; i < nargs; i++) { - if (streq(parlist[i], wp)) { + char* wp; + int i; + + wp = workp; /* Here's where it starts */ + if (!scanstring(delim, save)) + return; /* Exit on scanstring error */ + workp[-1] = EOS; /* Erase trailing quote */ + wp++; /* -> first string content byte */ + for (i = 0; i < nargs; i++) + { + if (streq(parlist[i], wp)) + { #ifdef SOLAR - *wp++ = DEL; - *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ - *wp++ = (char)(i + MAC_PARM); /* Make a formal marker */ - *wp = wp[-4]; /* Add on closing quote */ - workp = wp + 1; /* Reset string end */ + *wp++ = DEL; + *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ + *wp++ = (char)(i + MAC_PARM); /* Make a formal marker */ + *wp = wp[-4]; /* Add on closing quote */ + workp = wp + 1; /* Reset string end */ #else - *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ - *wp++ = (i + MAC_PARM); /* Make a formal marker */ - *wp = wp[-3]; /* Add on closing quote */ - workp = wp + 1; /* Reset string end */ + *wp++ = MAC_PARM + PAR_MAC; /* Stuff a magic marker */ + *wp++ = (i + MAC_PARM); /* Make a formal marker */ + *wp = wp[-3]; /* Add on closing quote */ + workp = wp + 1; /* Reset string end */ #endif - return; - } + return; } - workp[-1] = wp[-1]; /* Nope, reset end quote. */ + } + workp[-1] = wp[-1]; /* Nope, reset end quote. */ } -void doundef() /* * Remove the symbol from the defined list. * Called from the #control processor. */ +void doundef() { - int c; - - if (type[(c = skipws())] != LET) - cerror("Illegal #undef argument", NULLST); - else { - scanid(c); /* Get name to token[] */ - if (defendel(token, TRUE) == NULL) { + int c; + + if (type[(c = skipws())] != LET) + cerror("Illegal #undef argument", NULLST); + else + { + scanid(c); /* Get name to token[] */ + if (defendel(token, TRUE) == NULL) + { #ifdef STRICT_UNDEF - cwarn("Symbol \"%s\" not defined in #undef", token); + cwarn("Symbol \"%s\" not defined in #undef", token); #endif - } } + } } -void textput(char* text) /* * Put the string in the parm[] buffer. */ +void textput(char* text) { - int size; - - size = strlen(text) + 1; - if ((parmp + size) >= &parm[NPARMWORK]) - cfatal("Macro work area overflow", NULLST); - else { - strcpy(parmp, text); - parmp += size; - } + int size; + + size = strlen(text) + 1; + if ((parmp + size) >= &parm[NPARMWORK]) + cfatal("Macro work area overflow", NULLST); + else + { + strcpy(parmp, text); + parmp += size; + } } -void charput(int c) /* * Put the byte in the parm[] buffer. */ +void charput(int c) { - if (parmp >= &parm[NPARMWORK]) - cfatal("Macro work area overflow", NULLST); - else { - *parmp++ = (char)c; - } + if (parmp >= &parm[NPARMWORK]) + cfatal("Macro work area overflow", NULLST); + else + { + *parmp++ = (char)c; + } } /* * M a c r o E x p a n s i o n */ -static DEFBUF *macro; /* Catches start of infinite macro */ +static DEFBUF* macro; /* Catches start of infinite macro */ -void expand(DEFBUF* tokenp) /* * Expand a macro. Called from the cpp mainline routine (via subroutine * macroid()) when a token is found in the symbol table. It calls @@ -341,176 +361,197 @@ void expand(DEFBUF* tokenp) * "pushed back" onto the input stream. (When the get() routine runs * off the end of the macro line, it will dismiss the macro itself.) */ +void expand(DEFBUF* tokenp) { - int c; - FILEINFO *file; + int c; + FILEINFO* file; #if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpadef("expand entry", tokenp); + if (debug) + dumpadef("expand entry", tokenp); #endif - /* - * If no macro is pending, save the name of this macro - * for an eventual error message. - */ - if (recursion++ == 0) - macro = tokenp; - else if (recursion == RECURSION_LIMIT) { - cerror("Recursive macro definition of \"%s\"", tokenp->name); - fprintf(stderr, "(Defined by \"%s\")\n", macro->name); - if (rec_recover) { - do { - c = get(); - } while (infile != NULL && infile->fp == NULL); - unget(); - recursion = 0; - return; + /* + * If no macro is pending, save the name of this macro + * for an eventual error message. + */ + if (recursion++ == 0) + macro = tokenp; + else if (recursion == RECURSION_LIMIT) + { + cerror("Recursive macro definition of \"%s\"", tokenp->name); + fprintf(stderr, "(Defined by \"%s\")\n", macro->name); + if (rec_recover) + { + do + { + c = get(); } + while (infile != NULL && infile->fp == NULL); + unget(); + recursion = 0; + return; } - /* - * Here's a macro to expand. - */ - nargs = 0; /* Formals counter */ - parmp = parm; /* Setup parm buffer */ - switch (tokenp->nargs) { - case (-2): /* __LINE__ */ - sprintf(work, "%d", line); - ungetstring(work); - break; - - case (-3): /* __FILE__ */ - for (file = infile; file != NULL; file = file->parent) { - if (file->fp != NULL) { - sprintf(work, "\"%s\"", (file->progname != NULL) + } + /* + * Here's a macro to expand. + */ + nargs = 0; /* Formals counter */ + parmp = parm; /* Setup parm buffer */ + switch (tokenp->nargs) + { + case (-2): /* __LINE__ */ + sprintf(work, "%d", line); + ungetstring(work); + break; + + case (-3): /* __FILE__ */ + for (file = infile; file != NULL; file = file->parent) + { + if (file->fp != NULL) + { + sprintf(work, "\"%s\"", (file->progname != NULL) ? file->progname : file->filename); - ungetstring(work); - break; - } + ungetstring(work); + break; } - break; + } + break; - default: + default: + /* + * Nothing funny about this macro. + */ + if (tokenp->nargs < 0) + cfatal("Bug: Illegal __ macro \"%s\"", tokenp->name); + while ((c = skipws()) == '\n') /* Look for (, skipping */ + wrongline = TRUE; /* spaces and newlines */ + if (c != '(') + { /* - * Nothing funny about this macro. + * If the programmer writes + * #define foo() ... + * ... + * foo [no ()] + * just write foo to the output stream. */ - if (tokenp->nargs < 0) - cfatal("Bug: Illegal __ macro \"%s\"", tokenp->name); - while ((c = skipws()) == '\n') /* Look for (, skipping */ - wrongline = TRUE; /* spaces and newlines */ - if (c != '(') { - /* - * If the programmer writes - * #define foo() ... - * ... - * foo [no ()] - * just write foo to the output stream. - */ - unget(); - cwarn("Macro \"%s\" needs arguments", tokenp->name); - fputs(tokenp->name, pCppOut ); - return; + unget(); + cwarn("Macro \"%s\" needs arguments", tokenp->name); + fputs(tokenp->name, pCppOut ); + return; + } + else if (expcollect()) /* Collect arguments */ + { + if (tokenp->nargs != nargs) /* Should be an error? */ + { + cwarn("Wrong number of macro arguments for \"%s\"", + tokenp->name); } - else if (expcollect()) { /* Collect arguments */ - if (tokenp->nargs != nargs) { /* Should be an error? */ - cwarn("Wrong number of macro arguments for \"%s\"", - tokenp->name); - } #if OSL_DEBUG_LEVEL > 1 - if (debug) - dumpparm("expand"); + if (debug) + dumpparm("expand"); #endif - } /* Collect arguments */ - case DEF_NOARGS: /* No parameters just stuffs */ - expstuff(tokenp); /* Do actual parameters */ - } /* nargs switch */ + } /* Collect arguments */ + case DEF_NOARGS: /* No parameters just stuffs */ + expstuff(tokenp); /* Do actual parameters */ + } /* nargs switch */ } -FILE_LOCAL int -expcollect() /* * Collect the actual parameters for this macro. TRUE if ok. */ +FILE_LOCAL int expcollect() { - int c; - int paren; /* For embedded ()'s */ - for (;;) { - paren = 0; /* Collect next arg. */ - while ((c = skipws()) == '\n') /* Skip over whitespace */ - wrongline = TRUE; /* and newlines. */ - if (c == ')') { /* At end of all args? */ - /* - * Note that there is a guard byte in parm[] - * so we don't have to check for overflow here. - */ - *parmp = EOS; /* Make sure terminated */ - break; /* Exit collection loop */ + int c; + int paren; /* For embedded ()'s */ + for (;;) + { + paren = 0; /* Collect next arg. */ + while ((c = skipws()) == '\n') /* Skip over whitespace */ + wrongline = TRUE; /* and newlines. */ + if (c == ')') /* At end of all args? */ + { + /* + * Note that there is a guard byte in parm[] + * so we don't have to check for overflow here. + */ + *parmp = EOS; /* Make sure terminated */ + break; /* Exit collection loop */ + } + else if (nargs >= LASTPARM) + cfatal("Too many arguments in macro expansion", NULLST); + parlist[nargs++] = parmp; /* At start of new arg */ + for (;; c = cget()) /* Collect arg's bytes */ + { + if (c == EOF_CHAR) + { + cerror("end of file within macro argument", NULLST); + return (FALSE); /* Sorry. */ } - else if (nargs >= LASTPARM) - cfatal("Too many arguments in macro expansion", NULLST); - parlist[nargs++] = parmp; /* At start of new arg */ - for (;; c = cget()) { /* Collect arg's bytes */ - if (c == EOF_CHAR) { - cerror("end of file within macro argument", NULLST); - return (FALSE); /* Sorry. */ - } - else if (c == '\\') { /* Quote next character */ - charput(c); /* Save the \ for later */ - charput(cget()); /* Save the next char. */ - continue; /* And go get another */ - } - else if (type[c] == QUO) { /* Start of string? */ - scanstring(c, charput); /* Scan it off */ - continue; /* Go get next char */ - } - else if (c == '(') /* Worry about balance */ - paren++; /* To know about commas */ - else if (c == ')') { /* Other side too */ - if (paren == 0) { /* At the end? */ - unget(); /* Look at it later */ - break; /* Exit arg getter. */ - } - paren--; /* More to come. */ + else if (c == '\\') /* Quote next character */ + { + charput(c); /* Save the \ for later */ + charput(cget()); /* Save the next char. */ + continue; /* And go get another */ + } + else if (type[c] == QUO) /* Start of string? */ + { + scanstring(c, charput); /* Scan it off */ + continue; /* Go get next char */ + } + else if (c == '(') /* Worry about balance */ + paren++; /* To know about commas */ + else if (c == ')') /* Other side too */ + { + if (paren == 0) /* At the end? */ + { + unget(); /* Look at it later */ + break; /* Exit arg getter. */ } - else if (c == ',' && paren == 0) /* Comma delimits args */ - break; - else if (c == '\n') /* Newline inside arg? */ - wrongline = TRUE; /* We'll need a #line */ - charput(c); /* Store this one */ - } /* Collect an argument */ - charput(EOS); /* Terminate argument */ + paren--; /* More to come. */ + } + else if (c == ',' && paren == 0) /* Comma delimits args */ + break; + else if (c == '\n') /* Newline inside arg? */ + wrongline = TRUE; /* We'll need a #line */ + charput(c); /* Store this one */ + } /* Collect an argument */ + charput(EOS); /* Terminate argument */ #if OSL_DEBUG_LEVEL > 1 - if (debug) + if (debug) fprintf( pCppOut, "parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]); #endif - } /* Collect all args. */ - return (TRUE); /* Normal return */ + } /* Collect all args. */ + return (TRUE); /* Normal return */ } -FILE_LOCAL -void expstuff(DEFBUF* tokenp) /* * Stuff the macro body, replacing formal parameters by actual parameters. */ +FILE_LOCAL void expstuff(DEFBUF* tokenp) { - int c; /* Current character */ - char *inp; /* -> repl string */ - char *defp; /* -> macro output buff */ - int size; /* Actual parm. size */ - char *defend; /* -> output buff end */ - int string_magic; /* String formal hack */ - FILEINFO *file; /* Funny #include */ - - file = getfile(NBUFF, tokenp->name); - inp = tokenp->repl; /* -> macro replacement */ - defp = file->buffer; /* -> output buffer */ - defend = defp + (NBUFF - 1); /* Note its end */ - if (inp != NULL) { - while ((c = (*inp++ & 0xFF)) != EOS) { + int c; /* Current character */ + char* inp; /* -> repl string */ + char* defp; /* -> macro output buff */ + int size; /* Actual parm. size */ + char* defend; /* -> output buff end */ + int string_magic; /* String formal hack */ + FILEINFO* file; /* Funny #include */ + + file = getfile(NBUFF, tokenp->name); + inp = tokenp->repl; /* -> macro replacement */ + defp = file->buffer; /* -> output buffer */ + defend = defp + (NBUFF - 1); /* Note its end */ + if (inp != NULL) + { + while ((c = (*inp++ & 0xFF)) != EOS) + { #ifdef SOLAR - if (c == DEL) { - c = (*inp++ & 0xFF); + if (c == DEL) + { + c = (*inp++ & 0xFF); #else ... etc. - the rest is truncated
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits