summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c183
1 files changed, 108 insertions, 75 deletions
diff --git a/parse.c b/parse.c
index 68fde6c..968d2c4 100644
--- a/parse.c
+++ b/parse.c
@@ -24,21 +24,32 @@ used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
+/* $XFree86: xc/config/makedepend/parse.c,v 1.12 2002/02/26 05:09:10 tsi Exp $ */
#include "def.h"
extern char *directives[];
-extern struct inclist maininclist;
-
-int
-gobble(filep, file, file_red)
- register struct filepointer *filep;
- struct inclist *file, *file_red;
+extern struct inclist inclist[ MAXFILES ],
+ *inclistnext,
+ maininclist;
+extern char *includedirs[ ],
+ **includedirsnext;
+
+static int deftype (char *line, struct filepointer *filep,
+ struct inclist *file_red, struct inclist *file,
+ int parse_it);
+static int zero_value(char *filename, char *exp, struct filepointer *filep,
+ struct inclist *file_red);
+static int merge2defines(struct inclist *file1, struct inclist *file2);
+
+static int
+gobble(struct filepointer *filep, struct inclist *file,
+ struct inclist *file_red)
{
- register char *line;
- register int type;
+ char *line;
+ int type;
- while ((line = getline(filep))) {
+ while ((line = getnextline(filep))) {
switch(type = deftype(line, filep, file_red, file, FALSE)) {
case IF:
case IFFALSE:
@@ -68,6 +79,8 @@ gobble(filep, file, file_red)
case SCCS:
case EJECT:
case WARNING:
+ case INCLUDENEXT:
+ case INCLUDENEXTDOT:
break;
case ELIF:
case ELIFFALSE:
@@ -88,14 +101,12 @@ gobble(filep, file, file_red)
/*
* Decide what type of # directive this line is.
*/
-int deftype (line, filep, file_red, file, parse_it)
- register char *line;
- register struct filepointer *filep;
- register struct inclist *file_red, *file;
- int parse_it;
+static int
+deftype (char *line, struct filepointer *filep,
+ struct inclist *file_red, struct inclist *file, int parse_it)
{
register char *p;
- char *directive, savechar;
+ char *directive, savechar, *q;
register int ret;
/*
@@ -106,7 +117,7 @@ int deftype (line, filep, file_red, file, parse_it)
directive++;
p = directive;
- while (*p >= 'a' && *p <= 'z')
+ while ((*p == '_') || (*p >= 'a' && *p <= 'z'))
p++;
savechar = *p;
*p = '\0';
@@ -152,6 +163,11 @@ int deftype (line, filep, file_red, file, parse_it)
*/
while (*p == ' ' || *p == '\t')
p++;
+ q = p + strlen(p);
+ do {
+ q--;
+ } while (*q == ' ' || *q == '\t');
+ q[1] = '\0';
switch (ret) {
case IF:
/*
@@ -174,13 +190,22 @@ int deftype (line, filep, file_red, file, parse_it)
*line = '\0';
break;
case INCLUDE:
- debug(2,("%s, line %d: #include %s\n",
- file->i_file, filep->f_line, p));
+ case INCLUDENEXT:
+ debug(2,("%s, line %d: #include%s %s\n",
+ file->i_file, filep->f_line,
+ (ret == INCLUDE) ? "" : "_next", p));
/* Support ANSI macro substitution */
- {
- struct symtab **sym = isdefined(p, file_red, NULL);
- while (sym) {
+ while (1) {
+ struct symtab **sym;
+
+ if (!*p || *p == '"' || *p == '<')
+ break;
+
+ sym = isdefined(p, file_red, NULL);
+ if (!sym)
+ break;
+
p = (*sym)->s_value;
debug(3,("%s : #includes SYMBOL %s = %s\n",
file->i_incstring,
@@ -188,8 +213,6 @@ int deftype (line, filep, file_red, file, parse_it)
(*sym) -> s_value));
/* mark file as having included a 'soft include' */
file->i_flags |= INCLUDED_SYM;
- sym = isdefined(p, file_red, NULL);
- }
}
/*
@@ -200,7 +223,10 @@ int deftype (line, filep, file_red, file, parse_it)
if (! *p)
return(-2);
if (*p++ == '"') {
- ret = INCLUDEDOT;
+ if (ret == INCLUDE)
+ ret = INCLUDEDOT;
+ else
+ ret = INCLUDENEXTDOT;
while (*p && *p != '"')
*line++ = *p++;
} else
@@ -222,6 +248,7 @@ int deftype (line, filep, file_red, file, parse_it)
case IDENT:
case SCCS:
case EJECT:
+ case WARNING:
debug(0,("%s, line %d: #%s\n",
file->i_file, filep->f_line, directives[ret]));
/*
@@ -232,34 +259,30 @@ int deftype (line, filep, file_red, file, parse_it)
return(ret);
}
-struct symtab **fdefined(symbol, file, srcfile)
- register char *symbol;
- struct inclist *file;
- struct inclist **srcfile;
+struct symtab **
+fdefined(char *symbol, struct inclist *file, struct inclist **srcfile)
{
- register struct inclist **ip;
- register struct symtab **val;
- register int i;
+ struct inclist **ip;
+ struct symtab **val;
+ int i;
static int recurse_lvl = 0;
if (file->i_flags & DEFCHECKED)
return(NULL);
+ debug(2,("Looking for %s in %s\n", symbol, file->i_file));
file->i_flags |= DEFCHECKED;
if ((val = slookup(symbol, file)))
debug(1,("%s defined in %s as %s\n",
symbol, file->i_file, (*val)->s_value));
if (val == NULL && file->i_list)
- {
+ {
for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++)
if (file->i_merged[i]==FALSE) {
val = fdefined(symbol, *ip, srcfile);
- if ((*ip)->i_flags & FINISHED) {
- merge2defines(file,*ip);
- file->i_merged[i]=TRUE;
- }
+ file->i_merged[i]=merge2defines(file,*ip);
if (val!=NULL) break;
}
- }
+ }
else if (val != NULL && srcfile != NULL) *srcfile = file;
recurse_lvl--;
file->i_flags &= ~DEFCHECKED;
@@ -267,12 +290,10 @@ struct symtab **fdefined(symbol, file, srcfile)
return(val);
}
-struct symtab **isdefined(symbol, file, srcfile)
- register char *symbol;
- struct inclist *file;
- struct inclist **srcfile;
+struct symtab **
+isdefined(char *symbol, struct inclist *file, struct inclist **srcfile)
{
- register struct symtab **val;
+ struct symtab **val;
if ((val = slookup(symbol, &maininclist))) {
debug(1,("%s defined on command line\n", symbol));
@@ -288,12 +309,11 @@ struct symtab **isdefined(symbol, file, srcfile)
/*
* Return type based on if the #if expression evaluates to 0
*/
-int
-zero_value(filename, exp, filep, file_red)
- register char *filename;
- register char *exp;
- register struct filepointer *filep;
- register struct inclist *file_red;
+static int
+zero_value(char *filename,
+ char *exp,
+ struct filepointer *filep,
+ struct inclist *file_red)
{
if (cppsetup(filename, exp, filep, file_red))
return(IFFALSE);
@@ -302,9 +322,7 @@ zero_value(filename, exp, filep, file_red)
}
void
-define2(name, val, file)
- char *name, *val;
- struct inclist *file;
+define2(char *name, char *val, struct inclist *file)
{
int first, last, below;
register struct symtab **sp = NULL, **dest;
@@ -364,6 +382,8 @@ define2(name, val, file)
just replace its s_value */
if (sp != NULL)
{
+ debug(1,("redefining %s from %s to %s in file %s\n",
+ name, (*sp)->s_value, val, file->i_file));
free((*sp)->s_value);
(*sp)->s_value = copy(val);
return;
@@ -380,15 +400,14 @@ define2(name, val, file)
if (stab == NULL)
fatalerr("malloc()/realloc() failure in insert_defn()\n");
+ debug(1,("defining %s to %s in file %s\n", name, val, file->i_file));
stab->s_name = copy(name);
stab->s_value = copy(val);
*sp = stab;
}
void
-define(def, file)
- char *def;
- struct inclist *file;
+define(char *def, struct inclist *file)
{
char *val;
@@ -406,9 +425,8 @@ define(def, file)
define2(def, val, file);
}
-struct symtab **slookup(symbol, file)
- register char *symbol;
- register struct inclist *file;
+struct symtab **
+slookup(char *symbol, struct inclist *file)
{
register int first = 0;
register int last = file->i_ndefs - 1;
@@ -446,12 +464,20 @@ struct symtab **slookup(symbol, file)
return(NULL);
}
-int merge2defines(file1, file2)
- struct inclist *file1;
- struct inclist *file2;
+static int
+merge2defines(struct inclist *file1, struct inclist *file2)
{
- if ((file1!=NULL) && (file2!=NULL))
- {
+ int i;
+
+ if ((file1==NULL) || (file2==NULL) ||
+ !(file2->i_flags & FINISHED))
+ return 0;
+
+ for (i=0; i < file2->i_listlen; i++)
+ if (file2->i_merged[i]==FALSE)
+ return 0;
+
+ {
int first1 = 0;
int last1 = file1->i_ndefs - 1;
@@ -462,6 +488,9 @@ int merge2defines(file1, file2)
struct symtab** i_defs = NULL;
int deflen=file1->i_ndefs+file2->i_ndefs;
+ debug(2,("merging %s into %s\n",
+ file2->i_file, file1->i_file));
+
if (deflen>0)
{
/* make sure deflen % SYMTABINC == 0 is still true */
@@ -501,13 +530,10 @@ int merge2defines(file1, file2)
return 1;
}
- return 0;
}
void
-undefine(symbol, file)
- char *symbol;
- register struct inclist *file;
+undefine(char *symbol, struct inclist *file)
{
register struct symtab **ptr;
struct inclist *srcfile;
@@ -520,17 +546,16 @@ undefine(symbol, file)
}
int
-find_includes(filep, file, file_red, recursion, failOK)
- struct filepointer *filep;
- struct inclist *file, *file_red;
- int recursion;
- boolean failOK;
+find_includes(struct filepointer *filep, struct inclist *file,
+ struct inclist *file_red, int recursion, boolean failOK)
{
+ struct inclist *inclistp;
+ char **includedirsp;
register char *line;
register int type;
boolean recfailOK;
- while ((line = getline(filep))) {
+ while ((line = getnextline(filep))) {
switch(type = deftype(line, filep, file_red, file, TRUE)) {
case IF:
doif:
@@ -614,12 +639,19 @@ find_includes(filep, file, file_red, recursion, failOK)
undefine(line, file_red);
break;
case INCLUDE:
- add_include(filep, file, file_red, line, FALSE, failOK);
- break;
case INCLUDEDOT:
- add_include(filep, file, file_red, line, TRUE, failOK);
+ case INCLUDENEXT:
+ case INCLUDENEXTDOT:
+ inclistp = inclistnext;
+ includedirsp = includedirsnext;
+ debug(2,("%s, reading %s, includes %s\n",
+ file_red->i_file, file->i_file, line));
+ add_include(filep, file, file_red, line, type, failOK);
+ inclistnext = inclistp;
+ includedirsnext = includedirsp;
break;
case ERROR:
+ case WARNING:
warning("%s", file_red->i_file);
if (file_red != file)
warning1(" (reading %s)", file->i_file);
@@ -649,5 +681,6 @@ find_includes(filep, file, file_red, recursion, failOK)
}
}
file->i_flags |= FINISHED;
+ debug(2,("finished with %s\n", file->i_file));
return(-1);
}