Commit 97527faa authored by Egbert Eich's avatar Egbert Eich

Importing vendor version xf86-4_4_99_1 on Sun Mar 14 00:26:39 PST 2004

parent cc985b59
......@@ -24,7 +24,7 @@ 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/cppsetup.c,v 3.10 2001/12/14 19:53:20 dawes Exp $ */
/* $XFree86: xc/config/makedepend/cppsetup.c,v 3.12 2004/03/05 16:02:58 tsi Exp $ */
#include "def.h"
......@@ -86,8 +86,8 @@ cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
pend = p;
ptrtab = slotab+COFF;
*--inp = SALT;
outp=inp;
*--inp = SALT;
outp=inp;
value = yyparse();
*p = savec;
return(value);
......@@ -181,26 +181,231 @@ my_eval_defined (IfParser *ip, const char *var, int len)
return 0;
}
int
variable_has_args (IfParser *ip, const char *var, int len)
{
struct symtab **s = lookup_variable (ip, var, len);
if (!s)
return 0;
if ((*s)->s_args)
return 1;
else
return 0;
}
/*
* this is tiny linked list implementation for temporarily storing
* and retriving pairs of macro parameter names and passed in macro arguments.
*/
typedef struct keyword_type_rec keyword_type;
struct keyword_type_rec {
keyword_type* pnext;
char *name;
char *value;
};
static keyword_type*
build_keyword_list (const char* keys, const char* values)
{
keyword_type *phead = NULL, *pnew;
const char *ptmp;
int len;
while (*keys)
{
/* alloc new member */
pnew = malloc(sizeof(*pnew));
if (!pnew)
{
fprintf(stderr, "out of memory in my_eval_variable\n");
exit(1);
}
/* extract key */
ptmp = keys;
len = 0;
while (*ptmp && (*ptmp != ','))
ptmp++, len++;
pnew->name = malloc(len+1);
strncpy(pnew->name, keys, len);
pnew->name[len] = '\0';
keys = ptmp;
if (*keys)
keys++;
/* extract arg */
ptmp = values;
len = 0;
while (*ptmp && (*ptmp != ',') && (*ptmp != ')'))
ptmp++, len++;
pnew->value = malloc(len+1);
strncpy(pnew->value, values, len);
pnew->value[len] = '\0';
values = ptmp;
if (*values)
values++;
/* chain in this new member */
pnew->pnext = phead;
phead = pnew;
}
return phead;
}
static const keyword_type*
get_keyword_entry (const keyword_type* phead, const char* keyname, const int keylen)
{
while (phead)
{
if (keylen == strlen(phead->name))
if (strncmp(keyname, phead->name, keylen) == 0)
return phead;
phead = phead->pnext;
}
return phead;
}
static void
free_keyword_list (keyword_type* phead)
{
keyword_type* pnext;
while (phead)
{
pnext = phead->pnext;
free(phead->name);
free(phead->value);
free(phead);
phead = pnext;
}
}
#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
static long
my_eval_variable (IfParser *ip, const char *var, int len)
my_eval_variable (IfParser *ip, const char *var, int len, const char *args)
{
long val;
char *newline = NULL;
int newline_len = 0, newline_offset = 0;
struct symtab **s;
s = lookup_variable (ip, var, len);
if (!s)
return 0;
do {
var = (*s)->s_value;
if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
break;
s = lookup_variable (ip, var, strlen(var));
} while (s);
if ((*s)->s_args)
{
const char *psrc, *psrc_qualifier;
char *pdst;
const keyword_type *pkeyword;
keyword_type *pkeylist;
newline_len = 64; /* start with some buffer, might increase later */
newline = malloc(newline_len);
if (!newline)
{
fprintf(stderr, "out of memory in my_eval_variable\n");
exit(1);
}
/* build up a list that pairs keywords and args */
pkeylist = build_keyword_list((*s)->s_args,args);
/* parse for keywords in macro content */
psrc = (*s)->s_value;
pdst = newline;
while (*psrc)
{
/* parse for next qualifier */
psrc_qualifier = psrc;
while (isalnum(*psrc) || *psrc == '_')
psrc++;
/* check if qualifier is in parameter keywords listing of macro */
pkeyword = get_keyword_entry(pkeylist,psrc_qualifier,psrc - psrc_qualifier);
if (pkeyword)
{ /* convert from parameter keyword to given argument */
const char *ptmp = pkeyword->value;
while (*ptmp)
{
*pdst++ = *ptmp++;
newline_offset++;
if (newline_offset + 2 >= newline_len)
{
newline_len *= 2;
newline = realloc(newline, newline_len);
if (!newline)
{
fprintf(stderr, "out of memory in my_eval_variable\n");
exit(1);
}
pdst = &newline[newline_offset];
}
}
}
else
{ /* perform post copy of qualifier that is not a parameter keyword */
const char *ptmp = psrc_qualifier;
while (ptmp < psrc)
{
*pdst++ = *ptmp++;
newline_offset++;
if (newline_offset + 2 >= newline_len)
{
newline_len *= 2;
newline = realloc(newline, newline_len);
if (!newline)
{
fprintf(stderr, "out of memory in my_eval_variable\n");
exit(1);
}
pdst = &newline[newline_offset];
}
}
}
/* duplicate chars that are not qualifier chars */
while (!(isalnum(*psrc) || *psrc == '_' || *psrc == '\0'))
{
*pdst++ = *psrc++;
newline_offset++;
if (newline_offset + 2 >= newline_len)
{
newline_len *= 2;
newline = realloc(newline, newline_len);
if (!newline)
{
fprintf(stderr, "out of memory in my_eval_variable\n");
exit(1);
}
pdst = &newline[newline_offset];
}
}
}
*pdst = '\0';
free_keyword_list(pkeylist);
var = newline;
}
else
{
var = (*s)->s_value;
}
var = ParseIfExpression(ip, var, &val);
if (var && *var) debug(4, ("extraneous: '%s'\n", var));
if (newline) free(newline);
return val;
}
......
......@@ -24,7 +24,7 @@ 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/def.h,v 3.13tsi Exp $ */
/* $XFree86: xc/config/makedepend/def.h,v 3.15 2004/03/05 16:02:58 tsi Exp $ */
#include "Xos.h"
#include "Xfuncproto.h"
......@@ -48,39 +48,39 @@ in this Software without prior written authorization from The Open Group.
#define MAXINCFILES 128 /* "-include" files */
#define MAXDIRS 64
#define SYMTABINC 10 /* must be > 1 for define() to work right */
#define TRUE 1
#define FALSE 0
#define TRUE 1
#define FALSE 0
/* the following must match the directives table in main.c */
#define IF 0
#define IFDEF 1
#define IFNDEF 2
#define ELSE 3
#define ENDIF 4
#define DEFINE 5
#define UNDEF 6
#define INCLUDE 7
#define LINE 8
#define PRAGMA 9
#define ERROR 10
#define IDENT 11
#define SCCS 12
#define ELIF 13
#define EJECT 14
#define WARNING 15
#define INCLUDENEXT 16
#define IFFALSE 17 /* pseudo value --- never matched */
#define ELIFFALSE 18 /* pseudo value --- never matched */
#define INCLUDEDOT 19 /* pseudo value --- never matched */
#define IFGUESSFALSE 20 /* pseudo value --- never matched */
#define ELIFGUESSFALSE 21 /* pseudo value --- never matched */
#define INCLUDENEXTDOT 22 /* pseudo value --- never matched */
#define IF 0
#define IFDEF 1
#define IFNDEF 2
#define ELSE 3
#define ENDIF 4
#define DEFINE 5
#define UNDEF 6
#define INCLUDE 7
#define LINE 8
#define PRAGMA 9
#define ERROR 10
#define IDENT 11
#define SCCS 12
#define ELIF 13
#define EJECT 14
#define WARNING 15
#define INCLUDENEXT 16
#define IFFALSE 17 /* pseudo value --- never matched */
#define ELIFFALSE 18 /* pseudo value --- never matched */
#define INCLUDEDOT 19 /* pseudo value --- never matched */
#define IFGUESSFALSE 20 /* pseudo value --- never matched */
#define ELIFGUESSFALSE 21 /* pseudo value --- never matched */
#define INCLUDENEXTDOT 22 /* pseudo value --- never matched */
#ifdef DEBUG
extern int _debugmask;
/*
* debug levels are:
*
*
* 0 show ifn*(def)*,endif
* 1 trace defined/!defined
* 2 show #include
......@@ -89,7 +89,7 @@ extern int _debugmask;
*/
#define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
#else
#define debug(level,arg) /**/
#define debug(level,arg) /**/
#endif /* DEBUG */
typedef unsigned char boolean;
......@@ -97,6 +97,7 @@ typedef unsigned char boolean;
struct symtab {
char *s_name;
char *s_value;
char *s_args;
};
/* possible i_flag */
......@@ -138,7 +139,7 @@ char *malloc(), *realloc();
#endif /* macII */
char *copy(char *str);
int match(char *str, char **list);
int match(char *str, char **list);
char *base_name(char *file);
char *getnextline(struct filepointer *fp);
struct symtab **slookup(char *symbol, struct inclist *file);
......@@ -147,36 +148,36 @@ struct symtab **isdefined(char *symbol, struct inclist *file,
struct symtab **fdefined(char *symbol, struct inclist *file,
struct inclist **srcfile);
struct filepointer *getfile(char *file);
void included_by(struct inclist *ip,
void included_by(struct inclist *ip,
struct inclist *newfile);
struct inclist *newinclude(char *newfile, char *incstring);
void inc_clean (void);
void inc_clean(void);
struct inclist *inc_path(char *file, char *include, int type);
void freefile(struct filepointer *fp);
void freefile(struct filepointer *fp);
void define2(char *name, char *val, struct inclist *file);
void define(char *def, struct inclist *file);
void undefine(char *symbol, struct inclist *file);
int find_includes(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
void define2(char *name, char *args, char *val,
struct inclist *file);
void define(char *def, struct inclist *file);
void undefine(char *symbol, struct inclist *file);
int find_includes(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
int recursion, boolean failOK);
void recursive_pr_include(struct inclist *head,
void recursive_pr_include(struct inclist *head,
char *file, char *base);
void add_include(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
void add_include(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
char *include, int type,
boolean failOK);
int cppsetup(char *filename,
int cppsetup(char *filename,
char *line,
struct filepointer *filep,
struct inclist *inc);
extern void fatalerr(char *, ...);
extern void warning(char *, ...);
extern void warning1(char *, ...);
......@@ -2,7 +2,7 @@
* $Xorg: ifparser.c,v 1.3 2000/08/17 19:41:50 cpqbld Exp $
*
* Copyright 1992 Network Computing Devices, Inc.
*
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
......@@ -12,7 +12,7 @@
* without specific, written prior permission. Network Computing Devices makes
* no representations about the suitability of this software for any purpose.
* It is provided ``as is'' without express or implied warranty.
*
*
* NETWORK COMPUTING DEVICES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
* IN NO EVENT SHALL NETWORK COMPUTING DEVICES BE LIABLE FOR ANY SPECIAL,
......@@ -20,46 +20,47 @@
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
*
* Author: Jim Fulton
* Network Computing Devices, Inc.
*
*
* Simple if statement processor
*
* This module can be used to evaluate string representations of C language
* if constructs. It accepts the following grammar:
*
*
* EXPRESSION := VALUE
* | VALUE BINOP EXPRESSION
* | VALUE BINOP EXPRESSION
* | VALUE '?' EXPRESSION ':' EXPRESSION
*
*
* VALUE := '(' EXPRESSION ')'
* | '!' VALUE
* | '-' VALUE
* | '+' VALUE
* | '!' VALUE
* | '-' VALUE
* | '+' VALUE
* | '~' VALUE
* | 'defined' '(' variable ')'
* | 'defined' variable
* | 'defined' '(' variable_name ')'
* | 'defined' variable_name
* | # variable '(' variable-list ')'
* | variable
* | number
*
* | variable(arglist)
* | variable
* | number
*
* BINOP := '*' | '/' | '%'
* | '+' | '-'
* | '<<' | '>>'
* | '<' | '>' | '<=' | '>='
* | '==' | '!='
* | '&' | '^' | '|'
* | '&&' | '||'
*
* | '+' | '-'
* | '<<' | '>>'
* | '<' | '>' | '<=' | '>='
* | '==' | '!='
* | '&' | '^' | '|'
* | '&&' | '||'
*
* The normal C order of precedence is supported.
*
*
*
*
* External Entry Points:
*
*
* ParseIfExpression parse a string for #if
*/
/* $XFree86: xc/config/makedepend/ifparser.c,v 3.10tsi Exp $ */
/* $XFree86: xc/config/makedepend/ifparser.c,v 3.12 2004/03/05 16:02:58 tsi Exp $ */
#include "ifparser.h"
#include <ctype.h>
......@@ -77,16 +78,53 @@
static const char *
parse_variable (IfParser *g, const char *cp, const char **varp)
parse_variable_name (IfParser *g, const char *cp, const char **varp, int *varlenp)
{
*varlenp = 0;
SKIPSPACE (cp);
if (!isvarfirstletter(*cp))
return CALLFUNC(g, handle_error) (g, cp, "variable name");
*varp = cp;
for (cp++; isalnum(*cp) || *cp == '_'; cp++) /* EMPTY */;
*varlenp = cp - *varp;
return cp;
}
static const char *
parse_variable (IfParser *g, const char *cp, const char **varp, int *varlenp, const char **argsp)
{
*argsp = NULL;
*varlenp = 0;
SKIPSPACE (cp);
/* this error handling call might prevent us from merging with above code */
if (!isvarfirstletter (*cp))
return CALLFUNC(g, handle_error) (g, cp, "variable name");
*varp = cp;
/* EMPTY */
for (cp++; isalnum(*cp) || *cp == '_'; cp++) ;
for (cp++; isalnum(*cp) || *cp == '_'; cp++) /* EMPTY */;
*varlenp = cp - *varp;
if (variable_has_args(g, *varp, *varlenp))
{
SKIPSPACE (cp);
if (*cp != '(')
{
return CALLFUNC(g, handle_error) (g, cp, "argument list");
}
cp++;
*argsp = cp;
for (cp++; *cp != ')'; cp++) /* EMPTY */;
cp++;
}
return cp;
}
......@@ -171,7 +209,8 @@ parse_character (IfParser *g, const char *cp, long *valp)
static const char *
parse_value (IfParser *g, const char *cp, long *valp)
{
const char *var, *varend;
const char *var, *args;
int varlen;
*valp = 0;
......@@ -183,7 +222,7 @@ parse_value (IfParser *g, const char *cp, long *valp)
case '(':
DO (cp = ParseIfExpression (g, cp + 1, valp));
SKIPSPACE (cp);
if (*cp != ')')
if (*cp != ')')
return CALLFUNC(g, handle_error) (g, cp, ")");
return cp + 1; /* skip the right paren */
......@@ -208,12 +247,12 @@ parse_value (IfParser *g, const char *cp, long *valp)
return cp;
case '#':
DO (cp = parse_variable (g, cp + 1, &var));
DO (cp = parse_variable (g, cp + 1, &var, &varlen, &args));
SKIPSPACE (cp);
if (*cp != '(')
return CALLFUNC(g, handle_error) (g, cp, "(");
do {
DO (cp = parse_variable (g, cp + 1, &var));
DO (cp = parse_variable (g, cp + 1, &var, &varlen, &args));
SKIPSPACE (cp);
} while (*cp && *cp != ')');
if (*cp != ')')
......@@ -230,7 +269,6 @@ parse_value (IfParser *g, const char *cp, long *valp)
case 'd':
if (strncmp (cp, "defined", 7) == 0 && !isalnum(cp[7])) {
int paren = 0;
int len;
cp += 7;
SKIPSPACE (cp);
......@@ -238,43 +276,31 @@ parse_value (IfParser *g, const char *cp, long *valp)
paren = 1;
cp++;
}
DO (cp = parse_variable (g, cp, &var));
len = cp - var;
DO (cp = parse_variable_name (g, cp, &var, &varlen));
SKIPSPACE (cp);
if (paren && *cp != ')')
return CALLFUNC(g, handle_error) (g, cp, ")");
*valp = (*(g->funcs.eval_defined)) (g, var, len);
*valp = (*(g->funcs.eval_defined)) (g, var, varlen);
return cp + paren; /* skip the right paren */
}
/* fall out */
}
if (isdigit(*cp)) {
/* determine the numeric value */
DO (cp = parse_number (g, cp, valp));
} else if (!isvarfirstletter(*cp))
return CALLFUNC(g, handle_error) (g, cp, "variable or number");
} else if (isvarfirstletter(*cp)) {
/* resolve the value of this macro.
* (macro argument substitution will take place
* and recursive macro resolvement will apply) */
DO (cp = parse_variable (g, cp, &var, &varlen, &args));
*valp = (*(g->funcs.eval_variable)) (g, var, varlen, args);
}
else {
DO (cp = parse_variable (g, cp, &var));
varend = cp;
SKIPSPACE(cp);
if (*cp != '(') {
*valp = (*(g->funcs.eval_variable)) (g, var, varend - var);
} else {
do {
long dummy;
DO (cp = ParseIfExpression (g, cp + 1, &dummy));
SKIPSPACE(cp);
if (*cp == ')')
break;
if (*cp != ',')