options.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * options.h - option parsing functions
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2008-2014 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef LIBDPKG_OPTIONS_H
  22. #define LIBDPKG_OPTIONS_H
  23. #include <dpkg/macros.h>
  24. #include <dpkg/dpkg-db.h>
  25. DPKG_BEGIN_DECLS
  26. /**
  27. * @defgroup options Option parsing
  28. * @ingroup dpkg-internal
  29. * @{
  30. */
  31. typedef int action_func(const char *const *argv);
  32. struct cmdinfo {
  33. const char *olong;
  34. char oshort;
  35. /*
  36. * 0 = Normal (-o, --option)
  37. * 1 = Standard value (-o=value, --option=value or
  38. * -o value, --option value)
  39. * 2 = Option string continued (--option-value)
  40. */
  41. int takesvalue;
  42. int *iassignto;
  43. const char **sassignto;
  44. void (*call)(const struct cmdinfo*, const char *value);
  45. int arg_int;
  46. void *arg_ptr;
  47. action_func *action;
  48. };
  49. void badusage(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1);
  50. #define MAX_CONFIG_LINE 1024
  51. void dpkg_options_load(const char *prog, const struct cmdinfo *cmdinfos);
  52. void dpkg_options_parse(const char *const **argvp,
  53. const struct cmdinfo *cmdinfos, const char *help_str);
  54. long dpkg_options_parse_arg_int(const struct cmdinfo *cmd, const char *str);
  55. struct pkginfo *
  56. dpkg_options_parse_pkgname(const struct cmdinfo *cmd, const char *name);
  57. /**
  58. * Current cmdinfo action.
  59. */
  60. extern const struct cmdinfo *cipaction;
  61. void setaction(const struct cmdinfo *cip, const char *value);
  62. void setobsolete(const struct cmdinfo *cip, const char *value);
  63. #define ACTION(longopt, shortopt, code, func) \
  64. { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, func }
  65. #define OBSOLETE(longopt, shortopt) \
  66. { longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL }
  67. /** @} */
  68. DPKG_END_DECLS
  69. #endif /* LIBDPKG_OPTIONS_H */