aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-20 10:51:45 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-21 11:19:55 +0200
commitcfb5a3a464ddb1d8aa9a1bbcb1a08db3a38ad619 (patch)
tree36b5509bab3d33128bfd534286207ce373ad1da6
parent5c23a8619bc282e998050561809a832f2bb8c6ce (diff)
downloadfref-cfb5a3a464ddb1d8aa9a1bbcb1a08db3a38ad619.tar.gz
Rename %ad to %hr, add %ad (access date)
-rw-r--r--example.t3
-rw-r--r--fref.lex66
2 files changed, 45 insertions, 24 deletions
diff --git a/example.t b/example.t
index 26775e4..1993af6 100644
--- a/example.t
+++ b/example.t
@@ -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
diff --git a/fref.lex b/fref.lex
index 41fa126..401604f 100644
--- a/fref.lex
+++ b/fref.lex
@@ -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", \