Commit 958f0587 958f058784b520433448ade9bb29491b028753b5 by Sergey Poznyakoff

(pop_source): Always free ali_filename.

Grammar: Bugfixes.
(mh_alias_read): Provide a debugging hook
(ali_verbatim): New function.
1 parent 356f6343
...@@ -310,13 +310,14 @@ pop_source () ...@@ -310,13 +310,14 @@ pop_source ()
310 #ifndef FLEX_SCANNER 310 #ifndef FLEX_SCANNER
311 lex_delete_buffer (current_buffer); 311 lex_delete_buffer (current_buffer);
312 #endif 312 #endif
313 if (ali_filename)
314 free (ali_filename);
315 ali_filename = NULL;
313 if (!context_stack) 316 if (!context_stack)
314 { 317 {
315 yyin = NULL; 318 yyin = NULL;
316 return 1; 319 return 1;
317 } 320 }
318 if (ali_filename)
319 free (ali_filename);
320 /* Restore previous context */ 321 /* Restore previous context */
321 ali_filename = context_stack->filename; 322 ali_filename = context_stack->filename;
322 ali_line_num = context_stack->line + 1; /* < line did not increment it */ 323 ali_line_num = context_stack->line + 1; /* < line did not increment it */
...@@ -333,6 +334,8 @@ extern int yyparse __P((void)); ...@@ -333,6 +334,8 @@ extern int yyparse __P((void));
333 %} 334 %}
334 WS [ \t]+ 335 WS [ \t]+
335 WORD [^ \t\n,:;<+=\*]+ 336 WORD [^ \t\n,:;<+=\*]+
337 SPEC [,:;+=\*]
338 %s VERBATIM
336 %% 339 %%
337 \\\n { ali_line_num++; } 340 \\\n { ali_line_num++; }
338 \n { ali_line_num++; return '\n';} 341 \n { ali_line_num++; return '\n';}
...@@ -345,19 +348,20 @@ WORD [^ \t\n,:;<+=\*]+ ...@@ -345,19 +348,20 @@ WORD [^ \t\n,:;<+=\*]+
345 return STRING;} 348 return STRING;}
346 {WS} ; 349 {WS} ;
347 {WORD} { yylval.string = strdup (yytext); return STRING;} 350 {WORD} { yylval.string = strdup (yytext); return STRING;}
348 ^{WS}?"<"{WS}?{WORD} { char *p; 351 ^{WS}?"<"{WS}?{WORD} {
352 char *p;
349 for (p = yytext; p < yytext + yyleng && isblank(*p); p++) 353 for (p = yytext; p < yytext + yyleng && isblank(*p); p++)
350 ; 354 ;
351 for (p++; p < yytext + yyleng; p++) 355 for (p++; p < yytext + yyleng; p++)
352 if (!isspace (*p)) 356 if (!isspace (*p))
353 break; 357 break;
354 push_source (p, 1); } 358 push_source (p, 1); }
355 "<"{WORD} { yylval.string = xmalloc (yyleng + 2); 359 {SPEC} return yytext[0];
356 yylval.string[0] = '<'; 360 <VERBATIM>[^ \t\n,:;+=\*][^\n,]* {
361 yylval.string = xmalloc (yyleng + 1);
357 memcpy(yylval.string, yytext, yyleng); 362 memcpy(yylval.string, yytext, yyleng);
358 yylval.string[yyleng+1] = 0; 363 yylval.string[yyleng] = 0;
359 return STRING;} 364 return STRING;}
360 =|\*|\+|,|:|\; return yytext[0];
361 . { char *p; 365 . { char *p;
362 asprintf (&p, 366 asprintf (&p,
363 _("Stray character %03o in alias file"), yytext[0]); 367 _("Stray character %03o in alias file"), yytext[0]);
...@@ -371,15 +375,29 @@ yywrap () ...@@ -371,15 +375,29 @@ yywrap ()
371 return pop_source(); 375 return pop_source();
372 } 376 }
373 377
374
375 /* Parses the named alias file */ 378 /* Parses the named alias file */
376 int 379 int
377 mh_alias_read (char *name, int fail) 380 mh_alias_read (char *name, int fail)
378 { 381 {
379 extern int yydebug; 382 extern int yydebug;
383 char *p = getenv("ALI_YYDEBUG");
384
385 if (p && *p > '0' && *p < '9')
386 yydebug = 1;
387
380 if (push_source (name, fail)) 388 if (push_source (name, fail))
381 return 1; 389 return 1;
390 if (yydebug)
391 fprintf (stderr, "Starting parse of %s\n", name);
382 return yyparse (); 392 return yyparse ();
383 } 393 }
384 394
395 void
396 ali_verbatim (int enable)
397 {
398 if (enable)
399 BEGIN(VERBATIM);
400 else
401 BEGIN(INITIAL);
402 }
385 403
......