ReactOS 0.4.16-dev-1946-g52006dd
wpp.c File Reference
#include "config.h"
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "../tools.h"
#include "utils.h"
#include "wpp_private.h"
Include dependency graph for wpp.c:

Go to the source code of this file.

Classes

struct  define
 

Macros

#define HASHKEY   2039
 
#define MAXIFSTACK   64
 

Functions

static charwpp_lookup (const char *name, int type, const char *parent_name)
 
static int pphash (const char *str)
 
pp_entry_tpplookup (const char *ident)
 
static void free_pp_entry (pp_entry_t *ppp, int idx)
 
static void pp_init_define_state (void)
 
static void pp_free_define_state (void)
 
void pp_del_define (const char *name)
 
pp_entry_tpp_add_define (const char *def, const char *text)
 
pp_entry_tpp_add_macro (char *id, char *args[], int nargs, int variadic, mtext_t *exp)
 
void wpp_add_include_path (const char *path)
 
charwpp_find_include (const char *name, const char *parent_name)
 
voidpp_open_include (const char *name, int type, const char *parent_name, char **newpath)
 
void pp_push_if (pp_if_state_t s)
 
pp_if_state_t pp_pop_if (void)
 
pp_if_state_t pp_if_state (void)
 
void pp_next_if_state (int i)
 
int pp_get_if_depth (void)
 
static void generic_msg (const char *s, const char *t, const char *n, va_list ap)
 
int ppy_error (const char *s,...)
 
int ppy_warning (const char *s,...)
 
static void add_cmdline_defines (void)
 
static void add_special_defines (void)
 
static void wpp_add_define (const char *name, const char *value)
 
void wpp_del_define (const char *name)
 
void wpp_add_cmdline_define (const char *value)
 
void wpp_set_debug (int lex_debug, int parser_debug, int msg_debug)
 
int wpp_parse (const char *input, FILE *output)
 

Variables

struct pp_status pp_status
 
static struct list pp_defines [HASHKEY]
 
static pp_if_state_t if_stack [MAXIFSTACK]
 
static int if_stack_idx = 0
 
int ppy_debug
 
int pp_flex_debug
 
static struct list cmdline_defines = LIST_INIT( cmdline_defines )
 
static struct strarray includes
 
static const char *const pp_if_state_str []
 

Macro Definition Documentation

◆ HASHKEY

#define HASHKEY   2039

Definition at line 39 of file wpp.c.

◆ MAXIFSTACK

#define MAXIFSTACK   64

Definition at line 43 of file wpp.c.

Function Documentation

◆ add_cmdline_defines()

static void add_cmdline_defines ( void  )
static

Definition at line 517 of file wpp.c.

518{
519 struct define *def;
520
522 {
523 if (def->value) pp_add_define( def->name, def->value );
524 }
525}
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
char * value
Definition: compiler.c:67
char * name
Definition: compiler.c:66
pp_entry_t * pp_add_define(const char *def, const char *text)
Definition: wpp.c:199
static struct list cmdline_defines
Definition: wpp.c:56

Referenced by wpp_parse().

◆ add_special_defines()

static void add_special_defines ( void  )
static

Definition at line 527 of file wpp.c.

528{
529 time_t now = time(NULL);
530 pp_entry_t *ppp;
531 char buf[32];
532
533 strftime(buf, sizeof(buf), "\"%b %d %Y\"", localtime(&now));
534 pp_add_define( "__DATE__", buf );
535
536 strftime(buf, sizeof(buf), "\"%H:%M:%S\"", localtime(&now));
537 pp_add_define( "__TIME__", buf );
538
539 ppp = pp_add_define( "__FILE__", "" );
540 ppp->type = def_special;
541
542 ppp = pp_add_define( "__LINE__", "" );
543 ppp->type = def_special;
544}
#define NULL
Definition: types.h:112
@ def_special
Definition: wpp_private.h:92
__kernel_time_t time_t
Definition: linux.h:252
time_t now
Definition: finger.c:65
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
__u16 time
Definition: mkdosfs.c:8
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
size_t CDECL strftime(char *str, size_t max, const char *format, const struct tm *mstm)
Definition: strftime.c:294
Definition: wpp_private.h:95
def_type_t type
Definition: wpp_private.h:98

Referenced by wpp_parse().

◆ free_pp_entry()

