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