bsd-getopt_long.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* $OpenBSD: getopt_long.c,v 1.13 2003/06/03 01:52:40 millert Exp $ */
  2. /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
  3. /*
  4. * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
  12. * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
  13. * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  15. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  16. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*-
  19. * Copyright (c) 2000 The NetBSD Foundation, Inc.
  20. * All rights reserved.
  21. *
  22. * This code is derived from software contributed to The NetBSD Foundation
  23. * by Dieter Baron and Thomas Klausner.
  24. *
  25. * Redistribution and use in source and binary forms, with or without
  26. * modification, are permitted provided that the following conditions
  27. * are met:
  28. * 1. Redistributions of source code must retain the above copyright
  29. * notice, this list of conditions and the following disclaimer.
  30. * 2. Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in the
  32. * documentation and/or other materials provided with the distribution.
  33. * 3. All advertising materials mentioning features or use of this software
  34. * must display the following acknowledgement:
  35. * This product includes software developed by the NetBSD
  36. * Foundation, Inc. and its contributors.
  37. * 4. Neither the name of The NetBSD Foundation nor the names of its
  38. * contributors may be used to endorse or promote products derived
  39. * from this software without specific prior written permission.
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  42. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  43. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  45. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  46. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  49. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  50. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  51. * POSSIBILITY OF SUCH DAMAGE.
  52. */
  53. #ifndef __BSD_GETOPT_LONG_H__
  54. #define __BSD_GETOPT_LONG_H__ 1
  55. #ifndef HAVE_GETOPT_LONG
  56. /*
  57. * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions
  58. */
  59. # ifndef no_argument
  60. # define no_argument 0
  61. # endif
  62. # ifndef required_argument
  63. # define required_argument 1
  64. # endif
  65. # ifndef optional_argument
  66. # define optional_argument 2
  67. # endif
  68. struct pure_option {
  69. /* name of long option */
  70. const char *name;
  71. /*
  72. * one of no_argument, required_argument, and optional_argument:
  73. * whether option takes an argument
  74. */
  75. int has_arg;
  76. /* if not NULL, set *flag to val when option found */
  77. int *flag;
  78. /* if flag not NULL, value to set *flag to; else return value */
  79. int val;
  80. };
  81. int pure_getopt_long(int nargc, char * const *nargv, const char *options,
  82. const struct pure_option *long_options, int *idx);
  83. int pure_getopt_long_only(int nargc, char * const *nargv,
  84. const char *options,
  85. const struct pure_option *long_options,
  86. int *idx);
  87. int pure_getopt(int nargc, char * const *nargv, const char *options);
  88. extern const char *pure_optarg; /* getopt(3) external variables */
  89. extern int pure_opterr;
  90. extern int pure_optind;
  91. extern int pure_optopt;
  92. extern int pure_optreset;
  93. /* prefix+macros just to avoid clashes with existing getopt() implementations */
  94. # ifndef IN_GETOPT_LONG_C
  95. # undef option
  96. # define option pure_option
  97. # undef getopt_long
  98. # define getopt_long(A, B, C, D, E) pure_getopt_long(A, B, C, D, E)
  99. # undef getopt_long_only
  100. # define getopt_long_only(A, B, C, D, E) pure_getopt_long_only(A, B, C, D, E)
  101. # undef getopt
  102. # define getopt(A, B, C) pure_getopt(A, B, C)
  103. # undef optarg
  104. # define optarg pure_optarg
  105. # undef opterr
  106. # define opterr pure_opterr
  107. # undef optind
  108. # define optind pure_optind
  109. # undef optopt
  110. # define optopt pure_optopt
  111. # undef optreset
  112. # define optreset pure_optreset
  113. # endif
  114. #endif
  115. #endif