args.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __MYARGP__
  2. #define __MYARGP__
  3. #include <argp.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6. #include <hoedown/buffer.h>
  7. /* This structure is used by main to communicate with parse_opt. */
  8. struct arguments {
  9. char *infile;
  10. char *langs;
  11. bool complement;
  12. };
  13. /*
  14. OPTIONS. Field 1 in ARGP.
  15. Order of fields: {NAME, KEY, ARG, FLAGS, DOC}.
  16. */
  17. static struct argp_option options[] = {
  18. {"language", 'L', "LANGUAGES", 0,
  19. "Provide a comma-separated list of languages. Use 'generic' for unspecified. Defaults to 'all'."},
  20. {"complement", 'c', 0, 0,
  21. "Only print out languages NOT selected by --language."},
  22. {0}
  23. };
  24. /*
  25. PARSER. Field 2 in ARGP.
  26. Order of parameters: KEY, ARG, STATE.
  27. */
  28. static error_t parse_opt (int key, char *arg, struct argp_state *state) {
  29. struct arguments *arguments = state->input;
  30. switch (key) {
  31. case 'c':
  32. arguments->complement = true;
  33. break;
  34. case 'L':
  35. arguments->langs = arg;
  36. break;
  37. case ARGP_KEY_ARG:
  38. if(state->arg_num > 0) {
  39. argp_usage(state);
  40. }
  41. arguments->infile = arg;
  42. break;
  43. default:
  44. return ARGP_ERR_UNKNOWN;
  45. }
  46. return 0;
  47. }
  48. /*
  49. ARGS_DOC. Field 3 in ARGP.
  50. A description of the non-option command-line arguments
  51. that we accept.
  52. */
  53. static char args_doc[] = "[FILE]";
  54. /*
  55. DOC. Field 4 in ARGP.
  56. Program documentation.
  57. */
  58. static char doc[] = "warp -- tangle fenced code from markdown.\n\n\
  59. If FILE is unspecified, read from stdin.";
  60. /*
  61. The ARGP structure itself.
  62. */
  63. static struct argp argp = {options, parse_opt, args_doc, doc};
  64. #endif