X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=parser.c;h=fbf0872a1ec2db564178d2905dc1fb73675b5e4d;hb=99ff52b783574342c2859359aa6c39229bd5dcda;hp=898bbfac2c3f2f0d9e1d8ac6e3d2ba1cfd0092fa;hpb=db59ee1476515a65cfcca10a3059d8ccb2d24d32;p=userv.git diff --git a/parser.c b/parser.c index 898bbfa..fbf0872 100644 --- a/parser.c +++ b/parser.c @@ -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;