Added the scanning of command line arguments.
authorArjen Baart <arjen@andromeda.nl>
Wed, 18 May 2011 15:34:38 +0000 (17:34 +0200)
committerArjen Baart <arjen@andromeda.nl>
Wed, 18 May 2011 15:34:38 +0000 (17:34 +0200)
The input file of bank mutations is now named in a command line argument
instead of always using a file named 'mut.txt'.

bank.cpp

index 8e46444..f81cd14 100644 (file)
--- a/bank.cpp
+++ b/bank.cpp
@@ -16,6 +16,7 @@
 #include <vector>
 #include <AXE/String.h>
 #include <AXE/date.h>
+#include <getopt.h>
 
 class BankTemplate
 {
@@ -131,12 +132,54 @@ const int DESCRIP4     = 13;
 const int DESCRIP5     = 14;
 const int DESCRIP6     = 15;
 
-main()
+static char  helptext[] = 
+     "Usage: bank [options] filename\n"
+     "\n"
+     "Options:\n"
+     "  --help               :  Print this helpful message\n"
+     "  -V\n"
+     "  --version            :  Print the version number\n";
+
+static struct option long_options[] =
+{
+   { "help",       no_argument,        0,   'h' },
+   { "version",    no_argument,        0,   'V' },
+   { 0, 0, 0, 0 }
+};
+
+main(int argc, char *argv[])
 {
+   int      c;
+
+   int      option_index = 0;
+
+   while ((c = getopt_long(argc, argv, "hV", long_options, &option_index)) != -1)
+   {
+      switch (c)
+      {
+      case 'h':
+         std::cout << helptext;
+         exit(0);
+         break;
+
+      case 'V':
+         std::cout << "bank version 1.1\n";
+         exit(0);
+         break;
+
+      }
+   }
+
+   if (optind == argc)
+   {
+      std::cerr << "Usage: bank [options] filename\n";
+      exit(1);
+   }
+
    //read_templates("Bank.templ");
    std::vector<BankTemplate> templates = read_templates("Bank.templ");
 
-   read_mutations("mut.txt", templates);
+   read_mutations(argv[optind], templates);
 }
 
 std::vector<BankTemplate> read_templates(const char * filename)