ReactOS 0.4.15-dev-8417-gb6b82fe
preproc.c File Reference
#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>
#include "wine/wpp.h"
#include "wpp_private.h"
Include dependency graph for preproc.c:

Go to the source code of this file.

Classes

struct  pp_def_state
 

Macros

#define HASHKEY   2039
 
#define MAXIFSTACK   64
 
#define INCLUDESEPARATOR   ":"
 

Typedefs

typedef struct pp_def_state pp_def_state_t
 

Functions

voidpp_xmalloc (size_t size)
 
voidpp_xrealloc (void *p, size_t size)
 
charpp_xstrdup (const char *str)
 
static charwpp_default_lookup (const char *name, int type, const char *parent_name, char **include_path, int include_path_count)
 
static voidwpp_default_open (const char *filename, int type)
 
static void wpp_default_close (void *file)
 
static int wpp_default_read (void *file, char *buffer, unsigned int len)
 
static void wpp_default_write (const char *buffer, unsigned int len)
 
static int pphash (const char *str)
 
pp_entry_tpplookup (const char *ident)
 
static void free_pp_entry (pp_entry_t *ppp, int idx)
 
int pp_push_define_state (void)
 
void pp_pop_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, marg_t *args[], int nargs, mtext_t *exp)
 
int 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)
 
static void wpp_default_error (const char *file, int line, int col, const char *near, const char *msg, va_list ap)
 
static void wpp_default_warning (const char *file, int line, int col, const char *near, const char *msg, va_list ap)
 
int ppy_error (const char *s,...)
 
int ppy_warning (const char *s,...)
 
void pp_internal_error (const char *file, int line, const char *s,...)
 

Variables

struct pp_status pp_status
 
static pp_def_state_tpp_def_state
 
static pp_if_state_t if_stack [MAXIFSTACK]
 
static int if_stack_idx = 0
 
static char ** includepath
 
static int nincludepath = 0
 
static const char *const pp_if_state_str []
 
static const struct wpp_callbacks default_callbacks
 
const struct wpp_callbackswpp_callbacks = &default_callbacks
 

Macro Definition Documentation

◆ HASHKEY

#define HASHKEY   2039

Definition at line 41 of file preproc.c.

◆ INCLUDESEPARATOR

#define INCLUDESEPARATOR   ":"

Definition at line 454 of file preproc.c.

◆ MAXIFSTACK

#define MAXIFSTACK   64

Definition at line 51 of file preproc.c.

Typedef Documentation

◆ pp_def_state_t

Function Documentation

◆ free_pp_entry()

static void free_pp_entry ( pp_entry_t ppp,
int  idx 
)
static

Definition at line 237 of file preproc.c.

238{
239 if(ppp->iep)
240 {
241 if(ppp->iep == pp_includelogiclist)
242 {
246 }
247 else
248 {
249 ppp->iep->prev->next = ppp->iep->next;
250 if(ppp->iep->next)
251 ppp->iep->next->prev = ppp->iep->prev;
252 }
253 free(ppp->iep->filename);
254 free(ppp->iep);
255 }
256
257 if(pp_def_state->defines[idx] == ppp)
258 {
259 pp_def_state->defines[idx] = ppp->next;
262 }
263 else
264 {
265 ppp->prev->next = ppp->next;
266 if(ppp->next)
267 ppp->next->prev = ppp->prev;
268 }
269
270 free(ppp);
271}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
includelogicentry_t * pp_includelogiclist
unsigned int idx
Definition: utils.c:41
struct includelogicentry * next
Definition: wpp_private.h:45
struct includelogicentry * prev
Definition: wpp_private.h:46
pp_entry_t * defines[HASHKEY]
Definition: preproc.c:36
struct pp_entry * next
Definition: wpp_private.h:96
includelogicentry_t * iep
Definition: wpp_private.h:109
struct pp_entry * prev
Definition: wpp_private.h:97

◆ generic_msg()

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

Definition at line 688 of file preproc.c.

