3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * GROningen Mixture of Alchemy and Childrens' Stories
44 #include "gmx_fatal.h"
47 gmx_bool
get_a_line(FILE *fp
,char line
[],int n
)
55 if (!fgets(line0
,n
+1,fp
)) {
59 dum
=strchr(line0
,'\n');
62 else if (strlen(line0
)==n
) {
63 fprintf(stderr
,"Warning: line length exceeds buffer length (%d), data might be corrupted\n",n
);
66 fprintf(stderr
,"Warning: file does not end with a newline, last line:\n%s\n",
68 dum
=strchr(line0
,';');
71 strncpy(line
,line0
,n
);
74 } while (dum
[0] == '\0');
80 gmx_bool
get_header(char line
[],char *header
)
82 char temp
[STRLEN
],*dum
;
91 gmx_fatal(FARGS
,"header is not terminated on line:\n'%s'\n",line
);
95 if (sscanf(temp
,"%s%*s",header
) != 1)
101 int get_strings(const char *db
,char ***strings
)
110 if (fscanf(in
,"%d",&nstr
) != 1) {
111 gmx_warning("File %s is empty",db
);
116 for(i
=0; (i
<nstr
); i
++) {
117 if(1 != fscanf(in
,"%s",buf
))
119 gmx_fatal(FARGS
,"Cannot read string from buffer");
122 fprintf(stderr
,"Have read: %s\n",buf
);
124 ptr
[i
] = strdup(buf
);
133 int search_str(int nstr
,char **str
,char *key
)
138 for(i
=0; (i
<nstr
); i
++)
139 if (gmx_strcasecmp(str
[i
],key
)==0)
145 int fget_lines(FILE *in
,char ***strings
)
152 pret
= fgets(buf
,255,in
);
153 if ( pret
==NULL
|| sscanf(buf
,"%d",&nstr
) != 1)
155 gmx_warning("File is empty");
161 for(i
=0; (i
<nstr
); i
++) {
163 ptr
[i
] = strdup(buf
);
171 int get_lines(const char *db
,char ***strings
)
177 nstr
= fget_lines(in
,strings
);
183 int get_file(const char *db
,char ***strings
)
193 while (fgets2(buf
,STRLEN
-1,in
)) {
198 ptr
[i
] = strdup(buf
);