diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/optparser.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to '')
-rw-r--r-- | src/stable/optparser.cpp | 732 |
1 files changed, 366 insertions, 366 deletions
diff --git a/src/stable/optparser.cpp b/src/stable/optparser.cpp index 10a8fb6..aca36a2 100644 --- a/src/stable/optparser.cpp +++ b/src/stable/optparser.cpp | |||
@@ -21,168 +21,168 @@ Bu::OptParser::~OptParser() | |||
21 | 21 | ||
22 | void Bu::OptParser::parse( int argc, char **argv ) | 22 | void Bu::OptParser::parse( int argc, char **argv ) |
23 | { | 23 | { |
24 | for( int j = 1; j < argc; j++ ) | 24 | for( int j = 1; j < argc; j++ ) |
25 | { | 25 | { |
26 | if( argv[j][0] == '-' ) | 26 | if( argv[j][0] == '-' ) |
27 | { | 27 | { |
28 | // Now we're on to something, which kind is it? | 28 | // Now we're on to something, which kind is it? |
29 | if( argv[j][1] == '-' ) | 29 | if( argv[j][1] == '-' ) |
30 | { | 30 | { |
31 | int iEPos; | 31 | int iEPos; |
32 | for( iEPos = 2; argv[j][iEPos] != '\0' && | 32 | for( iEPos = 2; argv[j][iEPos] != '\0' && |
33 | argv[j][iEPos] != '='; iEPos++ ) { } | 33 | argv[j][iEPos] != '='; iEPos++ ) { } |
34 | 34 | ||
35 | Bu::String sOpt; | 35 | Bu::String sOpt; |
36 | int iCount = argc-j; | 36 | int iCount = argc-j; |
37 | Bu::String sExtraParam; | 37 | Bu::String sExtraParam; |
38 | if( argv[j][iEPos] == '=' ) | 38 | if( argv[j][iEPos] == '=' ) |
39 | { | 39 | { |
40 | sOpt.set( argv[j]+2, iEPos-2 ); | 40 | sOpt.set( argv[j]+2, iEPos-2 ); |
41 | iCount++; | 41 | iCount++; |
42 | sExtraParam.set( argv[j]+iEPos+1 ); | 42 | sExtraParam.set( argv[j]+iEPos+1 ); |
43 | } | 43 | } |
44 | else | 44 | else |
45 | { | 45 | { |
46 | sOpt.set( argv[j]+2 ); | 46 | sOpt.set( argv[j]+2 ); |
47 | } | 47 | } |
48 | if( !hlOption.has( sOpt ) ) | 48 | if( !hlOption.has( sOpt ) ) |
49 | { | 49 | { |
50 | optionError( "--" + sOpt ); | 50 | optionError( "--" + sOpt ); |
51 | } | 51 | } |
52 | else | 52 | else |
53 | { | 53 | { |
54 | // Long param, cool, that's easy, first search for = | 54 | // Long param, cool, that's easy, first search for = |
55 | Option *pOpt = hlOption.get( sOpt ); | 55 | Option *pOpt = hlOption.get( sOpt ); |
56 | if( pOpt->sUsed ) | 56 | if( pOpt->sUsed ) |
57 | { | 57 | { |
58 | Bu::StrArray aParams( iCount ); | 58 | Bu::StrArray aParams( iCount ); |
59 | aParams.append( sOpt ); | 59 | aParams.append( sOpt ); |
60 | if( sExtraParam.isSet() ) | 60 | if( sExtraParam.isSet() ) |
61 | { | 61 | { |
62 | aParams.append( argv[j]+iEPos+1 ); | 62 | aParams.append( argv[j]+iEPos+1 ); |
63 | } | 63 | } |
64 | for( int k = j+1; k < argc; k++ ) | 64 | for( int k = j+1; k < argc; k++ ) |
65 | { | 65 | { |
66 | aParams.append( argv[k] ); | 66 | aParams.append( argv[k] ); |
67 | } | 67 | } |
68 | j += pOpt->sUsed( aParams ); | 68 | j += pOpt->sUsed( aParams ); |
69 | } | 69 | } |
70 | else if( pOpt->pProxy ) | 70 | else if( pOpt->pProxy ) |
71 | { | 71 | { |
72 | if( pOpt->sOverride.isSet() ) | 72 | if( pOpt->sOverride.isSet() ) |
73 | { | 73 | { |
74 | pOpt->pProxy->setValue( pOpt->sOverride ); | 74 | pOpt->pProxy->setValue( pOpt->sOverride ); |
75 | } | 75 | } |
76 | else if( sExtraParam.isSet() ) | 76 | else if( sExtraParam.isSet() ) |
77 | { | 77 | { |
78 | pOpt->pProxy->setValueFromStr( sExtraParam ); | 78 | pOpt->pProxy->setValueFromStr( sExtraParam ); |
79 | } | 79 | } |
80 | else if( argv[j+1] != '\0' ) | 80 | else if( argv[j+1] != '\0' ) |
81 | { | 81 | { |
82 | pOpt->pProxy->setValueFromStr( argv[j+1] ); | 82 | pOpt->pProxy->setValueFromStr( argv[j+1] ); |
83 | j++; | 83 | j++; |
84 | } | 84 | } |
85 | } | 85 | } |
86 | } | 86 | } |
87 | } | 87 | } |
88 | else | 88 | else |
89 | { | 89 | { |
90 | int iCPos; | 90 | int iCPos; |
91 | for( iCPos = 1; argv[j][iCPos] != '\0'; iCPos++ ) | 91 | for( iCPos = 1; argv[j][iCPos] != '\0'; iCPos++ ) |
92 | { | 92 | { |
93 | if( !hsOption.has( argv[j][iCPos] ) ) | 93 | if( !hsOption.has( argv[j][iCPos] ) ) |
94 | { | 94 | { |
95 | Bu::String sOpt("-"); | 95 | Bu::String sOpt("-"); |
96 | sOpt += argv[j][iCPos]; | 96 | sOpt += argv[j][iCPos]; |
97 | optionError( sOpt ); | 97 | optionError( sOpt ); |
98 | } | 98 | } |
99 | else | 99 | else |
100 | { | 100 | { |
101 | Option *pOpt = hsOption.get( argv[j][iCPos] ); | 101 | Option *pOpt = hsOption.get( argv[j][iCPos] ); |
102 | char buf[2] = {argv[j][iCPos], '\0'}; | 102 | char buf[2] = {argv[j][iCPos], '\0'}; |
103 | if( pOpt->sUsed ) | 103 | if( pOpt->sUsed ) |
104 | { | 104 | { |
105 | Bu::StrArray aParams( argc-j+1 ); | 105 | Bu::StrArray aParams( argc-j+1 ); |
106 | aParams.append( buf ); | 106 | aParams.append( buf ); |
107 | int iMod = 0; | 107 | int iMod = 0; |
108 | if( argv[j][iCPos+1] != '\0' ) | 108 | if( argv[j][iCPos+1] != '\0' ) |
109 | { | 109 | { |
110 | aParams.append( argv[j]+iCPos+1 ); | 110 | aParams.append( argv[j]+iCPos+1 ); |
111 | iMod = -1; | 111 | iMod = -1; |
112 | } | 112 | } |
113 | for( int k = j+1; k < argc; k++ ) | 113 | for( int k = j+1; k < argc; k++ ) |
114 | { | 114 | { |
115 | aParams.append( argv[k] ); | 115 | aParams.append( argv[k] ); |
116 | } | 116 | } |
117 | int iUsed = pOpt->sUsed( aParams ); | 117 | int iUsed = pOpt->sUsed( aParams ); |
118 | if( iUsed > 0 ) | 118 | if( iUsed > 0 ) |
119 | { | 119 | { |
120 | j += iUsed + iMod; | 120 | j += iUsed + iMod; |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | else if( pOpt->pProxy ) | 124 | else if( pOpt->pProxy ) |
125 | { | 125 | { |
126 | if( pOpt->sOverride.isSet() ) | 126 | if( pOpt->sOverride.isSet() ) |
127 | { | 127 | { |
128 | pOpt->pProxy->setValue( pOpt->sOverride ); | 128 | pOpt->pProxy->setValue( pOpt->sOverride ); |
129 | } | 129 | } |
130 | else if( argv[j][iCPos+1] != '\0' ) | 130 | else if( argv[j][iCPos+1] != '\0' ) |
131 | { | 131 | { |
132 | pOpt->pProxy->setValueFromStr( | 132 | pOpt->pProxy->setValueFromStr( |
133 | argv[j]+iCPos+1 | 133 | argv[j]+iCPos+1 |
134 | ); | 134 | ); |
135 | break; | 135 | break; |
136 | } | 136 | } |
137 | else if( argv[j+1] ) | 137 | else if( argv[j+1] ) |
138 | { | 138 | { |
139 | pOpt->pProxy->setValueFromStr( | 139 | pOpt->pProxy->setValueFromStr( |
140 | argv[j+1] | 140 | argv[j+1] |
141 | ); | 141 | ); |
142 | j++; | 142 | j++; |
143 | break; | 143 | break; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |
150 | else | 150 | else |
151 | { | 151 | { |
152 | if( !sNonOption ) | 152 | if( !sNonOption ) |
153 | { | 153 | { |
154 | optionError( argv[j] ); | 154 | optionError( argv[j] ); |
155 | } | 155 | } |
156 | else | 156 | else |
157 | { | 157 | { |
158 | int iCount = argc-j; | 158 | int iCount = argc-j; |
159 | Bu::StrArray aParams( iCount ); | 159 | Bu::StrArray aParams( iCount ); |
160 | for( int k = j; k < argc; k++ ) | 160 | for( int k = j; k < argc; k++ ) |
161 | { | 161 | { |
162 | aParams.append( argv[k] ); | 162 | aParams.append( argv[k] ); |
163 | } | 163 | } |
164 | j += sNonOption( aParams ); | 164 | j += sNonOption( aParams ); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | void Bu::OptParser::parse( const Bu::String &sLine ) | 170 | void Bu::OptParser::parse( const Bu::String &sLine ) |
171 | { | 171 | { |
172 | Bu::String sCmd = sLine.clone(); | 172 | Bu::String sCmd = sLine.clone(); |
173 | int iParams = 0; | 173 | int iParams = 0; |
174 | bool bInGap = true; | 174 | bool bInGap = true; |
175 | bool bInQuote = false; | 175 | bool bInQuote = false; |
176 | for( Bu::String::iterator i = sCmd.begin(); i; i++ ) | 176 | for( Bu::String::iterator i = sCmd.begin(); i; i++ ) |
177 | { | 177 | { |
178 | if( bInQuote == false && (*i == ' ' || *i == '\t') ) | 178 | if( bInQuote == false && (*i == ' ' || *i == '\t') ) |
179 | { | 179 | { |
180 | if( bInGap == false ) | 180 | if( bInGap == false ) |
181 | { | 181 | { |
182 | bInGap = true; | 182 | bInGap = true; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | else if( *i == '"' ) | 185 | else if( *i == '"' ) |
186 | { | 186 | { |
187 | bInQuote = !bInQuote; | 187 | bInQuote = !bInQuote; |
188 | } | 188 | } |
@@ -211,242 +211,242 @@ void Bu::OptParser::parse( const Bu::String &sLine ) | |||
211 | } | 211 | } |
212 | } | 212 | } |
213 | else if( *i == '"' ) | 213 | else if( *i == '"' ) |
214 | { | 214 | { |
215 | bInQuote = !bInQuote; | 215 | bInQuote = !bInQuote; |
216 | } | 216 | } |
217 | else | 217 | else |
218 | { | 218 | { |
219 | if( bInGap ) | 219 | if( bInGap ) |
220 | { | 220 | { |
221 | asParam[iParams++] = i; | 221 | asParam[iParams++] = i; |
222 | bInGap = false; | 222 | bInGap = false; |
223 | } | 223 | } |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | parse( iParams, asParam ); | 227 | parse( iParams, asParam ); |
228 | 228 | ||
229 | delete[] asParam; | 229 | delete[] asParam; |
230 | } | 230 | } |
231 | 231 | ||
232 | void Bu::OptParser::addOption( const Option &opt ) | 232 | void Bu::OptParser::addOption( const Option &opt ) |
233 | { | 233 | { |
234 | lOption.append( opt ); | 234 | lOption.append( opt ); |
235 | if( opt.cOpt != '\0' ) | 235 | if( opt.cOpt != '\0' ) |
236 | hsOption.insert( opt.cOpt, &lOption.last() ); | 236 | hsOption.insert( opt.cOpt, &lOption.last() ); |
237 | if( opt.sOpt.isSet() ) | 237 | if( opt.sOpt.isSet() ) |
238 | hlOption.insert( opt.sOpt, &lOption.last() ); | 238 | hlOption.insert( opt.sOpt, &lOption.last() ); |
239 | } | 239 | } |
240 | 240 | ||
241 | void Bu::OptParser::setOverride( char cOpt, const Bu::Variant &sOverride ) | 241 | void Bu::OptParser::setOverride( char cOpt, const Bu::Variant &sOverride ) |
242 | { | 242 | { |
243 | hsOption.get( cOpt )->sOverride = sOverride; | 243 | hsOption.get( cOpt )->sOverride = sOverride; |
244 | } | 244 | } |
245 | 245 | ||
246 | void Bu::OptParser::setOverride( const Bu::String &sOpt, const Bu::Variant &sOverride ) | 246 | void Bu::OptParser::setOverride( const Bu::String &sOpt, const Bu::Variant &sOverride ) |
247 | { | 247 | { |
248 | hlOption.get( sOpt )->sOverride = sOverride; | 248 | hlOption.get( sOpt )->sOverride = sOverride; |
249 | } | 249 | } |
250 | 250 | ||
251 | void Bu::OptParser::setHelpDefault( const Bu::String &sOpt, const Bu::String &sTxt ) | 251 | void Bu::OptParser::setHelpDefault( const Bu::String &sOpt, const Bu::String &sTxt ) |
252 | { | 252 | { |
253 | hlOption.get( sOpt )->sHelpDefault = sTxt; | 253 | hlOption.get( sOpt )->sHelpDefault = sTxt; |
254 | } | 254 | } |
255 | 255 | ||
256 | void Bu::OptParser::addHelpOption( char c, const Bu::String &s, const Bu::String &sHelp ) | 256 | void Bu::OptParser::addHelpOption( char c, const Bu::String &s, const Bu::String &sHelp ) |
257 | { | 257 | { |
258 | Option o; | 258 | Option o; |
259 | o.sUsed = slot( this, &OptParser::optHelp ); | 259 | o.sUsed = slot( this, &OptParser::optHelp ); |
260 | o.cOpt = c; | 260 | o.cOpt = c; |
261 | o.sOpt = s; | 261 | o.sOpt = s; |
262 | o.sHelp = sHelp; | 262 | o.sHelp = sHelp; |
263 | addOption( o ); | 263 | addOption( o ); |
264 | } | 264 | } |
265 | 265 | ||
266 | void Bu::OptParser::addHelpBanner( const Bu::String &sText, bool bFormatted ) | 266 | void Bu::OptParser::addHelpBanner( const Bu::String &sText, bool bFormatted ) |
267 | { | 267 | { |
268 | Banner b; | 268 | Banner b; |
269 | b.sText = sText; | 269 | b.sText = sText; |
270 | b.bFormatted = bFormatted; | 270 | b.bFormatted = bFormatted; |
271 | if( lOption.getSize() > 0 ) | 271 | if( lOption.getSize() > 0 ) |
272 | { | 272 | { |
273 | for( b.iAfter = lOption.begin(); b.iAfter+1; b.iAfter++ ) { } | 273 | for( b.iAfter = lOption.begin(); b.iAfter+1; b.iAfter++ ) { } |
274 | } | 274 | } |
275 | lBanner.append( b ); | 275 | lBanner.append( b ); |
276 | } | 276 | } |
277 | 277 | ||
278 | int Bu::OptParser::optHelp( StrArray /*aParams*/ ) | 278 | int Bu::OptParser::optHelp( StrArray /*aParams*/ ) |
279 | { | 279 | { |
280 | bool bHasShort = false; | 280 | bool bHasShort = false; |
281 | int iMaxWidth = 0; | 281 | int iMaxWidth = 0; |
282 | int iScrWidth = 80; | 282 | int iScrWidth = 80; |
283 | char *env = getenv("COLUMNS"); | 283 | char *env = getenv("COLUMNS"); |
284 | if( env ) | 284 | if( env ) |
285 | iScrWidth = strtol( env, NULL, 10 ); | 285 | iScrWidth = strtol( env, NULL, 10 ); |
286 | for( OptionList::iterator i = lOption.begin(); i; i++ ) | 286 | for( OptionList::iterator i = lOption.begin(); i; i++ ) |
287 | { | 287 | { |
288 | if( (*i).cOpt != '\0' ) | 288 | if( (*i).cOpt != '\0' ) |
289 | bHasShort = true; | 289 | bHasShort = true; |
290 | int lOptSize = (*i).sOpt.getSize() + (*i).sHelpDefault.getSize(); | 290 | int lOptSize = (*i).sOpt.getSize() + (*i).sHelpDefault.getSize(); |
291 | if( (*i).sOpt.isSet() && iMaxWidth < lOptSize ) | 291 | if( (*i).sOpt.isSet() && iMaxWidth < lOptSize ) |
292 | iMaxWidth = lOptSize; | 292 | iMaxWidth = lOptSize; |
293 | } | 293 | } |
294 | int iIndent = 4; | 294 | int iIndent = 4; |
295 | if( bHasShort ) | 295 | if( bHasShort ) |
296 | iIndent += 4; | 296 | iIndent += 4; |
297 | if( iMaxWidth > 0 ) | 297 | if( iMaxWidth > 0 ) |
298 | iIndent += 4 + iMaxWidth; | 298 | iIndent += 4 + iMaxWidth; |
299 | 299 | ||
300 | BannerList::iterator iBanner; | 300 | BannerList::iterator iBanner; |
301 | for( iBanner = lBanner.begin(); iBanner; iBanner++ ) | 301 | for( iBanner = lBanner.begin(); iBanner; iBanner++ ) |
302 | { | 302 | { |
303 | if( (*iBanner).iAfter ) | 303 | if( (*iBanner).iAfter ) |
304 | break; | 304 | break; |
305 | 305 | ||
306 | if( (*iBanner).bFormatted ) | 306 | if( (*iBanner).bFormatted ) |
307 | sio << format( (*iBanner).sText, iScrWidth-1, 0 ); | 307 | sio << format( (*iBanner).sText, iScrWidth-1, 0 ); |
308 | else | 308 | else |
309 | sio << (*iBanner).sText; | 309 | sio << (*iBanner).sText; |
310 | sio << sio.nl; | 310 | sio << sio.nl; |
311 | } | 311 | } |
312 | for( OptionList::iterator i = lOption.begin(); i; i++ ) | 312 | for( OptionList::iterator i = lOption.begin(); i; i++ ) |
313 | { | 313 | { |
314 | sio << " "; | 314 | sio << " "; |
315 | if( bHasShort ) | 315 | if( bHasShort ) |
316 | { | 316 | { |
317 | if( (*i).cOpt == '\0' ) | 317 | if( (*i).cOpt == '\0' ) |
318 | sio << " "; | 318 | sio << " "; |
319 | else | 319 | else |
320 | sio << "-" << (*i).cOpt; | 320 | sio << "-" << (*i).cOpt; |
321 | sio << " "; | 321 | sio << " "; |
322 | } | 322 | } |
323 | if( iMaxWidth > 0 ) | 323 | if( iMaxWidth > 0 ) |
324 | { | 324 | { |
325 | if( (*i).sOpt.isSet() ) | 325 | if( (*i).sOpt.isSet() ) |
326 | { | 326 | { |
327 | sio << "--" << Fmt(iMaxWidth, Fmt::Left) | 327 | sio << "--" << Fmt(iMaxWidth, Fmt::Left) |
328 | << (*i).sOpt + (*i).sHelpDefault; | 328 | << (*i).sOpt + (*i).sHelpDefault; |
329 | } | 329 | } |
330 | else | 330 | else |
331 | { | 331 | { |
332 | sio << " " << Fmt(iMaxWidth) << ""; | 332 | sio << " " << Fmt(iMaxWidth) << ""; |
333 | } | 333 | } |
334 | sio << " "; | 334 | sio << " "; |
335 | } | 335 | } |
336 | sio << format( (*i).sHelp, iScrWidth-iIndent-1, iIndent ); | 336 | sio << format( (*i).sHelp, iScrWidth-iIndent-1, iIndent ); |
337 | sio << sio.nl; | 337 | sio << sio.nl; |
338 | 338 | ||
339 | for( ; iBanner; iBanner++ ) | 339 | for( ; iBanner; iBanner++ ) |
340 | { | 340 | { |
341 | if( (*iBanner).iAfter != i ) | 341 | if( (*iBanner).iAfter != i ) |
342 | break; | 342 | break; |
343 | 343 | ||
344 | if( (*iBanner).bFormatted ) | 344 | if( (*iBanner).bFormatted ) |
345 | sio << format( (*iBanner).sText, iScrWidth-1, 0 ); | 345 | sio << format( (*iBanner).sText, iScrWidth-1, 0 ); |
346 | else | 346 | else |
347 | sio << (*iBanner).sText; | 347 | sio << (*iBanner).sText; |
348 | sio << sio.nl; | 348 | sio << sio.nl; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | exit( 0 ); | 351 | exit( 0 ); |
352 | return 0; | 352 | return 0; |
353 | } | 353 | } |
354 | 354 | ||
355 | void Bu::OptParser::optionError( const Bu::String &sOption ) | 355 | void Bu::OptParser::optionError( const Bu::String &sOption ) |
356 | { | 356 | { |
357 | sio << "Unregcognized option discovered: " << sOption << sio.nl << sio.nl; | 357 | sio << "Unregcognized option discovered: " << sOption << sio.nl << sio.nl; |
358 | exit( 1 ); | 358 | exit( 1 ); |
359 | } | 359 | } |
360 | 360 | ||
361 | void Bu::OptParser::setNonOption( OptionSignal sSignal ) | 361 | void Bu::OptParser::setNonOption( OptionSignal sSignal ) |
362 | { | 362 | { |
363 | sNonOption = sSignal; | 363 | sNonOption = sSignal; |
364 | } | 364 | } |
365 | 365 | ||
366 | Bu::String Bu::OptParser::format( const Bu::String &sIn, int iWidth, | 366 | Bu::String Bu::OptParser::format( const Bu::String &sIn, int iWidth, |
367 | int iIndent ) | 367 | int iIndent ) |
368 | { | 368 | { |
369 | Bu::String sOut; | 369 | Bu::String sOut; |
370 | Bu::String sIndent; | 370 | Bu::String sIndent; |
371 | for( int j = 0; j < iIndent; j++ ) | 371 | for( int j = 0; j < iIndent; j++ ) |
372 | sIndent.append(" ", 1); | 372 | sIndent.append(" ", 1); |
373 | bool bFirst = true; | 373 | bool bFirst = true; |
374 | int iSpaceCount = 0; | 374 | int iSpaceCount = 0; |
375 | bool bSpace = false; | 375 | bool bSpace = false; |
376 | int iPrevLineLen; | 376 | int iPrevLineLen; |
377 | int iLineLen = 0; | 377 | int iLineLen = 0; |
378 | Bu::String::const_iterator iLastSpace, iStart; | 378 | Bu::String::const_iterator iLastSpace, iStart; |
379 | for( Bu::String::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) | 379 | for( Bu::String::const_iterator i = iLastSpace = iStart = sIn.begin(); i; i++ ) |
380 | { | 380 | { |
381 | if( *i == ' ' ) | 381 | if( *i == ' ' ) |
382 | { | 382 | { |
383 | if( bSpace == false ) | 383 | if( bSpace == false ) |
384 | { | 384 | { |
385 | iLastSpace = i; | 385 | iLastSpace = i; |
386 | iSpaceCount++; | 386 | iSpaceCount++; |
387 | bSpace = true; | 387 | bSpace = true; |
388 | iPrevLineLen = iLineLen; | 388 | iPrevLineLen = iLineLen; |
389 | } | 389 | } |
390 | } | 390 | } |
391 | else | 391 | else |
392 | { | 392 | { |
393 | bSpace = false; | 393 | bSpace = false; |
394 | } | 394 | } |
395 | iLineLen++; | 395 | iLineLen++; |
396 | 396 | ||
397 | if( iLineLen >= iWidth ) | 397 | if( iLineLen >= iWidth ) |
398 | { | 398 | { |
399 | iSpaceCount--; | 399 | iSpaceCount--; |
400 | if( bFirst == true ) | 400 | if( bFirst == true ) |
401 | bFirst = false; | 401 | bFirst = false; |
402 | else | 402 | else |
403 | sOut += sIndent; | 403 | sOut += sIndent; |
404 | int iExtraSpaces = iWidth-iPrevLineLen; | 404 | int iExtraSpaces = iWidth-iPrevLineLen; |
405 | bSpace = false; | 405 | bSpace = false; |
406 | float fFill = 0.0; | 406 | float fFill = 0.0; |
407 | int iSubSpaceCount = 0; | 407 | int iSubSpaceCount = 0; |
408 | float fAdd = ((float)iExtraSpaces/(float)iSpaceCount); | 408 | float fAdd = ((float)iExtraSpaces/(float)iSpaceCount); |
409 | for( Bu::String::const_iterator k = iStart; k != iLastSpace; k++ ) | 409 | for( Bu::String::const_iterator k = iStart; k != iLastSpace; k++ ) |
410 | { | 410 | { |
411 | sOut += *k; | 411 | sOut += *k; |
412 | if( *k == ' ' ) | 412 | if( *k == ' ' ) |
413 | { | 413 | { |
414 | if( bSpace == false && iExtraSpaces > 0 ) | 414 | if( bSpace == false && iExtraSpaces > 0 ) |
415 | { | 415 | { |
416 | bSpace = true; | 416 | bSpace = true; |
417 | fFill += fAdd; | 417 | fFill += fAdd; |
418 | iSubSpaceCount++; | 418 | iSubSpaceCount++; |
419 | for( int sp = 0; sp < (int)(fFill); sp++ ) | 419 | for( int sp = 0; sp < (int)(fFill); sp++ ) |
420 | { | 420 | { |
421 | sOut += ' '; | 421 | sOut += ' '; |
422 | iExtraSpaces--; | 422 | iExtraSpaces--; |
423 | } | 423 | } |
424 | fFill -= (int)fFill; | 424 | fFill -= (int)fFill; |
425 | if( iSubSpaceCount == iSpaceCount && iExtraSpaces > 0 ) | 425 | if( iSubSpaceCount == iSpaceCount && iExtraSpaces > 0 ) |
426 | { | 426 | { |
427 | for(; iExtraSpaces > 0; iExtraSpaces-- ) | 427 | for(; iExtraSpaces > 0; iExtraSpaces-- ) |
428 | { | 428 | { |
429 | sOut += ' '; | 429 | sOut += ' '; |
430 | } | 430 | } |
431 | } | 431 | } |
432 | } | 432 | } |
433 | } | 433 | } |
434 | else | 434 | else |
435 | bSpace = false; | 435 | bSpace = false; |
436 | } | 436 | } |
437 | //sOut.append( iStart, iLastSpace ); | 437 | //sOut.append( iStart, iLastSpace ); |
438 | sOut.append("\n"); | 438 | sOut.append("\n"); |
439 | for(; iLastSpace && *iLastSpace == ' '; iLastSpace++ ) { } | 439 | for(; iLastSpace && *iLastSpace == ' '; iLastSpace++ ) { } |
440 | iStart = i = iLastSpace; | 440 | iStart = i = iLastSpace; |
441 | bSpace = false; | 441 | bSpace = false; |
442 | iLineLen = 1; | 442 | iLineLen = 1; |
443 | iSpaceCount = 0; | 443 | iSpaceCount = 0; |
444 | } | 444 | } |
445 | } | 445 | } |
446 | if( !bFirst ) | 446 | if( !bFirst ) |
447 | sOut += sIndent; | 447 | sOut += sIndent; |
448 | sOut.append( iStart ); | 448 | sOut.append( iStart ); |
449 | return sOut; | 449 | return sOut; |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
@@ -467,26 +467,26 @@ Bu::OptParser::_ValueProxy::~_ValueProxy() | |||
467 | // | 467 | // |
468 | 468 | ||
469 | Bu::OptParser::Option::Option() : | 469 | Bu::OptParser::Option::Option() : |
470 | cOpt( '\0' ), | 470 | cOpt( '\0' ), |
471 | pProxy( NULL ) | 471 | pProxy( NULL ) |
472 | { | 472 | { |
473 | } | 473 | } |
474 | 474 | ||
475 | Bu::OptParser::Option::Option( const Option &rSrc ) : | 475 | Bu::OptParser::Option::Option( const Option &rSrc ) : |
476 | cOpt( rSrc.cOpt ), | 476 | cOpt( rSrc.cOpt ), |
477 | sOpt( rSrc.sOpt ), | 477 | sOpt( rSrc.sOpt ), |
478 | sHelp( rSrc.sHelp ), | 478 | sHelp( rSrc.sHelp ), |
479 | sUsed( rSrc.sUsed ), | 479 | sUsed( rSrc.sUsed ), |
480 | pProxy( NULL ), | 480 | pProxy( NULL ), |
481 | sOverride( rSrc.sOverride ) | 481 | sOverride( rSrc.sOverride ) |
482 | { | 482 | { |
483 | if( rSrc.pProxy ) | 483 | if( rSrc.pProxy ) |
484 | pProxy = rSrc.pProxy->clone(); | 484 | pProxy = rSrc.pProxy->clone(); |
485 | } | 485 | } |
486 | 486 | ||
487 | Bu::OptParser::Option::~Option() | 487 | Bu::OptParser::Option::~Option() |
488 | { | 488 | { |
489 | delete pProxy; | 489 | delete pProxy; |
490 | pProxy = NULL; | 490 | pProxy = NULL; |
491 | } | 491 | } |
492 | 492 | ||