[Avida-SVN] r1176 - development/source/main

baerb at myxo.css.msu.edu baerb at myxo.css.msu.edu
Thu Jan 11 09:40:05 PST 2007


Author: baerb
Date: 2007-01-11 12:40:05 -0500 (Thu, 11 Jan 2007)
New Revision: 1176

Modified:
   development/source/main/cAvidaConfig.cc
   development/source/main/cAvidaConfig.h
Log:

Changed behaviour for when user uses the -c (or -g) command line option and the
file does not exist.  Now the program will stop instead of creating a new file 
with that name.  

If the user runs the program without specifing an avida config file and 
avida.cfg does not exist a new avida.cfg will be created using internal 
defaults.



Modified: development/source/main/cAvidaConfig.cc
===================================================================
--- development/source/main/cAvidaConfig.cc	2007-01-10 13:55:21 UTC (rev 1175)
+++ development/source/main/cAvidaConfig.cc	2007-01-11 17:40:05 UTC (rev 1176)
@@ -36,15 +36,24 @@
   }
 }
 
-void cAvidaConfig::Load(const cString & filename)
+void cAvidaConfig::Load(const cString & filename, 
+                        const bool & crash_if_not_found = false)
 {
   // Load the contents from the file.
   cInitFile init_file(filename);
   
   if (!init_file.IsOpen()) {
-    // If we failed to open the config file, try creating it.
-    cerr << "Warning: Unable to find file '" << filename << "'.  Creating default." << endl;
-    Print(filename);
+    if (crash_if_not_found) {
+      // exit the program if the requested configuration file is not found
+      cerr << "Warning: Unable to find file '" << filename 
+           << "'.  Ending the program." << endl;
+      exit(-1);
+    } else {
+      // If we failed to open the config file, try creating it.
+      cerr << "Warning: Unable to find file '" << filename 
+           << "'.  Creating default." << endl;
+      Print(filename);
+    }
   }
   
   init_file.Load();
@@ -77,6 +86,8 @@
   init_file.WarnUnused();
 }
 
+/* Routine to create an avida configuration file from internal default values */
+
 void cAvidaConfig::Print(const cString & filename)
 {
   ofstream fp(filename);
@@ -300,6 +311,7 @@
 cAvidaConfig* cAvidaConfig::LoadWithCmdLineArgs(int argc, char * argv[])
 {
   cString config_filename = "avida.cfg";
+  bool crash_if_not_found = false;
   tDictionary<cString> sets;
   
   int arg_num = 1;              // Argument number being looked at.
@@ -315,6 +327,7 @@
       exit(0);
     }
     config_filename = args[2];
+    crash_if_not_found = true;
     arg_num += 2;
   } else if (argc > 1 && (args[1] == "-g" || args[1] == "-genesis")) {
     cerr << "Warning: Use of -g[enesis] deprecated in favor of -c[onfig]." << endl;
@@ -323,12 +336,13 @@
       exit(0);
     }
     config_filename = args[2];
+    crash_if_not_found = true;
     arg_num += 2;
   }
   
   // Create Config object, load with values from configuration file
   cAvidaConfig* cfg = new cAvidaConfig();
-  cfg->Load(config_filename);
+  cfg->Load(config_filename, crash_if_not_found);
   
   // Then scan through and process the rest of the args.
   while (arg_num < argc) {

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-01-10 13:55:21 UTC (rev 1175)
+++ development/source/main/cAvidaConfig.h	2007-01-11 17:40:05 UTC (rev 1176)
@@ -305,7 +305,7 @@
 
 #endif
   
-  void Load(const cString& filename);
+  void Load(const cString& filename, const bool& crash_if_not_found);
   void Print(const cString& filename);
   void Status();
   void PrintReview();




More information about the Avida-cvs mailing list