home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
001-099
/
ff055.lzh
/
Csh
/
run.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-03-01
|
2KB
|
102 lines
/*
* RUN.C
*
* (c)1986 Matthew Dillon 9 October 1986
*
* RUN handles running of external commands.
*
* version 2.05M (Manx Version and Additions) by Steve Drew 20-Jan-87
*
*/
#include "shell.h"
char *FindIt();
do_run(str)
char *str;
{
int i, try = -1;
int run = 0;
char buf[128];
char runcmd[128];
char *save, *path;
if (path = FindIt(av[0],"",buf)) {
if (!strcmp(av[0],"run")) {
if (FindIt(av[1],"",runcmd)) {
run = 1;
save = av[1];
av[1] = runcmd;
}
}
if ((try = fexecv(path, av)) == 0)
i = wait();
if (run) av[1] = save;
}
if (try) {
long lock;
char *copy;
if ((path = FindIt(av[0],".sh",buf)) == NULL) {
fprintf(stderr,"Command Not Found %s\n",av[0]);
return (-1);
}
av[1] = buf; /* particular to do_source() */
copy = malloc(strlen(str)+3);
strcpy(copy+2,str);
copy[0] = 'x';
copy[1] = ' ';
i = do_source(copy);
free(copy);
}
return (i);
}
char *
FindIt(cmd, ext, buf)
char *cmd;
char *ext;
char *buf;
{
long lock = 0;
char hasprefix = 0;
APTR original;
char *ptr, *s = NULL;
original = Myprocess->pr_WindowPtr;
for (ptr = cmd; *ptr; ++ptr) {
if (*ptr == '/' || *ptr == ':')
hasprefix = 1;
}
if (!hasprefix) {
Myprocess->pr_WindowPtr = (APTR)(-1);
s = get_var(LEVEL_SET, V_PATH);
}
strcpy(buf, cmd);
strcat(buf, ext);
while ((lock = (long)Lock(buf, ACCESS_READ)) == 0) {
if (*s == NULL || hasprefix) break;
for(ptr = s; *s && *s != ','; s++) ;
strcpy(buf, ptr);
buf[s-ptr] = '\0';
strcat(buf, cmd);
strcat(buf, ext);
if (*s) s++;
}
Myprocess->pr_WindowPtr = original;
if (lock) {
UnLock(lock);
return(buf);
}
return(NULL);
}