#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh ttb.c <<'END_OF_ttb.c' X#define about "tibtobib 0.3, 1989 by uf" X X#include X#include X X#define maxlines 50 X#define linelen 256 X#define ntypes 8 X#define ntags 18 X X#define article 0 X#define conference 1 X#define inbook 2 X#define mastersthesis 3 X#define phdthesis 4 X#define techreport 5 X#define book 6 X#define misc 7 X X#define HELP 0 X#define NOREF 10 X#define NOBIB 11 X#define BIGITEM 12 X#define NOCONT1 13 X#define NOCONT2 14 X#define BIGLINE 15 X#define BADTAG 16 X#define MEMFULL 17 X Xchar RCSHeader[]="$Header: /home/tex/local/ttb.c,v 1.3 90/02/15 14:55:30 sk Rel $"; X Xstatic char *inputtype[]={"ARTICLE","CONFERENCE","INBOOK","MASTERSTHESIS", X "PHDTHESIS","TECHREPORT","BOOK","MISC"}, X *recordtype[]={"AUTHOR","BOOKTITLE","ADDRESS","YEAR","EDITOR", X "PUBLISHER","JOURNAL","KEY","NUMBER","NOTE","PAGES", X "TYPE","SERIES","TITLE","VOLUME","COMMENT","ANNOTE", X "ABSTRACT"}, X allowedtag[]={'A','B','C','D','E','I','J','K','N','O','P','R','S','T','V', X '%','x','X'}, X organization[]="ORGANIZATION"; X X Xchar *item[maxlines],buffer[maxlines*linelen], X reffile[linelen],bibfile[linelen]; Xint curline=0,type,ilines; X XFILE *ref,*bib,*fopen(); X Xmain(argc,argv) Xint argc; Xchar **argv; X{ int notready; X X if (argc != 2) { X fprintf(stderr,"%s, usage: ttb \n",about); X exit(HELP); X } X X strcpy(reffile,argv[1]); X if ((ref=fopen(reffile,"r")) == NULL) { X sprintf(reffile,"%s.ref",argv[1]); X if ((ref=fopen(reffile,"r")) == NULL) { X fprintf(stderr,"ttb: can open neither %s nor %s\n",argv[1],reffile); X exit(NOREF); X } X } X X if (!strcmp(argv[1]+strlen(argv[1])-4,".ref")) X argv[1][strlen(argv[1])-4]='\0'; X sprintf(bibfile,"%s.bib",argv[1]); X if ((bib=fopen(bibfile,"w")) == NULL) { X fprintf(stderr,"ttb: can't open %s\n",bibfile); X exit(NOBIB); X } X X /* main loop */ X X do { X notready=getitem(); X type=classifyitem(); X /* printitem(); */ X putitem(); X } X while(notready); X X /* exit */ X X fclose(ref); X fclose(bib); X} X X Xgetitem() X{ char firstchar,secondchar; X int i,j,k,ok,ilm1,space,used,ignored=0; X X ilines = 0; X space = maxlines*linelen-1; X *item = buffer; X X while(!feof(ref)) { X X if (space<=0) { X fprintf(stderr,"ttb: %s, %d: buffer space exhausted\n",reffile,curline); X exit(MEMFULL); X } X X fgets(item[ilines++],space,ref); X ilm1 = ilines-1; X for (k=strlen(item[ilm1])-1; k>-1 && isspace(item[ilm1][k]); item[ilm1][k--]=0) X ; X /* printf("%s\n",item[ilm1]); */ X curline++; X X if (ilines>maxlines) { X fprintf(stderr,"ttb: %s, line %d: too many lines for this item, line ignored\n",reffile,curline); X ilines--; X continue; X } X X if (strlen(item[ilm1]) == 0) { /* blank line */ X ilines--; X ignored=0; X break; X } X X if ((firstchar=item[ilm1][0]) != '%') { /* continuation line */ X if (ilines == 1) { X fprintf(stderr,"ttb: %s, line %d: leading continuation line ignored\n",reffile,curline); X ilines--; X continue; X } X if (ignored) { X fprintf(stderr,"ttb: %s, line %d: continuation line ignored\n",reffile,curline); X ilines--; X continue; X } X X ilines--; X *(item[ilines]-1) = '\n'; X used = strlen(item[ilines])+1; X item[ilines] += used; X continue; X } X X secondchar = item[ilm1][1]; X ok = 0; X for (i=0; i 4) { X strcpy(author,item[p-1]+3); X author[i-4]=0; X } X else { X for (k=strlen(item[p-1]); k>2 && item[p-1][k] != ' ' && item[p-1][k] != '.'; k--) X ; X strcpy(author,item[p-1]+k+1); X } X } X else X strcpy(author,"Mr.X"); X X if (p=test('D')) X strcpy(year,item[p-1]+strlen(item[p-1])-2); X else X strcpy(year,"??"); X X if (p=test('P')) { X for (i=3; i0 ? ',' : ' '); X else X fprintf(bib,"@%s{%s%s:%s%c\n",inputtype[type],author,year,page,ilines>0 ? ',' : ' '); X X /* special cases: several authors, editors */ X X first = !0; X strcpy(author,""); X if (test('A')) { X for (i=0; ittb.1 <<'END_OF_ttb.1' X.TH TTB 1 "15-Feb-1990" X.SH NAME Xttb - tib to bibtex bibliography converter X X.SH SYNOPSIS X.B ttb X.IB file [.ref] X X.SH DESCRIPTION X.B ttb Xtakes as input a bibliography in tib format (see X.BR tib(5) ) Xand produces an equivalent bibliography for use with X.BR bibtex(1) Xin X.IB file .bib. X.PP XIf a X.B %K Xfield is present in the X.B .ref Xfile, it is used as X.I key Xfor a LaTeX \\cite command. XOtherwise the X.I key Xis made up from the author, year and page of the reference like this: X.I author year X.B : X.I page X.SH FILES X.TP 16 X~tex/local Xsource directory for ttb X.SH VERSION Xttb.c,v 1.3 X.PP XTo find out what version you are using, type X.IP X.B ident `which ttb` X.SH "SEE ALSO" X.B tib(1,5,7), bibtex(1) X X.SH AUTHOR XUlrich Fastenrath END_OF_ttb.1 if test 727 -ne `wc -c