1 /* 2 * Generic Options Support Header File 3 * 4 * Copyright (c) 2001 Stanislav Karchebny <berk@madfire.net> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #ifndef YASM_OPTIONS_H 28 #define YASM_OPTIONS_H 29 30 /* an option structure 31 * operate on either -sopt, --lopt, -sopt <val> or --lopt=<val> 32 */ 33 typedef struct opt_option_s 34 { 35 /* short option letter if present, 0 otherwise */ 36 char sopt; 37 38 /* long option name if present, NULL otherwise */ 39 /*@null@*/ const char *lopt; 40 41 /* !=0 if option requires parameter, 0 if not */ 42 int takes_param; 43 44 int (*handler) (char *cmd, /*@null@*/ char *param, int extra); 45 int extra; /* extra value for handler */ 46 47 /* description to use in help_msg() */ 48 /*@observer@*/ const char *description; 49 50 /* optional description for the param taken (NULL if not present) */ 51 /* (short - will be printed after option sopt/lopt) */ 52 /*@observer@*/ /*@null@*/ const char *param_desc; 53 } opt_option; 54 55 /* handle everything that is not an option */ 56 int not_an_option_handler(char *param); 57 58 /* handle possibly other special-case options; no parameters allowed */ 59 int other_option_handler(char *option); 60 61 /* parse command line calling handlers when appropriate 62 * argc, argv - pass directly from main(argc,argv) 63 * options - array of options 64 * nopts - options count 65 */ 66 int parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts, 67 void (*print_error) (const char *fmt, ...)); 68 69 /* display help message msg followed by list of options in options and followed 70 * by tail 71 */ 72 void help_msg(const char *msg, const char *tail, opt_option *options, 73 size_t nopts); 74 75 #endif 76