ReactOS
0.4.16-dev-329-g9223134
ArgumentParser.cpp
Go to the documentation of this file.
1
/*
2
* regexpl - Console Registry Explorer
3
*
4
* Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
20
*/
21
22
// ArgumentParser.cpp: implementation of the CArgumentParser class.
23
//
25
26
#include "
ph.h
"
27
#include "
ArgumentParser.h
"
28
30
// Construction/Destruction
32
33
CArgumentParser::CArgumentParser
()
34
{
35
m_pchArgumentList
=
NULL
;
36
m_pchArgumentListEnd
=
NULL
;
37
m_pchArgument
=
NULL
;
38
}
39
40
CArgumentParser::~CArgumentParser
()
41
{
42
}
43
44
void
CArgumentParser::SetArgumentList
(
TCHAR
*pchArguments)
45
{
46
TCHAR
*
pch
=
m_pchArgumentList
= pchArguments;
47
m_pchArgumentListEnd
= pchArguments +
_tcslen
(pchArguments);
48
49
BOOL
blnLongArg =
FALSE
;
50
while
(*
pch
)
51
{
52
switch
(*
pch
)
53
{
54
case
_T
(
'^'
):
// argument parser ignores escape sequences
55
if
(
pch
[1])
56
pch
++;
57
break
;
58
case
_T
(
'\"'
):
59
blnLongArg = !blnLongArg;
60
break
;
61
case
_T
(
' '
):
62
case
_T
(
'\t'
):
63
case
_T
(
'\r'
):
64
case
_T
(
'\n'
):
65
if
(!blnLongArg)
66
*
pch
= 0;
67
break
;
68
}
69
pch
++;
70
}
71
72
ResetArgumentIteration
();
73
}
74
75
TCHAR
*
CArgumentParser::GetNextArgument
()
76
{
77
ASSERT
(
m_pchArgumentList
);
// call SetArgumentList() before calling this function
78
ASSERT
(
m_pchArgumentListEnd
);
// call SetArgumentList() before calling this function
79
ASSERT
(
m_pchArgumentListEnd
>=
m_pchArgumentList
);
80
81
// if this is begin of iteration
82
if
(!
m_pchArgument
)
83
m_pchArgument
=
m_pchArgumentList
;
84
85
while
(
m_pchArgument
)
86
{
87
if
(
m_pchArgument
>
m_pchArgumentListEnd
)
88
{
// if end of arguments list reached
89
ASSERT
(
m_pchArgument
- 1 ==
m_pchArgumentListEnd
);
90
break
;
91
}
92
93
TCHAR
*pchArg =
m_pchArgument
;
94
95
// Next argument
96
m_pchArgument
+=
_tcslen
(
m_pchArgument
)+1;
97
98
if
(*pchArg)
99
{
// if argument is not an empty string
100
return
pchArg;
101
}
102
}
103
104
return
NULL
;
105
}
106
107
void
CArgumentParser::ResetArgumentIteration
()
108
{
109
m_pchArgument
=
NULL
;
110
}
ArgumentParser.h
CArgumentParser::~CArgumentParser
virtual ~CArgumentParser()
Definition:
ArgumentParser.cpp:40
CArgumentParser::SetArgumentList
void SetArgumentList(TCHAR *pchArguments)
Definition:
ArgumentParser.cpp:44
CArgumentParser::m_pchArgument
TCHAR * m_pchArgument
Definition:
ArgumentParser.h:38
CArgumentParser::m_pchArgumentListEnd
const TCHAR * m_pchArgumentListEnd
Definition:
ArgumentParser.h:37
CArgumentParser::ResetArgumentIteration
void ResetArgumentIteration()
Definition:
ArgumentParser.cpp:107
CArgumentParser::CArgumentParser
CArgumentParser()
Definition:
ArgumentParser.cpp:33
CArgumentParser::GetNextArgument
TCHAR * GetNextArgument()
Definition:
ArgumentParser.cpp:75
CArgumentParser::m_pchArgumentList
TCHAR * m_pchArgumentList
Definition:
ArgumentParser.h:36
NULL
#define NULL
Definition:
types.h:112
FALSE
#define FALSE
Definition:
types.h:117
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
pch
#define pch(ap)
Definition:
match.c:418
ASSERT
#define ASSERT(a)
Definition:
mode.c:44
ph.h
_T
#define _T(x)
Definition:
vfdio.h:22
TCHAR
char TCHAR
Definition:
xmlstorage.h:189
_tcslen
#define _tcslen
Definition:
xmlstorage.h:198
modules
rosapps
applications
sysutils
regexpl
ArgumentParser.cpp
Generated on Sat Dec 7 2024 06:06:22 for ReactOS by
1.9.6