95a024ad7409efb94141e967247c569b75c2e307
[reactos.git] / rosapps / sysutils / regexpl / ArgumentParser.cpp
1 /* $Id: ArgumentParser.cpp,v 1.3 2001/01/10 01:25:29 narnaoud Exp $
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (C) 2000 Nedko Arnaoudov <nedkohome@atia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 // ArgumentParser.cpp: implementation of the CArgumentParser class.
24 //
25 //////////////////////////////////////////////////////////////////////
26
27 #include "ph.h"
28 #include "ArgumentParser.h"
29
30 //////////////////////////////////////////////////////////////////////
31 // Construction/Destruction
32 //////////////////////////////////////////////////////////////////////
33
34 CArgumentParser::CArgumentParser()
35 {
36 m_pchArgumentList = NULL;
37 m_pchArgumentListEnd = NULL;
38 m_pchArgument = NULL;
39 }
40
41 CArgumentParser::~CArgumentParser()
42 {
43 }
44
45 void CArgumentParser::SetArgumentList(TCHAR *pchArguments)
46 {
47 TCHAR *pch = m_pchArgumentList = pchArguments;
48 m_pchArgumentListEnd = pchArguments + _tcslen(pchArguments);
49
50 BOOL blnLongArg = FALSE;
51 while (*pch)
52 {
53 switch(*pch)
54 {
55 case _T('\"'):
56 blnLongArg = !blnLongArg;
57 break;
58 case _T(' '):
59 case _T('\t'):
60 case _T('\r'):
61 case _T('\n'):
62 if (!blnLongArg)
63 *pch = 0;
64 break;
65 }
66 pch++;
67 }
68
69 ResetArgumentIteration();
70 }
71
72 TCHAR * CArgumentParser::GetNextArgument()
73 {
74 ASSERT(m_pchArgumentList); // call SetArgumentList() before calling this function
75 ASSERT(m_pchArgumentListEnd); // call SetArgumentList() before calling this function
76 ASSERT(m_pchArgumentListEnd >= m_pchArgumentList);
77
78 // if this is begin of iteration
79 if (!m_pchArgument)
80 m_pchArgument = m_pchArgumentList;
81
82 while(m_pchArgument)
83 {
84 if (m_pchArgument > m_pchArgumentListEnd)
85 { // if end of arguments list reached
86 ASSERT(m_pchArgument - 1 == m_pchArgumentListEnd);
87 break;
88 }
89
90 TCHAR *pchArg = m_pchArgument;
91
92 // Next argument
93 m_pchArgument += _tcslen(m_pchArgument)+1;
94
95 if(*pchArg)
96 { // if argument is not an empty string
97 return pchArg;
98 }
99 }
100
101 return NULL;
102 }
103
104 void CArgumentParser::ResetArgumentIteration()
105 {
106 m_pchArgument = NULL;
107 }