Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2016 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e26fdadd4a88fbd3c27db74d09db5158 to your computer and use it in GitHub Desktop.
Save anonymous/e26fdadd4a88fbd3c27db74d09db5158 to your computer and use it in GitHub Desktop.
Program GetLongOpts_Error;
{ program demonstrating misbehaving of GetLongOpts }
{$h+}
Uses getopts;
Var c : char;
OptionIndex : Longint;
TheOpts : array[1..2] Of TOption;
flag : char;
Begin
flag := #0;
With TheOpts[1] Do
Begin
name := 'option';
has_arg := 0;
flag := @flag;
value := 'o';
End;
With TheOpts[2] Do
Begin
name := '';
has_arg := 0;
flag := Nil;
value := #0;
End;
c := #0;
WriteLn('Getting there');
Repeat
c := GetLongOpts('o',@TheOpts[1],OptionIndex);
Case c Of
'o' :
Begin
flag := 'x';
WriteLn(
'This will never be printed should we use long option. If you are here, it means short option was used, wasn''t it?'
);
break;
End;
End;
Until c=EndOfOptions;
If (flag <> #0) Then WriteLn('flag=',flag)
Else
WriteLn('flag=0');
End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment