From: Arjen Baart Date: Wed, 18 May 2011 15:34:38 +0000 (+0200) Subject: Added the scanning of command line arguments. X-Git-Url: http://www.andromeda.nl/gitweb/?p=account.git;a=commitdiff_plain;h=95e8c6e8f8c6387354647e18d3a86f87252a70c4 Added the scanning of command line arguments. The input file of bank mutations is now named in a command line argument instead of always using a file named 'mut.txt'. --- diff --git a/bank.cpp b/bank.cpp index 8e46444..f81cd14 100644 --- a/bank.cpp +++ b/bank.cpp @@ -16,6 +16,7 @@ #include #include #include +#include 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 templates = read_templates("Bank.templ"); - read_mutations("mut.txt", templates); + read_mutations(argv[optind], templates); } std::vector read_templates(const char * filename)