Commit 04ae435f authored by Alexandre Julliard's avatar Alexandre Julliard

wrc: Use the standard memory allocation wrappers in the preprocessor.

parent b69ce347
......@@ -153,6 +153,7 @@ ul [uUlL]|[uUlL][lL]|[lL][uU]|[lL][lL][uU]|[uU][lL][lL]|[lL][uU][lL]
%{
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
......@@ -172,6 +173,7 @@ ul [uUlL]|[uUlL][lL]|[lL][uU]|[lL][lL][uU]|[uU][lL][lL]|[lL][uU][lL]
#define YY_NO_UNISTD_H
#endif
#include "utils.h"
#include "wpp_private.h"
#include "ppy.tab.h"
......@@ -291,58 +293,13 @@ include_state_t pp_incl_state =
0 /* seen_junk */
};
struct list pp_includelogiclist = LIST_INIT( pp_includelogiclist );
static struct list pp_includelogiclist = LIST_INIT( pp_includelogiclist );
#define YY_INPUT(buf,result,max_size) \
{ \
result = fread(buf, 1, max_size, pp_status.file); \
}
#define BUFFERINITIALCAPACITY 256
void pp_writestring(const char *format, ...)
{
va_list valist;
int len;
static char *buffer;
static int buffercapacity;
char *new_buffer;
if(buffercapacity == 0)
{
buffer = pp_xmalloc(BUFFERINITIALCAPACITY);
buffercapacity = BUFFERINITIALCAPACITY;
}
va_start(valist, format);
len = vsnprintf(buffer, buffercapacity,
format, valist);
va_end(valist);
/* If the string is longer than buffersize, vsnprintf returns
* the string length with glibc >= 2.1, -1 with glibc < 2.1 */
while(len > buffercapacity || len < 0)
{
do
{
buffercapacity *= 2;
} while(len > buffercapacity);
new_buffer = pp_xrealloc(buffer, buffercapacity);
if(new_buffer == NULL)
{
va_end(valist);
return;
}
buffer = new_buffer;
va_start(valist, format);
len = vsnprintf(buffer, buffercapacity,
format, valist);
va_end(valist);
}
fwrite(buffer, 1, len, ppy_out);
}
%}
/*
......@@ -445,7 +402,7 @@ void pp_writestring(const char *format, ...)
* Handle #ifdef, #ifndef and #undef
* to get only an untranslated/unexpanded identifier
*/
<pp_ifd>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
<pp_ifd>{cident} ppy_lval.cptr = xstrdup(ppy_text); return tIDENT;
<pp_ifd>{ws}+ ;
<pp_ifd>\n newline(1); yy_pop_state(); return tNL;
<pp_ifd>\\\r?\n newline(0);
......@@ -464,7 +421,7 @@ void pp_writestring(const char *format, ...)
* This is necessary to get the identifier prior to any
* substitutions.
*/
<pp_defined>{cident} yy_pop_state(); ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
<pp_defined>{cident} yy_pop_state(); ppy_lval.cptr = xstrdup(ppy_text); return tIDENT;
<pp_defined>{ws}+ ;
<pp_defined>(\()|(\)) return *ppy_text;
<pp_defined>\\\r?\n newline(0);
......@@ -476,17 +433,17 @@ void pp_writestring(const char *format, ...)
* will act appropriately.
* Comments are stripped from the literal text.
*/
<pp_eol>[^/\\\n]+ if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
<pp_eol>\/[^/\\\n*]* if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
<pp_eol>(\\\r?)|(\/[^/*]) if(yy_top_state() != pp_ignore) { ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL; }
<pp_eol>[^/\\\n]+ if(yy_top_state() != pp_ignore) { ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL; }
<pp_eol>\/[^/\\\n*]* if(yy_top_state() != pp_ignore) { ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL; }
<pp_eol>(\\\r?)|(\/[^/*]) if(yy_top_state() != pp_ignore) { ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL; }
<pp_eol>\n newline(1); yy_pop_state(); if(yy_current_state() != pp_ignore) { return tNL; }
<pp_eol>\\\r?\n newline(0);
/*
* Handle left side of #define
*/
<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 = xstrdup(ppy_text); ppy_lval.cptr[ppy_leng-1] = '\0'; yy_pp_state(pp_macro); return tMACRO;
<pp_def>{cident} ppy_lval.cptr = xstrdup(ppy_text); yy_pp_state(pp_define); return tDEFINE;
<pp_def>{ws}+ ;
<pp_def>\\\r?\n newline(0);
<pp_def>(\\\r?)|(\n)|(.) perror("Identifier expected");
......@@ -494,9 +451,9 @@ void pp_writestring(const char *format, ...)
/*
* Scan the substitution of a define
*/
<pp_define>[^'"/\\\n]+ ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
<pp_define>(\\\r?)|(\/[^/*]) ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
<pp_define>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = pp_xstrdup(" "); return tLITERAL;
<pp_define>[^'"/\\\n]+ ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL;
<pp_define>(\\\r?)|(\/[^/*]) ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL;
<pp_define>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = xstrdup(" "); return tLITERAL;
<pp_define>\\\r?\n newline(0);
<pp_define>\n newline(1); yy_pop_state(); return tNL;
<pp_define>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
......@@ -507,7 +464,7 @@ void pp_writestring(const char *format, ...)
*/
<pp_macro>\){ws}* yy_pp_state(pp_mbody); return tMACROEND;
<pp_macro>{ws}+ ;
<pp_macro>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
<pp_macro>{cident} ppy_lval.cptr = xstrdup(ppy_text); return tIDENT;
<pp_macro>, return ',';
<pp_macro>"..." return tELLIPSIS;
<pp_macro>(\\\r?)|(\n)|(.)|(\.\.?) ppy_error("Argument identifier expected");
......@@ -516,13 +473,13 @@ void pp_writestring(const char *format, ...)
/*
* Scan the substitution of a macro
*/
<pp_mbody>[^a-zA-Z0-9'"#/\\\n]+ ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
<pp_mbody>{cident} ppy_lval.cptr = pp_xstrdup(ppy_text); return tIDENT;
<pp_mbody>[^a-zA-Z0-9'"#/\\\n]+ ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL;
<pp_mbody>{cident} ppy_lval.cptr = xstrdup(ppy_text); return tIDENT;
<pp_mbody>\#\# return tCONCAT;
<pp_mbody>\# return tSTRINGIZE;
<pp_mbody>[0-9][a-zA-Z0-9]*[^a-zA-Z0-9'"#/\\\n]* ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
<pp_mbody>(\\\r?)|(\/[^/*'"#\\\n]*) ppy_lval.cptr = pp_xstrdup(ppy_text); return tLITERAL;
<pp_mbody>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = pp_xstrdup(" "); return tLITERAL;
<pp_mbody>[0-9][a-zA-Z0-9]*[^a-zA-Z0-9'"#/\\\n]* ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL;
<pp_mbody>(\\\r?)|(\/[^/*'"#\\\n]*) ppy_lval.cptr = xstrdup(ppy_text); return tLITERAL;
<pp_mbody>\\\r?\n{ws}+ newline(0); ppy_lval.cptr = xstrdup(" "); return tLITERAL;
<pp_mbody>\\\r?\n newline(0);
<pp_mbody>\n newline(1); yy_pop_state(); return tNL;
<pp_mbody>\' new_string(); add_string(ppy_text, ppy_leng); yy_push_state(pp_sqs);
......@@ -689,7 +646,7 @@ void pp_writestring(const char *format, ...)
else if(yy_current_state() == pp_if)
{
ppy_lval.cptr = pp_xstrdup(ppy_text);
ppy_lval.cptr = xstrdup(ppy_text);
return tIDENT;
}
else {
......@@ -738,8 +695,8 @@ void pp_writestring(const char *format, ...)
<pp_macexp>(\n)|(.)|(\\\r?(\n|.)) put_buffer(ppy_text, ppy_leng);
<RCINCL>[A-Za-z0-9_\.\\/]+ {
ppy_lval.cptr=pp_xstrdup(ppy_text);
yy_pop_state();
ppy_lval.cptr = xstrdup(ppy_text);
yy_pop_state();
return tRCINCLUDEPATH;
}
......@@ -946,24 +903,17 @@ static int make_number(int radix, YYSTYPE *val, const char *str, int len)
static void expand_special(pp_entry_t *ppp)
{
static char *buf = NULL;
char *new_buf;
assert(ppp->type == def_special);
if(!strcmp(ppp->ident, "__LINE__"))
{
new_buf = pp_xrealloc(buf, 32);
if(!new_buf)
return;
buf = new_buf;
buf = xrealloc(buf, 32);
sprintf(buf, "%d", pp_status.line_number);
}
else if(!strcmp(ppp->ident, "__FILE__"))
{
new_buf = pp_xrealloc(buf, strlen(pp_status.input) + 3);
if(!new_buf)
return;
buf = new_buf;
buf = xrealloc(buf, strlen(pp_status.input) + 3);
sprintf(buf, "\"%s\"", pp_status.input);
}
else
......@@ -1008,21 +958,12 @@ static char *curdef_text = NULL;
static void add_text(const char *str, int len)
{
int new_alloc;
char *new_text;
if(len == 0)
return;
if(curdef_idx >= curdef_alloc || curdef_alloc - curdef_idx < len)
{
new_alloc = curdef_alloc + ((len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1));
new_text = pp_xrealloc(curdef_text, new_alloc * sizeof(curdef_text[0]));
if(!new_text)
return;
curdef_text = new_text;
curdef_alloc = new_alloc;
if(curdef_alloc > 65536)
ppy_warning("Reallocating macro-expansion buffer larger than 64kB");
curdef_alloc += (len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1);
curdef_text = xrealloc(curdef_text, curdef_alloc * sizeof(curdef_text[0]));
}
memcpy(&curdef_text[curdef_idx], str, len);
curdef_idx += len;
......@@ -1214,21 +1155,12 @@ static void new_string(void)
static void add_string(const char *str, int len)
{
int new_alloc;
char *new_buffer;
if(len == 0)
return;
if(strbuf_idx >= strbuf_alloc || strbuf_alloc - strbuf_idx < len)
{
new_alloc = strbuf_alloc + ((len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1));
new_buffer = pp_xrealloc(strbuffer, new_alloc * sizeof(strbuffer[0]));
if(!new_buffer)
return;
strbuffer = new_buffer;
strbuf_alloc = new_alloc;
if(strbuf_alloc > 65536)
ppy_warning("Reallocating string buffer larger than 64kB");
strbuf_alloc += (len + ALLOCBLOCKSIZE-1) & ~(ALLOCBLOCKSIZE-1);
strbuffer = xrealloc(strbuffer, strbuf_alloc * sizeof(strbuffer[0]));
}
memcpy(&strbuffer[strbuf_idx], str, len);
strbuf_idx += len;
......@@ -1236,7 +1168,7 @@ static void add_string(const char *str, int len)
static char *get_string(void)
{
char *str = pp_xmalloc(strbuf_idx + 1);
char *str = xmalloc(strbuf_idx + 1);
memcpy(str, strbuffer, strbuf_idx);
str[strbuf_idx] = '\0';
......@@ -1313,7 +1245,7 @@ static bufferstackentry_t *pop_buffer(void)
if(!bufferstack[bufferstackidx].should_pop)
{
fclose(pp_status.file);
pp_writestring("# %d \"%s\" 2\n", bufferstack[bufferstackidx].line_number, bufferstack[bufferstackidx].filename);
fprintf(ppy_out, "# %d \"%s\" 2\n", bufferstack[bufferstackidx].line_number, bufferstack[bufferstackidx].filename);
/* We have EOF, check the include logic */
if(pp_incl_state.state == 2 && !pp_incl_state.seen_junk && pp_incl_state.ppp)
......@@ -1321,7 +1253,7 @@ static bufferstackentry_t *pop_buffer(void)
pp_entry_t *ppp = pplookup(pp_incl_state.ppp);
if(ppp)
{
iep = pp_xmalloc(sizeof(includelogicentry_t));
iep = xmalloc(sizeof(includelogicentry_t));
iep->ppp = ppp;
ppp->iep = iep;
iep->filename = bufferstack[bufferstackidx].include_filename;
......@@ -1387,7 +1319,7 @@ static void push_macro(pp_entry_t *ppp)
return;
}
macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
macexpstack[macexpstackidx] = xmalloc(sizeof(macexpstack[0][0]));
memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
macexpstack[macexpstackidx]->ppp = ppp;
macexpstackidx++;
......@@ -1425,13 +1357,8 @@ static void add_text_to_macro(const char *text, int len)
if(mep->curargalloc - mep->curargsize <= len+1) /* +1 for '\0' */
{
char *new_curarg;
int new_alloc = mep->curargalloc + ((ALLOCBLOCKSIZE > len+1) ? ALLOCBLOCKSIZE : len+1);
new_curarg = pp_xrealloc(mep->curarg, new_alloc * sizeof(mep->curarg[0]));
if(!new_curarg)
return;
mep->curarg = new_curarg;
mep->curargalloc = new_alloc;
mep->curargalloc += (ALLOCBLOCKSIZE > len+1) ? ALLOCBLOCKSIZE : len+1;
mep->curarg = xrealloc(mep->curarg, mep->curargalloc * sizeof(mep->curarg[0]));
}
memcpy(mep->curarg + mep->curargsize, text, len);
mep->curargsize += len;
......@@ -1446,11 +1373,11 @@ static void macro_add_arg(int last)
assert(mep->ppp->expanding == 0);
mep->args = pp_xrealloc(mep->args, (mep->nargs+1) * sizeof(mep->args[0]));
mep->ppargs = pp_xrealloc(mep->ppargs, (mep->nargs+1) * sizeof(mep->ppargs[0]));
mep->nnls = pp_xrealloc(mep->nnls, (mep->nargs+1) * sizeof(mep->nnls[0]));
mep->args = xrealloc(mep->args, (mep->nargs+1) * sizeof(mep->args[0]));
mep->ppargs = xrealloc(mep->ppargs, (mep->nargs+1) * sizeof(mep->ppargs[0]));
mep->nnls = xrealloc(mep->nnls, (mep->nargs+1) * sizeof(mep->nnls[0]));
mep->args[mep->nargs] = pp_xstrdup(mep->curarg ? mep->curarg : "");
mep->args[mep->nargs] = xstrdup(mep->curarg ? mep->curarg : "");
cptr = mep->args[mep->nargs]-1;
while((cptr = strchr(cptr+1, '\n')))
{
......@@ -1485,7 +1412,7 @@ static void macro_add_expansion(void)
assert(mep->ppp->expanding == 0);
mep->ppargs[mep->nargs-1] = pp_xstrdup(mep->curarg ? mep->curarg : "");
mep->ppargs[mep->nargs-1] = xstrdup(mep->curarg ? mep->curarg : "");
free(mep->curarg);
mep->curargalloc = mep->curargsize = 0;
mep->curarg = NULL;
......@@ -1573,7 +1500,7 @@ void pp_do_include(char *fname, int type)
pp_status.file = fp;
ppy__switch_to_buffer(ppy__create_buffer(NULL, YY_BUF_SIZE));
pp_writestring("# 1 \"%s\" 1%s\n", newpath, type ? "" : " 3");
fprintf(ppy_out, "# 1 \"%s\" 1%s\n", newpath, type ? "" : " 3");
}
/*
......
......@@ -30,6 +30,7 @@
#include <ctype.h>
#include <string.h>
#include "utils.h"
#include "wpp_private.h"
......@@ -270,27 +271,23 @@ preprocessor
| tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
pp_add_macro($1, macro_args, nmacro_args, $5);
}
| tLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tNL { if($3) pp_writestring("# %d %s\n", $2 , $3); free($3); }
| tLINE tSINT tDQSTRING tNL { if($3) fprintf(ppy_out, "# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tNL { if($3) fprintf(ppy_out, "# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tNL
{ if($3) pp_writestring("# %d %s %d\n", $2, $3, $4); free($3); }
{ if($3) fprintf(ppy_out, "# %d %s %d\n", $2, $3, $4); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
{ if($3) pp_writestring("# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
{ if($3) fprintf(ppy_out, "# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
{ if($3) pp_writestring("# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
{ if($3) fprintf(ppy_out, "# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
{ if($3) pp_writestring("# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
{ if($3) fprintf(ppy_out, "# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
| tGCCLINE tNL /* The null-token */
| tERROR opt_text tNL { ppy_error("#error directive: '%s'", $2); free($2); }
| tWARNING opt_text tNL { ppy_warning("#warning directive: '%s'", $2); free($2); }
| tPRAGMA opt_text tNL { pp_writestring("#pragma %s\n", $2 ? $2 : ""); free($2); }
| tPRAGMA opt_text tNL { fprintf(ppy_out, "#pragma %s\n", $2 ? $2 : ""); free($2); }
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
| tRCINCLUDE tRCINCLUDEPATH {
int nl=strlen($2) +3;
char *fn=pp_xmalloc(nl);
sprintf(fn,"\"%s\"",$2);
pp_do_include(fn,1);
free($2);
pp_do_include(strmake( "\"%s\"", $2 ),1);
}
| tRCINCLUDE tDQSTRING {
pp_do_include($2,1);
......@@ -538,8 +535,8 @@ static int boolean(cval_t *v)
static char *add_new_marg(char *str)
{
char *ma;
macro_args = pp_xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
macro_args[nmacro_args++] = ma = pp_xstrdup(str);
macro_args = xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
macro_args[nmacro_args++] = ma = xstrdup(str);
return ma;
}
......@@ -558,7 +555,7 @@ static int marg_index(char *id)
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
{
mtext_t *mt = pp_xmalloc(sizeof(mtext_t));
mtext_t *mt = xmalloc(sizeof(mtext_t));
if(str == NULL)
mt->subst.argidx = idx;
......@@ -579,7 +576,7 @@ static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
if(tail->type == exp_text && mtp->type == exp_text)
{
tail->subst.text = pp_xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
tail->subst.text = xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
strcat(tail->subst.text, mtp->subst.text);
free(mtp->subst.text);
free(mtp);
......@@ -645,7 +642,7 @@ static char *merge_text(char *s1, char *s2)
{
int l1 = strlen(s1);
int l2 = strlen(s2);
s1 = pp_xrealloc(s1, l1+l2+1);
s1 = xrealloc(s1, l1+l2+1);
memcpy(s1+l1, s2, l2+1);
free(s2);
return s1;
......
......@@ -34,6 +34,7 @@
# include <unistd.h>
#endif
#include "utils.h"
#include "wpp_private.h"
struct pp_status pp_status;
......@@ -57,42 +58,8 @@ struct define
static struct list cmdline_defines = LIST_INIT( cmdline_defines );
void *pp_xmalloc(size_t size)
{
void *res;
assert(size > 0);
res = malloc(size);
if(res == NULL)
{
fprintf( stderr, "Virtual memory exhausted\n" );
exit(1);
}
return res;
}
void *pp_xrealloc(void *p, size_t size)
{
void *res;
assert(size > 0);
res = realloc(p, size);
if(res == NULL)
{
fprintf( stderr, "Virtual memory exhausted\n" );
exit(1);
}
return res;
}
char *pp_xstrdup(const char *str)
{
int len = strlen(str)+1;
return memcpy(pp_xmalloc(len), str, len);
}
char *wpp_lookup(const char *name, int type, const char *parent_name,
char **include_path, int include_path_count)
static char *wpp_lookup(const char *name, int type, const char *parent_name,
char **include_path, int include_path_count)
{
char *cpy;
char *cptr;
......@@ -100,7 +67,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
const char *ccptr;
int i, fd;
cpy = pp_xmalloc(strlen(name)+1);
cpy = xmalloc(strlen(name)+1);
cptr = cpy;
for(ccptr = name; *ccptr; ccptr++)
......@@ -125,7 +92,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
if ((p = strrchr( parent_name, '/' ))) p++;
else p = parent_name;
path = pp_xmalloc( (p - parent_name) + strlen(cpy) + 1 );
path = xmalloc( (p - parent_name) + strlen(cpy) + 1 );
memcpy( path, parent_name, p - parent_name );
strcpy( path + (p - parent_name), cpy );
fd = open( path, O_RDONLY );
......@@ -140,10 +107,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
/* Search -I path */
for(i = 0; i < include_path_count; i++)
{
path = pp_xmalloc(strlen(include_path[i]) + strlen(cpy) + 2);
strcpy(path, include_path[i]);
strcat(path, "/");
strcat(path, cpy);
path = strmake("%s/%s", include_path[i], cpy);
fd = open( path, O_RDONLY );
if (fd != -1)
{
......@@ -195,7 +159,7 @@ static void free_pp_entry( pp_entry_t *ppp, int idx )
}
/* initialize the define state */
void pp_init_define_state(void)
static void pp_init_define_state(void)
{
int i;
......@@ -203,7 +167,7 @@ void pp_init_define_state(void)
}
/* free the current define state */
void pp_free_define_state(void)
static void pp_free_define_state(void)
{
int i;
pp_entry_t *ppp, *ppp2;
......@@ -255,12 +219,12 @@ pp_entry_t *pp_add_define(const char *def, const char *text)
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", def, ppp->filename, ppp->linenumber);
pp_del_define(def);
}
ppp = pp_xmalloc(sizeof(pp_entry_t));
ppp = xmalloc(sizeof(pp_entry_t));
memset( ppp, 0, sizeof(*ppp) );
ppp->ident = pp_xstrdup(def);
ppp->ident = xstrdup(def);
ppp->type = def_define;
ppp->subst.text = text ? pp_xstrdup(text) : NULL;
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->subst.text = text ? xstrdup(text) : NULL;
ppp->filename = xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
list_add_head( &pp_defines[idx], &ppp->entry );
if(ppp->subst.text)
......@@ -295,14 +259,14 @@ pp_entry_t *pp_add_macro(char *id, char *args[], int nargs, mtext_t *exp)
ppy_warning("Redefinition of %s\n\tPrevious definition: %s:%d", id, ppp->filename, ppp->linenumber);
pp_del_define(id);
}
ppp = pp_xmalloc(sizeof(pp_entry_t));
ppp = xmalloc(sizeof(pp_entry_t));
memset( ppp, 0, sizeof(*ppp) );
ppp->ident = id;
ppp->type = def_macro;
ppp->margs = args;
ppp->nargs = nargs;
ppp->subst.mtext= exp;
ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->filename = xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>");
ppp->linenumber = pp_status.input ? pp_status.line_number : 0;
list_add_head( &pp_defines[idx], &ppp->entry );
if(pp_status.debug)
......@@ -349,7 +313,7 @@ static int nincludepath = 0;
void wpp_add_include_path(const char *path)
{
char *tok;
char *cpy = pp_xstrdup(path);
char *cpy = xstrdup(path);
tok = strtok(cpy, INCLUDESEPARATOR);
while(tok)
......@@ -358,7 +322,7 @@ void wpp_add_include_path(const char *path)
char *dir;
char *cptr;
dir = pp_xstrdup(tok);
dir = xstrdup(tok);
for(cptr = dir; *cptr; cptr++)
{
/* Convert to forward slash */
......@@ -370,7 +334,7 @@ void wpp_add_include_path(const char *path)
*cptr = '\0';
/* Add to list */
includepath = pp_xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
includepath = xrealloc(includepath, (nincludepath+1) * sizeof(*includepath));
includepath[nincludepath] = dir;
nincludepath++;
}
......@@ -633,14 +597,14 @@ static void wpp_add_define( const char *name, const char *value )
if (!strcmp( def->name, name ))
{
free( def->value );
def->value = pp_xstrdup(value);
def->value = xstrdup(value);
return;
}
}
def = pp_xmalloc( sizeof(*def) );
def->name = pp_xstrdup(name);
def->value = pp_xstrdup(value);
def = xmalloc( sizeof(*def) );
def->name = xstrdup(name);
def->value = xstrdup(value);
list_add_head( &cmdline_defines, &def->entry );
}
......@@ -666,7 +630,7 @@ void wpp_del_define( const char *name )
void wpp_add_cmdline_define( const char *value )
{
char *p;
char *str = pp_xstrdup(value);
char *str = xstrdup(value);
p = strchr( str, '=' );
if (p) *p++ = 0;
......@@ -708,10 +672,10 @@ int wpp_parse( const char *input, FILE *output )
else if (!(pp_status.file = fopen(input, "rt")))
ppy_error("Could not open %s\n", input);
pp_status.input = input ? pp_xstrdup(input) : NULL;
pp_status.input = input ? xstrdup(input) : NULL;
ppy_out = output;
pp_writestring("# 1 \"%s\" 1\n", input ? input : "");
fprintf(ppy_out, "# 1 \"%s\" 1\n", input ? input : "");
ret = ppy_parse();
......
......@@ -155,12 +155,7 @@ typedef struct cval {
void *pp_xmalloc(size_t);
void *pp_xrealloc(void *, size_t);
char *pp_xstrdup(const char *str);
pp_entry_t *pplookup(const char *ident);
void pp_init_define_state(void);
void pp_free_define_state(void);
pp_entry_t *pp_add_define(const char *def, const char *text);
pp_entry_t *pp_add_macro(char *ident, char *args[], int nargs, mtext_t *exp);
void pp_del_define(const char *name);
......@@ -170,12 +165,6 @@ void pp_next_if_state(int);
pp_if_state_t pp_pop_if(void);
pp_if_state_t pp_if_state(void);
int pp_get_if_depth(void);
char *wpp_lookup(const char *name, int type, const char *parent_name,
char **include_path, int include_path_count);
#ifndef __GNUC__
#define __attribute__(x) /*nothing*/
#endif
int ppy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int ppy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
......@@ -195,7 +184,6 @@ struct pp_status
extern struct pp_status pp_status;
extern include_state_t pp_incl_state;
extern struct list pp_includelogiclist;
/*
* From ppl.l
......@@ -210,8 +198,6 @@ void pp_do_include(char *fname, int type);
void pp_push_ignore_state(void);
void pp_pop_ignore_state(void);
void pp_writestring(const char *format, ...) __attribute__((format (printf, 1, 2)));
/*
* From ppy.y
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment