-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.cpp
95 lines (77 loc) · 2.75 KB
/
opts.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// class to handle options and setup for main program
//
// Author: Robert Wolff
// Copyright 2020 Robert Wolff with MIT license
//
#include "opts.h"
opts::opts() {
logFileName="";
sourceDir="";
sourceDirRecursive = false;
fileExtRaw = "MP4";
fileExtList.clear();
inFile="";
timeBetweenSamples = 5;
};
opts::~opts() {};
bool opts::expandPath(const char* inPath, std::string &expandedPath) {
int status;
wordexp_t exp_result;
status = wordexp(inPath, &exp_result, 0);
expandedPath = exp_result.we_wordv[0];
wordfree(&exp_result);
return status==0;
}
void opts::processOpts(int argc, const char** argv) {
struct getopt args( argc, argv );
if( args.has("-h") || args.has("--help") || args.has("-?") || args.size() == 1 ) {
showHelp();
exit(1);
}
if( args.has("--version") ) {
std::cout << args["0"] << PROG_NAME << " Version " << PROG_VER << " Compiled on " << __DATE__ << std::endl;
exit(2);
}
if ( args.has("--showargs") ) {
std::cout << "---" << std::endl;
std::cout << args.cmdline() << std::endl;
std::cout << args.size() << " MAP: " << args.str() << std::endl;
exit(3);
}
if( args.has("--infile") && (args.has("--sourcedir") || args.has("--fileext")) ) {
std::cout << "ERROR: --infile is mutually exclusive from --sourcedir and --fileext" << std::endl;
exit(-3);
}
if( args.has("--sourcedir") ) {
if (!expandPath(args["--sourcedir"].c_str(), sourceDir)) {
std::cout << "ERROR: Expansion of path failed: " << args["--sourcedir"] << std::endl;
exit(-4);
}
}
if( args.has("--fileext") ) {
fileExtRaw = args["--fileext"];
}
if( args.has("--infile") ) {
if (!expandPath(args["--infile"].c_str(), inFile)) {
std::cout << "ERROR: Expansion of path failed: " << args["--infile"] << std::endl;
exit(-5);
}
}
if (args.has("--timebetweensamples")) {
timeBetweenSamples = (unsigned int)atoi( args["--timebetweensamples"].c_str() );
}
if( args.has("--recursive") ) {
sourceDirRecursive=true;
}
};
void opts::showHelp() {
std::cout << "goproWhereWhen Usage:" << std::endl
<< " --help : Print this message." << std::endl
<< " --version : Print product version." << std::endl
<< " --sourcedir=<directory> : Process MP4 files from this location." << std::endl
<< " --fileext=extlist [no '*' or '.' ... just extensions separated by commas (ie mp4,mov,mpeg)]" << std::endl
<< " --infile=filename [process a singular input file - mutually exclusive from --sourcedir and --fileext]" << std::endl
<< " --recursive : Process sourcedir and all directories under it. (default: false)" << std::endl
<< std::endl;
};