argv.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * \pre
  33. * - none
  34. *
  35. * \return
  36. * The number of space separated words in the specified string.
  37. *
  38. * \post
  39. * - none
  40. */
  41. unsigned lub_argv_wordcount(
  42. /**
  43. * The string to analyse
  44. */
  45. const char *line);
  46. /**
  47. * This operation is used to construct an instance of this class. The client
  48. * species a string and an offset within that string, from which to start
  49. * collecting "words" to place into the vector instance.
  50. *
  51. * \pre
  52. * - none
  53. *
  54. * \return
  55. * - A instance of an argument vector, which represents the words contained in
  56. * the provided string.
  57. * - NULL if there is insuffcient resource
  58. *
  59. * \post
  60. * - The client becomes resposible for releasing the instance when they are
  61. * finished with it, by calling lub_argv_delete()
  62. */
  63. lub_argv_t *lub_argv_new(
  64. /**
  65. * The string to analyse
  66. */
  67. const char *line,
  68. /**
  69. * The offset in the string to start from
  70. */
  71. size_t offset);
  72. void lub_argv_delete(lub_argv_t * instance);
  73. unsigned lub_argv__get_count(const lub_argv_t * instance);
  74. const char *lub_argv__get_arg(const lub_argv_t * instance, unsigned index);
  75. size_t lub_argv__get_offset(const lub_argv_t * instance, unsigned index);
  76. bool_t lub_argv__get_quoted(const lub_argv_t * instance, unsigned index);
  77. void lub_argv__set_arg(lub_argv_t * instance, unsigned index, const char *arg);
  78. char **lub_argv__get_argv(const lub_argv_t * instance, char *argv0);
  79. const char *lub_argv__get_line(const lub_argv_t * instance);
  80. _END_C_DECL
  81. #endif /* _lub_argv_h */
  82. /** @} lub_argv */