Changeset 126
- Timestamp:
- 08/16/07 18:20:08 (1 year ago)
- Files:
-
- misc/comboparse.d (added)
- misc/combotest.d (added)
- misc/configparse.d (modified) (4 diffs)
- misc/optparse.d (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
misc/configparse.d
r104 r126 39 39 40 40 version (Tango) { 41 // Although I've placed these Tango imports here, Tango support is 42 // incomplete. 41 43 import tango.io.FileSystem : FileSystem; 42 44 import tango.io.FilePath : FilePath; … … 55 57 import std.conv : toInt, toReal, ConvError; 56 58 import std.path : getBaseName, getDirName, join, pathsep; 57 import std.c.stdlib : getenv, strlen; 59 import std.c.stdlib : getenv; 60 import std.c.string : strlen; 58 61 } 59 62 … … 132 135 char[][] paths = split(env("PATH"), SystemPathSeparator); 133 136 foreach (path; paths) { 134 if ( new FileProxy(bin_name.join(path)).isExisting())137 if ((new FileProxy(bin_name.join(path))).isExisting()) 135 138 return file.join(path).toUtf8(); 136 139 } … … 228 231 /// Requests if a section exists in the parser. 229 232 bool has_section(char[] name) { 230 return name in config!is null;233 return (name in config) !is null; 231 234 } 232 235 private void no_section(char[] section) { misc/optparse.d
r125 r126 211 211 enum Action { /+++/Store, /+++/StoreConst, /+++/Append, /+++/AppendConst, /+++/Count, /+++/SetTrue, /+++/SetFalse, /+++/Callback, /+++/CallbackFancy, /+++/Help /+++/} 212 212 /// 213 enum ArgType { /+/+++/None,+/ /+++/String, /+++/Integer /+++/}213 enum ArgType { /+/+++/None,+/ /+++/String, /+++/Integer, /+++/Bool /+++/} 214 214 215 215 /++ … … 275 275 } 276 276 //enum Action { Store, StoreConst, Append, AppendConst, Count, SetTrue, SetFalse, Callback, CallbackFancy, Help } 277 bool supports_default() { 278 return false; 279 } 280 ArgType def_type() { 281 throw new OptionError("Option "~name~" does not support default arguments."); 282 } 283 bool has_default() { 284 throw new OptionError("Option "~name~" does not support default arguments."); 285 } 277 286 void issue_default(Options results) { 278 287 return; … … 333 342 static const ArgType default_type = ArgType.String; 334 343 ArgType type; 335 bool has_default = false;344 bool _has_default = false; 336 345 char[] default_string; 337 346 this(char[][] options, char[] name, ArgType type) { 338 347 super(options, name); 348 if (type != ArgType.Integer && type != ArgType.String) { 349 throw new OptionError("Argument type for Store and Append must be Integer or String."); 350 } 339 351 this.type = type; 340 352 } … … 345 357 } 346 358 } 359 override ArgType def_type() { 360 return this.type; 361 } 347 362 override Option def(char[] val) { 348 363 if (this.type != ArgType.String) 349 364 super.def(val); 350 this. has_default = true;365 this._has_default = true; 351 366 this.default_string = val; 352 367 return this; … … 355 370 if (this.type != ArgType.Integer) 356 371 super.def(val); 357 this. has_default = true;372 this._has_default = true; 358 373 this.default_string = .toString(val); 359 374 return this; 360 375 } 376 override bool supports_default() { 377 return true; 378 } 379 override bool has_default() { 380 return _has_default; 381 } 361 382 override void issue_default(Options results) { 362 if ( has_default) results.storeArg(this.name, this.default_string);383 if (_has_default) results.storeArg(this.name, this.default_string); 363 384 } 364 385 override bool hasArg() { … … 386 407 } 387 408 abstract class ConstOption : Option { 388 bool has_default = false;409 bool _has_default = false; 389 410 char[] default_value; 390 411 char[] const_value; … … 394 415 } 395 416 override Option def(char[] val) { 396 this. has_default = true;417 this._has_default = true; 397 418 this.default_value = val; 398 419 return this; 399 420 } 421 override ArgType def_type() { 422 return ArgType.String; 423 } 424 override bool supports_default() { 425 return true; 426 } 427 override bool has_default() { 428 return _has_default; 429 } 400 430 override void issue_default(Options results) { 401 if ( has_default) results.storeArg(this.name, this.default_value);431 if (_has_default) results.storeArg(this.name, this.default_value); 402 432 } 403 433 } … … 419 449 } 420 450 abstract class SetBool : Option { 421 bool has_default = false;451 bool _has_default = false; 422 452 bool default_flag = false; 423 453 this(char[][] options, char[] name) { … … 425 455 } 426 456 override Option def(bool val) { 427 this. has_default = true;457 this._has_default = true; 428 458 this.default_flag = val; 429 459 return this; 430 460 } 461 override ArgType def_type() { 462 return ArgType.Bool; 463 } 464 override bool supports_default() { 465 return true; 466 } 467 override bool has_default() { 468 return _has_default; 469 } 431 470 override void issue_default(Options results) { 432 if ( has_default) results.storeArg(this.name, this.default_flag);471 if (_has_default) results.storeArg(this.name, this.default_flag); 433 472 } 434 473 } … … 703 742 int idx; 704 743 Option match; 744 745 foreach (o; this.options) { 746 o.issue_default(options); 747 } 705 748 706 749 for (int i=0; i<args.length; ++i) { … … 778 821 } 779 822 } 780 foreach (o; this.options) {781 o.issue_default(options);782 }783 823 return options; 784 824 }
