This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progargs.cpp
48 lines (40 loc) · 1.63 KB
/
progargs.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
/* Source file containing the code that handles argument parsing */
#include "common.hpp"
#include <cstring>
#include <filesystem>
#include <iostream>
using namespace std;
void argvalidation(int argc) {
if (argc != 4) { /* Checks if enough arguments were provided */
printf("\nWrong format: \n image in_path out_path oper \n operation: copy, histo, mono, gauss\n");
exit(-1);
}
}
struct Datastruct argparsing(const string &in, const string& out, const string& oper){
Datastruct data;
const char *in_file= in.c_str();
const char *out_file=out.c_str();
const char *op=oper.c_str();
if ((strcmp(op, "copy") != 0) && (strcmp(op, "histo") != 0) && (strcmp(op, "mono") != 0) && (strcmp(op, "gauss") != 0)) {
printf("Unexpected operation: %s \n image in_path out_path oper \n operation: copy, histo, mono, gauss \n",
op);
exit(-1);
} else {
printf("\nInput path: %s \nOutput path: %s \n", in_file, out_file);
if (not(filesystem::exists(in_file))) {
printf("Cannot open directory [%s]\n image in_path out_path oper\n opertion: copy, histo, mono, gauss \n",
in_file);
exit(-1);
} else if (not(filesystem::exists(out_file))) {
printf("Output directory [%s] does not exist\n image in_path out_path oper\n opertion: copy, histo, mono, gauss \n",
out_file);
exit(-1);
} else {
filesystem::path in_path(in_file);
data.in= in_path;
filesystem::path out_path(out_file);
data.out=out_path;
return data;
}
}
}