We are not using wpp at this time. We can always add a

more recent copy if we ever need it.

svn path=/trunk/; revision=10791
This commit is contained in:
Steven Edwards 2004-09-06 15:04:16 +00:00
parent 23e7f4df4f
commit b1d9a8f8ff
12 changed files with 0 additions and 22304 deletions

View file

@ -1,2 +0,0 @@
*.o
*.a

View file

@ -1,29 +0,0 @@
# $Id: Makefile,v 1.1 2003/12/14 19:53:39 sedwards Exp $
PATH_TO_TOP = ../..
TARGET = wpp.a
HOST_CFLAGS = -I$(PATH_TO_TOP)/include/wine -I$(PATH_TO_TOP)/include -D__USE_W32API
OBJECTS = \
lex.yy.o \
y.tab.o \
mkstemps.o \
preproc.o \
wpp.o
all: $(TARGET)
%.o: %.c
$(HOST_CC) $(HOST_CFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(HOST_AR) -r $(TARGET) $^
clean:
- $(RM) *.o
- $(RM) $(TARGET)
.PHONY: all clean
include $(PATH_TO_TOP)/rules.mak

View file

@ -1,37 +0,0 @@
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
LEXOPT = -Cf #-w -b
YACCOPT = #-v
MODULE = libwpp.a
C_SRCS = \
preproc.c \
wpp.c
EXTRA_SRCS = ppy.y ppl.l
EXTRA_OBJS = y.tab.o @LEX_OUTPUT_ROOT@.o
all: $(MODULE)
@MAKE_RULES@
$(MODULE): $(OBJS)
$(RM) $@
$(AR) $@ $(OBJS)
$(RANLIB) $@
y.tab.c y.tab.h: ppy.y
$(YACC) $(YACCOPT) -ppp -d -t $(SRCDIR)/ppy.y
# hack to allow parallel make
y.tab.h: y.tab.c
y.tab.o: y.tab.h
@LEX_OUTPUT_ROOT@.c: ppl.l
$(LEX) $(LEXOPT) -d -Ppp -o$@ -8 $(SRCDIR)/ppl.l
@LEX_OUTPUT_ROOT@.o: y.tab.h
### Dependencies:

File diff suppressed because it is too large Load diff

View file

@ -1,139 +0,0 @@
/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc.
This file is derived from mkstemp.c from the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "wine/port.h"
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_PROCESS_H
#include <process.h>
#endif
/* We need to provide a type for gcc_uint64_t. */
#ifdef __GNUC__
__extension__ typedef unsigned long long gcc_uint64_t;
#else
typedef unsigned long gcc_uint64_t;
#endif
#ifndef TMP_MAX
#define TMP_MAX 16384
#endif
/*
@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len})
Generate a unique temporary file name from @var{template}.
@var{template} has the form:
@example
@var{path}/ccXXXXXX@var{suffix}
@end example
@var{suffix_len} tells us how long @var{suffix} is (it can be zero
length). The last six characters of @var{template} before @var{suffix}
must be @samp{XXXXXX}; they are replaced with a string that makes the
filename unique. Returns a file descriptor open on the file for
reading and writing.
@end deftypefn
*/
int
mkstemps (
char *template,
int suffix_len)
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static gcc_uint64_t value;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
#endif
char *XXXXXX;
size_t len;
int count;
len = strlen (template);
if ((int) len < 6 + suffix_len
|| strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6))
{
return -1;
}
XXXXXX = &template[len - 6 - suffix_len];
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
gettimeofday (&tv, NULL);
value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
#else
value += getpid ();
#endif
for (count = 0; count < TMP_MAX; ++count)
{
gcc_uint64_t v = value;
int fd;
/* Fill in the random bits. */
XXXXXX[0] = letters[v % 62];
v /= 62;
XXXXXX[1] = letters[v % 62];
v /= 62;
XXXXXX[2] = letters[v % 62];
v /= 62;
XXXXXX[3] = letters[v % 62];
v /= 62;
XXXXXX[4] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
#ifdef VMS
fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd");
#else
fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600);
#endif
if (fd >= 0)
/* The file does not exist. */
return fd;
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
with (module 2^32). */
value += 7777;
}
/* We return the null string if we can't find a unique file name. */
template[0] = '\0';
return -1;
}

File diff suppressed because it is too large Load diff

View file

