From 9442c45c805479f02792691ebd51bc36b05aa4c7 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 3 Dec 2020 15:01:54 +0100 Subject: [PATCH] wpp: Merge preproc.c into wpp.c. Signed-off-by: Alexandre Julliard --- libs/wpp/Makefile.in | 4 +- libs/wpp/{preproc.c => wpp.c} | 153 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 152 insertions(+), 5 deletions(-) rename libs/wpp/{preproc.c => wpp.c} (81%) diff --git a/libs/wpp/Makefile.in b/libs/wpp/Makefile.in index f6fb5400b7d..982d34b15bd 100644 --- a/libs/wpp/Makefile.in +++ b/libs/wpp/Makefile.in @@ -1,8 +1,6 @@ STATICLIB = libwpp.a -C_SRCS = \ - preproc.c \ - wpp.c +C_SRCS = wpp.c LEX_SRCS = ppl.l BISON_SRCS = ppy.y diff --git a/libs/wpp/preproc.c b/libs/wpp/wpp.c similarity index 81% rename from libs/wpp/preproc.c rename to libs/wpp/wpp.c index b805e2a7552..0e26121330c 100644 --- a/libs/wpp/preproc.c +++ b/libs/wpp/wpp.c @@ -1,5 +1,8 @@ /* - * Copyright 1998 Bertho A. Stultiens (BS) + * 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 @@ -26,12 +29,13 @@ #include #include #include +#include #ifdef HAVE_UNISTD_H # include #endif -#include "wine/wpp.h" #include "wpp_private.h" +#include "wine/wpp.h" struct pp_status pp_status; @@ -43,6 +47,17 @@ static struct list pp_defines[HASHKEY]; static pp_if_state_t if_stack[MAXIFSTACK]; static int if_stack_idx = 0; +int ppy_debug, pp_flex_debug; + +struct define +{ + struct list entry; + char *name; + char *value; +}; + +static struct list cmdline_defines = LIST_INIT( cmdline_defines ); + void *pp_xmalloc(size_t size) { void *res; @@ -577,3 +592,137 @@ void pp_internal_error(const char *file, int line, const char *s, ...) va_end(ap); exit(3); } + +static void add_cmdline_defines(void) +{ + struct define *def; + + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) + { + if (def->value) pp_add_define( def->name, def->value ); + } +} + +static void add_special_defines(void) +{ + time_t now = time(NULL); + pp_entry_t *ppp; + char buf[32]; + + strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now)); + pp_add_define( "__DATE__", buf ); + + strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now)); + pp_add_define( "__TIME__", buf ); + + ppp = pp_add_define( "__FILE__", "" ); + ppp->type = def_special; + + ppp = pp_add_define( "__LINE__", "" ); + ppp->type = def_special; +} + +/* add a define to the preprocessor list */ +static void wpp_add_define( const char *name, const char *value ) +{ + struct define *def; + + if (!value) value = ""; + + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) + { + if (!strcmp( def->name, name )) + { + free( def->value ); + def->value = pp_xstrdup(value); + return; + } + } + + def = pp_xmalloc( sizeof(*def) ); + def->name = pp_xstrdup(name); + def->value = pp_xstrdup(value); + list_add_head( &cmdline_defines, &def->entry ); +} + + +/* undefine a previously added definition */ +void wpp_del_define( const char *name ) +{ + struct define *def; + + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) + { + if (!strcmp( def->name, name )) + { + free( def->value ); + def->value = NULL; + return; + } + } +} + + +/* add a command-line define of the form NAME=VALUE */ +void wpp_add_cmdline_define( const char *value ) +{ + char *p; + char *str = pp_xstrdup(value); + + p = strchr( str, '=' ); + if (p) *p++ = 0; + wpp_add_define( str, p ); + free( str ); +} + + +/* set the various debug flags */ +void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug ) +{ + pp_flex_debug = lex_debug; + 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_init_define_state(); + add_cmdline_defines(); + add_special_defines(); + + if (!input) pp_status.file = stdin; + else if (!(pp_status.file = fopen(input, "rt"))) + ppy_error("Could not open %s\n", input); + + pp_status.input = input ? pp_xstrdup(input) : NULL; + + ppy_out = output; + pp_writestring("# 1 \"%s\" 1\n", input ? input : ""); + + ret = ppy_parse(); + + if (input) + { + fclose(pp_status.file); + free(pp_status.input); + } + /* Clean if_stack, it could remain dirty on errors */ + while (pp_get_if_depth()) pp_pop_if(); + pp_free_define_state(); + return ret; +} -- 2.11.4.GIT