From d2390f71937a1ef1d2b01d58029e7e92fdbbe8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 21 Jul 2021 14:17:15 +0200 Subject: Clean up field function --- fref.lex | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fref.lex b/fref.lex index 750711c..5a35bd4 100644 --- a/fref.lex +++ b/fref.lex @@ -37,7 +37,7 @@ /* END */ void entry(void); - void field(char *); + void field(); struct trans *gettrans(char *); int pf(char *, ...); @@ -74,8 +74,8 @@ %% \n lines++; ECHO; -^%.*\n line = ++lines; field(yytext); BEGIN(ENTRY); -^%.*\n lines++; field(yytext); +^%.*\n line = ++lines; field(); BEGIN(ENTRY); +^%.*\n lines++; field(); ^[^%] entry(); ECHO; BEGIN(0); <> entry(); yyterminate(); %% @@ -115,17 +115,19 @@ main(int argc, char *argv[]) /* Save entry field. */ void -field(char *s) +field() { - s++; - s[strcspn(s, "\n")] = 0; + yytext++; + yytext[strcspn(yytext, "\n")] = 0; /* Fill corresponding field. */ - #define AS(a,b) \ - if(strncmp(s, a, 2) == 0 && (s += 3)){ strcpy(b, s); return; } + #define FI(s,m) if(strncmp(yytext,s,2) == 0 && (yytext += 3)){ \ + strcpy(m, yytext); \ + return; \ + } - AS("au",e.au[e.a++]); - #define DO(s,n,m) AS(s,m) + FI("au",e.au[e.a++]); + #define DO(s,n,m) FI(s,m) FOR_FIELDS #undef DO @@ -134,7 +136,7 @@ field(char *s) * with a positive value. */ fprintf(stderr, "%s: unrecognized field %%%.2s at line %d\n", - name, s, lines); + name, yytext, lines); exit(1); } @@ -142,8 +144,8 @@ field(char *s) void entry() { - struct trans *t; int i; + struct trans *t; /* Get translation strings. */ t = gettrans(*e.lc ? e.lc : lang); -- cgit v1.2.3