summaryrefslogtreecommitdiff
path: root/rsc/source
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2014-10-04 00:20:18 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2014-10-04 08:58:12 -0500
commit0091f937116550a9f5e30bf200f536701cc0b068 (patch)
treedfc9c7d5a2010325d469bf86e4a4fd174863c779 /rsc/source
parent9b401751a8a8b96cfe9f85eefce1173fe4cabe6f (diff)
cosmetic: start bringing rscpp in this century c-wise
Change-Id: I469bc4c518c3ac299a18559cdd3e1b49d34b5ace
Diffstat (limited to 'rsc/source')
-rw-r--r--rsc/source/rscpp/cpp.h167
-rw-r--r--rsc/source/rscpp/cpp2.c719
-rw-r--r--rsc/source/rscpp/cpp3.c489
-rw-r--r--rsc/source/rscpp/cpp4.c735
-rw-r--r--rsc/source/rscpp/cpp5.c562
-rw-r--r--rsc/source/rscpp/cpp6.c1416
6 files changed, 2153 insertions, 1935 deletions
diff --git a/rsc/source/rscpp/cpp.h b/rsc/source/rscpp/cpp.h
index 7f453756e61e..1a9f5c6a9841 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 71db0c359b58..4a564dad205c 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 124215dbb60a..f663a9f13ab8 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 0925cafdd45f..6240c1b99514 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
- if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC)) {
+ if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC))
+ {
#endif
string_magic = (c == (MAC_PARM + PAR_MAC));
if (string_magic)
@@ -518,28 +559,34 @@ void expstuff(DEFBUF* tokenp)
/*
* Replace formal parameter by actual parameter string.
*/
- if ((c -= MAC_PARM) < nargs) {
+ if ((c -= MAC_PARM) < nargs)
+ {
size = strlen(parlist[c]);
if ((defp + size) >= defend)
goto nospace;
/*
* Erase the extra set of quotes.
*/
- if (string_magic && defp[-1] == parlist[c][0]) {
+ if (string_magic && defp[-1] == parlist[c][0])
+ {
strcpy(defp-1, parlist[c]);
defp += (size - 2);
}
- else {
+ else
+ {
strcpy(defp, parlist[c]);
defp += size;
}
}
}
- else if (defp >= defend) {
-nospace: cfatal("Out of space in macro \"%s\" arg expansion",
- tokenp->name);
+ else if (defp >= defend)
+ {
+ nospace:
+ cfatal("Out of space in macro \"%s\" arg expansion",
+ tokenp->name);
}
- else {
+ else
+ {
*defp++ = (char)c;
}
}
@@ -549,23 +596,25 @@ nospace: cfatal("Out of space in macro \"%s\" arg expansion",
if (debug > 1)
fprintf( pCppOut, "macroline: \"%s\"\n", file->buffer);
#endif
-}
+ }
#if OSL_DEBUG_LEVEL > 1
-void dumpparm(char* why)
-/*
- * Dump parameter list.
- */
-{
+
+ /*
+ * Dump parameter list.
+ */
+ void dumpparm(char* why)
+ {
int i;
- fprintf( pCppOut, "dump of %d parameters (%" SAL_PRI_SIZET "u bytes total) %s\n",
- nargs, parmp - parm, why);
- for (i = 0; i < nargs; i++) {
- fprintf( pCppOut, "parm[%d] (%d) = \"%s\"\n",
- i + 1, (int)strlen(parlist[i]), parlist[i]);
+ fprintf( pCppOut, "dump of %d parameters (%" SAL_PRI_SIZET "u bytes total) %s\n",
+ nargs, parmp - parm, why);
+ for (i = 0; i < nargs; i++)
+ {
+ fprintf( pCppOut, "parm[%d] (%d) = \"%s\"\n",
+ i + 1, (int)strlen(parlist[i]), parlist[i]);
}
-}
+ }
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/rsc/source/rscpp/cpp5.c b/rsc/source/rscpp/cpp5.c
index 62d8f4b0f44d..6ccafe02e4f6 100644
--- a/rsc/source/rscpp/cpp5.c
+++ b/rsc/source/rscpp/cpp5.c
@@ -26,7 +26,7 @@
* Evaluate an #if expression.
*/
-static char *opname[] = { /* For debug and error messages */
+static char* opname[] = { /* For debug and error messages */
"end of expression", "val", "id",
"+", "-", "*", "/", "%",
"<<", ">>", "&", "|", "^",
@@ -80,7 +80,8 @@ static char opdope[OP_MAX] = {
#define S_ANDOR 2
#define S_QUEST 1
-typedef struct optab {
+typedef struct optab
+{
char op; /* Operator */
char prec; /* Its precedence */
char skip; /* Short-circuit: TRUE to skip */
@@ -133,7 +134,8 @@ static int evalue; /* Current value from evallex() */
#define S_PFPTR (sizeof (int (*)(void)))
#endif
-typedef struct types {
+typedef struct types
+{
short type; /* This is the bit if */
char *name; /* this is the token word */
} TYPES;
@@ -184,9 +186,6 @@ void InitCpp5()
}
-
-int
-eval()
/*
* Evaluate an expression. Straight-forward operator precedence.
* This is called from control() on encountering an #if statement.
@@ -199,23 +198,26 @@ eval()
* For compatibility with older cpp's, this return returns 1 (TRUE)
* if a syntax error is detected.
*/
+int eval()
{
- int op; /* Current operator */
- int *valp; /* -> value vector */
- OPTAB *opp; /* Operator stack */
- int prec; /* Op precedence */
- int binop; /* Set if binary op. needed */
- int op1; /* Operand from stack */
- int skip; /* For short-circuit testing */
- int value[NEXP]; /* Value stack */
- OPTAB opstack[NEXP]; /* Operand stack */
+ int op; /* Current operator */
+ int* valp; /* -> value vector */
+ OPTAB* opp; /* Operator stack */
+ int prec; /* Op precedence */
+ int binop; /* Set if binary op. needed */
+ int op1; /* Operand from stack */
+ int skip; /* For short-circuit testing */
+ int value[NEXP]; /* Value stack */
+ OPTAB opstack[NEXP]; /* Operand stack */
+
valp = value;
opp = opstack;
opp->op = OP_END; /* Mark bottom of stack */
opp->prec = opdope[OP_END]; /* And its precedence */
opp->skip = 0; /* Not skipping now */
binop = 0;
-again: ;
+
+again:
#ifdef DEBUG_EVAL
fprintf( pCppOut, "In #if at again: skip = %d, binop = %d, line is: %s",
opp->skip, binop, infile->bptr);
@@ -230,129 +232,143 @@ again: ;
fprintf( pCppOut, "op = %s, opdope = %03o, binop = %d, skip = %d\n",
opname[op], opdope[op], binop, opp->skip);
#endif
- if (op == DIG) { /* Value? */
- if (binop != 0) {
- cerror("misplaced constant in #if", NULLST);
- return (1);
+ if (op == DIG) /* Value? */
+ {
+ if (binop != 0)
+ {
+ cerror("misplaced constant in #if", NULLST);
+ return (1);
}
- else if (valp >= &value[NEXP-1]) {
- cerror("#if value stack overflow", NULLST);
- return (1);
+ else if (valp >= &value[NEXP-1])
+ {
+ cerror("#if value stack overflow", NULLST);
+ return (1);
}
- else {
+ else
+ {
#ifdef DEBUG_EVAL
- fprintf( pCppOut, "pushing %d onto value stack[%d]\n",
- evalue, valp - value);
+ fprintf( pCppOut, "pushing %d onto value stack[%d]\n",
+ evalue, valp - value);
#endif
- *valp++ = evalue;
- binop = 1;
+ *valp++ = evalue;
+ binop = 1;
}
goto again;
}
- else if (op > OP_END) {
+ else if (op > OP_END)
+ {
cerror("Illegal #if line", NULLST);
return (1);
}
prec = opdope[op];
- if (binop != (prec & 1)) {
+ if (binop != (prec & 1))
+ {
cerror("Operator %s in incorrect context", opname[op]);
return (1);
}
binop = (prec & 2) >> 1;
- for (;;) {
+ for (;;)
+ {
#ifdef DEBUG_EVAL
fprintf( pCppOut, "op %s, prec %d., stacked op %s, prec %d, skip %d\n",
opname[op], prec, opname[opp->op], opp->prec, opp->skip);
#endif
- if (prec > opp->prec) {
- if (op == OP_LPA)
- prec = OP_RPA_PREC;
- else if (op == OP_QUE)
- prec = OP_QUE_PREC;
- op1 = opp->skip; /* Save skip for test */
- /*
- * Push operator onto op. stack.
- */
- opp++;
- if (opp >= &opstack[NEXP]) {
- cerror("expression stack overflow at op \"%s\"",
- opname[op]);
- return (1);
- }
- opp->op = (char)op;
- opp->prec = (char)prec;
- /*
- * Do the short-circuit stuff here. Short-circuiting
- * stops automagically when operators are evaluated.
- */
- if ((op == OP_ANA && valp[-1] == 0)
- || (op == OP_ORO && valp[-1] != 0))
- opp->skip = S_ANDOR; /* And/or skip starts */
- else if (op == OP_QUE) /* Start of ?: operator */
- opp->skip = (char)((op1 & S_ANDOR) | ((valp[-1] == 0) ? S_QUEST : 0));
- else if (op == OP_COL) { /* : inverts S_QUEST */
- opp->skip = (char)((op1 & S_ANDOR)
- | (((op1 & S_QUEST) != 0) ? 0 : S_QUEST));
- }
- else { /* Other ops leave */
- opp->skip = (char)op1; /* skipping unchanged. */
- }
+ if (prec > opp->prec)
+ {
+ if (op == OP_LPA)
+ prec = OP_RPA_PREC;
+ else if (op == OP_QUE)
+ prec = OP_QUE_PREC;
+ op1 = opp->skip; /* Save skip for test */
+ /*
+ * Push operator onto op. stack.
+ */
+ opp++;
+ if (opp >= &opstack[NEXP])
+ {
+ cerror("expression stack overflow at op \"%s\"",
+ opname[op]);
+ return (1);
+ }
+ opp->op = (char)op;
+ opp->prec = (char)prec;
+ /*
+ * Do the short-circuit stuff here. Short-circuiting
+ * stops automagically when operators are evaluated.
+ */
+ if ((op == OP_ANA && valp[-1] == 0) ||
+ (op == OP_ORO && valp[-1] != 0))
+ {
+ opp->skip = S_ANDOR; /* And/or skip starts */
+ }
+ else if (op == OP_QUE) /* Start of ?: operator */
+ opp->skip = (char)((op1 & S_ANDOR) | ((valp[-1] == 0) ? S_QUEST : 0));
+ else if (op == OP_COL) /* : inverts S_QUEST */
+ {
+ opp->skip = (char)((op1 & S_ANDOR)
+ | (((op1 & S_QUEST) != 0) ? 0 : S_QUEST));
+ }
+ else /* Other ops leave */
+ {
+ opp->skip = (char)op1; /* skipping unchanged. */
+ }
#ifdef DEBUG_EVAL
- fprintf( pCppOut, "stacking %s, valp[-1] == %d at %s",
- opname[op], valp[-1], infile->bptr);
- dumpstack(opstack, opp, value, valp);
+ fprintf( pCppOut, "stacking %s, valp[-1] == %d at %s",
+ opname[op], valp[-1], infile->bptr);
+ dumpstack(opstack, opp, value, valp);
#endif
- goto again;
+ goto again;
}
/*
* Pop operator from op. stack and evaluate it.
* End of stack and '(' are specials.
*/
skip = opp->skip; /* Remember skip value */
- switch ((op1 = opp->op)) { /* Look at stacked op */
- case OP_END: /* Stack end marker */
- if (op == OP_EOE)
- return (valp[-1]); /* Finished ok. */
- goto again; /* Read another op. */
-
- case OP_LPA: /* ( on stack */
- if (op != OP_RPA) { /* Matches ) on input */
- cerror("unbalanced paren's, op is \"%s\"", opname[op]);
- return (1);
- }
- opp--; /* Unstack it */
- /* goto again; -- Fall through */
+ switch ((op1 = opp->op)) /* Look at stacked op */
+ {
+ case OP_END: /* Stack end marker */
+ if (op == OP_EOE)
+ return (valp[-1]); /* Finished ok. */
+ goto again; /* Read another op. */
+
+ case OP_LPA: /* ( on stack */
+ if (op != OP_RPA) /* Matches ) on input */
+ {
+ cerror("unbalanced paren's, op is \"%s\"", opname[op]);
+ return (1);
+ }
+ opp--; /* Unstack it */
+ /* goto again; -- Fall through */
case OP_QUE:
- goto again; /* Evaluate true expr. */
-
- case OP_COL: /* : on stack. */
- opp--; /* Unstack : */
- if (opp->op != OP_QUE) { /* Matches ? on stack? */
- cerror("Misplaced '?' or ':', previous operator is %s",
- opname[(int)opp->op]);
- return (1);
- }
+ goto again; /* Evaluate true expr. */
+
+ case OP_COL: /* : on stack. */
+ opp--; /* Unstack : */
+ if (opp->op != OP_QUE) /* Matches ? on stack? */
+ {
+ cerror("Misplaced '?' or ':', previous operator is %s",
+ opname[(int)opp->op]);
+ return (1);
+ }
/*
* Evaluate op1.
*/
default: /* Others: */
- opp--; /* Unstack the operator */
+ opp--; /* Unstack the operator */
#ifdef DEBUG_EVAL
- fprintf( pCppOut, "Stack before evaluation of %s\n", opname[op1]);
- dumpstack(opstack, opp, value, valp);
+ fprintf( pCppOut, "Stack before evaluation of %s\n", opname[op1]);
+ dumpstack(opstack, opp, value, valp);
#endif
- valp = evaleval(valp, op1, skip);
+ valp = evaleval(valp, op1, skip);
#ifdef DEBUG_EVAL
- fprintf( pCppOut, "Stack after evaluation\n");
- dumpstack(opstack, opp, value, valp);
+ fprintf( pCppOut, "Stack after evaluation\n");
+ dumpstack(opstack, opp, value, valp);
#endif
} /* op1 switch end */
} /* Stack unwind loop */
}
-FILE_LOCAL int
-evallex(int skip)
/*
* Return next eval operator or value. Called from eval(). It
* calls a special-purpose routines for 'char' strings and
@@ -360,46 +376,62 @@ evallex(int skip)
* evalchar called to evaluate 'x'
* evalnum called to evaluate numbers.
*/
+FILE_LOCAL int evallex(int skip)
{
- int c, c1, t;
+ int c;
+ int c1;
+ int t;
-again: do { /* Collect the token */
+again:
+ do /* Collect the token */
+ {
c = skipws();
- if ((c = macroid(c)) == EOF_CHAR || c == '\n') {
- unget();
- return (OP_EOE); /* End of expression */
+ if ((c = macroid(c)) == EOF_CHAR || c == '\n')
+ {
+ unget();
+ return (OP_EOE); /* End of expression */
}
- } while ((t = type[c]) == LET && catenate());
- if (t == INV) { /* Total nonsense */
- if (!skip) {
- if (isascii(c) && isprint(c))
- cierror("illegal character '%c' in #if", c);
- else
- cierror("illegal character (%d decimal) in #if", c);
+ }
+ while ((t = type[c]) == LET && catenate());
+ if (t == INV) /* Total nonsense */
+ {
+ if (!skip)
+ {
+ if (isascii(c) && isprint(c))
+ cierror("illegal character '%c' in #if", c);
+ else
+ cierror("illegal character (%d decimal) in #if", c);
}
return (OP_FAIL);
}
- else if (t == QUO) { /* ' or " */
- if (c == '\'') { /* Character constant */
- evalue = evalchar(skip); /* Somewhat messy */
+ else if (t == QUO) /* ' or " */
+ {
+ if (c == '\'') /* Character constant */
+ {
+ evalue = evalchar(skip); /* Somewhat messy */
#ifdef DEBUG_EVAL
- fprintf( pCppOut, "evalchar returns %d.\n", evalue);
+ fprintf( pCppOut, "evalchar returns %d.\n", evalue);
#endif
- return (DIG); /* Return a value */
+ return (DIG); /* Return a value */
}
cerror("Can't use a string in an #if", NULLST);
return (OP_FAIL);
}
- else if (t == LET) { /* ID must be a macro */
- if (streq(token, "defined")) { /* Or defined name */
+ else if (t == LET) /* ID must be a macro */
+ {
+ if (streq(token, "defined")) /* Or defined name */
+ {
c1 = c = skipws();
if (c == '(') /* Allow defined(name) */
c = skipws();
- if (type[c] == LET) {
+ if (type[c] == LET)
+ {
evalue = (lookid(c) != NULL);
- if (c1 != '(' /* Need to balance */
- || skipws() == ')') /* Did we balance? */
- return (DIG); /* Parsed ok */
+ if (c1 != '(' || /* Need to balance */
+ skipws() == ')') /* Did we balance? */
+ {
+ return (DIG); /* Parsed ok */
+ }
}
cerror("Bad #if ... defined() syntax", NULLST);
return (OP_FAIL);
@@ -419,70 +451,73 @@ again: do { /* Collect the token */
evalue = 0;
return (DIG);
}
- else if (t == DIG) { /* Numbers are harder */
+ else if (t == DIG) /* Numbers are harder */
+ {
evalue = evalnum(c);
#ifdef DEBUG_EVAL
fprintf( pCppOut, "evalnum returns %d.\n", evalue);
#endif
}
- else if (strchr("!=<>&|\\", c) != NULL) {
+ else if (strchr("!=<>&|\\", c) != NULL)
+ {
/*
* Process a possible multi-byte lexeme.
*/
- c1 = cget(); /* Peek at next char */
- switch (c) {
+ c1 = cget(); /* Peek at next char */
+ switch (c)
+ {
case '!':
- if (c1 == '=')
- return (OP_NE);
- break;
+ if (c1 == '=')
+ return (OP_NE);
+ break;
case '=':
- if (c1 != '=') { /* Can't say a=b in #if */
- unget();
- cerror("= not allowed in #if", NULLST);
- return (OP_FAIL);
- }
- return (OP_EQ);
+ if (c1 != '=') /* Can't say a=b in #if */
+ {
+ unget();
+ cerror("= not allowed in #if", NULLST);
+ return (OP_FAIL);
+ }
+ return (OP_EQ);
case '>':
case '<':
- if (c1 == c)
- return ((c == '<') ? OP_ASL : OP_ASR);
- else if (c1 == '=')
- return ((c == '<') ? OP_LE : OP_GE);
- break;
+ if (c1 == c)
+ return ((c == '<') ? OP_ASL : OP_ASR);
+ else if (c1 == '=')
+ return ((c == '<') ? OP_LE : OP_GE);
+ break;
case '|':
case '&':
- if (c1 == c)
- return ((c == '|') ? OP_ORO : OP_ANA);
- break;
+ if (c1 == c)
+ return ((c == '|') ? OP_ORO : OP_ANA);
+ break;
case '\\':
- if (c1 == '\n') /* Multi-line if */
- goto again;
- cerror("Unexpected \\ in #if", NULLST);
- return (OP_FAIL);
+ if (c1 == '\n') /* Multi-line if */
+ goto again;
+ cerror("Unexpected \\ in #if", NULLST);
+ return (OP_FAIL);
}
unget();
}
return (t);
}
-
-FILE_LOCAL int
-dosizeof()
+
/*
* Process the sizeof (basic type) operation in an #if string.
* Sets evalue to the size and returns
* DIG success
* OP_FAIL bad parse or something.
*/
+FILE_LOCAL int dosizeof()
{
- int c;
- TYPES *tp;
- SIZES *sizp;
- short *testp;
- short typecode;
+ int c;
+ TYPES* tp;
+ SIZES* sizp;
+ short* testp;
+ short typecode;
if ((c = skipws()) != '(')
goto nogood;
@@ -490,52 +525,60 @@ dosizeof()
* Scan off the tokens.
*/
typecode = 0;
- while (0 != (c = skipws())) {
+ while (0 != (c = skipws()))
+ {
if ((c = macroid(c)) == EOF_CHAR || c == '\n')
goto nogood; /* End of line is a bug */
- else if (c == '(') { /* thing (*)() func ptr */
- if (skipws() == '*'
- && skipws() == ')') { /* We found (*) */
+ else if (c == '(') /* thing (*)() func ptr */
+ {
+ if (skipws() == '*' && skipws() == ')')
+ { /* We found (*) */
if (skipws() != '(') /* Let () be optional */
unget();
else if (skipws() != ')')
goto nogood;
- typecode |= T_FPTR; /* Function pointer */
+ typecode |= T_FPTR; /* Function pointer */
}
- else { /* Junk is a bug */
+ else /* Junk is a bug */
goto nogood;
- }
}
- else if (type[c] != LET) /* Exit if not a type */
+ else if (type[c] != LET) /* Exit if not a type */
break;
- else if (!catenate()) { /* Maybe combine tokens */
+ else if (!catenate()) /* Maybe combine tokens */
+ {
/*
* Look for this unexpandable token in basic_types.
* The code accepts "int long" as well as "long int"
* which is a minor bug as bugs go (and one shared with
* a lot of C compilers).
*/
- for (tp = basic_types; tp->name != NULLST; tp++) {
+ for (tp = basic_types; tp->name != NULLST; tp++)
+ {
if (streq(token, tp->name))
- break;
+ break;
}
- if (tp->name == NULLST) {
+ if (tp->name == NULLST)
+ {
cerror("#if sizeof, unknown type \"%s\"", token);
return (OP_FAIL);
}
- typecode |= tp->type; /* Or in the type bit */
+ typecode |= tp->type; /* Or in the type bit */
}
}
/*
* We are at the end of the type scan. Chew off '*' if necessary.
*/
- if (c == '*') {
+ if (c == '*')
+ {
typecode |= T_PTR;
c = skipws();
}
- if (c == ')') { /* Last syntax check */
- for (testp = test_table; *testp != 0; testp++) {
- if (!bittest(typecode & *testp)) {
+ if (c == ')') /* Last syntax check */
+ {
+ for (testp = test_table; *testp != 0; testp++)
+ {
+ if (!bittest(typecode & *testp))
+ {
cerror("#if ... sizeof: illegal type combination", NULLST);
return (OP_FAIL);
}
@@ -546,24 +589,28 @@ dosizeof()
* We assume that signed and unsigned don't change the size:
* sizeof (signed int) == (sizeof unsigned int)
*/
- if ((typecode & T_FPTR) != 0) /* Function pointer */
+ if ((typecode & T_FPTR) != 0) /* Function pointer */
typecode = T_FPTR | T_PTR;
- else { /* Var or var * datum */
+ else /* Var or var * datum */
+ {
typecode &= ~(T_SIGNED | T_UNSIGNED);
if ((typecode & (T_SHORT | T_LONG)) != 0)
typecode &= ~T_INT;
}
- if ((typecode & ~T_PTR) == 0) {
+ if ((typecode & ~T_PTR) == 0)
+ {
cerror("#if sizeof() error, no type specified", NULLST);
return (OP_FAIL);
}
/*
* Exactly one bit (and possibly T_PTR) may be set.
*/
- for (sizp = size_table; sizp->bits != 0; sizp++) {
- if ((typecode & ~T_PTR) == sizp->bits) {
+ for (sizp = size_table; sizp->bits != 0; sizp++)
+ {
+ if ((typecode & ~T_PTR) == sizp->bits)
+ {
evalue = ((typecode & T_PTR) != 0)
- ? sizp->psize : sizp->size;
+ ? sizp->psize : sizp->size;
return (DIG);
}
} /* We shouldn't fail */
@@ -571,17 +618,20 @@ dosizeof()
return (OP_FAIL);
}
-nogood: unget();
+ nogood:
+ unget();
cerror("#if ... sizeof() syntax error", NULLST);
return (OP_FAIL);
}
-FILE_LOCAL int
-bittest(int value)
/*
* TRUE if value is zero or exactly one bit is set in value.
*/
+FILE_LOCAL int bittest(int value)
{
+/* whoaa!! really worried about non 2's complement machines...
+ * but not at all about cross-compiling ?
+ */
#if (4096 & ~(-4096)) == 0
return ((value & ~(-value)) == 0);
#else
@@ -592,36 +642,37 @@ bittest(int value)
#endif
}
-FILE_LOCAL int
-evalnum(int c)
/*
* Expand number for #if lexical analysis. Note: evalnum recognizes
* the unsigned suffix, but only returns a signed int value.
*/
+FILE_LOCAL int evalnum(int c)
{
- int value;
- int base;
- int c1;
+ int value;
+ int base;
+ int c1;
if (c != '0')
base = 10;
- else if ((c = cget()) == 'x' || c == 'X') {
+ else if ((c = cget()) == 'x' || c == 'X')
+ {
base = 16;
c = cget();
}
else base = 8;
value = 0;
- for (;;) {
+ for (;;)
+ {
c1 = c;
if (isascii(c) && isupper(c1))
c1 = tolower(c1);
#ifdef EBCDIC
if (c1 <= 'f')
#else
- if (c1 >= 'a')
+ if (c1 >= 'a')
#endif
- c1 -= ('a' - 10);
- else c1 -= '0';
+ c1 -= ('a' - 10);
+ else c1 -= '0';
if (c1 < 0 || c1 >= base)
break;
value *= base;
@@ -634,95 +685,101 @@ evalnum(int c)
return (value);
}
-FILE_LOCAL int
-evalchar(int skip)
/*
* Get a character constant
*/
+FILE_LOCAL int evalchar(int skip)
{
- int c;
- int value;
- int count;
+ int c;
+ int value;
+ int count;
instring = TRUE;
- if ((c = cget()) == '\\') {
- switch ((c = cget())) {
+ if ((c = cget()) == '\\')
+ {
+ switch ((c = cget()))
+ {
case 'a': /* New in Standard */
#if ('a' == '\a' || '\a' == ALERT)
- value = ALERT; /* Use predefined value */
+ value = ALERT; /* Use predefined value */
#else
- value = '\a'; /* Use compiler's value */
+ value = '\a'; /* Use compiler's value */
#endif
- break;
+ break;
case 'b':
- value = '\b';
- break;
+ value = '\b';
+ break;
case 'f':
- value = '\f';
- break;
+ value = '\f';
+ break;
case 'n':
- value = '\n';
- break;
+ value = '\n';
+ break;
case 'r':
- value = '\r';
- break;
+ value = '\r';
+ break;
case 't':
- value = '\t';
- break;
+ value = '\t';
+ break;
case 'v': /* New in Standard */
#if ('v' == '\v' || '\v' == VT)
- value = VT; /* Use predefined value */
+ value = VT; /* Use predefined value */
#else
- value = '\v'; /* Use compiler's value */
+ value = '\v'; /* Use compiler's value */
#endif
- break;
+ break;
case 'x': /* '\xFF' */
- count = 3;
- value = 0;
- while ((((c = get()) >= '0' && c <= '9')
- || (c >= 'a' && c <= 'f')
- || (c >= 'A' && c <= 'F'))
- && (--count >= 0)) {
- value *= 16;
+ count = 3;
+ value = 0;
+ while ((((c = get()) >= '0' && c <= '9') ||
+ (c >= 'a' && c <= 'f') ||
+ (c >= 'A' && c <= 'F')) &&
+ (--count >= 0))
+ {
+ value *= 16;
#ifdef EBCDIC
- value += (c <= '9') ? (c - '0') : ((c & 0xF) + 9);
+ value += (c <= '9') ? (c - '0') : ((c & 0xF) + 9);
#else
- value += (c >= '0') ? (c - '0') : ((c & 0xF) + 9);
+ value += (c >= '0') ? (c - '0') : ((c & 0xF) + 9);
#endif
- }
- unget();
- break;
+ }
+ unget();
+ break;
default:
- if (c >= '0' && c <= '7') {
- count = 3;
- value = 0;
- while (c >= '0' && c <= '7' && --count >= 0) {
- value *= 8;
- value += (c - '0');
- c = get();
+ if (c >= '0' && c <= '7')
+ {
+ count = 3;
+ value = 0;
+ while (c >= '0' && c <= '7' && --count >= 0)
+ {
+ value *= 8;
+ value += (c - '0');
+ c = get();
+ }
+ unget();
}
- unget();
- }
- else value = c;
- break;
+ else value = c;
+ break;
}
}
else if (c == '\'')
value = 0;
- else value = c;
+ else
+ value = c;
/*
* We warn on multi-byte constants and try to hack
* (big|little)endian machines.
*/
- while ((c = get()) != '\'' && c != EOF_CHAR && c != '\n') {
+ while ((c = get()) != '\'' && c != EOF_CHAR && c != '\n')
+ {
if (!skip)
ciwarn("multi-byte constant '%c' isn't portable", c);
value <<= BITS_CHAR;
@@ -732,8 +789,6 @@ evalchar(int skip)
return (value);
}
-FILE_LOCAL int *
-evaleval(int* valp, int op, int skip)
/*
* Apply the argument operator to the data on the value stack.
* One or two values are popped from the value stack and the result
@@ -743,22 +798,25 @@ evaleval(int* valp, int op, int skip)
*
* evaleval() returns the new pointer to the top of the value stack.
*/
+FILE_LOCAL int * evaleval(int* valp, int op, int skip)
{
- int v1, v2 = 0;
+ int v1;
+ int v2 = 0;
if (isbinary(op))
v2 = *--valp;
v1 = *--valp;
#ifdef DEBUG_EVAL
fprintf( pCppOut, "%s op %s", (isbinary(op)) ? "binary" : "unary",
- opname[op]);
+ opname[op]);
if (isbinary(op))
fprintf( pCppOut, ", v2 = %d.", v2);
fprintf( pCppOut, ", v1 = %d.\n", v1);
#endif
- switch (op) {
+ switch (op)
+ {
case OP_EOE:
- break;
+ break;
case OP_ADD:
v1 += v2;
@@ -774,10 +832,12 @@ evaleval(int* valp, int op, int skip)
case OP_DIV:
case OP_MOD:
- if (v2 == 0) {
- if (!skip) {
+ if (v2 == 0)
+ {
+ if (!skip)
+ {
cwarn("%s by zero in #if, zero result assumed",
- (op == OP_DIV) ? "divide" : "mod");
+ (op == OP_DIV) ? "divide" : "mod");
}
v1 = 0;
}
@@ -878,12 +938,14 @@ int value[NEXP]; /* Value stack */
int *valp; /* -> value vector */
{
fprintf( pCppOut, "index op prec skip name -- op stack at %s", infile->bptr);
- while (opp > opstack) {
+ while (opp > opstack)
+ {
fprintf( pCppOut, " [%2d] %2d %03o %d %s\n", opp - opstack,
- opp->op, opp->prec, opp->skip, opname[opp->op]);
+ opp->op, opp->prec, opp->skip, opname[opp->op]);
opp--;
}
- while (--valp >= value) {
+ while (--valp >= value)
+ {
fprintf( pCppOut, "value[%d] = %d\n", (valp - value), *valp);
}
}
diff --git a/rsc/source/rscpp/cpp6.c b/rsc/source/rscpp/cpp6.c
index 45297a25825b..a024e7777516 100644
--- a/rsc/source/rscpp/cpp6.c
+++ b/rsc/source/rscpp/cpp6.c
@@ -185,75 +185,76 @@ void InitCpp6()
-void skipnl()
/*
* Skip to the end of the current input line.
*/
+void skipnl()
{
- int c;
+ int c;
- do { /* Skip to newline */
- c = get();
- } while (c != '\n' && c != EOF_CHAR);
+ do
+ { /* Skip to newline */
+ c = get();
+ }
+ while (c != '\n' && c != EOF_CHAR);
}
-int
-skipws()
/*
* Skip over whitespace
*/
+int skipws()
{
- int c;
+ int c;
- do { /* Skip whitespace */
- c = get();
- } while (type[c] == SPA);
- return (c);
+ do { /* Skip whitespace */
+ c = get();
+ } while (type[c] == SPA);
+ return (c);
}
-void scanid(int c)
/*
* Get the next token (an id) into the token buffer.
* Note: this code is duplicated in lookid().
* Change one, change both.
*/
+void scanid(int c)
{
- char *bp;
-
- if (c == DEF_MAGIC) /* Eat the magic token */
- c = get(); /* undefiner. */
- bp = token;
- do {
- if (bp < &token[IDMAX]) /* token dim is IDMAX+1 */
- *bp++ = (char)c;
- c = get();
- } while (type[c] == LET || type[c] == DIG);
- unget();
- *bp = EOS;
+ char* bp;
+
+ if (c == DEF_MAGIC) /* Eat the magic token */
+ c = get(); /* undefiner. */
+ bp = token;
+ do
+ {
+ if (bp < &token[IDMAX]) /* token dim is IDMAX+1 */
+ *bp++ = (char)c;
+ c = get();
+ }
+ while (type[c] == LET || type[c] == DIG);
+ unget();
+ *bp = EOS;
}
-int
-macroid(int c)
/*
* If c is a letter, scan the id. if it's #defined, expand it and scan
* the next character and try again.
*
* Else, return the character. If type[c] is a LET, the token is in token.
*/
+int macroid(int c)
{
- DEFBUF *dp;
-
- if (infile != NULL && infile->fp != NULL)
- recursion = 0;
- while (type[c] == LET && (dp = lookid(c)) != NULL) {
- expand(dp);
- c = get();
- }
- return (c);
+ DEFBUF* dp;
+
+ if (infile != NULL && infile->fp != NULL)
+ recursion = 0;
+ while (type[c] == LET && (dp = lookid(c)) != NULL)
+ {
+ expand(dp);
+ c = get();
+ }
+ return (c);
}
-int
-catenate()
/*
* A token was just read (via macroid).
* If the next character is TOK_SEP, concatenate the next token
@@ -261,492 +262,531 @@ catenate()
* macroid's argument. If it is not TOK_SEP, unget() the character
* and return FALSE.
*/
+int catenate()
{
- int c;
- char *token1;
-
- if (get() != TOK_SEP) { /* Token concatenation */
- unget();
- return (FALSE);
- }
- else {
- token1 = savestring(token); /* Save first token */
- c = macroid(get()); /* Scan next token */
- switch(type[c]) { /* What was it? */
- case LET: /* An identifier, ... */
- if (strlen(token1) + strlen(token) >= NWORK)
- cfatal("work buffer overflow doing %s #", token1);
- sprintf(work, "%s%s", token1, token);
- break;
+ int c;
+ char* token1;
- case DIG: /* A digit string */
- strcpy(work, token1);
- workp = work + strlen(work);
- do {
- save(c);
- } while ((c = get()) != TOK_SEP);
- /*
- * The trailing TOK_SEP is no longer needed.
- */
- save(EOS);
- break;
-
- default: /* An error, ... */
- if (isprint(c))
- cierror("Strange character '%c' after #", c);
- else
- cierror("Strange character (%d.) after #", c);
- strcpy(work, token1);
- unget();
- break;
+ if (get() != TOK_SEP) /* Token concatenation */
+ {
+ unget();
+ return (FALSE);
+ }
+ else
+ {
+ token1 = savestring(token); /* Save first token */
+ c = macroid(get()); /* Scan next token */
+ switch(type[c]) /* What was it? */
+ {
+ case LET: /* An identifier, ... */
+ if (strlen(token1) + strlen(token) >= NWORK)
+ cfatal("work buffer overflow doing %s #", token1);
+ sprintf(work, "%s%s", token1, token);
+ break;
+
+ case DIG: /* A digit string */
+ strcpy(work, token1);
+ workp = work + strlen(work);
+ do
+ {
+ save(c);
}
+ while ((c = get()) != TOK_SEP);
/*
- * work has the concatenated token and token1 has
- * the first token (no longer needed). Unget the
- * new (concatenated) token after freeing token1.
- * Finally, setup to read the new token.
+ * The trailing TOK_SEP is no longer needed.
*/
- free(token1); /* Free up memory */
- ungetstring(work); /* Unget the new thing, */
- return (TRUE);
+ save(EOS);
+ break;
+
+ default: /* An error, ... */
+ if (isprint(c))
+ cierror("Strange character '%c' after #", c);
+ else
+ cierror("Strange character (%d.) after #", c);
+ strcpy(work, token1);
+ unget();
+ break;
}
+ /*
+ * work has the concatenated token and token1 has
+ * the first token (no longer needed). Unget the
+ * new (concatenated) token after freeing token1.
+ * Finally, setup to read the new token.
+ */
+ free(token1); /* Free up memory */
+ ungetstring(work); /* Unget the new thing, */
+ return (TRUE);
+ }
}
-int
-scanstring(int delim,
-#ifndef _NO_PROTO
-void (*outfun)( int ) /* BP */ /* Output function */
-#else
-void (*outfun)() /* BP */
-#endif
-)
/*
* Scan off a string. Warning if terminated by newline or EOF.
* outfun() outputs the character -- to a buffer if in a macro.
* TRUE if ok, FALSE if error.
*/
+int scanstring(int delim,
+#ifndef _NO_PROTO
+ void (*outfun)( int ) /* BP */ /* Output function */
+#else
+ void (*outfun)() /* BP */
+#endif
+ )
{
- int c;
-
- instring = TRUE; /* Don't strip comments */
- (*outfun)(delim);
- while ((c = get()) != delim
- && c != '\n'
- && c != EOF_CHAR) {
-
- if (c != DEF_MAGIC)
- (*outfun)(c);
- if (c == '\\')
- (*outfun)(get());
- }
- instring = FALSE;
- if (c == delim) {
+ int c;
+
+ instring = TRUE; /* Don't strip comments */
+ (*outfun)(delim);
+ while ((c = get()) != delim &&
+ c != '\n' &&
+ c != EOF_CHAR)
+ {
+ if (c != DEF_MAGIC)
(*outfun)(c);
- return (TRUE);
- }
- else {
- cerror("Unterminated string", NULLST);
- unget();
- return (FALSE);
- }
+ if (c == '\\')
+ (*outfun)(get());
+ }
+ instring = FALSE;
+ if (c == delim)
+ {
+ (*outfun)(c);
+ return (TRUE);
+ }
+ else
+ {
+ cerror("Unterminated string", NULLST);
+ unget();
+ return (FALSE);
+ }
}
-void scannumber(int c,
-#ifndef _NO_PROTO
-void (*outfun)( int ) /* BP */ /* Output/store func */
-#else
-void (*outfun)() /* BP */
-#endif
-)
/*
* Process a number. We know that c is from 0 to 9 or dot.
* Algorithm from Dave Conroy's Decus C.
*/
+void scannumber(int c,
+#ifndef _NO_PROTO
+ void (*outfun)( int ) /* BP */ /* Output/store func */
+#else
+ void (*outfun)() /* BP */
+#endif
+ )
{
- int radix; /* 8, 10, or 16 */
- int expseen; /* 'e' seen in floater */
- int signseen; /* '+' or '-' seen */
- int octal89; /* For bad octal test */
- int dotflag; /* TRUE if '.' was seen */
-
- expseen = FALSE; /* No exponent seen yet */
- signseen = TRUE; /* No +/- allowed yet */
- octal89 = FALSE; /* No bad octal yet */
- radix = 10; /* Assume decimal */
- if ((dotflag = (c == '.')) != FALSE) { /* . something? */
- (*outfun)('.'); /* Always out the dot */
- if (type[(c = get())] != DIG) { /* If not a float numb, */
- unget(); /* Rescan strange char */
- return; /* All done for now */
- }
- } /* End of float test */
- else if (c == '0') { /* Octal or hex? */
- (*outfun)(c); /* Stuff initial zero */
- radix = 8; /* Assume it's octal */
- c = get(); /* Look for an 'x' */
- if (c == 'x' || c == 'X') { /* Did we get one? */
- radix = 16; /* Remember new radix */
- (*outfun)(c); /* Stuff the 'x' */
- c = get(); /* Get next character */
- }
+ int radix; /* 8, 10, or 16 */
+ int expseen; /* 'e' seen in floater */
+ int signseen; /* '+' or '-' seen */
+ int octal89; /* For bad octal test */
+ int dotflag; /* TRUE if '.' was seen */
+
+ expseen = FALSE; /* No exponent seen yet */
+ signseen = TRUE; /* No +/- allowed yet */
+ octal89 = FALSE; /* No bad octal yet */
+ radix = 10; /* Assume decimal */
+ if ((dotflag = (c == '.')) != FALSE) /* . something? */
+ {
+ (*outfun)('.'); /* Always out the dot */
+ if (type[(c = get())] != DIG) /* If not a float numb, */
+ {
+ unget(); /* Rescan strange char */
+ return; /* All done for now */
}
- for (;;) { /* Process curr. char. */
- /*
- * Note that this algorithm accepts "012e4" and "03.4"
- * as legitimate floating-point numbers.
- */
- if (radix != 16 && (c == 'e' || c == 'E')) {
- if (expseen) /* Already saw 'E'? */
- break; /* Exit loop, bad nbr. */
- expseen = TRUE; /* Set exponent seen */
- signseen = FALSE; /* We can read '+' now */
- radix = 10; /* Decimal exponent */
- }
- else if (radix != 16 && c == '.') {
- if (dotflag) /* Saw dot already? */
- break; /* Exit loop, two dots */
- dotflag = TRUE; /* Remember the dot */
- radix = 10; /* Decimal fraction */
- }
- else if (c == '+' || c == '-') { /* 1.0e+10 */
- if (signseen) /* Sign in wrong place? */
- break; /* Exit loop, not nbr. */
- /* signseen = TRUE; */ /* Remember we saw it */
- }
- else { /* Check the digit */
- switch (c) {
- case '8': case '9': /* Sometimes wrong */
- octal89 = TRUE; /* Do check later */
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- break; /* Always ok */
-
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- if (radix == 16) /* Alpha's are ok only */
- break; /* if reading hex. */
- default: /* At number end */
- goto done; /* Break from for loop */
- } /* End of switch */
- } /* End general case */
- (*outfun)(c); /* Accept the character */
- signseen = TRUE; /* Don't read sign now */
- c = get(); /* Read another char */
- } /* End of scan loop */
+ } /* End of float test */
+ else if (c == '0') /* Octal or hex? */
+ {
+ (*outfun)(c); /* Stuff initial zero */
+ radix = 8; /* Assume it's octal */
+ c = get(); /* Look for an 'x' */
+ if (c == 'x' || c == 'X') /* Did we get one? */
+ {
+ radix = 16; /* Remember new radix */
+ (*outfun)(c); /* Stuff the 'x' */
+ c = get(); /* Get next character */
+ }
+ }
+ for (;;) /* Process curr. char. */
+ {
/*
- * When we break out of the scan loop, c contains the first
- * character (maybe) not in the number. If the number is an
- * integer, allow a trailing 'L' for long and/or a trailing 'U'
- * for unsigned. If not those, push the trailing character back
- * on the input stream. Floating point numbers accept a trailing
- * 'L' for "long double".
+ * Note that this algorithm accepts "012e4" and "03.4"
+ * as legitimate floating-point numbers.
*/
-done: if (dotflag || expseen) { /* Floating point? */
- if (c == 'l' || c == 'L') {
- (*outfun)(c);
- get(); /* Ungotten later */
- }
+ if (radix != 16 && (c == 'e' || c == 'E'))
+ {
+ if (expseen) /* Already saw 'E'? */
+ break; /* Exit loop, bad nbr. */
+ expseen = TRUE; /* Set exponent seen */
+ signseen = FALSE; /* We can read '+' now */
+ radix = 10; /* Decimal exponent */
}
- else { /* Else it's an integer */
- /*
- * We know that dotflag and expseen are both zero, now:
- * dotflag signals "saw 'L'", and
- * expseen signals "saw 'U'".
- */
- for (;;) {
- switch (c) {
- case 'l':
- case 'L':
- if (dotflag)
- goto nomore;
- dotflag = TRUE;
- break;
-
- case 'u':
- case 'U':
- if (expseen)
- goto nomore;
- expseen = TRUE;
- break;
-
- default:
+ else if (radix != 16 && c == '.')
+ {
+ if (dotflag) /* Saw dot already? */
+ break; /* Exit loop, two dots */
+ dotflag = TRUE; /* Remember the dot */
+ radix = 10; /* Decimal fraction */
+ }
+ else if (c == '+' || c == '-') /* 1.0e+10 */
+ {
+ if (signseen) /* Sign in wrong place? */
+ break; /* Exit loop, not nbr. */
+ /* signseen = TRUE; */ /* Remember we saw it */
+ }
+ else /* Check the digit */
+ {
+ switch (c)
+ {
+ case '8': case '9': /* Sometimes wrong */
+ octal89 = TRUE; /* Do check later */
+ case '0': case '1': case '2': case '3':
+ case '4': case '5': case '6': case '7':
+ break; /* Always ok */
+
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ if (radix == 16) /* Alpha's are ok only */
+ break; /* if reading hex. */
+ default: /* At number end */
+ goto done; /* Break from for loop */
+ } /* End of switch */
+ } /* End general case */
+ (*outfun)(c); /* Accept the character */
+ signseen = TRUE; /* Don't read sign now */
+ c = get(); /* Read another char */
+ } /* End of scan loop */
+ /*
+ * When we break out of the scan loop, c contains the first
+ * character (maybe) not in the number. If the number is an
+ * integer, allow a trailing 'L' for long and/or a trailing 'U'
+ * for unsigned. If not those, push the trailing character back
+ * on the input stream. Floating point numbers accept a trailing
+ * 'L' for "long double".
+ */
+ done:
+ if (dotflag || expseen) /* Floating point? */
+ {
+ if (c == 'l' || c == 'L')
+ {
+ (*outfun)(c);
+ get(); /* Ungotten later */
+ }
+ }
+ else /* Else it's an integer */
+ {
+ /*
+ * We know that dotflag and expseen are both zero, now:
+ * dotflag signals "saw 'L'", and
+ * expseen signals "saw 'U'".
+ */
+ for (;;)
+ {
+ switch (c)
+ {
+ case 'l':
+ case 'L':
+ if (dotflag)
goto nomore;
- }
- (*outfun)(c); /* Got 'L' or 'U'. */
- c = get(); /* Look at next, too. */
+ dotflag = TRUE;
+ break;
+
+ case 'u':
+ case 'U':
+ if (expseen)
+ goto nomore;
+ expseen = TRUE;
+ break;
+
+ default:
+ goto nomore;
}
+ (*outfun)(c); /* Got 'L' or 'U'. */
+ c = get(); /* Look at next, too. */
}
-nomore: unget(); /* Not part of a number */
- if (octal89 && radix == 8)
- cwarn("Illegal digit in octal number", NULLST);
+ }
+ nomore:
+ unget(); /* Not part of a number */
+ if (octal89 && radix == 8)
+ cwarn("Illegal digit in octal number", NULLST);
}
void save(int c)
{
- if (workp >= &work[NWORK]) {
- work[NWORK-1] = '\0';
- cfatal("Work buffer overflow: %s", work);
- }
- else *workp++ = (char)c;
+ if (workp >= &work[NWORK])
+ {
+ work[NWORK-1] = '\0';
+ cfatal("Work buffer overflow: %s", work);
+ }
+ else
+ *workp++ = (char)c;
}
-char *
-savestring(char* text)
/*
* Store a string into free memory.
*/
+char* savestring(char* text)
{
- char *result;
+ char* result;
- result = getmem(strlen(text) + 1);
- strcpy(result, text);
- return (result);
+ result = getmem(strlen(text) + 1);
+ strcpy(result, text);
+ return (result);
}
-FILEINFO *
-getfile(int bufsize, char* name)
/*
* Common FILEINFO buffer initialization for a new file or macro.
*/
+FILEINFO* getfile(int bufsize, char* name)
{
- FILEINFO *file;
- int size;
-
- size = strlen(name); /* File/macro name */
- file = (FILEINFO *) getmem(sizeof (FILEINFO) + bufsize + size);
- file->parent = infile; /* Chain files together */
- file->fp = NULL; /* No file yet */
- file->filename = savestring(name); /* Save file/macro name */
- file->progname = NULL; /* No #line seen yet */
- file->unrecur = 0; /* No macro fixup */
- file->bptr = file->buffer; /* Initialize line ptr */
- file->buffer[0] = EOS; /* Force first read */
- file->line = 0; /* (Not used just yet) */
- if (infile != NULL) /* If #include file */
- infile->line = line; /* Save current line */
- infile = file; /* New current file */
- line = 1; /* Note first line */
- return (file); /* All done. */
+ FILEINFO* file;
+ int size;
+
+ size = strlen(name); /* File/macro name */
+ file = (FILEINFO*) getmem(sizeof (FILEINFO) + bufsize + size);
+ file->parent = infile; /* Chain files together */
+ file->fp = NULL; /* No file yet */
+ file->filename = savestring(name); /* Save file/macro name */
+ file->progname = NULL; /* No #line seen yet */
+ file->unrecur = 0; /* No macro fixup */
+ file->bptr = file->buffer; /* Initialize line ptr */
+ file->buffer[0] = EOS; /* Force first read */
+ file->line = 0; /* (Not used just yet) */
+ if (infile != NULL) /* If #include file */
+ infile->line = line; /* Save current line */
+ infile = file; /* New current file */
+ line = 1; /* Note first line */
+ return (file); /* All done. */
}
-char *
-getmem(int size)
/*
* Get a block of free memory.
*/
+char* getmem(int size)
{
- char *result;
+ char* result;
- if ((result = malloc((unsigned) size)) == NULL)
- cfatal("Out of memory", NULLST);
- return (result);
+ if ((result = malloc((unsigned) size)) == NULL)
+ cfatal("Out of memory", NULLST);
+ return (result);
}
-DEFBUF *
-lookid(int c)
/*
* Look for the next token in the symbol table. Returns token in "token".
* If found, returns the table pointer; Else returns NULL.
*/
+DEFBUF* lookid(int c)
{
- int nhash;
- DEFBUF *dp;
- char *np;
- int temp = 0;
- int isrecurse; /* For #define foo foo */
-
- np = token;
- nhash = 0;
- if (0 != (isrecurse = (c == DEF_MAGIC))) /* If recursive macro */
- c = get(); /* hack, skip DEF_MAGIC */
- do {
- if (np < &token[IDMAX]) { /* token dim is IDMAX+1 */
- *np++ = (char)c; /* Store token byte */
- nhash += c; /* Update hash value */
- }
- c = get(); /* And get another byte */
- } while (type[c] == LET || type[c] == DIG);
- unget(); /* Rescan terminator */
- *np = EOS; /* Terminate token */
- if (isrecurse) /* Recursive definition */
- return (NULL); /* undefined just now */
- nhash += (np - token); /* Fix hash value */
- dp = symtab[nhash & SBMASK]; /* Starting bucket */
- while (dp != (DEFBUF *) NULL) { /* Search symbol table */
- if (dp->hash == nhash /* Fast precheck */
- && (temp = strcmp(dp->name, token)) >= 0)
- break;
- dp = dp->link; /* Nope, try next one */
+ int nhash;
+ DEFBUF* dp;
+ char* np;
+ int temp = 0;
+ int isrecurse; /* For #define foo foo */
+
+ np = token;
+ nhash = 0;
+ if (0 != (isrecurse = (c == DEF_MAGIC)))/* If recursive macro */
+ c = get(); /* hack, skip DEF_MAGIC */
+ do
+ {
+ if (np < &token[IDMAX]) /* token dim is IDMAX+1 */
+ {
+ *np++ = (char)c; /* Store token byte */
+ nhash += c; /* Update hash value */
}
- return ((temp == 0) ? dp : NULL);
+ c = get(); /* And get another byte */
+ }
+ while (type[c] == LET || type[c] == DIG);
+ unget(); /* Rescan terminator */
+ *np = EOS; /* Terminate token */
+ if (isrecurse) /* Recursive definition */
+ return (NULL); /* undefined just now */
+ nhash += (np - token); /* Fix hash value */
+ dp = symtab[nhash & SBMASK]; /* Starting bucket */
+ while (dp != (DEFBUF*) NULL) /* Search symbol table */
+ {
+ if (dp->hash == nhash && /* Fast precheck */
+ (temp = strcmp(dp->name, token)) >= 0)
+ {
+ break;
+ }
+ dp = dp->link; /* Nope, try next one */
+ }
+ return ((temp == 0) ? dp : NULL);
}
-DEFBUF *
-defendel(char* name, int delete)
/*
* Enter this name in the lookup table (delete = FALSE)
* or delete this name (delete = TRUE).
* Returns a pointer to the define block (delete = FALSE)
* Returns NULL if the symbol wasn't defined (delete = TRUE).
*/
+DEFBUF* defendel(char* name, int delete)
{
- DEFBUF *dp;
- DEFBUF **prevp;
- char *np;
- int nhash;
- int temp;
- int size;
-
- for (nhash = 0, np = name; *np != EOS;)
- nhash += *np++;
- size = (np - name);
- nhash += size;
- prevp = &symtab[nhash & SBMASK];
- while ((dp = *prevp) != (DEFBUF *) NULL) {
- if (dp->hash == nhash
- && (temp = strcmp(dp->name, name)) >= 0) {
- if (temp > 0)
- dp = NULL; /* Not found */
- else {
- *prevp = dp->link; /* Found, unlink and */
- if (dp->repl != NULL) /* Free the replacement */
- free(dp->repl); /* if any, and then */
- free((char *) dp); /* Free the symbol */
- dp = NULL;
- }
- break;
+ DEFBUF* dp;
+ DEFBUF** prevp;
+ char* np;
+ int nhash;
+ int temp;
+ int size;
+
+ for (nhash = 0, np = name; *np != EOS;)
+ nhash += *np++;
+ size = (np - name);
+ nhash += size;
+ prevp = &symtab[nhash & SBMASK];
+ while ((dp = *prevp) != (DEFBUF*) NULL)
+ {
+ if (dp->hash == nhash &&
+ (temp = strcmp(dp->name, name)) >= 0)
+ {
+ if (temp > 0)
+ dp = NULL; /* Not found */
+ else
+ {
+ *prevp = dp->link; /* Found, unlink and */
+ if (dp->repl != NULL) /* Free the replacement */
+ free(dp->repl); /* if any, and then */
+ free((char*) dp); /* Free the symbol */
+ dp = NULL;
}
- prevp = &dp->link;
- }
- if (!delete) {
- dp = (DEFBUF *) getmem(sizeof (DEFBUF) + size);
- dp->link = *prevp;
- *prevp = dp;
- dp->hash = nhash;
- dp->repl = NULL;
- dp->nargs = 0;
- strcpy(dp->name, name);
+ break;
}
- return (dp);
+ prevp = &dp->link;
+ }
+ if (!delete)
+ {
+ dp = (DEFBUF*) getmem(sizeof (DEFBUF) + size);
+ dp->link = *prevp;
+ *prevp = dp;
+ dp->hash = nhash;
+ dp->repl = NULL;
+ dp->nargs = 0;
+ strcpy(dp->name, name);
+ }
+ return (dp);
}
#if OSL_DEBUG_LEVEL > 1
-void dumpdef(char *why)
+void dumpdef(char* why)
{
- DEFBUF *dp;
- DEFBUF **syp;
- FILE *pRememberOut = NULL;
-
- if ( bDumpDefs ) /*ER */
+ DEFBUF* dp;
+ DEFBUF** syp;
+ FILE* pRememberOut = NULL;
+
+ if ( bDumpDefs ) /*ER */
+ {
+ pRememberOut = pCppOut;
+ pCppOut = pDefOut;
+ }
+ fprintf( pCppOut, "CPP symbol table dump %s\n", why);
+ for (syp = symtab; syp < &symtab[SBSIZE]; syp++)
+ {
+ if ((dp = *syp) != (DEFBUF*) NULL)
{
- pRememberOut = pCppOut;
- pCppOut = pDefOut;
- }
- fprintf( pCppOut, "CPP symbol table dump %s\n", why);
- for (syp = symtab; syp < &symtab[SBSIZE]; syp++) {
- if ((dp = *syp) != (DEFBUF *) NULL) {
- fprintf( pCppOut, "symtab[%" SAL_PRI_PTRDIFFT "d]\n", (syp - symtab));
- do {
- dumpadef((char *) NULL, dp);
- } while ((dp = dp->link) != (DEFBUF *) NULL);
+ fprintf( pCppOut, "symtab[%" SAL_PRI_PTRDIFFT "d]\n", (syp - symtab));
+ do
+ {
+ dumpadef((char*) NULL, dp);
}
+ while ((dp = dp->link) != (DEFBUF*) NULL);
}
- if ( bDumpDefs )
- {
- fprintf( pCppOut, "\n");
- pCppOut = pRememberOut;
- }
+ }
+ if ( bDumpDefs )
+ {
+ fprintf( pCppOut, "\n");
+ pCppOut = pRememberOut;
+ }
}
-void dumpadef(char *why, DEFBUF *dp)
+void dumpadef(char* why, DEFBUF* dp)
{
- char *cp;
- int c;
- FILE *pRememberOut = NULL;
+ char* cp;
+ int c;
+ FILE* pRememberOut = NULL;
/*ER dump #define's to pDefOut */
- if ( bDumpDefs )
+ if ( bDumpDefs )
+ {
+ pRememberOut = pCppOut;
+ pCppOut = pDefOut;
+ }
+ fprintf( pCppOut, " \"%s\" [%d]", dp->name, dp->nargs);
+ if (why != NULL)
+ fprintf( pCppOut, " (%s)", why);
+ if (dp->repl != NULL)
+ {
+ fprintf( pCppOut, " => ");
+ for (cp = dp->repl; (c = *cp++ & 0xFF) != EOS;)
{
- pRememberOut = pCppOut;
- pCppOut = pDefOut;
- }
- fprintf( pCppOut, " \"%s\" [%d]", dp->name, dp->nargs);
- if (why != NULL)
- fprintf( pCppOut, " (%s)", why);
- if (dp->repl != NULL) {
- fprintf( pCppOut, " => ");
- for (cp = dp->repl; (c = *cp++ & 0xFF) != EOS;) {
#ifdef SOLAR
- if (c == DEL) {
- c = *cp++ & 0xFF;
- if( c == EOS ) break;
- fprintf( pCppOut, "<%%%d>", c - MAC_PARM);
- }
+ if (c == DEL)
+ {
+ c = *cp++ & 0xFF;
+ if( c == EOS ) break;
+ fprintf( pCppOut, "<%%%d>", c - MAC_PARM);
+ }
#else
- if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC))
- fprintf( pCppOut, "<%%%d>", c - MAC_PARM);
+ if (c >= MAC_PARM && c <= (MAC_PARM + PAR_MAC))
+ fprintf( pCppOut, "<%%%d>", c - MAC_PARM);
#endif
- else if (isprint(c) || c == '\n' || c == '\t')
- PUTCHAR(c);
- else if (c < ' ')
- fprintf( pCppOut, "<^%c>", c + '@');
- else
- fprintf( pCppOut, "<\\0%o>", c);
- }
+ else if (isprint(c) || c == '\n' || c == '\t')
+ PUTCHAR(c);
+ else if (c < ' ')
+ fprintf( pCppOut, "<^%c>", c + '@');
+ else
+ fprintf( pCppOut, "<\\0%o>", c);
+ }
/*ER evaluate macros to pDefOut */
#ifdef EVALDEFS
- if ( bDumpDefs && !bIsInEval && dp->nargs <= 0 )
+ if ( bDumpDefs && !bIsInEval && dp->nargs <= 0 )
+ {
+ FILEINFO* infileSave = infile;
+ char* tokenSave = savestring( token );
+ char* workSave = savestring( work );
+ int lineSave = line;
+ int wronglineSave = wrongline;
+ int recursionSave = recursion;
+ FILEINFO* file;
+ EVALTYPE valEval;
+
+ bIsInEval = 1;
+ infile = NULL; /* start from scrap */
+ line = 0;
+ wrongline = 0;
+ *token = EOS;
+ *work = EOS;
+ recursion = 0;
+ file = getfile( strlen( dp->repl ), dp->name );
+ strcpy( file->buffer, dp->repl );
+ fprintf( pCppOut, " ===> ");
+ nEvalOff = 0;
+ cppmain(); /* get() frees also *file */
+ valEval = 0;
+ if ( 0 == evaluate( EvalBuf, &valEval ) )
{
- FILEINFO *infileSave = infile;
- char *tokenSave = savestring( token );
- char *workSave = savestring( work );
- int lineSave = line;
- int wronglineSave = wrongline;
- int recursionSave = recursion;
- FILEINFO *file;
- EVALTYPE valEval;
-
- bIsInEval = 1;
- infile = NULL; /* start from scrap */
- line = 0;
- wrongline = 0;
- *token = EOS;
- *work = EOS;
- recursion = 0;
- file = getfile( strlen( dp->repl ), dp->name );
- strcpy( file->buffer, dp->repl );
- fprintf( pCppOut, " ===> ");
- nEvalOff = 0;
- cppmain(); /* get() frees also *file */
- valEval = 0;
- if ( 0 == evaluate( EvalBuf, &valEval ) )
- {
#ifdef EVALFLOATS
- if ( valEval != (EVALTYPE)((long)valEval ) )
- fprintf( pCppOut, " ==eval=> %f", valEval );
- else
+ if ( valEval != (EVALTYPE)((long)valEval ) )
+ fprintf( pCppOut, " ==eval=> %f", valEval );
+ else
#endif
- fprintf( pCppOut, " ==eval=> %ld", (long)valEval );
- }
- recursion = recursionSave;
- wrongline = wronglineSave;
- line = lineSave;
- strcpy( work, workSave );
- free( workSave );
- strcpy( token, tokenSave );
- free( tokenSave );
- infile = infileSave;
- bIsInEval = 0;
+ fprintf( pCppOut, " ==eval=> %ld", (long)valEval );
}
-#endif
- }
- else {
- fprintf( pCppOut, ", no replacement.");
+ recursion = recursionSave;
+ wrongline = wronglineSave;
+ line = lineSave;
+ strcpy( work, workSave );
+ free( workSave );
+ strcpy( token, tokenSave );
+ free( tokenSave );
+ infile = infileSave;
+ bIsInEval = 0;
}
- PUTCHAR('\n');
- if ( bDumpDefs )
- pCppOut = pRememberOut;
+#endif
+ }
+ else
+ {
+ fprintf( pCppOut, ", no replacement.");
+ }
+ PUTCHAR('\n');
+ if ( bDumpDefs )
+ pCppOut = pRememberOut;
}
#endif
@@ -754,269 +794,290 @@ void dumpadef(char *why, DEFBUF *dp)
* G E T
*/
-int
-get()
/*
* Return the next character from a macro or the current file.
* Handle end of file from #include files.
*/
+int get()
{
- int c;
- FILEINFO *file;
- int popped; /* Recursion fixup */
-
- popped = 0;
-get_from_file:
- if ((file = infile) == NULL)
- return (EOF_CHAR);
-newline:
-
+ int c;
+ FILEINFO* file;
+ int popped; /* Recursion fixup */
+
+ popped = 0;
+ get_from_file:
+ if ((file = infile) == NULL)
+ return (EOF_CHAR);
+ newline:
+
+ /*
+ * Read a character from the current input line or macro.
+ * At EOS, either finish the current macro (freeing temp.
+ * storage) or read another line from the current input file.
+ * At EOF, exit the current file (#include) or, at EOF from
+ * the cpp input file, return EOF_CHAR to finish processing.
+ */
+ if ((c = *file->bptr++ & 0xFF) == EOS)
+ {
/*
- * Read a character from the current input line or macro.
- * At EOS, either finish the current macro (freeing temp.
- * storage) or read another line from the current input file.
- * At EOF, exit the current file (#include) or, at EOF from
- * the cpp input file, return EOF_CHAR to finish processing.
+ * Nothing in current line or macro. Get next line (if
+ * input from a file), or do end of file/macro processing.
+ * In the latter case, jump back to restart from the top.
*/
- if ((c = *file->bptr++ & 0xFF) == EOS) {
- /*
- * Nothing in current line or macro. Get next line (if
- * input from a file), or do end of file/macro processing.
- * In the latter case, jump back to restart from the top.
- */
- if (file->fp == NULL) { /* NULL if macro */
- popped++;
- recursion -= file->unrecur;
- if (recursion < 0)
- recursion = 0;
- infile = file->parent; /* Unwind file chain */
- }
- else { /* Else get from a file */
- if ((file->bptr = fgets(file->buffer, NBUFF, file->fp))
- != NULL) {
+ if (file->fp == NULL) /* NULL if macro */
+ {
+ popped++;
+ recursion -= file->unrecur;
+ if (recursion < 0)
+ recursion = 0;
+ infile = file->parent; /* Unwind file chain */
+ }
+ else /* Else get from a file */
+ {
+ if ((file->bptr = fgets(file->buffer, NBUFF, file->fp)) != NULL)
+ {
#if OSL_DEBUG_LEVEL > 1
- if (debug > 1) { /* Dump it to stdout */
- fprintf( pCppOut, "\n#line %d (%s), %s",
- line, file->filename, file->buffer);
- }
-#endif
- goto newline; /* process the line */
+ if (debug > 1) /* Dump it to stdout */
+ {
+ fprintf( pCppOut, "\n#line %d (%s), %s",
+ line, file->filename, file->buffer);
}
- else {
- if( file->fp != stdin )
- fclose(file->fp); /* Close finished file */
- if ((infile = file->parent) != NULL) {
- /*
- * There is an "ungotten" newline in the current
- * infile buffer (set there by doinclude() in
- * cpp1.c). Thus, we know that the mainline code
- * is skipping over blank lines and will do a
- * #line at its convenience.
- */
- wrongline = TRUE; /* Need a #line now */
- }
+#endif
+ goto newline; /* process the line */
+ }
+ else
+ {
+ if( file->fp != stdin )
+ fclose(file->fp); /* Close finished file */
+ if ((infile = file->parent) != NULL)
+ {
+ /*
+ * There is an "ungotten" newline in the current
+ * infile buffer (set there by doinclude() in
+ * cpp1.c). Thus, we know that the mainline code
+ * is skipping over blank lines and will do a
+ * #line at its convenience.
+ */
+ wrongline = TRUE; /* Need a #line now */
}
}
- /*
- * Free up space used by the (finished) file or macro and
- * restart input from the parent file/macro, if any.
- */
- free(file->filename); /* Free name and */
- if (file->progname != NULL) /* if a #line was seen, */
- free(file->progname); /* free it, too. */
- free((char *) file); /* Free file space */
- if (infile == NULL) /* If at end of file */
- return (EOF_CHAR); /* Return end of file */
- line = infile->line; /* Reset line number */
- goto get_from_file; /* Get from the top. */
}
/*
- * Common processing for the new character.
+ * Free up space used by the (finished) file or macro and
+ * restart input from the parent file/macro, if any.
*/
- if (c == DEF_MAGIC && file->fp != NULL) /* Don't allow delete */
- goto newline; /* from a file */
- if (file->parent != NULL) { /* Macro or #include */
- if (popped != 0)
- file->parent->unrecur += popped;
- else {
- recursion -= file->parent->unrecur;
- if (recursion < 0)
- recursion = 0;
- file->parent->unrecur = 0;
- }
+ free(file->filename); /* Free name and */
+ if (file->progname != NULL) /* if a #line was seen, */
+ free(file->progname); /* free it, too. */
+ free((char*) file); /* Free file space */
+ if (infile == NULL) /* If at end of file */
+ return (EOF_CHAR); /* Return end of file */
+ line = infile->line; /* Reset line number */
+ goto get_from_file; /* Get from the top. */
+ }
+ /*
+ * Common processing for the new character.
+ */
+ if (c == DEF_MAGIC && file->fp != NULL) /* Don't allow delete */
+ goto newline; /* from a file */
+ if (file->parent != NULL) /* Macro or #include */
+ {
+ if (popped != 0)
+ file->parent->unrecur += popped;
+ else
+ {
+ recursion -= file->parent->unrecur;
+ if (recursion < 0)
+ recursion = 0;
+ file->parent->unrecur = 0;
}
+ }
#if (HOST == SYS_UNIX)
-/*ER*/ if (c == '\r')
-/*ER*/ return get(); /* DOS fuck */
+ if (c == '\r')
+ return get(); /* DOS fuck */
#endif
- if (c == '\n') /* Maintain current */
- ++line; /* line counter */
- if (instring) /* Strings just return */
- return (c); /* the character. */
- else if (c == '/') { /* Comment? */
- instring = TRUE; /* So get() won't loop */
-/*MM c++ comments */
-/*MM*/ c = get();
-/*MM*/ if ((c != '*') && (c != '/')) { /* Next byte '*'? */
- instring = FALSE; /* Nope, no comment */
- unget(); /* Push the char. back */
- return ('/'); /* Return the slash */
- }
- if (keepcomments) { /* If writing comments */
- PUTCHAR('/'); /* Write out the */
- /* initializer */
-/*MM*/ if( '*' == c )
- PUTCHAR('*');
-/*MM*/ else
-/*MM*/ PUTCHAR('/');
+ if (c == '\n') /* Maintain current */
+ ++line; /* line counter */
+ if (instring) /* Strings just return */
+ return (c); /* the character. */
+ else if (c == '/') /* Comment? */
+ {
+ instring = TRUE; /* So get() won't loop */
+
+ c = get();
+ if ((c != '*') && (c != '/')) /* Next byte '*'? */
+ {
+ instring = FALSE; /* Nope, no comment */
+ unget(); /* Push the char. back */
+ return ('/'); /* Return the slash */
+ }
+ if (keepcomments) /* If writing comments */
+ {
+ PUTCHAR('/'); /* Write out the */
+ /* initializer */
+ if( '*' == c )
+ PUTCHAR('*');
+ else
+ PUTCHAR('/');
+ }
+ if( '*' == c )
+ {
+ for (;;) /* Eat a comment */
+ {
+ c = get();
+ test:
+ if (keepcomments && c != EOF_CHAR)
+ cput(c);
+ switch (c)
+ {
+ case EOF_CHAR:
+ cerror("EOF in comment", NULLST);
+ return (EOF_CHAR);
- }
-/*MM*/ if( '*' == c ){
- for (;;) { /* Eat a comment */
- c = get();
- test: if (keepcomments && c != EOF_CHAR)
- cput(c);
- switch (c) {
- case EOF_CHAR:
- cerror("EOF in comment", NULLST);
- return (EOF_CHAR);
-
- case '/':
- if ((c = get()) != '*') /* Don't let comments */
- goto test; /* Nest. */
+ case '/':
+ if ((c = get()) != '*') /* Don't let comments */
+ goto test; /* Nest. */
#ifdef STRICT_COMMENTS
- cwarn("Nested comments", NULLST);
+ cwarn("Nested comments", NULLST);
#endif
- /* Fall into * stuff */
- case '*':
- if ((c = get()) != '/') /* If comment doesn't */
- goto test; /* end, look at next */
- instring = FALSE; /* End of comment, */
- if (keepcomments) { /* Put out the comment */
- cput(c); /* terminator, too */
- }
- /*
- * A comment is syntactically "whitespace" --
- * however, there are certain strange sequences
- * such as
- * #define foo(x) (something)
- * foo|* comment *|(123)
- * these are '/' ^ ^
- * where just returning space (or COM_SEP) will cause
- * problems. This can be "fixed" by overwriting the
- * '/' in the input line buffer with ' ' (or COM_SEP)
- * but that may mess up an error message.
- * So, we peek ahead -- if the next character is
- * "whitespace" we just get another character, if not,
- * we modify the buffer. All in the name of purity.
- */
- if (*file->bptr == '\n'
- || type[*file->bptr & 0xFF] == SPA)
- goto newline;
- return ((file->bptr[-1] = ' '));
-
- case '\n': /* we'll need a #line */
- if (!keepcomments)
- wrongline = TRUE; /* later... */
- default: /* Anything else is */
- break; /* Just a character */
- } /* End switch */
- } /* End comment loop */
- }
- else{ /* c++ comment */
-/*MM c++ comment*/
- for (;;) { /* Eat a comment */
- c = get();
- if (keepcomments && c != EOF_CHAR)
- cput(c);
- if( EOF_CHAR == c )
- return (EOF_CHAR);
- else if( '\n' == c ){
- instring = FALSE; /* End of comment, */
- return( c );
+ /* Fall into * stuff */
+ case '*':
+ if ((c = get()) != '/') /* If comment doesn't */
+ goto test; /* end, look at next */
+ instring = FALSE; /* End of comment, */
+ if (keepcomments) /* Put out the comment */
+ {
+ cput(c); /* terminator, too */
}
- }
- }
- } /* End if in comment */
- else if (!inmacro && c == '\\') { /* If backslash, peek */
- if ((c = get()) == '\n') { /* for a <nl>. If so, */
- wrongline = TRUE;
- goto newline;
- }
- else { /* Backslash anything */
- unget(); /* Get it later */
- return ('\\'); /* Return the backslash */
- }
+ /*
+ * A comment is syntactically "whitespace" --
+ * however, there are certain strange sequences
+ * such as
+ * #define foo(x) (something)
+ * foo|* comment *|(123)
+ * these are '/' ^ ^
+ * where just returning space (or COM_SEP) will cause
+ * problems. This can be "fixed" by overwriting the
+ * '/' in the input line buffer with ' ' (or COM_SEP)
+ * but that may mess up an error message.
+ * So, we peek ahead -- if the next character is
+ * "whitespace" we just get another character, if not,
+ * we modify the buffer. All in the name of purity.
+ */
+ if (*file->bptr == '\n' || type[*file->bptr & 0xFF] == SPA)
+ goto newline;
+ return ((file->bptr[-1] = ' '));
+
+ case '\n': /* we'll need a #line */
+ if (!keepcomments)
+ wrongline = TRUE; /* later... */
+ default: /* Anything else is */
+ break; /* Just a character */
+ } /* End switch */
+ } /* End comment loop */
}
- else if (c == '\f' || c == VT) /* Form Feed, Vertical */
- c = ' '; /* Tab are whitespace */
- else if (c == 0xef) /* eat up UTF-8 BOM */
+ else /* c++ comment */
{
- if((c = get()) == 0xbb)
+ for (;;) /* Eat a comment */
{
- if((c = get()) == 0xbf)
- {
- c = get();
- return c;
- }
- else
+ c = get();
+ if (keepcomments && c != EOF_CHAR)
+ cput(c);
+ if( EOF_CHAR == c )
+ return (EOF_CHAR);
+ else if( '\n' == c )
{
- unget();
- unget();
- return 0xef;
+ instring = FALSE; /* End of comment, */
+ return( c );
}
}
+ }
+ } /* End if in comment */
+ else if (!inmacro && c == '\\') /* If backslash, peek */
+ {
+ if ((c = get()) == '\n') /* for a <nl>. If so, */
+ {
+ wrongline = TRUE;
+ goto newline;
+ }
+ else /* Backslash anything */
+ {
+ unget(); /* Get it later */
+ return ('\\'); /* Return the backslash */
+ }
+ }
+ else if (c == '\f' || c == VT) /* Form Feed, Vertical */
+ {
+ c = ' '; /* Tab are whitespace */
+ }
+ else if (c == 0xef) /* eat up UTF-8 BOM */
+ {
+ if((c = get()) == 0xbb)
+ {
+ if((c = get()) == 0xbf)
+ {
+ c = get();
+ return c;
+ }
else
{
unget();
+ unget();
return 0xef;
}
}
- return (c); /* Just return the char */
+ else
+ {
+ unget();
+ return 0xef;
+ }
+ }
+ return (c); /* Just return the char */
}
-
-void unget()
+
/*
* Backup the pointer to reread the last character. Fatal error
* (code bug) if we backup too far. unget() may be called,
* without problems, at end of file. Only one character may
* be ungotten. If you need to unget more, call ungetstring().
*/
+void unget()
{
- FILEINFO *file;
-
- if ((file = infile) == NULL)
- return; /* Unget after EOF */
- if (--file->bptr < file->buffer)
- cfatal("Too much pushback", NULLST);
- if (*file->bptr == '\n') /* Ungetting a newline? */
- --line; /* Unget the line number, too */
+ FILEINFO* file;
+
+ if ((file = infile) == NULL)
+ return; /* Unget after EOF */
+ if (--file->bptr < file->buffer)
+ cfatal("Too much pushback", NULLST);
+ if (*file->bptr == '\n') /* Ungetting a newline? */
+ --line; /* Unget the line number, too */
}
-void ungetstring(char* text)
/*
* Push a string back on the input stream. This is done by treating
* the text as if it were a macro.
*/
+void ungetstring(char* text)
{
- FILEINFO *file;
- file = getfile(strlen(text) + 1, "");
- strcpy(file->buffer, text);
+ FILEINFO* file;
+ file = getfile(strlen(text) + 1, "");
+ strcpy(file->buffer, text);
}
-int
-cget()
/*
* Get one character, absorb "funny space" after comments or
* token concatenation
*/
+int cget()
{
- int c;
-
- do {
- c = get();
- } while (c == TOK_SEP);
- return (c);
+ int c;
+
+ do
+ {
+ c = get();
+ }
+ while (c == TOK_SEP);
+ return (c);
}
/*
@@ -1026,84 +1087,87 @@ cget()
* are shorter than char *'s.
*/
-static void domsg(char* severity, char* format, void* arg)
/*
* Print filenames, macro names, and line numbers for error messages.
*/
+static void domsg(char* severity, char* format, void* arg)
{
- char *tp;
- FILEINFO *file;
-
- fprintf(stderr, "%sline %d, %s: ", MSG_PREFIX, line, &severity[1]);
- if (*severity == 'S')
- fprintf(stderr, format, (char *)arg);
+ char* tp;
+ FILEINFO* file;
+
+ fprintf(stderr, "%sline %d, %s: ", MSG_PREFIX, line, &severity[1]);
+ if (*severity == 'S')
+ fprintf(stderr, format, (char*)arg);
+ else
+ fprintf(stderr, format, *((int*)arg) );
+ putc('\n', stderr);
+ if ((file = infile) == NULL)
+ return; /* At end of file */
+ if (file->fp != NULL)
+ {
+ tp = file->buffer; /* Print current file */
+ fprintf(stderr, "%s", tp); /* name, making sure */
+ if (tp[strlen(tp) - 1] != '\n') /* there's a newline */
+ putc('\n', stderr);
+ }
+ while ((file = file->parent) != NULL) /* Print #includes, too */
+ {
+ if (file->fp == NULL)
+ fprintf(stderr, "from macro %s\n", file->filename);
else
- fprintf(stderr, format, *((int *)arg) );
- putc('\n', stderr);
- if ((file = infile) == NULL)
- return; /* At end of file */
- if (file->fp != NULL) {
- tp = file->buffer; /* Print current file */
- fprintf(stderr, "%s", tp); /* name, making sure */
- if (tp[strlen(tp) - 1] != '\n') /* there's a newline */
- putc('\n', stderr);
- }
- while ((file = file->parent) != NULL) { /* Print #includes, too */
- if (file->fp == NULL)
- fprintf(stderr, "from macro %s\n", file->filename);
- else {
- tp = file->buffer;
- fprintf(stderr, "from file %s, line %d:\n%s",
+ {
+ tp = file->buffer;
+ fprintf(stderr, "from file %s, line %d:\n%s",
(file->progname != NULL)
- ? file->progname : file->filename,
+ ? file->progname : file->filename,
file->line, tp);
- if (tp[strlen(tp) - 1] != '\n')
- putc('\n', stderr);
- }
+ if (tp[strlen(tp) - 1] != '\n')
+ putc('\n', stderr);
}
+ }
}
-void cerror(char* format, char* sarg)
/*
* Print a normal error message, string argument.
*/
+void cerror(char* format, char* sarg)
{
- domsg("SError", format, sarg);
- errors++;
+ domsg("SError", format, sarg);
+ errors++;
}
-void cierror(char* format, int narg)
/*
* Print a normal error message, numeric argument.
*/
+void cierror(char* format, int narg)
{
- domsg("IError", format, &narg);
- errors++;
+ domsg("IError", format, &narg);
+ errors++;
}
-void cfatal(char* format, char* sarg)
/*
* A real disaster
*/
+void cfatal(char* format, char* sarg)
{
- domsg("SFatal error", format, sarg);
- exit(IO_ERROR);
+ domsg("SFatal error", format, sarg);
+ exit(IO_ERROR);
}
-void cwarn(char* format, char* sarg)
/*
* A non-fatal error, string argument.
*/
+void cwarn(char* format, char* sarg)
{
- domsg("SWarning", format, sarg);
+ domsg("SWarning", format, sarg);
}
-void ciwarn(char* format, int narg)
/*
* A non-fatal error, numeric argument.
*/
+void ciwarn(char* format, int narg)
{
- domsg("IWarning", format, &narg);
+ domsg("IWarning", format, &narg);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */