steps.push_back(pair<string, int> (msg.str(), commands.size()));
cout << "Doing " << msg.str() << endl; logFile << timeStr() << "Doing " << msg.str() << endl;
int main(int argc, char ** argv){  if (!GetOptions(argc, argv)){    cerr << "Command line parsing failed, use -h option for usage info" 	 << endl;    //printHelpText();    finish(1);  }  char * amosConf;  if (globals.find("conffile") == globals.end()){    amosConf = getenv("AMOSCONF");    if (amosConf == NULL){      cerr << "A configuration file must be passed either through command line\n"	"option -C or through environment variable AMOSCONF" << endl;      finish(1);    }    confFile = string(amosConf);  } else     confFile = globals["conffile"];  vector<pair<string, int> > steps; //steps that will be executed  vector<string> commands; // commands that will be executed  ifstream conf(confFile.c_str());  if (! conf.is_open()){    cerr << "Could not open config file " << confFile << endl;    finish(1);  }  if (variables.find("PREFIX") != variables.end()){    logFile.open((variables["PREFIX"] + ".runAmos.log").c_str(), ios::out);    logFileName = variables["PREFIX"] + ".runAmos.log";  } else {    logFile.open("runAmos.log", ios::out);    logFileName = "runAmos.log";  }  if (!logFile.is_open()){    cerr << "Cannot open logfile!" << endl;    finish(1);  } else {    cout << "The log file is: " << logFileName << endl;  }  logFile.setf(ios::unitbuf);  // make sure buffer flushes on endls  if (globals.find("start") != globals.end() &&      globals.find("end") != globals.end()){      if (strtol(globals["start"].c_str(), NULL, 10) > 	  strtol(globals["end"].c_str(), NULL, 10)){	logFile << timeStr() << "Start must be less than end\n" << endl;	finish(1);      }  }  string line;  int lineno = 0;  string message;  bool multiline = false;  bool continuation = false;  string outline = "";  int currstep = -1;  int step;  int noscan;// where scanf stops  time_t start;  bool noop = false;  allstart = time(NULL);  while (getline(conf, line)){    lineno++;    if (line.length() > 1 && line[0] == '#' && line[1] == '#'){ // message - will be saved      message = line.substr(2);      continue;    }     if (line.length() > 0 && line[0] == '#')      continue; // comment        bool space = true;    for (int i = 0; i < line.length(); i++)      if (! isspace(line[i])){	space = false;	break;      }    if (space)      continue; // skip empty lines    int numvars;    if (sscanf(line.c_str(), "EXPECT %d", &numvars) == 1){      //      cout << "Expecting " << numvars << endl;      if (cmdLnVars.size() < numvars){	cerr << "Expecting " << numvars 	     << " parameters. Try -h for usage info" <<endl;	finish(1);      }      continue;    }     if (multiline){ // part of a multi-line command      if (line.length() == 1 && line[0] == '.'){ // end multiline	multiline = false;	noop = false;	if (continuation){	  commands.push_back(outline);	}	continuation = false;	outline = "";	continue;      }      if (! noop){	if (line.substr(line.size() - 1) == "\\"){ // is continuation line	  outline += line.substr(0, line.size() - 1);	  continuation = true;	} else if (continuation){	  outline += line;	  commands.push_back(outline);	  outline = "";	  continuation = false;	} else 	  commands.push_back(line);      }      continue;    } // multiline command    if (sscanf(line.c_str(), "%d : %n", &step, &noscan) >= 1 ) {// numbered command      if (step <= currstep){	logFile << timeStr() << "Steps appear out of order at line " << lineno 		<< " in " << confFile << endl;	cerr << "Steps appear out of order at line " << lineno 	     << " in " << confFile << endl;	finish(1);      } else 	currstep = step;                  if (globals.find("start") != globals.end() &&	  strtol(globals["start"].c_str(), NULL, 10) > currstep)	noop =  true;      if (globals.find("end") != globals.end() &&	  strtol(globals["end"].c_str(), NULL, 10) < currstep)	noop = true;              if (! noop) {	ostringstream msg;	msg << "step " << step;	if (message.length() != 0){	  msg << ": " << message;	  message = "";	}	steps.push_back(pair<string, int> (msg.str(), commands.size()));      }            if (line.substr(noscan).length() == 0) {// multiline command	multiline = true;	continue;      } else { 	if (! noop)	  commands.push_back(line.substr(noscan));	noop = false;      }            continue;    } // numbered commands         char varname[MAX_STRING];    char c;     if (sscanf(line.c_str(), "%[a-zA-Z0-9_-] %c %n", varname, &c, &noscan) >= 2 && c == '='){      //      cout << line << " is variable definition \n";       processDefn(line); // variable definition      continue;    }    logFile << timeStr() << "Cannot parse line " << lineno << " in " 	    << confFile << ":" << endl << line << endl;    cerr << "Cannot parse line " << lineno << " in " 	 << confFile << endl;    finish(1);  } // while each line in configuration file  // before running make sure everything is kosher  if (globals.find("ocd") != globals.end()){    globals.erase("ocd");    checkFiles();  }  for (int vi = 0; vi < steps.size(); vi++){    int lastcmd;    start = time(NULL);    cout << "Doing " << steps[vi].first << endl;    logFile << timeStr() << "Doing " << steps[vi].first << endl;    if (vi == steps.size() - 1)      lastcmd = commands.size();    else      lastcmd = steps[vi + 1].second;        for (int ci = steps[vi].second; ci < lastcmd; ci++)      doCommand(commands[ci]);    logFile << timeStr() << "Done! Elapsed time:" 	    << elapsed(time(NULL) - start) << endl;  }  if (globals.find("clean") != globals.end())    cleanFiles();  // successful end  finish(0);}// main