xref: /original-bsd/contrib/bib/src/listrefs.c (revision 264c46cb)
1 #ifndef lint
2 static char sccsid[] = "@(#)listrefs.c	2.1	06/22/83";
3 #endif not lint
4 
5 /*
6         list all documents in ref index file
7                                                         */
8 # include <stdio.h>
9 # include <ctype.h>
10 # include "bib.h"
11 # include "streams.h"
12 # define MAXLINE 250
13 
14 FILE *tfd;
15 int  count = 1;
16 char refs[REFSIZE], *rp;
17 
18 main(argc, argv)
19    int argc;
20    char **argv;
21 {
22    tfd = stdout;
23    doargs(argc, argv, "/usr/lib/bmac/bib.list");
24    exit(0);
25 }
26 
27 /* rdtext - process a file */
28    rdtext(ifile)
29    FILE *ifile;
30 {
31    long int start, length;
32    int  i, numauths, numeds;
33    char *p, c;
34 
35    start = length = 0L;
36 
37    for (;;) {
38       start = nextrecord(ifile, start + length);
39       if (start == EOF) break;
40       length = recsize(ifile, start);
41 
42       /* count number of authors */
43       numauths = numeds = 0;
44       p = refs;
45       for (i = length; i > 0; i--)
46          if ((*p++ = getc(ifile)) == '%') {
47             i--;
48             c = *p++ = getc(ifile);
49             if (c == 'A')
50                numauths++;
51             else if (c == 'E')
52                numeds++;
53             }
54 
55       *p = 0;
56       expand(refs);
57       rp = refs;
58       dumpref(stdout, numauths, numeds);
59 
60      }
61 }
62 
63 /* get a line from reference file */
64    char refgets(line)
65    char line[];
66 {
67    char c, *p;
68 
69    if (*rp == 0)
70       return(0);
71    for (p = line;;) {
72       while ((c = *rp++) != '\n')
73          if (c == 0)
74             return(0);
75          else
76             *p++ = c;
77       c = *rp;
78       if (c == 0)
79          break;
80       if (c == '.' || c == '%' || c == '\n')
81          break;
82       *p++ = ' ';
83       }
84    *p++ = '\n';
85    *p = 0;
86    return(' ');
87 }
88 
89 /* dump reference */
90    dumpref(ofile, maxauths, maxeds)
91    FILE *ofile;
92    int maxauths, maxeds;
93 {
94    char line[250], *p;
95    int  numauths, numeds;
96 
97    fprintf(tfd, ".[-\n");
98    fprintf(tfd, ".ds [F %d\n", count++);
99    numauths = numeds = 0;
100    while (refgets(line) != 0) {
101       if (line[0] == '\n')
102          break;
103       else if (line[0] == '.')
104          fprintf(ofile, "%s\n", line);
105       else {
106          if (line[0] == '%') {
107             for (p = &line[2]; isspace(*p); p++);
108             if (line[1] == 'A')
109                numauths++;
110             else if (line[1] == 'E')
111                numeds++;
112             doline(line[1], p, numauths, maxauths, numeds, maxeds, ofile);
113             }
114          }
115       }
116    fprintf(tfd, ".][\n");
117 }
118