ptypes

ptypes Commit Details


Date:2013-05-28 19:11:00 (11 years 7 months ago)
Author:Natalie Adams
Branch:default
Commit:e92cdf39e4c3
Parents: f52628c1d1c6
Message:Moving pparser to src folder

Changes:
Dwin32/ppparser.cxx (full)
Asrc/ppparser.cxx (full)
Mwin32/PTypes_Lib.vcxproj (2 diffs)
Mwin32/PTypes_Lib.vcxproj.filters (1 diff)
Mwin32/PTypes_Lib.vcxproj.user (1 diff)

File differences

src/ppparser.cxx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "ptypes.h"
#include "pstreams.h"
USING_PTYPES
pparser::pparser(int argc, char * argv[], const tobjlist<Parameter> & parameters)
{
this->checkreq = true;
// Assumptions:
// *) options will not start with -
// *) parameters will not be repeated
int z = 0;
tpodlist<int> parasused;
bool docontinue = false;
for(int i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (z != parameters.get_count())
{
for (int zz = 0; zz < parameters.get_count(); zz++)
{
docontinue = false;
for (int pu = 0; pu < parasused.get_count(); pu++)
{
if (parasused[pu] == zz)
{
docontinue = true;
break;
}
}
if (docontinue)
continue;
if (argv[i] == ("-" + parameters[zz]->longparameter) || argv[i] == ("-" + parameters[zz]->shortparameter))
{
if (parameters[zz]->numberofparameters == 0)
{
put(this->choices, argv[i], "");
} else {
variant options;
if ((i+parameters[zz]->numberofparameters) <= argc)
{
for(int ii = 0; ii < parameters[zz]->numberofparameters; ii++)
{
add(options, (pt::string)argv[ii+i+1]);
}
put(this->choices, argv[i], options);
i += parameters[zz]->numberofparameters;
} else {
this->checkreq = false;
}
}
z++;
parasused.add(zz);
break;
}
}
} else {
// hit the end of scanned parameters but user provided parameters still exist?
this->checkreq = false;
this->invalidparas.add(argv[i]);
}
} else {
//should never look at a parameter that doesn't start with a -
this->checkreq = false;
this->invalidparas.add(argv[i]);
}
this->argv.add(argv[i]);
}
if (z != parameters.get_count())
{
//scan through parameters for missing paras
for(int zz = z; zz < parameters.get_count(); zz++)
{
if (parameters[zz]->required)
{
this->checkreq = false;
this->missingparas.add(const_cast <char *>((const char *)parameters[zz]->shortparameter));
}
}
}
this->paras = const_cast <tobjlist<Parameter> *>(&parameters);
}
void pparser::printusage(const char * header, const char * pname, const char * footer)
{
pout.put(header);
pout.put("\n");
if (this->invalidparas.get_count() > 0)
{
pout.put("Invalid parameters: ");
for(int i = 0; i < this->invalidparas.get_count(); i++)
{
pout.put(this->invalidparas[i]);
pout.put(" ");
}
pout.put("\n\n");
}
if (this->missingparas.get_count() > 0)
{
pout.put("Missing parameters: ");
for(int i = 0; i < this->missingparas.get_count(); i++)
{
pout.put("-");
pout.put(this->missingparas[i]);
pout.put(" ");
}
pout.put("\n\n");
}
pout.put("USAGE: ");
pout.put(pname);
pout.put(" ");
string parameterlist;
string paralisthints;
for(int i = 0; i < this->paras->get_count(); i++)
{
if ((*this->paras)[i]->required)
parameterlist += "-" + (*this->paras)[i]->shortparameter + " ";
else
parameterlist += "[-" + (*this->paras)[i]->shortparameter + "] ";
paralisthints += "-" + (*this->paras)[i]->shortparameter + ", --" + (*this->paras)[i]->longparameter + "\n" + (*this->paras)[i]->hint + "\n\n";
}
pout.put(parameterlist);
pout.put("\n");
pout.put("\n");
pout.put(paralisthints);
pout.put(footer);
pout.put("\n");
}
bool pparser::isparameterset(const Parameter * para)
{
if (get(this->choices, "--" + para->longparameter) == nullvar && get(this->choices, "-" + para->shortparameter) == nullvar)
{
return false;
}
return true;
}
variant pparser::getoptions(const Parameter * para)
{
if (get(this->choices, "--" + para->longparameter) != nullvar)
return get(this->choices, "--" + para->longparameter);
if (get(this->choices, "-" + para->shortparameter) != nullvar)
return get(this->choices, "-" + para->shortparameter);
return nullvar;
}
win32/PTypes_Lib.vcxproj
163163
164164
165165
166
166167
167168
168169
......
434435
435436
436437
437
438438
439439
440440
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\src\ppparser.cxx" />
<ClCompile Include="..\src\pstrcase.cxx">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="ppparser.cxx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\pasync.h" />
win32/PTypes_Lib.vcxproj.filters
188188
189189
190190
191
191
192192
193193
194194
<ClCompile Include="..\src\ptparray.cxx">
<Filter>Types</Filter>
</ClCompile>
<ClCompile Include="ppparser.cxx">
<ClCompile Include="..\src\ppparser.cxx">
<Filter>Types</Filter>
</ClCompile>
</ItemGroup>
win32/PTypes_Lib.vcxproj.user
11
22
3
4
5
36
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>
win32/ppparser.cxx
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "ptypes.h"
#include "pstreams.h"
USING_PTYPES
pparser::pparser(int argc, char * argv[], const tobjlist<Parameter> & parameters)
{
this->checkreq = true;
// Assumptions:
// *) options will not start with -
// *) parameters will not be repeated
int z = 0;
tpodlist<int> parasused;
bool docontinue = false;
for(int i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (z != parameters.get_count())
{
for (int zz = 0; zz < parameters.get_count(); zz++)
{
docontinue = false;
for (int pu = 0; pu < parasused.get_count(); pu++)
{
if (parasused[pu] == zz)
{
docontinue = true;
break;
}
}
if (docontinue)
continue;
if (argv[i] == ("-" + parameters[zz]->longparameter) || argv[i] == ("-" + parameters[zz]->shortparameter))
{
if (parameters[zz]->numberofparameters == 0)
{
put(this->choices, argv[i], "");
} else {
variant options;
if ((i+parameters[zz]->numberofparameters) <= argc)
{
for(int ii = 0; ii < parameters[zz]->numberofparameters; ii++)
{
add(options, (pt::string)argv[ii+i+1]);
}
put(this->choices, argv[i], options);
i += parameters[zz]->numberofparameters;
} else {
this->checkreq = false;
}
}
z++;
parasused.add(zz);
break;
}
}
} else {
// hit the end of scanned parameters but user provided parameters still exist?
this->checkreq = false;
this->invalidparas.add(argv[i]);
}
} else {
//should never look at a parameter that doesn't start with a -
this->checkreq = false;
this->invalidparas.add(argv[i]);
}
this->argv.add(argv[i]);
}
if (z != parameters.get_count())
{
//scan through parameters for missing paras
for(int zz = z; zz < parameters.get_count(); zz++)
{
if (parameters[zz]->required)
{
this->checkreq = false;
this->missingparas.add(const_cast <char *>((const char *)parameters[zz]->shortparameter));
}
}
}
this->paras = const_cast <tobjlist<Parameter> *>(&parameters);
}
void pparser::printusage(const char * header, const char * pname, const char * footer)
{
pout.put(header);
pout.put("\n");
if (this->invalidparas.get_count() > 0)
{
pout.put("Invalid parameters: ");
for(int i = 0; i < this->invalidparas.get_count(); i++)
{
pout.put(this->invalidparas[i]);
pout.put(" ");
}
pout.put("\n\n");
}
if (this->missingparas.get_count() > 0)
{
pout.put("Missing parameters: ");
for(int i = 0; i < this->missingparas.get_count(); i++)
{
pout.put("-");
pout.put(this->missingparas[i]);
pout.put(" ");
}
pout.put("\n\n");
}
pout.put("USAGE: ");
pout.put(pname);
pout.put(" ");
string parameterlist;
string paralisthints;
for(int i = 0; i < this->paras->get_count(); i++)
{
if ((*this->paras)[i]->required)
parameterlist += "-" + (*this->paras)[i]->shortparameter + " ";
else
parameterlist += "[-" + (*this->paras)[i]->shortparameter + "] ";
paralisthints += "-" + (*this->paras)[i]->shortparameter + ", --" + (*this->paras)[i]->longparameter + "\n" + (*this->paras)[i]->hint + "\n\n";
}
pout.put(parameterlist);
pout.put("\n");
pout.put("\n");
pout.put(paralisthints);
pout.put(footer);
pout.put("\n");
}
bool pparser::isparameterset(const Parameter * para)
{
if (get(this->choices, "--" + para->longparameter) == nullvar && get(this->choices, "-" + para->shortparameter) == nullvar)
{
return false;
}
return true;
}
variant pparser::getoptions(const Parameter * para)
{
if (get(this->choices, "--" + para->longparameter) != nullvar)
return get(this->choices, "--" + para->longparameter);
if (get(this->choices, "-" + para->shortparameter) != nullvar)
return get(this->choices, "-" + para->shortparameter);
return nullvar;
}

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.67537s using 14 queries.