diff options
-rw-r--r-- | example.t | 3 | ||||
-rw-r--r-- | fref.lex | 66 |
2 files changed, 45 insertions, 24 deletions
@@ -10,7 +10,8 @@ References %ci Варшава %pu Типография Михаила Земкевича %pp 110-123 -%ad http://www.example.com/b1887.pdf +%hr http://www.example.com/b1887.pdf +%ad 2020-04-27 .XP %au Baudouin de Courtenay, J. %au Author, Fake Extra @@ -3,6 +3,10 @@ * given on standard in. The specification syntax is similar to that of * refer, but differs in that all identifiers are two letters instead of * one (like troff itself). This allows for a larger number of fields. + * + * To build fref, run the following commands: + * $ lex fref.lex + * $ cc -std=c89 -O2 -o fref lex.yy.c -lfl */ %x ENTRY @@ -10,8 +14,12 @@ #include <err.h> #include <stdarg.h> - #define MAX 255 + #define MAX 255 /* Max field length. */ + /* + * The following string constants can be redefined to support + * other languages. + */ #define AND "och" #define AVAIL "Tillgänglig: " #define ED "red." @@ -21,21 +29,22 @@ #define VOL "vol." #define DO_ENTRIES \ - DO("ad",ad,e.ad) /* internet address */ \ - DO("bo",bo,e.bo) /* book */ \ - DO("ci",ci,e.ci) /* city */ \ - DO("da",da,e.da) /* date (year) */ \ - DO("ed",ed,e.ed) /* editor */ \ - DO("jo",jo,e.jo) /* journal */ \ - DO("la",la,e.la) /* label */ \ - DO("no",no,e.no) /* TODO: issue number */ \ - DO("pp",pp,e.pp) /* pages */ \ - DO("pu",pu,e.pu) /* publisher */ \ - DO("se",se,e.se) /* TODO: series */ \ - DO("ti",ti,e.ti) /* title */ \ - DO("tr",tr,e.tr) /* translator */ \ - DO("vo",vo,e.vo) /* volume */ \ - DO("xx",xx,e.xx) /* extra information */ \ + DO("ad",ad,e.ad) /* Access date. */ \ + DO("bo",bo,e.bo) /* Book. */ \ + DO("ci",ci,e.ci) /* City. */ \ + DO("da",da,e.da) /* Date (year). */ \ + DO("ed",ed,e.ed) /* Editor. */ \ + DO("hr",hr,e.hr) /* Hypertext reference. */ \ + DO("jo",jo,e.jo) /* Journal. */ \ + DO("la",la,e.la) /* Label. */ \ + DO("no",no,e.no) /* TODO: Issue number. */ \ + DO("pp",pp,e.pp) /* Pages. */ \ + DO("pu",pu,e.pu) /* Publisher. */ \ + DO("se",se,e.se) /* TODO: Series. */ \ + DO("ti",ti,e.ti) /* Title. */ \ + DO("tr",tr,e.tr) /* Translator. */ \ + DO("vo",vo,e.vo) /* Volume. */ \ + DO("xx",xx,e.xx) /* Extra information. */ \ /* END */ void field(char *); @@ -44,15 +53,19 @@ int pf(char *, ...); char *name; - int line; /* line at which entry begins */ - int lines = 0; /* total number of lines */ + int line; /* Line at which entry begins. */ + int lines = 0; /* Total number of lines. */ + /* + e is a struct holding all fields of the current entry. + It is zeroed before each call to entry(). + */ struct entry { #define DO(s,n,m) char n[MAX]; DO_ENTRIES #undef DO - int a; /* number of authors */ - char au[MAX][MAX]; /* author */ + int a; /* Number of authors. */ + char au[MAX][MAX]; /* Authors. */ } e; %% @@ -97,6 +110,10 @@ field(char *t) void entry() { + /* + * Presently, fref supports only Harvard-style citations, but + * allows for future extensions. + */ harvard(); } @@ -151,10 +168,13 @@ harvard() /* Print other information. */ pf("%.\n", e.xx); - /* Print internet address. */ - pf(AVAIL"%\n", e.ad); + /* Print hypertext reference. */ + pf(AVAIL"%\n", e.hr); - /* Clear entries. */ + /* Print access date. */ + pf("[%]\n", e.ad); + + /* Clear unused fields. */ e.a = 0; #define DO(s,n,m) \ if(*m) fprintf(stderr, "%s: unused field %%"s" at line %d\n", \ |