increase version number to 0.1
[ecparse.git] / Main.cpp
1 /**
2  * © 2008 by David Roden <droden@gmail.com>
3  */
4
5 #include <string.h>
6 #include "Main.h"
7
8 void printSyntaxHelp() {
9         printf("ecparse %s - © 2008 by David ‘Bombe’ Roden <bombe@pterodactylus.net\n", VERSION);
10         printf("ecparse [ -v | --verbose ] [ { -f | --file } <file> ]\n");
11 }
12
13 int main(int argc, char** argv) {
14         FileReaderInput* fileReaderInput;
15         CollectionReader* collectionReader;
16         char* currentArgument;
17         char* fileToOpen = NULL;
18         FILE* file = NULL;
19         int argumentIndex;
20         ED2KLink* nextLink = NULL;
21
22         for (argumentIndex = 1; argumentIndex < argc; argumentIndex++) {
23                 currentArgument = argv[argumentIndex];
24                 if (!strcmp("--help", currentArgument) || !strcmp("-h", currentArgument)) {
25                         printSyntaxHelp();
26                 } else if (!strcmp("--verbose", currentArgument) || !strcmp("-v", currentArgument)) {
27                         GlobalSettings::setVerbose(true);
28                 } else if (!strcmp("--file", currentArgument) || !strcmp("-f", currentArgument)) {
29                         fileToOpen = argv[++argumentIndex];
30                 } else {
31                         printf("Unknown Parameter: %s\n", currentArgument);
32                         return 1;
33                 }
34         }
35
36         if (fileToOpen) {
37                 file = fopen(fileToOpen, "r");
38                 fileReaderInput = new FileReaderInput(file);
39         } else {
40                 fileReaderInput = new FileReaderInput(stdin);
41         }
42
43         collectionReader = new CollectionReader(fileReaderInput);
44         while ((nextLink = collectionReader->getNextLink())) {
45                 printf("%s\n", nextLink->getLink());
46         }
47
48         if (file) {
49                 fclose(file);
50         }
51
52         return 0;
53 }
54