This repository was archived by the owner on Aug 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathArguments.cpp
More file actions
88 lines (71 loc) · 1.83 KB
/
Arguments.cpp
File metadata and controls
88 lines (71 loc) · 1.83 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
* Distributed under the terms of the MIT License.
*/
#include "Arguments.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Arguments::Arguments(int defaultArgcNum, const char* const* defaultArgv)
: fUsageRequested(false),
fShellArgumentCount(0),
fShellArguments(NULL),
fRecordNow(false),
fFullScreen(false)
{
_SetShellArguments(defaultArgcNum, defaultArgv);
}
Arguments::~Arguments()
{
_SetShellArguments(0, NULL);
}
void
Arguments::Parse(int argc, const char* const* argv)
{
int argi;
for (argi = 1; argi < argc; argi ++) {
const char* arg = argv[argi];
if (*arg == '-') {
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0)
fUsageRequested = true;
else if (strcmp(arg, "-r") == 0 || strcmp(arg, "--recordnow") == 0) {
fRecordNow = true;
} else if (strcmp(arg, "-f") == 0 || strcmp(arg, "--fullscreen")
== 0)
fFullScreen = true;
else {
// illegal option
fprintf(stderr, "Unrecognized option \"%s\"\n", arg);
fUsageRequested = true;
}
} else {
// no option, so the remainder is the shell program with arguments
_SetShellArguments(argc - argi, argv + argi);
argi = argc;
}
}
}
void
Arguments::GetShellArguments(int& argc, const char* const*& argv) const
{
argc = fShellArgumentCount;
argv = fShellArguments;
}
void
Arguments::_SetShellArguments(int argc, const char* const* argv)
{
// delete old arguments
for (int32 i = 0; i < fShellArgumentCount; i++)
free((void *)fShellArguments[i]);
delete[] fShellArguments;
fShellArguments = NULL;
fShellArgumentCount = 0;
// copy new ones
if (argc > 0 && argv) {
fShellArguments = new const char*[argc + 1];
for (int i = 0; i < argc; i++)
fShellArguments[i] = strdup(argv[i]);
fShellArguments[argc] = NULL;
fShellArgumentCount = argc;
}
}