Parcourir la source

uutlCommandLine: new function utlHandleAllOptions

master
Martok il y a 9 ans
Parent
révision
eab7e2415a
3 fichiers modifiés avec 62 ajouts et 2 suppressions
  1. +5
    -1
      bitSpaceUtils.lpk
  2. +2
    -1
      bitSpaceUtils.pas
  3. +55
    -0
      uutlCommandLine.pas

+ 5
- 1
bitSpaceUtils.lpk Voir le fichier

@@ -11,7 +11,7 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Files Count="30">
<Files Count="31">
<Item1>
<Filename Value="uutlAlgorithm.pas"/>
<UnitName Value="uutlAlgorithm"/>
@@ -132,6 +132,10 @@
<Filename Value="uutlVariantSet.pas"/>
<UnitName Value="uutlVariantSet"/>
</Item30>
<Item31>
<Filename Value="uutlCommandLine.pas"/>
<UnitName Value="uutlCommandLine"/>
</Item31>
</Files>
<RequiredPkgs Count="2">
<Item1>


+ 2
- 1
bitSpaceUtils.pas Voir le fichier

@@ -11,7 +11,8 @@ uses
uutlAlgorithm, uutlArrayContainer, uutlCommon, uutlComparer, uutlCompression, uutlEmbeddedProfiler, uutlEnumerator,
uutlEvent, uutlEventManager, uutlFilter, uutlGenerics, uutlInterfaces, uutlKeyCodes, uutlLinq, uutlListBase,
uutlLogger, uutlMCF, uutlObservable, uutlSScanf, uutlStreamHelper, uutlSyncObjs, uutlThreads, uutlTypes,
uutlXmlHelper, uutlVariantObject, uutlVariantProperty, uutlVariantEnum, uutlVariantSet, LazarusPackageIntf;
uutlXmlHelper, uutlVariantObject, uutlVariantProperty, uutlVariantEnum, uutlVariantSet, uutlCommandLine,
LazarusPackageIntf;

implementation



+ 55
- 0
uutlCommandLine.pas Voir le fichier

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


Chargement…
Annuler
Enregistrer