[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Looking for the source to bib(1)
From: |
Jorgen Grahn |
Subject: |
Re: [Groff] Looking for the source to bib(1) |
Date: |
Sat, 24 May 2003 10:51:38 +0200 |
User-agent: |
Mutt/1.4i |
On Wed May 7 09:14:41 2003, address@hidden wrote:
> On Tue May 6 14:39:40 2003, address@hidden wrote:
> > On Tue, 6 May 2003, Ted Harding wrote:
> > > On 06-May-03 Jorgen Grahn wrote:
> > > > Since I'm not satisfied with refer, I thought I'd try
> > > > its early 1980s replacement: Timothy A. Budd's bib
> > >
> > > I have one from 1998 (bib.tar.Z); it's 90KB. I'm mailing it to
> > > you, Jörgen, but if anyone else would like a copy plase let me
> > > know.
>
> Got it; thanks!
>
> > I have a copy on my computer at home, which I am sure is the same as
> > Ted's. But I have never got it successfully to run on my Linux boxes. It
> > compiles (IIRC) without errors, but segfaults whenever it is invoked. If
> > you manage to update the source so that it runs properly on a modern
> > machine, please let us all know. (Do you think we could resurrect the
> > contrib directory on ffii,org?)
>
> I'll see what I can do, given time and energy. In the meanwhile, there is
> a kind-of-temporary copy of the archive Ted sent me at
>
> http://as3-1-3.ml.g.bonet.se/~grahn/tmp/bib.tar.Z
It turned out I had little time and energy for this... I got bib to compile,
and I got rid of the obvious segfaults (modifying string constants is not a
good idea, nor is ignoring fopen() error checking!).
I ran out of energy after bib compiled and ran, but before I managed to make
it do something useful. Maybe I'll continue some day. If not, here is a
patch.
Sorry that it's so long and the Makefile is gcc-specific; I wasn't
aware that I hated pre-ANSI C /that/ much!
/Jörgen
Index: bib/Makefile
diff -c bib/Makefile:1.1.1.1 bib/Makefile:1.2
*** bib/Makefile:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/Makefile Mon May 12 00:04:32 2003
***************
*** 1,3 ****
--- 1,6 ----
+ all:
+ cd source; make
+
install:
echo 'have you edited source/bib.h?'
cd source; make install
Index: bib/source/Makefile
diff -c bib/source/Makefile:1.1.1.1 bib/source/Makefile:1.4
*** bib/source/Makefile:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/Makefile Sat May 24 10:37:42 2003
***************
*** 1,17 ****
! .c.o:
! cc -g -c $*.c
INVo = invert.o streams.o makekey.o
- INVc = invert.c streams.c makekey.c
LOOKo = lookup.o locate.o alpha.seek.o streams.o makekey.o
- LOOKc = lookup.c locate.c alpha.seek.c streams.c makekey.c
NEWBIBo = newbib.o newbibargs.o locate.o alpha.seek.o streams.o makekey.o
BIBTEXo = bibtex.o bibtargs.o locate.o alpha.seek.o streams.o makekey.o
BIBo = bib.o bibargs.o locate.o alpha.seek.o streams.o makekey.o
- BIBc = bib.c bibargs.c locate.c alpha.seek.c streams.c makekey.c
LISTo = listrefs.o bibargs.o streams.o makekey.o
NEWLISTo = newlistrefs.o newbibargs.o streams.o makekey.o
- LISTc = listrefs.c bibargs.c streams.c makekey.c
all: invert lookup listrefs bib
--- 1,13 ----
! CFLAGS=-ansi -Wall -pedantic -g
! CPPFLAGS=-D_BSD_SOURCE
INVo = invert.o streams.o makekey.o
LOOKo = lookup.o locate.o alpha.seek.o streams.o makekey.o
NEWBIBo = newbib.o newbibargs.o locate.o alpha.seek.o streams.o makekey.o
BIBTEXo = bibtex.o bibtargs.o locate.o alpha.seek.o streams.o makekey.o
BIBo = bib.o bibargs.o locate.o alpha.seek.o streams.o makekey.o
LISTo = listrefs.o bibargs.o streams.o makekey.o
NEWLISTo = newlistrefs.o newbibargs.o streams.o makekey.o
all: invert lookup listrefs bib
***************
*** 46,63 ****
bibTex: $(BIBTEXo)
cc -g $(BIBTEXo) -o bibtex
- bib.lint: $(BIBc) bib.h streams.h
- lint $(BIBc) >bib.lint
-
listrefs: $(LISTo)
cc -g $(LISTo) -o listrefs
newlist: $(NEWLISTo)
cc -g $(NEWLISTo) -o newlistrefs
- listrefs.lint: $(LISTc) bib.h streams.h
- lint $(LISTc) >listrefs.lint
-
bib.o: bib.h
bibargs.o: bib.h
listrefs.o: bib.h
--- 42,53 ----
***************
*** 95,97 ****
--- 85,107 ----
shar:
shar *.h *.c >sharfile.bib
+
+ tags:
+ etags *.c *.h
+
+ depend:
+ makedepend -- $(CPPFLAGS) -- -Y -I. *.c
+
+ # DO NOT DELETE
+
+ alpha.seek.o: streams.h
+ bibargs.o: bib.h
+ bib.o: bib.h
+ bibtargs.o: bib.h
+ bibtex.o: bib.h
+ invert.o: streams.h bib.h
+ listrefs.o: bib.h streams.h
+ locate.o: streams.h
+ lookup.o: streams.h bib.h
+ makekey.o: bib.h
+ streams.o: streams.h
Index: bib/source/bib.c
diff -c bib/source/bib.c:1.1.1.1 bib/source/bib.c:1.2
*** bib/source/bib.c:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/bib.c Sat May 24 10:37:42 2003
***************
*** 18,23 ****
--- 18,24 ----
*/
# include <stdio.h>
+ # include <stdlib.h>
# include <ctype.h>
# include "bib.h"
***************
*** 36,42 ****
long int rend = 1; /* last position in rfd (first char unused)*/
int numrefs = -1; /* number of references generated so far */
FILE *tfd; /* output of pass 1 of file(s) */
! char tmpfile[] = TMPTEXTFILE ; /* output of pass 1 */
char common[] = COMFILE ; /* common word file */
char *citestr[MAXREFS]; /* citation strings */
int findex = false; /* can we read the file INDEX ? */
--- 37,44 ----
long int rend = 1; /* last position in rfd (first char unused)*/
int numrefs = -1; /* number of references generated so far */
FILE *tfd; /* output of pass 1 of file(s) */
! static
! char tmpfile1[] = TMPTEXTFILE ; /* output of pass 1 */
char common[] = COMFILE ; /* common word file */
char *citestr[MAXREFS]; /* citation strings */
int findex = false; /* can we read the file INDEX ? */
***************
*** 47,52 ****
--- 49,59 ----
extern char sortstr[], pfile[], citetemplate[], bibfname[];
+ void rdtext(FILE *fd);
+ static void rdcite(FILE *fd, char ch);
+
+
+ int
main(argc, argv)
int argc;
char **argv;
***************
*** 62,76 ****
}
/* open temporaries, reffile will contain references collected in
! pass 1, and tmpfile will contain text.
*/
mktemp(reffile);
rfd = fopen(reffile,"w+");
if (rfd == NULL)
error("can't open temporary reference file");
putc('x', rfd); /* put garbage in first position (not used) */
! mktemp(tmpfile);
! tfd = fopen(tmpfile,"w");
if (tfd == NULL)
error("can't open temporary output file");
--- 69,83 ----
}
/* open temporaries, reffile will contain references collected in
! pass 1, and tmpfile1 will contain text.
*/
mktemp(reffile);
rfd = fopen(reffile,"w+");
if (rfd == NULL)
error("can't open temporary reference file");
putc('x', rfd); /* put garbage in first position (not used) */
! mktemp(tmpfile1);
! tfd = fopen(tmpfile1,"w");
if (tfd == NULL)
error("can't open temporary output file");
***************
*** 98,104 ****
*/
fclose(tfd);
! tfd = fopen(tmpfile,"r");
if (tfd == NULL)
error("can't open temporary output file for reading");
--- 105,111 ----
*/
fclose(tfd);
! tfd = fopen(tmpfile1,"r");
if (tfd == NULL)
error("can't open temporary output file for reading");
***************
*** 114,125 ****
fclose(tfd);
fclose(rfd);
! unlink(tmpfile);
unlink(reffile);
exit(0);
}
/* rdtext - read and process a text file, looking for [. commands */
rdtext(fd)
FILE *fd;
{ char lastc, c, d;
--- 121,133 ----
fclose(tfd);
fclose(rfd);
! unlink(tmpfile1);
unlink(reffile);
exit(0);
}
/* rdtext - read and process a text file, looking for [. commands */
+ void
rdtext(fd)
FILE *fd;
{ char lastc, c, d;
***************
*** 164,172 ****
}
/* rdcite - read citation information inside a [. command */
! rdcite(fd, ch)
! FILE *fd;
! char ch;
{ long int n, getref();
char huntstr[HUNTSIZE], c, info[HUNTSIZE];
--- 172,178 ----
}
/* rdcite - read citation information inside a [. command */
! static void rdcite(FILE *fd, char ch)
{ long int n, getref();
char huntstr[HUNTSIZE], c, info[HUNTSIZE];
***************
*** 235,240 ****
--- 241,247 ----
}
/* addc - add a character to hunt string */
+ static void
addc(huntstr, c)
char huntstr[HUNTSIZE], c;
{ int i;
Index: bib/source/bib.h
diff -c bib/source/bib.h:1.1.1.1 bib/source/bib.h:1.3
*** bib/source/bib.h:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/bib.h Sat May 24 10:37:42 2003
***************
*** 18,43 ****
/* output of invert, input file for references */
# define INDXFILE "INDEX"
/* pass1 reference collection file */
! # define TMPREFFILE "/usr/tmp/bibrXXXXXX"
/* pass2 text collection file */
! # define TMPTEXTFILE "/usr/tmp/bibpXXXXXX"
/* temp file used in invert */
! # define INVTEMPFILE "/usr/tmp/invertXXXXXX"
/* common words */
! # define COMFILE "/users/budd/Distrib/sources/bib/bmac/common"
/* default system dictionary */
! # define SYSINDEX "/users/budd/Distrib/sources/bib/docs/INDEX"
/* where macro libraries live */
! # define BMACLIB "/users/budd/Distrib/sources/bib/bmac"
/* default style of references */
! # define DEFSTYLE "/users/budd/Distrib/sources/bib/bmac/bib.stdsn"
/* size limits */
/* maximum number of characters in common file */
# define MAXCOMM 1000
-
- char *malloc();
/* fix needed for systems where open [w]+ doesn't work */
# ifdef READWRITE
--- 18,43 ----
/* output of invert, input file for references */
# define INDXFILE "INDEX"
/* pass1 reference collection file */
! # define TMPREFFILE "/tmp/bibrXXXXXX"
/* pass2 text collection file */
! # define TMPTEXTFILE "/tmp/bibpXXXXXX"
/* temp file used in invert */
! # define INVTEMPFILE "/tmp/invertXXXXXX"
!
! #define BIBBASE "../"
/* common words */
! # define COMFILE BIBBASE "bmac/common"
/* default system dictionary */
! # define SYSINDEX BIBBASE "docs/INDEX"
/* where macro libraries live */
! # define BMACLIB BIBBASE "bmac"
/* default style of references */
! # define DEFSTYLE BIBBASE "bmac/bib.stdsn"
/* size limits */
/* maximum number of characters in common file */
# define MAXCOMM 1000
/* fix needed for systems where open [w]+ doesn't work */
# ifdef READWRITE
Index: bib/source/bibargs.c
diff -c bib/source/bibargs.c:1.1.1.1 bib/source/bibargs.c:1.2
*** bib/source/bibargs.c:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/bibargs.c Sat May 24 10:37:42 2003
***************
*** 347,352 ****
--- 347,353 ----
}
/* error - report unrecoverable error message */
+ void
error(str)
char str[];
{
Index: bib/source/invert.c
diff -c bib/source/invert.c:1.1.1.1 bib/source/invert.c:1.3
*** bib/source/invert.c:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/invert.c Sat May 24 10:37:42 2003
***************
*** 3,9 ****
output: key:file1 start/length ... start/length:file2 start/length ...
*/
! # include "stdio.h"
# include "streams.h"
# include "bib.h"
# define isnull(x) (*(x) == NULL)
--- 3,11 ----
output: key:file1 start/length ... start/length:file2 start/length ...
*/
! # include <stdio.h>
! # include <stdlib.h>
! # include <unistd.h>
# include "streams.h"
# include "bib.h"
# define isnull(x) (*(x) == NULL)
***************
*** 18,24 ****
char *INDEX= /* name of output file */
INDXFILE;
! char *tmpfile = /* name of temporary file */
INVTEMPFILE;
int silent = 0; /* 0 => statistics printed */
--- 20,26 ----
char *INDEX= /* name of output file */
INDXFILE;
! char tmpname[] = /* name of temporary file */
INVTEMPFILE;
int silent = 0; /* 0 => statistics printed */
***************
*** 31,36 ****
--- 33,43 ----
int argc;
char **argv;
+
+ static void flags(void);
+
+
+ int
main(argcount,arglist)
int argcount;
char **arglist;
***************
*** 48,55 ****
argc= argcount-1;
argv= arglist+1;
! mktemp(tmpfile);
! output= fopen(tmpfile,"w");
for ( flags() ; argc>0 ; argc--, argv++ ,flags() )
{ /* open input file */
--- 55,66 ----
argc= argcount-1;
argv= arglist+1;
! mktemp(tmpname);
! output= fopen(tmpname,"w");
! if(!output) {
! perror("invert: failed to open tmpfile");
! return 1;
! }
for ( flags() ; argc>0 ; argc--, argv++ ,flags() )
{ /* open input file */
***************
*** 69,80 ****
records++;
kcnt= 0;
length= recsize(input,start);
! sprintf(tag_line, " %s %D %D\n", filename, start, length);
while (ftell(input) < start+length && kcnt < max_kcnt)
{ getword(input,word,ignore);
makekey(word,max_klen,common);
! if (!isnull(word))
{ fputs(word,output); fputs(tag_line,output);
kcnt++; keys++;
}
--- 80,91 ----
records++;
kcnt= 0;
length= recsize(input,start);
! sprintf(tag_line, " %s %ld %ld\n", filename, start, length);
while (ftell(input) < start+length && kcnt < max_kcnt)
{ getword(input,word,ignore);
makekey(word,max_klen,common);
! if (word[0])
{ fputs(word,output); fputs(tag_line,output);
kcnt++; keys++;
}
***************
*** 84,96 ****
}
fclose(output);
! sprintf(sortcmd, sort_it, tmpfile, tmpfile);
system(sortcmd);
! distinct = shorten(tmpfile,INDEX);
if( silent == 0 )
fprintf(stderr,
! "%D documents %D distinct keys %D key occurrences\n",
records, distinct, keys);
exit(0);
}
--- 95,107 ----
}
fclose(output);
! sprintf(sortcmd, sort_it, tmpname, tmpname);
system(sortcmd);
! distinct = shorten(tmpname,INDEX);
if( silent == 0 )
fprintf(stderr,
! "%ld documents %ld distinct keys %ld key occurrences\n",
records, distinct, keys);
exit(0);
}
***************
*** 111,117 ****
# define operand (strlen(*argv+2)==0 ? (argv++,argc--,*argv) : *argv+2)
! flags()
{ for (; argc>0 && *argv[0]=='-'; argc--,argv++)
{ switch ((*argv)[1])
{ case 'k': max_kcnt= atoi(operand);
--- 122,128 ----
# define operand (strlen(*argv+2)==0 ? (argv++,argc--,*argv) : *argv+2)
! static void flags(void)
{ for (; argc>0 && *argv[0]=='-'; argc--,argv++)
{ switch ((*argv)[1])
{ case 'k': max_kcnt= atoi(operand);
***************
*** 157,178 ****
}
getline(in,line);
! sscanf(line,"%s%s%D%D", key, file, &start, &length);
! fprintf(out, "%s :%s %D/%D", key, file, start, length);
for ( getline(in, line) ; !feof(in); getline(in, line))
! { sscanf(line,"%s%s%D%D", newkey, newfile, &start, &length);
if (strcmp(key,newkey)!=0)
{ strcpy(key, newkey);
strcpy(file, newfile);
! fprintf(out, "\n%s :%s %D/%D", key, file, start, length);
lines++;
}
else if (strcmp(file,newfile)!=0)
{ strcpy(file,newfile);
! fprintf(out, ":%s %D/%D", file, start, length);
}
else
! fprintf(out, " %D/%D", start, length);
}
fprintf(out, "\n");
lines++;
--- 168,189 ----
}
getline(in,line);
! sscanf(line,"%s%s%ld%ld", key, file, &start, &length);
! fprintf(out, "%s :%s %ld/%ld", key, file, start, length);
for ( getline(in, line) ; !feof(in); getline(in, line))
! { sscanf(line,"%s%s%ld%ld", newkey, newfile, &start, &length);
if (strcmp(key,newkey)!=0)
{ strcpy(key, newkey);
strcpy(file, newfile);
! fprintf(out, "\n%s :%s %ld/%ld", key, file, start, length);
lines++;
}
else if (strcmp(file,newfile)!=0)
{ strcpy(file,newfile);
! fprintf(out, ":%s %ld/%ld", file, start, length);
}
else
! fprintf(out, " %ld/%ld", start, length);
}
fprintf(out, "\n");
lines++;
Index: bib/source/makekey.c
diff -c bib/source/makekey.c:1.1.1.1 bib/source/makekey.c:1.2
*** bib/source/makekey.c:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/makekey.c Sat May 24 10:37:42 2003
***************
*** 1,19 ****
#
! # include "stdio.h"
! # include "ctype.h"
# include "bib.h"
char commlist[MAXCOMM]= /* list of strings of common words */
"";
int firsttime = 1;
/* makekey(p,max_klen,common): compresses *p into a key
folds upper to lower case. ignores non-alphanumeric
drops keys of length <= 1.
drops words in common (name of file of words, one per line)
(first call determines common for all later calls)
*/
makekey(p,max_klen,common)
char *p;
int max_klen; /* max key length */
--- 1,24 ----
#
! # include <stdio.h>
! # include <ctype.h>
# include "bib.h"
+ # include "streams.h"
char commlist[MAXCOMM]= /* list of strings of common words */
"";
int firsttime = 1;
+ static void load_comm(char *common);
+ static int lookup(char *list, char*p);
+
/* makekey(p,max_klen,common): compresses *p into a key
folds upper to lower case. ignores non-alphanumeric
drops keys of length <= 1.
drops words in common (name of file of words, one per line)
(first call determines common for all later calls)
*/
+ void
makekey(p,max_klen,common)
char *p;
int max_klen; /* max key length */
***************
*** 23,44 ****
if (firsttime) {firsttime= 0; load_comm(common); }
from= p; to= p; stop= max_klen+p;
! while (*from != NULL && to < stop)
{ if (islower(*from)) *to++ = *from++;
else if (isdigit(*from)) *to++ = *from++;
else if (isupper(*from)) { *to++ = tolower(*from); from++; }
else from++;
}
! *to= NULL;
if (to<=p+1 ||
! lookup(commlist, p) ) *p= NULL;
}
/* list is a string of null terminated strings, final string is null.
p is a null terminated string.
return 1 if p is a string in list, 0 ow.
*/
int lookup(list,p)
char *list, *p;
{ int len;
--- 28,50 ----
if (firsttime) {firsttime= 0; load_comm(common); }
from= p; to= p; stop= max_klen+p;
! while (*from && to < stop)
{ if (islower(*from)) *to++ = *from++;
else if (isdigit(*from)) *to++ = *from++;
else if (isupper(*from)) { *to++ = tolower(*from); from++; }
else from++;
}
! *to= 0;
if (to<=p+1 ||
! lookup(commlist, p) ) *p= 0;
}
/* list is a string of null terminated strings, final string is null.
p is a null terminated string.
return 1 if p is a string in list, 0 ow.
*/
+ static
int lookup(list,p)
char *list, *p;
{ int len;
***************
*** 52,57 ****
--- 58,64 ----
/* read file common into commlist
*/
+ static void
load_comm(common)
char *common;
{ FILE *commfile; /* stream of common words */
***************
*** 62,74 ****
{ /* read commfile into commlist */
p= commlist; stop= commlist+MAXCOMM-1;
while (p<stop && ((*p= getc(commfile))!=EOF))
! { if (*p=='\n') *p= NULL;
p++;
}
! if (*p==EOF) *p= NULL;
else
{ fprintf(stderr, "invert: too many common words\n");
! commlist[0]= NULL;
}
fclose(commfile);
}
--- 69,81 ----
{ /* read commfile into commlist */
p= commlist; stop= commlist+MAXCOMM-1;
while (p<stop && ((*p= getc(commfile))!=EOF))
! { if (*p=='\n') *p= 0;
p++;
}
! if (*p==EOF) *p= 0;
else
{ fprintf(stderr, "invert: too many common words\n");
! commlist[0]= 0;
}
fclose(commfile);
}
Index: bib/source/streams.c
diff -c bib/source/streams.c:1.1.1.1 bib/source/streams.c:1.2
*** bib/source/streams.c:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/streams.c Sat May 24 10:37:42 2003
***************
*** 1,8 ****
#
! # include "stdio.h"
# include "streams.h"
! # include "ctype.h"
/* getword(stream,p,ignore):
read next sequence of nonspaces on current line into *p.
--- 1,9 ----
#
! # include <stdio.h>
# include "streams.h"
! # include <ctype.h>
! # include <string.h>
/* getword(stream,p,ignore):
read next sequence of nonspaces on current line into *p.
***************
*** 11,17 ****
all words of the form %a are returned as null.
*p is a null terminated string (char p[maxstr]).
*/
! getword(stream,p,ignore)
FILE *stream;
char *p, *ignore;
{ char c;
--- 12,18 ----
all words of the form %a are returned as null.
*p is a null terminated string (char p[maxstr]).
*/
! void getword(stream,p,ignore)
FILE *stream;
char *p, *ignore;
{ char c;
***************
*** 27,36 ****
if (p < stop) p++;
c= getc(stream);
}
! *p= NULL;
if (oldp[0]=='%')
! { oldp[0]= NULL;
if (index(ignore, oldp[1]) != NULL)
while (c!='\n') c=getc(stream);
}
--- 28,37 ----
if (p < stop) p++;
c= getc(stream);
}
! *p= 0;
if (oldp[0]=='%')
! { oldp[0]= 0;
if (index(ignore, oldp[1]) != NULL)
while (c!='\n') c=getc(stream);
}
***************
*** 110,115 ****
--- 111,117 ----
/* printline(stream): copies stream up to a newline
*/
+ void
printline(stream)
FILE *stream;
{ char c;
***************
*** 121,126 ****
--- 123,129 ----
advance stream past \n.
limit of maxstr-1 chars may be stored at p.
*/
+ void
getline(stream,p)
FILE *stream;
char *p;
***************
*** 128,132 ****
stop= p+maxstr-1;
while ( (*p= getc(stream)) != '\n' && *p!=EOF)
if (p<stop) p++;
! *p= NULL;
}
--- 131,135 ----
stop= p+maxstr-1;
while ( (*p= getc(stream)) != '\n' && *p!=EOF)
if (p<stop) p++;
! *p= 0;
}
Index: bib/source/streams.h
diff -c bib/source/streams.h:1.1.1.1 bib/source/streams.h:1.2
*** bib/source/streams.h:1.1.1.1 Wed May 7 16:31:01 2003
--- bib/source/streams.h Sat May 24 10:37:42 2003
***************
*** 2,7 ****
--- 2,11 ----
long int nextrecord(), recsize(), nextline();
+ void getword();
+ void makekey();
+ void getline();
+
# define maxstr 256
# define pos(x) fseek(stream,x,0)
--
// Jörgen Grahn "And then the design was ignored, and small children
\X/ <address@hidden> with crayons were given the O'Reilly Perl books and
told to Create. And lo, it was done."
-- Teo de H, in ASR