@ -1,658 +0,0 @@
/*
* Wrc preprocessor syntax analysis
*
* Copyright 1999-2000 Bertho A. Stultiens (BS)
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* 24-Apr-2000 BS Restructured the lot to fit the new scanner
* and reintegrate into the wine-tree.
* 01-Jan-2000 BS FIXME: win16 preprocessor calculates with
* 16 bit ints and overflows...?
* 26-Dec-1999 BS Started this file
*
*/
%{
#include "config.h"
#include "wine/port.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "wpp_private.h"
#define UNARY_OP(r, v, OP) \
switch(v.type) \
{ \
case cv_sint: r.val.si = OP v.val.si; break; \
case cv_uint: r.val.ui = OP v.val.ui; break; \
case cv_slong: r.val.sl = OP v.val.sl; break; \
case cv_ulong: r.val.ul = OP v.val.ul; break; \
case cv_sll: r.val.sll = OP v.val.sll; break; \
case cv_ull: r.val.ull = OP v.val.ull; break; \
}
#define cv_signed(v) ((v.type & FLAG_SIGNED) != 0)
#define BIN_OP_INT(r, v1, v2, OP) \
r.type = v1.type; \
if(cv_signed(v1) && cv_signed(v2)) \
r.val.si = v1.val.si OP v2.val.si; \
else if(cv_signed(v1) && !cv_signed(v2)) \
r.val.si = v1.val.si OP v2.val.ui; \
else if(!cv_signed(v1) && cv_signed(v2)) \
r.val.ui = v1.val.ui OP v2.val.si; \
else \
r.val.ui = v1.val.ui OP v2.val.ui;
#define BIN_OP_LONG(r, v1, v2, OP) \
r.type = v1.type; \
if(cv_signed(v1) && cv_signed(v2)) \
r.val.sl = v1.val.sl OP v2.val.sl; \
else if(cv_signed(v1) && !cv_signed(v2)) \
r.val.sl = v1.val.sl OP v2.val.ul; \
else if(!cv_signed(v1) && cv_signed(v2)) \
r.val.ul = v1.val.ul OP v2.val.sl; \
else \
r.val.ul = v1.val.ul OP v2.val.ul;
#define BIN_OP_LONGLONG(r, v1, v2, OP) \
r.type = v1.type; \
if(cv_signed(v1) && cv_signed(v2)) \
r.val.sll = v1.val.sll OP v2.val.sll; \
else if(cv_signed(v1) && !cv_signed(v2)) \
r.val.sll = v1.val.sll OP v2.val.ull; \
else if(!cv_signed(v1) && cv_signed(v2)) \
r.val.ull = v1.val.ull OP v2.val.sll; \
else \
r.val.ull = v1.val.ull OP v2.val.ull;
#define BIN_OP(r, v1, v2, OP) \
switch(v1.type & SIZE_MASK) \
{ \
case SIZE_INT: BIN_OP_INT(r, v1, v2, OP); break; \
case SIZE_LONG: BIN_OP_LONG(r, v1, v2, OP); break; \
case SIZE_LONGLONG: BIN_OP_LONGLONG(r, v1, v2, OP); break; \
default: pp_internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \
}
/*
* Prototypes
*/
static int boolean(cval_t *v);
static void promote_equal_size(cval_t *v1, cval_t *v2);
static void cast_to_sint(cval_t *v);
static void cast_to_uint(cval_t *v);
static void cast_to_slong(cval_t *v);
static void cast_to_ulong(cval_t *v);
static void cast_to_sll(cval_t *v);
static void cast_to_ull(cval_t *v);
static marg_t *new_marg(char *str, def_arg_t type);
static marg_t *add_new_marg(char *str, def_arg_t type);
static int marg_index(char *id);
static mtext_t *new_mtext(char *str, int idx, def_exp_t type);
static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp);
static char *merge_text(char *s1, char *s2);
/*
* Local variables
*/
static marg_t **macro_args; /* Macro parameters array while parsing */
static int nmacro_args;
%}
%union{
int sint;
unsigned int uint;
long slong;
unsigned long ulong;
wrc_sll_t sll;
wrc_ull_t ull;
int *iptr;
char *cptr;
cval_t cval;
marg_t *marg;
mtext_t *mtext;
}
%token tRCINCLUDE
%token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
%token tINCLUDE tLINE tGCCLINE tERROR tWARNING tPRAGMA tPPIDENT
%token tUNDEF tMACROEND tCONCAT tELIPSIS tSTRINGIZE
%token <cptr> tIDENT tLITERAL tMACRO tDEFINE
%token <cptr> tDQSTRING tSQSTRING tIQSTRING
%token <uint> tUINT
%token <sint> tSINT
%token <ulong> tULONG
%token <slong> tSLONG
%token <ull> tULONGLONG
%token <sll> tSLONGLONG
%token <cptr> tRCINCLUDEPATH
%right '?' ':'
%left tLOGOR
%left tLOGAND
%left '|'
%left '^'
%left '&'
%left tEQ tNE
%left '<' tLTE '>' tGTE
%left tLSHIFT tRSHIFT
%left '+' '-'
%left '*' '/'
%right '~' '!'
%type <cval> pp_expr
%type <marg> emargs margs
%type <mtext> opt_mtexts mtexts mtext
%type <sint> allmargs
%type <cptr> opt_text text
/*
**************************************************************************
* The parser starts here
**************************************************************************
*/
%%
pp_file : /* Empty */
| pp_file preprocessor
;
preprocessor
: tINCLUDE tDQSTRING tNL { pp_do_include($2, 1); }
| tINCLUDE tIQSTRING tNL { pp_do_include($2, 0); }
| tIF pp_expr tNL { pp_next_if_state(boolean(&$2)); }
| tIFDEF tIDENT tNL { pp_next_if_state(pplookup($2) != NULL); free($2); }
| tIFNDEF tIDENT tNL {
int t = pplookup($2) == NULL;
if(pp_incl_state.state == 0 && t && !pp_incl_state.seen_junk)
{
pp_incl_state.state = 1;
pp_incl_state.ppp = $2;
pp_incl_state.ifdepth = pp_get_if_depth();
}
else if(pp_incl_state.state != 1)
{
pp_incl_state.state = -1;
free($2);
}
else
free($2);
pp_next_if_state(t);
if(pp_status.debug)
fprintf(stderr, "tIFNDEF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
}
| tELIF pp_expr tNL {
pp_if_state_t s = pp_pop_if();
switch(s)
{
case if_true:
case if_elif:
pp_push_if(if_elif);
break;
case if_false:
pp_push_if(boolean(&$2) ? if_true : if_false);
break;
case if_ignore:
pp_push_if(if_ignore);
break;
case if_elsetrue:
case if_elsefalse:
pperror("#elif cannot follow #else");
default:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
}
}
| tELSE tNL {
pp_if_state_t s = pp_pop_if();
switch(s)
{
case if_true:
pp_push_if(if_elsefalse);
break;
case if_elif:
pp_push_if(if_elif);
break;
case if_false:
pp_push_if(if_elsetrue);
break;
case if_ignore:
pp_push_if(if_ignore);
break;
case if_elsetrue:
case if_elsefalse:
pperror("#else clause already defined");
default:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
}
}
| tENDIF tNL {
pp_pop_if();
if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
{
pp_incl_state.state = 2;
pp_incl_state.seen_junk = 0;
}
else if(pp_incl_state.state != 1)
{
pp_incl_state.state = -1;
}
if(pp_status.debug)
fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
}
| tUNDEF tIDENT tNL { pp_del_define($2); free($2); }
| tDEFINE opt_text tNL { pp_add_define($1, $2); }
| tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
pp_add_macro($1, macro_args, nmacro_args, $5);
}
| tLINE tSINT tDQSTRING tNL { fprintf(ppout, "# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tNL { fprintf(ppout, "# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tNL
{ fprintf(ppout, "# %d %s %d\n", $2, $3, $4); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
{ fprintf(ppout, "# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
{ fprintf(ppout, "# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
{ fprintf(ppout, "# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
| tGCCLINE tNL /* The null-token */
| tERROR opt_text tNL { pperror("#error directive: '%s'", $2); if($2) free($2); }
| tWARNING opt_text tNL { ppwarning("#warning directive: '%s'", $2); if($2) free($2); }
| tPRAGMA opt_text tNL { fprintf(ppout, "#pragma %s\n", $2 ? $2 : ""); if ($2) free($2); }
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppwarning("#ident ignored (arg: '%s')", $2); if($2) free($2); }
| tRCINCLUDE tRCINCLUDEPATH {
int nl=strlen($2) +3;
char *fn=pp_xmalloc(nl);
sprintf(fn,"\"%s\"",$2);
free($2);
pp_do_include(fn,1);
}
| tRCINCLUDE tDQSTRING {
pp_do_include($2,1);
}
/*| tNL*/
;
opt_text: /* Empty */ { $$ = NULL; }
| text { $$ = $1; }
;
text : tLITERAL { $$ = $1; }
| tDQSTRING { $$ = $1; }
| tSQSTRING { $$ = $1; }
| text tLITERAL { $$ = merge_text($1, $2); }
| text tDQSTRING { $$ = merge_text($1, $2); }
| text tSQSTRING { $$ = merge_text($1, $2); }
;
res_arg : /* Empty */ { macro_args = NULL; nmacro_args = 0; }
;
allmargs: /* Empty */ { $$ = 0; macro_args = NULL; nmacro_args = 0; }
| emargs { $$ = nmacro_args; }
;
emargs : margs { $$ = $1; }
| margs ',' tELIPSIS { $$ = add_new_marg(NULL, arg_list); nmacro_args *= -1; }
;
margs : margs ',' tIDENT { $$ = add_new_marg($3, arg_single); }
| tIDENT { $$ = add_new_marg($1, arg_single); }
;
opt_mtexts
: /* Empty */ { $$ = NULL; }
| mtexts {
for($$ = $1; $$ && $$->prev; $$ = $$->prev)
;
}
;
mtexts : mtext { $$ = $1; }
| mtexts mtext { $$ = combine_mtext($1, $2); }
;
mtext : tLITERAL { $$ = new_mtext($1, 0, exp_text); }
| tDQSTRING { $$ = new_mtext($1, 0, exp_text); }
| tSQSTRING { $$ = new_mtext($1, 0, exp_text); }
| tCONCAT { $$ = new_mtext(NULL, 0, exp_concat); }
| tSTRINGIZE tIDENT {
int mat = marg_index($2);
if(mat < 0)
pperror("Stringification identifier must be an argument parameter");
$$ = new_mtext(NULL, mat, exp_stringize);
}
| tIDENT {
int mat = marg_index($1);
if(mat >= 0)
$$ = new_mtext(NULL, mat, exp_subst);
else
$$ = new_mtext($1, 0, exp_text);
}
;
pp_expr : tSINT { $$.type = cv_sint; $$.val.si = $1; }
| tUINT { $$.type = cv_uint; $$.val.ui = $1; }
| tSLONG { $$.type = cv_slong; $$.val.sl = $1; }
| tULONG { $$.type = cv_ulong; $$.val.ul = $1; }
| tSLONGLONG { $$.type = cv_sll; $$.val.sl = $1; }
| tULONGLONG { $$.type = cv_ull; $$.val.ul = $1; }
| tDEFINED tIDENT { $$.type = cv_sint; $$.val.si = pplookup($2) != NULL; }
| tDEFINED '(' tIDENT ')' { $$.type = cv_sint; $$.val.si = pplookup($3) != NULL; }
| tIDENT { $$.type = cv_sint; $$.val.si = 0; }
| pp_expr tLOGOR pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) || boolean(&$3); }
| pp_expr tLOGAND pp_expr { $$.type = cv_sint; $$.val.si = boolean(&$1) && boolean(&$3); }
| pp_expr tEQ pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ==) }
| pp_expr tNE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, !=) }
| pp_expr '<' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <) }
| pp_expr '>' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >) }
| pp_expr tLTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <=) }
| pp_expr tGTE pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >=) }
| pp_expr '+' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, +) }
| pp_expr '-' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, -) }
| pp_expr '^' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, ^) }
| pp_expr '&' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, &) }
| pp_expr '|' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, |) }
| pp_expr '*' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, *) }
| pp_expr '/' pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, /) }
| pp_expr tLSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, <<) }
| pp_expr tRSHIFT pp_expr { promote_equal_size(&$1, &$3); BIN_OP($$, $1, $3, >>) }
| '+' pp_expr { $$ = $2; }
| '-' pp_expr { UNARY_OP($$, $2, -) }
| '~' pp_expr { UNARY_OP($$, $2, ~) }
| '!' pp_expr { $$.type = cv_sint; $$.val.si = !boolean(&$2); }
| '(' pp_expr ')' { $$ = $2; }
| pp_expr '?' pp_expr ':' pp_expr { $$ = boolean(&$1) ? $3 : $5; }
;
%%
/*
**************************************************************************
* Support functions
**************************************************************************
*/
static void cast_to_sint(cval_t *v)
{
switch(v->type)
{
case cv_sint: break;
case cv_uint: break;
case cv_slong: v->val.si = v->val.sl; break;
case cv_ulong: v->val.si = v->val.ul; break;
case cv_sll: v->val.si = v->val.sll; break;
case cv_ull: v->val.si = v->val.ull; break;
}
v->type = cv_sint;
}
static void cast_to_uint(cval_t *v)
{
switch(v->type)
{
case cv_sint: break;
case cv_uint: break;
case cv_slong: v->val.ui = v->val.sl; break;
case cv_ulong: v->val.ui = v->val.ul; break;
case cv_sll: v->val.ui = v->val.sll; break;
case cv_ull: v->val.ui = v->val.ull; break;
}
v->type = cv_uint;
}
static void cast_to_slong(cval_t *v)
{
switch(v->type)
{
case cv_sint: v->val.sl = v->val.si; break;
case cv_uint: v->val.sl = v->val.ui; break;
case cv_slong: break;
case cv_ulong: break;
case cv_sll: v->val.sl = v->val.sll; break;
case cv_ull: v->val.sl = v->val.ull; break;
}
v->type = cv_slong;
}
static void cast_to_ulong(cval_t *v)
{
switch(v->type)
{
case cv_sint: v->val.ul = v->val.si; break;
case cv_uint: v->val.ul = v->val.ui; break;
case cv_slong: break;
case cv_ulong: break;
case cv_sll: v->val.ul = v->val.sll; break;
case cv_ull: v->val.ul = v->val.ull; break;
}
v->type = cv_ulong;
}
static void cast_to_sll(cval_t *v)
{
switch(v->type)
{
case cv_sint: v->val.sll = v->val.si; break;
case cv_uint: v->val.sll = v->val.ui; break;
case cv_slong: v->val.sll = v->val.sl; break;
case cv_ulong: v->val.sll = v->val.ul; break;
case cv_sll: break;
case cv_ull: break;
}
v->type = cv_sll;
}
static void cast_to_ull(cval_t *v)
{
switch(v->type)
{
case cv_sint: v->val.ull = v->val.si; break;
case cv_uint: v->val.ull = v->val.ui; break;
case cv_slong: v->val.ull = v->val.sl; break;
case cv_ulong: v->val.ull = v->val.ul; break;
case cv_sll: break;
case cv_ull: break;
}
v->type = cv_ull;
}
static void promote_equal_size(cval_t *v1, cval_t *v2)
{
#define cv_sizeof(v) ((int)(v->type & SIZE_MASK))
int s1 = cv_sizeof(v1);
int s2 = cv_sizeof(v2);
#undef cv_sizeof
if(s1 == s2)
return;
else if(s1 > s2)
{
switch(v1->type)
{
case cv_sint: cast_to_sint(v2); break;
case cv_uint: cast_to_uint(v2); break;
case cv_slong: cast_to_slong(v2); break;
case cv_ulong: cast_to_ulong(v2); break;
case cv_sll: cast_to_sll(v2); break;
case cv_ull: cast_to_ull(v2); break;
}
}
else
{
switch(v2->type)
{
case cv_sint: cast_to_sint(v1); break;
case cv_uint: cast_to_uint(v1); break;
case cv_slong: cast_to_slong(v1); break;
case cv_ulong: cast_to_ulong(v1); break;
case cv_sll: cast_to_sll(v1); break;
case cv_ull: cast_to_ull(v1); break;
}
}
}
static int boolean(cval_t *v)
{
switch(v->type)
{
case cv_sint: return v->val.si != (int)0;
case cv_uint: return v->val.ui != (unsigned int)0;
case cv_slong: return v->val.sl != (long)0;
case cv_ulong: return v->val.ul != (unsigned long)0;
case cv_sll: return v->val.sll != (wrc_sll_t)0;
case cv_ull: return v->val.ull != (wrc_ull_t)0;
}
return 0;
}
static marg_t *new_marg(char *str, def_arg_t type)
{
marg_t *ma = pp_xmalloc(sizeof(marg_t));
ma->arg = str;
ma->type = type;
ma->nnl = 0;
return ma;
}
static marg_t *add_new_marg(char *str, def_arg_t type)
{
marg_t *ma = new_marg(str, type);
nmacro_args++;
macro_args = pp_xrealloc(macro_args, nmacro_args * sizeof(macro_args[0]));
macro_args[nmacro_args-1] = ma;
return ma;
}
static int marg_index(char *id)
{
int t;
for(t = 0; t < nmacro_args; t++)
{
if(!strcmp(id, macro_args[t]->arg))
break;
}
return t < nmacro_args ? t : -1;
}
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
{
mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
if(str == NULL)
mt->subst.argidx = idx;
else
mt->subst.text = str;
mt->type = type;
mt->next = mt->prev = NULL;
return mt;
}
static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
{
if(!tail)
return mtp;
if(!mtp)
return tail;
if(tail->type == exp_text && mtp->type == exp_text)
{
tail->subst.text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
strcat(tail->subst.text, mtp->subst.text);
free(mtp->subst.text);
free(mtp);
return tail;
}
if(tail->type == exp_concat && mtp->type == exp_concat)
{
free(mtp);
return tail;
}
if(tail->type == exp_concat && mtp->type == exp_text)
{
int len = strlen(mtp->subst.text);
while(len)
{
/* FIXME: should delete space from head of string */
if(isspace(mtp->subst.text[len-1] & 0xff))
mtp->subst.text[--len] = '\0';
else
break;
}
if(!len)
{
free(mtp->subst.text);
free(mtp);
return tail;
}
}
if(tail->type == exp_text && mtp->type == exp_concat)
{
int len = strlen(tail->subst.text);
while(len)
{
if(isspace(tail->subst.text[len-1] & 0xff))
tail->subst.text[--len] = '\0';
else
break;
}
if(!len)
{
mtp->prev = tail->prev;
mtp->next = tail->next;
if(tail->prev)
tail->prev->next = mtp;
free(tail->subst.text);
free(tail);
return mtp;
}
}
tail->next = mtp;
mtp->prev = tail;
return mtp;
}
static char *merge_text(char *s1, char *s2)
{
int l1 = strlen(s1);
int l2 = strlen(s2);
s1 = pp_xrealloc(s1, l1+l2+1);
memcpy(s1+l1, s2, l2+1);
free(s2);
return s1;
}

