-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcclparser.cpp
More file actions
71 lines (67 loc) · 1.75 KB
/
cclparser.cpp
File metadata and controls
71 lines (67 loc) · 1.75 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
63
64
65
66
67
68
69
70
71
#include "cclparser.h"
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include "getopt.h"
#include "errors.h"
clparser::clparser(int argc, char **argv) {
/*
This class parses command line input and checks if it's OK.
*/
clparser::argc = argc;
clparser::argv = argv;
clparser::parse();
clparser::check();
}
void clparser::check() {
/*
This function checks if we have both the correct number of inputs and if the inputs are valid, e.g. if input files exist.
*/
if (clparser::nargs != 4) {
throw_error(CCLPARSER_INVALID_NUMBER_OF_PARAMETERS);
} else if (!is_file_existing(clparser::in_FITS_filename)) {
throw_error(CCLPARSER_INPUT_FITS_FILE_NO_EXIST);
} else if (!is_file_existing(clparser::in_params_filename)) {
throw_error(CCLPARSER_INPUT_PARAMETERS_FILE_NO_EXIST);
} else if (!is_file_existing(clparser::in_config_filename)) {
throw_error(CCLPARSER_INPUT_CONFIG_FILE_NO_EXIST);
}
}
void clparser::parse() {
/*
This function parses the command line input arguments.
*/
int opterr = 0;
int c;
while ((c = getopt(clparser::argc, clparser::argv, "i:p:o:c:|")) != -1)
switch (c)
{
case 'i':
in_FITS_filename = std::string(optarg);
nargs++;
break;
case 'p':
in_params_filename = std::string(optarg);
nargs++;
break;
case 'c':
in_config_filename = std::string(optarg);
nargs++;
break;
case 'o':
out_FITS_filename = std::string(optarg);
nargs++;
break;
case '?':
if (optopt == 'i' || optopt == 'p' || optopt == 'o' || optopt == 'c') {
throw_error(CCLPARSER_OPTION_NO_ARGUMENT);
} else if (isprint(optopt)) {
throw_error(CCLPARSER_UNKNOWN_OPTION);
} else {
throw_error(CCLPARSER_UNKNOWN_CHARACTER);
}
default:
throw_error(CCLPARSER_UNKNOWN_CONDITION);
}
}