"Fossies" - the Fresh Open Source Software Archive

Member "npadmin-0.14/getopt.h" (19 Apr 2001, 5402 Bytes) of package /linux/misc/old/npadmin-0.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (c) 2000 Ben Woodard
    2  * All rights reserved.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public Licence
    6  * as published by the Free Software Foundation; either version 2
    7  * of the Licence, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRENTY; without even the implied warrenty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   12  * GNU General Public Licence in the COPYING file for more
   13  * details.
   14  *
   15  * You should have received a copy of the GNU Library General 
   16  * Public License along with the GNU C Library; see the file 
   17  * COPYING.LIB.  If not, write to the Free Software Foundation, 
   18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
   19  */
   20 
   21 /* Declarations for getopt.
   22    Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
   23 
   24 NOTE: The canonical source of this file is maintained with the GNU C Library.
   25 Bugs can be reported to bug-glibc@gnu.org.
   26 
   27 This program is free software; you can redistribute it and/or modify it
   28 under the terms of the GNU General Public License as published by the
   29 Free Software Foundation; either version 2, or (at your option) any
   30 later version.
   31 
   32 This program is distributed in the hope that it will be useful,
   33 but WITHOUT ANY WARRANTY; without even the implied warranty of
   34 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   35 GNU General Public License for more details.
   36 
   37 You should have received a copy of the GNU General Public License
   38 along with this program; if not, write to the Free Software
   39 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
   40 USA.  */
   41 
   42 #ifndef _GETOPT_H
   43 #define _GETOPT_H 1
   44 
   45 #ifdef  __cplusplus
   46 extern "C" {
   47 #endif
   48 
   49 /* For communication from `getopt' to the caller.
   50    When `getopt' finds an option that takes an argument,
   51    the argument value is returned here.
   52    Also, when `ordering' is RETURN_IN_ORDER,
   53    each non-option ARGV-element is returned here.  */
   54 
   55 extern char *optarg;
   56 
   57 /* Index in ARGV of the next element to be scanned.
   58    This is used for communication to and from the caller
   59    and for communication between successive calls to `getopt'.
   60 
   61    On entry to `getopt', zero means this is the first call; initialize.
   62 
   63    When `getopt' returns -1, this is the index of the first of the
   64    non-option elements that the caller should itself scan.
   65 
   66    Otherwise, `optind' communicates from one call to the next
   67    how much of ARGV has been scanned so far.  */
   68 
   69 extern int optind;
   70 
   71 /* Callers store zero here to inhibit the error message `getopt' prints
   72    for unrecognized options.  */
   73 
   74 extern int opterr;
   75 
   76 /* Set to an option character which was unrecognized.  */
   77 
   78 extern int optopt;
   79 
   80 /* Describe the long-named options requested by the application.
   81    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
   82    of `struct option' terminated by an element containing a name which is
   83    zero.
   84 
   85    The field `has_arg' is:
   86    no_argument      (or 0) if the option does not take an argument,
   87    required_argument    (or 1) if the option requires an argument,
   88    optional_argument    (or 2) if the option takes an optional argument.
   89 
   90    If the field `flag' is not NULL, it points to a variable that is set
   91    to the value given in the field `val' when the option is found, but
   92    left unchanged if the option is not found.
   93 
   94    To have a long-named option do something other than set an `int' to
   95    a compiled-in constant, such as set a value from `optarg', set the
   96    option's `flag' field to zero and its `val' field to a nonzero
   97    value (the equivalent single-letter option character, if there is
   98    one).  For long options that have a zero `flag' field, `getopt'
   99    returns the contents of the `val' field.  */
  100 
  101 struct option
  102 {
  103 #if defined (__STDC__) && __STDC__
  104   const char *name;
  105 #else
  106   char *name;
  107 #endif
  108   /* has_arg can't be an enum because some compilers complain about
  109      type mismatches in all the code that assumes it is an int.  */
  110   int has_arg;
  111   int *flag;
  112   int val;
  113 };
  114 
  115 /* Names for the values of the `has_arg' field of `struct option'.  */
  116 
  117 #define no_argument     0
  118 #define required_argument   1
  119 #define optional_argument   2
  120 
  121 #if defined (__STDC__) && __STDC__
  122 #ifdef __GNU_LIBRARY__
  123 /* Many other libraries have conflicting prototypes for getopt, with
  124    differences in the consts, in stdlib.h.  To avoid compilation
  125    errors, only prototype getopt for the GNU C library.  */
  126 extern int getopt (int argc, char *const *argv, const char *shortopts);
  127 #else /* not __GNU_LIBRARY__ */
  128 extern int getopt ();
  129 #endif /* __GNU_LIBRARY__ */
  130 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  131                 const struct option *longopts, int *longind);
  132 extern int getopt_long_only (int argc, char *const *argv,
  133                  const char *shortopts,
  134                      const struct option *longopts, int *longind);
  135 
  136 /* Internal only.  Users should not call this directly.  */
  137 extern int _getopt_internal (int argc, char *const *argv,
  138                  const char *shortopts,
  139                      const struct option *longopts, int *longind,
  140                  int long_only);
  141 #else /* not __STDC__ */
  142 extern int getopt ();
  143 extern int getopt_long ();
  144 extern int getopt_long_only ();
  145 
  146 extern int _getopt_internal ();
  147 #endif /* __STDC__ */
  148 
  149 #ifdef  __cplusplus
  150 }
  151 #endif
  152 
  153 #endif /* _GETOPT_H */