aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fref.lex52
1 files changed, 35 insertions, 17 deletions
diff --git a/fref.lex b/fref.lex
index ddfa71d..6155f3a 100644
--- a/fref.lex
+++ b/fref.lex
@@ -47,9 +47,12 @@
char *avail;
char *ed;
char *p;
+ char *P;
char *pp;
+ char *Pp;
char *tr;
char *vo;
+ char *Vo;
};
/* Fields of current entry. */
@@ -68,6 +71,7 @@
char *lang; /* Main language (-l). */
int line; /* Line at which entry begins. */
int lines; /* Total number of lines. */
+ int punct; /* Was punctuation printed? */
struct trans *len; /* English strings. */
struct trans *lru; /* Russian strings. */
struct trans *lsv; /* Swedish strings. */
@@ -87,7 +91,7 @@ main(int argc, char *argv[])
int c;
/* Initialize global variables. */
- lines = 0;
+ lines = punct = 0;
lang = NULL;
len = lru = lsv = tglob = NULL;
memset(&e, 0, sizeof(e));
@@ -167,29 +171,28 @@ entry()
if(i == e.a-2)
pf("* * ", e.au[i++], t->and);
if(i == e.a-1)
- pf("*", e.au[i]);
+ pf("%", e.au[i]);
/* Print date. */
- if(!pf(" (%).\n", e.da) && e.a){
- if(!strpbrk(e.au[i]+strlen(e.au[i])-1, ".,?!"))
- pf(".");
- pf("\n");
- }
+ (pf(" (%).\n", e.da) || pf(".\n"));
/* Print title, book/journal. */
if(*e.bo || *e.jo){
pf("%.\n", e.ti);
pf("\\fI%\\fP", e.bo ? e.bo : e.jo);
pf(" (*%)", t->ed, e.ed);
- }else
+ }else{
pf("\\fI%\\fP", e.ti);
+ }
/* Print volume. */
- pf(", *%", t->vo, e.vo);
+ pf(", *%", punct ? t->Vo : t->vo, e.vo);
/* Print pages, converting hyphens to en dashes. */
if(*e.pg){
- pf(", *", strpbrk(e.pg, ",-") ? t->pp : t->p);
+ pf(", *", strpbrk(e.pg, ",-") ?
+ (punct ? t->Pp :t->pp)
+ : (punct ? t->P : t->p));
for(i = 0; i < strlen(e.pg); i++){
if(e.pg[i] == '-') putchar('\\');
putchar(e.pg[i]);
@@ -237,9 +240,12 @@ gettrans(char *lg)
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){
@@ -249,10 +255,13 @@ gettrans(char *lg)
lru->and = strdup("и");
lru->avail = strdup("Доступная: ");
lru->ed = strdup("ред. ");
- lru->p = strdup("c. ");
+ 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){
@@ -263,9 +272,12 @@ gettrans(char *lg)
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{
@@ -287,7 +299,7 @@ int
pf(char *fmt, ...)
{
char *buf, *p, **fs;
- int i, n, punct, sz;
+ int i, n, sz;
va_list ap;
/* Count interpolated strings. */
@@ -311,15 +323,12 @@ pf(char *fmt, ...)
}
va_end(ap);
- /* Keep track of prior punctuation. */
- punct = 0;
-
/* Print formatted string. */
for(i = 0; *fmt; fmt++)
switch(*fmt){
case '%':
p = fs[i]+strlen(fs[i])-1;
- punct = strpbrk(p, ".,?!") ? 1 : 0;
+ punct = strpbrk(p, ".?!") ? 1 : 0;
printf("%s", fs[i]);
fs[i][0] = 0;
i++;
@@ -333,8 +342,17 @@ pf(char *fmt, ...)
case ',':
case '?':
case '!':
- if(punct && punct--)
+ if(!punct)
+ putchar(*fmt);
+ punct = 0;
+ break;
+ case '\\':
+ /* Don't reset punctuation for \fX escape. */
+ if(strncmp(fmt, "\\f", 2) == 0 && fmt[2]){
+ printf("%.3s", fmt);
+ fmt += 2;
break;
+ }
/* FALLTHROUGH */
default:
punct = 0;