From 5f9a1992570e20fee4b0dc2a09899bcc686f8d6f Mon Sep 17 00:00:00 2001 From: carl Date: Sat, 2 Mar 2019 01:36:11 +0800 Subject: [PATCH] CPP ISO C90 compatibility and conversion. --- lang/cem/cpp.ansi/LLlex.c | 34 +++++++----- lang/cem/cpp.ansi/LLlex.h | 13 +++++ lang/cem/cpp.ansi/LLmessage.c | 11 ++-- lang/cem/cpp.ansi/ch3bin.c | 7 +-- lang/cem/cpp.ansi/ch3mon.c | 5 +- lang/cem/cpp.ansi/class.h | 12 ++--- lang/cem/cpp.ansi/domacro.c | 95 ++++++++++++++++++++-------------- lang/cem/cpp.ansi/error.c | 24 ++++----- lang/cem/cpp.ansi/expr.c | 5 +- lang/cem/cpp.ansi/expression.g | 3 ++ lang/cem/cpp.ansi/init.c | 8 +-- lang/cem/cpp.ansi/input.c | 10 ++-- lang/cem/cpp.ansi/input.h | 9 +++- lang/cem/cpp.ansi/main.c | 40 ++++++++------ lang/cem/cpp.ansi/options.c | 12 ++--- lang/cem/cpp.ansi/preprocess.c | 14 +++-- lang/cem/cpp.ansi/replace.c | 82 +++++++++++++---------------- lang/cem/cpp.ansi/replace.str | 13 +++++ lang/cem/cpp.ansi/skip.c | 11 ++-- 19 files changed, 236 insertions(+), 172 deletions(-) diff --git a/lang/cem/cpp.ansi/LLlex.c b/lang/cem/cpp.ansi/LLlex.c index 40c6c57dc..583db777b 100644 --- a/lang/cem/cpp.ansi/LLlex.c +++ b/lang/cem/cpp.ansi/LLlex.c @@ -15,7 +15,9 @@ #include "idf.h" #include "LLlex.h" #include "Lpars.h" +#include "replace.h" #include "class.h" +#include "error.h" #include "bits.h" #define BUFSIZ 1024 @@ -30,20 +32,26 @@ int AccFileSpecifier = 0; /* return filespecifier <...> */ int LexSave = 0; /* last character read by GetChar */ extern int InputLevel; /* # of current macro expansions */ -extern char* string_token(); -extern arith char_constant(); + #define FLG_ESEEN 0x01 /* possibly a floating point number */ #define FLG_DOTSEEN 0x02 /* certainly a floating point number */ -void skipcomment(); -void skiplinecomment(void); -int LLlex() +/* Private forward definitions */ + +static arith char_constant(char*); +static char* string_token(char *, int); +static int quoted(register int); +static int val_in_base(register int, int); +static int trigraph(void); + + +int LLlex(void) { return (DOT != EOF) ? GetToken(&dot) : EOF; } -int GetToken(ptok) register struct token* ptok; +int GetToken(register struct token* ptok) { /* GetToken() is the actual token recognizer. It calls the control line interpreter if it encounters a "\n{w}*#" @@ -385,7 +393,7 @@ again: /* rescan the input after an error or replacement */ /*NOTREACHED*/ } -void skipcomment() +void skipcomment(void) { /* The last character read has been the '*' of '/_*'. The characters, except NL and EOI, between '/_*' and the first @@ -437,7 +445,7 @@ void skiplinecomment(void) } } -arith char_constant(nm) char* nm; +static arith char_constant(char* nm) { register arith val = 0; register int ch; @@ -471,7 +479,7 @@ arith char_constant(nm) char* nm; return val; } -char* string_token(nm, stop_char) char* nm; +static char* string_token(char *nm, int stop_char) { register int ch; register int str_size; @@ -504,7 +512,7 @@ char* string_token(nm, stop_char) char* nm; return str; } -int quoted(ch) register int ch; +static int quoted(register int ch) { /* quoted() replaces an escaped character sequence by the character meant. @@ -567,7 +575,7 @@ int quoted(ch) register int ch; return ch & 0377; } -int val_in_base(ch, base) register int ch; +static int val_in_base(register int ch, int base) { switch (base) { @@ -583,7 +591,7 @@ int val_in_base(ch, base) register int ch; } } -int GetChar() +int GetChar(void) { /* The routines GetChar and trigraph parses the trigraph sequences and removes occurences of \\\n. @@ -612,7 +620,7 @@ again: return (LexSave = ch); } -int trigraph() +static int trigraph(void) { register int ch; diff --git a/lang/cem/cpp.ansi/LLlex.h b/lang/cem/cpp.ansi/LLlex.h index 6c7e7ee07..a46c6861d 100644 --- a/lang/cem/cpp.ansi/LLlex.h +++ b/lang/cem/cpp.ansi/LLlex.h @@ -4,6 +4,8 @@ */ /* $Id$ */ /* D E F I N I T I O N S F O R T H E L E X I C A L A N A L Y Z E R */ +#ifndef LLLEX_H_ +#define LLLEX_H_ /* A token from the input stream is represented by an integer, called a "symbol", but it may have other information associated @@ -44,3 +46,14 @@ extern int err_occurred; /* "error.c" */ #define DOT dot.tk_symb #define EOF (-1) + +/* Public function declarations */ + +int LLlex(void); +int GetToken(register struct token* ptok); +void skipcomment(void); +void skiplinecomment(void); +/* Get next character input, with trigraph parsing and newline */ +int GetChar(void); + +#endif /* LLLLEX_H_ */ diff --git a/lang/cem/cpp.ansi/LLmessage.c b/lang/cem/cpp.ansi/LLmessage.c index 92b507097..c7259d3f1 100644 --- a/lang/cem/cpp.ansi/LLmessage.c +++ b/lang/cem/cpp.ansi/LLmessage.c @@ -8,15 +8,20 @@ #include "arith.h" #include "LLlex.h" #include "Lpars.h" +#include "skip.h" +#include "error.h" extern char *symbol2str(); -LLmessage(tk) { +void LLmessage(int tk) +{ if (tk < 0) error("garbage at end of line"); - else if (tk) { + else if (tk) + { error("%s missing", symbol2str(tk)); - if (DOT != EOF) SkipToNewLine(); + if (DOT != EOF) + SkipToNewLine(); DOT = EOF; } else diff --git a/lang/cem/cpp.ansi/ch3bin.c b/lang/cem/cpp.ansi/ch3bin.c index c458487a5..8caf9b3ff 100644 --- a/lang/cem/cpp.ansi/ch3bin.c +++ b/lang/cem/cpp.ansi/ch3bin.c @@ -7,10 +7,11 @@ #include "Lpars.h" #include "arith.h" +#include "ch3bin.h" +#include "skip.h" +#include "error.h" -ch3bin(pval, pis_uns, oper, val, is_uns) - register arith *pval, val; - int oper, is_uns, *pis_uns; +void ch3bin(register arith *pval, int *pis_uns, int oper, register arith val, int is_uns) { if (is_uns) *pis_uns = 1; switch (oper) { diff --git a/lang/cem/cpp.ansi/ch3mon.c b/lang/cem/cpp.ansi/ch3mon.c index a5f6095b7..f4368242c 100644 --- a/lang/cem/cpp.ansi/ch3mon.c +++ b/lang/cem/cpp.ansi/ch3mon.c @@ -5,13 +5,12 @@ /* $Id$ */ /* EVALUATION OF MONADIC OPERATORS */ +#include "ch3mon.h" #include "Lpars.h" #include "arith.h" /*ARGSUSED2*/ -ch3mon(oper, pval, puns) - register arith *pval; - int *puns; +void ch3mon(int oper, register arith *pval, int *puns) { switch (oper) { case '~': diff --git a/lang/cem/cpp.ansi/class.h b/lang/cem/cpp.ansi/class.h index 09e03d893..5046ddfdf 100644 --- a/lang/cem/cpp.ansi/class.h +++ b/lang/cem/cpp.ansi/class.h @@ -10,7 +10,7 @@ At present such a class number is supposed to fit in 4 bits. */ -#define class(ch) ((tkclass)[ch]) +#define class(ch) ((tkclass)[(unsigned int)ch]) /* Being the start of a token is, fortunately, a mutual exclusive property, so, as there are less than 16 classes they can be @@ -37,11 +37,11 @@ class. This is implemented as a collection of tables to speed up the decision whether a character has a special meaning. */ -#define in_idf(ch) (inidf[ch]) -#define is_oct(ch) (isoct[ch]) -#define is_dig(ch) (isdig[ch]) -#define is_hex(ch) (ishex[ch]) -#define is_wsp(ch) (iswsp[ch]) +#define in_idf(ch) (inidf[(unsigned int)ch]) +#define is_oct(ch) (isoct[(unsigned int)ch]) +#define is_dig(ch) (isdig[(unsigned int)ch]) +#define is_hex(ch) (ishex[(unsigned int)ch]) +#define is_wsp(ch) (iswsp[(unsigned int)ch]) extern char tkclass[]; extern char inidf[], isoct[], isdig[], ishex[], iswsp[]; diff --git a/lang/cem/cpp.ansi/domacro.c b/lang/cem/cpp.ansi/domacro.c index 39c2d8482..b382a0c60 100644 --- a/lang/cem/cpp.ansi/domacro.c +++ b/lang/cem/cpp.ansi/domacro.c @@ -8,22 +8,26 @@ #include #include #include +#include "domacro.h" #include "arith.h" #include "LLlex.h" #include "Lpars.h" #include "idf.h" #include "input.h" +#include "error.h" #include "parameters.h" +#include "preprocess.h" #include #include "class.h" #include "macro.h" +#include "LLlex.h" #include "bits.h" +#include "skip.h" #include "replace.h" extern char options[]; extern char** inctable; /* list of include directories */ -extern char* getwdir(); char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ /* 1 if a corresponding ELSE has been */ /* encountered. */ @@ -33,10 +37,33 @@ int svnestlevel[30] = { -1 }; int nestcount; extern int do_preprocess; -void macro_def(); -void do_define(); - -char* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */ +/* Internal declarations */ + + +static void do_define(void); +static void do_elif(void); +static void do_else(void); +static void push_if(void); +static void do_endif(void); +static void do_if(void); +static void do_ifdef(int); +static void do_include(void); +static void do_line(unsigned int); +static int find_name(char* , char* []); +static char* get_text(char* [], int* ); +static int getparams(char* [], char []); +static int ifexpr(void); +static int macroeq(register char*, register char *); +static void skip_block(int); +static void do_error(void); + +/* External dependencies to C files with no include files */ +extern void If_expr(void); +extern void add_dependency(char *); + + +char* GetIdentifier(int skiponerr /* skip the rest of the line on error */ + ) { /* Returns a pointer to the identifier that is read from the input stream. When the input does not contain an @@ -62,16 +89,8 @@ char* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on er return tk.tk_str; } -/* domacro() is the control line interpreter. The '#' has already - been read by the lexical analyzer by which domacro() is called. - The token appearing directly after the '#' is obtained by calling - the basic lexical analyzing function GetToken() and is interpreted - to perform the action belonging to that token. - An error message is produced when the token is not recognized. - Pragma's are handled by do_pragma(). They are passed on to the - compiler. -*/ -domacro() + +void domacro(void) { struct token tk; /* the token itself */ register struct idf* id; @@ -156,7 +175,7 @@ domacro() } } -void skip_block(to_endif) int to_endif; +static void skip_block(int to_endif) { /* skip_block() skips the input from 1) a false #if, #ifdef, #ifndef or #elif until the @@ -303,9 +322,9 @@ void skip_block(to_endif) int to_endif; } } -ifexpr() +static int ifexpr(void) { - /* ifexpr() returns whether the restricted constant + /* Returns whether the restricted constant expression following #if or #elif evaluates to true. This is done by calling the LLgen generated subparser for constant expressions. The result of this expression will @@ -324,7 +343,7 @@ ifexpr() return (errors == err_occurred) && (ifval != (arith)0); } -do_include() +static void do_include(void) { /* do_include() performs the inclusion of a file. */ @@ -368,7 +387,7 @@ do_include() } } -void do_define() +static void do_define(void) { /* do_define() interprets a #define control line. */ @@ -378,8 +397,7 @@ void do_define() char parbuf[PARBUFSIZE]; /* names of formals */ char* repl_text; /* start of the replacement text */ int length; /* length of the replacement text */ - register ch; - char* get_text(); + register int ch; /* read the #defined macro's name */ if (!(str = GetIdentifier(1))) @@ -411,7 +429,7 @@ void do_define() LineNumber++; } -push_if() +static void push_if(void) { if (nestlevel >= IFDEPTH) fatal("too many nested #if/#ifdef/#ifndef"); @@ -419,7 +437,7 @@ push_if() ifstack[++nestlevel] = 0; } -do_elif() +static void do_elif(void) { if (nestlevel <= svnestlevel[nestcount]) { @@ -439,7 +457,7 @@ do_elif() } } -do_else() +static void do_else(void) { if (SkipToNewLine()) { @@ -459,7 +477,7 @@ do_else() } } -do_endif() +static void do_endif(void) { if (SkipToNewLine()) { @@ -474,14 +492,14 @@ do_endif() nestlevel--; } -do_if() +static void do_if(void) { push_if(); if (!ifexpr()) /* a false #if/#elif expression */ skip_block(0); } -do_ifdef(how) +static void do_ifdef(int how) { register struct idf* id; register char* str; @@ -513,7 +531,7 @@ do_ifdef(how) } /* argstr != NULL when the undef came from a -U option */ -do_undef(argstr) char* argstr; +void do_undef(char* argstr) { register struct idf* id; register char* str = argstr; @@ -548,7 +566,7 @@ do_undef(argstr) char* argstr; error("illegal #undef construction"); } -do_error() +static void do_error(void) { int len; char* get_text(); @@ -559,8 +577,7 @@ do_error() LineNumber++; } -int getparams(buf, parbuf) char* buf[]; -char parbuf[]; +static int getparams(char* buf[], char parbuf[]) { /* getparams() reads the formal parameter list of a macro definition. @@ -633,8 +650,7 @@ char parbuf[]; /*NOTREACHED*/ } -void macro_def(id, text, nformals, length, flags) register struct idf* id; -char* text; +void macro_def(register struct idf* id, char* text, int nformals, int length, int flags) { register struct macro* newdef = id->id_macro; @@ -681,7 +697,7 @@ char* text; newdef->mc_flag = flags; /* special flags */ } -int find_name(nm, index) char *nm, *index[]; +static int find_name(char* nm, char *index[]) { /* find_name() returns the index of "nm" in the namelist "index" if it can be found there. 0 is returned if it is @@ -698,8 +714,7 @@ int find_name(nm, index) char *nm, *index[]; #define BLANK(ch) ((ch == ' ') || (ch == '\t')) -char* get_text(formals, length) char* formals[]; -int* length; +static char* get_text(char* formals[], int* length) { /* get_text() copies the replacement text of a macro definition with zero, one or more parameters, thereby @@ -811,7 +826,7 @@ int* length; add2repl(repl, ' '); } /* construct the formal parameter mark or identifier */ - if (n = find_name(id_buf, formals)) + if ((n = find_name(id_buf, formals))) add2repl(repl, FORMALP | (char)n); else { @@ -873,7 +888,7 @@ int* length; as strings, without taking care of the leading and trailing blanks (spaces and tabs). */ -macroeq(s, t) register char* s, *t; +static int macroeq(register char* s, register char *t) { /* skip leading spaces */ @@ -902,7 +917,7 @@ macroeq(s, t) register char* s, *t; } } -do_line(l) unsigned int l; +static void do_line(unsigned int l) { struct token tk; int t = GetToken(&tk); diff --git a/lang/cem/cpp.ansi/error.c b/lang/cem/cpp.ansi/error.c index 0920976b8..bdaf6fa47 100644 --- a/lang/cem/cpp.ansi/error.c +++ b/lang/cem/cpp.ansi/error.c @@ -14,6 +14,7 @@ #include "parameters.h" #include "arith.h" +#include "print.h" #include "LLlex.h" /* This file contains the (non-portable) error-message and diagnostic @@ -23,8 +24,7 @@ int err_occurred; -err_hdr(s) - char *s; +static void err_hdr(char *s) { if (FileName) { fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s); @@ -34,7 +34,7 @@ err_hdr(s) #if __STDC__ /*VARARGS*/ -error(char *fmt, ...) +void error(char *fmt, ...) { va_list ap; @@ -47,7 +47,7 @@ error(char *fmt, ...) } /*VARARGS*/ -warning(char *fmt, ...) +void warning(char *fmt, ...) { va_list ap; @@ -59,7 +59,7 @@ warning(char *fmt, ...) } /*VARARGS*/ -strict(char *fmt, ...) +void strict(char *fmt, ...) { va_list ap; @@ -71,7 +71,7 @@ strict(char *fmt, ...) } /*VARARGS*/ -crash(char *fmt, ...) +void crash(char *fmt, ...) { va_list ap; @@ -84,7 +84,7 @@ crash(char *fmt, ...) } /*VARARGS*/ -fatal(char *fmt, ...) +void fatal(char *fmt, ...) { va_list ap; @@ -97,7 +97,7 @@ fatal(char *fmt, ...) } #else /*VARARGS*/ -error(va_alist) +void error(va_alist) va_dcl { char *fmt; @@ -113,7 +113,7 @@ error(va_alist) } /*VARARGS*/ -warning(va_alist) +void warning(va_alist) va_dcl { char *fmt; @@ -128,7 +128,7 @@ warning(va_alist) } /*VARARGS*/ -strict(va_alist) +void strict(va_alist) va_dcl { char *fmt; @@ -143,7 +143,7 @@ strict(va_alist) } /*VARARGS*/ -crash(va_alist) +void crash(va_alist) va_dcl { char *fmt; @@ -159,7 +159,7 @@ crash(va_alist) } /*VARARGS*/ -fatal(va_alist) +void fatal(va_alist) va_dcl { char *fmt; diff --git a/lang/cem/cpp.ansi/expr.c b/lang/cem/cpp.ansi/expr.c index 7b02643ba..fc933cc23 100644 --- a/lang/cem/cpp.ansi/expr.c +++ b/lang/cem/cpp.ansi/expr.c @@ -5,11 +5,10 @@ /* $Id$ */ /* OPERATOR HANDLING */ +#include "expr.h" #include "Lpars.h" -int -rank_of(oper) - int oper; +int rank_of(int oper) { /* The rank of the operator oper is returned. */ diff --git a/lang/cem/cpp.ansi/expression.g b/lang/cem/cpp.ansi/expression.g index 384ea18a6..351a7c51a 100644 --- a/lang/cem/cpp.ansi/expression.g +++ b/lang/cem/cpp.ansi/expression.g @@ -10,6 +10,9 @@ { #include "arith.h" #include "LLlex.h" +#include "ch3mon.h" +#include "ch3bin.h" +#include "expr.h" extern arith ifval; } diff --git a/lang/cem/cpp.ansi/init.c b/lang/cem/cpp.ansi/init.c index 810b4204c..a0aeb8f27 100644 --- a/lang/cem/cpp.ansi/init.c +++ b/lang/cem/cpp.ansi/init.c @@ -13,7 +13,10 @@ #include "time.h" #include "class.h" #include "macro.h" +#include "print.h" +#include "error.h" #include "idf.h" +#include "domacro.h" struct mkey { char *mk_reserved; @@ -34,9 +37,8 @@ struct mkey { {0, K_UNKNOWN} }; -char *sprint(); -init_pp() +void init_pp(void) { static char *months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -74,7 +76,7 @@ init_pp() /* __DATE__ */ sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon], tp->tm_mday, tp->tm_year+1900); - /* if (tp->tm_mday < 10) dbuf[5] = ' '; /* hack */ + /* if (tp->tm_mday < 10) dbuf[5] = ' '; */ /* hack */ macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF); /* __TIME__ */ diff --git a/lang/cem/cpp.ansi/input.c b/lang/cem/cpp.ansi/input.c index 8e7de52f4..161f065eb 100644 --- a/lang/cem/cpp.ansi/input.c +++ b/lang/cem/cpp.ansi/input.c @@ -9,6 +9,8 @@ #include #include "file_info.h" #include "input.h" +#include "error.h" +#include "replace.h" #define INP_PUSHBACK 3 #define INP_TYPE struct file_info @@ -17,9 +19,7 @@ struct file_info finfo; #include #include -char * -getwdir(fn) - register char *fn; +char *getwdir(register char *fn) { register char *p; char *strrchr(); @@ -44,7 +44,7 @@ getwdir(fn) int NoUnstack; int InputLevel; -AtEoIT() +int AtEoIT(void) { InputLevel--; /* if (NoUnstack) warning("unexpected EOF"); ??? */ @@ -52,7 +52,7 @@ AtEoIT() return 0; } -AtEoIF() +int AtEoIF(void) { extern int nestlevel; extern int nestcount; diff --git a/lang/cem/cpp.ansi/input.h b/lang/cem/cpp.ansi/input.h index 55a79acde..f2634d953 100644 --- a/lang/cem/cpp.ansi/input.h +++ b/lang/cem/cpp.ansi/input.h @@ -11,4 +11,11 @@ #define UnGetChar() ((LexSave != EOI) ? ChPushBack(LexSave) : 0) extern int LexSave; /* last character read by GetChar */ -extern int GetChar(); /* character input, with trigraph parsing */ + + +/* Returns the working directory from a complete path+filename specification. + * If there is just a filename and no path, it returns DOT e.g the current + * directory. + */ +char *getwdir(register char *fn); + diff --git a/lang/cem/cpp.ansi/main.c b/lang/cem/cpp.ansi/main.c index be8a7cd82..15fe8a1e3 100644 --- a/lang/cem/cpp.ansi/main.c +++ b/lang/cem/cpp.ansi/main.c @@ -15,7 +15,14 @@ #include "arith.h" #include "file_info.h" #include "idf.h" +#include "init.h" +#include "print.h" +#include "options.h" +#include "error.h" +#include "input.h" #include "macro.h" +#include "preprocess.h" + extern char *symbol2str(); extern char *getwdir(); @@ -24,7 +31,7 @@ extern int do_dependencies; extern char *dep_file; int idfsize = IDFSIZE; extern char options[]; -static File *dep_fd = STDOUT; +static File *dep_fd; arith ifval; @@ -33,13 +40,18 @@ char *prog_name; extern char **inctable; extern int inc_max, inc_total; -void dependency(); +/* Forward declarations */ +void compile(int argc, char *argv[]); +void add_dependency(char *); +static void list_dependencies(char *); +static void dependency(char *, char *); + -main(argc, argv) - char *argv[]; +int main(int argc, char *argv[]) { /* parse and interpret the command line options */ prog_name = argv[0]; + dep_fd = STDOUT; init_idf(); @@ -67,8 +79,7 @@ main(argc, argv) /*NOTREACHED*/ } -compile(argc, argv) - char *argv[]; +void compile(int argc, char *argv[]) { register char *source = 0; char *dummy; @@ -97,10 +108,9 @@ compile(argc, argv) } struct idf *file_head; -extern char *strrchr(); -list_dependencies(source) - char *source; + +static void list_dependencies(char *source) { register struct idf *p = file_head; @@ -115,7 +125,7 @@ list_dependencies(source) * object generated, so don't include the pathname * leading to it. */ - if (s = strrchr(source, '/')) { + if ((s = strrchr(source, '/'))) { source = s + 1; } } @@ -131,8 +141,7 @@ list_dependencies(source) } } -add_dependency(s) - char *s; +void add_dependency(char *s) { register struct idf *p = str2idf(s, 0); @@ -143,9 +152,7 @@ add_dependency(s) } } -void -dependency(s, source) - char *s, *source; +static void dependency(char *s, char *source) { if (options['i'] && !strncmp(s, "/usr/include/", 13)) { return; @@ -156,8 +163,7 @@ dependency(s, source) else fprint(dep_fd, "%s\n", s); } -void -No_Mem() /* called by alloc package */ +void No_Mem(void) /* called by alloc package */ { fatal("out of memory"); } diff --git a/lang/cem/cpp.ansi/options.c b/lang/cem/cpp.ansi/options.c index 21d1e2212..ec6698aa4 100644 --- a/lang/cem/cpp.ansi/options.c +++ b/lang/cem/cpp.ansi/options.c @@ -11,7 +11,9 @@ #include "parameters.h" #include "class.h" #include "macro.h" +#include "domacro.h" #include "idf.h" +#include "error.h" char options[128]; /* one for every char */ int inc_pos = 1; /* place where next -I goes */ @@ -23,10 +25,10 @@ char **inctable; char *dep_file = 0; extern int idfsize; -int txt2int(); -do_option(text) - char *text; +static int txt2int(char **tp); + +void do_option(char *text) { switch(*text++) { case '-': @@ -127,9 +129,7 @@ do_option(text) } } -int -txt2int(tp) - char **tp; +static int txt2int(char **tp) { /* the integer pointed to by *tp is read, while increasing *tp; the resulting value is yielded. diff --git a/lang/cem/cpp.ansi/preprocess.c b/lang/cem/cpp.ansi/preprocess.c index ed8119cf5..11a373c3f 100644 --- a/lang/cem/cpp.ansi/preprocess.c +++ b/lang/cem/cpp.ansi/preprocess.c @@ -9,14 +9,19 @@ #include #include #include +#include "preprocess.h" #include "input.h" #include "parameters.h" #include "arith.h" #include "LLlex.h" #include "class.h" #include "macro.h" +#include "domacro.h" +#include "replace.h" #include "idf.h" +#include "error.h" #include "bits.h" +#include "skip.h" char _obuf[OBUFSIZE]; #ifdef DOBITS @@ -26,7 +31,7 @@ extern int InputLevel; extern char* sprint(); -Xflush() +void Xflush(void) { sys_write(STDOUT, _obuf, OBUFSIZE); } @@ -45,7 +50,7 @@ struct prag_info static struct prag_info* pragma_tab; static int pragma_nr; -do_pragma() +void do_pragma(void) { register int size = ITEXTSIZE; char* cur_line = Malloc((unsigned)size); @@ -123,7 +128,7 @@ do_pragma() char Xbuf[256]; -void preprocess(fn) char* fn; +void preprocess(char *fn) { register int c; register char* op = _obuf; @@ -535,8 +540,7 @@ void preprocess(fn) char* fn; /*NOTREACHED*/ } -static char* SkipComment(op, lineno) char* op; -int* lineno; +static char* SkipComment(char *op, int *lineno) { char* ob = &_obuf[OBUFSIZE]; register int c, oldc = '\0'; diff --git a/lang/cem/cpp.ansi/replace.c b/lang/cem/cpp.ansi/replace.c index 270cd36c2..7dd3c5c20 100644 --- a/lang/cem/cpp.ansi/replace.c +++ b/lang/cem/cpp.ansi/replace.c @@ -19,19 +19,25 @@ #include "arith.h" #include "LLlex.h" #include "class.h" +#include "skip.h" +#include "domacro.h" #include "replace.h" +#include "error.h" -extern char *GetIdentifier(); +; extern int InputLevel; struct repl *ReplaceList; /* list of currently active macros */ -void expand_defined(); -void getactuals(); -void macro2buffer(); +static int expand_macro(register struct repl *, register struct idf *); +static void expand_defined(register struct repl *); +static void getactuals(struct repl *, register struct idf *); +static int actual(struct repl *); +static void macro_func(register struct idf *); +static void macro2buffer(register struct repl *, register struct idf *, register struct args *); +static char *stringify( register struct repl *, register char *, register struct args *); +static void stash(struct repl *, register int ch, int ); -int -replace(idf) - register struct idf *idf; +int replace(register struct idf *idf) { /* replace is called by the lexical analyzer to perform macro replacement. The routine actualy functions as a @@ -57,13 +63,12 @@ replace(idf) return 1; } -unstackrepl() +void unstackrepl(void) { Unstacked++; } -freeargs(args) - struct args *args; +static void freeargs(struct args *args) { register int i; @@ -81,7 +86,7 @@ freeargs(args) free_args(args); } -EnableMacros() +void EnableMacros(void) { register struct repl *r = ReplaceList, *prev = 0; @@ -103,9 +108,9 @@ EnableMacros() Unstacked = 0; } -expand_macro(repl, idf) - register struct repl *repl; - register struct idf *idf; +static int expand_macro( + register struct repl *repl, + register struct idf *idf) { /* expand_macro() does the actual macro replacement. "idf" is a description of the identifier which @@ -168,9 +173,7 @@ expand_macro(repl, idf) return 1; } -void -expand_defined(repl) - register struct repl *repl; +static void expand_defined(register struct repl *repl) { register int ch = GetChar(); struct idf *id; @@ -205,17 +208,13 @@ expand_defined(repl) add2repl(repl, ' '); } -newarg(args) - struct args *args; +static void newarg(struct args *args) { args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF)); args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF)); } -void -getactuals(repl, idf) - struct repl *repl; - register struct idf *idf; +static void getactuals(struct repl *repl, register struct idf *idf) { /* Get the actual parameters from the input stream. The hard part is done by actual(), only comma's and @@ -256,8 +255,7 @@ getactuals(repl, idf) error("too many macro arguments"); } -saveraw(repl) -struct repl *repl; +static void saveraw(struct repl *repl) { register struct repl *nrepl = ReplaceList; register struct args *ap = nrepl->r_args; @@ -294,9 +292,7 @@ struct repl *repl; } } -int -actual(repl) - struct repl *repl; +static int actual(struct repl *repl) { /* This routine deals with the scanning of an actual parameter. It keeps in account the opening and closing brackets, @@ -497,8 +493,7 @@ a_new_line: ch = GetChar(); } } -macro_func(idef) - register struct idf *idef; +static void macro_func(register struct idf *idef) { /* macro_func() performs the special actions needed with some macros. These macros are __FILE__ and __LINE__ which @@ -526,11 +521,10 @@ macro_func(idef) } } -void -macro2buffer(repl, idf, args) - register struct repl *repl; - register struct idf *idf; - register struct args *args; +static void macro2buffer( + register struct repl *repl, + register struct idf *idf, + register struct args *args) { /* macro2buffer expands the replacement list and places the result onto the replacement buffer. It deals with the # @@ -680,11 +674,10 @@ macro2buffer(repl, idf, args) error("illegal use of ## operator"); } -char * -stringify(repl, ptr, args) - register struct repl *repl; - register char *ptr; - register struct args *args; +static char *stringify( + register struct repl *repl, + register char *ptr, + register struct args *args) { /* If a parameter is immediately preceded by a # token both are replaced by a single string literal that @@ -747,9 +740,7 @@ stringify(repl, ptr, args) /* The following routine is also called from domacro.c. */ -add2repl(repl, ch) - register struct repl *repl; - int ch; +void add2repl(register struct repl *repl, int ch) { register int index = repl->r_ptr - repl->r_text; @@ -766,10 +757,7 @@ add2repl(repl, ch) * buffer. If the variable is zero, we must only stash into the expanded * buffer. Otherwise, we must use both buffers. */ -stash(repl, ch, stashraw) - struct repl *repl; - register int ch; - int stashraw; +static void stash(struct repl *repl, register int ch, int stashraw) { /* Stash characters into the macro expansion buffer. */ diff --git a/lang/cem/cpp.ansi/replace.str b/lang/cem/cpp.ansi/replace.str index b8c8a91f4..bb9a17155 100644 --- a/lang/cem/cpp.ansi/replace.str +++ b/lang/cem/cpp.ansi/replace.str @@ -4,6 +4,10 @@ */ /* $Id$ */ /* DEFINITIONS FOR THE MACRO REPLACEMENT ROUTINES */ +#ifndef _REPLACE_H_ +#define _REPLACE_H_ + +#include "parameters.h" struct repl { struct repl *next; @@ -48,3 +52,12 @@ struct args { /* ALLOCDEF "args" 2 */ #define NO_ARGS (struct args *)0 + +struct idf; + +void unstackrepl(void); +int replace(register struct idf *idf); +void EnableMacros(void); +void add2repl(register struct repl *repl, int ch); + +#endif /* REPLACE_H_ */ diff --git a/lang/cem/cpp.ansi/skip.c b/lang/cem/cpp.ansi/skip.c index 1783562bb..9baa82f0c 100644 --- a/lang/cem/cpp.ansi/skip.c +++ b/lang/cem/cpp.ansi/skip.c @@ -9,14 +9,13 @@ #include "LLlex.h" #include "class.h" #include "input.h" +#include "domacro.h" +#include "error.h" extern int InputLevel; -int skipspaces(ch, skipnl) register int ch; +int skipspaces(register int ch, int skipnl) { - /* skipspaces() skips any white space and returns the first - non-space character. - */ register int nlseen = 0; for (;;) @@ -65,9 +64,11 @@ int skipspaces(ch, skipnl) register int ch; else return ch; } + /* garbage */ + return 0; } -SkipToNewLine() +int SkipToNewLine(void) { register int ch; register int garbage = 0; -- 2.34.1