strparse.c 506 B

1234567891011121314151617181920212223242526272829303132
  1. #include <u.h>
  2. #include <libc.h>
  3. int strcomment = '#';
  4. int
  5. strparse(char *p, int arsize, char **arv)
  6. {
  7. int arc = 0;
  8. /*print("parse: 0x%lux = \"%s\"\n", p, p);/**/
  9. while(p){
  10. while(*p == ' ' || *p == '\t')
  11. p++;
  12. if(*p == 0 || *p == strcomment)
  13. break;
  14. if(arc >= arsize-1)
  15. break;
  16. arv[arc++] = p;
  17. while(*p && *p != ' ' && *p != '\t')
  18. p++;
  19. if(*p == 0)
  20. break;
  21. *p++ = 0;
  22. }
  23. arv[arc] = 0;
  24. /*while(*arv){
  25. print("\t0x%lux = \"%s\"\n", *arv, *arv);
  26. ++arv;
  27. }/**/
  28. return arc;
  29. }