689{
690 fprintf(stderr, "%s:%d:%d: %s: ", pp_status.input ? pp_status.input : "stdin",
692 vfprintf(stderr, s, ap);
693#ifdef WANT_NEAR_INDICATION
694 {
695 char *cpy, *p;
696 if(n)
697 {
698 cpy = pp_xstrdup(n);
699 if(!cpy)
700 goto end;
701 for (p = cpy; *p; p++) if(!isprint(*p)) *p = ' ';
702 fprintf(stderr, " near '%s'", cpy);
703 free(cpy);
704 }
705 }
706end:
707#endif
708 fprintf(stderr, "\n");
709}
#define isprint(c)
Definition: acclib.h:73
char * pp_xstrdup(const char *str)
Definition: preproc.c:73
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
GLdouble GLdouble t
Definition: gl.h:2047
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
#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 wpp_default_error(), and wpp_default_warning().

◆ pp_add_define()

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

Definition at line 323 of file preproc.c.

324{
325 int len;
326 char *cptr;
327 int idx;
328 pp_entry_t *ppp;
329
330 if(!def)
331 return NULL;
332 idx = pphash(def);
333 if((ppp = pplookup(def)) != NULL)
334 {
336 ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
337 pp_del_define(def);
338 }
339 ppp = pp_xmalloc(sizeof(pp_entry_t));
340 if(!ppp)
341 return NULL;
342 memset( ppp, 0, sizeof(*ppp) );
343 ppp->ident = pp_xstrdup(def);
344 if(!ppp->ident)
345 goto error;
346 ppp->type = def_define;
347 ppp->subst.text = text ? pp_xstrdup(text) : NULL;
348 if(text && !ppp->subst.text)
349 goto error;
350 ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
351 if(!ppp->filename)
352 goto error;
354 ppp->next = pp_def_state->defines[idx];
355 pp_def_state->defines[idx] = ppp;
356 if(ppp->next)
357 ppp->next->prev = ppp;
358 if(ppp->subst.text)
359 {
360 /* Strip trailing white space from subst text */
361 len = strlen(ppp->subst.text);
362 while(len && strchr(" \t\r\n", ppp->subst.text[len-1]))
363 {
364 ppp->subst.text[--len] = '\0';
365 }
366 /* Strip leading white space from subst text */
367 for(cptr = ppp->subst.text; *cptr && strchr(" \t\r", *cptr); cptr++)
368 ;
369 if(ppp->subst.text != cptr)
370 memmove(ppp->subst.text, cptr, strlen(cptr)+1);
371 }
372 if(pp_status.debug)
373 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)");
374
375 return ppp;
376
377error:
378 free(ppp->ident);
379 free(ppp->subst.text);
380 free(ppp);
381 return NULL;
382}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
int WINAPIV ppy_warning(const char *msg,...)
Definition: compiler.c:149
void * pp_xmalloc(size_t size)
Definition: preproc.c:45
static int pphash(const char *str)
Definition: preproc.c:87
pp_entry_t * pplookup(const char *ident)
Definition: preproc.c:95
void pp_del_define(const char *name)
Definition: preproc.c:176
@ def_define
Definition: wpp_private.h:90
const WCHAR * text
Definition: package.c:1799
#define printf
Definition: freeldr.h:97
GLenum GLsizei len
Definition: glext.h:6722
#define error(str)
Definition: mkdosfs.c:1605
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define memset(x, y, z)
Definition: compat.h:39
Definition: wpp_private.h:95
int linenumber
Definition: wpp_private.h:108
char * text
Definition: wpp_private.h:104
union pp_entry::@240 subst
char * filename
Definition: wpp_private.h:107
def_type_t type
Definition: wpp_private.h:98
char * ident
Definition: wpp_private.h:99
int pedantic
Definition: wpp_private.h:225

◆ pp_add_macro()

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

Definition at line 384 of file preproc.c.

