1
0

argv.h 2.5 KB

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