aboutsummaryrefslogtreecommitdiff
path: root/refs.lex
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-20 02:10:11 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-20 02:10:11 +0200
commit253264591e14d173ac256fcb0b83b3463548c8fc (patch)
tree4fa000bb37879e61131b5044ddc5abf8a7605da4 /refs.lex
parent7fb5e36da3b4e873793036f5e7feaccbde924b10 (diff)
downloadfref-253264591e14d173ac256fcb0b83b3463548c8fc.tar.gz
Handle multiple authors
Diffstat (limited to 'refs.lex')
-rw-r--r--refs.lex81
1 files changed, 59 insertions, 22 deletions
diff --git a/refs.lex b/refs.lex
index 5440777..02ebbb0 100644
--- a/refs.lex
+++ b/refs.lex
@@ -2,6 +2,8 @@
#include <stdarg.h>
#define MAX 255
+
+ #define AND "och"
#define ED "red."
#define TR "Övers."
@@ -12,13 +14,22 @@
char *name;
struct entry {
- char au[MAX]; char al[MAX];
- char bo[MAX]; char ci[MAX];
- char da[MAX]; char ed[MAX];
- char jo[MAX]; char no[MAX];
- char pg[MAX]; char pu[MAX];
- char se[MAX]; char ti[MAX];
- char tr[MAX]; char vo[MAX];
+ int a; /* Number of authors. */
+ char au[MAX][MAX];
+ char al[MAX];
+ char bo[MAX];
+ char ci[MAX];
+ char da[MAX];
+ char ed[MAX];
+ char jo[MAX];
+ char no[MAX];
+ char pg[MAX];
+ char pu[MAX];
+ char se[MAX];
+ char ti[MAX];
+ char tr[MAX];
+ char vo[MAX];
+ char QQ[MAX];
} e;
%s ENTRY
@@ -32,6 +43,7 @@ void
main(int argc, char *argv[0])
{
name = argv[0];
+ e.a = 0;
yylex();
}
@@ -45,13 +57,21 @@ field(char *t)
t++;
t[strcspn(t, "\n")] = 0;
- AS("au",e.au); AS("al",e.al);
- AS("bo",e.bo); AS("ci",e.ci);
- AS("da",e.da); AS("ed",e.ed);
- AS("jo",e.jo); AS("no",e.no);
- AS("pg",e.pg); AS("pu",e.pu);
- AS("se",e.se); AS("ti",e.ti);
- AS("tr",e.tr); AS("vo",e.vo);
+ AS("au",e.au[e.a++]);
+ AS("al",e.al);
+ AS("bo",e.bo);
+ AS("ci",e.ci);
+ AS("da",e.da);
+ AS("ed",e.ed);
+ AS("jo",e.jo);
+ AS("no",e.no);
+ AS("pg",e.pg);
+ AS("pu",e.pu);
+ AS("se",e.se);
+ AS("ti",e.ti);
+ AS("tr",e.tr);
+ AS("vo",e.vo);
+ AS("??",e.QQ);
fprintf(stderr, "%s: unrecognized field %%%.2s\n", name, t);
exit(1);
@@ -61,10 +81,19 @@ field(char *t)
void
entry()
{
+ int i;
#define EI(a, b) a ? a : b
- (pf("% (%).\n", e.au, e.da) || pf("%.\n", e.au));
+ /* Print authors. */
+ for(i = 0; i < e.a-2; i++)
+ printf("%s, ", e.au[i]);
+ if(i == e.a-2)
+ printf("%s "AND" ", e.au[i++]);
+ if(i == e.a-1)
+ printf("%s", e.au[i]);
+
+ (pf(" (%).\n", e.da) || (e.a ? pf(".\n") : 0));
if (*e.bo || *e.jo){
pf("%.\n", e.ti);
pf("\\fI%\\fP", EI(e.bo, e.jo));
@@ -77,13 +106,21 @@ entry()
#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);
+ e.a = 0;
+ 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);
+ CL(e.QQ);
}
/* Print formatted text if given strings are non-empty. */