CommandLine.cpp
Go to the documentation of this file.00001 //*** CommandLine.cpp *** 00002 00003 #include "CommandLine.h" 00004 #include "Platform_OS.h" 00005 #include "StandardLibrary.h" 00006 00007 //**** Constructor *** 00008 00009 CommandLine::CommandLine() 00010 { 00011 if (Platform::GetPlatform_OS()) 00012 { 00013 const char* commandLineString=Platform::GetPlatform_OS()->GetCommandLineString(); 00014 if (commandLineString) 00015 { 00016 ParseCommandLine(commandLineString); 00017 } 00018 } 00019 } 00020 00021 00022 //**** Constructor *** 00023 00024 CommandLine::CommandLine(const char* commandLineString) 00025 { 00026 if (commandLineString) 00027 { 00028 ParseCommandLine(commandLineString); 00029 } 00030 } 00031 00032 00033 //*** ParseCommandLine *** 00034 00035 void CommandLine::ParseCommandLine(const char* commandLine) 00036 { 00037 00038 while (commandLine && *commandLine) 00039 { 00040 if (*commandLine==' ') 00041 { 00042 commandLine++; 00043 } 00044 else if (*commandLine=='-') 00045 { 00046 commandLine++; 00047 const char* end=StrChr(commandLine,' '); 00048 if (!end) 00049 { 00050 commandLineFlags_.Add(StringId(commandLine)); 00051 } 00052 else 00053 { 00054 int length=(int)(end-commandLine); 00055 char* buffer=static_cast<char*>(Malloc(length+1)); 00056 StrNCpy(buffer,commandLine,length); 00057 buffer[length]='\0'; 00058 commandLineFlags_.Add(StringId(buffer)); 00059 Free(buffer); 00060 } 00061 commandLine=end; 00062 } 00063 else if (*commandLine=='"') 00064 { 00065 commandLine++; 00066 const char* end=StrChr(commandLine,'"'); 00067 if (!end) 00068 { 00069 commandLineStrings_.Add(StringId(commandLine)); 00070 commandLine=0; 00071 } 00072 else 00073 { 00074 int length=(int)(end-commandLine); 00075 char* buffer=static_cast<char*>(Malloc(length+1)); 00076 StrNCpy(buffer,commandLine,length); 00077 buffer[length]='\0'; 00078 commandLineStrings_.Add(StringId(buffer)); 00079 Free(buffer); 00080 commandLine=end+1; 00081 } 00082 } 00083 else 00084 { 00085 const char* end=StrChr(commandLine,' '); 00086 if (!end) 00087 { 00088 commandLineStrings_.Add(StringId(commandLine)); 00089 } 00090 else 00091 { 00092 int length=(int)(end-commandLine); 00093 char* buffer=static_cast<char*>(Malloc(length+1)); 00094 StrNCpy(buffer,commandLine,length); 00095 buffer[length]='\0'; 00096 commandLineStrings_.Add(StringId(buffer)); 00097 Free(buffer); 00098 } 00099 commandLine=end; 00100 } 00101 } 00102 } 00103 00104 00105 //*** IsCommandLineFlagSet *** 00106 00107 bool CommandLine::IsCommandLineFlagSet(StringId flag) 00108 { 00109 for (int i=0; i<commandLineFlags_.GetItemCount(); i++) 00110 { 00111 if (commandLineFlags_.Get(i)==flag) 00112 { 00113 return true; 00114 } 00115 } 00116 00117 return false; 00118 } 00119 00120 00121 //*** GetCommandLineFlagCount *** 00122 00123 int CommandLine::GetCommandLineFlagCount() 00124 { 00125 return commandLineFlags_.GetItemCount(); 00126 } 00127 00128 00129 //*** GetCommandLineFlag *** 00130 00131 StringId CommandLine::GetCommandLineFlag(int index) 00132 { 00133 return commandLineFlags_.Get(index); 00134 } 00135 00136 00137 //*** GetCommandLineStringCount *** 00138 00139 int CommandLine::GetCommandLineStringCount() 00140 { 00141 return commandLineStrings_.GetItemCount(); 00142 } 00143 00144 00145 //*** GetCommandLineString *** 00146 00147 StringId CommandLine::GetCommandLineString(int index) 00148 { 00149 return commandLineStrings_.Get(index); 00150 } 00151 00152
Reproduction/republishing of any material on this site without permission is strictly prohibited.
