From c0fa598f67188998e71910547a710691cf0c249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 22 Jul 2021 09:55:39 +0200 Subject: Save global pointer to default language strings --- fref.lex | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fref.lex b/fref.lex index fb6fb47..e57eb01 100644 --- a/fref.lex +++ b/fref.lex @@ -65,12 +65,13 @@ extern int optind; char *name; /* Program name. */ - char *lang = NULL; /* Main language (-l). */ + char *lang; /* Main language (-l). */ int line; /* Line at which entry begins. */ - int lines = 0; /* Total number of lines. */ - struct trans *len = NULL; /* English strings. */ - struct trans *lru = NULL; /* Russian strings. */ - struct trans *lsv = NULL; /* Swedish strings. */ + int lines; /* Total number of lines. */ + struct trans *len; /* English strings. */ + struct trans *lru; /* Russian strings. */ + struct trans *lsv; /* Swedish strings. */ + struct trans *tglob; /* Global (default) strings. */ %% \n lines++; ECHO; @@ -85,6 +86,12 @@ main(int argc, char *argv[]) { int c; + /* Initialize global variables. */ + lines = 0; + lang = NULL; + len = lru = lsv = tglob = NULL; + memset(&e, 0, sizeof(e)); + /* Save program name. */ name = strrchr(argv[0], '/'); if(name) name++; @@ -103,12 +110,8 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if(!lang) - lang = strdup("en"); - gettrans(lang); - - /* Clear entry struct. */ - memset(&e, 0, sizeof(e)); + /* Get global language strings. */ + tglob = gettrans(lang ? lang : "en"); yylex(); } @@ -148,7 +151,7 @@ entry() struct trans *t; /* Get translation strings. */ - t = gettrans(*e.lc ? e.lc : lang); + t = *e.lc ? gettrans(e.lc) : tglob; *e.lc = 0; /* Print label. */ @@ -240,7 +243,7 @@ gettrans(char *lg) if(!(lru = malloc(sizeof(struct trans)))) err(1, "malloc"); lru->and = strdup("и"); - lru->avail = strdup("Доступный: "); + lru->avail = strdup("Доступная: "); lru->ed = strdup("ред. "); lru->p = strdup("c. "); lru->pp = strdup("с. "); -- cgit v1.2.3