385{
386 int idx;
387 pp_entry_t *ppp;
388
389 if(!id)
390 return NULL;
391 idx = pphash(id);
392 if((ppp = pplookup(id)) != NULL)
393 {
395 ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
396 pp_del_define(id);
397 }
398 ppp = pp_xmalloc(sizeof(pp_entry_t));
399 if(!ppp)
400 return NULL;
401 memset( ppp, 0, sizeof(*ppp) );
402 ppp->ident = id;
403 ppp->type = def_macro;
404 ppp->margs = args;
405 ppp->nargs = nargs;
406 ppp->subst.mtext= exp;
407 ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
408 if(!ppp->filename)
409 {
410 free(ppp);
411 return NULL;
412 }
414 ppp->next = pp_def_state->defines[idx];
415 pp_def_state->defines[idx] = ppp;
416 if(ppp->next)
417 ppp->next->prev = ppp;
418
419 if(pp_status.debug)
420 {
421 fprintf(stderr, "Added macro (%s, %d) <%s(%d)> to <", pp_status.input, pp_status.line_number, ppp->ident, nargs);
422 for(; exp; exp = exp->next)
423 {
424 switch(exp->type)
425 {
426 case exp_text:
427 fprintf(stderr, " \"%s\" ", exp->subst.text);
428 break;
429 case exp_stringize:
430 fprintf(stderr, " #(%d) ", exp->subst.argidx);
431 break;
432 case exp_concat:
433 fprintf(stderr, "##");
434 break;
435 case exp_subst:
436 fprintf(stderr, " <%d> ", exp->subst.argidx);
437 break;
438 }
439 }
440 fprintf(stderr, ">\n");
441 }
442 return ppp;
443}
@ 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
mtext_t * mtext
Definition: wpp_private.h:103
marg_t ** margs
Definition: wpp_private.h:100
int nargs
Definition: wpp_private.h:101

◆ pp_del_define()

void pp_del_define ( const char name)

Definition at line 302 of file preproc.c.

303{
304 pp_entry_t *ppp;
305 int idx = pphash(name);
306
307 if((ppp = pplookup(name)) == NULL)
308 {
310 ppy_warning("%s was not defined", name);
311 return;
312 }
313
314 if(pp_status.debug)
315 printf("Deleting (%s, %d) <%s>\n", pp_status.input, pp_status.line_number, name);
316
317 free( ppp->ident );
318 free( ppp->subst.text );
319 free( ppp->filename );
320 free_pp_entry( ppp, idx );
321}
static void free_pp_entry(pp_entry_t *ppp, int idx)
Definition: preproc.c:111
Definition: name.c:39

◆ pp_get_if_depth()

int pp_get_if_depth ( void  )

Definition at line 681 of file preproc.c.

682{
683 return if_stack_idx;
684}
static int if_stack_idx
Definition: preproc.c:43

◆ pp_if_state()

pp_if_state_t pp_if_state ( void  )

Definition at line 653 of file preproc.c.

654{
655 if(!if_stack_idx)
656 return if_true;
657 else
658 return if_stack[if_stack_idx-1];
659}
static pp_if_state_t if_stack[MAXIFSTACK]
Definition: preproc.c:42
@ if_true
Definition: wpp_private.h:120

◆ pp_internal_error()

void pp_internal_error ( const char file,
int  line,
const char s,
  ... 
)

Definition at line 754 of file preproc.c.

755{
756 va_list ap;
757 va_start(ap, s);
758 fprintf(stderr, "Internal error (please report) %s %d: ", file, line);
759 vfprintf(stderr, s, ap);
760 fprintf(stderr, "\n");
761 va_end(ap);
762 exit(3);
763}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define exit(n)
Definition: config.h:202
Definition: fci.c:127
Definition: parser.c:49

◆ pp_next_if_state()

void pp_next_if_state ( int  i)

Definition at line 662 of file preproc.c.

663{
664 switch(pp_if_state())
665 {
666 case if_true:
667 case if_elsetrue:
669 break;
670 case if_false:
671 case if_elsefalse:
672 case if_elif:
673 case if_ignore:
675 break;
676 default:
677 pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #{if,ifdef,ifndef} directive", (int)pp_if_state());
678 }
679}
pp_if_state_t pp_if_state(void)
Definition: preproc.c:405
void pp_push_if(pp_if_state_t s)
Definition: preproc.c:357
void WINAPIV pp_internal_error(const char *file, int line, const char *s,...)
Definition: preproc.c:438
@ if_elif
Definition: wpp_private.h:121
@ if_elsefalse
Definition: wpp_private.h:122
@ if_elsetrue
Definition: wpp_private.h:123
@ if_false
Definition: wpp_private.h:119
@ if_ignore
Definition: wpp_private.h:124
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

◆ pp_open_include()

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

Definition at line 514 of file preproc.c.

