merge XFree86 4.3.0.1 to -CURRENT

parent ac5d447a
......@@ -24,6 +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.11 2001/12/17 20:52:22 dawes Exp $ */
#include "def.h"
......@@ -39,7 +40,7 @@ in this Software without prior written authorization from The Open Group.
#define QB 16
#define WB 32
#define SALT '#'
#if pdp11 | vax | ns16000 | mc68000 | ibm032
#if defined(pdp11) || defined(vax) || defined(ns16000) || defined(mc68000) || defined(ibm032)
#define COFF 128
#else
#define COFF 0
......@@ -58,12 +59,10 @@ extern char slotab[];
struct filepointer *currentfile;
struct inclist *currentinc;
cppsetup(line, filep, inc)
register char *line;
register struct filepointer *filep;
register struct inclist *inc;
int
cppsetup(char *line, struct filepointer *filep, struct inclist *inc)
{
register char *p, savec;
char *p, savec;
static boolean setupdone = FALSE;
boolean value;
......@@ -132,10 +131,7 @@ struct _parse_data {
};
static const char *
my_if_errors (ip, cp, expecting)
IfParser *ip;
const char *cp;
const char *expecting;
my_if_errors (IfParser *ip, const char *cp, const char *expecting)
{
struct _parse_data *pd = (struct _parse_data *) ip->data;
int lineno = pd->filep->f_line;
......@@ -162,10 +158,7 @@ my_if_errors (ip, cp, expecting)
#define MAXNAMELEN 256
static struct symtab **
lookup_variable (ip, var, len)
IfParser *ip;
const char *var;
int len;
lookup_variable (IfParser *ip, const char *var, int len)
{
char tmpbuf[MAXNAMELEN + 1];
struct _parse_data *pd = (struct _parse_data *) ip->data;
......@@ -180,10 +173,7 @@ lookup_variable (ip, var, len)
static int
my_eval_defined (ip, var, len)
IfParser *ip;
const char *var;
int len;
my_eval_defined (IfParser *ip, const char *var, int len)
{
if (lookup_variable (ip, var, len))
return 1;
......@@ -194,11 +184,9 @@ my_eval_defined (ip, var, len)
#define isvarfirstletter(ccc) (isalpha(ccc) || (ccc) == '_')
static long
my_eval_variable (ip, var, len)
IfParser *ip;
const char *var;
int len;
my_eval_variable (IfParser *ip, const char *var, int len)
{
long val;
struct symtab **s;
s = lookup_variable (ip, var, len);
......@@ -206,20 +194,21 @@ my_eval_variable (ip, var, len)
return 0;
do {
var = (*s)->s_value;
if (!isvarfirstletter(*var))
if (!isvarfirstletter(*var) || !strcmp((*s)->s_name, var))
break;
s = lookup_variable (ip, var, strlen(var));
} while (s);
return strtol(var, NULL, 0);
var = ParseIfExpression(ip, var, &val);
if (var && *var) debug(4, ("extraneous: '%s'\n", var));
return val;
}
cppsetup(filename, line, filep, inc)
register char *filename;
register char *line;
register struct filepointer *filep;
register struct inclist *inc;
int
cppsetup(char *filename,
char *line,
struct filepointer *filep,
struct inclist *inc)
{
IfParser ip;
struct _parse_data pd;
......
......@@ -24,22 +24,28 @@ 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.14 2003/01/17 17:09:49 tsi Exp $ */
#include "Xos.h"
#include "Xfuncproto.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#if 0
#ifndef X_NOT_POSIX
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
#endif
#endif
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#define MAXDEFINES 512
#define MAXFILES 1024
#define MAXINCFILES 128 /* "-include" files */
#define MAXDIRS 64
#define SYMTABINC 10 /* must be > 1 for define() to work right */
#define TRUE 1
......@@ -61,12 +67,14 @@ in this Software without prior written authorization from The Open Group.
#define SCCS 12
#define ELIF 13
#define EJECT 14
#define WARNING 15
#define IFFALSE 16 /* pseudo value --- never matched */
#define ELIFFALSE 17 /* pseudo value --- never matched */
#define INCLUDEDOT 18 /* pseudo value --- never matched */
#define IFGUESSFALSE 19 /* pseudo value --- never matched */
#define ELIFGUESSFALSE 20 /* pseudo value --- never matched */
#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;
......@@ -113,35 +121,62 @@ struct inclist {
};
struct filepointer {
char *f_name;
char *f_p;
char *f_base;
char *f_end;
long f_len;
long f_line;
long cmdinc_count;
char **cmdinc_list;
long cmdinc_line;
};
#ifndef X_NOT_STDC_ENV
#include <stdlib.h>
#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */
char *malloc(), *realloc();
#endif /* macII */
#else
char *malloc();
char *realloc();
#endif
char *copy();
char *base_name();
char *getline();
struct symtab **slookup();
struct symtab **isdefined();
struct symtab **fdefined();
struct filepointer *getfile();
struct inclist *newinclude();
struct inclist *inc_path();
#if NeedVarargsPrototypes
char *copy(char *str);
int match(char *str, char **list);
char *base_name(char *file);
char *getnextline(struct filepointer *fp);
struct symtab **slookup(char *symbol, struct inclist *file);
struct symtab **isdefined(char *symbol, struct inclist *file,
struct inclist **srcfile);
struct symtab **fdefined(char *symbol, struct inclist *file,
struct inclist **srcfile);
struct filepointer *getfile(char *file);
void included_by(struct inclist *ip,
struct inclist *newfile);
struct inclist *newinclude(char *newfile, char *incstring);
void inc_clean (void);
struct inclist *inc_path(char *file, char *include, int type);
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,
int recursion, boolean failOK);
void recursive_pr_include(struct inclist *head,
char *file, char *base);
void add_include(struct filepointer *filep,
struct inclist *file,
struct inclist *file_red,
char *include, int type,
boolean failOK);
int cppsetup(char *filename,
char *line,
struct filepointer *filep,
struct inclist *inc);
extern void fatalerr(char *, ...);
extern void warning(char *, ...);
extern void warning1(char *, ...);
#endif
......@@ -31,10 +31,13 @@
*
* EXPRESSION := VALUE
* | VALUE BINOP EXPRESSION
* | VALUE '?' EXPRESSION ':' EXPRESSION
*
* VALUE := '(' EXPRESSION ')'
* | '!' VALUE
* | '-' VALUE
* | '+' VALUE
* | '~' VALUE
* | 'defined' '(' variable ')'
* | 'defined' variable
* | # variable '(' variable-list ')'
......@@ -46,19 +49,22 @@
* | '<<' | '>>'
* | '<' | '>' | '<=' | '>='
* | '==' | '!='
* | '&' | '|'
* | '&' | '^' | '|'
* | '&&' | '||'
*
* The normal C order of precidence is supported.
* 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.11 2002/09/23 01:48:08 tsi Exp $ */
#include "ifparser.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/****************************************************************************
Internal Macros and Utilities for Parser
......@@ -71,10 +77,7 @@
static const char *
parse_variable (g, cp, varp)
IfParser *g;
const char *cp;
const char **varp;
parse_variable (IfParser *g, const char *cp, const char **varp)
{
SKIPSPACE (cp);
......@@ -89,32 +92,55 @@ parse_variable (g, cp, varp)
static const char *
parse_number (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_number (IfParser *g, const char *cp, long *valp)
{
long base = 10;
SKIPSPACE (cp);
if (!isdigit(*cp))
return CALLFUNC(g, handle_error) (g, cp, "number");
*valp = strtol(cp, &cp, 0);
/* skip trailing qualifiers */
*valp = 0;
if (*cp == '0') {
cp++;
if ((*cp == 'x') || (*cp == 'X')) {
base = 16;
cp++;
} else {
base = 8;
}
}
/* Ignore overflows and assume ASCII, what source is usually written in */
while (1) {
int increment = -1;
if (base == 8) {
if ((*cp >= '0') && (*cp <= '7'))
increment = *cp++ - '0';
} else if (base == 16) {
if ((*cp >= '0') && (*cp <= '9'))
increment = *cp++ - '0';
else if ((*cp >= 'A') && (*cp <= 'F'))
increment = *cp++ - ('A' - 10);
else if ((*cp >= 'a') && (*cp <= 'f'))
increment = *cp++ - ('a' - 10);
} else { /* Decimal */
if ((*cp >= '0') && (*cp <= '9'))
increment = *cp++ - '0';
}
if (increment < 0)
break;
*valp = (*valp * base) + increment;
}
/* Skip trailing qualifiers */
while (*cp == 'U' || *cp == 'u' || *cp == 'L' || *cp == 'l') cp++;
#if 0
*valp = atoi (cp);
/* EMPTY */
for (cp++; isdigit(*cp); cp++) ;
#endif
return cp;
}
static const char *
parse_character (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_character (IfParser *g, const char *cp, long *valp)
{
char val;
......@@ -143,12 +169,9 @@ parse_character (g, cp, valp)
}
static const char *
parse_value (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_value (IfParser *g, const char *cp, long *valp)
{
const char *var;
const char *var, *varend;
*valp = 0;
......@@ -175,6 +198,15 @@ parse_value (g, cp, valp)
*valp = -(*valp);
return cp;
case '+':
DO (cp = parse_value (g, cp + 1, valp));
return cp;
case '~':
DO (cp = parse_value (g, cp + 1, valp));
*valp = ~(*valp);
return cp;
case '#':
DO (cp = parse_variable (g, cp + 1, &var));
SKIPSPACE (cp);
......@@ -223,7 +255,24 @@ parse_value (g, cp, valp)
return CALLFUNC(g, handle_error) (g, cp, "variable or number");
else {
DO (cp = parse_variable (g, cp, &var));
*valp = (*(g->funcs.eval_variable)) (g, var, 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 != ',')
return CALLFUNC(g, handle_error) (g, cp, ",");
} while (1);
*valp = 1; /* XXX */
cp++;
}
}
return cp;
......@@ -232,10 +281,7 @@ parse_value (g, cp, valp)
static const char *
parse_product (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_product (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -263,10 +309,7 @@ parse_product (g, cp, valp)
static const char *
parse_sum (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_sum (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -289,10 +332,7 @@ parse_sum (g, cp, valp)
static const char *
parse_shift (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_shift (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -319,10 +359,7 @@ parse_shift (g, cp, valp)
static const char *
parse_inequality (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_inequality (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -355,10 +392,7 @@ parse_inequality (g, cp, valp)
static const char *
parse_equality (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_equality (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -385,10 +419,7 @@ parse_equality (g, cp, valp)
static const char *
parse_band (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_band (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -408,16 +439,31 @@ parse_band (g, cp, valp)
static const char *
parse_bor (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_bxor (IfParser *g, const char *cp, long *valp)
{
long rightval;
DO (cp = parse_band (g, cp, valp));
SKIPSPACE (cp);
switch (*cp) {
case '^':
DO (cp = parse_bxor (g, cp + 1, &rightval));
*valp = (*valp ^ rightval);
break;
}
return cp;
}
static const char *
parse_bor (IfParser *g, const char *cp, long *valp)
{
long rightval;
DO (cp = parse_bxor (g, cp, valp));
SKIPSPACE (cp);
switch (*cp) {
case '|':
if (cp[1] != '|') {
......@@ -431,10 +477,7 @@ parse_bor (g, cp, valp)
static const char *
parse_land (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_land (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -454,10 +497,7 @@ parse_land (g, cp, valp)
static const char *
parse_lor (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
parse_lor (IfParser *g, const char *cp, long *valp)
{
long rightval;
......@@ -476,17 +516,34 @@ parse_lor (g, cp, valp)
}
static const char *
parse_cond(IfParser *g, const char *cp, long *valp)
{
long trueval, falseval;
DO (cp = parse_lor (g, cp, valp));
SKIPSPACE (cp);
switch (*cp) {
case '?':
DO (cp = parse_cond (g, cp + 1, &trueval));
SKIPSPACE (cp);
if (*cp != ':')
return CALLFUNC(g, handle_error) (g, cp, ":");
DO (cp = parse_cond (g, cp + 1, &falseval));
*valp = (*valp ? trueval : falseval);
break;
}
return cp;
}
/****************************************************************************
External Entry Points
****************************************************************************/
const char *
ParseIfExpression (g, cp, valp)
IfParser *g;
const char *cp;
long *valp;
ParseIfExpression (IfParser *g, const char *cp, long *valp)
{
return parse_lor (g, cp, valp);
return parse_cond (g, cp, valp);
}
......@@ -31,10 +31,12 @@
*
* EXPRESSION := VALUE
* | VALUE BINOP EXPRESSION
* | VALUE '?' EXPRESSION ':' EXPRESSION
*
* VALUE := '(' EXPRESSION ')'
* | '!' VALUE
* | '-' VALUE
* | '~' VALUE
* | 'defined' '(' variable ')'
* | variable
* | number
......@@ -44,10 +46,10 @@
* | '<<' | '>>'
* | '<' | '>' | '<=' | '>='
* | '==' | '!='
* | '&' | '|'
* | '&' | '^' | '|'
* | '&&' | '||'
*
* The normal C order of precidence is supported.
* The normal C order of precedence is supported.
*
*
* External Entry Points:
......@@ -55,28 +57,27 @@
* ParseIfExpression parse a string for #if
*/
/* $XFree86: xc/config/makedepend/ifparser.h,v 3.5 2001/07/25 15:04:40 dawes Exp $ */
#include <stdio.h>
#define const /**/
typedef int Bool;
#define False 0
#define True 1
typedef struct _if_parser {
struct { /* functions */
char *(*handle_error) (/* struct _if_parser *, const char *,
const char * */);
long (*eval_variable) (/* struct _if_parser *, const char *, int */);
int (*eval_defined) (/* struct _if_parser *, const char *, int */);
const char *(*handle_error) (struct _if_parser *, const char *,
const char *);
long (*eval_variable) (struct _if_parser *, const char *, int);
int (*eval_defined) (struct _if_parser *, const char *, int);
} funcs;
char *data;
} IfParser;
char *ParseIfExpression (
#ifdef __STDC__
const char *ParseIfExpression (
IfParser *,
const char *,
long *
#endif
);
</