瀏覽代碼

uutlCommandLine: new function utlHandleAllOptions

master
Martok 9 年之前
父節點
當前提交
eab7e2415a
共有 3 個檔案被更改,包括 62 行新增 和 2 行删除
  1. +5
    -1
      bitSpaceUtils.lpk
  2. +2
    -1
      bitSpaceUtils.pas
  3. +55
    -0
      uutlCommandLine.pas

+ 5
- 1
bitSpaceUtils.lpk 查看文件

@@ -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>


+ 2
- 1
bitSpaceUtils.pas 查看文件

@@ -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




+ 55
- 0
uutlCommandLine.pas 查看文件

@@ -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.


Loading…
取消
儲存