515{
516 char *path;
517 void *fp;
518
519 if (!(path = wpp_callbacks->lookup(name, type, parent_name, includepath,
520 nincludepath))) return NULL;
521 fp = wpp_callbacks->open(path, type);
522
523 if (fp)
524 {
525 if (pp_status.debug)
526 printf("Going to include <%s>\n", path);
527 if (newpath) *newpath = path;
528 else free( path );
529 return fp;
530 }
531 free( path );
532 return NULL;
533}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static int nincludepath
Definition: preproc.c:458
static char ** includepath
Definition: preproc.c:457
void *(* open)(const char *filename, int type)
Definition: wpp.h:38
char *(* lookup)(const char *filename, int type, const char *parent_name, char **include_path, int include_path_count)
Definition: wpp.h:35

◆ pp_pop_define_state()

void pp_pop_define_state ( void  )

Definition at line 287 of file preproc.c.

288{
289 int i;
290 pp_entry_t *ppp;
292
293 for (i = 0; i < HASHKEY; i++)
294 {
295 while ((ppp = pp_def_state->defines[i]) != NULL) pp_del_define( ppp->ident );
296 }
298 pp_def_state = state->next;
299 free( state );
300}
static int state
Definition: maze.c:121
static pp_def_state_t * pp_def_state
Definition: preproc.c:39
#define HASHKEY
Definition: preproc.c:31

◆ pp_pop_if()

pp_if_state_t pp_pop_if ( void  )

Definition at line 618 of file preproc.c.

619{
620 if(if_stack_idx <= 0)
621 {
622 ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
623 return if_error;
624 }
625
626 switch(pp_if_state())
627 {
628 case if_true:
629 case if_elsetrue:
630 break;
631 case if_false:
632 case if_elsefalse:
633 case if_elif:
634 case if_ignore:
636 break;
637 default:
638 pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
639 }
640
641 if(pp_flex_debug)
642 fprintf(stderr, "Pop if %s:%d: %s(%d) -> %s(%d)\n",
648 if_stack_idx-1);
649
650 return if_stack[--if_stack_idx];
651}
int WINAPIV ppy_error(const char *msg,...)
Definition: compiler.c:135
@ if_error
Definition: wpp_private.h:125
void pp_pop_ignore_state(void)
static const char *const pp_if_state_str[]
Definition: preproc.c:583
int pp_flex_debug
Definition: wpp.c:31

◆ pp_push_define_state()

int pp_push_define_state ( void  )

Definition at line 274 of file preproc.c.

275{
276 pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
277 if(!state)
278 return 1;
279
280 memset( state->defines, 0, sizeof(state->defines) );
281 state->next = pp_def_state;
283 return 0;
284}

◆ pp_push_if()

void pp_push_if ( pp_if_state_t  s)

Definition at line 592 of file preproc.c.

593{
595 pp_internal_error(__FILE__, __LINE__, "#if-stack overflow; #{if,ifdef,ifndef} nested too deeply (> %d)", MAXIFSTACK);
596
597 if(pp_flex_debug)
599
601
602 switch(s)
603 {
604 case if_true:
605 case if_elsetrue:
606 break;
607 case if_false:
608 case if_elsefalse:
609 case if_elif:
610 case if_ignore:
612 break;
613 default:
614 pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
615 }
616}
#define MAXIFSTACK
Definition: preproc.c:41
void pp_push_ignore_state(void)

◆ pp_xmalloc()

void * pp_xmalloc ( size_t  size)

Definition at line 77 of file preproc.c.

78{
79 void *res;
80
81 assert(size > 0);
82 res = malloc(size);
83 if(res == NULL)
84 {
85 /* Set the error flag */
86 pp_status.state = 1;
87 }
88 return res;
89}
#define malloc
Definition: debug_ros.c:4
#define assert(x)
Definition: debug.h:53
GLsizeiptr size
Definition: glext.h:5919
GLuint res
Definition: glext.h:9613

◆ pp_xrealloc()

void * pp_xrealloc ( void p,
size_t  size 
)

Definition at line 91 of file preproc.c.

92{
93 void *res;
94
95 assert(size > 0);
96 res = realloc(p, size);
97 if(res == NULL)
98 {
99 /* Set the error flag */
100 pp_status.state = 1;
101 }
102 return res;
103}
#define realloc
Definition: debug_ros.c:6

◆ pp_xstrdup()

char * pp_xstrdup ( const char str)

Definition at line 105 of file preproc.c.

106{
107 char *s;
108 int len;
109
110 assert(str != NULL);
111 len = strlen(str)+1;
112 s = pp_xmalloc(len);
113 if(!s)
114 return NULL;
115 return memcpy(s, str, len);
116}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const WCHAR * str

