wpp: Remove some dead code.
[wine/zf.git] / libs / wpp / wpp.c
blob5db744d9c00d262313a7f11645aa237e17bbd051
1 /*
2 * Exported functions of the Wine preprocessor
4 * Copyright 1998 Bertho A. Stultiens
5 * Copyright 2002 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <time.h>
26 #include <stdlib.h>
28 #include "wpp_private.h"
29 #include "wine/wpp.h"
31 int ppy_debug, pp_flex_debug;
33 struct define
35 struct list entry;
36 char *name;
37 char *value;
40 static struct list cmdline_defines = LIST_INIT( cmdline_defines );
42 static void add_cmdline_defines(void)
44 struct define *def;
46 LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry )
48 if (def->value) pp_add_define( def->name, def->value );
52 static void add_special_defines(void)
54 time_t now = time(NULL);
55 pp_entry_t *ppp;
56 char buf[32];
58 strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
59 pp_add_define( "__DATE__", buf );
61 strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
62 pp_add_define( "__TIME__", buf );
64 ppp = pp_add_define( "__FILE__", "" );
65 ppp->type = def_special;
67 ppp = pp_add_define( "__LINE__", "" );
68 ppp->type = def_special;
71 /* add a define to the preprocessor list */
72 static void wpp_add_define( const char *name, const char *value )
74 struct define *def;
76 if (!value) value = "";
78 LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry )
80 if (!strcmp( def->name, name ))
82 free( def->value );
83 def->value = pp_xstrdup(value);
84 return;
88 def = pp_xmalloc( sizeof(*def) );
89 def->name = pp_xstrdup(name);
90 def->value = pp_xstrdup(value);
91 list_add_head( &cmdline_defines, &def->entry );
95 /* undefine a previously added definition */
96 void wpp_del_define( const char *name )
98 struct define *def;
100 LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry )
102 if (!strcmp( def->name, name ))
104 free( def->value );
105 def->value = NULL;
106 return;
112 /* add a command-line define of the form NAME=VALUE */
113 void wpp_add_cmdline_define( const char *value )
115 char *p;
116 char *str = pp_xstrdup(value);
118 p = strchr( str, '=' );
119 if (p) *p++ = 0;
120 wpp_add_define( str, p );
121 free( str );
125 /* set the various debug flags */
126 void wpp_set_debug( int lex_debug, int parser_debug, int msg_debug )
128 pp_flex_debug = lex_debug;
129 ppy_debug = parser_debug;
130 pp_status.debug = msg_debug;
134 /* set the pedantic mode */
135 void wpp_set_pedantic( int on )
137 pp_status.pedantic = on;
141 /* the main preprocessor parsing loop */
142 int wpp_parse( const char *input, FILE *output )
144 int ret;
146 pp_status.input = NULL;
147 pp_status.line_number = 1;
148 pp_status.char_number = 1;
150 pp_init_define_state();
151 add_cmdline_defines();
152 add_special_defines();
154 if (!input) pp_status.file = stdin;
155 else if (!(pp_status.file = fopen(input, "rt")))
156 ppy_error("Could not open %s\n", input);
158 pp_status.input = input ? pp_xstrdup(input) : NULL;
160 ppy_out = output;
161 pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
163 ret = ppy_parse();
165 if (input)
167 fclose(pp_status.file);
168 free(pp_status.input);
170 /* Clean if_stack, it could remain dirty on errors */
171 while (pp_get_if_depth()) pp_pop_if();
172 pp_free_define_state();
173 return ret;