static void free_pp_entry ( pp_entry_t ppp,
int  idx 
)
static

Definition at line 140 of file wpp.c.

141{
142 if(ppp->iep)
143 {
144 list_remove( &ppp->iep->entry );
145 free(ppp->iep->filename);
146 free(ppp->iep);
147 }
148 list_remove( &ppp->entry );
149 free(ppp);
150}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
#define free
Definition: debug_ros.c:5
struct list entry
Definition: wpp_private.h:42
struct list entry
Definition: wpp_private.h:78
includelogicentry_t * iep
Definition: wpp_private.h:109

Referenced by pp_del_define(), and pp_free_define_state().

◆ generic_msg()

static void generic_msg ( const char s,
const char t,
const char n,
va_list  ap 
)
static

Definition at line 491 of file wpp.c.

492{
493 fprintf(stderr, "%s:%d:%d: %s: ", pp_status.input ? pp_status.input : "stdin",
495 vfprintf(stderr, s, ap);
496 fprintf(stderr, "\n");
497}
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble t
Definition: gl.h:2047
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
int char_number
Definition: wpp_private.h:223
char * input
Definition: wpp_private.h:220
int line_number
Definition: wpp_private.h:222
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by ppy_error(), and ppy_warning().

◆ pp_add_define()

pp_entry_t * pp_add_define ( const char def,
const char text 
)

Definition at line 199 of file wpp.c.

200{
201 int len;
202 char *cptr;
203 int idx;
204 pp_entry_t *ppp;
205
206 idx = pphash(def);
207 if((ppp = pplookup(def)) != NULL)
208 {
209 if(pedantic)
210 ppy_warning("Redefinition of %s\n%s:%d: note: previous definition was here",
211 def, ppp->filename, ppp->linenumber);
212 pp_del_define(def);
213 }
214 ppp = xmalloc(sizeof(pp_entry_t));
215 memset( ppp, 0, sizeof(*ppp) );
216 ppp->ident = xstrdup(def);
217 ppp->type = def_define;
218 ppp->subst.text = text ? xstrdup(text) : NULL;
219 ppp->filename = xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
221 list_add_head( &pp_defines[idx], &ppp->entry );
222 if(ppp->subst.text)
223 {
224 /* Strip trailing white space from subst text */
225 len = strlen(ppp->subst.text);
226 while(len && strchr(" \t\r\n", ppp->subst.text[len-1]))
227 {
228 ppp->subst.text[--len] = '\0';
229 }
230 /* Strip leading white space from subst text */
231 for(cptr = ppp->subst.text; *cptr && strchr(" \t\r", *cptr); cptr++)
232 ;
233 if(ppp->subst.text != cptr)
234 memmove(ppp->subst.text, cptr, strlen(cptr)+1);
235 }
236 if(pp_status.debug)
237 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)");
238
239 return ppp;
240}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
char * xstrdup(const char *s)
Definition: uimain.c:768
void * xmalloc(int size)
Definition: uimain.c:747
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
@ def_define
Definition: wpp_private.h:90
unsigned int idx
Definition: utils.c:41
const WCHAR * text
Definition: package.c:1794
#define printf
Definition: freeldr.h:97
GLenum GLsizei len
Definition: glext.h:6722
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define memset(x, y, z)
Definition: compat.h:39
int linenumber
Definition: wpp_private.h:108
char * text
Definition: wpp_private.h:104
union pp_entry::@276 subst
char * filename
Definition: wpp_private.h:107
char * ident
Definition: wpp_private.h:99
int pedantic
Definition: widl.c:97
int ppy_warning(const char *s,...)
Definition: wpp.c:508
static int pphash(const char *str)
Definition: wpp.c:116
pp_entry_t * pplookup(const char *ident)
Definition: wpp.c:124
static struct list pp_defines[HASHKEY]
Definition: wpp.c:41
void pp_del_define(const char *name)
Definition: wpp.c:178

Referenced by add_cmdline_defines(), and add_special_defines().

◆ pp_add_macro()

pp_entry_t * pp_add_macro ( char id,
char args[],
int  nargs,
int  variadic,
mtext_t exp 
)

Definition at line 242 of file wpp.c.

