home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / getopt.h < prev    next >
C/C++ Source or Header  |  1992-01-19  |  4KB  |  108 lines

  1. /* declarations for getopt
  2.    Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* For communication from `getopt' to the caller.
  19.    When `getopt' finds an option that takes an argument,
  20.    the argument value is returned here.
  21.    Also, when `ordering' is RETURN_IN_ORDER,
  22.    each non-option ARGV-element is returned here.  */
  23.  
  24. extern char *optarg;
  25. extern char *Optarg;
  26.  
  27. /* Index in ARGV of the next element to be scanned.
  28.    This is used for communication to and from the caller
  29.    and for communication between successive calls to `getopt'.
  30.  
  31.    On entry to `getopt', zero means this is the first call; initialize.
  32.  
  33.    When `getopt' returns EOF, this is the index of the first of the
  34.    non-option elements that the caller should itself scan.
  35.  
  36.    Otherwise, `optind' communicates from one call to the next
  37.    how much of ARGV has been scanned so far.  */
  38.  
  39. extern int optind;
  40. extern int Optind, Optlead;
  41.  
  42. /* Callers store zero here to inhibit the error message `getopt' prints
  43.    for unrecognized options.  */
  44.  
  45. extern int opterr;
  46. extern int Opterr;
  47.  
  48. /* Describe the long-named options requested by the application.
  49.    _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
  50.    element containing a name which is zero.
  51.  
  52.    The field `has_arg' is:
  53.    0 if the option does not take an argument,
  54.    1 if the option requires an argument,
  55.    2 if the option takes an optional argument.
  56.  
  57.    If the field `flag' is nonzero, it points to a variable that is set
  58.    to the value given in the field `val' when the option is found, but
  59.    left unchanged if the option is not found.
  60.  
  61.    To have a long-named option do something other than set an `int' to
  62.    a compiled-in constant, such as set a value from `optarg', set the
  63.    option's `flag' field to zero and its `val' field to a nonzero
  64.    value (the equivalent single-letter option character, if there is
  65.    one).  For long options that have a zero `flag' field, `getopt'
  66.    returns the contents of the `val' field.  */
  67.  
  68. struct option
  69. {
  70.   char *name;
  71.   int has_arg;
  72.   int *flag;
  73.   int val;
  74. };
  75.  
  76. #if defined(__STDC__) || defined(OS2)
  77. extern const struct option *_getopt_long_options;
  78. #else
  79. extern struct option *_getopt_long_options;
  80. #endif
  81.  
  82. /* If nonzero, '-' can introduce long-named options.
  83.    Set by getopt_long_only.  */
  84.  
  85. extern int _getopt_long_only;
  86.  
  87. /* The index in GETOPT_LONG_OPTIONS of the long-named option found.
  88.    Only valid when a long-named option has been found by the most
  89.    recent call to `getopt'.  */
  90.  
  91. extern int option_index;
  92.  
  93. #if defined(__STDC__) || defined(OS2)
  94. int getopt (int argc, char **argv, const char *shortopts);
  95. int getopt_long (int argc, char **argv, const char *shortopts,
  96.          const struct option *longopts, int *longind);
  97. int getopt_long_only (int argc, char **argv, const char *shortopts,
  98.               const struct option *longopts, int *longind);
  99. void envopt(int *pargc, char ***pargv, char *optstr);
  100. int Getopt (int argc, char **argv, const char *shortopts, const char *leader);
  101. #else
  102. int getopt ();
  103. int getopt_long ();
  104. int getopt_long_only ();
  105. void envopt();
  106. int Getopt ();
  107. #endif
  108.