1
0

argv.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * argv.h
  3. */
  4. /**
  5. \ingroup lub
  6. \defgroup lub_argv argv
  7. @{
  8. \brief This utility provides a simple means of manipulating a vector of
  9. command textual words.
  10. A word is either separated by whitespace, or if quotes are used a word is
  11. defined by the scope of the quotes.
  12. e.g.
  13. \verbatim
  14. one two "this is the third word" four
  15. \endverbatim
  16. contains four "words" the third of which is a string.
  17. */
  18. #ifndef _lub_argv_h
  19. #define _lub_argv_h
  20. #include <stddef.h>
  21. #include "c_decl.h"
  22. #include "types.h"
  23. _BEGIN_C_DECL
  24. /**
  25. * This type is used to reference an instance of an argument vector
  26. */
  27. typedef struct lub_argv_s lub_argv_t;
  28. /*=====================================
  29. * ARGV INTERFACE
  30. *===================================== */
  31. /**
  32. * This operation is used to construct an instance of this class. The client
  33. * species a string and an offset within that string, from which to start
  34. * collecting "words" to place into the vector instance.
  35. *
  36. * \pre
  37. * - none
  38. *
  39. * \return
  40. * - A instance of an argument vector, which represents the words contained in
  41. * the provided string.
  42. * - NULL if there is insuffcient resource
  43. *
  44. * \post
  45. * - The client becomes resposible for releasing the instance when they are
  46. * finished with it, by calling lub_argv_delete()
  47. */
  48. lub_argv_t *lub_argv_new(
  49. /**
  50. * The string to analyse
  51. */
  52. const char *line,
  53. /**
  54. * The offset in the string to start from
  55. */
  56. size_t offset);
  57. void lub_argv_delete(lub_argv_t * instance);
  58. unsigned lub_argv__get_count(const lub_argv_t * instance);
  59. const char *lub_argv__get_arg(const lub_argv_t * instance, unsigned index);
  60. size_t lub_argv__get_offset(const lub_argv_t * instance, unsigned index);
  61. bool_t lub_argv__get_quoted(const lub_argv_t * instance, unsigned index);
  62. void lub_argv__set_arg(lub_argv_t * instance, unsigned index, const char *arg);
  63. char **lub_argv__get_argv(const lub_argv_t * instance, const char *argv0);
  64. void lub_argv__free_argv(char **argv);
  65. char *lub_argv__get_line(const lub_argv_t * instance);
  66. void lub_argv_add(lub_argv_t * instance, const char *text);
  67. _END_C_DECL
  68. #endif /* _lub_argv_h */
  69. /** @} lub_argv */