our_getopt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * our_getopt.h
  3. *
  4. * Header file for the getopt_long deprived.
  5. *
  6. * $Id: our_getopt.h,v 1.1.1.1 2002/06/21 08:52:00 fenix_nl Exp $
  7. */
  8. /* Declarations for getopt.
  9. Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
  10. This file is part of the GNU C Library.
  11. The GNU C Library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Library General Public License as
  13. published by the Free Software Foundation; either version 2 of the
  14. License, or (at your option) any later version.
  15. The GNU C Library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Library General Public License for more details.
  19. You should have received a copy of the GNU Library General Public
  20. License along with the GNU C Library; see the file COPYING.LIB. If not,
  21. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA. */
  23. #ifndef _GETOPT_H
  24. #ifndef __need_getopt
  25. # define _GETOPT_H 1
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* For communication from `getopt' to the caller.
  31. When `getopt' finds an option that takes an argument,
  32. the argument value is returned here.
  33. Also, when `ordering' is RETURN_IN_ORDER,
  34. each non-option ARGV-element is returned here. */
  35. extern char *optarg;
  36. /* Index in ARGV of the next element to be scanned.
  37. This is used for communication to and from the caller
  38. and for communication between successive calls to `getopt'.
  39. On entry to `getopt', zero means this is the first call; initialize.
  40. When `getopt' returns -1, this is the index of the first of the
  41. non-option elements that the caller should itself scan.
  42. Otherwise, `optind' communicates from one call to the next
  43. how much of ARGV has been scanned so far. */
  44. extern int optind;
  45. /* Callers store zero here to inhibit the error message `getopt' prints
  46. for unrecognized options. */
  47. extern int opterr;
  48. /* Set to an option character which was unrecognized. */
  49. extern int optopt;
  50. #ifndef __need_getopt
  51. /* Describe the long-named options requested by the application.
  52. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  53. of `struct option' terminated by an element containing a name which is
  54. zero.
  55. The field `has_arg' is:
  56. no_argument (or 0) if the option does not take an argument,
  57. required_argument (or 1) if the option requires an argument,
  58. optional_argument (or 2) if the option takes an optional argument.
  59. If the field `flag' is not NULL, it points to a variable that is set
  60. to the value given in the field `val' when the option is found, but
  61. left unchanged if the option is not found.
  62. To have a long-named option do something other than set an `int' to
  63. a compiled-in constant, such as set a value from `optarg', set the
  64. option's `flag' field to zero and its `val' field to a nonzero
  65. value (the equivalent single-letter option character, if there is
  66. one). For long options that have a zero `flag' field, `getopt'
  67. returns the contents of the `val' field. */
  68. struct option
  69. {
  70. # if defined __STDC__ && __STDC__
  71. const char *name;
  72. # else
  73. char *name;
  74. # endif
  75. /* has_arg can't be an enum because some compilers complain about
  76. type mismatches in all the code that assumes it is an int. */
  77. int has_arg;
  78. int *flag;
  79. int val;
  80. };
  81. /* Names for the values of the `has_arg' field of `struct option'. */
  82. # define no_argument 0
  83. # define required_argument 1
  84. # define optional_argument 2
  85. #endif /* need getopt */
  86. /* Get definitions and prototypes for functions to process the
  87. arguments in ARGV (ARGC of them, minus the program name) for
  88. options given in OPTS.
  89. Return the option character from OPTS just read. Return -1 when
  90. there are no more options. For unrecognized options, or options
  91. missing arguments, `optopt' is set to the option letter, and '?' is
  92. returned.
  93. The OPTS string is a list of characters which are recognized option
  94. letters, optionally followed by colons, specifying that that letter
  95. takes an argument, to be placed in `optarg'.
  96. If a letter in OPTS is followed by two colons, its argument is
  97. optional. This behavior is specific to the GNU `getopt'.
  98. The argument `--' causes premature termination of argument
  99. scanning, explicitly telling `getopt' that there are no more
  100. options.
  101. If OPTS begins with `--', then non-option arguments are treated as
  102. arguments to the option '\0'. This behavior is specific to the GNU
  103. `getopt'. */
  104. #if defined __STDC__ && __STDC__
  105. # ifdef __GNU_LIBRARY__
  106. /* Many other libraries have conflicting prototypes for getopt, with
  107. differences in the consts, in stdlib.h. To avoid compilation
  108. errors, only prototype getopt for the GNU C library. */
  109. extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
  110. # else /* not __GNU_LIBRARY__ */
  111. extern int getopt ();
  112. # endif /* __GNU_LIBRARY__ */
  113. # ifndef __need_getopt
  114. extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
  115. const struct option *__longopts, int *__longind);
  116. extern int getopt_long_only (int __argc, char *const *__argv,
  117. const char *__shortopts,
  118. const struct option *__longopts, int *__longind);
  119. /* Internal only. Users should not call this directly. */
  120. extern int _getopt_internal (int __argc, char *const *__argv,
  121. const char *__shortopts,
  122. const struct option *__longopts, int *__longind,
  123. int __long_only);
  124. # endif
  125. #else /* not __STDC__ */
  126. extern int getopt ();
  127. # ifndef __need_getopt
  128. extern int getopt_long ();
  129. extern int getopt_long_only ();
  130. extern int _getopt_internal ();
  131. # endif
  132. #endif /* __STDC__ */
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. /* Make sure we later can get all the definitions and declarations. */
  137. #undef __need_getopt
  138. #endif /* getopt.h */