View file

@ -1,616 +0,0 @@
/*
* Copyright 1998 Bertho A. Stultiens (BS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#include "wpp_private.h"
struct pp_status pp_status;
#define HASHKEY 2039
typedef struct pp_def_state
{
struct pp_def_state *next;
pp_entry_t *defines[HASHKEY];
} pp_def_state_t;
static pp_def_state_t *pp_def_state;
#define MAXIFSTACK 64
static pp_if_state_t if_stack[MAXIFSTACK];
static int if_stack_idx = 0;
#if 0
void pp_print_status(void) __attribute__((destructor));
void pp_print_status(void)
{
int i;
int sum;
int total = 0;
pp_entry_t *ppp;
fprintf(stderr, "Defines statistics:\n");
for(i = 0; i < HASHKEY; i++)
{
sum = 0;
for(ppp = pp_def_state->defines[i]; ppp; ppp = ppp->next)
sum++;
total += sum;
if (sum) fprintf(stderr, "%4d, %3d\n", i, sum);
}
fprintf(stderr, "Total defines: %d\n", total);
}
#endif
void *pp_xmalloc(size_t size)
{
void *res;
assert(size > 0);
res = malloc(size);
if(res == NULL)
{
fprintf(stderr, "Virtual memory exhausted.\n");
exit(2);
}
return res;
}
void *pp_xrealloc(void *p, size_t size)
{
void *res;
assert(size > 0);
res = realloc(p, size);
if(res == NULL)
{
fprintf(stderr, "Virtual memory exhausted.\n");
exit(2);
}
return res;
}
char *pp_xstrdup(const char *str)
{
char *s;
assert(str != NULL);
s = pp_xmalloc(strlen(str)+1);
return strcpy(s, str);
}
/* Don't comment on the hash, its primitive but functional... */
static int pphash(const char *str)
{
int sum = 0;
while(*str)
sum += *str++;
return sum % HASHKEY;
}
pp_entry_t *pplookup(const char *ident)
{
int idx = pphash(ident);
pp_entry_t *ppp;
for(ppp = pp_def_state->defines[idx]; ppp; ppp = ppp->next)
{
if(!strcmp(ident, ppp->ident))
return ppp;
}
return NULL;
}
static void free_pp_entry( pp_entry_t *ppp, int idx )
{
if(ppp->iep)
{
if(ppp->iep == pp_includelogiclist)
{
pp_includelogiclist = ppp->iep->next;
if(pp_includelogiclist)
pp_includelogiclist->prev = NULL;
}
else
{
ppp->iep->prev->next = ppp->iep->next;
if(ppp->iep->next)
ppp->iep->next->prev = ppp->iep->prev;
}
free(ppp->iep->filename);
free(ppp->iep);
}
if(pp_def_state->defines[idx] == ppp)
{
pp_def_state->defines[idx] = ppp->next;
if(pp_def_state->defines[idx])
pp_def_state->defines[idx]->prev = NULL;
}
else
{
ppp->prev->next = ppp->next;
if(ppp->next)
ppp->next->prev = ppp->prev;
}
free(ppp);
}
/* push a new (empty) define state */
void pp_push_define_state(void)
{
pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
memset( state->defines, 0, sizeof(state->defines) );
state->next = pp_def_state;
pp_def_state = state;
}
/* pop the current define state */
void pp_pop_define_state(void)
{
int i;
pp_entry_t *ppp;
pp_def_state_t *state;
for (i = 0; i < HASHKEY; i++)
{
while ((ppp = pp_def_state->defines[i]) != NULL) free_pp_entry( ppp, i );
}
state = pp_def_state;
pp_def_state = state->next;
free( state );
}
void pp_del_define(const char *name)
{
pp_entry_t *ppp;
if((ppp = pplookup(name)) == NULL)
{
if(pp_status.pedantic)
ppwarning("%s was not defined", name);
return;
}
free_pp_entry( ppp, pphash(name) );
if(pp_status.debug)
printf("Deleted (%s, %d) <%s>\n", pp_status.input, pp_status.line_number, name);
}
pp_entry_t *pp_add_define(char *def, char *text)
{
int len;
char *cptr;
int idx = pphash(def);
pp_entry_t *ppp;
if((ppp = pplookup(def)) != NULL)
{
if(pp_status.pedantic)
ppwarning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
pp_del_define(def);
}
ppp = pp_xmalloc(sizeof(pp_entry_t));
memset( ppp, 0, sizeof(*ppp) );
ppp->ident = def;
ppp->type = def_define;
ppp->subst.text = text;
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
ppp->next = pp_def_state->defines[idx];
pp_def_state->defines[idx] = ppp;
if(ppp->next)
ppp->next->prev = ppp;
if(text)
{
/* Strip trailing white space from subst text */
len = strlen(text);
while(len && strchr(" \t\r\n", text[len-1]))
{
text[--len] = '\0';
}
/* Strip leading white space from subst text */
for(cptr = text; *cptr && strchr(" \t\r", *cptr); cptr++)
;
if(text != cptr)
memmove(text, cptr, strlen(cptr)+1);
}
if(pp_status.debug)
printf("Added define (%s, %d) <%s> to <%s>\n", pp_status.input, pp_status.line_number, ppp->ident, text ? text : "(null)");
return ppp;
}
pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
{
int idx = pphash(id);
pp_entry_t *ppp;
if((ppp = pplookup(id)) != NULL)
{
if(pp_status.pedantic)
ppwarning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
pp_del_define(id);
}
ppp = pp_xmalloc(sizeof(pp_entry_t));
memset( ppp, 0, sizeof(*ppp) );
ppp->ident = id;
ppp->type = def_macro;
ppp->margs = args;
ppp->nargs = nargs;
ppp->subst.mtext= exp;
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
ppp->next = pp_def_state->defines[idx];
pp_def_state->defines[idx] = ppp;
if(ppp->next)
ppp->next->prev = ppp;
if(pp_status.debug)
{
fprintf(stderr, "Added macro (%s, %d) <%s(%d)> to <", pp_status.input, pp_status.line_number, ppp->ident, nargs);
for(; exp; exp = exp->next)
{
switch(exp->type)
{
case exp_text:
fprintf(stderr, " \"%s\" ", exp->subst.text);
break;
case exp_stringize:
fprintf(stderr, " #(%d) ", exp->subst.argidx);
break;
case exp_concat:
fprintf(stderr, "##");
break;
case exp_subst:
fprintf(stderr, " <%d> ", exp->subst.argidx);
break;
}
}
fprintf(stderr, ">\n");
}
return ppp;
}
/*
*-------------------------------------------------------------------------
* Include management
*-------------------------------------------------------------------------
*/
#if defined(_Windows) || defined(__MSDOS__)
#define INCLUDESEPARATOR ";"
#else
#define INCLUDESEPARATOR ":"
#endif
static char **includepath;
static int nincludepath = 0;
void wpp_add_include_path(const char *path)
{
char *tok;
char *cpy = pp_xstrdup(path);
tok = strtok(cpy, INCLUDESEPARATOR);
while(tok)
{
char *dir;
char *cptr;
if(strlen(tok) == 0)
continue;
dir = pp_xstrdup(tok);
for(cptr = dir; *cptr; cptr++)
{
/* Convert to forward slash */
if(*cptr == '\\')
*cptr = '/';
}
/* Kill eventual trailing '/' */
if(*(cptr = dir + strlen(dir)-1) == '/')
*cptr = '\0';
/* Add to list */
nincludepath++;
includepath = pp_xrealloc(includepath, nincludepath * sizeof(*includepath));
includepath[nincludepath-1] = dir;
tok = strtok(NULL, INCLUDESEPARATOR);
}
free(cpy);
}
char *wpp_find_include(const char *name, int search)
{
char *cpy = pp_xstrdup(name);
char *cptr;
int i, fd;
for(cptr = cpy; *cptr; cptr++)
{
/* kill double backslash */
if(*cptr == '\\' && *(cptr+1) == '\\')
memmove(cptr, cptr+1, strlen(cptr));
/* Convert to forward slash */
if(*cptr == '\\')
*cptr = '/';
}
if(search)
{
/* Search current dir and then -I path */
fd = open( cpy, O_RDONLY );
if (fd != -1)
{
close( fd );
return cpy;
}
}
/* Search -I path */
for(i = 0; i < nincludepath; i++)
{
char *path;
path = pp_xmalloc(strlen(includepath[i]) + strlen(cpy) + 2);
strcpy(path, includepath[i]);
strcat(path, "/");
strcat(path, cpy);
fd = open( path, O_RDONLY );
if (fd != -1)
{
close( fd );
free( cpy );
return path;
}
free( path );
}
free( cpy );
return NULL;
}
FILE *pp_open_include(const char *name, int search, char **newpath)
{
char *path;
FILE *fp;
if (!(path = wpp_find_include( name, search ))) return NULL;
fp = fopen(path, "rt");
if (fp)
{
if (pp_status.debug)
printf("Going to include <%s>\n", path);
if (newpath) *newpath = path;
else free( path );
return fp;
}
free( path );
return NULL;
}
/*
*-------------------------------------------------------------------------
* #if, #ifdef, #ifndef, #else, #elif and #endif state management
*
* #if state transitions are made on basis of the current TOS and the next
* required state. The state transitions are required to housekeep because
* #if:s can be nested. The ignore case is activated to prevent output from
* within a false clause.
* Some special cases come from the fact that the #elif cases are not
* binary, but three-state. The problem is that all other elif-cases must
* be false when one true one has been found. A second problem is that the
* #else clause is a final clause. No extra #else:s may follow.
*
* The states mean:
* if_true Process input to output
* if_false Process input but no output
* if_ignore Process input but no output
* if_elif Process input but no output
* if_elsefalse Process input but no output
* if_elsettrue Process input to output
*
* The possible state-sequences are [state(stack depth)] (rest can be deduced):
* TOS #if 1 #else #endif
* if_true(n) if_true(n+1) if_elsefalse(n+1)
* if_false(n) if_ignore(n+1) if_ignore(n+1)
* if_elsetrue(n) if_true(n+1) if_elsefalse(n+1)
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1)
* if_elif(n) if_ignore(n+1) if_ignore(n+1)
* if_ignore(n) if_ignore(n+1) if_ignore(n+1)
*
* TOS #if 1 #elif 0 #else #endif
* if_true(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
* if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_elsetrue(n) if_true(n+1) if_elif(n+1) if_elif(n+1)
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
*
* TOS #if 0 #elif 1 #else #endif
* if_true(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
* if_false(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_elsetrue(n) if_false(n+1) if_true(n+1) if_elsefalse(n+1)
* if_elsefalse(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_elif(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
* if_ignore(n) if_ignore(n+1) if_ignore(n+1) if_ignore(n+1)
*
*-------------------------------------------------------------------------
*/
static const char * const pp_if_state_str[] = {
"if_false",
"if_true",
"if_elif",
"if_elsefalse",
"if_elsetrue",
"if_ignore"
};
void pp_push_if(pp_if_state_t s)
{
if(if_stack_idx >= MAXIFSTACK)
pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
if(pp_flex_debug)
fprintf(stderr, "Push if %s:%d: %s(%d) -> %s(%d)\n", pp_status.input, pp_status.line_number, pp_if_state_str[pp_if_state()], if_stack_idx, pp_if_state_str[s], if_stack_idx+1);
if_stack[if_stack_idx++] = s;
switch(s)
{
case if_true:
case if_elsetrue:
break;
case if_false:
case if_elsefalse:
case if_elif:
case if_ignore:
pp_push_ignore_state();
break;
}
}
pp_if_state_t pp_pop_if(void)
{
if(if_stack_idx <= 0)
pperror("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
switch(pp_if_state())
{
case if_true:
case if_elsetrue:
break;
case if_false:
case if_elsefalse:
case if_elif:
case if_ignore:
pp_pop_ignore_state();
break;
}
if(pp_flex_debug)
fprintf(stderr, "Pop if %s:%d: %s(%d) -> %s(%d)\n",
pp_status.input,
pp_status.line_number,
pp_if_state_str[pp_if_state()],
if_stack_idx,
pp_if_state_str[if_stack[if_stack_idx <= 1 ? if_true : if_stack_idx-2]],
if_stack_idx-1);
return if_stack[--if_stack_idx];
}
pp_if_state_t pp_if_state(void)
{
if(!if_stack_idx)
return if_true;
else
return if_stack[if_stack_idx-1];
}
void pp_next_if_state(int i)
{
switch(pp_if_state())
{
case if_true:
case if_elsetrue:
pp_push_if(i ? if_true : if_false);
break;
case if_false:
case if_elsefalse:
case if_elif:
case if_ignore:
pp_push_if(if_ignore);
break;
default:
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #{if,ifdef,ifndef} directive", (int)pp_if_state());
}
}
int pp_get_if_depth(void)
{
return if_stack_idx;
}
/* #define WANT_NEAR_INDICATION */
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
{
fprintf(stderr, "%s:%d:%d: %s: ", pp_status.input ? pp_status.input : "stdin",
pp_status.line_number, pp_status.char_number, t);
vfprintf(stderr, s, ap);
#ifdef WANT_NEAR_INDICATION
{
char *cpy, *p;
if(n)
{
cpy = pp_xstrdup(n);
for (p = cpy; *p; p++) if(!isprint(*p)) *p = ' ';
fprintf(stderr, " near '%s'", cpy);
free(cpy);
}
}
#endif
fprintf(stderr, "\n");
}
int pperror(const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(s, "Error", pptext, ap);
va_end(ap);
exit(1);
return 1;
}
int ppwarning(const char *s, ...)
{
va_list ap;
va_start(ap, s);
generic_msg(s, "Warning", pptext, ap);
va_end(ap);
return 0;
}
void pp_internal_error(const char *file, int line, const char *s, ...)
{
va_list ap;
va_start(ap, s);
fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(3);
}

View file

@ -1,228 +0,0 @@
/*
* Exported functions of the Wine preprocessor
*
* Copyrignt 1998 Bertho A. Stultiens
* Copyright 2002 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <time.h>
#include <stdlib.h>
#include "wpp_private.h"
#include "wine/wpp.h"
#if defined(WIN32)
#include <windows.h>
#endif
int ppdebug;
struct define
{
struct define *next;
char *name;
char *value;
};
static struct define *cmdline_defines;
static void add_cmdline_defines(void)
{
struct define *def;
for (def = cmdline_defines; def; def = def->next)
{
if (def->value) pp_add_define( pp_xstrdup(def->name), pp_xstrdup(def->value) );
}
}
static void add_special_defines(void)
{
time_t now = time(NULL);
pp_entry_t *ppp;
char buf[32];
strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
pp_add_define( pp_xstrdup("__DATE__"), pp_xstrdup(buf) );
strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
pp_add_define( pp_xstrdup("__TIME__"), pp_xstrdup(buf) );
ppp = pp_add_define( pp_xstrdup("__FILE__"), pp_xstrdup("") );
ppp->type = def_special;
ppp = pp_add_define( pp_xstrdup("__LINE__"), pp_xstrdup("") );
ppp->type = def_special;
}
/* add a define to the preprocessor list */
void wpp_add_define( const char *name, const char *value )
{
struct define *def;
if (!value) value = "";
for (def = cmdline_defines; def; def = def->next)
{
if (!strcmp( def->name, name ))
{
if (def->value) free( def->value );
def->value = pp_xstrdup(value);
return;
}
}
def = pp_xmalloc( sizeof(*def) );
def->next = cmdline_defines;
def->name = pp_xstrdup(name);
def->value = pp_xstrdup(value);
cmdline_defines = def;
}
/* undefine a previously added definition */
void wpp_del_define( const char *name )
{
struct define *def;
for (def = cmdline_defines; def; def = def->next)
{
if (!strcmp( def->name, name ))
{
if (def->value) free( def->value );
def->value = NULL;
return;
}
}
}
/* add a command-line define of the form NAME=VALUE */
void wpp_add_cmdline_define( const char *value )
{
char *str = pp_xstrdup(value);
char *p = strchr( str, '=' );
if (p) *p++ = 0;
wpp_add_define( str, p );
free( str );
}
/* set the various debug flags */
void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug )
{
pp_flex_debug = lex_debug;
ppdebug = parser_debug;
pp_status.debug = msg_debug;
}
/* set the pedantic mode */
void wpp_set_pedantic( int on )
{
pp_status.pedantic = on;
}
/* the main preprocessor parsing loop */
int wpp_parse( const char *input, FILE *output )
{
int ret;
pp_push_define_state();
add_cmdline_defines();
add_special_defines();
if (!input) ppin = stdin;
else if (!(ppin = fopen(input, "rt")))
{
fprintf(stderr,"Could not open %s\n", input);
exit(2);
}
pp_status.input = input;
ppout = output;
fprintf(ppout, "# 1 \"%s\" 1\n", input ? input : "");
ret = ppparse();
if (input) fclose(ppin);
pp_pop_define_state();
return ret;
}
/* parse into a temporary file */
int wpp_parse_temp( const char *input, const char *output_base, char **output_name )
{
FILE *output;
int ret, fd;
char *temp_name;
#if defined(WIN32)
char tmppath[MAX_PATH];
char tmpfile[MAX_PATH];
#endif
#if defined(WIN32)
if (!output_base || !output_base[0]) output_base = "WPP";
if (GetTempPathA(MAX_PATH, tmppath) == 0)
{
fprintf(stderr, "Could not get temporary path.\n");
exit(2);
}
if (GetTempFileNameA(tmppath, output_base, 0, tmpfile) == 0)
{
fprintf(stderr, "Could not generate a temporary file name.\n");
exit(2);
}
temp_name = pp_xmalloc( strlen(tmpfile) + 1 );
strcpy( temp_name, tmpfile );
if (!(output = fopen(temp_name, "wt")))
{
fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
exit(2);
}
#else
if (!output_base || !output_base[0]) output_base = "wpptmp";
temp_name = pp_xmalloc( strlen(output_base) + 8 );
strcpy( temp_name, output_base );
strcat( temp_name, ".XXXXXX" );
if((fd = mkstemps( temp_name, 0 )) == -1)
{
fprintf(stderr, "Could not generate a temp name from %s\n", temp_name);
exit(2);
}
if (!(output = fdopen(fd, "wt")))
{
fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
exit(2);
}
#endif
*output_name = temp_name;
ret = wpp_parse( input, output );
fclose( output );
return ret;
}

