/*--------------------------------------------------------------------------- ## \section{inspec2bibtex} ## ## \subsection*{Purpose} ## Convert inspec export data to bibtex format ## ## \subsection*{Description} ## Read inspec data from standard in and write bibtex data to standard ## out. ## ## \subsection*{Usage } ## \begin{verbatim} ## inspec2bibtex < inspec-file > bibtex-file ## \end{verbatim} ## ## \subsection*{Date created} ## 30 January 1994 +---------------------------------------------------------------------------+ | Trygve Randen | | Rogaland University Center, Dept. of Elect. and Computer Eng. | | P.O. Box 2557 Ullandhaug, 4004 Stavanger, Norway | | Tel.: +47 51 87 43 36, Fax.: +47 51 87 42 36 | | E-mail: tranden@hsr.no | +--------------------------------------------------------------------------*/ #include #include #define MAX_LINE_LEN 100 #define MAX_LINES 500 #define FALSE 0 #define TRUE 1 #define SUPPRESS 0 #define ADDRESS 1 #define ANNOTE 2 #define AUTHOR 3 #define BOOKTITLE 4 #define CHAPTER 5 #define EDITION 6 #define EDITOR 7 #define HOWPUBLISHED 8 #define INSTITUTION 9 #define JOURNAL 10 #define KEY 11 #define MONTH 12 #define NOTE 13 #define NUMBER 14 #define ORGANIZATION 15 #define PAGES 16 #define PUBLISHER 17 #define SCHOOL 18 #define SERIES 19 #define TITLE 20 #define TYPE 21 #define VOLUME 22 #define YEAR 23 #define _DOC_TYPE_ 50 #define _SUBMITTED_ 51 #define UNKNOWN_DOC_TYPE 0 #define BOOK 1 #define BOOK_CHAPTER 2 #define CONFERENCE_PAPER 3 #define CONFERENCE_PAPER_IN_JOURNAL 4 #define CONFERENCE_PROCEEDINGS 5 #define CONFERENCE_PROCEEDINGS_IN_JOURNAL 6 #define DISSERTATION 7 #define JOURNAL_PAPER 8 #define REPORT 9 #define REPORT_SECTION 10 typedef int Boolean; char * read_line(char *line) { return gets(line); } int read_record(char *lines) { Boolean contin=TRUE; Boolean blanks=TRUE; char line[MAX_LINE_LEN]; int line_no=0; /* Skip introducing blank lines and read first line of record */ while(contin && blanks) { contin=(read_line(line)!=NULL); blanks=(line[0]==0); } strcpy((lines+MAX_LINE_LEN*line_no++),line); while(contin && !blanks) { contin=(read_line(line)!=NULL); blanks=(line[0]==0); strcpy((lines+MAX_LINE_LEN*line_no++),line); } return line_no-1; } modify_author(char *str) { /* Replace `;' by `and' */ int i,j; char newstr[MAX_LINE_LEN]; j=0; for(i=0;i='0') j++; else j=0; if (j==4) break; } strncpy(year_str,&line[i-3],4); year_str[4]='\0'; year=atoi(year_str); if (year>2100 || year<1900) fprintf(stderr,"Year in illegal range: %d\n",year); return year; } extract_author_for_key(char *author, char *line) { int i; strncpy(author,line,5); author[5]='\0'; for(i=0; i<5; i++) { if(author[i]==',') author[i]='\0'; else if(author[i]==' ') author[i]='-'; else author[i]=tolower(author[i]); } } char * extract_word(char *word, char *line) { int i; strncpy(word,line,MAX_LINE_LEN); for (i=0; i