| @@ -11,7 +11,7 @@ | |||||
| <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> | <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> | ||||
| </SearchPaths> | </SearchPaths> | ||||
| </CompilerOptions> | </CompilerOptions> | ||||
| <Files Count="30"> | |||||
| <Files Count="31"> | |||||
| <Item1> | <Item1> | ||||
| <Filename Value="uutlAlgorithm.pas"/> | <Filename Value="uutlAlgorithm.pas"/> | ||||
| <UnitName Value="uutlAlgorithm"/> | <UnitName Value="uutlAlgorithm"/> | ||||
| @@ -132,6 +132,10 @@ | |||||
| <Filename Value="uutlVariantSet.pas"/> | <Filename Value="uutlVariantSet.pas"/> | ||||
| <UnitName Value="uutlVariantSet"/> | <UnitName Value="uutlVariantSet"/> | ||||
| </Item30> | </Item30> | ||||
| <Item31> | |||||
| <Filename Value="uutlCommandLine.pas"/> | |||||
| <UnitName Value="uutlCommandLine"/> | |||||
| </Item31> | |||||
| </Files> | </Files> | ||||
| <RequiredPkgs Count="2"> | <RequiredPkgs Count="2"> | ||||
| <Item1> | <Item1> | ||||
| @@ -11,7 +11,8 @@ uses | |||||
| uutlAlgorithm, uutlArrayContainer, uutlCommon, uutlComparer, uutlCompression, uutlEmbeddedProfiler, uutlEnumerator, | uutlAlgorithm, uutlArrayContainer, uutlCommon, uutlComparer, uutlCompression, uutlEmbeddedProfiler, uutlEnumerator, | ||||
| uutlEvent, uutlEventManager, uutlFilter, uutlGenerics, uutlInterfaces, uutlKeyCodes, uutlLinq, uutlListBase, | uutlEvent, uutlEventManager, uutlFilter, uutlGenerics, uutlInterfaces, uutlKeyCodes, uutlLinq, uutlListBase, | ||||
| uutlLogger, uutlMCF, uutlObservable, uutlSScanf, uutlStreamHelper, uutlSyncObjs, uutlThreads, uutlTypes, | uutlLogger, uutlMCF, uutlObservable, uutlSScanf, uutlStreamHelper, uutlSyncObjs, uutlThreads, uutlTypes, | ||||
| uutlXmlHelper, uutlVariantObject, uutlVariantProperty, uutlVariantEnum, uutlVariantSet, LazarusPackageIntf; | |||||
| uutlXmlHelper, uutlVariantObject, uutlVariantProperty, uutlVariantEnum, uutlVariantSet, uutlCommandLine, | |||||
| LazarusPackageIntf; | |||||
| implementation | implementation | ||||
| @@ -0,0 +1,55 @@ | |||||
| unit uutlCommandLine; | |||||
| {$mode objfpc}{$H+} | |||||
| interface | |||||
| uses | |||||
| getopts; | |||||
| { Forward definitions so getopts doesn't have to be used } | |||||
| type | |||||
| TOption = getopts.TOption; | |||||
| const | |||||
| No_Argument = getopts.No_Argument; | |||||
| Required_Argument = getopts.Required_Argument; | |||||
| Optional_Argument = getopts.Optional_Argument; | |||||
| type | |||||
| TOptionHandler = procedure (const opt: string; const OptArg: string); | |||||
| TOptions = array[1..10] of TOption; | |||||
| POptions = ^TOptions; | |||||
| (* | |||||
| Process all arguments as defined in ShortOpts and LongOpts | |||||
| Arguments: | |||||
| ShortOpts - short option string (see getopts) | |||||
| LongOpts - pointer to the first element of an array of long options, terminated by an empty option record (see getopts) | |||||
| Handler - pointer to a function called to handle each option | |||||
| Result: | |||||
| The index of the first option not processed (this correctly handles the -- delimiter) | |||||
| *) | |||||
| function utlHandleAllOptions(ShortOpts : String; LongOpts : POptions; Handler: TOptionHandler): integer; | |||||
| implementation | |||||
| function utlHandleAllOptions(ShortOpts : String; LongOpts : POptions; Handler: TOptionHandler): integer; | |||||
| var | |||||
| optIndex: integer; | |||||
| opt: string; | |||||
| begin | |||||
| optIndex:= 0; | |||||
| while True do begin | |||||
| opt:= GetLongOpts(ShortOpts, POption(LongOpts), optIndex); | |||||
| if opt = EndOfOptions then | |||||
| break; | |||||
| if opt = #0 then | |||||
| opt:= LongOpts^[optIndex].Name; | |||||
| Handler(opt, getopts.optArg); | |||||
| end; | |||||
| Result:= getopts.OptInd; | |||||
| end; | |||||
| end. | |||||