tasm-options.h 2.6 KB

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