getopt.h
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:5k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

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