2
* function system() - slightly modified from sources dLibs 1.2
3
* - a freely distributable C library for Atari ST.
4
* Authors: Dale Schumacher and John Stanley, I believe.
5
* Changes for gcc compiler and gnulib.olb - Michal Jaegermann
19
#define _COOKIE(x) puts(x);putchar('\n')
23
parse_args(char *cmdln, register char **argv)
26
static char delim[] = " \t\r\n";
28
if(NULL != (p = strtok(cmdln, delim))) {
31
} while(NULL != (p = strtok(NULL, delim)));
36
/* this is used by assembler statement to keep a copy of registers */
37
static volatile long savearea[16];
41
system(const char *command)
44
register int (*shell)();
50
char *getenv(const char *);
55
/* get _shell_p value */
56
p = (char *) Super(0L); /* supervisor mode */
57
shell = (int (*)()) *((long *) 0x4F6L);
58
(void) Super(p); /* restore user mode */
60
/* validate _shell_p */
61
if((shell) && /* Shell available. */
62
(((long) shell) < ((long) _base)) && /* Reasonable shell pointer. */
63
(strncmp((char *)shell, "PATH", 4))) /* Not corrupted */
68
/* execute the command */
70
_COOKIE("system: using _shell_p");
71
printf("'shell' got value 0x%08lx\n", (long)shell);
73
/* a bit of paranoia caused by some misbehaving programs */
75
asm("moveml d1-d7/a0-a7,_savearea");
76
ret = (*shell)(command);
77
asm("moveml _savearea,d1-d7/a0-a7");
80
return ((*shell)(command));
84
strcpy(cmdln, command); /* copy the command line for parsing */
86
if((p = getenv("SHELL")) && (*p)) /* SHELL= variable? */
89
parse_args(cmdln, (args + 1));
91
_COOKIE("system: executing SHELL");
95
else /* attempt to find first token as a program on the path */
97
parse_args(cmdln, args);
100
_COOKIE("system: directly executing program");
106
return(spawnvp(0, p, args));
107
#else /* original from dLibs */
108
forkvpe(p, args, NULL);
110
return((rv[1] == 0) ? rv[0] : rv[1]);