home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / zc.lzh / ZC / ZCSRC.LZH / system / fexec.c next >
Encoding:
C/C++ Source or Header  |  1989-06-11  |  1017 b   |  63 lines

  1. #include    <exec/types.h>
  2. #include    <exec/tasks.h>
  3. #include    <libraries/dosextens.h>
  4.  
  5. typedef struct CommandLineInterface CLI;
  6. typedef struct Process PROC;
  7. typedef struct FileHandle HANDLE;
  8.  
  9. long
  10. fexecv(cmd, argv)
  11. char *cmd, *argv[];
  12. {
  13.     register CLI *cli;
  14.     PROC *pp;
  15.     PROC *FindTask();
  16.     HANDLE *fhp;
  17.     long sav, ret_val;
  18.     union {
  19.         long *lp;
  20.         long ll;
  21.     } path;
  22.     long LoadSeg(), CurrentDir();
  23.     char buf[128];
  24.  
  25.     /*
  26.      * Make sure I'm running from the CLI.
  27.      */
  28.  
  29.     pp = FindTask(0L);
  30.     if ((cli = (CLI *)((long)pp->pr_CLI << 2)) == NULL) {
  31.         return(-1);
  32.     }
  33.  
  34.     /*
  35.      * Search currentdir and "Path" for the cmd.
  36.      */
  37.  
  38.     if (seg = LoadSeg(cmd))
  39.         goto found;
  40.  
  41.     path.lp = (long *) cli->cli_CommandDir;
  42.     while (path.ll) {
  43.         path.ll <<= 2;
  44.         sav = CurrentDir(path.lp[1]);
  45.         seg = LoadSeg(cmd);
  46.         CurrentDir(sav);
  47.         if (seg)
  48.             goto found;
  49.         path.ll = *path.lp;
  50.     }
  51.  
  52.     strcpy(buf, "c:");
  53.     strcat(buf, cmd);
  54.     if (seg = LoadSeg(buf))
  55.         goto found;
  56.     return(-1);
  57.  
  58. found:
  59.     ret_val = System0(cmd, seg, argv);
  60.     UnLoadSeg(seg);
  61.     return ret_val;
  62. }
  63.