243{
244 int idx;
245 pp_entry_t *ppp;
246
247 idx = pphash(id);
248 if((ppp = pplookup(id)) != NULL)
249 {
250 if(pedantic)
251 ppy_warning("Redefinition of %s\n%s:%d: note: previous definition was here",
252 id, ppp->filename, ppp->linenumber);
253 pp_del_define(id);
254 }
255 ppp = xmalloc(sizeof(pp_entry_t));
256 memset( ppp, 0, sizeof(*ppp) );
257 ppp->ident = id;
258 ppp->type = def_macro;
259 ppp->margs = args;
260 ppp->nargs = nargs;
261 ppp->variadic = variadic;
262 ppp->subst.mtext= exp;
263 ppp->filename = xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
265 list_add_head( &pp_defines[idx], &ppp->entry );
266 if(pp_status.debug)
267 {
268 fprintf(stderr, "Added macro (%s, %d) <%s(%d%s)> to <", pp_status.input, pp_status.line_number, ppp->ident, nargs, variadic ? ",va" : "");
269 for(; exp; exp = exp->next)
270 {
271 switch(exp->type)
272 {
273 case exp_text:
274 fprintf(stderr, " \"%s\" ", exp->subst.text);
275 break;
276 case exp_stringize:
277 fprintf(stderr, " #(%d) ", exp->subst.argidx);
278 break;
279 case exp_concat:
280 fprintf(stderr, "##");
281 break;
282 case exp_subst:
283 fprintf(stderr, " <%d> ", exp->subst.argidx);
284 break;
285 }
286 }
287 fprintf(stderr, ">\n");
288 }
289 return ppp;
290}
@ exp_stringize
Definition: wpp_private.h:71
@ exp_text
Definition: wpp_private.h:69
@ exp_subst
Definition: wpp_private.h:72
@ exp_concat
Definition: wpp_private.h:70
@ def_macro
Definition: wpp_private.h:91
GLuint id
Definition: glext.h:5910
DWORD exp
Definition: msg.c:16058
#define args
Definition: format.c:66
int variadic
Definition: wpp_private.h:83
mtext_t * mtext
Definition: wpp_private.h:103
int nargs
Definition: wpp_private.h:101
marg_t ** margs
Definition: wpp_private.h:100

◆ pp_del_define()

void pp_del_define ( const char name)

Definition at line 178 of file wpp.c.

179{
180 pp_entry_t *ppp;
181 int idx = pphash(name);
182
183 if((ppp = pplookup(name)) == NULL)
184 {
185 if(pedantic)
186 ppy_warning("%s was not defined", name);
187 return;
188 }
189
190 if(pp_status.debug)
191 printf("Deleting (%s, %d) <%s>\n", pp_status.input, pp_status.line_number, name);
192
193 free( ppp->ident );
194 free( ppp->subst.text );
195 free( ppp->filename );
196 free_pp_entry( ppp, idx );
197}
Definition: name.c:39
static void free_pp_entry(pp_entry_t *ppp, int idx)
Definition: wpp.c:140

Referenced by pp_add_define(), and pp_add_macro().

◆ pp_free_define_state()

static void pp_free_define_state ( void  )
static

Definition at line 161 of file wpp.c.

162{
163 int i;
164 pp_entry_t *ppp, *ppp2;
165
166 for (i = 0; i < HASHKEY; i++)
167 {
169 {
170 free( ppp->ident );
171 free( ppp->subst.text );
172 free( ppp->filename );
173 free_pp_entry( ppp, i );
174 }
175 }
176}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
#define HASHKEY
Definition: wpp.c:39

Referenced by wpp_parse().

◆ pp_get_if_depth()

int pp_get_if_depth ( void  )

Definition at line 486 of file wpp.c.

487{
488 return if_stack_idx;
489}
static int if_stack_idx
Definition: wpp.c:45

Referenced by wpp_parse().

◆ pp_if_state()

pp_if_state_t pp_if_state ( void  )

Definition at line 458 of file wpp.c.

459{
460 if(!if_stack_idx)
461 return if_true;
462 else
463 return if_stack[if_stack_idx-1];
464}
@ if_true
Definition: wpp_private.h:120
static pp_if_state_t if_stack[MAXIFSTACK]
Definition: wpp.c:44

Referenced by pp_next_if_state(), pp_pop_if(), and pp_push_if().

◆ pp_init_define_state()

static void pp_init_define_state ( void  )
static

Definition at line 153 of file wpp.c.

