syntax help and some cmd-line parsing
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 5 Jul 2008 12:47:46 +0000 (14:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 5 Jul 2008 12:47:46 +0000 (14:47 +0200)
Main.cpp

index aa44bdc..364d62b 100644 (file)
--- a/Main.cpp
+++ b/Main.cpp
@@ -2,11 +2,34 @@
  * © 2008 by David Roden <droden@gmail.com>
  */
 
+#include <string.h>
 #include "Main.h"
 
+void printSyntaxHelp() {
+       printf("ecparse %s - © 2008 by David ‘Bombe’ Roden <bombe@pterodactylus.net\n", VERSION);
+       printf("ecparse [ -v | --verbose ] [ { -f | --file } <file> ]\n");
+}
+
 int main(int argc, char** argv) {
        FileReaderInput* fileReaderInput;
        CollectionReader* collectionReader;
+       char* currentArgument;
+       char* fileToOpen = NULL;
+       int argumentIndex;
+
+       for (argumentIndex = 1; argumentIndex < argc; argumentIndex++) {
+               currentArgument = argv[argumentIndex];
+               if (!strcmp("--help", currentArgument) || !strcmp("-h", currentArgument)) {
+                       printSyntaxHelp();
+               } else if (!strcmp("--verbose", currentArgument) || !strcmp("-v", currentArgument)) {
+                       GlobalSettings::getInstance()->setVerbose(true);
+               } else if (!strcmp("--file", currentArgument) || !strcmp("-f", currentArgument)) {
+                       fileToOpen = currentArgument;
+               } else {
+                       printf("Unknown Parameter: %s\n", currentArgument);
+                       return 1;
+               }
+       }
 
        return 0;
 }