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 TASM_OPTIONS_H
28#define TASM_OPTIONS_H
29
30/* an option structure
31 * operate on either -sopt, --lopt, -sopt <val> or --lopt=<val>
32 */
33typedef struct opt_option_s
34{
35    /* option */
36    const char *opt;
37
38    /* !=0 if option requires parameter, 0 if not */
39    int takes_param;
40
41    int (*handler) (char *cmd, /*@null@*/ char *param, int extra);
42    int extra;                 /* extra value for handler */
43
44    /* description to use in help_msg() */
45    /*@observer@*/ const char *description;
46
47    /* optional description for the param taken (NULL if not present) */
48    /*  (short - will be printed after option sopt/lopt) */
49    /*@observer@*/ /*@null@*/ const char *param_desc;
50} opt_option;
51
52/* handle everything that is not an option */
53int not_an_option_handler(char *param);
54
55/* parse command line calling handlers when appropriate
56 * argc, argv - pass directly from main(argc,argv)
57 * options - array of options
58 * nopts - options count
59 */
60int parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
61                  void (*print_error) (const char *fmt, ...));
62
63/* display help message msg followed by list of options in options and followed
64 * by tail
65 */
66void help_msg(const char *msg, const char *tail, opt_option *options,
67              size_t nopts);
68
69#endif
70