2
0

cmdline_parser.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef CMDLINE_PARSER_H
  2. #define CMDLINE_PARSER_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #if 0
  7. } /* to fake out automatic code indenters */
  8. #endif
  9. #include "int.h"
  10. /*
  11. NOTE NOTE NOTE: cmd_getOptionValueString() and
  12. cmd_getArgument() return malloc'ed memory (and abort the program if
  13. out of memory). You must free it.
  14. */
  15. enum optiontype {
  16. OPTTYPE_FLAG,
  17. OPTTYPE_INT,
  18. OPTTYPE_UINT,
  19. OPTTYPE_STRING,
  20. OPTTYPE_BINUINT,
  21. OPTTYPE_FLOAT
  22. };
  23. struct cmdlineParserCtl;
  24. typedef struct cmdlineParserCtl * cmdlineParser;
  25. void
  26. cmd_processOptions(cmdlineParser const cpP,
  27. int const argc,
  28. const char ** const argv,
  29. const char ** const errorP);
  30. cmdlineParser
  31. cmd_createOptionParser(void);
  32. void
  33. cmd_destroyOptionParser(cmdlineParser const cpP);
  34. void
  35. cmd_defineOption(cmdlineParser const cpP,
  36. const char * const name,
  37. enum optiontype const type);
  38. int
  39. cmd_optionIsPresent(cmdlineParser const cpP,
  40. const char * const name);
  41. int
  42. cmd_getOptionValueInt(cmdlineParser const cpP,
  43. const char * const name);
  44. unsigned int
  45. cmd_getOptionValueUint(cmdlineParser const cpP,
  46. const char * const name);
  47. const char *
  48. cmd_getOptionValueString(cmdlineParser const cpP,
  49. const char * const name);
  50. uint64_t
  51. cmd_getOptionValueBinUint(cmdlineParser const cpP,
  52. const char * const name);
  53. double
  54. cmd_getOptionValueFloat(cmdlineParser const cpP,
  55. const char * const name);
  56. unsigned int
  57. cmd_argumentCount(cmdlineParser const cpP);
  58. const char *
  59. cmd_getArgument(cmdlineParser const cpP,
  60. unsigned int const argNumber);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif