xref: /freebsd/crypto/heimdal/lib/roken/getarg.h (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
1b528cefcSMark Murray /*
2*ae771770SStanislav Sedov  * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
3b528cefcSMark Murray  * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray  * All rights reserved.
5b528cefcSMark Murray  *
6b528cefcSMark Murray  * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray  * modification, are permitted provided that the following conditions
8b528cefcSMark Murray  * are met:
9b528cefcSMark Murray  *
10b528cefcSMark Murray  * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray  *
13b528cefcSMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray  *    notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray  *    documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray  *
17b528cefcSMark Murray  * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray  *    may be used to endorse or promote products derived from this software
19b528cefcSMark Murray  *    without specific prior written permission.
20b528cefcSMark Murray  *
21b528cefcSMark Murray  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray  * SUCH DAMAGE.
32b528cefcSMark Murray  */
33b528cefcSMark Murray 
34*ae771770SStanislav Sedov /* $Id$ */
35b528cefcSMark Murray 
36b528cefcSMark Murray #ifndef __GETARG_H__
37b528cefcSMark Murray #define __GETARG_H__
38b528cefcSMark Murray 
39b528cefcSMark Murray #include <stddef.h>
40b528cefcSMark Murray 
41c19800e8SDoug Rabson #ifndef ROKEN_LIB_FUNCTION
42c19800e8SDoug Rabson #ifdef _WIN32
43*ae771770SStanislav Sedov #define ROKEN_LIB_FUNCTION
44*ae771770SStanislav Sedov #define ROKEN_LIB_CALL     __cdecl
45c19800e8SDoug Rabson #else
46c19800e8SDoug Rabson #define ROKEN_LIB_FUNCTION
47*ae771770SStanislav Sedov #define ROKEN_LIB_CALL
48c19800e8SDoug Rabson #endif
49c19800e8SDoug Rabson #endif
50c19800e8SDoug Rabson 
51b528cefcSMark Murray struct getargs{
52b528cefcSMark Murray     const char *long_name;
53b528cefcSMark Murray     char short_name;
54b528cefcSMark Murray     enum { arg_integer,
55b528cefcSMark Murray 	   arg_string,
56b528cefcSMark Murray 	   arg_flag,
57b528cefcSMark Murray 	   arg_negative_flag,
58b528cefcSMark Murray 	   arg_strings,
59b528cefcSMark Murray 	   arg_double,
60b528cefcSMark Murray 	   arg_collect,
61b528cefcSMark Murray 	   arg_counter
62b528cefcSMark Murray     } type;
63b528cefcSMark Murray     void *value;
64b528cefcSMark Murray     const char *help;
65b528cefcSMark Murray     const char *arg_help;
66b528cefcSMark Murray };
67b528cefcSMark Murray 
68b528cefcSMark Murray enum {
69b528cefcSMark Murray     ARG_ERR_NO_MATCH  = 1,
70b528cefcSMark Murray     ARG_ERR_BAD_ARG,
71b528cefcSMark Murray     ARG_ERR_NO_ARG
72b528cefcSMark Murray };
73b528cefcSMark Murray 
74b528cefcSMark Murray typedef struct getarg_strings {
75b528cefcSMark Murray     int num_strings;
76b528cefcSMark Murray     char **strings;
77b528cefcSMark Murray } getarg_strings;
78b528cefcSMark Murray 
79b528cefcSMark Murray typedef int (*getarg_collect_func)(int short_opt,
80b528cefcSMark Murray 				   int argc,
81b528cefcSMark Murray 				   char **argv,
828373020dSJacques Vidrine 				   int *goptind,
838373020dSJacques Vidrine 				   int *goptarg,
84b528cefcSMark Murray 				   void *data);
85b528cefcSMark Murray 
86b528cefcSMark Murray typedef struct getarg_collect_info {
87b528cefcSMark Murray     getarg_collect_func func;
88b528cefcSMark Murray     void *data;
89b528cefcSMark Murray } getarg_collect_info;
90b528cefcSMark Murray 
91*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
92c19800e8SDoug Rabson getarg(struct getargs *args, size_t num_args,
938373020dSJacques Vidrine        int argc, char **argv, int *goptind);
94b528cefcSMark Murray 
95*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
96c19800e8SDoug Rabson arg_printusage (struct getargs *args,
97b528cefcSMark Murray 		size_t num_args,
98b528cefcSMark Murray 		const char *progname,
99b528cefcSMark Murray 		const char *extra_string);
100b528cefcSMark Murray 
101*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
102*ae771770SStanislav Sedov arg_printusage_i18n (struct getargs *args,
103*ae771770SStanislav Sedov 		     size_t num_args,
104*ae771770SStanislav Sedov 		     const char *usage,
105*ae771770SStanislav Sedov 		     const char *progname,
106*ae771770SStanislav Sedov 		     const char *extra_string,
107*ae771770SStanislav Sedov 		     char *(*i18n)(const char *));
108*ae771770SStanislav Sedov 
109*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
110c19800e8SDoug Rabson free_getarg_strings (getarg_strings *);
111adb0ddaeSAssar Westerlund 
112b528cefcSMark Murray #endif /* __GETARG_H__ */
113