◆ pphash()

static int pphash ( const char str)
static

Definition at line 213 of file preproc.c.

214{
215 int sum = 0;
216 while(*str)
217 sum += *str++;
218 return sum % HASHKEY;
219}
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35

◆ pplookup()

pp_entry_t * pplookup ( const char ident)

Definition at line 221 of file preproc.c.

222{
223 int idx;
224 pp_entry_t *ppp;
225
226 if(!ident)
227 return NULL;
228 idx = pphash(ident);
229 for(ppp = pp_def_state->defines[idx]; ppp; ppp = ppp->next)
230 {
231 if(!strcmp(ident, ppp->ident))
232 return ppp;
233 }
234 return NULL;
235}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
_In_ ULONG _In_ ULONG_PTR ident
Definition: winddi.h:3994

◆ ppy_error()

int ppy_error ( const char s,
  ... 
)

Definition at line 735 of file preproc.c.

736{
737 va_list ap;
738 va_start(ap, s);
740 va_end(ap);
741 pp_status.state = 1;
742 return 1;
743}
char * ppy_text
void(* error)(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
Definition: wpp.h:47

◆ ppy_warning()

int ppy_warning ( const char s,
  ... 
)

Definition at line 745 of file preproc.c.

746{
747 va_list ap;
748 va_start(ap, s);
750 va_end(ap);
751 return 0;
752}
void(* warning)(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
Definition: wpp.h:48

◆ wpp_add_include_path()

int wpp_add_include_path ( const char path)

Definition at line 460 of file preproc.c.

461{
462 char *tok;
463 char *cpy = pp_xstrdup(path);
464 if(!cpy)
465 return 1;
466
467 tok = strtok(cpy, INCLUDESEPARATOR);
468 while(tok)
469 {
470 if(*tok) {
471 char *dir;
472 char *cptr;
473 char **new_path;
474
475 dir = pp_xstrdup(tok);
476 if(!dir)
477 {
478 free(cpy);
479 return 1;
480 }
481 for(cptr = dir; *cptr; cptr++)
482 {
483 /* Convert to forward slash */
484 if(*cptr == '\\')
485 *cptr = '/';
486 }
487 /* Kill eventual trailing '/' */
488 if(*(cptr = dir + strlen(dir)-1) == '/')
489 *cptr = '\0';
490
491 /* Add to list */
492 new_path = pp_xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
493 if(!new_path)
494 {
495 free(dir);
496 free(cpy);
497 return 1;
498 }
499 includepath = new_path;
501 nincludepath++;
502 }
504 }
505 free(cpy);
506 return 0;
507}
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
unsigned int dir
Definition: maze.c:112
#define INCLUDESEPARATOR
Definition: preproc.c:454
void * pp_xrealloc(void *p, size_t size)
Definition: preproc.c:91

Referenced by main().

◆ wpp_default_close()

static void wpp_default_close ( void file)
static

Definition at line 200 of file preproc.c.

200 {
201 fclose(file);
202}
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

◆ wpp_default_error()

static void wpp_default_error ( const char file,
int  line,
int  col,
const char near,
const char msg,
va_list  ap 
)
static

Definition at line 711 of file preproc.c.

712{
713 generic_msg(msg, "Error", near, ap);
714 exit(1);
715}
#define msg(x)
Definition: auth_time.c:54
static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
Definition: preproc.c:688
#define near
Definition: windef.h:115

◆ wpp_default_lookup()

static char * wpp_default_lookup ( const char name,
int  type,
const char parent_name,
char **  include_path,
int  include_path_count 
)
static

Definition at line 118 of file preproc.c.

120{
121 char *cpy;
122 char *cptr;
123 char *path;
124 const char *ccptr;
125 int i, fd;
126
127 cpy = pp_xmalloc(strlen(name)+1);
128 if(!cpy)
129 return NULL;
130 cptr = cpy;
131
132 for(ccptr = name; *ccptr; ccptr++)
133 {
134 /* Convert to forward slash */
135 if(*ccptr == '\\') {
136 /* kill double backslash */
137 if(ccptr[1] == '\\')
138 ccptr++;
139 *cptr = '/';
140 }else {
141 *cptr = *ccptr;
142 }
143 cptr++;
144 }
145 *cptr = '\0';
146
147 if(type && parent_name)
148 {
149 /* Search directory of parent include and then -I path */
150 const char *p;
151
152 if ((p = strrchr( parent_name, '/' ))) p++;
153 else p = parent_name;
154 path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
155 if(!path)
156 {
157 free(cpy);
158 return NULL;
159 }
160 memcpy( path, parent_name, p - parent_name );
161 strcpy( path + (p - parent_name), cpy );
162 fd = open( path, O_RDONLY );
163 if (fd != -1)
164 {
165 close( fd );
166 free( cpy );
167 return path;
168 }
169 free( path );
170 }
171 /* Search -I path */
172 for(i = 0; i < include_path_count; i++)
173 {
174 path = pp_xmalloc(strlen(include_path[i]) + strlen(cpy) + 2);
175 if(!path)
176 {
177 free(cpy);
178 return NULL;
179 }
180 strcpy(path, include_path[i]);
181 strcat(path, "/");
182 strcat(path, cpy);
183 fd = open( path, O_RDONLY );
184 if (fd != -1)
185 {
186 close( fd );
187 free( cpy );
188 return path;
189 }
190 free( path );
191 }
192 free( cpy );
193 return NULL;
194}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define O_RDONLY
Definition: acwin.h:108
#define open
Definition: acwin.h:95
#define close
Definition: acwin.h:98
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static int fd
Definition: io.c:51

Referenced by wpp_find_include().

◆ wpp_default_open()

static void * wpp_default_open ( const char filename,
int  type 
)
static

Definition at line 196 of file preproc.c.

196 {
197 return fopen(filename,"rt");
198}
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
const char * filename
Definition: ioapi.h:137

◆ wpp_default_read()

static int wpp_default_read ( void file,
char buffer,
unsigned int  len 
)
static

Definition at line 204 of file preproc.c.

204 {
205 return fread(buffer, 1, len, file);
206}
GLuint buffer
Definition: glext.h:5915
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)

◆ wpp_default_warning()

static void wpp_default_warning ( const char file,
int  line,
int  col,
const char near,
const char msg,
va_list  ap 
)
static

Definition at line 717 of file preproc.c.

718{
719 generic_msg(msg, "Warning", near, ap);
720}

◆ wpp_default_write()

static void wpp_default_write ( const char buffer,
unsigned int  len 
)
static

Definition at line 208 of file preproc.c.

208 {
209 fwrite(buffer, 1, len, ppy_out);
210}
FILE * ppy_out
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)