154{
155 int i;
156
157 for (i = 0; i < HASHKEY; i++) list_init( &pp_defines[i] );
158}
static void list_init(struct list_entry *head)
Definition: list.h:51

Referenced by wpp_parse().

◆ pp_next_if_state()

void pp_next_if_state ( int  i)

Definition at line 467 of file wpp.c.

468{
469 switch(pp_if_state())
470 {
471 case if_true:
472 case if_elsetrue:
474 break;
475 case if_false:
476 case if_elsefalse:
477 case if_elif:
478 case if_ignore:
480 break;
481 case if_error:
482 assert(0);
483 }
484}
@ if_elif
Definition: wpp_private.h:121
@ if_elsefalse
Definition: wpp_private.h:122
@ if_elsetrue
Definition: wpp_private.h:123
@ if_error
Definition: wpp_private.h:125
@ if_false
Definition: wpp_private.h:119
@ if_ignore
Definition: wpp_private.h:124
#define assert(x)
Definition: debug.h:53
pp_if_state_t pp_if_state(void)
Definition: wpp.c:458
void pp_push_if(pp_if_state_t s)
Definition: wpp.c:397

◆ pp_open_include()

void * pp_open_include ( const char name,
int  type,
const char parent_name,
char **  newpath 
)

Definition at line 320 of file wpp.c.

321{
322 char *path;
323 void *fp;
324
325 if (!(path = wpp_lookup(name, type, parent_name))) return NULL;
326 fp = fopen(path, "rt");
327
328 if (fp)
329 {
330 if (pp_status.debug)
331 printf("Going to include <%s>\n", path);
332 if (newpath) *newpath = path;
333 else free( path );
334 return fp;
335 }
336 free( path );
337 return NULL;
338}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static char * wpp_lookup(const char *name, int type, const char *parent_name)
Definition: wpp.c:59

◆ pp_pop_if()

pp_if_state_t pp_pop_if ( void  )

Definition at line 423 of file wpp.c.

424{
425 if(if_stack_idx <= 0)
426 {
427 ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
428 return if_error;
429 }
430
431 switch(pp_if_state())
432 {
433 case if_true:
434 case if_elsetrue:
435 break;
436 case if_false:
437 case if_elsefalse:
438 case if_elif:
439 case if_ignore:
441 break;
442 case if_error:
443 assert(0);
444 }
445
446 if(pp_flex_debug)
447 fprintf(stderr, "Pop if %s:%d: %s(%d) -> %s(%d)\n",
453 if_stack_idx-1);
454
455 return if_stack[--if_stack_idx];
456}
void pp_pop_ignore_state(void)
int pp_flex_debug
Definition: wpp.c:47
static const char *const pp_if_state_str[]
Definition: wpp.c:388
int ppy_error(const char *s,...)
Definition: wpp.c:499

Referenced by wpp_parse().

◆ pp_push_if()

void pp_push_if ( pp_if_state_t  s)

Definition at line 397 of file wpp.c.

398{
400 error("#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)\n", MAXIFSTACK);
401
402 if(pp_flex_debug)
404
406
407 switch(s)
408 {
409 case if_true:
410 case if_elsetrue:
411 break;
412 case if_false:
413 case if_elsefalse:
414 case if_elif:
415 case if_ignore:
417 break;
418 case if_error:
419 assert(0);
420 }
421}
void pp_push_ignore_state(void)
#define error(str)
Definition: mkdosfs.c:1605
#define MAXIFSTACK
Definition: wpp.c:43

Referenced by pp_next_if_state().

◆ pphash()

static int pphash ( const char str)
static

Definition at line 116 of file wpp.c.

117{
118 int sum = 0;
119 while(*str)
120 sum += *str++;
121 return sum % HASHKEY;
122}
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
const WCHAR * str

Referenced by pp_add_define(), pp_add_macro(), pp_del_define(), and pplookup().

◆ pplookup()

pp_entry_t * pplookup ( const char ident)

Definition at line 124 of file wpp.c.

125{
126 int idx;
127 pp_entry_t *ppp;
128
129 if(!ident)
130 return NULL;
131 idx = pphash(ident);
133 {
134 if(!strcmp(ident, ppp->ident))
135 return ppp;
136 }
137 return NULL;
138}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
_In_ ULONG _In_ ULONG_PTR ident
Definition: winddi.h:3994

