-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg_parser.h
More file actions
46 lines (36 loc) · 1.56 KB
/
arg_parser.h
File metadata and controls
46 lines (36 loc) · 1.56 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
#ifdef __APPLE__
#ifndef ARG_PARSER
#define ARG_PARSER
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct arg_params {
string inputFile, outputFile;
};
struct arg_params arg_parser(int argc, const char* argv[]){
struct arg_params args;
/* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ARG CHECKER ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
if (argc == 2 && string(argv[1]) == "--name"){
printf("Josh Miltier\n"); // check for --name
exit(-1);
} else if (argc == 4) {} // continue on to execution
else { // catch all else
printf("\nERROR: Program option parameters are invalid.\n"
" Expected 3 options, but got %i.\n"
" Refer to the README for execution instructions.\n\n", argc-1);
exit(-1);
}
/* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ END ARG CHECK ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */
/* ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ARG PARSER ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ */
// txt input file (argv 1)
args.inputFile = string(argv[1]);
// txt output file (argv 3), with syntax checking
if (string(argv[2]).rfind("-o", 0)) {
printf("ERROR: incorrect flag for output file. Expected: '-o' Actual: '%s'\n", argv[2]); exit(-1);
} else args.outputFile = string(argv[3]);
/* ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ END ARG PARSER ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ */
return args;
}
#endif // ARG_PARSER
#endif // __APPLE__