author | František Kučera <franta-hg@frantovo.cz> |
Thu, 29 Nov 2018 22:30:11 +0100 | |
branch | v_0 |
changeset 6 | 114521cca04a |
parent 2 | 117e4145fff8 |
child 7 | 95e647bf1922 |
permissions | -rw-r--r-- |
6 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
0
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
#pragma once |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
#include <locale.h> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <string> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <vector> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <sstream> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
#include <locale> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include <codecvt> |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
using namespace std; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
namespace relpipe { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
namespace cli { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
/** |
2 | 33 |
* a common header-only library for CLI programs |
0
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
*/ |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
class CLI { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
public: |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
CLI(int argc, char* argv[]) { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
setlocale(LC_ALL, ""); |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
this->argc = &argc; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
this->argv = &argv; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
program = convertor.from_bytes(argv[0]); |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
for (int i = 1; i < argc; i++) { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
args.insert(args.end(), convertor.from_bytes(argv[i])); |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
CLI(const CLI& orig) { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
virtual ~CLI() { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
const wstring programName() { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
return (const wstring) program; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
const vector<wstring> arguments() { |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
return (const vector<wstring>)args; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
static const int EXIT_CODE_SUCCESS = 0; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
static const int EXIT_CODE_UNEXPECTED_ERROR = 1; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
static const int EXIT_CODE_BAD_SYNTAX = 3; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
static const int EXIT_CODE_UNKNOWN_COMMAND = 4; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
static const int EXIT_CODE_DATA_ERROR = 5; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
private: |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
int* argc; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
char*** argv; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
wstring program; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
vector<wstring> args; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
}; |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
|
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
} |
00d1dd4f816a
create netbeans project, add CLI.h from relpipe-in-cli / relpipe-in-fstab projects
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
} |