home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DIFFPT.ZIP / GETOPT.H < prev    next >
C/C++ Source or Header  |  1991-07-01  |  4KB  |  103 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.  
  26. /* Index in ARGV of the next element to be scanned.
  27.    This is used for communication to and from the caller
  28.    and for communication between successive calls to `getopt'.
  29.  
  30.    On entry to `getopt', zero means this is the first call; initialize.
  31.  
  32.    When `getopt' returns EOF, this is the index of the first of the
  33.    non-option elements that the caller should itself scan.
  34.  
  35.    Otherwise, `optind' communicates from one call to the next
  36.    how much of ARGV has been scanned so far.  */
  37.  
  38. extern int optind;
  39.  
  40. /* Callers store zero here to inhibit the error message `getopt' prints
  41.    for unrecognized options.  */
  42.  
  43. extern int opterr;
  44.  
  45. /* Describe the long-named options requested by the application.
  46.    _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
  47.    element containing a name which is zero.
  48.  
  49.    The field `has_arg' is:
  50.    0 if the option does not take an argument,
  51.    1 if the option requires an argument,
  52.    2 if the option takes an optional argument.
  53.  
  54.    If the field `flag' is nonzero, it points to a variable that is set
  55.    to the value given in the field `val' when the option is found, but
  56.    left unchanged if the option is not found.
  57.  
  58.    To have a long-named option do something other than set an `int' to
  59.    a compiled-in constant, such as set a value from `optarg', set the
  60.    option's `flag' field to zero and its `val' field to a nonzero
  61.    value (the equivalent single-letter option character, if there is
  62.    one).  For long options that have a zero `flag' field, `getopt'
  63.    returns the contents of the `val' field.  */
  64.  
  65. struct option
  66. {
  67.   char *name;
  68.   int has_arg;
  69.   int *flag;
  70.   int val;
  71. };
  72.  
  73. #if defined(__STDC__) || defined(MSDOS)
  74. extern const struct option *_getopt_long_options;
  75. #else
  76. extern struct option *_getopt_long_options;
  77. #endif
  78.  
  79. /* If nonzero, '-' can introduce long-named options.
  80.    Set by getopt_long_only.  */
  81.  
  82. extern int _getopt_long_only;
  83.  
  84. /* The index in GETOPT_LONG_OPTIONS of the long-named option found.
  85.    Only valid when a long-named option has been found by the most
  86.    recent call to `getopt'.  */
  87.  
  88. extern int option_index;
  89.  
  90. #if defined(__STDC__) || defined(MSDOS)
  91. int getopt (int argc, char **argv, const char *shortopts);
  92. int getopt_long (int argc, char **argv, const char *shortopts,
  93.          const struct option *longopts, int *longind);
  94. int getopt_long_only (int argc, char **argv, const char *shortopts,
  95.               const struct option *longopts, int *longind);
  96. void envopt(int *pargc, char ***pargv, char *optstr);
  97. #else
  98. int getopt ();
  99. int getopt_long ();
  100. int getopt_long_only ();
  101. void envopt();
  102. #endif
  103.