GEMDOS Device I/O and Process Control
mainQ
{
int status;
int len, done=0;
int index^l;
/ * Get command line * /
Cconws("Enter command line [include filename extension]\n\r");
buffer[0]=80; / * prepare buffer for command string entry * /
buffer[82]=0;
Cconws("> "); /* prompt */
len = Cconrs(buffer); /* get command string */
Cconws("\n\n\r"); / * skip a couple of lines * /
/* Split it into command file and command tail */
while (Sdone) /* check for 1st space character */
{
if (buffer[++index]==' ') /* if it's there, end * /
done = 2;
if (index == (len+1 )) /* if you're at end of string, end */
(
done=l;
index++; /* move index past last character */
)
)
buffer[index]=0; /* replace separator with ASCII zero */
strcpy(file,buffer+2); /* put filename in buffer */
if (done==l) /* if there wasn't a command tail */
command=OL; / * set command address to zero */
else / * if there was, put tail length — */
buffer[index] = len-strlen(buffer+2 ); / * at beginning of string */
command=buffer+index; /* and set pointer */
)
status = Pexec(0, file, command, OL); /* execute the program */
printf ("Command status = %lx\n",status);
} / * end of main * /
/******** end of GPEXEC.C * * * * * /
Again, note that the startup segment (GEMSTART.O on
the Alcyon compiler, or its equivalent on other compilers)
must return enough memory with Mshrink() to make room
for the program to be loaded.
The functions used to terminate a process are mostly of
interest to machine language programmers, since the startup
modules supplied with C language compilers automatically
call one of these functions when the C program terminates.
The first and simplest of the functions used to terminate a
process is called PtermO(). Its calling syntax is
PtermO( );
This terminates the current process, closes all open files, reî™…
leases any allocated memory, and exits with a return code of
103