wpp: Remove the assumption ppy_error calls exit().
This commit is contained in:
parent
37e7116862
commit
026ca4cd00
|
@ -639,7 +639,7 @@ includelogicentry_t *pp_includelogiclist = NULL;
|
|||
if(yy_current_state() == pp_inc)
|
||||
ppy_error("Expected include filename");
|
||||
|
||||
if(yy_current_state() == pp_if)
|
||||
else if(yy_current_state() == pp_if)
|
||||
{
|
||||
ppy_lval.cptr = pp_xstrdup(ppy_text);
|
||||
return tIDENT;
|
||||
|
@ -808,7 +808,10 @@ static int make_number(int radix, YYSTYPE *val, const char *str, int len)
|
|||
ext[0] = len > 2 ? toupper(str[len-3]) : ' ';
|
||||
|
||||
if(!strcmp(ext, "LUL"))
|
||||
{
|
||||
ppy_error("Invalid constant suffix");
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp(ext, "LLU") || !strcmp(ext, "ULL"))
|
||||
{
|
||||
is_ll++;
|
||||
|
@ -1085,7 +1088,10 @@ static void expand_macro(macexpstackentry_t *mep)
|
|||
assert(ppp->expanding == 0);
|
||||
|
||||
if((ppp->nargs >= 0 && nargs != ppp->nargs) || (ppp->nargs < 0 && nargs < -ppp->nargs))
|
||||
{
|
||||
ppy_error("Too %s macro arguments (%d)", nargs < abs(ppp->nargs) ? "few" : "many", nargs);
|
||||
return;
|
||||
}
|
||||
|
||||
for(n = 0; n < nargs; n++)
|
||||
nnl += mep->nnls[n];
|
||||
|
@ -1323,7 +1329,10 @@ static bufferstackentry_t *pop_buffer(void)
|
|||
static void push_macro(pp_entry_t *ppp)
|
||||
{
|
||||
if(macexpstackidx >= MAXMACEXPSTACK)
|
||||
{
|
||||
ppy_error("Too many nested macros");
|
||||
return;
|
||||
}
|
||||
|
||||
macexpstack[macexpstackidx] = pp_xmalloc(sizeof(macexpstack[0][0]));
|
||||
memset( macexpstack[macexpstackidx], 0, sizeof(macexpstack[0][0]));
|
||||
|
@ -1472,13 +1481,19 @@ void pp_do_include(char *fname, int type)
|
|||
n = strlen(fname);
|
||||
|
||||
if(n <= 2)
|
||||
{
|
||||
ppy_error("Empty include filename");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Undo the effect of the quotation */
|
||||
fname[n-1] = '\0';
|
||||
|
||||
if((ppy_in = pp_open_include(fname+1, type ? pp_status.input : NULL, &newpath)) == NULL)
|
||||
{
|
||||
ppy_error("Unable to open include file %s", fname+1);
|
||||
return;
|
||||
}
|
||||
|
||||
fname[n-1] = *fname; /* Redo the quotes */
|
||||
push_buffer(NULL, newpath, fname, 0);
|
||||
|
|
|
@ -224,6 +224,9 @@ preprocessor
|
|||
case if_elsetrue:
|
||||
case if_elsefalse:
|
||||
ppy_error("#elif cannot follow #else");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #elif directive", s);
|
||||
}
|
||||
|
@ -247,24 +250,29 @@ preprocessor
|
|||
case if_elsetrue:
|
||||
case if_elsefalse:
|
||||
ppy_error("#else clause already defined");
|
||||
break;
|
||||
case if_error:
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d) in #else directive", s);
|
||||
}
|
||||
}
|
||||
| tENDIF tNL {
|
||||
pp_pop_if();
|
||||
if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
|
||||
if(pp_pop_if() != if_error)
|
||||
{
|
||||
pp_incl_state.state = 2;
|
||||
pp_incl_state.seen_junk = 0;
|
||||
if(pp_incl_state.ifdepth == pp_get_if_depth() && pp_incl_state.state == 1)
|
||||
{
|
||||
pp_incl_state.state = 2;
|
||||
pp_incl_state.seen_junk = 0;
|
||||
}
|
||||
else if(pp_incl_state.state != 1)
|
||||
{
|
||||
pp_incl_state.state = -1;
|
||||
}
|
||||
if(pp_status.debug)
|
||||
fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
|
||||
pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
|
||||
}
|
||||
else if(pp_incl_state.state != 1)
|
||||
{
|
||||
pp_incl_state.state = -1;
|
||||
}
|
||||
if(pp_status.debug)
|
||||
fprintf(stderr, "tENDIF: %s:%d: include_state=%d, include_ppp='%s', include_ifdepth=%d\n",
|
||||
pp_status.input, pp_status.line_number, pp_incl_state.state, pp_incl_state.ppp, pp_incl_state.ifdepth);
|
||||
}
|
||||
| tUNDEF tIDENT tNL { pp_del_define($2); free($2); }
|
||||
| tDEFINE opt_text tNL { pp_add_define($1, $2); }
|
||||
|
@ -346,7 +354,8 @@ mtext : tLITERAL { $$ = new_mtext($1, 0, exp_text); }
|
|||
int mat = marg_index($2);
|
||||
if(mat < 0)
|
||||
ppy_error("Stringification identifier must be an argument parameter");
|
||||
$$ = new_mtext(NULL, mat, exp_stringize);
|
||||
else
|
||||
$$ = new_mtext(NULL, mat, exp_stringize);
|
||||
}
|
||||
| tIDENT {
|
||||
int mat = marg_index($1);
|
||||
|
|
|
@ -519,13 +519,18 @@ void pp_push_if(pp_if_state_t s)
|
|||
case if_ignore:
|
||||
pp_push_ignore_state();
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
}
|
||||
|
||||
pp_if_state_t pp_pop_if(void)
|
||||
{
|
||||
if(if_stack_idx <= 0)
|
||||
{
|
||||
ppy_error("#{endif,else,elif} without #{if,ifdef,ifndef} (#if-stack underflow)");
|
||||
return if_error;
|
||||
}
|
||||
|
||||
switch(pp_if_state())
|
||||
{
|
||||
|
@ -538,6 +543,8 @@ pp_if_state_t pp_pop_if(void)
|
|||
case if_ignore:
|
||||
pp_pop_ignore_state();
|
||||
break;
|
||||
default:
|
||||
pp_internal_error(__FILE__, __LINE__, "Invalid pp_if_state (%d)", (int)pp_if_state());
|
||||
}
|
||||
|
||||
if(pp_flex_debug)
|
||||
|
|
|
@ -144,6 +144,7 @@ int wpp_parse( const char *input, FILE *output )
|
|||
int ret;
|
||||
|
||||
pp_status.input = NULL;
|
||||
pp_status.state = 0;
|
||||
|
||||
pp_push_define_state();
|
||||
add_cmdline_defines();
|
||||
|
@ -152,8 +153,8 @@ int wpp_parse( const char *input, FILE *output )
|
|||
if (!input) ppy_in = stdin;
|
||||
else if (!(ppy_in = fopen(input, "rt")))
|
||||
{
|
||||
fprintf(stderr,"Could not open %s\n", input);
|
||||
exit(2);
|
||||
ppy_error("Could not open %s\n", input);
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp_status.input = input;
|
||||
|
@ -162,6 +163,8 @@ int wpp_parse( const char *input, FILE *output )
|
|||
fprintf(ppy_out, "# 1 \"%s\" 1\n", input ? input : "");
|
||||
|
||||
ret = ppy_parse();
|
||||
/* If there were errors during processing, return an error code */
|
||||
if(!ret && pp_status.state) ret = pp_status.state;
|
||||
|
||||
if (input) fclose(ppy_in);
|
||||
pp_pop_define_state();
|
||||
|
@ -184,14 +187,14 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na
|
|||
|
||||
if((fd = mkstemps( temp_name, 0 )) == -1)
|
||||
{
|
||||
fprintf(stderr, "Could not generate a temp name from %s\n", temp_name);
|
||||
exit(2);
|
||||
ppy_error("Could not generate a temp name from %s\n", temp_name);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!(output = fdopen(fd, "wt")))
|
||||
{
|
||||
fprintf(stderr,"Could not open fd %s for writing\n", temp_name);
|
||||
exit(2);
|
||||
ppy_error("Could not open fd %s for writing\n", temp_name);
|
||||
return 2;
|
||||
}
|
||||
|
||||
*output_name = temp_name;
|
||||
|
|
|
@ -113,7 +113,8 @@ typedef enum {
|
|||
if_elif,
|
||||
if_elsefalse,
|
||||
if_elsetrue,
|
||||
if_ignore
|
||||
if_ignore,
|
||||
if_error
|
||||
} pp_if_state_t;
|
||||
|
||||
|
||||
|
@ -228,6 +229,7 @@ struct pp_status
|
|||
const char *input; /* current input file name */
|
||||
int line_number; /* current line number */
|
||||
int char_number; /* current char number in line */
|
||||
int state; /* current error state */
|
||||
int pedantic; /* pedantic option */
|
||||
int debug; /* debug messages flag */
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue