#include "idf.h"
#include "LLlex.h"
#include "Lpars.h"
+#include "replace.h"
#include "class.h"
+#include "error.h"
#include "bits.h"
#define BUFSIZ 1024
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}*#"
/*NOTREACHED*/
}
-void skipcomment()
+void skipcomment(void)
{
/* The last character read has been the '*' of '/_*'. The
characters, except NL and EOI, between '/_*' and the first
}
}
-arith char_constant(nm) char* nm;
+static arith char_constant(char* nm)
{
register arith val = 0;
register int ch;
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;
return str;
}
-int quoted(ch) register int ch;
+static int quoted(register int ch)
{
/* quoted() replaces an escaped character sequence by the
character meant.
return ch & 0377;
}
-int val_in_base(ch, base) register int ch;
+static int val_in_base(register int ch, int base)
{
switch (base)
{
}
}
-int GetChar()
+int GetChar(void)
{
/* The routines GetChar and trigraph parses the trigraph
sequences and removes occurences of \\\n.
return (LexSave = ch);
}
-int trigraph()
+static int trigraph(void)
{
register int ch;
*/
/* $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
#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_ */
#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
#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) {
/* $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 '~':
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
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[];
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#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 <alloc.h>
#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. */
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
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;
}
}
-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
}
}
-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
return (errors == err_occurred) && (ifval != (arith)0);
}
-do_include()
+static void do_include(void)
{
/* do_include() performs the inclusion of a file.
*/
}
}
-void do_define()
+static void do_define(void)
{
/* do_define() interprets a #define control line.
*/
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)))
LineNumber++;
}
-push_if()
+static void push_if(void)
{
if (nestlevel >= IFDEPTH)
fatal("too many nested #if/#ifdef/#ifndef");
ifstack[++nestlevel] = 0;
}
-do_elif()
+static void do_elif(void)
{
if (nestlevel <= svnestlevel[nestcount])
{
}
}
-do_else()
+static void do_else(void)
{
if (SkipToNewLine())
{
}
}
-do_endif()
+static void do_endif(void)
{
if (SkipToNewLine())
{
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;
}
/* 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;
error("illegal #undef construction");
}
-do_error()
+static void do_error(void)
{
int len;
char* get_text();
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.
/*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;
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
#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
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
{
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 */
}
}
-do_line(l) unsigned int l;
+static void do_line(unsigned int l)
{
struct token tk;
int t = GetToken(&tk);
#include "parameters.h"
#include "arith.h"
+#include "print.h"
#include "LLlex.h"
/* This file contains the (non-portable) error-message and diagnostic
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);
#if __STDC__
/*VARARGS*/
-error(char *fmt, ...)
+void error(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-warning(char *fmt, ...)
+void warning(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-strict(char *fmt, ...)
+void strict(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-crash(char *fmt, ...)
+void crash(char *fmt, ...)
{
va_list ap;
}
/*VARARGS*/
-fatal(char *fmt, ...)
+void fatal(char *fmt, ...)
{
va_list ap;
}
#else
/*VARARGS*/
-error(va_alist)
+void error(va_alist)
va_dcl
{
char *fmt;
}
/*VARARGS*/
-warning(va_alist)
+void warning(va_alist)
va_dcl
{
char *fmt;
}
/*VARARGS*/
-strict(va_alist)
+void strict(va_alist)
va_dcl
{
char *fmt;
}
/*VARARGS*/
-crash(va_alist)
+void crash(va_alist)
va_dcl
{
char *fmt;
}
/*VARARGS*/
-fatal(va_alist)
+void fatal(va_alist)
va_dcl
{
char *fmt;
/* $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.
*/
{
#include "arith.h"
#include "LLlex.h"
+#include "ch3mon.h"
+#include "ch3bin.h"
+#include "expr.h"
extern arith ifval;
}
#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;
{0, K_UNKNOWN}
};
-char *sprint();
-init_pp()
+void init_pp(void)
{
static char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
/* __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__ */
#include <string.h>
#include "file_info.h"
#include "input.h"
+#include "error.h"
+#include "replace.h"
#define INP_PUSHBACK 3
#define INP_TYPE struct file_info
#include <inp_pkg.body>
#include <alloc.h>
-char *
-getwdir(fn)
- register char *fn;
+char *getwdir(register char *fn)
{
register char *p;
char *strrchr();
int NoUnstack;
int InputLevel;
-AtEoIT()
+int AtEoIT(void)
{
InputLevel--;
/* if (NoUnstack) warning("unexpected EOF"); ??? */
return 0;
}
-AtEoIF()
+int AtEoIF(void)
{
extern int nestlevel;
extern int nestcount;
#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);
+
#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();
extern char *dep_file;
int idfsize = IDFSIZE;
extern char options[];
-static File *dep_fd = STDOUT;
+static File *dep_fd;
arith ifval;
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();
/*NOTREACHED*/
}
-compile(argc, argv)
- char *argv[];
+void compile(int argc, char *argv[])
{
register char *source = 0;
char *dummy;
}
struct idf *file_head;
-extern char *strrchr();
-list_dependencies(source)
- char *source;
+
+static void list_dependencies(char *source)
{
register struct idf *p = file_head;
* object generated, so don't include the pathname
* leading to it.
*/
- if (s = strrchr(source, '/')) {
+ if ((s = strrchr(source, '/'))) {
source = s + 1;
}
}
}
}
-add_dependency(s)
- char *s;
+void add_dependency(char *s)
{
register struct idf *p = str2idf(s, 0);
}
}
-void
-dependency(s, source)
- char *s, *source;
+static void dependency(char *s, char *source)
{
if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
return;
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");
}
#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 */
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 '-':
}
}
-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.
#include <stdio.h>
#include <system.h>
#include <alloc.h>
+#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
extern char* sprint();
-Xflush()
+void Xflush(void)
{
sys_write(STDOUT, _obuf, OBUFSIZE);
}
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);
char Xbuf[256];
-void preprocess(fn) char* fn;
+void preprocess(char *fn)
{
register int c;
register char* op = _obuf;
/*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';
#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
return 1;
}
-unstackrepl()
+void unstackrepl(void)
{
Unstacked++;
}
-freeargs(args)
- struct args *args;
+static void freeargs(struct args *args)
{
register int i;
free_args(args);
}
-EnableMacros()
+void EnableMacros(void)
{
register struct repl *r = ReplaceList, *prev = 0;
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
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;
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
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;
}
}
-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,
}
}
-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
}
}
-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 #
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
/* 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;
* 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.
*/
*/
/* $Id$ */
/* DEFINITIONS FOR THE MACRO REPLACEMENT ROUTINES */
+#ifndef _REPLACE_H_
+#define _REPLACE_H_
+
+#include "parameters.h"
struct repl {
struct repl *next;
/* 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_ */
#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 (;;)
else
return ch;
}
+ /* garbage */
+ return 0;
}
-SkipToNewLine()
+int SkipToNewLine(void)
{
register int ch;
register int garbage = 0;