mpeg4ip_getopt.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifdef WIN32
  2. #define HAVE_IN_PORT_T
  3. #define HAVE_SOCKLEN_T
  4. #define __STDC__ 1
  5. #else
  6. #include "mpeg4ip.h"
  7. #endif
  8. #ifdef HAVE_UNISTD_H
  9. #include <unistd.h>
  10. #endif
  11. #ifdef HAVE_GETOPT_H
  12. #include <getopt.h>
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #if !defined(HAVE_GETOPT) && !defined(HAVE_GETOPT_LONG) && !defined(HAVE_GETOPT_LONG_ONLY)
  18. /* For communication from `getopt' to the caller.
  19. When `getopt' finds an option that takes an argument,
  20. the argument value is returned here.
  21. Also, when `ordering' is RETURN_IN_ORDER,
  22. each non-option ARGV-element is returned here. */
  23. extern char *optarg;
  24. /* Index in ARGV of the next element to be scanned.
  25. This is used for communication to and from the caller
  26. and for communication between successive calls to `getopt'.
  27. On entry to `getopt', zero means this is the first call; initialize.
  28. When `getopt' returns -1, this is the index of the first of the
  29. non-option elements that the caller should itself scan.
  30. Otherwise, `optind' communicates from one call to the next
  31. how much of ARGV has been scanned so far. */
  32. extern int optind;
  33. /* Callers store zero here to inhibit the error message `getopt' prints
  34. for unrecognized options. */
  35. extern int opterr;
  36. /* Set to an option character which was unrecognized. */
  37. extern int optopt;
  38. #endif
  39. #if !defined(HAVE_GETOPT_LONG) && !defined(HAVE_GETOPT_LONG_ONLY)
  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 option
  58. {
  59. # if defined __STDC__ && __STDC__
  60. const char *name;
  61. # else
  62. char *name;
  63. # endif
  64. /* has_arg can't be an enum because some compilers complain about
  65. type mismatches in all the code that assumes it is an int. */
  66. int has_arg;
  67. int *flag;
  68. int val;
  69. };
  70. /* Names for the values of the `has_arg' field of `struct option'. */
  71. #ifndef no_argument
  72. # define no_argument 0
  73. # define required_argument 1
  74. # define optional_argument 2
  75. #endif
  76. #endif /* no HAVE_GETOPT defines */
  77. #ifndef HAVE_GETOPT
  78. /* Get definitions and prototypes for functions to process the
  79. arguments in ARGV (ARGC of them, minus the program name) for
  80. options given in OPTS.
  81. Return the option character from OPTS just read. Return -1 when
  82. there are no more options. For unrecognized options, or options
  83. missing arguments, `optopt' is set to the option letter, and '?' is
  84. returned.
  85. The OPTS string is a list of characters which are recognized option
  86. letters, optionally followed by colons, specifying that that letter
  87. takes an argument, to be placed in `optarg'.
  88. If a letter in OPTS is followed by two colons, its argument is
  89. optional. This behavior is specific to the GNU `getopt'.
  90. The argument `--' causes premature termination of argument
  91. scanning, explicitly telling `getopt' that there are no more
  92. options.
  93. If OPTS begins with `--', then non-option arguments are treated as
  94. arguments to the option '\0'. This behavior is specific to the GNU
  95. `getopt'. */
  96. /* Many other libraries have conflicting prototypes for getopt, with
  97. differences in the consts, in stdlib.h. To avoid compilation
  98. errors, only prototype getopt for the GNU C library. */
  99. extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
  100. #endif /* HAVE_GETOPT */
  101. #ifndef HAVE_GETOPT_LONG
  102. extern int getopt_long (int ___argc, char *const *___argv, const char *__shortopts,
  103. const struct option *__longopts, int *__longind);
  104. #endif /* HAVE_GETOPT_LONG */
  105. #ifndef HAVE_GETOPT_LONG_ONLY
  106. extern int getopt_long_only (int ___argc, char *const *___argv,
  107. const char *__shortopts,
  108. const struct option *__longopts, int *__longind);
  109. #endif /* HAVE_GETOPT_LONG */
  110. #if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_LONG) || !defined(HAVE_GETOPT_LONG_ONLY)
  111. extern int _getopt_internal (int ___argc, char *const *argv,
  112. const char *optstring,
  113. const struct option *longopts,
  114. int *longind, int long_only);
  115. #endif
  116. #ifdef __cplusplus
  117. }
  118. #endif