argv_wordcount.c 626 B

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