46 for (tmp=theList; tmp!= NULL; tmp = tmp ->
next) {
47 if (!strcasecmp(tmp->name, key))
60 char *temps =
new char[len1 + 1];
63 NAMD_die(
"new failed in ConfigList::add_element");
66 #ifndef NAMD_NO_STDOUT_FLUSH 69 strncpy(temps, s1, len1);
73 tmpList = find_key_word( temps);
74 if (tmpList == NULL ) {
76 if ( tmpList == NULL )
78 NAMD_die(
"new failed in ConfigList::add_element");
86 temps =
new char[len2 + 1];
89 NAMD_die(
"new failed in ConfigList::add_element");
92 strncpy(temps, s2, len2);
96 if ( newStrList == NULL )
98 NAMD_die(
"new failed in ConfigList::add_element");
100 newStrList ->
next = NULL;
101 if (tmpList -> data == NULL) {
102 tmpList -> data = newStrList;
105 while (tmpStrList ->
next != NULL)
106 tmpStrList = tmpStrList ->
next;
107 tmpStrList ->
next = newStrList;
147 char *filename =
new char[strlen(filename_in)+1];
148 strcpy(filename,filename_in);
156 if (!strcmp(filename,
"-")) {
159 if ( (infile =
Fopen(filename,
"r")) == NULL ) {
160 iout <<
iWARN <<
"Unable to open configuration file '" 161 << filename <<
"'.\n" <<
endi;
170 char *namestart, *nameend, *datastart, *dataend;
174 while ((fileok = ! ! fgets(buf, 999, infile)) || fileStack) {
175 if ( fileStack && ! fileok ) {
179 infile = fileStack->
file;
181 fileStack = fileStack->
next;
186 namestart = nameend = datastart = dataend = NULL;
189 for (s = buf; *s && *s!=
'\n'; s++) {
194 if ( !isspace(*s) && !namestart)
195 {namestart = s;
continue; }
196 if ( (isspace(*s) || *s ==
'=') &&
197 namestart && !nameend)
199 if ( !isspace(*s) && !datastart &&
201 if (*s ==
'=' && spacecount == 0)
202 {spacecount++;
continue; }
204 {datastart = s;
continue; }
210 iout <<
iWARN <<
"Line " << linenumber <<
" of configuration file " 211 << filename <<
" contains more than 999 characters." 212 <<
" Excess characters will be ignored.\n" <<
endi;
220 if (!namestart || !nameend || !datastart || !dataend) {
221 if (!namestart && datastart || namestart && !datastart) {
222 iout <<
iWARN <<
"Couldn't parse line " << linenumber <<
" in " 223 <<
"configuration file " << filename <<
". The line was: " 224 << buf <<
"\n" <<
endi;
229 if ( ! strncmp(namestart,
"source", nameend-namestart+1) ) {
236 newStack->
file = infile;
237 newStack->
next = fileStack;
238 fileStack = newStack;
241 char *cpychar =
new char[dataend-datastart+2];
242 strcpy(cpychar,datastart);
246 if ( (infile =
Fopen(filename,
"r")) == NULL ) {
248 << filename <<
"' sourced by '" 249 << fileStack->
filename <<
"' at line " 258 }
else if (datastart[0] ==
'{') {
261 std::ostringstream alldata;
265 int open_brace_count = 1;
266 char *newline = datastart;
267 strcat(newline,
"\n");
272 for (i=0; i<1000; i++) {
280 if (newline[i] ==
'\\' && ! escape_next) {
283 if (newline[i] ==
'{' && ! escape_next) {
286 if (newline[i] ==
'}' && ! escape_next) {
287 if ( ( found_end = ! --open_brace_count ) ) {
294 if (found_end)
break;
296 if ( ! fgets(newdata, 999, infile) )
break;
299 std::string alldatastr = alldata.str();
300 add_element(namestart, nameend-namestart+1, alldatastr.c_str(), alldata.str().length());
304 sprintf(newdata,
"configuration file ended early while parsing line " 305 "%d of keyword structure %s", linenumber, namestart);
310 add_element( namestart, nameend - namestart + 1, datastart,
311 dataend - datastart + 1 );
315 if (strcmp(filename,
"-")) {
344 tmpList = find_key_word(name);
346 return tmpList -> data;
351 #ifdef TEST_CONFIGLIST_C 352 #include <iostream.h> 361 NAMD_die(
"Can't continue - cannot get info from file.");
362 std::cout <<
"Searching for: 'fullname'\n";
363 strings = dat.find(
"fullname");
365 NAMD_die(
"Couldn't find fullname.\n");
369 std::cout << i <<
" = " << strings->
data <<
'\n';
370 strings = strings ->
next;
std::ostream & iINFO(std::ostream &s)
void add_element(const char *s1, int len1, const char *s2, int len2)
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
static Units next(Units u)
FILE * Fopen(const char *filename, const char *mode)
void NAMD_die(const char *err_msg)
int main(int argc, char *argv[])
StringList * find(const char *name) const