4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_strdb_c
= "$Id$";
39 bool get_a_line(FILE *fp
,char line
[],int n
)
41 static char *line0
=NULL
;
47 srenew(line0
,nalloc
+1);
50 if (!fgets(line0
,n
+1,fp
)) {
53 dum
=strchr(line0
,'\n');
56 else if (strlen(line0
)==n
) {
57 fprintf(stderr
,"Warning: line length exceeds buffer length (%d), data might be corrupted\n",n
);
60 fprintf(stderr
,"Warning: file does end with a newline, last line:\n%s\n",
62 dum
=strchr(line0
,';');
68 } while (dum
[0] == '\0');
73 bool get_header(char line
[],char *header
)
75 char temp
[STRLEN
],*dum
;
84 fatal_error(0,"header is not terminated on line:\n'%s'\n",line
);
88 if (sscanf(temp
,"%s%*s",header
) != 1)
94 int get_strings(char *db
,char ***strings
)
103 set_warning_line(db
,1);
104 if (fscanf(in
,"%d",&nstr
) != 1) {
105 sprintf(warn_buf
,"File %s is empty",db
);
111 for(i
=0; (i
<nstr
); i
++) {
114 fprintf(stderr
,"Have read: %s\n",buf
);
116 ptr
[i
] = strdup(buf
);
125 int search_str(int nstr
,char **str
,char *key
)
130 for(i
=0; (i
<nstr
); i
++)
131 if (strcasecmp(str
[i
],key
)==0)
137 int fget_lines(FILE *in
,char ***strings
)
144 if (sscanf(buf
,"%d",&nstr
) != 1) {
145 sprintf(warn_buf
,"File is empty");
152 for(i
=0; (i
<nstr
); i
++) {
154 ptr
[i
] = strdup(buf
);
162 int get_lines(char *db
,char ***strings
)
167 set_warning_line(db
,1);
169 nstr
= fget_lines(in
,strings
);
175 int get_file(char *db
,char ***strings
)
185 while (fgets2(buf
,255,in
)) {
190 ptr
[i
] = strdup(buf
);