home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / getopt.h < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  128 lines

  1. /*****************************************************************************
  2.  * $Id: getopt.h,v 1.2 1992/09/02 20:08:05 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: getopt.h,v $
  5.  * Revision 1.2  1992/09/02  20:08:05  ak
  6.  * Version AK200
  7.  * - Tape access
  8.  * - Quick file access
  9.  * - OS/2 extended attributes
  10.  * - Some OS/2 fixes
  11.  * - Some fixes of Kai Uwe Rommel
  12.  *
  13.  * Revision 1.1.1.1  1992/09/02  19:21:35  ak
  14.  * Original GNU Tar 1.10 with some filenames changed for FAT compatibility.
  15.  *
  16.  * Revision 1.1  1992/09/02  19:21:33  ak
  17.  * Initial revision
  18.  *
  19.  *****************************************************************************/
  20.  
  21. /* Declarations for getopt.
  22.    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  23.  
  24.    This program is free software; you can redistribute it and/or modify
  25.    it under the terms of the GNU General Public License as published by
  26.    the Free Software Foundation; either version 2, or (at your option)
  27.    any later version.
  28.  
  29.    This program is distributed in the hope that it will be useful,
  30.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  31.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  32.    GNU General Public License for more details.
  33.  
  34.    You should have received a copy of the GNU General Public License
  35.    along with this program; if not, write to the Free Software
  36.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  37.  
  38. #ifndef _GETOPT_H_
  39. #define _GETOPT_H_
  40.  
  41. /* For communication from `getopt' to the caller.
  42.    When `getopt' finds an option that takes an argument,
  43.    the argument value is returned here.
  44.    Also, when `ordering' is RETURN_IN_ORDER,
  45.    each non-option ARGV-element is returned here.  */
  46.  
  47. extern char *optarg;
  48.  
  49. /* Index in ARGV of the next element to be scanned.
  50.    This is used for communication to and from the caller
  51.    and for communication between successive calls to `getopt'.
  52.  
  53.    On entry to `getopt', zero means this is the first call; initialize.
  54.  
  55.    When `getopt' returns EOF, this is the index of the first of the
  56.    non-option elements that the caller should itself scan.
  57.  
  58.    Otherwise, `optind' communicates from one call to the next
  59.    how much of ARGV has been scanned so far.  */
  60.  
  61. extern int optind;
  62.  
  63. /* Callers store zero here to inhibit the error message `getopt' prints
  64.    for unrecognized options.  */
  65.  
  66. extern int opterr;
  67.  
  68. /* Describe the long-named options requested by the application.
  69.    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  70.    of `struct option' terminated by an element containing a name which is
  71.    zero.
  72.  
  73.    The field `has_arg' is:
  74.    no_argument        (or 0) if the option does not take an argument,
  75.    required_argument    (or 1) if the option requires an argument,
  76.    optional_argument     (or 2) if the option takes an optional argument.
  77.  
  78.    If the field `flag' is not NULL, it points to a variable that is set
  79.    to the value given in the field `val' when the option is found, but
  80.    left unchanged if the option is not found.
  81.  
  82.    To have a long-named option do something other than set an `int' to
  83.    a compiled-in constant, such as set a value from `optarg', set the
  84.    option's `flag' field to zero and its `val' field to a nonzero
  85.    value (the equivalent single-letter option character, if there is
  86.    one).  For long options that have a zero `flag' field, `getopt'
  87.    returns the contents of the `val' field.  */
  88.  
  89. struct option
  90. {
  91. #ifdef    __STDC__
  92.   const char *name;
  93. #else
  94.   char *name;
  95. #endif
  96.   enum
  97.     {
  98.       no_argument,
  99.       required_argument,
  100.       optional_argument
  101.     } has_arg;
  102.   int *flag;
  103.   int val;
  104. };
  105.  
  106. #if defined(__STDC__) || defined(MSDOS) || defined(OS2)
  107. extern int getopt (int argc, char *const *argv, const char *shortopts);
  108. extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  109.                 const struct option *longopts, int *longind);
  110. extern int getopt_long_only (int argc, char *const *argv,
  111.                  const char *shortopts,
  112.                      const struct option *longopts, int *longind);
  113.  
  114. /* Internal only.  Users should not call this directly.  */
  115. extern int _getopt_internal (int argc, char *const *argv,
  116.                  const char *shortopts,
  117.                      const struct option *longopts, int *longind,
  118.                  int long_only);
  119. #else /* not __STDC__ */
  120. extern int getopt ();
  121. extern int getopt_long ();
  122. extern int getopt_long_only ();
  123.  
  124. extern int _getopt_internal ();
  125. #endif /* not __STDC__ */
  126.  
  127. #endif /* _GETOPT_H_ */
  128.