aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fref.lex141
1 files changed, 75 insertions, 66 deletions
diff --git a/fref.lex b/fref.lex
index b52cce5..d984f8e 100644
--- a/fref.lex
+++ b/fref.lex
@@ -69,10 +69,7 @@
char *name; /* Program name. */
char *lang; /* Main language (-l). */
- struct trans *len; /* English strings. */
- struct trans *lru; /* Russian strings. */
- struct trans *lsv; /* Swedish strings. */
- struct trans *tglob; /* Global (default) strings. */
+ struct trans *tglob; /* Global translation strings (-l). */
unsigned int line; /* Line at which entry begins. */
unsigned int lines; /* Total number of lines. */
unsigned int punct; /* Was punctuation printed? */
@@ -91,9 +88,9 @@ main(int argc, char *argv[])
int c;
/* Initialize global variables. */
- lines = punct = 0;
+ line = lines = punct = 0;
lang = NULL;
- len = lru = lsv = tglob = NULL;
+ tglob = NULL;
memset(&e, 0, sizeof(e));
/* Save program name. */
@@ -120,6 +117,78 @@ main(int argc, char *argv[])
yylex();
}
+/* Return pointer to translation struct. */
+struct trans *
+gettrans(char *lg)
+{
+ static struct trans *len = NULL;
+ static struct trans *lru = NULL;
+ static struct trans *lsv = NULL;
+
+ if(strncmp(lg, "en", 2) == 0){
+ if(!len){
+ if(!(len = malloc(sizeof(struct trans))))
+ err(1, "malloc");
+ len->and = strdup("and");
+ len->avail = strdup("Available: ");
+ len->ed = strdup("ed. ");
+ len->p = strdup("p. ");
+ len->P = strdup("P. ");
+ len->pp = strdup("pp. ");
+ len->Pp = strdup("Pp. ");
+ len->tr = strdup("Trans. ");
+ len->vo = strdup("vol. ");
+ len->Vo = strdup("Vol. ");
+ }
+ return len;
+ }
+
+ if(strncmp(lg, "ru", 2) == 0){
+ if(!lru){
+ if(!(lru = malloc(sizeof(struct trans))))
+ err(1, "malloc");
+ lru->and = strdup("и");
+ lru->avail = strdup("Доступная: ");
+ lru->ed = strdup("ред. ");
+ lru->p = strdup("с. ");
+ lru->P = strdup("С. ");
+ lru->pp = strdup("с. ");
+ lru->Pp = strdup("С. ");
+ lru->tr = strdup("Перев. ");
+ lru->vo = strdup("том ");
+ lru->Vo = strdup("Том ");
+ }
+ return lru;
+ }
+
+ if(strncmp(lg, "sv", 2) == 0){
+ if(!lsv){
+ if(!(lsv = malloc(sizeof(struct trans))))
+ err(1, "malloc");
+ lsv->and = strdup("och");
+ lsv->avail = strdup("Tillgänglig: ");
+ lsv->ed = strdup("red. ");
+ lsv->p = strdup("s. ");
+ lsv->P = strdup("S. ");
+ lsv->pp = strdup("ss. ");
+ lsv->Pp = strdup("Ss. ");
+ lsv->tr = strdup("Övers. ");
+ lsv->vo = strdup("vol. ");
+ lsv->Vo = strdup("Vol. ");
+ }
+ return lsv;
+ }
+
+ if(line)
+ fprintf(stderr, "%s: unrecognized language %s"
+ " in reference at line %d\n",
+ name, lg, line);
+ else
+ fprintf(stderr, "%s: unrecognized language %s\n",
+ name, lg);
+ exit(1);
+}
+
/* Save entry field. */
void
field()
@@ -228,66 +297,6 @@ entry()
#undef DO
}
-/* Return pointer to translation struct. */
-struct trans *
-gettrans(char *lg)
-{
- if(strncmp(lg, "en", 2) == 0){
- if(!len){
- if(!(len = malloc(sizeof(struct trans))))
- err(1, "malloc");
- len->and = strdup("and");
- len->avail = strdup("Available: ");
- len->ed = strdup("ed. ");
- len->p = strdup("p. ");
- len->P = strdup("P. ");
- len->pp = strdup("pp. ");
- len->Pp = strdup("Pp. ");
- len->tr = strdup("Trans. ");
- len->vo = strdup("vol. ");
- len->Vo = strdup("Vol. ");
- }
- return len;
- }else if(strncmp(lg, "ru", 2) == 0){
- if(!lru){
- if(!(lru = malloc(sizeof(struct trans))))
- err(1, "malloc");
- lru->and = strdup("и");
- lru->avail = strdup("Доступная: ");
- lru->ed = strdup("ред. ");
- lru->p = strdup("с. ");
- lru->P = strdup("С. ");
- lru->pp = strdup("с. ");
- lru->Pp = strdup("С. ");
- lru->tr = strdup("Перев. ");
- lru->vo = strdup("том ");
- lru->Vo = strdup("Том ");
- }
- return lru;
- }else if(strncmp(lg, "sv", 2) == 0){
- if(!lsv){
- if(!(lsv = malloc(sizeof(struct trans))))
- err(1, "malloc");
- lsv->and = strdup("och");
- lsv->avail = strdup("Tillgänglig: ");
- lsv->ed = strdup("red. ");
- lsv->p = strdup("s. ");
- lsv->P = strdup("S. ");
- lsv->pp = strdup("ss. ");
- lsv->Pp = strdup("Ss. ");
- lsv->tr = strdup("Övers. ");
- lsv->vo = strdup("vol. ");
- lsv->Vo = strdup("Vol. ");
- }
- return lsv;
- }else{
- fprintf(stderr, "%s: unrecognized language %s"
- " in reference at line %d\n",
- name, lg, line);
- exit(1);
- }
-}
-
/*
* This function interpolates any number of strings into a formatted
* string, which is printed only if all interpolated strings are non-empty.