diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-21 14:17:15 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-21 14:17:15 +0200 |
commit | d2390f71937a1ef1d2b01d58029e7e92fdbbe8fb (patch) | |
tree | 310387215b0b148c23ad381778e6c2de57b73ede | |
parent | fef2148c031fbd80fc849393bcf3f5bcb7fefdae (diff) | |
download | fref-d2390f71937a1ef1d2b01d58029e7e92fdbbe8fb.tar.gz |
Clean up field function
-rw-r--r-- | fref.lex | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -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); -<ENTRY>^%.*\n lines++; field(yytext); +^%.*\n line = ++lines; field(); BEGIN(ENTRY); +<ENTRY>^%.*\n lines++; field(); <ENTRY>^[^%] entry(); ECHO; BEGIN(0); <ENTRY><<EOF>> 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); |