1 /* ................................................ */
2 /* ... Input filter for Medline Ovid format ... */
3 /* ... Last change 08.05.1997 ... */
4 /* ................................................ */
5
6 #include "biblio.h"
7 #include <iostream>
8 #include <fstream>
9
Read_MedlineOvid(char * fname,char * doct)10 int BIBLIO::Read_MedlineOvid(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(isdigit(s[0])){
30 add_citation();
31 put_id(last,last);
32 if (strcmp(doct,"abstract")==0) {
33 put_doctype(last,"article");
34 put_note(last,"[Abstract]");
35 }
36 else if(strcmp(doct,"inpress")==0) {
37 put_doctype(last,"article");
38 put_note(last,"[in press]");
39 }
40 else put_doctype(last,doct);
41 };
42 // ******* Author **************;
43 if(s[0]=='A' && s[1]=='U') {
44 strcpy(item,"AU");
45 limit_reached=0;
46 ts=exright(6,s);
47 add_author(last,ts);
48 } // ******* Editor **************;
49 if(s[0]=='E' && s[1]=='D') {
50 strcpy(item,"ED");
51 limit_reached=0;
52 ts=exright(6,s);
53 add_editor(last,ts);
54 }
55 // ******* Title ***************;
56 if(s[0]=='T' && s[1]=='I') {
57 strcpy(item,"TI");
58 limit_reached=0;
59 ts=exright(6,s);
60 put_title(last,ts);
61 }
62 // ******* Booktitle ***************;
63 if(s[0]=='B' && s[1]=='K') {
64 strcpy(item,"BK");
65 limit_reached=0;
66 ts=exright(6,s);
67 put_booktitle(last,ts);
68 }
69 // ******* Institution *********;
70 if(s[0]=='I' && s[1]=='N') {
71 strcpy(item,"IN");
72 limit_reached=0;
73 ts=exright(6,s);
74 put_institution(last,ts);
75 }
76 // ******* Abstract **************;
77 if(s[0]=='A' && s[1]=='B') {
78 strcpy(item,"AB");
79 limit_reached=0;
80 ts=exright(6,s);
81 if(strcmp(doct,"unpublished")==0)
82 put_note(last,ts);
83 else put_abstract(last,ts);
84 }
85 // ******* Keyword ***************;
86 if(s[0]=='M' && s[1]=='H') {
87 strcpy(item,"MH");
88 limit_reached=0;
89 ts=exright(6,s);
90 add_keyword(last,ts);
91 }
92 // ******* Source ***************;
93 if(s[0]=='S' && s[1]=='O') {
94 strcpy(item,"SO");
95 limit_reached=0;
96 ts=exright(6,s);
97 i=strcspn(ts,";");
98 for(n=i;(isdigit(ts[n])==0 && n>0);n--);
99 i=n;
100 for(n=i;(isdigit(ts[n]) && n>0);n--) ;
101 for(i=n;(ts[i]==' ' && i>0);i--) ;
102 if (strcmp(c[last-1]->doctype,"article")==0)
103 put_journal(last,ts,i+1);
104 if (strcmp(c[last-1]->doctype,"book")==0 ||
105 strcmp(c[last-1]->doctype,"inbook")==0)
106 put_publisher(last,ts,i+1);
107 put_year(last,ts+n+1);
108 if(strchr(ts,';')) put_volume(last,strchr(ts,';')+1);
109 if(strchr(ts,':')) put_pages(last,strchr(ts,':')+1);
110 }
111 // ******* Space ***************;
112 if(s[0]==' ' && s[1]==' ') {
113 if(strcmp(item,"TI")==0) {
114 ts=exright(6,s);
115 n=strlen(c[last-1]->title)+1+strlen(ts)+1;
116 c[last-1]->title=(char *)realloc(c[last-1]->title,n);
117 strcat(c[last-1]->title,"\n");
118 strcat(c[last-1]->title,ts);
119 }
120 if(strcmp(item,"BK")==0) {
121 ts=exright(6,s);
122 n=strlen(c[last-1]->booktitle)+1+strlen(ts)+1;
123 c[last-1]->booktitle=(char *)realloc(c[last-1]->booktitle,n);
124 strcat(c[last-1]->booktitle,"\n");
125 strcat(c[last-1]->booktitle,ts);
126 }
127 if(strcmp(item,"IN")==0) {
128 ts=exright(6,s);
129 n=strlen(c[last-1]->institution)+1+strlen(ts)+1;
130 c[last-1]->institution=(char *)realloc(c[last-1]->institution,n);
131 strcat(c[last-1]->institution,"\n");
132 strcat(c[last-1]->institution,ts);
133 }
134 if(strcmp(item,"AB")==0) {
135 ts=exright(6,s);
136 if (strcmp(doct,"unpublished")==0) {
137 n=strlen(c[last-1]->note)+1+strlen(ts)+1;
138 if (n<MAX_FIELD_LENGTH && !limit_reached) {
139 c[last-1]->note=(char *)realloc(c[last-1]->note,n);
140 strcat(c[last-1]->note,"\n");
141 strcat(c[last-1]->note,ts); }
142 else {limit_reached=1;}
143 }
144 else {
145 n=strlen(c[last-1]->abstract)+1+strlen(ts)+1;
146 if (n<MAX_FIELD_LENGTH && !limit_reached) {
147 c[last-1]->abstract=(char *)realloc(c[last-1]->abstract,n);
148 strcat(c[last-1]->abstract,"\n");
149 strcat(c[last-1]->abstract,ts); }
150 else {limit_reached=1;}
151 }
152 }
153 }
154 }
155 fin.close();
156 ende:
157 return(rc);
158 }
159
160