home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / startup / parseargs.c < prev    next >
Encoding:
Text File  |  1996-04-15  |  864 b   |  47 lines

  1. /* GCC Library
  2.  * Jörg Höhle, 21-Nov-92
  3.  * from parseargs (c) Matthew Dillon
  4.  */
  5.  
  6. /*
  7.  * Returns argc for arguments.  Does NOT include arg0
  8.  */
  9. int
  10. _tokenize(volatile char* copy, int len)
  11. {
  12.   int ac = 0;
  13.   for (;;) {
  14.     while (*copy == ' ' || *copy == '\t') ++copy;
  15.     if (*copy == 0 || *copy == '\n') break;
  16.     ++ac;
  17.     if (*copy == '\"') {
  18.       do {
  19.     ++copy;
  20.       } while (*copy && *copy != '\n' && *copy != '\"') ;
  21.     } else {
  22.       while (*copy && *copy != '\n' && *copy != ' ' && *copy != '\t')
  23.     ++copy;
  24.     }
  25.     if (*copy == 0) break;
  26.     *copy++ = 0;
  27.   }
  28.   return(ac);
  29. }
  30.  
  31. /*
  32.  * Dumps 'ac' arguments into av beginning at index 0.
  33.  */
  34. void
  35. _dumpargs(char* copy, char** av, int ac)
  36. {
  37.   while (ac) {
  38.     while (*copy == ' ' || *copy == '\t') ++copy;
  39.     if (*copy == '\"') ++copy;
  40.     *av++ = copy;
  41.     while (*copy) ++copy;
  42.     ++copy;
  43.     --ac;
  44.   }
  45. }
  46.  
  47.