Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-10

Using flag field in Getopts

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

luciano de souza

Hello listers,
Getopts offers very good features to process commandline arguments. As far as I could understand, I used it successfully. But it remains one unknown aspect for me. What is the field "flag"" of TOption record? How to use it?

  TOption = Record
    Name    : String;
    Has_arg : Integer;
    Flag    : PChar;
    Value   : Char;
  end;

Best regards,
Luciano

Reply by email

Henry Vermaak
to luciano de souza
luciano de souza wrote 12 lines
Hello listers, Getopts offers very good features to process commandline arguments. As far as I could understand, I used it successfully. But it remains one unknown aspect for me. What is the field "flag"" of TOption record? How to use it? TOption = Record Name : String; Has_arg : Integer; Flag : PChar; Value : Char; end;

I think the man page for getopt explains best how this is supposed to work:

flag specifies how results are returned for a long option. If flag is NULL, then getopt_long() returns val. (For example, the calling program may set val to the equivalent short option character.) Otherwise, getopt_long() returns 0, and flag points to a variable which is set to val if the option is found, but left unchanged if the option is not found.

Henry

Reply by email

luciano de souza
to Henry Vermaak

If I correctly understood, the flag field is to find arguments. If it remains "nil", the argument was not found, otherwise, it's a pointer to the short option.

2012/10/30, Henry Vermaak :

Show quoted text 27 lines
On 30/10/12 10:05, luciano de souza wrote: > Hello listers, > Getopts offers very good features to process commandline arguments. As > far as I could understand, I used it successfully. But it remains one > unknown aspect for me. What is the field "flag"" of TOption record? > How to use it? > > TOption = Record > Name : String; > Has_arg : Integer; > Flag : PChar; > Value : Char; > end; I think the man page for getopt explains best how this is supposed to work: flag specifies how results are returned for a long option. If flag is NULL, then getopt_long() returns val. (For example, the calling program may set val to the equivalent short option character.) Otherwise, getopt_long() returns 0, and flag points to a variable which is set to val if the option is found, but left unchanged if the option is not found. Henry _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Luciano de Souza

Reply by email