You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* Declarations for getopt.
  2. Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3. Copyright (C) 2000, 01, 2002 Salvador E. Tropea.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #ifndef HEADER_GETOPT_H
  16. #define HEADER_GETOPT_H 1
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* For communication from `getopt' to the caller.
  21. When `getopt' finds an option that takes an argument,
  22. the argument value is returned here.
  23. Also, when `ordering' is RETURN_IN_ORDER,
  24. each non-option ARGV-element is returned here. */
  25. extern char *CLY_optarg;
  26. /* Index in ARGV of the next element to be scanned.
  27. This is used for communication to and from the caller
  28. and for communication between successive calls to `getopt'.
  29. On entry to `getopt', zero means this is the first call; initialize.
  30. When `getopt' returns EOF, this is the index of the first of the
  31. non-option elements that the caller should itself scan.
  32. Otherwise, `optind' communicates from one call to the next
  33. how much of ARGV has been scanned so far. */
  34. extern int CLY_optind;
  35. /* Callers store zero here to inhibit the error message `getopt' prints
  36. for unrecognized options. */
  37. extern int CLY_opterr;
  38. /* Set to an option character which was unrecognized. */
  39. extern int CLY_optopt;
  40. /* Describe the long-named options requested by the application.
  41. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  42. of `struct option' terminated by an element containing a name which is
  43. zero.
  44. The field `has_arg' is:
  45. no_argument (or 0) if the option does not take an argument,
  46. required_argument (or 1) if the option requires an argument,
  47. optional_argument (or 2) if the option takes an optional argument.
  48. If the field `flag' is not NULL, it points to a variable that is set
  49. to the value given in the field `val' when the option is found, but
  50. left unchanged if the option is not found.
  51. To have a long-named option do something other than set an `int' to
  52. a compiled-in constant, such as set a value from `optarg', set the
  53. option's `flag' field to zero and its `val' field to a nonzero
  54. value (the equivalent single-letter option character, if there is
  55. one). For long options that have a zero `flag' field, `getopt'
  56. returns the contents of the `val' field. */
  57. struct CLY_option
  58. {
  59. const char *name;
  60. /* has_arg can't be an enum because some compilers complain about
  61. type mismatches in all the code that assumes it is an int. */
  62. int has_arg;
  63. int *flag;
  64. int val;
  65. };
  66. /* Names for the values of the `has_arg' field of `struct option'. */
  67. #define CLY_no_argument 0
  68. #define CLY_required_argument 1
  69. #define CLY_optional_argument 2
  70. extern int CLY_getopt(int argc, char *const *argv, const char *shortopts);
  71. extern int CLY_getopt_long(int argc, char *const *argv, const char *shortopts,
  72. const struct CLY_option *longopts, int *longind);
  73. extern int CLY_getopt_long_only(int argc, char *const *argv,
  74. const char *shortopts,
  75. const struct CLY_option *longopts,
  76. int *longind);
  77. /* Internal only. Users should not call this directly. */
  78. extern int CLY_getopt_internal(int argc, char *const *argv,
  79. const char *shortopts,
  80. const struct CLY_option *longopts,
  81. int *longind,
  82. int long_only);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* HEADER_GETOPT_H */