mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-06 17:14:06 +00:00
wpp: Don't try to recover from memory allocation errors.
wpp is only used in short-lived tools. Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
d3a4477bad
commit
de2f4ceeb8
|
@ -24,14 +24,14 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
/* Return value == 0 means successful execution */
|
extern void wpp_add_define( const char *name, const char *value );
|
||||||
extern int wpp_add_define( const char *name, const char *value );
|
|
||||||
extern void wpp_del_define( const char *name );
|
extern void wpp_del_define( const char *name );
|
||||||
extern int wpp_add_cmdline_define( 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_debug( int lex_debug, int parser_debug, int msg_debug );
|
||||||
extern void wpp_set_pedantic( int on );
|
extern void wpp_set_pedantic( int on );
|
||||||
extern int wpp_add_include_path( const char *path );
|
extern void wpp_add_include_path( const char *path );
|
||||||
extern char *wpp_find_include( const char *name, const char *parent_name );
|
extern char *wpp_find_include( const char *name, const char *parent_name );
|
||||||
|
/* Return value == 0 means successful execution */
|
||||||
extern int wpp_parse( const char *input, FILE *output );
|
extern int wpp_parse( const char *input, FILE *output );
|
||||||
|
|
||||||
#endif /* __WINE_WPP_H */
|
#endif /* __WINE_WPP_H */
|
||||||
|
|
|
@ -322,8 +322,6 @@ void pp_writestring(const char *format, ...)
|
||||||
if(buffercapacity == 0)
|
if(buffercapacity == 0)
|
||||||
{
|
{
|
||||||
buffer = pp_xmalloc(BUFFERINITIALCAPACITY);
|
buffer = pp_xmalloc(BUFFERINITIALCAPACITY);
|
||||||
if(buffer == NULL)
|
|
||||||
return;
|
|
||||||
buffercapacity = BUFFERINITIALCAPACITY;
|
buffercapacity = BUFFERINITIALCAPACITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +496,7 @@ void pp_writestring(const char *format, ...)
|
||||||
/*
|
/*
|
||||||
* Handle left side of #define
|
* Handle left side of #define
|
||||||
*/
|
*/
|
||||||
<pp_def>{cident}\( ppy_lval.cptr = pp_xstrdup(ppy_text); if(ppy_lval.cptr) ppy_lval.cptr[ppy_leng-1] = '\0'; yy_pp_state(pp_macro); return tMACRO;
|
<pp_def>{cident}\( ppy_lval.cptr = pp_xstrdup(ppy_text); ppy_lval.cptr[ppy_leng-1] = '\0'; yy_pp_state(pp_macro); return tMACRO;
|
||||||
<pp_def>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); yy_pp_state(pp_define); return tDEFINE;
|
<pp_def>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); yy_pp_state(pp_define); return tDEFINE;
|
||||||
<pp_def>{ws}+ ;
|
<pp_def>{ws}+ ;
|
||||||
<pp_def>\\\r?\n newline(0);
|
<pp_def>\\\r?\n newline(0);
|
||||||
|
@ -1258,8 +1256,7 @@ static void add_string(const char *str, int len)
|
||||||
static char *get_string(void)
|
static char *get_string(void)
|
||||||
{
|
{
|
||||||
char *str = pp_xmalloc(strbuf_idx + 1);
|
char *str = pp_xmalloc(strbuf_idx + 1);
|
||||||
if(!str)
|
|
||||||
return NULL;
|
|
||||||
memcpy(str, strbuffer, strbuf_idx);
|
memcpy(str, strbuffer, strbuf_idx);
|
||||||
str[strbuf_idx] = '\0';
|
str[strbuf_idx] = '\0';
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -1350,8 +1347,6 @@ static bufferstackentry_t *pop_buffer(void)
|
||||||
if(ppp)
|
if(ppp)
|
||||||
{
|
{
|
||||||
iep = pp_xmalloc(sizeof(includelogicentry_t));
|
iep = pp_xmalloc(sizeof(includelogicentry_t));
|
||||||
if (iep)
|
|
||||||
{
|
|
||||||
iep->ppp = ppp;
|
iep->ppp = ppp;
|
||||||
ppp->iep = iep;
|
ppp->iep = iep;
|
||||||
iep->filename = bufferstack[bufferstackidx].include_filename;
|
iep->filename = bufferstack[bufferstackidx].include_filename;
|
||||||
|
@ -1365,7 +1360,6 @@ static bufferstackentry_t *pop_buffer(void)
|
||||||
bufferstack[bufferstackidx].filename, bufferstack[bufferstackidx].line_number, pp_incl_state.ppp, iep->filename);
|
bufferstack[bufferstackidx].filename, bufferstack[bufferstackidx].line_number, pp_incl_state.ppp, iep->filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(pp_incl_state.ppp);
|
free(pp_incl_state.ppp);
|
||||||
pp_incl_state = bufferstack[bufferstackidx].incl;
|
pp_incl_state = bufferstack[bufferstackidx].incl;
|
||||||
|
|
||||||
|
@ -1423,8 +1417,6 @@ static void push_macro(pp_entry_t *ppp)
|
||||||
}
|
}
|
||||||
|
|
||||||
macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
|
macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
|
||||||
if(!macexpstack[macexpstackidx])
|
|
||||||
return;
|
|
||||||
memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
|
memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
|
||||||
macexpstack[macexpstackidx]->ppp = ppp;
|
macexpstack[macexpstackidx]->ppp = ppp;
|
||||||
macexpstackidx++;
|
macexpstackidx++;
|
||||||
|
@ -1479,30 +1471,15 @@ static void macro_add_arg(int last)
|
||||||
{
|
{
|
||||||
int nnl = 0;
|
int nnl = 0;
|
||||||
char *cptr;
|
char *cptr;
|
||||||
char **new_args, **new_ppargs;
|
|
||||||
int *new_nnls;
|
|
||||||
macexpstackentry_t *mep = top_macro();
|
macexpstackentry_t *mep = top_macro();
|
||||||
|
|
||||||
assert(mep->ppp->expanding == 0);
|
assert(mep->ppp->expanding == 0);
|
||||||
|
|
||||||
new_args = pp_xrealloc(mep->args, (mep->nargs+1) * sizeof(mep->args[0]));
|
mep->args = pp_xrealloc(mep->args, (mep->nargs+1) * sizeof(mep->args[0]));
|
||||||
if(!new_args)
|
mep->ppargs = pp_xrealloc(mep->ppargs, (mep->nargs+1) * sizeof(mep->ppargs[0]));
|
||||||
return;
|
mep->nnls = pp_xrealloc(mep->nnls, (mep->nargs+1) * sizeof(mep->nnls[0]));
|
||||||
mep->args = new_args;
|
|
||||||
|
|
||||||
new_ppargs = pp_xrealloc(mep->ppargs, (mep->nargs+1) * sizeof(mep->ppargs[0]));
|
|
||||||
if(!new_ppargs)
|
|
||||||
return;
|
|
||||||
mep->ppargs = new_ppargs;
|
|
||||||
|
|
||||||
new_nnls = pp_xrealloc(mep->nnls, (mep->nargs+1) * sizeof(mep->nnls[0]));
|
|
||||||
if(!new_nnls)
|
|
||||||
return;
|
|
||||||
mep->nnls = new_nnls;
|
|
||||||
|
|
||||||
mep->args[mep->nargs] = pp_xstrdup(mep->curarg ? mep->curarg : "");
|
mep->args[mep->nargs] = pp_xstrdup(mep->curarg ? mep->curarg : "");
|
||||||
if(!mep->args[mep->nargs])
|
|
||||||
return;
|
|
||||||
cptr = mep->args[mep->nargs]-1;
|
cptr = mep->args[mep->nargs]-1;
|
||||||
while((cptr = strchr(cptr+1, '\n')))
|
while((cptr = strchr(cptr+1, '\n')))
|
||||||
{
|
{
|
||||||
|
|
|
@ -295,18 +295,12 @@ preprocessor
|
||||||
| tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
|
| tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
|
||||||
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
|
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
|
||||||
| tRCINCLUDE tRCINCLUDEPATH {
|
| tRCINCLUDE tRCINCLUDEPATH {
|
||||||
if($2)
|
|
||||||
{
|
|
||||||
int nl=strlen($2) +3;
|
int nl=strlen($2) +3;
|
||||||
char *fn=pp_xmalloc(nl);
|
char *fn=pp_xmalloc(nl);
|
||||||
if(fn)
|
|
||||||
{
|
|
||||||
sprintf(fn,"\"%s\"",$2);
|
sprintf(fn,"\"%s\"",$2);
|
||||||
pp_do_include(fn,1);
|
pp_do_include(fn,1);
|
||||||
}
|
|
||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
| tRCINCLUDE tDQSTRING {
|
| tRCINCLUDE tDQSTRING {
|
||||||
pp_do_include($2,1);
|
pp_do_include($2,1);
|
||||||
}
|
}
|
||||||
|
@ -552,8 +546,7 @@ static int boolean(cval_t *v)
|
||||||
static marg_t *new_marg(char *str, def_arg_t type)
|
static marg_t *new_marg(char *str, def_arg_t type)
|
||||||
{
|
{
|
||||||
marg_t *ma = pp_xmalloc(sizeof(marg_t));
|
marg_t *ma = pp_xmalloc(sizeof(marg_t));
|
||||||
if(!ma)
|
|
||||||
return NULL;
|
|
||||||
ma->arg = str;
|
ma->arg = str;
|
||||||
ma->type = type;
|
ma->type = type;
|
||||||
ma->nnl = 0;
|
ma->nnl = 0;
|
||||||
|
@ -562,17 +555,11 @@ static marg_t *new_marg(char *str, def_arg_t type)
|
||||||
|
|
||||||
static marg_t *add_new_marg(char *str, def_arg_t type)
|
static marg_t *add_new_marg(char *str, def_arg_t type)
|
||||||
{
|
{
|
||||||
marg_t **new_macro_args;
|
|
||||||
marg_t *ma;
|
marg_t *ma;
|
||||||
if(!str)
|
if(!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
new_macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
|
macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
|
||||||
if(!new_macro_args)
|
|
||||||
return NULL;
|
|
||||||
macro_args = new_macro_args;
|
|
||||||
ma = new_marg(str, type);
|
ma = new_marg(str, type);
|
||||||
if(!ma)
|
|
||||||
return NULL;
|
|
||||||
macro_args[nmacro_args] = ma;
|
macro_args[nmacro_args] = ma;
|
||||||
nmacro_args++;
|
nmacro_args++;
|
||||||
return ma;
|
return ma;
|
||||||
|
@ -594,8 +581,7 @@ static int marg_index(char *id)
|
||||||
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
|
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
|
||||||
{
|
{
|
||||||
mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
|
mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
|
||||||
if(!mt)
|
|
||||||
return NULL;
|
|
||||||
if(str == NULL)
|
if(str == NULL)
|
||||||
mt->subst.argidx = idx;
|
mt->subst.argidx = idx;
|
||||||
else
|
else
|
||||||
|
@ -615,11 +601,7 @@ static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
|
||||||
|
|
||||||
if(tail->type == exp_text && mtp->type == exp_text)
|
if(tail->type == exp_text && mtp->type == exp_text)
|
||||||
{
|
{
|
||||||
char *new_text;
|
tail->subst.text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
|
||||||
new_text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
|
|
||||||
if(!new_text)
|
|
||||||
return mtp;
|
|
||||||
tail->subst.text = new_text;
|
|
||||||
strcat(tail->subst.text, mtp->subst.text);
|
strcat(tail->subst.text, mtp->subst.text);
|
||||||
free(mtp->subst.text);
|
free(mtp->subst.text);
|
||||||
free(mtp);
|
free(mtp);
|
||||||
|
@ -683,22 +665,9 @@ static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
|
||||||
|
|
||||||
static char *merge_text(char *s1, char *s2)
|
static char *merge_text(char *s1, char *s2)
|
||||||
{
|
{
|
||||||
int l1;
|
int l1 = strlen(s1);
|
||||||
int l2;
|
int l2 = strlen(s2);
|
||||||
char *snew;
|
s1 = pp_xrealloc(s1, l1+l2+1);
|
||||||
if(!s1)
|
|
||||||
return s2;
|
|
||||||
if(!s2)
|
|
||||||
return s1;
|
|
||||||
l1 = strlen(s1);
|
|
||||||
l2 = strlen(s2);
|
|
||||||
snew = pp_xrealloc(s1, l1+l2+1);
|
|
||||||
if(!snew)
|
|
||||||
{
|
|
||||||
free(s2);
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
s1 = snew;
|
|
||||||
memcpy(s1+l1, s2, l2+1);
|
memcpy(s1+l1, s2, l2+1);
|
||||||
free(s2);
|
free(s2);
|
||||||
return s1;
|
return s1;
|
||||||
|
|
|
@ -79,8 +79,8 @@ void *pp_xmalloc(size_t size)
|
||||||
res = malloc(size);
|
res = malloc(size);
|
||||||
if(res == NULL)
|
if(res == NULL)
|
||||||
{
|
{
|
||||||
/* Set the error flag */
|
fprintf( stderr, "Virtual memory exhausted\n" );
|
||||||
pp_status.state = 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -93,23 +93,16 @@ void *pp_xrealloc(void *p, size_t size)
|
||||||
res = realloc(p, size);
|
res = realloc(p, size);
|
||||||
if(res == NULL)
|
if(res == NULL)
|
||||||
{
|
{
|
||||||
/* Set the error flag */
|
fprintf( stderr, "Virtual memory exhausted\n" );
|
||||||
pp_status.state = 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pp_xstrdup(const char *str)
|
char *pp_xstrdup(const char *str)
|
||||||
{
|
{
|
||||||
char *s;
|
int len = strlen(str)+1;
|
||||||
int len;
|
return memcpy(pp_xmalloc(len), str, len);
|
||||||
|
|
||||||
assert(str != NULL);
|
|
||||||
len = strlen(str)+1;
|
|
||||||
s = pp_xmalloc(len);
|
|
||||||
if(!s)
|
|
||||||
return NULL;
|
|
||||||
return memcpy(s, str, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wpp_lookup(const char *name, int type, const char *parent_name,
|
char *wpp_lookup(const char *name, int type, const char *parent_name,
|
||||||
|
@ -122,8 +115,6 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
|
||||||
int i, fd;
|
int i, fd;
|
||||||
|
|
||||||
cpy = pp_xmalloc(strlen(name)+1);
|
cpy = pp_xmalloc(strlen(name)+1);
|
||||||
if(!cpy)
|
|
||||||
return NULL;
|
|
||||||
cptr = cpy;
|
cptr = cpy;
|
||||||
|
|
||||||
for(ccptr = name; *ccptr; ccptr++)
|
for(ccptr = name; *ccptr; ccptr++)
|
||||||
|
@ -149,11 +140,6 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
|
||||||
if ((p = strrchr( parent_name, '/' ))) p++;
|
if ((p = strrchr( parent_name, '/' ))) p++;
|
||||||
else p = parent_name;
|
else p = parent_name;
|
||||||
path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
|
path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
|
||||||
if(!path)
|
|
||||||
{
|
|
||||||
free(cpy);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy( path, parent_name, p - parent_name );
|
memcpy( path, parent_name, p - parent_name );
|
||||||
strcpy( path + (p - parent_name), cpy );
|
strcpy( path + (p - parent_name), cpy );
|
||||||
fd = open( path, O_RDONLY );
|
fd = open( path, O_RDONLY );
|
||||||
|
@ -169,11 +155,6 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
|
||||||
for(i = 0; i < include_path_count; i++)
|
for(i = 0; i < include_path_count; i++)
|
||||||
{
|
{
|
||||||
path = pp_xmalloc(strlen(include_path[i]) + strlen(cpy) + 2);
|
path = pp_xmalloc(strlen(include_path[i]) + strlen(cpy) + 2);
|
||||||
if(!path)
|
|
||||||
{
|
|
||||||
free(cpy);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(path, include_path[i]);
|
strcpy(path, include_path[i]);
|
||||||
strcat(path, "/");
|
strcat(path, "/");
|
||||||
strcat(path, cpy);
|
strcat(path, cpy);
|
||||||
|
@ -252,16 +233,13 @@ static void free_pp_entry( pp_entry_t *ppp, int idx )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* push a new (empty) define state */
|
/* push a new (empty) define state */
|
||||||
int pp_push_define_state(void)
|
void pp_push_define_state(void)
|
||||||
{
|
{
|
||||||
pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
|
pp_def_state_t *state = pp_xmalloc( sizeof(*state) );
|
||||||
if(!state)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
memset( state->defines, 0, sizeof(state->defines) );
|
memset( state->defines, 0, sizeof(state->defines) );
|
||||||
state->next = pp_def_state;
|
state->next = pp_def_state;
|
||||||
pp_def_state = state;
|
pp_def_state = state;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pop the current define state */
|
/* pop the current define state */
|
||||||
|
@ -308,8 +286,6 @@ pp_entry_t *pp_add_define(const char *def, const char *text)
|
||||||
int idx;
|
int idx;
|
||||||
pp_entry_t *ppp;
|
pp_entry_t *ppp;
|
||||||
|
|
||||||
if(!def)
|
|
||||||
return NULL;
|
|
||||||
idx = pphash(def);
|
idx = pphash(def);
|
||||||
if((ppp = pplookup(def)) != NULL)
|
if((ppp = pplookup(def)) != NULL)
|
||||||
{
|
{
|
||||||
|
@ -318,19 +294,11 @@ pp_entry_t *pp_add_define(const char *def, const char *text)
|
||||||
pp_del_define(def);
|
pp_del_define(def);
|
||||||
}
|
}
|
||||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||||
if(!ppp)
|
|
||||||
return NULL;
|
|
||||||
memset( ppp, 0, sizeof(*ppp) );
|
memset( ppp, 0, sizeof(*ppp) );
|
||||||
ppp->ident = pp_xstrdup(def);
|
ppp->ident = pp_xstrdup(def);
|
||||||
if(!ppp->ident)
|
|
||||||
goto error;
|
|
||||||
ppp->type = def_define;
|
ppp->type = def_define;
|
||||||
ppp->subst.text = text ? pp_xstrdup(text) : NULL;
|
ppp->subst.text = text ? pp_xstrdup(text) : NULL;
|
||||||
if(text && !ppp->subst.text)
|
|
||||||
goto error;
|
|
||||||
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
||||||
if(!ppp->filename)
|
|
||||||
goto error;
|
|
||||||
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
||||||
ppp->next = pp_def_state->defines[idx];
|
ppp->next = pp_def_state->defines[idx];
|
||||||
pp_def_state->defines[idx] = ppp;
|
pp_def_state->defines[idx] = ppp;
|
||||||
|
@ -354,12 +322,6 @@ pp_entry_t *pp_add_define(const char *def, const char *text)
|
||||||
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)");
|
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)");
|
||||||
|
|
||||||
return ppp;
|
return ppp;
|
||||||
|
|
||||||
error:
|
|
||||||
free(ppp->ident);
|
|
||||||
free(ppp->subst.text);
|
|
||||||
free(ppp);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||||
|
@ -367,8 +329,6 @@ pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||||
int idx;
|
int idx;
|
||||||
pp_entry_t *ppp;
|
pp_entry_t *ppp;
|
||||||
|
|
||||||
if(!id)
|
|
||||||
return NULL;
|
|
||||||
idx = pphash(id);
|
idx = pphash(id);
|
||||||
if((ppp = pplookup(id)) != NULL)
|
if((ppp = pplookup(id)) != NULL)
|
||||||
{
|
{
|
||||||
|
@ -377,8 +337,6 @@ pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||||
pp_del_define(id);
|
pp_del_define(id);
|
||||||
}
|
}
|
||||||
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
ppp = pp_xmalloc(sizeof(pp_entry_t));
|
||||||
if(!ppp)
|
|
||||||
return NULL;
|
|
||||||
memset( ppp, 0, sizeof(*ppp) );
|
memset( ppp, 0, sizeof(*ppp) );
|
||||||
ppp->ident = id;
|
ppp->ident = id;
|
||||||
ppp->type = def_macro;
|
ppp->type = def_macro;
|
||||||
|
@ -386,11 +344,6 @@ pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||||
ppp->nargs = nargs;
|
ppp->nargs = nargs;
|
||||||
ppp->subst.mtext= exp;
|
ppp->subst.mtext= exp;
|
||||||
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
|
||||||
if(!ppp->filename)
|
|
||||||
{
|
|
||||||
free(ppp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
|
||||||
ppp->next = pp_def_state->defines[idx];
|
ppp->next = pp_def_state->defines[idx];
|
||||||
pp_def_state->defines[idx] = ppp;
|
pp_def_state->defines[idx] = ppp;
|
||||||
|
@ -438,12 +391,10 @@ pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp)
|
||||||
static char **includepath;
|
static char **includepath;
|
||||||
static int nincludepath = 0;
|
static int nincludepath = 0;
|
||||||
|
|
||||||
int wpp_add_include_path(const char *path)
|
void wpp_add_include_path(const char *path)
|
||||||
{
|
{
|
||||||
char *tok;
|
char *tok;
|
||||||
char *cpy = pp_xstrdup(path);
|
char *cpy = pp_xstrdup(path);
|
||||||
if(!cpy)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
tok = strtok(cpy, INCLUDESEPARATOR);
|
tok = strtok(cpy, INCLUDESEPARATOR);
|
||||||
while(tok)
|
while(tok)
|
||||||
|
@ -451,14 +402,8 @@ int wpp_add_include_path(const char *path)
|
||||||
if(*tok) {
|
if(*tok) {
|
||||||
char *dir;
|
char *dir;
|
||||||
char *cptr;
|
char *cptr;
|
||||||
char **new_path;
|
|
||||||
|
|
||||||
dir = pp_xstrdup(tok);
|
dir = pp_xstrdup(tok);
|
||||||
if(!dir)
|
|
||||||
{
|
|
||||||
free(cpy);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for(cptr = dir; *cptr; cptr++)
|
for(cptr = dir; *cptr; cptr++)
|
||||||
{
|
{
|
||||||
/* Convert to forward slash */
|
/* Convert to forward slash */
|
||||||
|
@ -470,21 +415,13 @@ int wpp_add_include_path(const char *path)
|
||||||
*cptr = '\0';
|
*cptr = '\0';
|
||||||
|
|
||||||
/* Add to list */
|
/* Add to list */
|
||||||
new_path = pp_xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
|
includepath = pp_xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
|
||||||
if(!new_path)
|
|
||||||
{
|
|
||||||
free(dir);
|
|
||||||
free(cpy);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
includepath = new_path;
|
|
||||||
includepath[nincludepath] = dir;
|
includepath[nincludepath] = dir;
|
||||||
nincludepath++;
|
nincludepath++;
|
||||||
}
|
}
|
||||||
tok = strtok(NULL, INCLUDESEPARATOR);
|
tok = strtok(NULL, INCLUDESEPARATOR);
|
||||||
}
|
}
|
||||||
free(cpy);
|
free(cpy);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wpp_find_include(const char *name, const char *parent_name)
|
char *wpp_find_include(const char *name, const char *parent_name)
|
||||||
|
@ -676,8 +613,6 @@ static void generic_msg(const char *s, const char *t, const char *n, va_list ap)
|
||||||
if(n)
|
if(n)
|
||||||
{
|
{
|
||||||
cpy = pp_xstrdup(n);
|
cpy = pp_xstrdup(n);
|
||||||
if(!cpy)
|
|
||||||
goto end;
|
|
||||||
for (p = cpy; *p; p++) if(!isprint(*p)) *p = ' ';
|
for (p = cpy; *p; p++) if(!isprint(*p)) *p = ' ';
|
||||||
fprintf(stderr, " near '%s'", cpy);
|
fprintf(stderr, " near '%s'", cpy);
|
||||||
free(cpy);
|
free(cpy);
|
||||||
|
|
|
@ -72,11 +72,9 @@ static void add_special_defines(void)
|
||||||
pp_add_define( "__TIME__", buf );
|
pp_add_define( "__TIME__", buf );
|
||||||
|
|
||||||
ppp = pp_add_define( "__FILE__", "" );
|
ppp = pp_add_define( "__FILE__", "" );
|
||||||
if(ppp)
|
|
||||||
ppp->type = def_special;
|
ppp->type = def_special;
|
||||||
|
|
||||||
ppp = pp_add_define( "__LINE__", "" );
|
ppp = pp_add_define( "__LINE__", "" );
|
||||||
if(ppp)
|
|
||||||
ppp->type = def_special;
|
ppp->type = def_special;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +88,7 @@ static void del_special_defines(void)
|
||||||
|
|
||||||
|
|
||||||
/* add a define to the preprocessor list */
|
/* add a define to the preprocessor list */
|
||||||
int wpp_add_define( const char *name, const char *value )
|
void wpp_add_define( const char *name, const char *value )
|
||||||
{
|
{
|
||||||
struct define *def;
|
struct define *def;
|
||||||
|
|
||||||
|
@ -100,35 +98,17 @@ int wpp_add_define( const char *name, const char *value )
|
||||||
{
|
{
|
||||||
if (!strcmp( def->name, name ))
|
if (!strcmp( def->name, name ))
|
||||||
{
|
{
|
||||||
char *new_value = pp_xstrdup(value);
|
|
||||||
if(!new_value)
|
|
||||||
return 1;
|
|
||||||
free( def->value );
|
free( def->value );
|
||||||
def->value = new_value;
|
def->value = pp_xstrdup(value);
|
||||||
|
return;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def = pp_xmalloc( sizeof(*def) );
|
def = pp_xmalloc( sizeof(*def) );
|
||||||
if(!def)
|
|
||||||
return 1;
|
|
||||||
def->next = cmdline_defines;
|
def->next = cmdline_defines;
|
||||||
def->name = pp_xstrdup(name);
|
def->name = pp_xstrdup(name);
|
||||||
if(!def->name)
|
|
||||||
{
|
|
||||||
free(def);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
def->value = pp_xstrdup(value);
|
def->value = pp_xstrdup(value);
|
||||||
if(!def->value)
|
|
||||||
{
|
|
||||||
free(def->name);
|
|
||||||
free(def);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
cmdline_defines = def;
|
cmdline_defines = def;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,17 +130,15 @@ void wpp_del_define( const char *name )
|
||||||
|
|
||||||
|
|
||||||
/* add a command-line define of the form NAME=VALUE */
|
/* add a command-line define of the form NAME=VALUE */
|
||||||
int wpp_add_cmdline_define( const char *value )
|
void wpp_add_cmdline_define( const char *value )
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char *str = pp_xstrdup(value);
|
char *str = pp_xstrdup(value);
|
||||||
if(!str)
|
|
||||||
return 1;
|
|
||||||
p = strchr( str, '=' );
|
p = strchr( str, '=' );
|
||||||
if (p) *p++ = 0;
|
if (p) *p++ = 0;
|
||||||
wpp_add_define( str, p );
|
wpp_add_define( str, p );
|
||||||
free( str );
|
free( str );
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,23 +166,14 @@ int wpp_parse( const char *input, FILE *output )
|
||||||
pp_status.input = NULL;
|
pp_status.input = NULL;
|
||||||
pp_status.line_number = 1;
|
pp_status.line_number = 1;
|
||||||
pp_status.char_number = 1;
|
pp_status.char_number = 1;
|
||||||
pp_status.state = 0;
|
|
||||||
|
|
||||||
ret = pp_push_define_state();
|
pp_push_define_state();
|
||||||
if(ret)
|
|
||||||
return ret;
|
|
||||||
add_cmdline_defines();
|
add_cmdline_defines();
|
||||||
add_special_defines();
|
add_special_defines();
|
||||||
|
|
||||||
if (!input) pp_status.file = stdin;
|
if (!input) pp_status.file = stdin;
|
||||||
else if (!(pp_status.file = fopen(input, "rt")))
|
else if (!(pp_status.file = fopen(input, "rt")))
|
||||||
{
|
|
||||||
ppy_error("Could not open %s\n", input);
|
ppy_error("Could not open %s\n", input);
|
||||||
del_special_defines();
|
|
||||||
del_cmdline_defines();
|
|
||||||
pp_pop_define_state();
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
pp_status.input = input ? pp_xstrdup(input) : NULL;
|
pp_status.input = input ? pp_xstrdup(input) : NULL;
|
||||||
|
|
||||||
|
@ -212,8 +181,6 @@ int wpp_parse( const char *input, FILE *output )
|
||||||
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
|
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
|
||||||
|
|
||||||
ret = ppy_parse();
|
ret = ppy_parse();
|
||||||
/* If there were errors during processing, return an error code */
|
|
||||||
if (!ret && pp_status.state) ret = pp_status.state;
|
|
||||||
|
|
||||||
if (input)
|
if (input)
|
||||||
{
|
{
|
||||||
|
|
|
@ -179,7 +179,7 @@ void *pp_xmalloc(size_t);
|
||||||
void *pp_xrealloc(void *, size_t);
|
void *pp_xrealloc(void *, size_t);
|
||||||
char *pp_xstrdup(const char *str);
|
char *pp_xstrdup(const char *str);
|
||||||
pp_entry_t *pplookup(const char *ident);
|
pp_entry_t *pplookup(const char *ident);
|
||||||
int pp_push_define_state(void);
|
void pp_push_define_state(void);
|
||||||
void pp_pop_define_state(void);
|
void pp_pop_define_state(void);
|
||||||
pp_entry_t *pp_add_define(const char *def, const char *text);
|
pp_entry_t *pp_add_define(const char *def, const char *text);
|
||||||
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
|
pp_entry_t *pp_add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
|
||||||
|
@ -211,7 +211,6 @@ struct pp_status
|
||||||
void *file; /* current input file descriptor */
|
void *file; /* current input file descriptor */
|
||||||
int line_number; /* current line number */
|
int line_number; /* current line number */
|
||||||
int char_number; /* current char number in line */
|
int char_number; /* current char number in line */
|
||||||
int state; /* current error state */
|
|
||||||
int pedantic; /* pedantic option */
|
int pedantic; /* pedantic option */
|
||||||
int debug; /* debug messages flag */
|
int debug; /* debug messages flag */
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue