1d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org/*
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Generic Options Support Header File
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (c) 2001  Stanislav Karchebny <berk@madfire.net>
545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without
745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions
845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met:
945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright
1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    notice, this list of conditions and the following disclaimer.
1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright
1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    notice, this list of conditions and the following disclaimer in the
1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *    documentation and/or other materials provided with the distribution.
1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *
1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE.
2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef TASM_OPTIONS_H
2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define TASM_OPTIONS_H
2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* an option structure
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * operate on either -sopt, --lopt, -sopt <val> or --lopt=<val>
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct opt_option_s
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* option */
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *opt;
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* !=0 if option requires parameter, 0 if not */
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int takes_param;
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int (*handler) (char *cmd, /*@null@*/ char *param, int extra);
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int extra;                 /* extra value for handler */
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* description to use in help_msg() */
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@observer@*/ const char *description;
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /* optional description for the param taken (NULL if not present) */
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*  (short - will be printed after option sopt/lopt) */
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@observer@*/ /*@null@*/ const char *param_desc;
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} opt_option;
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* handle everything that is not an option */
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint not_an_option_handler(char *param);
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* parse command line calling handlers when appropriate
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * argc, argv - pass directly from main(argc,argv)
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * options - array of options
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * nopts - options count
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                  void (*print_error) (const char *fmt, ...));
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* display help message msg followed by list of options in options and followed
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * by tail
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid help_msg(const char *msg, const char *tail, opt_option *options,
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org              size_t nopts);
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
70