Referenced by pp_add_define(), pp_add_macro(), and pp_del_define().

◆ ppy_error()

int ppy_error ( const char s,
  ... 
)

Definition at line 499 of file wpp.c.

500{
501 va_list ap;
502 va_start(ap, s);
503 generic_msg(s, "error", ppy_text, ap);
504 va_end(ap);
505 exit(1);
506}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
char * ppy_text
#define exit(n)
Definition: config.h:202
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
Definition: wpp.c:491

Referenced by pp_pop_if(), and wpp_parse().

◆ ppy_warning()

int ppy_warning ( const char s,
  ... 
)

Definition at line 508 of file wpp.c.

509{
510 va_list ap;
511 va_start(ap, s);
512 generic_msg(s, "warning", ppy_text, ap);
513 va_end(ap);
514 return 0;
515}

Referenced by pp_add_define(), pp_add_macro(), and pp_del_define().

◆ wpp_add_cmdline_define()

void wpp_add_cmdline_define ( const char value)

Definition at line 588 of file wpp.c.

589{
590 char *p;
591 char *str = xstrdup(value);
592
593 p = strchr( str, '=' );
594 if (p) *p++ = 0;
595 wpp_add_define( str, p );
596 free( str );
597}
GLfloat GLfloat p
Definition: glext.h:8902
Definition: pdh_main.c:96
static void wpp_add_define(const char *name, const char *value)
Definition: wpp.c:547

Referenced by add_widl_version_define(), main(), and option_callback().

◆ wpp_add_define()

static void wpp_add_define ( const char name,
const char value 
)
static

Definition at line 547 of file wpp.c.

548{
549 struct define *def;
550
551 if (!value) value = "";
552
554 {
555 if (!strcmp( def->name, name ))
556 {
557 free( def->value );
558 def->value = xstrdup(value);
559 return;
560 }
561 }
562
563 def = xmalloc( sizeof(*def) );
564 def->name = xstrdup(name);
565 def->value = xstrdup(value);
567}
struct list entry
Definition: wpp.c:51

Referenced by wpp_add_cmdline_define().

◆ wpp_add_include_path()

void wpp_add_include_path ( const char path)

Definition at line 298 of file wpp.c.

299{
300 char *dir = xstrdup(path);
301 char *cptr;
302
303 for(cptr = dir; *cptr; cptr++)
304 {
305 /* Convert to forward slash */
306 if(*cptr == '\\')
307 *cptr = '/';
308 }
309 /* Kill eventual trailing '/' */
310 if(*(cptr = dir + strlen(dir)-1) == '/') *cptr = '\0';
311
313}
unsigned int dir
Definition: maze.c:112
static void strarray_add(struct strarray *array, const char *str)
Definition: tools.h:183
static struct strarray includes
Definition: wpp.c:57

Referenced by main(), and option_callback().

◆ wpp_del_define()

void wpp_del_define ( const char name)

Definition at line 571 of file wpp.c.

572{
573 struct define *def;
574
576 {
577 if (!strcmp( def->name, name ))
578 {
579 free( def->value );
580 def->value = NULL;
581 return;
582 }
583 }
584}

◆ wpp_find_include()

char * wpp_find_include ( const char name,
const char parent_name 
)

Definition at line 315 of file wpp.c.

316{
317 return wpp_lookup(name, !!parent_name, parent_name);
318}

Referenced by find_input_file().

◆ wpp_lookup()

static char * wpp_lookup ( const char name,
int  type,
const char parent_name 
)
static

Definition at line 59 of file wpp.c.

