| 1 | /* |
| 2 | * File: Arguments.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Oct 6, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "HerculesStudio.h" |
| 26 | #include "Arguments.h" |
| 27 | |
| 28 | #include <string> |
| 29 | |
| 30 | Arguments Arguments::instance; |
| 31 | |
| 32 | Arguments::Arguments() : |
| 33 | mHelp(false) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | Arguments::~Arguments() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | Arguments& Arguments::getInstance() |
| 42 | { |
| 43 | return instance; |
| 44 | } |
| 45 | |
| 46 | bool Arguments::helpRequested() const |
| 47 | { |
| 48 | return mHelp; |
| 49 | } |
| 50 | |
| 51 | const std::string& Arguments::configFileName() const |
| 52 | { |
| 53 | return mConfigFile; |
| 54 | } |
| 55 | |
| 56 | const std::string& Arguments::resourceFileName() const |
| 57 | { |
| 58 | return mResourceFile; |
| 59 | } |
| 60 | |
| 61 | int Arguments::parse(int argc, char * argv[]) |
| 62 | { |
| 63 | while(--argc) |
| 64 | { |
| 65 | argv++; |
| 66 | if (argv[0][0] != '-') return(-1); |
| 67 | |
| 68 | switch(argv[0][1]) |
| 69 | { |
| 70 | case('h'): |
| 71 | mHelp = true; |
| 72 | break; |
| 73 | |
| 74 | case('f'): |
| 75 | --argc; |
| 76 | ++argv; |
| 77 | if (argc > 0) mConfigFile = argv[0]; |
| 78 | break; |
| 79 | |
| 80 | case('r'): |
| 81 | --argc; |
| 82 | ++argv; |
| 83 | if (argc > 0) mResourceFile = argv[0]; |
| 84 | break; |
| 85 | |
| 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | hOutDebug(1,"resource file:'" << mResourceFile << "'"); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | void Arguments::printUsage() |
| 96 | { |
| 97 | hOutDebug(0, "Usage:" << "\n\n" |
| 98 | << "\tHerculesStudio [ -f <hercules-config-file> ] [ -r <hercules-run-commands-file> ] [ -h ]"); |
| 99 | } |
| 100 |