aboutsummaryrefslogtreecommitdiff
path: root/src/optparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/optparser.cpp')
-rw-r--r--src/optparser.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/optparser.cpp b/src/optparser.cpp
index bab93d0..74aba3e 100644
--- a/src/optparser.cpp
+++ b/src/optparser.cpp
@@ -167,6 +167,68 @@ void Bu::OptParser::parse( int argc, char **argv )
167 } 167 }
168} 168}
169 169
170void Bu::OptParser::parse( const Bu::String &sLine )
171{
172 Bu::String sCmd = sLine.clone();
173 int iParams = 0;
174 bool bInGap = true;
175 bool bInQuote = false;
176 for( Bu::String::iterator i = sCmd.begin(); i; i++ )
177 {
178 if( bInQuote == false && (*i == ' ' || *i == '\t') )
179 {
180 if( bInGap == false )
181 {
182 bInGap = true;
183 }
184 }
185 else if( *i == '"' )
186 {
187 bInQuote = !bInQuote;
188 }
189 else
190 {
191 if( bInGap )
192 {
193 iParams++;
194 bInGap = false;
195 }
196 }
197 }
198
199 bInQuote = false;
200 bInGap = true;
201 char **asParam = new char*[iParams];
202 iParams = 0;
203 for( char *i = sCmd.getStr(); *i; i++ )
204 {
205 if( bInQuote == false && (*i == ' ' || *i == '\t') )
206 {
207 if( bInGap == false )
208 {
209 bInGap = true;
210 *i = '\0';
211 }
212 }
213 else if( *i == '"' )
214 {
215 bInQuote = !bInQuote;
216 }
217 else
218 {
219 if( bInGap )
220 {
221 asParam[iParams++] = i;
222 bInGap = false;
223 }
224 }
225 }
226
227 parse( iParams, asParam );
228
229 delete[] asParam;
230}
231
170void Bu::OptParser::addOption( const Option &opt ) 232void Bu::OptParser::addOption( const Option &opt )
171{ 233{
172 lOption.append( opt ); 234 lOption.append( opt );