60{
61 char *cpy;
62 char *cptr;
63 char *path;
64 const char *ccptr;
65 int i, fd;
66
67 cpy = xmalloc(strlen(name)+1);
68 cptr = cpy;
69
70 for(ccptr = name; *ccptr; ccptr++)
71 {
72 /* Convert to forward slash */
73 if(*ccptr == '\\') {
74 /* kill double backslash */
75 if(ccptr[1] == '\\')
76 ccptr++;
77 *cptr = '/';
78 }else {
79 *cptr = *ccptr;
80 }
81 cptr++;
82 }
83 *cptr = '\0';
84
85 if(type && parent_name)
86 {
87 /* Search directory of parent include and then -I path */
88 path = strmake( "%s/%s", get_dirname(parent_name), cpy );
89 fd = open( path, O_RDONLY );
90 if (fd != -1)
91 {
92 close( fd );
93 free( cpy );
94 return path;
95 }
96 free( path );
97 }
98 /* Search -I path */
99 for(i = 0; i < includes.count; i++)
100 {
101 path = strmake("%s/%s", includes.str[i], cpy);
102 fd = open( path, O_RDONLY );
103 if (fd != -1)
104 {
105 close( fd );
106 free( cpy );
107 return path;
108 }
109 free( path );
110 }
111 free( cpy );
112 return NULL;
113}
#define O_RDONLY
Definition: acwin.h:108
#define open
Definition: acwin.h:95
#define close
Definition: acwin.h:98
char * strmake(size_t *lenp,...)
Definition: util.c:82
static int fd
Definition: io.c:51
static char * get_dirname(const char *file)
Definition: tools.h:320

Referenced by pp_open_include(), and wpp_find_include().

◆ wpp_parse()

int wpp_parse ( const char input,
FILE output 
)

Definition at line 610 of file wpp.c.

611{
612 int ret;
613
617
621
622 if (!input) pp_status.file = stdin;
623 else if (!(pp_status.file = fopen(input, "rt")))
624 ppy_error("Could not open %s\n", input);
625
627
628 ppy_out = output;
629 fprintf(ppy_out, "# 1 \"%s\" 1\n", input ? input : "");
630
631 ret = ppy_parse();
632
633 if (input)
634 {
637 }
638 /* Clean if_stack, it could remain dirty on errors */
639 while (pp_get_if_depth()) pp_pop_if();
641 return ret;
642}
void WINAPIV int ppy_parse(void)
FILE * ppy_out
return ret
Definition: mutex.c:146
GLenum GLenum GLenum input
Definition: glext.h:9031
#define stdin
Definition: stdio.h:98
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
void * file
Definition: wpp_private.h:221
static void add_special_defines(void)
Definition: wpp.c:527
int pp_get_if_depth(void)
Definition: wpp.c:486
static void pp_free_define_state(void)
Definition: wpp.c:161
static void pp_init_define_state(void)
Definition: wpp.c:153
pp_if_state_t pp_pop_if(void)
Definition: wpp.c:423
static void add_cmdline_defines(void)
Definition: wpp.c:517

◆ wpp_set_debug()

void wpp_set_debug ( int  lex_debug,
int  parser_debug,
int  msg_debug 
)

Definition at line 601 of file wpp.c.

602{
603 pp_flex_debug = lex_debug;
605 pp_status.debug = msg_debug;
606}
int parser_debug
Definition: widl.c:95
int ppy_debug
Definition: wpp.c:47

Referenced by main().

Variable Documentation

◆ cmdline_defines

struct list cmdline_defines = LIST_INIT( cmdline_defines )
static

Definition at line 56 of file wpp.c.

Referenced by add_cmdline_defines(), wpp_add_define(), and wpp_del_define().

◆ if_stack

pp_if_state_t if_stack[MAXIFSTACK]
static

Definition at line 44 of file wpp.c.

Referenced by pp_if_state(), pp_pop_if(), and pp_push_if().

◆ if_stack_idx

int if_stack_idx = 0
static

Definition at line 45 of file wpp.c.

Referenced by pp_get_if_depth(), pp_if_state(), pp_pop_if(), and pp_push_if().

◆ includes

struct strarray includes
static

Definition at line 57 of file wpp.c.

Referenced by wpp_add_include_path(), and wpp_lookup().

◆ pp_defines

struct list pp_defines[HASHKEY]
static

◆ pp_flex_debug

int pp_flex_debug

Definition at line 47 of file wpp.c.

Referenced by pp_pop_if(), pp_push_if(), and wpp_set_debug().

◆ pp_if_state_str

const char* const pp_if_state_str[]
static
Initial value:
= {
"if_false",
"if_true",
"if_elif",
"if_elsefalse",
"if_elsetrue",
"if_ignore"
}

Definition at line 388 of file wpp.c.

Referenced by pp_pop_if(), and pp_push_if().

◆ pp_status

Definition at line 37 of file wpp.c.

◆ ppy_debug

int ppy_debug

Definition at line 47 of file wpp.c.

Referenced by wpp_set_debug().