home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / psh / c / builtin < prev    next >
Encoding:
Text File  |  1995-05-08  |  566 b   |  38 lines

  1. /* vi:tabstop=4:shiftwidth=4:smartindent
  2.  *
  3.  * builtin.c - Parses the command line of a builtin command
  4.  *             into argc, argv, then calls the function.
  5.  *
  6.  */
  7.  
  8. #include <ctype.h>
  9. #include "psh.h"
  10.  
  11. int    do_builtin(char *cmd_line, int (*cmd_fun)(int argc, char **argv))
  12. {
  13.     char    *argv[MAXLEN];
  14.     int        argc = 0;
  15.     char    *p = cmd_line;
  16.  
  17.     argv[argc++] = cmd_line;
  18.  
  19.     while (*p)
  20.     {
  21.         if (isspace(*p))
  22.         {
  23.             *p = '\0';
  24.             while (isspace(*++p));
  25.             if (*p)
  26.             {
  27.                 argv[argc++] = p;
  28.             }
  29.         }
  30.         else
  31.         {
  32.             p++;
  33.         }
  34.     }
  35.     argv[argc] = NULL;
  36.     return cmd_fun(argc, argv);
  37. }
  38.