our_getopt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * our_getopt.h
  3. *
  4. * Header file for the getopt_long deprived.
  5. */
  6. /* Declarations for getopt.
  7. Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
  8. This file is part of the GNU C Library.
  9. The GNU C Library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Library General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. The GNU C Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. Library General Public License for more details.
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB. If not,
  19. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA. */
  21. #ifndef _GETOPT_H
  22. #ifndef __need_getopt
  23. # define _GETOPT_H 1
  24. #endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* For communication from `getopt' to the caller.
  29. When `getopt' finds an option that takes an argument,
  30. the argument value is returned here.
  31. Also, when `ordering' is RETURN_IN_ORDER,
  32. each non-option ARGV-element is returned here. */
  33. extern char *optarg;
  34. /* Index in ARGV of the next element to be scanned.
  35. This is used for communication to and from the caller
  36. and for communication between successive calls to `getopt'.
  37. On entry to `getopt', zero means this is the first call; initialize.
  38. When `getopt' returns -1, this is the index of the first of the
  39. non-option elements that the caller should itself scan.
  40. Otherwise, `optind' communicates from one call to the next
  41. how much of ARGV has been scanned so far. */
  42. extern int optind;
  43. /* Callers store zero here to inhibit the error message `getopt' prints
  44. for unrecognized options. */
  45. extern int opterr;
  46. /* Set to an option character which was unrecognized. */
  47. extern int optopt;
  48. #ifndef __need_getopt
  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. #endif /* need getopt */
  84. /* Get definitions and prototypes for functions to process the
  85. arguments in ARGV (ARGC of them, minus the program name) for
  86. options given in OPTS.
  87. Return the option character from OPTS just read. Return -1 when
  88. there are no more options. For unrecognized options, or options
  89. missing arguments, `optopt' is set to the option letter, and '?' is
  90. returned.
  91. The OPTS string is a list of characters which are recognized option
  92. letters, optionally followed by colons, specifying that that letter
  93. takes an argument, to be placed in `optarg'.
  94. If a letter in OPTS is followed by two colons, its argument is
  95. optional. This behavior is specific to the GNU `getopt'.
  96. The argument `--' causes premature termination of argument
  97. scanning, explicitly telling `getopt' that there are no more
  98. options.
  99. If OPTS begins with `--', then non-option arguments are treated as
  100. arguments to the option '\0'. This behavior is specific to the GNU
  101. `getopt'. */
  102. #if defined __STDC__ && __STDC__
  103. # ifdef __GNU_LIBRARY__
  104. /* Many other libraries have conflicting prototypes for getopt, with
  105. differences in the consts, in stdlib.h. To avoid compilation
  106. errors, only prototype getopt for the GNU C library. */
  107. extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
  108. # else /* not __GNU_LIBRARY__ */
  109. extern int getopt ();
  110. # endif /* __GNU_LIBRARY__ */
  111. # ifndef __need_getopt
  112. extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
  113. const struct option *__longopts, int *__longind);
  114. extern int getopt_long_only (int __argc, char *const *__argv,
  115. const char *__shortopts,
  116. const struct option *__longopts, int *__longind);
  117. /* Internal only. Users should not call this directly. */
  118. extern int _getopt_internal (int __argc, char *const *__argv,
  119. const char *__shortopts,
  120. const struct option *__longopts, int *__longind,
  121. int __long_only);
  122. # endif
  123. #else /* not __STDC__ */
  124. extern int getopt ();
  125. # ifndef __need_getopt
  126. extern int getopt_long ();
  127. extern int getopt_long_only ();
  128. extern int _getopt_internal ();
  129. # endif
  130. #endif /* __STDC__ */
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. /* Make sure we later can get all the definitions and declarations. */
  135. #undef __need_getopt
  136. #endif /* getopt.h */