[fpc-pascal]Re: About GetOpts and configuration file parsing

Yet Another Geek yetanothergeek at yahoo.com
Fri Jul 12 10:54:17 CEST 2002


If your program only requires short (single-character)
then you can just add this line at the beginning of
your program:


Not sure how you would handle multi-char (string)
options, though.

The problem is that the getopts unit follows the POSIX

standard, and most DOS programs do not .

The getopts unit decides if an option is a string
or a set of single-character options by whether 
the option begins with "-" or "--"

For instance, if the options are:

-a : Show the current date.
-b : Show the current time.
-c : Destroy the hard drive.
--abc : Tell a funny joke.

Then obviously, "-abc" and "--abc" 
will have completely different results !

So to use slashes with a mixure of single-char (short)
and multi-char (long) options you would need to
specify your
long options with '//' on the command line. This would
but it would look a little bit strange :


program slashopt;
  I: integer;
  { convert options from '/' to '-' before parsing ...
  for I:=1 to argc -1  do begin
    if ( argv[I] <> nil ) and ( argv[I][0] = '/' )
then  begin
      argv[I][0] := '-' ;
      if ( argv[I][1] = '/' ) then  argv[I][1] := '-' 
  { ... Now your command line is ready for the getopts
unit }

 - Jeff

Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free

More information about the fpc-pascal mailing list