◆ wpp_find_include()

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

Definition at line 509 of file preproc.c.

510{
511 return wpp_default_lookup(name, !!parent_name, parent_name, includepath, nincludepath);
512}
static char * wpp_default_lookup(const char *name, int type, const char *parent_name, char **include_path, int include_path_count)
Definition: preproc.c:118

Referenced by open_typelib().

Variable Documentation

◆ default_callbacks

const struct wpp_callbacks default_callbacks
static
Initial value:
=
{
}
static void wpp_default_error(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
Definition: preproc.c:711
static void * wpp_default_open(const char *filename, int type)
Definition: preproc.c:196
static void wpp_default_write(const char *buffer, unsigned int len)
Definition: preproc.c:208
static void wpp_default_warning(const char *file, int line, int col, const char *near, const char *msg, va_list ap)
Definition: preproc.c:717
static int wpp_default_read(void *file, char *buffer, unsigned int len)
Definition: preproc.c:204
static void wpp_default_close(void *file)
Definition: preproc.c:200

Definition at line 722 of file preproc.c.

◆ if_stack

pp_if_state_t if_stack[MAXIFSTACK]
static

Definition at line 52 of file preproc.c.

◆ if_stack_idx

int if_stack_idx = 0
static

Definition at line 53 of file preproc.c.

◆ includepath

char** includepath
static

Definition at line 457 of file preproc.c.

Referenced by pp_open_include(), wpp_add_include_path(), and wpp_find_include().

◆ nincludepath

int nincludepath = 0
static

Definition at line 458 of file preproc.c.

Referenced by pp_open_include(), wpp_add_include_path(), and wpp_find_include().

◆ pp_def_state

Definition at line 49 of file preproc.c.

◆ 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 583 of file preproc.c.

Referenced by pp_pop_if(), and pp_push_if().

◆ pp_status

Definition at line 39 of file preproc.c.

◆ wpp_callbacks