getopt_int.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _GETOPT_INT_H
  18. #define _GETOPT_INT_H 1
  19. extern int _getopt_internal (int ___argc, char *const *___argv,
  20. const char *__shortopts,
  21. const struct option *__longopts, int *__longind,
  22. int __long_only) attribute_hidden;
  23. /* Reentrant versions which can handle parsing multiple argument
  24. vectors at the same time. */
  25. enum
  26. {
  27. REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  28. };
  29. /* Data type for reentrant functions. */
  30. struct _getopt_data
  31. {
  32. /* These have exactly the same meaning as the corresponding global
  33. variables, except that they are used for the reentrant
  34. versions of getopt. */
  35. char *optarg;
  36. int optind;
  37. int opterr;
  38. int optopt;
  39. /* Internal members. */
  40. /* True if the internal members have been initialized. */
  41. smallint __initialized;
  42. /* If the POSIXLY_CORRECT environment variable is set. */
  43. smallint __posixly_correct;
  44. /* Describe how to deal with options that follow non-option ARGV-elements.
  45. If the caller did not specify anything,
  46. the default is REQUIRE_ORDER if the environment variable
  47. POSIXLY_CORRECT is defined, PERMUTE otherwise.
  48. REQUIRE_ORDER means don't recognize them as options;
  49. stop option processing when the first non-option is seen.
  50. This is what Unix does.
  51. This mode of operation is selected by either setting the environment
  52. variable POSIXLY_CORRECT, or using `+' as the first character
  53. of the list of option characters.
  54. PERMUTE is the default. We permute the contents of ARGV as we
  55. scan, so that eventually all the non-options are at the end.
  56. This allows options to be given in any order, even with programs
  57. that were not written to expect this.
  58. RETURN_IN_ORDER is an option available to programs that were
  59. written to expect options and other ARGV-elements in any order
  60. and that care about the ordering of the two. We describe each
  61. non-option ARGV-element as if it were the argument of an option
  62. with character code 1. Using `-' as the first character of the
  63. list of option characters selects this mode of operation.
  64. The special argument `--' forces an end of option-scanning regardless
  65. of the value of `ordering'. In the case of RETURN_IN_ORDER, only
  66. `--' can cause `getopt' to return -1 with `optind' != ARGC. */
  67. smallint __ordering;
  68. /* The next char to be scanned in the option-element
  69. in which the last option character we returned was found.
  70. This allows us to pick up the scan where we left off.
  71. If this is zero, or a null string, it means resume the scan
  72. by advancing to the next ARGV-element. */
  73. char *__nextchar;
  74. /* Handle permutation of arguments. */
  75. /* Describe the part of ARGV that contains non-options that have
  76. been skipped. `first_nonopt' is the index in ARGV of the first
  77. of them; `last_nonopt' is the index after the last of them. */
  78. int __first_nonopt;
  79. int __last_nonopt;
  80. #if defined _LIBC && defined USE_NONOPTION_FLAGS
  81. int __nonoption_flags_max_len;
  82. int __nonoption_flags_len;
  83. # endif
  84. };
  85. /* The initializer is necessary to set OPTIND and OPTERR to their
  86. default values and to clear the initialization flag. */
  87. #define _GETOPT_DATA_INITIALIZER { 1, 1 }
  88. #if 0 /* first is static on uClibc, the others not used */
  89. extern int _getopt_internal_r (int ___argc, char *const *___argv,
  90. const char *__shortopts,
  91. const struct option *__longopts, int *__longind,
  92. int __long_only, struct _getopt_data *__data);
  93. extern int _getopt_long_r (int ___argc, char *const *___argv,
  94. const char *__shortopts,
  95. const struct option *__longopts, int *__longind,
  96. struct _getopt_data *__data);
  97. extern int _getopt_long_only_r (int ___argc, char *const *___argv,
  98. const char *__shortopts,
  99. const struct option *__longopts,
  100. int *__longind,
  101. struct _getopt_data *__data);
  102. #endif
  103. #endif /* getopt_int.h */