X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=parser.c;h=e49b5ca6895b86e6a3782bf9cc9c5b78ff2e0226;hp=898bbfac2c3f2f0d9e1d8ac6e3d2ba1cfd0092fa;hb=6958227c2a4665dabcb489d0a731659aed383ffa;hpb=db59ee1476515a65cfcca10a3059d8ccb2d24d32 diff --git a/parser.c b/parser.c index 898bbfa..e49b5ca 100644 --- a/parser.c +++ b/parser.c @@ -173,6 +173,7 @@ static int dequote(char *inplace) { } } assert(*p); assert(!*++p); + *q++= 0; return tokv_quotedstring; } @@ -838,8 +839,7 @@ int df_reset(int dtoken) { r= pa_mnl(); if (r) return r; r= parse_string(RESET_CONFIGURATION,"",1); - assert(!r); - return 0; + return r; } int dfg_fdwant(int dtoken) { @@ -1235,8 +1235,10 @@ static void parser_pop(void) { } int parse_string(const char *string, const char *descrip, int isinternal) { - /* Returns the same things as parser, except that tokv_eof - * is turned into 0. + /* Returns the same things as parser, except that tokv_eof is turned + * into 0. *string must be statically allocated or copied, so that + * it is not overwritten while the parsing takes place (unlike with + * parse_file). */ static const struct stat blankstab; @@ -1256,9 +1258,10 @@ int parse_string(const char *string, const char *descrip, int isinternal) { } static int parse_file(const char *string, int *didexist) { - /* Returns the same things as parser, except that tokv_eof - * is turned into 0. If *didexist is 0 then errno will - * have been set. + /* Returns the same things as parser, except that tokv_eof is turned + * into 0. If *didexist is 0 then errno will have been set. + * *string will be copied by parse_file so it may be be overwritten + * during the parsing (so, for example, yytext need not be copied). */ static int fileparselevel= 0; @@ -1266,6 +1269,7 @@ static int parse_file(const char *string, int *didexist) { YY_BUFFER_STATE ybuf; int r; FILE *file; + char *filename; struct stat newstab; if (fileparselevel >= MAX_INCLUDE_NEST) { @@ -1296,7 +1300,8 @@ static int parse_file(const char *string, int *didexist) { ybuf= yy_create_buffer(file,YY_BUF_SIZE); if (!ybuf) syscallerror("unable to create flex buffer for file"); - parser_push(&usestate,string,&newstab,ybuf,0); + filename= xstrsave(string); + parser_push(&usestate,filename,&newstab,ybuf,0); fileparselevel++; r= parser(0); @@ -1304,9 +1309,10 @@ static int parse_file(const char *string, int *didexist) { parseerrprint("error reading configuration file `%s'",string); r= tokv_error; } - + fileparselevel--; parser_pop(); + free(filename); fclose(file); if (r == tokv_eof) r= 0; return r;