forked from An-dz/datSheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
62 lines (57 loc) · 2.42 KB
/
main.cc
File metadata and controls
62 lines (57 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream> // cout, cerr, clog, left, endl
#include <iomanip> // setw
#include <cstring> // strncmp
#include "xlsx.hh" // XLSX parser
#include "importer.hh" // XLSX importer
int main(int argc, char const *argv[])
{
int option = 0;
int files[256];
int num_files = 0;
// check passed arguments
for (int i = 1; i < argc; ++i) {
if (!std::strncmp(argv[i], "-V", 3) || !std::strncmp(argv[i], "--version", 10)) {
option |= 1;
}
else if (!std::strncmp(argv[i], "-h", 3) || !std::strncmp(argv[i], "--help", 7)) {
option |= 2;
}
else if (!std::strncmp(argv[i], "-i", 3) || !std::strncmp(argv[i], "--import", 9)) {
option |= 4;
}
else if (argv[i][0] != '-') {
files[num_files++] = i;
}
}
// if no arguments were passed and no option was chosen
if ((num_files == 0 && option == 0) || (option == 4 && num_files < 2)) {
std::clog << "datSheet : No file error NFN:No file specified!\n";
return EXIT_FAILURE;
}
// if --help was seleced
if (option > 1 && option != 4) {
std::cout << "usage: datSheet [dir] <file(s)>\n\noptions:\n " << std::left << std::setw(15) << "-i --import" << "Create sheet file from one directory\n" << std::setw(15) << "-h --help" << "Display this help text\n " << std::setw(15) << "-V --version" << "Print version\n\nsupported file types: XLSX\n\nproject homepage: <https://github.com/An-dz/datSheet>\n";
return EXIT_SUCCESS;
}
// if --version was selected
if (option > 0 && option != 4) {
std::cout << "Simutrans datSheet " << VERSION << "\n Copyright (c) 2018 Andre' Zanghelini (An_dz)\n Project homepage: <https://github.com/An-dz/datSheet>\n\nA big thanks to the following libraries:\npugixml <https://pugixml.org>\n Copyright (c) 2006-2018 Arseny Kapoulkine.\nlibzip <https://libzip.org/>\n Copyright (c) 1999-2018 Dieter Baron and Thomas Klausner\nlibzip++ <http://hg.markand.fr/libzip>\n Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>\nICU <http://site.icu-project.org/>\n Copyright (c) 1991-2018 Unicode, Inc. All rights reserved.\n";
return EXIT_SUCCESS;
}
try {
if (option == 0) {
for (int i = 0; i < num_files; ++i) {
XLSX xlsx(argv[files[i]]);
xlsx.parse();
}
}
else {
Importer xlsx(argv[files[1]]);
xlsx.import(argv[files[0]]);
}
std::cout << "Finished without errors.\n";
} catch (const std::runtime_error& e) {
std::cerr << "datSheet : error " << e.what() << std::endl;
return EXIT_FAILURE;
}
}