getopt_int.h 4.6 KB

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