author | František Kučera <franta-hg@frantovo.cz> |
Sat, 28 Jul 2018 08:13:35 +0200 | |
branch | v_0 |
changeset 10 | 77593735b057 |
child 11 | 3798b6bc9aea |
permissions | -rw-r--r-- |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <locale.h> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <string> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <vector> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
#include <sstream> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <locale> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
#include <codecvt> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
using namespace std; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
namespace relpipe { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
namespace cli { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
class CLI { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
public: |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
CLI(int argc, char* argv[]) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
setlocale(LC_ALL, ""); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
this->argc = &argc; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
this->argv = &argv; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
program = convertor.from_bytes(argv[0]); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
for (int i = 1; i < argc; i++) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
args.insert(args.end(), convertor.from_bytes(argv[i])); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
CLI(const CLI& orig) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
virtual ~CLI() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
const wstring programName() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
return (const wstring) program; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
const vector<wstring> arguments() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
return (const vector<wstring>)args; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
static const int EXIT_CODE_SUCCESS = 0; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
static const int EXIT_CODE_UNEXPECTED_ERROR = 1; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
static const int EXIT_CODE_BAD_SYNTAX = 3; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
static const int EXIT_CODE_UNKNOWN_COMMAND = 4; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
static const int EXIT_CODE_DATA_ERROR = 5; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
private: |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
int* argc; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
char*** argv; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
wstring program; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
vector<wstring> args; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
}; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
} |