summaryrefslogtreecommitdiffstats
path: root/CCommandLine.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-03-09 15:14:01 +0100
committermanuel <manuel@mausz.at>2013-03-09 15:14:01 +0100
commit41f7119d8631a142fa5a97285a8443f9d7eb7e14 (patch)
tree75e35bffcfc8e82c989331335e11bac0c86da131 /CCommandLine.cpp
downloadsteamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.gz
steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.bz2
steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.zip
initial import of UpdateTool 0.4
Diffstat (limited to 'CCommandLine.cpp')
-rw-r--r--CCommandLine.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/CCommandLine.cpp b/CCommandLine.cpp
new file mode 100644
index 0000000..3df07b1
--- /dev/null
+++ b/CCommandLine.cpp
@@ -0,0 +1,79 @@
1/*
2 This file is a part of "Didrole's Update Tool"
3 ©2k12, Didrole
4
5 License : Public domain
6*/
7
8#include "CCommandLine.h"
9#include <stdlib.h>
10#include <string.h>
11
12CCommandLine::CCommandLine(int argc, char **argv)
13{
14 m_argc = 0;
15 for(int i = 0; i < argc; i++)
16 AddParm(argv[i]);
17}
18
19CCommandLine::~CCommandLine()
20{
21 for(int i = 0; i < m_argc; i++)
22 {
23 delete[] m_argv[i];
24 }
25}
26
27void CCommandLine::AddParm(const char *psz)
28{
29 m_argv[m_argc] = new char[strlen(psz) + 1];
30 strcpy(m_argv[m_argc], psz);
31 m_argc++;
32}
33
34const char* CCommandLine::ParmValue(const char *psz, const char *pDefaultVal) const
35{
36 int nIndex = FindParm(psz);
37 if((nIndex == 0) || (nIndex == m_argc - 1))
38 return pDefaultVal;
39
40 if(m_argv[nIndex + 1][0] == '-' || m_argv[nIndex + 1][0] == '+')
41 return pDefaultVal;
42
43 return m_argv[nIndex + 1];
44}
45
46int CCommandLine::ParmValue(const char *psz, int nDefaultVal) const
47{
48 const char* cszValue = ParmValue(psz);
49
50 if(!cszValue)
51 return nDefaultVal;
52
53 return atoi(cszValue);
54}
55
56unsigned int CCommandLine::ParmCount() const
57{
58 return m_argc;
59}
60
61unsigned int CCommandLine::FindParm(const char *psz) const
62{
63 for(int i = 1; i < m_argc; i++)
64 {
65 if(strcmp(m_argv[i], psz) == 0)
66 return i;
67 }
68
69 return 0;
70}
71
72const char* CCommandLine::GetParm(unsigned int nIndex) const
73{
74 if(nIndex < (unsigned int)m_argc)
75 return m_argv[nIndex];
76
77 return NULL;
78}
79