args.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. bool minted;
  11. };
  12. /*
  13. OPTIONS. Field 1 in ARGP.
  14. Order of fields: {NAME, KEY, ARG, FLAGS, DOC}.
  15. */
  16. static struct argp_option options[] = {
  17. {"use-minted", 'm', 0, 0,
  18. "Highlight syntax using minted. Use at your own risk."},
  19. {0}
  20. };
  21. /*
  22. PARSER. Field 2 in ARGP.
  23. Order of parameters: KEY, ARG, STATE.
  24. */
  25. static error_t parse_opt (int key, char *arg, struct argp_state *state) {
  26. struct arguments *arguments = state->input;
  27. switch (key) {
  28. case 'm':
  29. arguments->minted = true;
  30. break;
  31. case ARGP_KEY_ARG:
  32. if(state->arg_num > 0) {
  33. argp_usage(state);
  34. }
  35. arguments->infile = arg;
  36. break;
  37. default:
  38. return ARGP_ERR_UNKNOWN;
  39. }
  40. return 0;
  41. }
  42. /*
  43. ARGS_DOC. Field 3 in ARGP.
  44. A description of the non-option command-line arguments
  45. that we accept.
  46. */
  47. static char args_doc[] = "[FILE]";
  48. /*
  49. DOC. Field 4 in ARGP.
  50. Program documentation.
  51. */
  52. static char doc[] = "mdtex -- Convert markdown to LaTeX.\n\n\
  53. If FILE is unspecified, read from stdin.";
  54. /*
  55. The ARGP structure itself.
  56. */
  57. static struct argp argp = {options, parse_opt, args_doc, doc};
  58. #endif