getopt_int.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Internal declarations for getopt.
  2. Copyright (C) 1989-1994,1996-1999,2001,2003,2004
  3. Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, see <http://www.gnu.org/licenses/>.  */
  16. #ifndef _GETOPT_INT_H
  17. #define _GETOPT_INT_H 1
  18. extern int _getopt_internal (int ___argc, char *const *___argv,
  19. const char *__shortopts,
  20. const struct option *__longopts, int *__longind,
  21. int __long_only) attribute_hidden;
  22. /* Reentrant versions which can handle parsing multiple argument
  23. vectors at the same time. */
  24. /* For __ordering member */
  25. enum {
  26. REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  27. };
  28. /* Data type for reentrant functions. */
  29. struct _getopt_data
  30. {
  31. /* These have exactly the same meaning as the corresponding global
  32. variables, except that they are used for the reentrant
  33. versions of getopt. */
  34. int optind;
  35. int opterr;
  36. char *optarg;
  37. smalluint optopt; /* we store characters here, a byte is enough */
  38. /* Internal members. */
  39. /* True if the internal members have been initialized. */
  40. smallint __initialized;
  41. /* Describe how to deal with options that follow non-option ARGV-elements.
  42. If the caller did not specify anything,
  43. the default is REQUIRE_ORDER if the environment variable
  44. POSIXLY_CORRECT is defined, PERMUTE otherwise.
  45. REQUIRE_ORDER means don't recognize them as options;
  46. stop option processing when the first non-option is seen.
  47. This is what Unix does.
  48. This mode of operation is selected by either setting the environment
  49. variable POSIXLY_CORRECT, or using `+' as the first character
  50. of the list of option characters.
  51. PERMUTE is the default. We permute the contents of ARGV as we
  52. scan, so that eventually all the non-options are at the end.
  53. This allows options to be given in any order, even with programs
  54. that were not written to expect this.
  55. RETURN_IN_ORDER is an option available to programs that were
  56. written to expect options and other ARGV-elements in any order
  57. and that care about the ordering of the two. We describe each
  58. non-option ARGV-element as if it were the argument of an option
  59. with character code 1. Using `-' as the first character of the
  60. list of option characters selects this mode of operation.
  61. The special argument `--' forces an end of option-scanning regardless
  62. of the value of `ordering'. In the case of RETURN_IN_ORDER, only
  63. `--' can cause `getopt' to return -1 with `optind' != ARGC. */
  64. smallint __ordering;
  65. /* If the POSIXLY_CORRECT environment variable is set. */
  66. smallint __posixly_correct;
  67. /* The next char to be scanned in the option-element
  68. in which the last option character we returned was found.
  69. This allows us to pick up the scan where we left off.
  70. If this is zero, or a null string, it means resume the scan
  71. by advancing to the next ARGV-element. */
  72. char *__nextchar;
  73. /* Handle permutation of arguments. */
  74. /* Describe the part of ARGV that contains non-options that have
  75. been skipped. `first_nonopt' is the index in ARGV of the first
  76. of them; `last_nonopt' is the index after the last of them. */
  77. int __first_nonopt;
  78. int __last_nonopt;
  79. #if defined _LIBC && defined USE_NONOPTION_FLAGS
  80. int __nonoption_flags_max_len;
  81. int __nonoption_flags_len;
  82. # endif
  83. };
  84. /* The initializer is necessary to set OPTIND and OPTERR to their
  85. default values and to clear the initialization flag. */
  86. #define _GETOPT_DATA_INITIALIZER { 1, 1 }
  87. #if 0 /* first is static on uClibc, the others not used */
  88. extern int _getopt_internal_r (int ___argc, char *const *___argv,
  89. const char *__shortopts,
  90. const struct option *__longopts, int *__longind,
  91. int __long_only, struct _getopt_data *__data);
  92. #endif
  93. #if defined __UCLIBC_HAS_GNU_GETOPT__ || defined __UCLIBC_HAS_GETOPT_LONG__
  94. #ifndef __need_getopt
  95. extern int _getopt_long_r (int ___argc, char *const *___argv,
  96. const char *__shortopts,
  97. const struct option *__longopts, int *__longind,
  98. struct _getopt_data *__data);
  99. extern int _getopt_long_only_r (int ___argc, char *const *___argv,
  100. const char *__shortopts,
  101. const struct option *__longopts,
  102. int *__longind,
  103. struct _getopt_data *__data);
  104. #endif
  105. #endif
  106. #endif /* getopt_int.h */