-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArgParser.cpp
More file actions
56 lines (44 loc) · 913 Bytes
/
ArgParser.cpp
File metadata and controls
56 lines (44 loc) · 913 Bytes
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
/*
* ArgParser.cpp
*
* Created on: October 22, 2014
* Author: Moustafa
* Version: 1.0
*
*/
#include "ArgParser.h"
#include <cstring>
#include <fstream>
ArgParser::ArgParser()
{
}
ArgParser::~ArgParser()
{
}
bool ArgParser::isValidPath(string path)
{
ifstream testF(path.c_str());
bool isGood = false;
if(testF.good()) isGood = true;
testF.close();
return isGood;
}
bool ArgParser::checkArgs(int argc, char* argv[], char* arg)
{
// assuming format of the command line is "[program name] [-arg1] [-arg2] .. [-arg3] [file(s)]
int i = 1;
while(i < argc && argv[i][0] == '-')
{
if(!strcmp(argv[i], arg)) return true;
i++;
}
return false;
}
int ArgParser::getFileArgs(int argc, char* argv[])
{
// assuming format of the command line is "[program name] [-arg1] [-arg2] .. [-arg3] [file(s)]
int i = 1;
while(i < argc && argv[i][0] == '-') i++;
if(i < argc) return i;
return 0;
}