00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "fsCommandLineParser.h"
00009
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015
00016 fsCommandLineParser::fsCommandLineParser()
00017 {
00018
00019 }
00020
00021 fsCommandLineParser::~fsCommandLineParser()
00022 {
00023
00024 }
00025
00026 BOOL fsCommandLineParser::Parse()
00027 {
00028 LPCSTR pszCmdLine = GetCommandLine ();
00029
00030 if (*pszCmdLine == '"')
00031 {
00032 pszCmdLine = strchr (pszCmdLine+1, '"');
00033 if (pszCmdLine)
00034 pszCmdLine++;
00035 else
00036 return FALSE;
00037 }
00038 else
00039 {
00040 while (*pszCmdLine && *pszCmdLine != ' ')
00041 pszCmdLine++;
00042 }
00043
00044 try{
00045
00046 while (*pszCmdLine)
00047 {
00048 char szParam [10000], szValue [10000];
00049 *szParam = *szValue = 0;
00050 bool bHasValue = true;
00051
00052
00053 while (*pszCmdLine && (*pszCmdLine == ' ' || *pszCmdLine == '\r' || *pszCmdLine == '\n'))
00054 pszCmdLine++;
00055
00056 if (*pszCmdLine == '/' || *pszCmdLine == '-')
00057 {
00058 int i = 0;
00059 while (*++pszCmdLine && *pszCmdLine != ' ' && *pszCmdLine != '=')
00060 szParam [i++] = *pszCmdLine;
00061
00062 szParam [i] = 0;
00063
00064 while (*pszCmdLine == ' ')
00065 pszCmdLine++;
00066
00067
00068 if (*pszCmdLine == '=')
00069 {
00070 pszCmdLine++;
00071 while (*pszCmdLine == ' ')
00072 pszCmdLine++;
00073 }
00074 else
00075 bHasValue = false;
00076 }
00077
00078 if (bHasValue)
00079 {
00080 char cSp = ' ';
00081 char cSp1 = '\n', cSp2 = '\r';
00082
00083 if (*pszCmdLine == '"' || *pszCmdLine == '\'')
00084 {
00085 cSp = *pszCmdLine++;
00086 cSp1 = cSp2 = 0;
00087 }
00088
00089
00090 if (*pszCmdLine != '/' && *pszCmdLine != '-')
00091 {
00092 int i = 0;
00093 while (*pszCmdLine && *pszCmdLine != cSp && *pszCmdLine != cSp1 && *pszCmdLine != cSp2)
00094 szValue [i++] = *pszCmdLine++;
00095
00096 szValue [i] = 0;
00097
00098 while (*pszCmdLine && (*pszCmdLine == cSp || *pszCmdLine == cSp1 || *pszCmdLine == cSp2))
00099 pszCmdLine++;
00100 }
00101 }
00102
00103 if (*szParam || *szValue)
00104 {
00105 fsCmdLineParameter par;
00106 par.strParam = szParam;
00107 par.strValue = szValue;
00108 m_vPars.add (par);
00109 }
00110 }
00111
00112 }
00113 catch (...) {}
00114
00115 return TRUE;
00116 }
00117
00118 int fsCommandLineParser::Get_ParameterCount()
00119 {
00120 return m_vPars.size ();
00121 }
00122
00123 LPCSTR fsCommandLineParser::Get_Parameter(int iIndex)
00124 {
00125 return m_vPars [iIndex].strParam;
00126 }
00127
00128 LPCSTR fsCommandLineParser::Get_ParameterValue(int iIndex)
00129 {
00130 return m_vPars [iIndex].strValue;
00131 }