aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-22 09:55:39 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-22 09:55:39 +0200
commitc0fa598f67188998e71910547a710691cf0c249c (patch)
tree8b384a90e0b63eb51f75b6522b5a1b35ff12fcb8
parent77e6918ba1c879b091c746b3b564b4bd76c5cfb3 (diff)
downloadfref-c0fa598f67188998e71910547a710691cf0c249c.tar.gz
Save global pointer to default language strings
-rw-r--r--fref.lex29
1 files 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("с. ");