argv_wordcount.c 583 B

12345678910111213141516171819202122232425
  1. /*
  2. * argv_wordcount.c
  3. *
  4. */
  5. #include "private.h"
  6. /*--------------------------------------------------------- */
  7. unsigned lub_argv_wordcount(const char *line)
  8. {
  9. const char *word;
  10. unsigned result = 0;
  11. size_t len = 0, offset = 0;
  12. bool_t quoted;
  13. for (word = lub_argv_nextword(line, &len, &offset, &quoted);
  14. *word;
  15. word = lub_argv_nextword(word + len, &len, &offset, &quoted)) {
  16. /* account for the terminating quotation mark */
  17. len += (BOOL_TRUE == quoted) ? 1 : 0;
  18. result++;
  19. }
  20. return result;
  21. }
  22. /*--------------------------------------------------------- */