Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commander.h 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // commander.h
  3. //
  4. // Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
  5. //
  6. #ifndef COMMANDER_H
  7. #define COMMANDER_H
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /*
  12. * Max options that can be defined.
  13. */
  14. #ifndef COMMANDER_MAX_OPTIONS
  15. #define COMMANDER_MAX_OPTIONS 32
  16. #endif
  17. /*
  18. * Max arguments that can be passed.
  19. */
  20. #ifndef COMMANDER_MAX_ARGS
  21. #define COMMANDER_MAX_ARGS 32
  22. #endif
  23. /*
  24. * Command struct.
  25. */
  26. struct command;
  27. /*
  28. * Option callback.
  29. */
  30. typedef void (* command_callback_t)(struct command *self);
  31. /*
  32. * Command option.
  33. */
  34. typedef struct {
  35. int optional_arg;
  36. int required_arg;
  37. char *argname;
  38. char *large;
  39. const char *small;
  40. const char *large_with_arg;
  41. const char *description;
  42. command_callback_t cb;
  43. } command_option_t;
  44. /*
  45. * Command.
  46. */
  47. typedef struct command {
  48. void *data;
  49. const char *usage;
  50. const char *arg;
  51. const char *name;
  52. const char *version;
  53. int option_count;
  54. command_option_t options[COMMANDER_MAX_OPTIONS];
  55. int argc;
  56. char *argv[COMMANDER_MAX_ARGS];
  57. char **nargv;
  58. } command_t;
  59. // prototypes
  60. void
  61. command_init(command_t *self, const char *name, const char *version);
  62. void
  63. command_free(command_t *self);
  64. void
  65. command_help(command_t *self);
  66. void
  67. command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
  68. void
  69. command_parse(command_t *self, int argc, char **argv);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif /* COMMANDER_H */