Commit b7d3c79b authored by Alexandre Julliard's avatar Alexandre Julliard

Split the C preprocessor from wrc into a separate library.

Prefixed exported functions by 'pp' to avoid namespace conflicts.
parent 75792878
......@@ -13314,7 +13314,7 @@ MAKE_DLL_RULES=dlls/Makedll.rules
MAKE_PROG_RULES=programs/Makeprog.rules
ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
ac_config_files="$ac_config_files Make.rules dlls/Makedll.rules programs/Makeprog.rules Makefile debugger/Makefile dlls/Makefile dlls/advapi32/Makefile dlls/avicap32/Makefile dlls/avifil32/Makefile dlls/comcat/Makefile dlls/comctl32/Makefile dlls/commdlg/Makefile dlls/crtdll/Makefile dlls/crypt32/Makefile dlls/d3d8/Makefile dlls/dciman32/Makefile dlls/ddraw/Makefile dlls/devenum/Makefile dlls/dinput/Makefile dlls/dinput8/Makefile dlls/dplay/Makefile dlls/dplayx/Makefile dlls/dsound/Makefile dlls/gdi/Makefile dlls/glu32/Makefile dlls/icmp/Makefile dlls/imagehlp/Makefile dlls/imm32/Makefile dlls/kernel/Makefile dlls/lzexpand/Makefile dlls/mapi32/Makefile dlls/mpr/Makefile dlls/msacm/Makefile dlls/msacm/imaadp32/Makefile dlls/msacm/msadp32/Makefile dlls/msacm/msg711/Makefile dlls/msacm/winemp3/Makefile dlls/msdmo/Makefile dlls/msimg32/Makefile dlls/msisys/Makefile dlls/msnet32/Makefile dlls/msrle32/Makefile dlls/msvcrt/Makefile dlls/msvcrt20/Makefile dlls/msvideo/Makefile dlls/netapi32/Makefile dlls/ntdll/Makefile dlls/odbc32/Makefile dlls/ole32/Makefile dlls/oleaut32/Makefile dlls/olecli/Makefile dlls/oledlg/Makefile dlls/olepro32/Makefile dlls/olesvr/Makefile dlls/opengl32/Makefile dlls/psapi/Makefile dlls/qcap/Makefile dlls/quartz/Makefile dlls/rasapi32/Makefile dlls/richedit/Makefile dlls/rpcrt4/Makefile dlls/serialui/Makefile dlls/setupapi/Makefile dlls/shdocvw/Makefile dlls/shell32/Makefile dlls/shfolder/Makefile dlls/shlwapi/Makefile dlls/snmpapi/Makefile dlls/sti/Makefile dlls/tapi32/Makefile dlls/ttydrv/Makefile dlls/twain/Makefile dlls/url/Makefile dlls/urlmon/Makefile dlls/user/Makefile dlls/version/Makefile dlls/win32s/Makefile dlls/winaspi/Makefile dlls/winedos/Makefile dlls/wineps/Makefile dlls/wininet/Makefile dlls/winmm/Makefile dlls/winmm/joystick/Makefile dlls/winmm/mcianim/Makefile dlls/winmm/mciavi/Makefile dlls/winmm/mcicda/Makefile dlls/winmm/mciseq/Makefile dlls/winmm/mciwave/Makefile dlls/winmm/midimap/Makefile dlls/winmm/wavemap/Makefile dlls/winmm/winealsa/Makefile dlls/winmm/winearts/Makefile dlls/winmm/wineoss/Makefile dlls/winnls/Makefile dlls/winsock/Makefile dlls/winspool/Makefile dlls/wintrust/Makefile dlls/wow32/Makefile dlls/wsock32/Makefile dlls/x11drv/Makefile documentation/Makefile include/Makefile library/Makefile miscemu/Makefile ole/Makefile programs/Makefile programs/avitools/Makefile programs/clock/Makefile programs/cmdlgtst/Makefile programs/control/Makefile programs/expand/Makefile programs/notepad/Makefile programs/osversioncheck/Makefile programs/progman/Makefile programs/regapi/Makefile programs/regedit/Makefile programs/regsvr32/Makefile programs/regtest/Makefile programs/uninstaller/Makefile programs/view/Makefile programs/wcmd/Makefile programs/wineconsole/Makefile programs/winefile/Makefile programs/winemine/Makefile programs/winepath/Makefile programs/winetest/Makefile programs/winhelp/Makefile programs/winver/Makefile server/Makefile tools/Makefile tools/winapi/Makefile tools/winebuild/Makefile tools/winedump/Makefile tools/wmc/Makefile tools/wpp/Makefile tools/wrc/Makefile tsx11/Makefile unicode/Makefile"
cat >confcache <<\_ACEOF
......@@ -13925,6 +13925,7 @@ do
"tools/winebuild/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/winebuild/Makefile" ;;
"tools/winedump/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/winedump/Makefile" ;;
"tools/wmc/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/wmc/Makefile" ;;
"tools/wpp/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/wpp/Makefile" ;;
"tools/wrc/Makefile" ) CONFIG_FILES="$CONFIG_FILES tools/wrc/Makefile" ;;
"tsx11/Makefile" ) CONFIG_FILES="$CONFIG_FILES tsx11/Makefile" ;;
"unicode/Makefile" ) CONFIG_FILES="$CONFIG_FILES unicode/Makefile" ;;
......
......@@ -1378,6 +1378,7 @@ tools/winapi/Makefile
tools/winebuild/Makefile
tools/winedump/Makefile
tools/wmc/Makefile
tools/wpp/Makefile
tools/wrc/Makefile
tsx11/Makefile
unicode/Makefile])
......
......@@ -13,6 +13,7 @@ SUBDIRS = \
winebuild \
winedump \
wmc \
wpp \
wrc
INSTALLSUBDIRS = $(SUBDIRS)
......@@ -27,6 +28,8 @@ all: $(PROGRAMS) $(SUBDIRS)
@MAKE_RULES@
wrc: wpp
makedep: makedep.o
$(CC) $(CFLAGS) -o makedep makedep.o
......
Makefile
lex.yy.c
y.tab.c
y.tab.h
DEFS = -D__WINE__
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
LEXOPT = -Cf #-w -b
YACCOPT = #-v
MODULE = none
C_SRCS = \
preproc.c \
wpp.c
EXTRA_SRCS = ppy.y ppl.l
EXTRA_OBJS = y.tab.o @LEX_OUTPUT_ROOT@.o
all: libwpp.a
@MAKE_RULES@
libwpp.a: $(OBJS)
$(RM) $@
$(AR) $@ $(OBJS)
$(RANLIB) $@
y.tab.c y.tab.h: ppy.y
$(YACC) $(YACCOPT) -ppp -d -t $(SRCDIR)/ppy.y
@LEX_OUTPUT_ROOT@.c: ppl.l
$(LEX) $(LEXOPT) -d -Ppp -o$@ -8 $(SRCDIR)/ppl.l
### Dependencies:
......@@ -38,10 +38,7 @@
#include <ctype.h>
#include <string.h>
#include "utils.h"
#include "newstruc.h"
#include "wrc.h"
#include "preproc.h"
#include "wpp_private.h"
#define UNARY_OP(r, v, OP) \
......@@ -96,7 +93,7 @@
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: internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \
default: pp_internal_error(__FILE__, __LINE__, "Invalid type indicator (0x%04x)", v1.type); \
}
......@@ -186,91 +183,93 @@ pp_file : /* Empty */
;
preprocessor
: tINCLUDE tDQSTRING tNL { do_include($2, 1); }
| tINCLUDE tIQSTRING tNL { do_include($2, 0); }
| tIF pp_expr tNL { next_if_state(boolean(&$2)); }
| tIFDEF tIDENT tNL { next_if_state(pplookup($2) != NULL); free($2); }
: 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(include_state == 0 && t && !seen_junk)
if(pp_incl_state.state == 0 && t && !pp_incl_state.seen_junk)
{
include_state = 1;
include_ppp = $2;
include_ifdepth = get_if_depth();
pp_incl_state.state = 1;
pp_incl_state.ppp = $2;
pp_incl_state.ifdepth = pp_get_if_depth();
}
else if(include_state != 1)
else if(pp_incl_state.state != 1)
{
include_state = -1;
pp_incl_state.state = -1;
free($2);
}
else
free($2);
next_if_state(t);
if(debuglevel & DEBUGLEVEL_PPMSG)
fprintf(stderr, "tIFNDEF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n", input_name, line_number, include_state, include_ppp, include_ifdepth);
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 {
if_state_t s = pop_if();
pp_if_state_t s = pp_pop_if();
switch(s)
{
case if_true:
case if_elif:
push_if(if_elif);
pp_push_if(if_elif);
break;
case if_false:
push_if(boolean(&$2) ? if_true : if_false);
pp_push_if(boolean(&$2) ? if_true : if_false);
break;
case if_ignore:
push_if(if_ignore);
pp_push_if(if_ignore);
break;
case if_elsetrue:
case if_elsefalse:
pperror("#elif cannot follow #else");
default:
internal_error(__FILE__, __LINE__, "Invalid if_state (%d) in #elif directive", s);
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
}
}
| tELSE tNL {
if_state_t s = pop_if();
pp_if_state_t s = pp_pop_if();
switch(s)
{
case if_true:
push_if(if_elsefalse);
pp_push_if(if_elsefalse);
break;
case if_elif:
push_if(if_elif);
pp_push_if(if_elif);
break;
case if_false:
push_if(if_elsetrue);
pp_push_if(if_elsetrue);
break;
case if_ignore:
push_if(if_ignore);
pp_push_if(if_ignore);
break;
case if_elsetrue:
case if_elsefalse:
pperror("#else clause already defined");
default:
internal_error(__FILE__, __LINE__, "Invalid if_state (%d) in #else directive", s);
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
}
}
| tENDIF tNL {
pop_if();
if(include_ifdepth == get_if_depth() && include_state == 1)
pp_pop_if();
if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
{
include_state = 2;
seen_junk = 0;
pp_incl_state.state = 2;
pp_incl_state.seen_junk = 0;
}
else if(include_state != 1)
else if(pp_incl_state.state != 1)
{
include_state = -1;
pp_incl_state.state = -1;
}
if(debuglevel & DEBUGLEVEL_PPMSG)
fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n", input_name, line_number, include_state, include_ppp, include_ifdepth);
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 { del_define($2); free($2); }
| tDEFINE opt_text tNL { add_define($1, $2); }
| 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 {
add_macro($1, macro_args, nmacro_args, $5);
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); }
......@@ -285,17 +284,17 @@ preprocessor
| 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 { if(pedantic) ppwarning("#pragma ignored (arg: '%s')", $2); if($2) free($2); }
| tPPIDENT opt_text tNL { if(pedantic) ppwarning("#ident ignored (arg: '%s')", $2); if($2) free($2); }
| tPRAGMA opt_text tNL { if(pp_status.pedantic) ppwarning("#pragma ignored (arg: '%s')", $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=xmalloc(nl);
snprintf(fn,nl,"\"%s\"",$2);
char *fn=pp_xmalloc(nl);
sprintf(fn,"\"%s\"",$2);
free($2);
do_include(fn,1);
pp_do_include(fn,1);
}
| tRCINCLUDE tDQSTRING {
do_include($2,1);
pp_do_include($2,1);
}
/*| tNL*/
;
......@@ -537,9 +536,10 @@ static int boolean(cval_t *v)
static marg_t *new_marg(char *str, def_arg_t type)
{
marg_t *ma = (marg_t *)xmalloc(sizeof(marg_t));
marg_t *ma = pp_xmalloc(sizeof(marg_t));
ma->arg = str;
ma->type = type;
ma->nnl = 0;
return ma;
}
......@@ -547,7 +547,7 @@ static marg_t *add_new_marg(char *str, def_arg_t type)
{
marg_t *ma = new_marg(str, type);
nmacro_args++;
macro_args = (marg_t **)xrealloc(macro_args, nmacro_args * sizeof(macro_args[0]));
macro_args = pp_xrealloc(macro_args, nmacro_args * sizeof(macro_args[0]));
macro_args[nmacro_args-1] = ma;
return ma;
}
......@@ -565,12 +565,13 @@ static int marg_index(char *id)
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
{
mtext_t *mt = (mtext_t *)xmalloc(sizeof(mtext_t));
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;
}
......@@ -584,7 +585,7 @@ static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
if(tail->type == exp_text && mtp->type == exp_text)
{
tail->subst.text = xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
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);
......@@ -650,7 +651,7 @@ static char *merge_text(char *s1, char *s2)
{
int l1 = strlen(s1);
int l2 = strlen(s2);
s1 = xrealloc(s1, l1+l2+1);
s1 = pp_xrealloc(s1, l1+l2+1);
memcpy(s1+l1, s2, l2+1);
free(s2);
return s1;
......
/*
* 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 <time.h>
#include "wpp_private.h"
#include "wpp.h"
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 )
{
if (!value) value = "";
pp_add_define( pp_xstrdup(name), pp_xstrdup(value) );
}
/* 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;
else p = "";
pp_add_define( str, pp_xstrdup(p) );
}
/* 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;
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);
return ret;
}
/* parse into a temporary file */
int wpp_parse_temp( const char *input, char **output_name )
{
char *temp_name;
FILE *output;
int ret;
if(!(temp_name = tmpnam(NULL)))
{
fprintf(stderr, "Could not generate a temp-name\n");
temp_name = pp_xstrdup(temp_name);
}
if (!(output = fopen(temp_name, "wt")))
{
fprintf(stderr,"Could not open %s for writing\n", temp_name);
exit(2);
}
*output_name = temp_name;
ret = wpp_parse( input, output );
fclose( output );
return ret;
}
/*
* Exported functions of the Wine preprocessor
*
* 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_H
#define __WINE_WPP_H
#include <stdio.h>
extern void wpp_add_define( const char *name, const char *value );
extern void wpp_add_cmdline_define( const char *value );
extern void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug );
extern void wpp_set_pedantic( int on );
extern void wpp_add_include_path( const char *path );
extern char *wpp_find_include( const char *name, int search );
extern int wpp_parse( const char *input, FILE *output );
extern int wpp_parse_temp( const char *input, char **output_name );
#endif /* __WINE_WPP_H */
/*
* 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
......@@ -16,8 +17,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WRC_PREPROC_H
#define __WRC_PREPROC_H
#ifndef __WINE_WPP_PRIVATE_H
#define __WINE_WPP_PRIVATE_H
#include <stdio.h>
#include <string.h>
struct pp_entry; /* forward */
/*
......@@ -106,7 +110,27 @@ typedef enum {
if_elsefalse,
if_elsetrue,
if_ignore
} if_state_t;
} 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
......@@ -167,19 +191,42 @@ typedef struct cval {
void *pp_xmalloc(size_t);
void *pp_xrealloc(void *, size_t);
char *pp_xstrdup(const char *str);
pp_entry_t *pplookup(char *ident);
pp_entry_t *add_define(char *def, char *text);
pp_entry_t *add_cmdline_define(char *set);
pp_entry_t *add_special_define(char *id);
pp_entry_t *add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
void del_define(char *name);
FILE *open_include(const char *name, int search, char **newpath);
void add_include_path(char *path);
void push_if(if_state_t s);
void next_if_state(int);
if_state_t pop_if(void);
if_state_t if_state(void);
int get_if_depth(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(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
......@@ -190,16 +237,10 @@ extern char *pptext;
extern int pp_flex_debug;
int pplex(void);
void do_include(char *fname, int type);
void push_ignore_state(void);
void pop_ignore_state(void);
void pp_do_include(char *fname, int type);
void pp_push_ignore_state(void);
void pp_pop_ignore_state(void);
extern int include_state;
extern char *include_ppp;
extern char *include_filename;
extern int include_ifdepth;
extern int seen_junk;
extern includelogicentry_t *includelogiclist;
/*
* From ppy.y
......@@ -207,5 +248,4 @@ extern includelogicentry_t *includelogiclist;
int ppparse(void);
extern int ppdebug;
#endif
#endif /* __WINE_WPP_PRIVATE_H */
Makefile
lex.ppl.c
lex.yy.c
ppy.tab.c
ppy.tab.h
wrc
y.tab.c
y.tab.h
ppy.tab.c
ppy.tab.h
y.output
ppy.output
lex.backup
......@@ -6,6 +6,8 @@ VPATH = @srcdir@
LEXOPT = -Cf #-w -b
YACCOPT = #-v
EXEEXT = @EXEEXT@
EXTRAINCL = -I$(TOPSRCDIR)/tools/wpp
EXTRALIBS = -L$(TOPOBJDIR)/tools/wpp -lwpp
PROGRAMS = wrc$(EXEEXT)
MODULE = none
......@@ -14,13 +16,11 @@ C_SRCS = \
dumpres.c \
genres.c \
newstruc.c \
preproc.c \
readres.c \
utils.c \
wrc.c \
writeres.c
GEN_C_SRCS = ppy.tab.c lex.ppl.c
EXTRA_SRCS = parser.y parser.l
EXTRA_OBJS = y.tab.o @LEX_OUTPUT_ROOT@.o
......@@ -28,26 +28,20 @@ all: $(PROGRAMS)
@MAKE_RULES@
wrc: $(OBJS)
$(CC) $(CFLAGS) -o wrc $(OBJS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) $(LDFLAGS)
wrc: $(OBJS) $(TOPOBJDIR)/tools/wpp/libwpp.a
$(CC) $(CFLAGS) -o wrc $(OBJS) $(EXTRALIBS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) $(LDFLAGS)
wrc.exe: $(OBJS)
$(CC) $(CFLAGS) -o wrc.exe $(OBJS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) -liberty $(LDFLAGS)
wrc.exe: $(OBJS) $(TOPOBJDIR)/tools/wpp/libwpp.a
$(CC) $(CFLAGS) -o wrc.exe $(OBJS) $(EXTRALIBS) $(LIBWINE) $(LIBUNICODE) $(LEXLIB) -liberty $(LDFLAGS)
y.tab.c y.tab.h: parser.y
$(YACC) $(YACCOPT) -d -t $(SRCDIR)/parser.y
ppy.tab.c ppy.tab.h: ppy.y
$(YACC) $(YACCOPT) -bppy -ppp -d -t $(SRCDIR)/ppy.y
@LEX_OUTPUT_ROOT@.c: parser.l
$(LEX) $(LEXOPT) -d -8 $(SRCDIR)/parser.l
lex.ppl.c: ppl.l
$(LEX) $(LEXOPT) -d -Ppp -8 -olex.ppl.c $(SRCDIR)/ppl.l
clean::
$(RM) ppy.tab.h ppy.output parser.output parser.tab.h lex.backup y.output
$(RM) parser.output parser.tab.h lex.backup y.output
install:: $(PROGRAMS)
$(MKINSTALLDIRS) $(bindir) $(mandir)/man$(prog_manext)
......
......@@ -102,7 +102,6 @@ cident [a-zA-Z_][0-9a-zA-Z_]*
#include "wrc.h"
#include "utils.h"
#include "preproc.h"
#include "parser.h"
#include "newstruc.h"
......
......@@ -136,7 +136,7 @@
#include "utils.h"
#include "newstruc.h"
#include "dumpres.h"
#include "preproc.h"
#include "wpp.h"
#include "parser.h"
#include "windef.h"
#include "winbase.h"
......@@ -2278,14 +2278,17 @@ static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
/* Raw data functions */
static raw_data_t *load_file(string_t *name)
{
FILE *fp;
FILE *fp = NULL;
char *path;
raw_data_t *rd;
if(name->type != str_char)
yyerror("Filename must be ASCII string");
fp = open_include(name->str.cstr, 1, NULL);
if(!fp)
if (!(path = wpp_find_include(name->str.cstr, 1)))
yyerror("Cannot open file %s", name->str.cstr);
if (!(fp = fopen( path, "rb" )))
yyerror("Cannot open file %s", name->str.cstr);
free( path );
rd = new_raw_data();
fseek(fp, 0, SEEK_END);
rd->size = ftell(fp);
......
......@@ -33,7 +33,6 @@
#include "wrc.h"
#include "utils.h"
#include "parser.h"
#include "preproc.h"
/* #define WANT_NEAR_INDICATION */
......@@ -90,26 +89,6 @@ int yywarning(const char *s, ...)
return 0;
}
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 internal_error(const char *file, int line, const char *s, ...)
{
va_list ap;
......
......@@ -31,8 +31,6 @@ void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *xstrdup(const char *str);
int pperror(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppwarning(const char *s, ...) __attribute__((format (printf, 1, 2)));
int yyerror(const char *s, ...) __attribute__((format (printf, 1, 2)));
int yywarning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4)));
......
......@@ -64,8 +64,8 @@
#include "dumpres.h"
#include "genres.h"
#include "newstruc.h"
#include "preproc.h"
#include "parser.h"
#include "wpp.h"
static char usage[] =
"Usage: wrc [options...] [infile[.rc|.res]]\n"
......@@ -342,7 +342,7 @@ int main(int argc,char *argv[])
debuglevel = strtol(optarg, NULL, 0);
break;
case 'D':
add_cmdline_define(optarg);
wpp_add_cmdline_define(optarg);
break;
case 'e':
extensions = 0;
......@@ -360,7 +360,7 @@ int main(int argc,char *argv[])
create_header = 1;
break;
case 'I':
add_include_path(optarg);
wpp_add_include_path(optarg);
break;
case 'l':
{
......@@ -419,6 +419,7 @@ int main(int argc,char *argv[])
break;
case 'W':
pedantic = 1;
wpp_set_pedantic(1);
break;
default:
lose++;
......@@ -571,28 +572,25 @@ int main(int argc,char *argv[])
yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0;
ppdebug = debuglevel & DEBUGLEVEL_PPTRACE ? 1 : 0;
pp_flex_debug = debuglevel & DEBUGLEVEL_PPLEX ? 1 : 0;
wpp_set_debug( (debuglevel & DEBUGLEVEL_PPLEX) != 0,
(debuglevel & DEBUGLEVEL_PPTRACE) != 0,
(debuglevel & DEBUGLEVEL_PPMSG) != 0 );
/* Set the default defined stuff */
add_cmdline_define("__WRC__=" WRC_EXP_STRINGIZE(WRC_MAJOR_VERSION));
add_cmdline_define("__WRC_MINOR__=" WRC_EXP_STRINGIZE(WRC_MINOR_VERSION));
add_cmdline_define("__WRC_MICRO__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION));
add_cmdline_define("__WRC_PATCH__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION));
wpp_add_cmdline_define("__WRC__=" WRC_EXP_STRINGIZE(WRC_MAJOR_VERSION));
wpp_add_cmdline_define("__WRC_MINOR__=" WRC_EXP_STRINGIZE(WRC_MINOR_VERSION));
wpp_add_cmdline_define("__WRC_MICRO__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION));
wpp_add_cmdline_define("__WRC_PATCH__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION));
add_cmdline_define("RC_INVOKED=1");
wpp_add_cmdline_define("RC_INVOKED=1");
if(win32)
{
add_cmdline_define("__WIN32__=1");
add_cmdline_define("__FLAT__=1");
wpp_add_cmdline_define("__WIN32__=1");
wpp_add_cmdline_define("__FLAT__=1");
}
add_special_define("__FILE__");
add_special_define("__LINE__");
add_special_define("__DATE__");
add_special_define("__TIME__");
/* Check if the user set a language, else set default */
if(!currentlanguage)
currentlanguage = new_language(0, 0);
......@@ -624,7 +622,6 @@ int main(int argc,char *argv[])
/* Run the preprocessor on the input */
if(!no_preprocess && !binary)
{
char *real_name;
/*
* Preprocess the input to a temp-file, or stdout if
* no output was given.
......@@ -632,54 +629,32 @@ int main(int argc,char *argv[])
chat("Starting preprocess");
if(preprocess_only && !output_name)
{
ppout = stdout;
}
else if(preprocess_only && output_name)
{
if(!(ppout = fopen(output_name, "wb")))
error("Could not open %s for writing\n", output_name);
}
else
{
if(!(temp_name = tmpnam(NULL)))
error("Could nor generate a temp-name\n");
temp_name = xstrdup(temp_name);
if(!(ppout = fopen(temp_name, "wb")))
error("Could not create a temp-file\n");
atexit(rm_tempfile);
}
real_name = input_name; /* Because it gets overwritten */
if(!input_name)
ppin = stdin;
else
{
if(!(ppin = fopen(input_name, "rb")))
error("Could not open %s\n", input_name);
}
fprintf(ppout, "# 1 \"%s\" 1\n", input_name ? input_name : "");
ret = ppparse();
input_name = real_name;
if(input_name)
fclose(ppin);
fclose(ppout);
input_name = temp_name;
if (!preprocess_only)
{
atexit(rm_tempfile);
ret = wpp_parse_temp( input_name, &temp_name );
}
else if (output_name)
{
FILE *output;
if (!(output = fopen( output_name, "w" )))
error( "Could not open %s for writing\n", output_name );
ret = wpp_parse( input_name, output );
fclose( output );
}
else
{
ret = wpp_parse( input_name, stdout );
}
if(ret)
exit(1); /* Error during preprocess */
if(preprocess_only)
exit(0);
input_name = temp_name;
}
if(!binary)
......@@ -761,4 +736,3 @@ static void segvhandler(int sig)
fflush(stderr);
abort();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment