More strict checks...

This commit is contained in:
Manoel Trapier
2013-03-18 18:58:21 +01:00
committed by Manoël Trapier
parent a8d9183e25
commit 2bbd5a38de
87 changed files with 473 additions and 537 deletions

View File

@@ -27,9 +27,6 @@ int AccFileSpecifier = 0; /* return filespecifier <...> */
int AccDefined = 0; /* accept "defined(...)" */
int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */
char *string_token(char *nm, int stop_char);
void skipcomment();
void PushLex()
{
DOT = 0;
@@ -43,6 +40,10 @@ int LLlex()
return (DOT != EOF) ? GetToken(&dot) : EOF;
}
#ifdef BUFSIZ
#undef BUFSIZ
#endif
#define BUFSIZ 1024
int GetToken(struct token *ptok)

View File

@@ -11,6 +11,8 @@
*/
#include <em_arith.h>
#include "system.h"
#include "print.h"
/* the structure of a token: */
struct token {
@@ -42,3 +44,34 @@ extern int err_occurred; /* "error.c" */
#define DOT dot.tk_symb
#define EOF (-1)
#include <symbol2str.h>
struct idf;
struct token;
char *string_token(char *nm, int stop_char);
void skipcomment();
int GetToken(struct token *ptok);
void fatal(char *fmt, ...);
void EnableMacros();
int replace(struct idf *idef);
void error(char *fmt, ...);
int quoted(int c);
int val_in_base(int c, int base);
void crash(char *fmt, ...);
void skipline();
void warning(char *fmt, ...);
void PushLex();
void If_expr(void);
void PopLex();
void add_dependency(char *s);
int skipspaces(int ch, int skipnl);
void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
void DoUnstack();
void init_pp();
void do_option(char *text);
void preprocess(char *fn);
void domacro();
/* External */
int InsertFile(char *, char **, char **);

View File

@@ -5,6 +5,7 @@
*/
/* EVALUATION OF BINARY OPERATORS */
#include "LLlex.h"
#include "Lpars.h"
#include <em_arith.h>

View File

@@ -51,7 +51,6 @@ static void do_undef();
static void do_line(unsigned int l);
static int getparams(char *buf[], char parbuf[]);
static int macroeq(char *s, char *t);
void macro_def(struct idf *id, char *text, int nformals, int length, int flags);
static char *get_text(char *formals[], int *length);
/* Externel dependency */
@@ -84,7 +83,7 @@ char *GetIdentifier()
void domacro()
{
struct token tk; /* the token itself */
register struct idf *id;
struct idf *id;
switch(GetToken(&tk)) { /* select control line action */
case IDENTIFIER: /* is it a macro keyword? */
@@ -169,8 +168,8 @@ static void skip_block(int to_endif)
#ifndef or #elif until the corresponding #endif is
seen.
*/
register int ch;
register int skiplevel = nestlevel; /* current nesting level */
int ch;
int skiplevel = nestlevel; /* current nesting level */
struct token tk;
struct idf *id;
@@ -315,7 +314,7 @@ static 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;
int ch;
/* read the #defined macro's name */
if (!(str = GetIdentifier())) {
@@ -403,7 +402,7 @@ static void do_if()
static void do_ifdef(int how)
{
register struct idf *id;
struct idf *id;
char *str;
/* how == 1 : ifdef; how == 0 : ifndef
@@ -432,8 +431,8 @@ static void do_ifdef(int how)
static void do_undef()
{
register struct idf *id;
register char *str = GetIdentifier();
struct idf *id;
char *str = GetIdentifier();
/* Forget a macro definition. */
if (str) {
@@ -475,10 +474,10 @@ static int getparams(char *buf[], char parbuf[])
Note that the '(' has already been eaten.
The names of the formal parameters are stored into parbuf.
*/
register char **pbuf = &buf[0];
register int c;
register char *ptr = &parbuf[0];
register char **pbuf2;
char **pbuf = &buf[0];
int c;
char *ptr = &parbuf[0];
char **pbuf2;
LoadChar(c);
c = skipspaces(c,0);
@@ -536,7 +535,7 @@ void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
table entry belonging to the name of the macro.
A warning is given if the definition overwrites another.
*/
register struct macro *newdef = id->id_macro;
struct macro *newdef = id->id_macro;
if (newdef) { /* is there a redefinition? */
if (macroeq(newdef->mc_text, text))
@@ -545,7 +544,7 @@ void macro_def(struct idf *id, char *text, int nformals, int length, int flags)
}
else {
#ifdef DOBITS
register char *p = id->id_text;
unsigned char *p = (unsigned char *)id->id_text;
#define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx)
setbit(bit0);
setbit(bit1);
@@ -573,7 +572,7 @@ static int find_name(char *nm, char *index[])
"index" if it can be found there. 0 is returned if it is
not there.
*/
register char **ip = &index[0];
char **ip = &index[0];
while (*ip)
if (strcmp(nm, *ip++) == 0)
@@ -599,10 +598,10 @@ static char *get_text(char *formals[], int *length)
identifiers, because they might be replaced by some actual
parameter. Other tokens will not be seen as such.
*/
register int c;
register unsigned int text_size;
int c;
unsigned int text_size;
char *text = Malloc(text_size = ITEXTSIZE);
register unsigned int pos = 0;
unsigned int pos = 0;
LoadChar(c);
@@ -639,7 +638,7 @@ static char *get_text(char *formals[], int *length)
else
if (formals && class(c) == STIDF) {
char id_buf[IDFSIZE + 1];
register char *idp = id_buf;
char *idp = id_buf;
int n;
/* read identifier: it may be a formal parameter */

View File

@@ -5,6 +5,9 @@
*/
/* F I L E I N F O R M A T I O N S T R U C T U R E */
#ifndef UTIL_CPP_FILE_INFO_H
#define UTIL_CPP_FILE_INFO_H
struct file_info {
unsigned int fil_lino;
char *fil_name;
@@ -16,3 +19,5 @@ struct file_info {
#define WorkingDir finfo.fil_wdir
extern struct file_info finfo; /* input.c */
#endif /* UTIL_CPP_FILE_INFO_H */

View File

@@ -8,6 +8,7 @@
#include <string.h>
#include <system.h>
#include <alloc.h>
#include "LLlex.h"
#include "class.h"
#include "macro.h"
#include "idf.h"

View File

@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "LLlex.h"
#include "file_info.h"
#include "input.h"
#define INP_TYPE struct file_info

View File

@@ -11,6 +11,7 @@
#include <em_arith.h>
#include <assert.h>
#include <system.h>
#include "LLlex.h"
#include "file_info.h"
#include "idfsize.h"
#include "idf.h"

View File

@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <alloc.h>
#include "LLlex.h"
#include "idfsize.h"
#include "class.h"
#include "macro.h"
@@ -29,7 +30,7 @@ void do_option(char *text)
{
switch(*text++) {
case '-':
options[*text] = 1;
options[*(unsigned char *)text] = 1;
break;
case 'u':
if (! strcmp(text,"ndef")) {
@@ -42,7 +43,7 @@ void do_option(char *text)
break;
case 'C' : /* comment output */
case 'P' : /* run preprocessor stand-alone, without #'s */
options[*(text-1)] = 1;
options[*(unsigned char *)(text-1)] = 1;
break;
case 'A' : /* for Amake */
case 'd' : /* dependency generation */
@@ -56,7 +57,7 @@ void do_option(char *text)
break;
case 'm':
case 'i':
options[*(text-1)] = 1;
options[*(unsigned char *)(text-1)] = 1;
break;
case 'D' : /* -Dname : predefine name */

View File

@@ -27,12 +27,11 @@ void Xflush()
if (do_preprocess) sys_write(STDOUT, _obuf, OBUFSIZE);
}
void preprocess(fn)
char *fn;
void preprocess(char *fn)
{
register int c;
register char *op = _obuf;
register char *ob = &_obuf[OBUFSIZE];
int c;
char *op = _obuf;
char *ob = &_obuf[OBUFSIZE];
char Xbuf[256];
int lineno = 0;
extern char options[];
@@ -45,7 +44,7 @@ void preprocess(fn)
/* Generate a line directive communicating the
source filename
*/
register char *p = Xbuf;
char *p = Xbuf;
sprint(p, "%s 1 \"%s\"\n",
LINE_PREFIX,
@@ -68,7 +67,7 @@ void preprocess(fn)
fn = FileName;
lineno = LineNumber;
if (! options['P']) {
register char *p = Xbuf;
char *p = Xbuf;
sprint(p, "%s %d \"%s\"\n",
LINE_PREFIX,
@@ -140,7 +139,7 @@ void preprocess(fn)
break;
case STSTR:
case STCHAR: {
register int stopc = c;
int stopc = c;
int escaped;
do {
@@ -199,9 +198,9 @@ void preprocess(fn)
case STIDF: {
extern int idfsize; /* ??? */
char buf[IDFSIZE + 1];
register char *tg = &buf[0];
register char *maxpos = &buf[idfsize];
register struct idf *idef;
char *tg = &buf[0];
char *maxpos = &buf[idfsize];
struct idf *idef;
#define tstmac(bx) if (!(bits[c] & bx)) goto nomac
#define cpy if (Unstacked) EnableMacros(); *tg++ = c

View File

@@ -20,6 +20,8 @@
#include "interface.h"
#include "file_info.h"
#include "LLlex.h"
#define EOS '\0'
#define overflow() (fatal("actual parameter buffer overflow"))