aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-20 01:48:01 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-20 01:48:01 +0200
commit7fb5e36da3b4e873793036f5e7feaccbde924b10 (patch)
tree9f0574b6ac150c08b9d74080ede00bfa612dda0e
parent1ef148f6f3fc515866be7abdbd5a844a45cb4f49 (diff)
downloadfref-7fb5e36da3b4e873793036f5e7feaccbde924b10.tar.gz
Clear fields after each entry
-rw-r--r--example.t6
-rw-r--r--refs.lex28
2 files changed, 28 insertions, 6 deletions
diff --git a/example.t b/example.t
index de0f5f5..b6051b7 100644
--- a/example.t
+++ b/example.t
@@ -1,14 +1,14 @@
.SH
References
.XP
-%au В. А. Богородицкий
+%au Богородицкий, В. А.
%al Bogorodickij
%da 1887
%ti Курс грамматики русского языка. Часть 1-ая: Фонетика
%ci Варшава
%pu Типография Михаила Земкевича
.XP
-%au J. Baudouin de Courtenay
+%au de Courtenay, J. Baudouin
%da 1972
%ti The Difference between Phonetics and Psychophonetics
%bo A Baudouin de Courtenay Anthology
@@ -17,7 +17,7 @@ References
%ci Bloomington
%pu Indiana University Press
.XP
-%au M. E. Lesk
+%au Lesk, M. E.
%ti Some Applications of Inverted Indexes on the UNIX System
%bo UNIX Programmer's Manual
%vo 2b
diff --git a/refs.lex b/refs.lex
index 714a79e..5440777 100644
--- a/refs.lex
+++ b/refs.lex
@@ -35,6 +35,7 @@ main(int argc, char *argv[0])
yylex();
}
+/* Save entry field. */
void
field(char *t)
{
@@ -56,15 +57,36 @@ field(char *t)
exit(1);
}
+/* Print formatted entry. */
void
entry()
{
+
+#define EI(a, b) a ? a : b
+
(pf("% (%).\n", e.au, e.da) || pf("%.\n", e.au));
- (pf("%.\n\\fI%\\fP.\n", e.ti, e.bo ? e.bo : e.jo)
- || pf("%.\n", e.ti));
+ if (*e.bo || *e.jo){
+ pf("%.\n", e.ti);
+ pf("\\fI%\\fP", EI(e.bo, e.jo));
+ pf(" ("ED" %)", e.ed);
+ pf(".\n");
+ }else
+ pf("\\fI%\\fP.\n", e.ti);
+ pf(TR" %.\n", e.tr);
(pf("%: %.\n", e.ci, e.pu) || pf("%.\n", e.pu));
+
+#define CL(a) *a = 0
+
+ CL(e.au); CL(e.al);
+ CL(e.bo); CL(e.ci);
+ CL(e.da); CL(e.ed);
+ CL(e.jo); CL(e.no);
+ CL(e.pg); CL(e.pu);
+ CL(e.se); CL(e.ti);
+ CL(e.tr); CL(e.vo);
}
+/* Print formatted text if given strings are non-empty. */
int
pf(char *fmt, ...)
{
@@ -85,7 +107,7 @@ pf(char *fmt, ...)
switch(*fmt){
case '%':
p = va_arg(ap, char *);
- if(!p || !p[0])
+ if(!p || !*p)
return 0;
strcat(buf, p);
break;