mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 08:05:43 +00:00
Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys.
This commit is contained in:
parent
b94e2d8ca0
commit
c2c66aff7d
24198 changed files with 0 additions and 37285 deletions
38
sdk/tools/wpp/CMakeLists.txt
Normal file
38
sdk/tools/wpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
if(MSVC)
|
||||
if(MSVC_VERSION LESS 1900)
|
||||
add_definitions(
|
||||
-Dsnprintf=_snprintf
|
||||
-Dstrtoull=_strtoui64
|
||||
-Dstrtoll=_strtoi64)
|
||||
|
||||
# Add this definition for WDK only, VS 9 doesn't like that
|
||||
if(DEFINED ENV{DDKBUILDENV})
|
||||
add_definitions(-Dvsnprintf=_vsnprintf)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
add_definitions(
|
||||
-D_DLL -D__USE_CRTIMP
|
||||
-D__NO_ISOCEXT
|
||||
-Dstrtoull=_strtoui64
|
||||
-Dstrtoll=_strtoi64
|
||||
-Dopen=_open
|
||||
-Dclose=_close)
|
||||
|
||||
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
|
||||
endif()
|
||||
|
||||
list(APPEND SOURCE
|
||||
preproc.c
|
||||
wpp.c
|
||||
ppl.yy.c
|
||||
ppy.tab.c)
|
||||
|
||||
if(CMAKE_CROSSCOMPILING)
|
||||
add_library(wpp ${SOURCE})
|
||||
else()
|
||||
add_library(wpphost ${SOURCE})
|
||||
endif()
|
1649
sdk/tools/wpp/ppl.l
Normal file
1649
sdk/tools/wpp/ppl.l
Normal file
File diff suppressed because it is too large
Load diff
4602
sdk/tools/wpp/ppl.yy.c
Normal file
4602
sdk/tools/wpp/ppl.yy.c
Normal file
File diff suppressed because it is too large
Load diff
2614
sdk/tools/wpp/ppy.tab.c
Normal file
2614
sdk/tools/wpp/ppy.tab.c
Normal file
File diff suppressed because it is too large
Load diff
124
sdk/tools/wpp/ppy.tab.h
Normal file
124
sdk/tools/wpp/ppy.tab.h
Normal file
|
@ -0,0 +1,124 @@
|
|||
/* A Bison parser, made by GNU Bison 3.0.2. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
#ifndef YY_PPY_PPY_TAB_H_INCLUDED
|
||||
# define YY_PPY_PPY_TAB_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 0
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
extern int ppy_debug;
|
||||
#endif
|
||||
|
||||
/* Token type. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
enum yytokentype
|
||||
{
|
||||
tRCINCLUDE = 258,
|
||||
tIF = 259,
|
||||
tIFDEF = 260,
|
||||
tIFNDEF = 261,
|
||||
tELSE = 262,
|
||||
tELIF = 263,
|
||||
tENDIF = 264,
|
||||
tDEFINED = 265,
|
||||
tNL = 266,
|
||||
tINCLUDE = 267,
|
||||
tLINE = 268,
|
||||
tGCCLINE = 269,
|
||||
tERROR = 270,
|
||||
tWARNING = 271,
|
||||
tPRAGMA = 272,
|
||||
tPPIDENT = 273,
|
||||
tUNDEF = 274,
|
||||
tMACROEND = 275,
|
||||
tCONCAT = 276,
|
||||
tELIPSIS = 277,
|
||||
tSTRINGIZE = 278,
|
||||
tIDENT = 279,
|
||||
tLITERAL = 280,
|
||||
tMACRO = 281,
|
||||
tDEFINE = 282,
|
||||
tDQSTRING = 283,
|
||||
tSQSTRING = 284,
|
||||
tIQSTRING = 285,
|
||||
tUINT = 286,
|
||||
tSINT = 287,
|
||||
tULONG = 288,
|
||||
tSLONG = 289,
|
||||
tULONGLONG = 290,
|
||||
tSLONGLONG = 291,
|
||||
tRCINCLUDEPATH = 292,
|
||||
tLOGOR = 293,
|
||||
tLOGAND = 294,
|
||||
tEQ = 295,
|
||||
tNE = 296,
|
||||
tLTE = 297,
|
||||
tGTE = 298,
|
||||
tLSHIFT = 299,
|
||||
tRSHIFT = 300
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 126 "ppy.y" /* yacc.c:1909 */
|
||||
|
||||
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;
|
||||
|
||||
#line 114 "ppy.tab.h" /* yacc.c:1909 */
|
||||
};
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
|
||||
extern YYSTYPE ppy_lval;
|
||||
|
||||
int ppy_parse (void);
|
||||
|
||||
#endif /* !YY_PPY_PPY_TAB_H_INCLUDED */
|
705
sdk/tools/wpp/ppy.y
Normal file
705
sdk/tools/wpp/ppy.y
Normal file
|
@ -0,0 +1,705 @@
|
|||
/*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 (signed) v2.val.ui; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.si = (signed) 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 (signed long) v2.val.ul; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sl = (signed long) 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 (wrc_sll_t) v2.val.ull; \
|
||||
else if(!cv_signed(v1) && cv_signed(v2)) \
|
||||
r.val.sll = (wrc_sll_t) 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:
|
||||
ppy_error("#elif cannot follow #else");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
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:
|
||||
ppy_error("#else clause already defined");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
|
||||
}
|
||||
}
|
||||
| tENDIF tNL {
|
||||
if(pp_pop_if() != if_error)
|
||||
{
|
||||
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); free($1); free($2); }
|
||||
| tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
|
||||
pp_add_macro($1, macro_args, nmacro_args, $5);
|
||||
}
|
||||
| tLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d\n", $2, $3, $4); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
|
||||
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
|
||||
{ if($3) pp_writestring("# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
|
||||
| tGCCLINE tNL /* The null-token */
|
||||
| tERROR opt_text tNL { ppy_error("#error directive: '%s'", $2); free($2); }
|
||||
| tWARNING opt_text tNL { ppy_warning("#warning directive: '%s'", $2); free($2); }
|
||||
| tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
|
||||
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
|
||||
| tRCINCLUDE tRCINCLUDEPATH {
|
||||
if($2)
|
||||
{
|
||||
int nl=strlen($2) +3;
|
||||
char *fn=pp_xmalloc(nl);
|
||||
if(fn)
|
||||
{
|
||||
sprintf(fn,"\"%s\"",$2);
|
||||
pp_do_include(fn,1);
|
||||
}
|
||||
free($2);
|
||||
}
|
||||
}
|
||||
| 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)
|
||||
ppy_error("Stringification identifier must be an argument parameter");
|
||||
else
|
||||
$$ = new_mtext(NULL, mat, exp_stringize);
|
||||
}
|
||||
| tIDENT {
|
||||
int mat = marg_index($1);
|
||||
if(mat >= 0)
|
||||
$$ = new_mtext(NULL, mat, exp_subst);
|
||||
else if($1)
|
||||
$$ = 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.sll = $1; }
|
||||
| tULONGLONG { $$.type = cv_ull; $$.val.ull = $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));
|
||||
if(!ma)
|
||||
return NULL;
|
||||
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 **new_macro_args;
|
||||
marg_t *ma;
|
||||
if(!str)
|
||||
return NULL;
|
||||
new_macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
|
||||
if(!new_macro_args)
|
||||
return NULL;
|
||||
macro_args = new_macro_args;
|
||||
ma = new_marg(str, type);
|
||||
if(!ma)
|
||||
return NULL;
|
||||
macro_args[nmacro_args] = ma;
|
||||
nmacro_args++;
|
||||
return ma;
|
||||
}
|
||||
|
||||
static int marg_index(char *id)
|
||||
{
|
||||
int t;
|
||||
if(!id)
|
||||
return -1;
|
||||
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(!mt)
|
||||
return NULL;
|
||||
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)
|
||||
{
|
||||
char *new_text;
|
||||
new_text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
|
||||
if(!new_text)
|
||||
return mtp;
|
||||
tail->subst.text = new_text;
|
||||
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;
|
||||
int l2;
|
||||
char *snew;
|
||||
if(!s1)
|
||||
return s2;
|
||||
if(!s2)
|
||||
return s1;
|
||||
l1 = strlen(s1);
|
||||
l2 = strlen(s2);
|
||||
snew = pp_xrealloc(s1, l1+l2+1);
|
||||
if(!snew)
|
||||
{
|
||||
free(s2);
|
||||
return s1;
|
||||
}
|
||||
s1 = snew;
|
||||
memcpy(s1+l1, s2, l2+1);
|
||||
free(s2);
|
||||
return s1;
|
||||
}
|
763
sdk/tools/wpp/preproc.c
Normal file
763
sdk/tools/wpp/preproc.c
Normal file
|
@ -0,0 +1,763 @@
|
|||
/*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "wine/port.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.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 "wine/wpp.h"
|
||||
#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)
|
||||
{
|
||||
/* Set the error flag */
|
||||
pp_status.state = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void *pp_xrealloc(void *p, size_t size)
|
||||
{
|
||||
void *res;
|
||||
|
||||
assert(size > 0);
|
||||
res = realloc(p, size);
|
||||
if(res == NULL)
|
||||
{
|
||||
/* Set the error flag */
|
||||
pp_status.state = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
char *pp_xstrdup(const char *str)
|
||||
{
|
||||
char *s;
|
||||
int len;
|
||||
|
||||
assert(str != NULL);
|
||||
len = strlen(str)+1;
|
||||
s = pp_xmalloc(len);
|
||||
if(!s)
|
||||
return NULL;
|
||||
return memcpy(s, str, len);
|
||||
}
|
||||
|
||||
static char *wpp_default_lookup(const char *name, int type, const char *parent_name,
|
||||
char **include_path, int include_path_count)
|
||||
{
|
||||
char *cpy;
|
||||
char *cptr;
|
||||
char *path;
|
||||
const char *ccptr;
|
||||
int i, fd;
|
||||
|
||||
cpy = pp_xmalloc(strlen(name)+1);
|
||||
if(!cpy)
|
||||
return NULL;
|
||||
cptr = cpy;
|
||||
|
||||
for(ccptr = name; *ccptr; ccptr++)
|
||||
{
|
||||
/* Convert to forward slash */
|
||||
if(*ccptr == '\\') {
|
||||
/* kill double backslash */
|
||||
if(ccptr[1] == '\\')
|
||||
ccptr++;
|
||||
*cptr = '/';
|
||||
}else {
|
||||
*cptr = *ccptr;
|
||||
}
|
||||
cptr++;
|
||||
}
|
||||
*cptr = '\0';
|
||||
|
||||
if(type && parent_name)
|
||||
{
|
||||
/* Search directory of parent include and then -I path */
|
||||
const char *p;
|
||||
|
||||
if ((p = strrchr( parent_name, '/' ))) p++;
|
||||
else p = parent_name;
|
||||
path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
|
||||
if(!path)
|
||||
{
|
||||
free(cpy);
|
||||
return NULL;
|
||||
}
|
||||
memcpy( path, parent_name, p - parent_name );
|
||||
strcpy( path + (p - parent_name), cpy );
|
||||
fd = open( path, O_RDONLY );
|
||||
if (fd != -1)
|
||||
{
|
||||
close( fd );
|
||||
free( cpy );
|
||||
return path;
|
||||
}
|
||||
free( path );
|
||||
}
|
||||
/* Search -I path */
|
||||
for(i = 0; i < include_path_count; i++)
|
||||
{
|
||||
path = pp_xmalloc(strlen(include_path[i]) + strlen(cpy) + 2);
|
||||
if(!path)
|
||||
{
|
||||
free(cpy);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(path, include_path[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;
|
||||
}
|
||||
|
||||
static void *wpp_default_open(const char *filename, int type) {
|
||||
return fopen(filename,"rt");
|
||||
}
|
||||
|
||||
static void wpp_default_close(void *file) {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
static int wpp_default_read(void *file, char *buffer, unsigned int len){
|
||||
return fread(buffer, 1, len, file);
|
||||
}
|
||||
|
||||
static void wpp_default_write( const char *buffer, unsigned int len ) {
|
||||
fwrite(buffer, 1, len, ppy_out);
|
||||
}
|
||||
|
||||
/* Don't comment on the hash, it's 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;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!ident)
|
||||
return NULL;
|
||||
idx = pphash(ident);
|
||||
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 */
|
||||
int pp_push_define_state(void)
|
||||
{
|
||||
pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
|
||||
if(!state)
|
||||
return 1;
|
||||
|
||||
memset( state->defines, 0, sizeof(state->defines) );
|
||||
state->next = pp_def_state;
|
||||
pp_def_state = state;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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) pp_del_define( ppp->ident );
|
||||
}
|
||||
state = pp_def_state;
|
||||
pp_def_state = state->next;
|
||||
free( state );
|
||||
}
|
||||
|
||||
void pp_del_define(const char *name)
|
||||
{
|
||||
pp_entry_t *ppp;
|
||||
int idx = pphash(name);
|
||||
|
||||
if((ppp = pplookup(name)) == NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("%s was not defined", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(pp_status.debug)
|
||||
printf("Deleting (%s, %d) <%s>\n", pp_status.input, pp_status.line_number, name);
|
||||
|
||||
free( ppp->ident );
|
||||
free( ppp->subst.text );
|
||||
free( ppp->filename );
|
||||
free_pp_entry( ppp, idx );
|
||||
}
|
||||
|
||||
pp_entry_t *pp_add_define(const char *def, const char *text)
|
||||
{
|
||||
int len;
|
||||
char *cptr;
|
||||
int idx;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!def)
|
||||
return NULL;
|
||||
idx = pphash(def);
|
||||
if((ppp = pplookup(def)) != NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
|
||||
pp_del_define(def);
|
||||
}
|
||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||
if(!ppp)
|
||||
return NULL;
|
||||
memset( ppp, 0, sizeof(*ppp) );
|
||||
ppp->ident = pp_xstrdup(def);
|
||||
if(!ppp->ident)
|
||||
goto error;
|
||||
ppp->type = def_define;
|
||||
ppp->subst.text = text ? pp_xstrdup(text) : NULL;
|
||||
if(text && !ppp->subst.text)
|
||||
goto error;
|
||||
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
||||
if(!ppp->filename)
|
||||
goto error;
|
||||
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(ppp->subst.text)
|
||||
{
|
||||
/* Strip trailing white space from subst text */
|
||||
len = strlen(ppp->subst.text);
|
||||
while(len && strchr(" \t\r\n", ppp->subst.text[len-1]))
|
||||
{
|
||||
ppp->subst.text[--len] = '\0';
|
||||
}
|
||||
/* Strip leading white space from subst text */
|
||||
for(cptr = ppp->subst.text; *cptr && strchr(" \t\r", *cptr); cptr++)
|
||||
;
|
||||
if(ppp->subst.text != cptr)
|
||||
memmove(ppp->subst.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, ppp->subst.text ? ppp->subst.text : "(null)");
|
||||
|
||||
return ppp;
|
||||
|
||||
error:
|
||||
free(ppp->ident);
|
||||
free(ppp->subst.text);
|
||||
free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||
{
|
||||
int idx;
|
||||
pp_entry_t *ppp;
|
||||
|
||||
if(!id)
|
||||
return NULL;
|
||||
idx = pphash(id);
|
||||
if((ppp = pplookup(id)) != NULL)
|
||||
{
|
||||
if(pp_status.pedantic)
|
||||
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
|
||||
pp_del_define(id);
|
||||
}
|
||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||
if(!ppp)
|
||||
return NULL;
|
||||
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>");
|
||||
if(!ppp->filename)
|
||||
{
|
||||
free(ppp);
|
||||
return NULL;
|
||||
}
|
||||
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(_WIN32) || defined(__MSDOS__)
|
||||
#define INCLUDESEPARATOR ";"
|
||||
#else
|
||||
#define INCLUDESEPARATOR ":"
|
||||
#endif
|
||||
|
||||
static char **includepath;
|
||||
static int nincludepath = 0;
|
||||
|
||||
int wpp_add_include_path(const char *path)
|
||||
{
|
||||
char *tok;
|
||||
char *cpy = pp_xstrdup(path);
|
||||
if(!cpy)
|
||||
return 1;
|
||||
|
||||
tok = strtok(cpy, INCLUDESEPARATOR);
|
||||
while(tok)
|
||||
{
|
||||
if(*tok) {
|
||||
char *dir;
|
||||
char *cptr;
|
||||
char **new_path;
|
||||
|
||||
dir = pp_xstrdup(tok);
|
||||
if(!dir)
|
||||
{
|
||||
free(cpy);
|
||||
return 1;
|
||||
}
|
||||
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 */
|
||||
new_path = pp_xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
|
||||
if(!new_path)
|
||||
{
|
||||
free(dir);
|
||||
free(cpy);
|
||||
return 1;
|
||||
}
|
||||
includepath = new_path;
|
||||
includepath[nincludepath] = dir;
|
||||
nincludepath++;
|
||||
}
|
||||
tok = strtok(NULL, INCLUDESEPARATOR);
|
||||
}
|
||||
free(cpy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *wpp_find_include(const char *name, const char *parent_name)
|
||||
{
|
||||
return wpp_default_lookup(name, !!parent_name, parent_name, includepath, nincludepath);
|
||||
}
|
||||
|
||||
void *pp_open_include(const char *name, int type, const char *parent_name, char **newpath)
|
||||
{
|
||||
char *path;
|
||||
void *fp;
|
||||
|
||||
if (!(path = wpp_callbacks->lookup(name, type, parent_name, includepath,
|
||||
nincludepath))) return NULL;
|
||||
fp = wpp_callbacks->open(path, type);
|
||||
|
||||
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;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
}
|
||||
|
||||
pp_if_state_t pp_pop_if(void)
|
||||
{
|
||||
if(if_stack_idx <= 0)
|
||||
{
|
||||
ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
|
||||
return if_error;
|
||||
}
|
||||
|
||||
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;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
|
||||
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);
|
||||
if(!cpy)
|
||||
goto end;
|
||||
for (p = cpy; *p; p++) if(!isprint(*p)) *p = ' ';
|
||||
fprintf(stderr, " near '%s'", cpy);
|
||||
free(cpy);
|
||||
}
|
||||
}
|
||||
end:
|
||||
#endif
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static void wpp_default_error(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
|
||||
{
|
||||
generic_msg(msg, "Error", near, ap);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void wpp_default_warning(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
|
||||
{
|
||||
generic_msg(msg, "Warning", near, ap);
|
||||
}
|
||||
|
||||
static const struct wpp_callbacks default_callbacks =
|
||||
{
|
||||
wpp_default_lookup,
|
||||
wpp_default_open,
|
||||
wpp_default_close,
|
||||
wpp_default_read,
|
||||
wpp_default_write,
|
||||
wpp_default_error,
|
||||
wpp_default_warning,
|
||||
};
|
||||
|
||||
const struct wpp_callbacks *wpp_callbacks = &default_callbacks;
|
||||
|
||||
int ppy_error(const char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
wpp_callbacks->error(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, ap);
|
||||
va_end(ap);
|
||||
pp_status.state = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ppy_warning(const char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, s);
|
||||
wpp_callbacks->warning(pp_status.input, pp_status.line_number, pp_status.char_number, ppy_text, s, 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);
|
||||
}
|
235
sdk/tools/wpp/wpp.c
Normal file
235
sdk/tools/wpp/wpp.c
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
* Exported functions of the Wine preprocessor
|
||||
*
|
||||
* Copyright 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "wine/port.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "wpp_private.h"
|
||||
#include "wine/wpp.h"
|
||||
|
||||
int ppy_debug, pp_flex_debug;
|
||||
|
||||
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( def->name, def->value );
|
||||
}
|
||||
}
|
||||
|
||||
static void del_cmdline_defines(void)
|
||||
{
|
||||
struct define *def;
|
||||
|
||||
for (def = cmdline_defines; def; def = def->next)
|
||||
{
|
||||
if (def->value) pp_del_define( def->name );
|
||||
}
|
||||
}
|
||||
|
||||
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( "__DATE__", buf );
|
||||
|
||||
strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
|
||||
pp_add_define( "__TIME__", buf );
|
||||
|
||||
ppp = pp_add_define( "__FILE__", "" );
|
||||
if(ppp)
|
||||
ppp->type = def_special;
|
||||
|
||||
ppp = pp_add_define( "__LINE__", "" );
|
||||
if(ppp)
|
||||
ppp->type = def_special;
|
||||
}
|
||||
|
||||
static void del_special_defines(void)
|
||||
{
|
||||
pp_del_define( "__DATE__" );
|
||||
pp_del_define( "__TIME__" );
|
||||
pp_del_define( "__FILE__" );
|
||||
pp_del_define( "__LINE__" );
|
||||
}
|
||||
|
||||
|
||||
/* add a define to the preprocessor list */
|
||||
int 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 ))
|
||||
{
|
||||
char *new_value = pp_xstrdup(value);
|
||||
if(!new_value)
|
||||
return 1;
|
||||
free( def->value );
|
||||
def->value = new_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
def = pp_xmalloc( sizeof(*def) );
|
||||
if(!def)
|
||||
return 1;
|
||||
def->next = cmdline_defines;
|
||||
def->name = pp_xstrdup(name);
|
||||
if(!def->name)
|
||||
{
|
||||
free(def);
|
||||
return 1;
|
||||
}
|
||||
def->value = pp_xstrdup(value);
|
||||
if(!def->value)
|
||||
{
|
||||
free(def->name);
|
||||
free(def);
|
||||
return 1;
|
||||
}
|
||||
cmdline_defines = def;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* 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 ))
|
||||
{
|
||||
free( def->value );
|
||||
def->value = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* add a command-line define of the form NAME=VALUE */
|
||||
int wpp_add_cmdline_define( const char *value )
|
||||
{
|
||||
char *p;
|
||||
char *str = pp_xstrdup(value);
|
||||
if(!str)
|
||||
return 1;
|
||||
p = strchr( str, '=' );
|
||||
if (p) *p++ = 0;
|
||||
wpp_add_define( str, p );
|
||||
free( str );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* set the various debug flags */
|
||||
void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug )
|
||||
{
|
||||
pp_flex_debug = lex_debug;
|
||||
ppy_debug = 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_status.input = NULL;
|
||||
pp_status.line_number = 1;
|
||||
pp_status.char_number = 1;
|
||||
pp_status.state = 0;
|
||||
|
||||
ret = pp_push_define_state();
|
||||
if(ret)
|
||||
return ret;
|
||||
add_cmdline_defines();
|
||||
add_special_defines();
|
||||
|
||||
if (!input) pp_status.file = stdin;
|
||||
else if (!(pp_status.file = wpp_callbacks->open(input, 1)))
|
||||
{
|
||||
ppy_error("Could not open %s\n", input);
|
||||
del_special_defines();
|
||||
del_cmdline_defines();
|
||||
pp_pop_define_state();
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp_status.input = input ? pp_xstrdup(input) : NULL;
|
||||
|
||||
ppy_out = output;
|
||||
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
|
||||
|
||||
ret = ppy_parse();
|
||||
/* If there were errors during processing, return an error code */
|
||||
if (!ret && pp_status.state) ret = pp_status.state;
|
||||
|
||||
if (input)
|
||||
{
|
||||
wpp_callbacks->close(pp_status.file);
|
||||
free(pp_status.input);
|
||||
}
|
||||
/* Clean if_stack, it could remain dirty on errors */
|
||||
while (pp_get_if_depth()) pp_pop_if();
|
||||
del_special_defines();
|
||||
del_cmdline_defines();
|
||||
pp_pop_define_state();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void wpp_set_callbacks( const struct wpp_callbacks *callbacks )
|
||||
{
|
||||
wpp_callbacks = callbacks;
|
||||
}
|
265
sdk/tools/wpp/wpp_private.h
Normal file
265
sdk/tools/wpp/wpp_private.h
Normal file
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __WINE_WPP_PRIVATE_H
|
||||
#define __WINE_WPP_PRIVATE_H
|
||||
|
||||
#ifndef __WINE_CONFIG_H
|
||||
# error You must include config.h to use this header
|
||||
#endif
|
||||
|
||||
#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,
|
||||
if_error
|
||||
} 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;
|
||||
|
||||
|
||||
/*
|
||||
* If the configure says we have long long then we can use it. Presumably
|
||||
* if we have long long then we have strtoull and strtoll too. If that is
|
||||
* not the case we will need to add to the configure tests.
|
||||
* If we do not have long long , 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.
|
||||
*/
|
||||
#ifdef HAVE_LONG_LONG
|
||||
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; /* Explicitly 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);
|
||||
int pp_push_define_state(void);
|
||||
void pp_pop_define_state(void);
|
||||
pp_entry_t *pp_add_define(const char *def, const 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);
|
||||
void *pp_open_include(const char *name, int type, const char *parent_name, 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
|
||||
|
||||
extern const struct wpp_callbacks *wpp_callbacks;
|
||||
|
||||
int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
|
||||
int ppy_warning(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
|
||||
{
|
||||
char *input; /* current input file name */
|
||||
void *file; /* current input file descriptor */
|
||||
int line_number; /* current line number */
|
||||
int char_number; /* current char number in line */
|
||||
int state; /* current error state */
|
||||
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 *ppy_in;
|
||||
extern FILE *ppy_out;
|
||||
extern char *ppy_text;
|
||||
extern int pp_flex_debug;
|
||||
int ppy_lex(void);
|
||||
|
||||
void pp_do_include(char *fname, int type);
|
||||
void pp_push_ignore_state(void);
|
||||
void pp_pop_ignore_state(void);
|
||||
|
||||
void pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
||||
/*
|
||||
* From ppy.y
|
||||
*/
|
||||
int ppy_parse(void);
|
||||
extern int ppy_debug;
|
||||
|
||||
#endif /* __WINE_WPP_PRIVATE_H */
|
Loading…
Add table
Add a link
Reference in a new issue