1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #ifndef __MYARGP__
- #define __MYARGP__
- #include <argp.h>
- #include <string.h>
- #include <stdbool.h>
- #include <hoedown/buffer.h>
- /* This structure is used by main to communicate with parse_opt. */
- struct arguments {
- char *infile;
- char *langs;
- bool complement;
- };
- /*
- OPTIONS. Field 1 in ARGP.
- Order of fields: {NAME, KEY, ARG, FLAGS, DOC}.
- */
- static struct argp_option options[] = {
- {"language", 'L', "LANGUAGES", 0,
- "Provide a comma-separated list of languages. Use 'generic' for unspecified. Defaults to 'all'."},
- {"complement", 'c', 0, 0,
- "Only print out languages NOT selected by --language."},
- {0}
- };
- /*
- PARSER. Field 2 in ARGP.
- Order of parameters: KEY, ARG, STATE.
- */
- static error_t parse_opt (int key, char *arg, struct argp_state *state) {
- struct arguments *arguments = state->input;
- switch (key) {
- case 'c':
- arguments->complement = true;
- break;
- case 'L':
- arguments->langs = arg;
- break;
- case ARGP_KEY_ARG:
- if(state->arg_num > 0) {
- argp_usage(state);
- }
- arguments->infile = arg;
- break;
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
- }
- /*
- ARGS_DOC. Field 3 in ARGP.
- A description of the non-option command-line arguments
- that we accept.
- */
- static char args_doc[] = "[FILE]";
- /*
- DOC. Field 4 in ARGP.
- Program documentation.
- */
- static char doc[] = "warp -- tangle fenced code from markdown.\n\n\
- If FILE is unspecified, read from stdin.";
- /*
- The ARGP structure itself.
- */
- static struct argp argp = {options, parse_opt, args_doc, doc};
- #endif
|