From 41f7119d8631a142fa5a97285a8443f9d7eb7e14 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 9 Mar 2013 15:14:01 +0100 Subject: initial import of UpdateTool 0.4 --- CCommandLine.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 CCommandLine.cpp (limited to 'CCommandLine.cpp') diff --git a/CCommandLine.cpp b/CCommandLine.cpp new file mode 100644 index 0000000..3df07b1 --- /dev/null +++ b/CCommandLine.cpp @@ -0,0 +1,79 @@ +/* + This file is a part of "Didrole's Update Tool" + ©2k12, Didrole + + License : Public domain +*/ + +#include "CCommandLine.h" +#include +#include + +CCommandLine::CCommandLine(int argc, char **argv) +{ + m_argc = 0; + for(int i = 0; i < argc; i++) + AddParm(argv[i]); +} + +CCommandLine::~CCommandLine() +{ + for(int i = 0; i < m_argc; i++) + { + delete[] m_argv[i]; + } +} + +void CCommandLine::AddParm(const char *psz) +{ + m_argv[m_argc] = new char[strlen(psz) + 1]; + strcpy(m_argv[m_argc], psz); + m_argc++; +} + +const char* CCommandLine::ParmValue(const char *psz, const char *pDefaultVal) const +{ + int nIndex = FindParm(psz); + if((nIndex == 0) || (nIndex == m_argc - 1)) + return pDefaultVal; + + if(m_argv[nIndex + 1][0] == '-' || m_argv[nIndex + 1][0] == '+') + return pDefaultVal; + + return m_argv[nIndex + 1]; +} + +int CCommandLine::ParmValue(const char *psz, int nDefaultVal) const +{ + const char* cszValue = ParmValue(psz); + + if(!cszValue) + return nDefaultVal; + + return atoi(cszValue); +} + +unsigned int CCommandLine::ParmCount() const +{ + return m_argc; +} + +unsigned int CCommandLine::FindParm(const char *psz) const +{ + for(int i = 1; i < m_argc; i++) + { + if(strcmp(m_argv[i], psz) == 0) + return i; + } + + return 0; +} + +const char* CCommandLine::GetParm(unsigned int nIndex) const +{ + if(nIndex < (unsigned int)m_argc) + return m_argv[nIndex]; + + return NULL; +} + -- cgit v1.2.3