forked from mirror/freedownload
/
fsCommandLineParser.cpp
141 lines (113 loc) · 2.67 KB
/
fsCommandLineParser.cpp
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
/*
Free Download Manager Copyright (c) 2003-2016 FreeDownloadManager.ORG
*/
#include "stdafx.h"
#include "FdmApp.h"
#include "fsCommandLineParser.h"
#include "vmsLogger.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
fsCommandLineParser::fsCommandLineParser()
{
}
fsCommandLineParser::~fsCommandLineParser()
{
}
BOOL fsCommandLineParser::Parse()
{
m_vPars.clear ();
LPCTSTR pszCmdLine = GetCommandLine ();
if (*pszCmdLine == _T('"'))
{
pszCmdLine = _tcschr (pszCmdLine+1, _T('"'));
if (pszCmdLine)
pszCmdLine++;
else
return FALSE;
}
else
{
while (*pszCmdLine && *pszCmdLine != _T(' '))
pszCmdLine++;
}
try
{
while (*pszCmdLine)
{
TCHAR szParam [10000], szValue [10000];
*szParam = *szValue = 0;
bool bHasValue = true;
while (*pszCmdLine && (*pszCmdLine == ' ' || *pszCmdLine == '\r' || *pszCmdLine == '\n'))
pszCmdLine++;
if (*pszCmdLine == '/' || *pszCmdLine == '-')
{
int i = 0;
while (*++pszCmdLine && *pszCmdLine != ' ' && *pszCmdLine != '=')
szParam [i++] = *pszCmdLine;
szParam [i] = 0;
while (*pszCmdLine == _T(' '))
pszCmdLine++;
if (*pszCmdLine == '=')
{
pszCmdLine++;
while (*pszCmdLine == ' ')
pszCmdLine++;
}
else
bHasValue = false;
}
if (bHasValue)
{
char cSp = ' ';
char cSp1 = '\n', cSp2 = '\r';
if (*pszCmdLine == '"' || *pszCmdLine == '\'')
{
cSp = *pszCmdLine++;
cSp1 = cSp2 = 0;
}
if (*pszCmdLine != '/' && *pszCmdLine != '-')
{
int i = 0;
while (*pszCmdLine && *pszCmdLine != cSp && *pszCmdLine != cSp1 && *pszCmdLine != cSp2)
szValue [i++] = *pszCmdLine++;
szValue [i] = 0;
while (*pszCmdLine && (*pszCmdLine == cSp || *pszCmdLine == cSp1 || *pszCmdLine == cSp2))
pszCmdLine++;
}
}
if (*szParam || *szValue)
{
fsCmdLineParameter par;
par.strParam = szParam;
par.strValue = szValue;
m_vPars.push_back (par);
}
}
}
catch (const std::exception& ex)
{
ASSERT (FALSE);
vmsLogger::WriteLog("fsCommandLineParser::Parse " + std::string(ex.what()));
}
catch (...)
{
ASSERT (FALSE);
vmsLogger::WriteLog("fsCommandLineParser::Parse unknown exception");
}
return TRUE;
}
int fsCommandLineParser::Get_ParameterCount()
{
return m_vPars.size ();
}
LPCTSTR fsCommandLineParser::Get_Parameter(int iIndex)
{
return m_vPars [iIndex].strParam;
}
LPCTSTR fsCommandLineParser::Get_ParameterValue(int iIndex)
{
return m_vPars [iIndex].strValue;
}