View file

@ -1,253 +0,0 @@
/*
* Copyright 1998 Bertho A. Stultiens (BS)
* Copyright 2002 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WINE_WPP_PRIVATE_H
#define __WINE_WPP_PRIVATE_H
#include <stdio.h>
#include <string.h>
struct pp_entry; /* forward */
/*
* Include logic
* A stack of files which are already included and
* are protected in the #ifndef/#endif way.
*/
typedef struct includelogicentry {
struct includelogicentry *next;
struct includelogicentry *prev;
struct pp_entry *ppp; /* The define which protects the file */
char *filename; /* The filename of the include */
} includelogicentry_t;
/*
* The arguments of a macrodefinition
*/
typedef enum {
arg_single,
arg_list
} def_arg_t;
typedef struct marg {
def_arg_t type; /* Normal or ... argument */
char *arg; /* The textual argument */
int nnl; /* Number of newlines in the text to subst */
} marg_t;
/*
* The expansiontext of a macro
*/
typedef enum {
exp_text, /* Simple text substitution */
exp_concat, /* Concat (##) operator requested */
exp_stringize, /* Stringize (#) operator requested */
exp_subst /* Substitute argument */
} def_exp_t;
typedef struct mtext {
struct mtext *next;
struct mtext *prev;
def_exp_t type;
union {
char *text;
int argidx; /* For exp_subst and exp_stringize reference */
} subst;
} mtext_t;
/*
* The define descriptor
*/
typedef enum {
def_none, /* Not-a-define; used as return value */
def_define, /* Simple defines */
def_macro, /* Macro defines */
def_special /* Special expansions like __LINE__ and __FILE__ */
} def_type_t;
typedef struct pp_entry {
struct pp_entry *next;
struct pp_entry *prev;
def_type_t type; /* Define or macro */
char *ident; /* The key */
marg_t **margs; /* Macro arguments array or NULL if none */
int nargs;
union {
mtext_t *mtext; /* The substitution sequence or NULL if none */
char *text;
} subst;
int expanding; /* Set when feeding substitution into the input */
char *filename; /* Filename where it was defined */
int linenumber; /* Linenumber where it was defined */
includelogicentry_t *iep; /* Points to the include it protects */
} pp_entry_t;
/*
* If logic
*/
#define MAXIFSTACK 64 /* If this isn't enough you should alter the source... */
typedef enum {
if_false,
if_true,
if_elif,
if_elsefalse,
if_elsetrue,
if_ignore
} pp_if_state_t;
/*
* Trace the include files to prevent double reading.
* This save 20..30% of processing time for most stuff
* that uses complex includes.
* States:
* -1 Don't track or seen junk
* 0 New include, waiting for "#ifndef __xxx_h"
* 1 Seen #ifndef, waiting for "#define __xxx_h ..."
* 2 Seen #endif, waiting for EOF
*/
typedef struct
{
int state;
char *ppp; /* The define to be set from the #ifndef */
int ifdepth; /* The level of ifs at the #ifdef */
int seen_junk; /* Set when junk is seen */
} include_state_t;
/*
* I assume that 'long long' exists in the compiler when it has a size
* of 8 or bigger. If not, then we revert to a simple 'long' for now.
* This should prevent most unexpected things with other compilers than
* gcc and egcs for now.
* In the future it should be possible to use another way, like a
* structure, so that we can emulate the MS compiler.
*/
#if defined(SIZEOF_LONGLONG) && SIZEOF_LONGLONG >= 8
typedef long long wrc_sll_t;
typedef unsigned long long wrc_ull_t;
#else
typedef long wrc_sll_t;
typedef unsigned long wrc_ull_t;
#endif
#define SIZE_CHAR 1
#define SIZE_SHORT 2
#define SIZE_INT 3
#define SIZE_LONG 4
#define SIZE_LONGLONG 5
#define SIZE_MASK 0x00ff
#define FLAG_SIGNED 0x0100
typedef enum {
#if 0
cv_schar = SIZE_CHAR + FLAG_SIGNED,
cv_uchar = SIZE_CHAR,
cv_sshort = SIZE_SHORT + FLAG_SIGNED,
cv_ushort = SIZE_SHORT,
#endif
cv_sint = SIZE_INT + FLAG_SIGNED,
cv_uint = SIZE_INT,
cv_slong = SIZE_LONG + FLAG_SIGNED,
cv_ulong = SIZE_LONG,
cv_sll = SIZE_LONGLONG + FLAG_SIGNED,
cv_ull = SIZE_LONGLONG
} ctype_t;
typedef struct cval {
ctype_t type;
union {
#if 0
signed char sc; /* Explicitely signed because compilers are stupid */
unsigned char uc;
short ss;
unsigned short us;
#endif
int si;
unsigned int ui;
long sl;
unsigned long ul;
wrc_sll_t sll;
wrc_ull_t ull;
} val;
} cval_t;
void *pp_xmalloc(size_t);
void *pp_xrealloc(void *, size_t);
char *pp_xstrdup(const char *str);
pp_entry_t *pplookup(const char *ident);
void pp_push_define_state(void);
void pp_pop_define_state(void);
pp_entry_t *pp_add_define(char *def, char *text);
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
void pp_del_define(const char *name);
FILE *pp_open_include(const char *name, int search, char **newpath);
void pp_push_if(pp_if_state_t s);
void pp_next_if_state(int);
pp_if_state_t pp_pop_if(void);
pp_if_state_t pp_if_state(void);
int pp_get_if_depth(void);
#ifndef __GNUC__
#define __attribute__(x) /*nothing*/
#endif
int pperror(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppwarning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void pp_internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
/* current preprocessor state */
/* everything is in this structure to avoid polluting the global symbol space */
struct pp_status
{
const char *input; /* current input file name */
int line_number; /* current line number */
int char_number; /* current char number in line */
int pedantic; /* pedantic option */
int debug; /* debug messages flag */
};
extern struct pp_status pp_status;
extern include_state_t pp_incl_state;
extern includelogicentry_t *pp_includelogiclist;
/*
* From ppl.l
*/
extern FILE *ppin;
extern FILE *ppout;
extern char *pptext;
extern int pp_flex_debug;
int pplex(void);
void pp_do_include(char *fname, int type);
void pp_push_ignore_state(void);
void pp_pop_ignore_state(void);
/*
* From ppy.y
*/
int ppparse(void);
extern int ppdebug;
#endif /* __WINE_WPP_PRIVATE_H */

File diff suppressed because it is too large Load diff

View file

@ -1,68 +0,0 @@
#ifndef BISON_Y_TAB_H
# define BISON_Y_TAB_H
#ifndef YYSTYPE
typedef union{
int sint;
unsigned int uint;
long slong;
unsigned long ulong;
wrc_sll_t sll;
wrc_ull_t ull;
int *iptr;
char *cptr;
cval_t cval;
marg_t *marg;
mtext_t *mtext;
} yystype;
# define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
#endif
# define tRCINCLUDE 257
# define tIF 258
# define tIFDEF 259
# define tIFNDEF 260
# define tELSE 261
# define tELIF 262
# define tENDIF 263
# define tDEFINED 264
# define tNL 265
# define tINCLUDE 266
# define tLINE 267
# define tGCCLINE 268
# define tERROR 269
# define tWARNING 270
# define tPRAGMA 271
# define tPPIDENT 272
# define tUNDEF 273
# define tMACROEND 274
# define tCONCAT 275
# define tELIPSIS 276
# define tSTRINGIZE 277
# define tIDENT 278
# define tLITERAL 279
# define tMACRO 280
# define tDEFINE 281
# define tDQSTRING 282
# define tSQSTRING 283
# define tIQSTRING 284
# define tUINT 285
# define tSINT 286
# define tULONG 287
# define tSLONG 288
# define tULONGLONG 289
# define tSLONGLONG 290
# define tRCINCLUDEPATH 291
# define tLOGOR 292
# define tLOGAND 293
# define tEQ 294
# define tNE 295
# define tLTE 296
# define tGTE 297
# define tLSHIFT 298
# define tRSHIFT 299
extern YYSTYPE pplval;
#endif /* not BISON_Y_TAB_H */