CPP ISO C90 compatibility and conversion.

This commit is contained in:
carl 2019-03-02 01:36:11 +08:00
parent f371f452b5
commit 5f9a199257
19 changed files with 235 additions and 171 deletions

View file

@ -15,7 +15,9 @@
#include "idf.h" #include "idf.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "replace.h"
#include "class.h" #include "class.h"
#include "error.h"
#include "bits.h" #include "bits.h"
#define BUFSIZ 1024 #define BUFSIZ 1024
@ -30,20 +32,26 @@ int AccFileSpecifier = 0; /* return filespecifier <...> */
int LexSave = 0; /* last character read by GetChar */ int LexSave = 0; /* last character read by GetChar */
extern int InputLevel; /* # of current macro expansions */ 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_ESEEN 0x01 /* possibly a floating point number */
#define FLG_DOTSEEN 0x02 /* certainly 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; 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 /* GetToken() is the actual token recognizer. It calls the
control line interpreter if it encounters a "\n{w}*#" control line interpreter if it encounters a "\n{w}*#"
@ -385,7 +393,7 @@ again: /* rescan the input after an error or replacement */
/*NOTREACHED*/ /*NOTREACHED*/
} }
void skipcomment() void skipcomment(void)
{ {
/* The last character read has been the '*' of '/_*'. The /* The last character read has been the '*' of '/_*'. The
characters, except NL and EOI, between '/_*' and the first 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 arith val = 0;
register int ch; register int ch;
@ -471,7 +479,7 @@ arith char_constant(nm) char* nm;
return val; return val;
} }
char* string_token(nm, stop_char) char* nm; static char* string_token(char *nm, int stop_char)
{ {
register int ch; register int ch;
register int str_size; register int str_size;
@ -504,7 +512,7 @@ char* string_token(nm, stop_char) char* nm;
return str; return str;
} }
int quoted(ch) register int ch; static int quoted(register int ch)
{ {
/* quoted() replaces an escaped character sequence by the /* quoted() replaces an escaped character sequence by the
character meant. character meant.
@ -567,7 +575,7 @@ int quoted(ch) register int ch;
return ch & 0377; return ch & 0377;
} }
int val_in_base(ch, base) register int ch; static int val_in_base(register int ch, int base)
{ {
switch (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 /* The routines GetChar and trigraph parses the trigraph
sequences and removes occurences of \\\n. sequences and removes occurences of \\\n.
@ -612,7 +620,7 @@ again:
return (LexSave = ch); return (LexSave = ch);
} }
int trigraph() static int trigraph(void)
{ {
register int ch; register int ch;

View file

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $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 */ /* 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, /* A token from the input stream is represented by an integer,
called a "symbol", but it may have other information associated 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 DOT dot.tk_symb
#define EOF (-1) #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_ */

View file

@ -8,15 +8,20 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "skip.h"
#include "error.h"
extern char *symbol2str(); extern char *symbol2str();
LLmessage(tk) { void LLmessage(int tk)
{
if (tk < 0) if (tk < 0)
error("garbage at end of line"); error("garbage at end of line");
else if (tk) { else if (tk)
{
error("%s missing", symbol2str(tk)); error("%s missing", symbol2str(tk));
if (DOT != EOF) SkipToNewLine(); if (DOT != EOF)
SkipToNewLine();
DOT = EOF; DOT = EOF;
} }
else else

View file

@ -7,10 +7,11 @@
#include "Lpars.h" #include "Lpars.h"
#include "arith.h" #include "arith.h"
#include "ch3bin.h"
#include "skip.h"
#include "error.h"
ch3bin(pval, pis_uns, oper, val, is_uns) void ch3bin(register arith *pval, int *pis_uns, int oper, register arith val, int is_uns)
register arith *pval, val;
int oper, is_uns, *pis_uns;
{ {
if (is_uns) *pis_uns = 1; if (is_uns) *pis_uns = 1;
switch (oper) { switch (oper) {

View file

@ -5,13 +5,12 @@
/* $Id$ */ /* $Id$ */
/* EVALUATION OF MONADIC OPERATORS */ /* EVALUATION OF MONADIC OPERATORS */
#include "ch3mon.h"
#include "Lpars.h" #include "Lpars.h"
#include "arith.h" #include "arith.h"
/*ARGSUSED2*/ /*ARGSUSED2*/
ch3mon(oper, pval, puns) void ch3mon(int oper, register arith *pval, int *puns)
register arith *pval;
int *puns;
{ {
switch (oper) { switch (oper) {
case '~': case '~':

View file

@ -10,7 +10,7 @@
At present such a class number is supposed to fit in 4 bits. 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 /* Being the start of a token is, fortunately, a mutual exclusive
property, so, as there are less than 16 classes they can be 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 class. This is implemented as a collection of tables to speed up
the decision whether a character has a special meaning. the decision whether a character has a special meaning.
*/ */
#define in_idf(ch) (inidf[ch]) #define in_idf(ch) (inidf[(unsigned int)ch])
#define is_oct(ch) (isoct[ch]) #define is_oct(ch) (isoct[(unsigned int)ch])
#define is_dig(ch) (isdig[ch]) #define is_dig(ch) (isdig[(unsigned int)ch])
#define is_hex(ch) (ishex[ch]) #define is_hex(ch) (ishex[(unsigned int)ch])
#define is_wsp(ch) (iswsp[ch]) #define is_wsp(ch) (iswsp[(unsigned int)ch])
extern char tkclass[]; extern char tkclass[];
extern char inidf[], isoct[], isdig[], ishex[], iswsp[]; extern char inidf[], isoct[], isdig[], ishex[], iswsp[];

View file

@ -8,22 +8,26 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "domacro.h"
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "idf.h" #include "idf.h"
#include "input.h" #include "input.h"
#include "error.h"
#include "parameters.h" #include "parameters.h"
#include "preprocess.h"
#include <alloc.h> #include <alloc.h>
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "LLlex.h"
#include "bits.h" #include "bits.h"
#include "skip.h"
#include "replace.h" #include "replace.h"
extern char options[]; extern char options[];
extern char** inctable; /* list of include directories */ extern char** inctable; /* list of include directories */
extern char* getwdir();
char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */
/* 1 if a corresponding ELSE has been */ /* 1 if a corresponding ELSE has been */
/* encountered. */ /* encountered. */
@ -33,10 +37,33 @@ int svnestlevel[30] = { -1 };
int nestcount; int nestcount;
extern int do_preprocess; extern int do_preprocess;
void macro_def(); /* Internal declarations */
void do_define();
char* GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */
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 /* Returns a pointer to the identifier that is read from the
input stream. When the input does not contain an 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; return tk.tk_str;
} }
/* domacro() is the control line interpreter. The '#' has already
been read by the lexical analyzer by which domacro() is called. void domacro(void)
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()
{ {
struct token tk; /* the token itself */ struct token tk; /* the token itself */
register struct idf* id; 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 /* skip_block() skips the input from
1) a false #if, #ifdef, #ifndef or #elif until the 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 expression following #if or #elif evaluates to true. This
is done by calling the LLgen generated subparser for is done by calling the LLgen generated subparser for
constant expressions. The result of this expression will constant expressions. The result of this expression will
@ -324,7 +343,7 @@ ifexpr()
return (errors == err_occurred) && (ifval != (arith)0); return (errors == err_occurred) && (ifval != (arith)0);
} }
do_include() static void do_include(void)
{ {
/* do_include() performs the inclusion of a file. /* 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. /* do_define() interprets a #define control line.
*/ */
@ -378,8 +397,7 @@ void do_define()
char parbuf[PARBUFSIZE]; /* names of formals */ char parbuf[PARBUFSIZE]; /* names of formals */
char* repl_text; /* start of the replacement text */ char* repl_text; /* start of the replacement text */
int length; /* length of the replacement text */ int length; /* length of the replacement text */
register ch; register int ch;
char* get_text();
/* read the #defined macro's name */ /* read the #defined macro's name */
if (!(str = GetIdentifier(1))) if (!(str = GetIdentifier(1)))
@ -411,7 +429,7 @@ void do_define()
LineNumber++; LineNumber++;
} }
push_if() static void push_if(void)
{ {
if (nestlevel >= IFDEPTH) if (nestlevel >= IFDEPTH)
fatal("too many nested #if/#ifdef/#ifndef"); fatal("too many nested #if/#ifdef/#ifndef");
@ -419,7 +437,7 @@ push_if()
ifstack[++nestlevel] = 0; ifstack[++nestlevel] = 0;
} }
do_elif() static void do_elif(void)
{ {
if (nestlevel <= svnestlevel[nestcount]) if (nestlevel <= svnestlevel[nestcount])
{ {
@ -439,7 +457,7 @@ do_elif()
} }
} }
do_else() static void do_else(void)
{ {
if (SkipToNewLine()) if (SkipToNewLine())
{ {
@ -459,7 +477,7 @@ do_else()
} }
} }
do_endif() static void do_endif(void)
{ {
if (SkipToNewLine()) if (SkipToNewLine())
{ {
@ -474,14 +492,14 @@ do_endif()
nestlevel--; nestlevel--;
} }
do_if() static void do_if(void)
{ {
push_if(); push_if();
if (!ifexpr()) /* a false #if/#elif expression */ if (!ifexpr()) /* a false #if/#elif expression */
skip_block(0); skip_block(0);
} }
do_ifdef(how) static void do_ifdef(int how)
{ {
register struct idf* id; register struct idf* id;
register char* str; register char* str;
@ -513,7 +531,7 @@ do_ifdef(how)
} }
/* argstr != NULL when the undef came from a -U option */ /* 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 struct idf* id;
register char* str = argstr; register char* str = argstr;
@ -548,7 +566,7 @@ do_undef(argstr) char* argstr;
error("illegal #undef construction"); error("illegal #undef construction");
} }
do_error() static void do_error(void)
{ {
int len; int len;
char* get_text(); char* get_text();
@ -559,8 +577,7 @@ do_error()
LineNumber++; LineNumber++;
} }
int getparams(buf, parbuf) char* buf[]; static int getparams(char* buf[], char parbuf[])
char parbuf[];
{ {
/* getparams() reads the formal parameter list of a macro /* getparams() reads the formal parameter list of a macro
definition. definition.
@ -633,8 +650,7 @@ char parbuf[];
/*NOTREACHED*/ /*NOTREACHED*/
} }
void macro_def(id, text, nformals, length, flags) register struct idf* id; void macro_def(register struct idf* id, char* text, int nformals, int length, int flags)
char* text;
{ {
register struct macro* newdef = id->id_macro; register struct macro* newdef = id->id_macro;
@ -681,7 +697,7 @@ char* text;
newdef->mc_flag = flags; /* special flags */ 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 /* find_name() returns the index of "nm" in the namelist
"index" if it can be found there. 0 is returned if it is "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')) #define BLANK(ch) ((ch == ' ') || (ch == '\t'))
char* get_text(formals, length) char* formals[]; static char* get_text(char* formals[], int* length)
int* length;
{ {
/* get_text() copies the replacement text of a macro /* get_text() copies the replacement text of a macro
definition with zero, one or more parameters, thereby definition with zero, one or more parameters, thereby
@ -811,7 +826,7 @@ int* length;
add2repl(repl, ' '); add2repl(repl, ' ');
} }
/* construct the formal parameter mark or identifier */ /* 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); add2repl(repl, FORMALP | (char)n);
else else
{ {
@ -873,7 +888,7 @@ int* length;
as strings, without taking care of the leading and trailing as strings, without taking care of the leading and trailing
blanks (spaces and tabs). blanks (spaces and tabs).
*/ */
macroeq(s, t) register char* s, *t; static int macroeq(register char* s, register char *t)
{ {
/* skip leading spaces */ /* 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; struct token tk;
int t = GetToken(&tk); int t = GetToken(&tk);

View file

@ -14,6 +14,7 @@
#include "parameters.h" #include "parameters.h"
#include "arith.h" #include "arith.h"
#include "print.h"
#include "LLlex.h" #include "LLlex.h"
/* This file contains the (non-portable) error-message and diagnostic /* This file contains the (non-portable) error-message and diagnostic
@ -23,8 +24,7 @@
int err_occurred; int err_occurred;
err_hdr(s) static void err_hdr(char *s)
char *s;
{ {
if (FileName) { if (FileName) {
fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s); fprint(ERROUT, "\"%s\", line %d: %s", FileName, (int)LineNumber, s);
@ -34,7 +34,7 @@ err_hdr(s)
#if __STDC__ #if __STDC__
/*VARARGS*/ /*VARARGS*/
error(char *fmt, ...) void error(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -47,7 +47,7 @@ error(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
warning(char *fmt, ...) void warning(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -59,7 +59,7 @@ warning(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
strict(char *fmt, ...) void strict(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -71,7 +71,7 @@ strict(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
crash(char *fmt, ...) void crash(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -84,7 +84,7 @@ crash(char *fmt, ...)
} }
/*VARARGS*/ /*VARARGS*/
fatal(char *fmt, ...) void fatal(char *fmt, ...)
{ {
va_list ap; va_list ap;
@ -97,7 +97,7 @@ fatal(char *fmt, ...)
} }
#else #else
/*VARARGS*/ /*VARARGS*/
error(va_alist) void error(va_alist)
va_dcl va_dcl
{ {
char *fmt; char *fmt;
@ -113,7 +113,7 @@ error(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
warning(va_alist) void warning(va_alist)
va_dcl va_dcl
{ {
char *fmt; char *fmt;
@ -128,7 +128,7 @@ warning(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
strict(va_alist) void strict(va_alist)
va_dcl va_dcl
{ {
char *fmt; char *fmt;
@ -143,7 +143,7 @@ strict(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
crash(va_alist) void crash(va_alist)
va_dcl va_dcl
{ {
char *fmt; char *fmt;
@ -159,7 +159,7 @@ crash(va_alist)
} }
/*VARARGS*/ /*VARARGS*/
fatal(va_alist) void fatal(va_alist)
va_dcl va_dcl
{ {
char *fmt; char *fmt;

View file

@ -5,11 +5,10 @@
/* $Id$ */ /* $Id$ */
/* OPERATOR HANDLING */ /* OPERATOR HANDLING */
#include "expr.h"
#include "Lpars.h" #include "Lpars.h"
int int rank_of(int oper)
rank_of(oper)
int oper;
{ {
/* The rank of the operator oper is returned. /* The rank of the operator oper is returned.
*/ */

View file

@ -10,6 +10,9 @@
{ {
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "ch3mon.h"
#include "ch3bin.h"
#include "expr.h"
extern arith ifval; extern arith ifval;
} }

View file

@ -13,7 +13,10 @@
#include "time.h" #include "time.h"
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "print.h"
#include "error.h"
#include "idf.h" #include "idf.h"
#include "domacro.h"
struct mkey { struct mkey {
char *mk_reserved; char *mk_reserved;
@ -34,9 +37,8 @@ struct mkey {
{0, K_UNKNOWN} {0, K_UNKNOWN}
}; };
char *sprint();
init_pp() void init_pp(void)
{ {
static char *months[12] = { static char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
@ -74,7 +76,7 @@ init_pp()
/* __DATE__ */ /* __DATE__ */
sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon], sprint(dbuf, "\"%s %2d %d\"", months[tp->tm_mon],
tp->tm_mday, tp->tm_year+1900); 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); macro_def(str2idf("__DATE__", 0), dbuf, -1, strlen(dbuf), NOUNDEF);
/* __TIME__ */ /* __TIME__ */

View file

@ -9,6 +9,8 @@
#include <string.h> #include <string.h>
#include "file_info.h" #include "file_info.h"
#include "input.h" #include "input.h"
#include "error.h"
#include "replace.h"
#define INP_PUSHBACK 3 #define INP_PUSHBACK 3
#define INP_TYPE struct file_info #define INP_TYPE struct file_info
@ -17,9 +19,7 @@ struct file_info finfo;
#include <inp_pkg.body> #include <inp_pkg.body>
#include <alloc.h> #include <alloc.h>
char * char *getwdir(register char *fn)
getwdir(fn)
register char *fn;
{ {
register char *p; register char *p;
char *strrchr(); char *strrchr();
@ -44,7 +44,7 @@ getwdir(fn)
int NoUnstack; int NoUnstack;
int InputLevel; int InputLevel;
AtEoIT() int AtEoIT(void)
{ {
InputLevel--; InputLevel--;
/* if (NoUnstack) warning("unexpected EOF"); ??? */ /* if (NoUnstack) warning("unexpected EOF"); ??? */
@ -52,7 +52,7 @@ AtEoIT()
return 0; return 0;
} }
AtEoIF() int AtEoIF(void)
{ {
extern int nestlevel; extern int nestlevel;
extern int nestcount; extern int nestcount;

View file

@ -11,4 +11,11 @@
#define UnGetChar() ((LexSave != EOI) ? ChPushBack(LexSave) : 0) #define UnGetChar() ((LexSave != EOI) ? ChPushBack(LexSave) : 0)
extern int LexSave; /* last character read by GetChar */ 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);

View file

@ -15,7 +15,14 @@
#include "arith.h" #include "arith.h"
#include "file_info.h" #include "file_info.h"
#include "idf.h" #include "idf.h"
#include "init.h"
#include "print.h"
#include "options.h"
#include "error.h"
#include "input.h"
#include "macro.h" #include "macro.h"
#include "preprocess.h"
extern char *symbol2str(); extern char *symbol2str();
extern char *getwdir(); extern char *getwdir();
@ -24,7 +31,7 @@ extern int do_dependencies;
extern char *dep_file; extern char *dep_file;
int idfsize = IDFSIZE; int idfsize = IDFSIZE;
extern char options[]; extern char options[];
static File *dep_fd = STDOUT; static File *dep_fd;
arith ifval; arith ifval;
@ -33,13 +40,18 @@ char *prog_name;
extern char **inctable; extern char **inctable;
extern int inc_max, inc_total; 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 */ /* parse and interpret the command line options */
prog_name = argv[0]; prog_name = argv[0];
dep_fd = STDOUT;
init_idf(); init_idf();
@ -67,8 +79,7 @@ main(argc, argv)
/*NOTREACHED*/ /*NOTREACHED*/
} }
compile(argc, argv) void compile(int argc, char *argv[])
char *argv[];
{ {
register char *source = 0; register char *source = 0;
char *dummy; char *dummy;
@ -97,10 +108,9 @@ compile(argc, argv)
} }
struct idf *file_head; struct idf *file_head;
extern char *strrchr();
list_dependencies(source)
char *source; static void list_dependencies(char *source)
{ {
register struct idf *p = file_head; register struct idf *p = file_head;
@ -115,7 +125,7 @@ list_dependencies(source)
* object generated, so don't include the pathname * object generated, so don't include the pathname
* leading to it. * leading to it.
*/ */
if (s = strrchr(source, '/')) { if ((s = strrchr(source, '/'))) {
source = s + 1; source = s + 1;
} }
} }
@ -131,8 +141,7 @@ list_dependencies(source)
} }
} }
add_dependency(s) void add_dependency(char *s)
char *s;
{ {
register struct idf *p = str2idf(s, 0); register struct idf *p = str2idf(s, 0);
@ -143,9 +152,7 @@ add_dependency(s)
} }
} }
void static void dependency(char *s, char *source)
dependency(s, source)
char *s, *source;
{ {
if (options['i'] && !strncmp(s, "/usr/include/", 13)) { if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
return; return;
@ -156,8 +163,7 @@ dependency(s, source)
else fprint(dep_fd, "%s\n", s); else fprint(dep_fd, "%s\n", s);
} }
void void No_Mem(void) /* called by alloc package */
No_Mem() /* called by alloc package */
{ {
fatal("out of memory"); fatal("out of memory");
} }

View file

@ -11,7 +11,9 @@
#include "parameters.h" #include "parameters.h"
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "domacro.h"
#include "idf.h" #include "idf.h"
#include "error.h"
char options[128]; /* one for every char */ char options[128]; /* one for every char */
int inc_pos = 1; /* place where next -I goes */ int inc_pos = 1; /* place where next -I goes */
@ -23,10 +25,10 @@ char **inctable;
char *dep_file = 0; char *dep_file = 0;
extern int idfsize; extern int idfsize;
int txt2int();
do_option(text) static int txt2int(char **tp);
char *text;
void do_option(char *text)
{ {
switch(*text++) { switch(*text++) {
case '-': case '-':
@ -127,9 +129,7 @@ do_option(text)
} }
} }
int static int txt2int(char **tp)
txt2int(tp)
char **tp;
{ {
/* the integer pointed to by *tp is read, while increasing /* the integer pointed to by *tp is read, while increasing
*tp; the resulting value is yielded. *tp; the resulting value is yielded.

View file

@ -9,14 +9,19 @@
#include <stdio.h> #include <stdio.h>
#include <system.h> #include <system.h>
#include <alloc.h> #include <alloc.h>
#include "preprocess.h"
#include "input.h" #include "input.h"
#include "parameters.h" #include "parameters.h"
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
#include "domacro.h"
#include "replace.h"
#include "idf.h" #include "idf.h"
#include "error.h"
#include "bits.h" #include "bits.h"
#include "skip.h"
char _obuf[OBUFSIZE]; char _obuf[OBUFSIZE];
#ifdef DOBITS #ifdef DOBITS
@ -26,7 +31,7 @@ extern int InputLevel;
extern char* sprint(); extern char* sprint();
Xflush() void Xflush(void)
{ {
sys_write(STDOUT, _obuf, OBUFSIZE); sys_write(STDOUT, _obuf, OBUFSIZE);
} }
@ -45,7 +50,7 @@ struct prag_info
static struct prag_info* pragma_tab; static struct prag_info* pragma_tab;
static int pragma_nr; static int pragma_nr;
do_pragma() void do_pragma(void)
{ {
register int size = ITEXTSIZE; register int size = ITEXTSIZE;
char* cur_line = Malloc((unsigned)size); char* cur_line = Malloc((unsigned)size);
@ -123,7 +128,7 @@ do_pragma()
char Xbuf[256]; char Xbuf[256];
void preprocess(fn) char* fn; void preprocess(char *fn)
{ {
register int c; register int c;
register char* op = _obuf; register char* op = _obuf;
@ -535,8 +540,7 @@ void preprocess(fn) char* fn;
/*NOTREACHED*/ /*NOTREACHED*/
} }
static char* SkipComment(op, lineno) char* op; static char* SkipComment(char *op, int *lineno)
int* lineno;
{ {
char* ob = &_obuf[OBUFSIZE]; char* ob = &_obuf[OBUFSIZE];
register int c, oldc = '\0'; register int c, oldc = '\0';

View file

@ -19,19 +19,25 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "skip.h"
#include "domacro.h"
#include "replace.h" #include "replace.h"
#include "error.h"
extern char *GetIdentifier(); ;
extern int InputLevel; extern int InputLevel;
struct repl *ReplaceList; /* list of currently active macros */ struct repl *ReplaceList; /* list of currently active macros */
void expand_defined(); static int expand_macro(register struct repl *, register struct idf *);
void getactuals(); static void expand_defined(register struct repl *);
void macro2buffer(); 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 int replace(register struct idf *idf)
replace(idf)
register struct idf *idf;
{ {
/* replace is called by the lexical analyzer to perform /* replace is called by the lexical analyzer to perform
macro replacement. The routine actualy functions as a macro replacement. The routine actualy functions as a
@ -57,13 +63,12 @@ replace(idf)
return 1; return 1;
} }
unstackrepl() void unstackrepl(void)
{ {
Unstacked++; Unstacked++;
} }
freeargs(args) static void freeargs(struct args *args)
struct args *args;
{ {
register int i; register int i;
@ -81,7 +86,7 @@ freeargs(args)
free_args(args); free_args(args);
} }
EnableMacros() void EnableMacros(void)
{ {
register struct repl *r = ReplaceList, *prev = 0; register struct repl *r = ReplaceList, *prev = 0;
@ -103,9 +108,9 @@ EnableMacros()
Unstacked = 0; Unstacked = 0;
} }
expand_macro(repl, idf) static int expand_macro(
register struct repl *repl; register struct repl *repl,
register struct idf *idf; register struct idf *idf)
{ {
/* expand_macro() does the actual macro replacement. /* expand_macro() does the actual macro replacement.
"idf" is a description of the identifier which "idf" is a description of the identifier which
@ -168,9 +173,7 @@ expand_macro(repl, idf)
return 1; return 1;
} }
void static void expand_defined(register struct repl *repl)
expand_defined(repl)
register struct repl *repl;
{ {
register int ch = GetChar(); register int ch = GetChar();
struct idf *id; struct idf *id;
@ -205,17 +208,13 @@ expand_defined(repl)
add2repl(repl, ' '); add2repl(repl, ' ');
} }
newarg(args) static void newarg(struct args *args)
struct args *args;
{ {
args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF)); args->a_expptr = args->a_expbuf = Malloc((unsigned)(args->a_expsize = ARGBUF));
args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF)); args->a_rawptr = args->a_rawbuf = Malloc((unsigned)(args->a_rawsize = ARGBUF));
} }
void static void getactuals(struct repl *repl, register struct idf *idf)
getactuals(repl, idf)
struct repl *repl;
register struct idf *idf;
{ {
/* Get the actual parameters from the input stream. /* Get the actual parameters from the input stream.
The hard part is done by actual(), only comma's and The hard part is done by actual(), only comma's and
@ -256,8 +255,7 @@ getactuals(repl, idf)
error("too many macro arguments"); error("too many macro arguments");
} }
saveraw(repl) static void saveraw(struct repl *repl)
struct repl *repl;
{ {
register struct repl *nrepl = ReplaceList; register struct repl *nrepl = ReplaceList;
register struct args *ap = nrepl->r_args; register struct args *ap = nrepl->r_args;
@ -294,9 +292,7 @@ struct repl *repl;
} }
} }
int static int actual(struct repl *repl)
actual(repl)
struct repl *repl;
{ {
/* This routine deals with the scanning of an actual parameter. /* This routine deals with the scanning of an actual parameter.
It keeps in account the opening and closing brackets, It keeps in account the opening and closing brackets,
@ -497,8 +493,7 @@ a_new_line: ch = GetChar();
} }
} }
macro_func(idef) static void macro_func(register struct idf *idef)
register struct idf *idef;
{ {
/* macro_func() performs the special actions needed with some /* macro_func() performs the special actions needed with some
macros. These macros are __FILE__ and __LINE__ which macros. These macros are __FILE__ and __LINE__ which
@ -526,11 +521,10 @@ macro_func(idef)
} }
} }
void static void macro2buffer(
macro2buffer(repl, idf, args) register struct repl *repl,
register struct repl *repl; register struct idf *idf,
register struct idf *idf; register struct args *args)
register struct args *args;
{ {
/* macro2buffer expands the replacement list and places the /* macro2buffer expands the replacement list and places the
result onto the replacement buffer. It deals with the # result onto the replacement buffer. It deals with the #
@ -680,11 +674,10 @@ macro2buffer(repl, idf, args)
error("illegal use of ## operator"); error("illegal use of ## operator");
} }
char * static char *stringify(
stringify(repl, ptr, args) register struct repl *repl,
register struct repl *repl; register char *ptr,
register char *ptr; register struct args *args)
register struct args *args;
{ {
/* If a parameter is immediately preceded by a # token /* If a parameter is immediately preceded by a # token
both are replaced by a single string literal that 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. /* The following routine is also called from domacro.c.
*/ */
add2repl(repl, ch) void add2repl(register struct repl *repl, int ch)
register struct repl *repl;
int ch;
{ {
register int index = repl->r_ptr - repl->r_text; 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. If the variable is zero, we must only stash into the expanded
* buffer. Otherwise, we must use both buffers. * buffer. Otherwise, we must use both buffers.
*/ */
stash(repl, ch, stashraw) static void stash(struct repl *repl, register int ch, int stashraw)
struct repl *repl;
register int ch;
int stashraw;
{ {
/* Stash characters into the macro expansion buffer. /* Stash characters into the macro expansion buffer.
*/ */

View file

@ -4,6 +4,10 @@
*/ */
/* $Id$ */ /* $Id$ */
/* DEFINITIONS FOR THE MACRO REPLACEMENT ROUTINES */ /* DEFINITIONS FOR THE MACRO REPLACEMENT ROUTINES */
#ifndef _REPLACE_H_
#define _REPLACE_H_
#include "parameters.h"
struct repl { struct repl {
struct repl *next; struct repl *next;
@ -48,3 +52,12 @@ struct args {
/* ALLOCDEF "args" 2 */ /* ALLOCDEF "args" 2 */
#define NO_ARGS (struct args *)0 #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_ */

View file

@ -9,14 +9,13 @@
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "input.h" #include "input.h"
#include "domacro.h"
#include "error.h"
extern int InputLevel; 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; register int nlseen = 0;
for (;;) for (;;)
@ -65,9 +64,11 @@ int skipspaces(ch, skipnl) register int ch;
else else
return ch; return ch;
} }
/* garbage */
return 0;
} }
SkipToNewLine() int SkipToNewLine(void)
{ {
register int ch; register int ch;
register int garbage = 0; register int garbage = 0;