home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
gondwana.ecr.mu.oz.au/pub/
/
Graphics.tar
/
Graphics
/
papers
/
RTBib.10.90.Z
/
RTBib.10.90
/
roffbib.c
< prev
Wrap
C/C++ Source or Header
|
1991-02-06
|
2KB
|
107 lines
/*
* A very simple version of ROFFBIB
*
* Paul Heckbert, 1985
*/
#include <stdio.h>
typedef struct {
char *code,*pref,*post;
} reftrans;
static reftrans reftab[] = {
"%A", "", ",", /* author (possibly several) */
"%B", "\\fI", "\\fP,", /* book title */
"%C", "", ",", /* city */
"%D", "", ",", /* date */
"%E", "", " ed.,", /* editor of book */
"%G", "NTIS ", ",", /* government order number */
"%I", "", ",", /* issuer (publisher) */
"%J", "\\fI", "\\fP,", /* journal/magazine */
"%K", "{", "},", /* keywords */
"%N", "no. ", ",", /* number (vol 5 no 3) */
"%O", "(", "),", /* other (misc info) */
"%P", "pp. ", ",", /* pages */
"%R", "", ",", /* report number */
"%T", "``", "'',", /* title */
"%V", "vol. ", ",", /* volume */
"%Y", "[", "],", /* owner(s) of copy */
"%Z", "\\fI", "\\fP," /* comments */
};
#define NREF (sizeof reftab / sizeof reftab[0])
static int lno;
main(ac,av)
int ac;
char **av;
{
char line[500];
int i,j;
FILE *fp;
if (ac==1) fp = stdin;
else if ((fp = fopen(av[1],"r"))==NULL) {
fprintf(stderr,"Can't find %s\n",av[1]);
exit(1);
}
lno = 0;
while (!feof(fp)) {
for (j=0; getline(fp,line)>0; j++) {
if (strlen(line)<4 || line[0]!='%' || line[2]!=' ') {
fprintf(stderr,"line %d is (%s)\n",lno,line);
printf("\n%s\n",line);
continue;
}
for (i=0; i<NREF && line[1]!=reftab[i].code[1]; i++);
if (i>=NREF) {
fprintf(stderr,"line %d bad code (%s)\n",lno,line);
printf("\n%s\n",line);
continue;
}
if (j==0 && (line[1]=='A' || line[1]=='E'))
surfirst(line);
printf("%s%s%s\n",reftab[i].pref,line+3,reftab[i].post);
}
printf("\n");
}
fclose(fp);
}
getline(fp,str)
FILE *fp;
char *str;
{
char *s;
int c;
s = str;
do {
while ((c = getc(fp))!='\n' && c!=EOF) *s++ = c;
*s++ = ' ';
lno++;
} while ((*s++ = c = getc(fp))!='%' && c!='\n' && c!=EOF);
ungetc(c,fp);
s[-2] = 0;
return strlen(str);
}
surfirst(str0) /* put surname first */
char *str0;
{
char *str,*s,buf[500];
str = str0+3;
s = str+strlen(str)-1;
do {
while (s>=str && *s!=' ') s--;
} while (s>str && *--s==',');
if (s>str) {
s += 2;
s[-1] = 0;
sprintf(buf,"%%%c \\fB%s\\fP, %s",str0[1],s,str);
strcpy(str0,buf);
}
}