Skip to content
Snippets Groups Projects
Select Git revision
  • b052be6c4a911cc98b91bda8b82e42b5ea3a96ac
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

Stack.pmod

Blame
  • Getopt.pmod 13.88 KiB
    #pike __REAL_VERSION__
    
    #pragma strict_types
    
    //! @[Getopt] is a group of functions which can be used to find command
    //! line options.
    //!
    //! Command line options come in two flavors: long and short. The short ones
    //! consists of a dash followed by a character (@tt{-t@}), the long ones
    //! consist of two dashes followed by a string of text (@tt{--test@}).
    //! The short options can also be combined, which means that you can write
    //! @tt{-tda@} instead of @tt{-t -d -a@}.
    //!
    //! Options can also require arguments, in which case they cannot be
    //! combined. To write an option with an argument you write
    //! @tt{-t @i{argument@}@} or @tt{-t@i{argument@}@} or
    //! @tt{--test=@i{argument@}@}.
    
    protected void my_error(string err, int throw_errors) {
      if(throw_errors) error(err);
      werror([string(0..255)]err);
      exit(1);
    }
    
    //!   This is a generic function to parse command line options of the
    //!   type @tt{-f@}, @tt{--foo@} or @tt{--foo=bar@}.
    //!
    //! @param argv
    //!   The first argument should be the array of strings that was sent as
    //!   the second argument to your @expr{main()@} function.
    //!
    //! @param shortform
    //!   The second is a string with the short form of your option. The
    //!   short form must be only one character long. It can also be an
    //!   array of strings, in which case any of the options in the array
    //!   will be accepted.
    //!
    //! @param longform
    //!   This is an alternative and maybe more readable way to give the
    //!   same option. If you give @expr{"foo"@} as @[longform] your program
    //!   will accept @tt{--foo@} as argument. This argument can also be
    //!   an array of strings, in which case any of the options in the
    //!   array will be accepted.
    //!
    //! @param envvars
    //!   This argument specifies an environment variable that can be used
    //!   to specify the same option, to make it easier to customize
    //!   program usage. It can also be an array of strings, in which case
    //!   any of the mentioned variables in the array may be used.
    //!
    //! @param def
    //!   This argument has two functions: It specifies if the option takes an
    //!   argument or not, and it informs @[find_option()] what to return if the
    //!   option is not present.
    //!
    //!   The value may be one of:
    //!   @mixed
    //!     @type int(0..0)|zero
    //!       The option does not require a value.
    //!     @type int(1..1)|string
    //!       The option requires a value, and @[def] will be returned
    //!       if the option is not present. If the option is present,
    //!       but does not have an argument @[find_option()] will fail.
    //!
    //!       Note that a set option will always return a @expr{string@},
    //!       so setting @[def] to @expr{1@} can be used to detect whether
    //!       the option is present or not.
    //!   @endmixed
    //!
    //! @param throw_errors