getopt.h 4.6 KB

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