1 /* .................................................. */
2 /* ...   Input filter for Medline Pubmed format   ... */
3 /* ...   Last change 08.05.1997                   ... */
4 /* .................................................. */
5 
6 #include <iostream>
7 #include <fstream>
8 #include "biblio.h"
9 
Read_MedlinePubmed(char * fname,char * doct)10 int BIBLIO::Read_MedlinePubmed(char *fname, char *doct) {
11   std::ifstream      fin;
12   int           rc=0;
13   unsigned long n,i;
14   char          s[256], *ts, item[3];
15   short         limit_reached=0;
16 
17 
18   fin.open(fname);
19   if (!fin) {
20     std::cout << "Cannot open file: " << fname <<"\n";
21     rc=-1;
22     goto ende;
23   }
24 
25   /* Hauptschleife */
26   while(!fin.eof()) {
27     fin.getline(s,255);
28     // ******* neue Referenz *******;
29     if(s[0]=='U' && s[1]=='I'){
30       strcpy(item,"UI");
31       add_citation();
32       put_id(last,last);
33       if (strcmp(doct,"abstract")==0) {
34 	put_doctype(last,"article");
35 	put_note(last,"[Abstract]");
36       }
37       else if(strcmp(doct,"inpress")==0) {
38 	put_doctype(last,"article");
39 	put_note(last,"[in press]");
40       }
41       else put_doctype(last,doct);
42     };
43     // ******* Author **************;
44     if(s[0]=='A' && s[1]=='U') {
45       strcpy(item,"AU");
46       limit_reached=0;
47       ts=exright(6,s);
48       add_author(last,ts);
49     }    // ******* Editor **************;
50     if(s[0]=='E' && s[1]=='D') {
51       strcpy(item,"ED");
52       limit_reached=0;
53       ts=exright(6,s);
54       add_editor(last,ts);
55     }
56     // ******* Title ***************;
57     if(s[0]=='T' && s[1]=='I') {
58       strcpy(item,"TI");
59       limit_reached=0;
60       ts=exright(6,s);
61       put_title(last,ts);
62     }
63     // ******* Booktitle ***************;
64     if(s[0]=='B' && s[1]=='K') {
65       strcpy(item,"BK");
66       limit_reached=0;
67       ts=exright(6,s);
68       put_booktitle(last,ts);
69     }
70     // ******* Institution *********;
71     if(s[0]=='I' && s[1]=='N') {
72       strcpy(item,"IN");
73       limit_reached=0;
74       ts=exright(6,s);
75       put_institution(last,ts);
76     }
77     // ******* Address put in Comment ***************;
78     if(s[0]=='A' && s[1]=='D') {
79       strcpy(item,"AD");
80       limit_reached=0;
81       ts=exright(6,s);
82       put_comment(last,ts);
83     }
84     // ******* Abstract **************;
85     if(s[0]=='A' && s[1]=='B') {
86       strcpy(item,"AB");
87       limit_reached=0;
88       ts=exright(6,s);
89       if(strcmp(doct,"unpublished")==0)
90 	put_note(last,ts);
91       else put_abstract(last,ts);
92     }
93     // ******* Keyword ***************;
94     if((s[0]=='M' && s[1]=='H') || (s[0]=='L' && s[1]=='A') ||
95        (s[0]=='P' && s[1]=='T') || (s[0]=='D' && s[1]=='P') ||
96        (s[0]=='I' && s[1]=='S') || (s[0]=='C' && s[1]=='Y') ) {
97       strcpy(item,"MH");
98       limit_reached=0;
99       ts=exright(6,s);
100       add_keyword(last,ts);
101     }
102     // ******* Source ***************;
103     if(s[0]=='S' && s[1]=='O') {
104       strcpy(item,"SO");
105       limit_reached=0;
106       ts=exright(6,s);
107       i=strcspn(ts,";");
108       for(n=i;(isdigit(ts[n])==0 && n>0);n--);
109       i=n;
110       for(n=i;(isdigit(ts[n]) && n>0);n--) ;
111       for(i=n;(ts[i]==' ' && i>0);i--) ;
112       if (strcmp(c[last-1]->doctype,"article")==0)
113 	put_journal(last,ts,i+1);
114       if (strcmp(c[last-1]->doctype,"book")==0 ||
115 	  strcmp(c[last-1]->doctype,"inbook")==0)
116 	put_publisher(last,ts,i+1);
117       put_year(last,ts+n+1);
118       if(strchr(ts,';')) put_volume(last,strchr(ts,';')+1);
119       if(strchr(ts,':')) put_pages(last,strchr(ts,':')+1);
120     }
121     // ******* Space ***************;
122     if(s[0]==' ' && s[1]==' ') {
123       if(strcmp(item,"TI")==0) {
124 	ts=exright(6,s);
125 	n=strlen(c[last-1]->title)+1+strlen(ts)+1;
126 	c[last-1]->title=(char *)realloc(c[last-1]->title,n);
127 	strcat(c[last-1]->title,"\n");
128 	strcat(c[last-1]->title,ts);
129       }
130       if(strcmp(item,"BK")==0) {
131 	ts=exright(6,s);
132 	n=strlen(c[last-1]->booktitle)+1+strlen(ts)+1;
133 	c[last-1]->booktitle=(char *)realloc(c[last-1]->booktitle,n);
134 	strcat(c[last-1]->booktitle,"\n");
135 	strcat(c[last-1]->booktitle,ts);
136       }
137       if(strcmp(item,"IN")==0) {
138 	ts=exright(6,s);
139 	n=strlen(c[last-1]->institution)+1+strlen(ts)+1;
140 	c[last-1]->institution=(char *)realloc(c[last-1]->institution,n);
141 	strcat(c[last-1]->institution,"\n");
142 	strcat(c[last-1]->institution,ts);
143       }
144       if(strcmp(item,"AD")==0) {
145 	ts=exright(6,s);
146 	n=strlen(c[last-1]->comment)+1+strlen(ts)+1;
147 	c[last-1]->comment=(char *)realloc(c[last-1]->comment,n);
148 	strcat(c[last-1]->comment,"\n");
149 	strcat(c[last-1]->comment,ts);
150       }
151       if(strcmp(item,"AB")==0) {
152 	ts=exright(6,s);
153 	if (strcmp(doct,"unpublished")==0) {
154 	  n=strlen(c[last-1]->note)+1+strlen(ts)+1;
155 	  if (n<MAX_FIELD_LENGTH && !limit_reached) {
156 	    c[last-1]->note=(char *)realloc(c[last-1]->note,n);
157 	    strcat(c[last-1]->note,"\n");
158 	    strcat(c[last-1]->note,ts); }
159 	  else {limit_reached=1;}
160 	}
161 	else {
162 	  n=strlen(c[last-1]->abstract)+1+strlen(ts)+1;
163 	  if (n<MAX_FIELD_LENGTH && !limit_reached) {
164 	    c[last-1]->abstract=(char *)realloc(c[last-1]->abstract,n);
165 	    strcat(c[last-1]->abstract,"\n");
166 	    strcat(c[last-1]->abstract,ts); }
167 	  else {limit_reached=1;}
168 	}
169       }
170     }
171   }
172   fin.close();
173  ende:
174   return(rc);
175 }
176 
177