| 1 | /* simpleparse.h - Minimalistic parser |
| 2 | Copyright (C) 2008 g10 Code GmbH |
| 3 | |
| 4 | This file is part of Poldi. |
| 5 | |
| 6 | Poldi is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | Poldi is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | /* This is a minimalistic parser for command-line arguments and |
| 21 | configuration files. Design goals are: |
| 22 | |
| 23 | - small and flexible, |
| 24 | - no global variables, |
| 25 | - uses callbacks. */ |
| 26 | |
| 27 | #ifndef SIMPLEPARSE_H |
| 28 | #define SIMPLEPARSE_Hcxx . . $ `src/util/simpleparse.h:28:9`! |
| 29 | |
| 30 | #include <poldi.h>cxx . . $ `<file>/src/poldi.h`/ |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | #include <stdarg.h> |
| 34 | |
| 35 | #include <util/simplelog.h>cxx . . $ `<file>/src/util/simplelog.h`/ |
| 36 | |
| 37 | enum simpleparse_argcxx . . $ simpleparse_arg# |
| 38 | { |
| 39 | SIMPLEPARSE_ARG_NONEcxx . . $ SIMPLEPARSE_ARG_NONE., |
| 40 | SIMPLEPARSE_ARG_OPTIONALcxx . . $ SIMPLEPARSE_ARG_OPTIONAL., |
| 41 | SIMPLEPARSE_ARG_REQUIREDcxx . . $ SIMPLEPARSE_ARG_REQUIRED. |
| 42 | }; |
| 43 | |
| 44 | typedef structcxx . . $ $anonymous_type_9ecc77981daa53a4_0# |
| 45 | { |
| 46 | int idcxx . . $ $anonymous_type_9ecc77981daa53a4_0#id.; |
| 47 | const char *long_optcxx . . $ $anonymous_type_9ecc77981daa53a4_0#long_opt.; |
| 48 | int short_optcxx . . $ $anonymous_type_9ecc77981daa53a4_0#short_opt.; |
| 49 | enum simpleparse_argcxx . . $ simpleparse_arg# argcxx . . $ $anonymous_type_9ecc77981daa53a4_0#arg.; |
| 50 | unsigned flagscxx . . $ $anonymous_type_9ecc77981daa53a4_0#flags.; |
| 51 | const char *descriptioncxx . . $ $anonymous_type_9ecc77981daa53a4_0#description.; /* optional option description */ |
| 52 | } simpleparse_opt_spec_tcxx . . $ simpleparse_opt_spec_t#; |
| 53 | typedef struct simpleparse_handlecxx . . $ simpleparse_handle# *simpleparse_handle_tcxx . . $ simpleparse_handle_t#; |
| 54 | |
| 55 | gpg_error_tcxx . . $ gpg_error_t# simpleparse_createcxx . . $ simpleparse_create(66008bf8c18601a7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# *handle); |
| 56 | void simpleparse_destroycxx . . $ simpleparse_destroy(f8a3a57ff17a2201). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle); |
| 57 | |
| 58 | void simpleparse_set_loghandlecxx . . $ simpleparse_set_loghandle(160e2747cca04437). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, |
| 59 | log_handle_tcxx . . $ log_handle_t# loghandle); |
| 60 | |
| 61 | typedef gpg_error_tcxx . . $ gpg_error_t# (*simpleparse_parse_cb_tcxx . . $ simpleparse_parse_cb_t#) (void *cookie, |
| 62 | simpleparse_opt_spec_tcxx . . $ simpleparse_opt_spec_t# spec, const char *arg); |
| 63 | |
| 64 | void simpleparse_set_parse_cbcxx . . $ simpleparse_set_parse_cb(3172d0a439858735). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, |
| 65 | simpleparse_parse_cb_tcxx . . $ simpleparse_parse_cb_t# parse_cb, void *cookie); |
| 66 | |
| 67 | typedef const char *(*simpleparse_i18n_cb_tcxx . . $ simpleparse_i18n_cb_t#) (void *cookie, const char *msg); |
| 68 | |
| 69 | void simpleparse_set_i18n_cbcxx . . $ simpleparse_set_i18n_cb(b8188d2bcc1bdd70). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, |
| 70 | simpleparse_i18n_cb_tcxx . . $ simpleparse_i18n_cb_t# i18n_cb, void *cookie); |
| 71 | |
| 72 | gpg_error_tcxx . . $ gpg_error_t# simpleparse_set_specscxx . . $ simpleparse_set_specs(79a7ca40abe9bcfd). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, simpleparse_opt_spec_tcxx . . $ simpleparse_opt_spec_t# *specs); |
| 73 | |
| 74 | void simpleparse_set_namecxx . . $ simpleparse_set_name(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *program_name); |
| 75 | void simpleparse_set_packagecxx . . $ simpleparse_set_package(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *package_name); |
| 76 | void simpleparse_set_copyrightcxx . . $ simpleparse_set_copyright(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *copyright_info); |
| 77 | void simpleparse_set_versioncxx . . $ simpleparse_set_version(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *program_version); |
| 78 | void simpleparse_set_bugaddresscxx . . $ simpleparse_set_bugaddress(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *bugaddress); |
| 79 | void simpleparse_set_authorcxx . . $ simpleparse_set_author(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *author); |
| 80 | void simpleparse_set_licensecxx . . $ simpleparse_set_license(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *license); |
| 81 | void simpleparse_set_descriptioncxx . . $ simpleparse_set_description(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *program_description); |
| 82 | void simpleparse_set_syntaxcxx . . $ simpleparse_set_syntax(a7aed6e50e87fbe7). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, const char *syntax_description); |
| 83 | void simpleparse_set_streamscxx . . $ simpleparse_set_streams(752ef5cc3e2dfb11). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, FILEcxx . . $ FILE# *stream_stdout, FILEcxx . . $ FILE# *stream_stderr); |
| 84 | |
| 85 | gpg_error_tcxx . . $ gpg_error_t# simpleparse_parsecxx . . $ simpleparse_parse(62ade082e5fc30eb). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, unsigned int flags, |
| 86 | unsigned int argc, const char **argv, const char ***rest_args); |
| 87 | |
| 88 | gpg_error_tcxx . . $ gpg_error_t# simpleparse_parse_filecxx . . $ simpleparse_parse_file(4e37b2a77adfc21a). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, unsigned int flags, |
| 89 | const char *filename); |
| 90 | |
| 91 | gpg_error_tcxx . . $ gpg_error_t# simpleparse_parse_streamcxx . . $ simpleparse_parse_stream(c210c2fed664be1f). (simpleparse_handle_tcxx . . $ simpleparse_handle_t# handle, unsigned int flags, |
| 92 | FILEcxx . . $ FILE# *stream); |
| 93 | |
| 94 | #endif |