Registry Explorer (console tool) by Nedko Arnaoudov added to the system utilities...
[reactos.git] / rosapps / sysutils / regexpl / ArgumentParser.cpp
1 /* $Id: ArgumentParser.cpp,v 1.1 2000/10/04 21:04:30 ea Exp $
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (c) 1999-2000 Nedko Arnaoudov <nedkohome@atia.com>
6 *
7 * License: GNU GPL
8 *
9 */
10
11 // ArgumentParser.cpp: implementation of the CArgumentParser class.
12 //
13 //////////////////////////////////////////////////////////////////////
14
15 #include "ph.h"
16 #include "ArgumentParser.h"
17
18 //////////////////////////////////////////////////////////////////////
19 // Construction/Destruction
20 //////////////////////////////////////////////////////////////////////
21
22 CArgumentParser::CArgumentParser()
23 {
24 m_pchArgumentList = NULL;
25 m_pchArgumentListEnd = NULL;
26 m_pchArgument = NULL;
27 }
28
29 CArgumentParser::~CArgumentParser()
30 {
31 }
32
33 void CArgumentParser::SetArgumentList(TCHAR *pchArguments)
34 {
35 TCHAR *pch = m_pchArgumentList = pchArguments;
36 m_pchArgumentListEnd = pchArguments + _tcslen(pchArguments);
37
38 BOOL blnLongArg = FALSE;
39 while (*pch)
40 {
41 switch(*pch)
42 {
43 case L'\"':
44 if (blnLongArg) blnLongArg = FALSE;
45 else blnLongArg = TRUE;
46 break;
47 case L' ':
48 case L'\t':
49 case L'\r':
50 case L'\n':
51 if (!blnLongArg) *pch = 0;
52 break;
53 }
54 pch++;
55 }
56
57 ResetArgumentIteration();
58 }
59
60 TCHAR * CArgumentParser::GetNextArgument()
61 {
62 ASSERT(m_pchArgumentList); // call SetArgumentList() before calling this function
63 ASSERT(m_pchArgumentListEnd); // call SetArgumentList() before calling this function
64 ASSERT(m_pchArgumentListEnd >= m_pchArgumentList);
65
66 // if this is begin of iteration
67 if (!m_pchArgument) m_pchArgument = m_pchArgumentList;
68
69 while(m_pchArgument)
70 {
71 if (m_pchArgument > m_pchArgumentListEnd)
72 { // if end of arguments list reached
73 ASSERT(m_pchArgument - 1 == m_pchArgumentListEnd);
74 break;
75 }
76
77 TCHAR *pchArg = m_pchArgument;
78
79 // Next argument
80 m_pchArgument += _tcslen(m_pchArgument)+1;
81
82 if(*pchArg)
83 { // if argument is not an empty string
84 return pchArg;
85 }
86 }
87
88 return NULL;
89 }
90
91 void CArgumentParser::ResetArgumentIteration()
92 {
93 m_pchArgument = NULL;
94 }