home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
util
/
misc
/
multiuser
/
src
/
support
/
runcommand.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-03
|
2KB
|
83 lines
/************************************************************
* MultiUser - MultiUser Task/File Support System *
* --------------------------------------------------------- *
* RunCommand - Run a Pogram using the Current Process *
* --------------------------------------------------------- *
* © Copyright 1993-1994 Geert Uytterhoeven *
* All Rights Reserved. *
************************************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <dos/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include "string.h"
#include "RunCommand_rev.h"
#include "Locale.h"
char __VersTag__[] = VERSTAG;
int __saveds Start(char *arg)
{
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct RDArgs *args;
LONG argarray[] = {
#define argCOMMAND 0
#define argARGS 1
NULL, NULL
};
int rc = RETURN_ERROR;
BPTR seglist;
ULONG stacksize;
STRPTR argptr;
ULONG argsize;
struct Process *proc;
struct CommandLineInterface *cli;
SysBase = *(struct ExecBase **)4;
if (!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) {
rc = ERROR_INVALID_RESIDENT_LIBRARY;
goto Exit;
}
args = ReadArgs("COMMAND/A,ARGS/F", argarray, NULL);
if (!args || (!(seglist = NewLoadSeg((STRPTR)argarray[argCOMMAND], NULL))))
PrintFault(IoErr(), NULL);
else {
proc = (struct Process *)SysBase->ThisTask;
if (cli = (struct CommandLineInterface *)BADDR(proc->pr_CLI)) {
stacksize = cli->cli_DefaultStack*4;
if (argarray[argARGS]) {
argsize = strlen((char *)argarray[argARGS])+1;
if (argptr = AllocVec(argsize+1, MEMF_PUBLIC|MEMF_CLEAR)) {
strcpy(argptr, (char *)argarray[argARGS]);
strcat(argptr, "\n");
rc = RunCommand(seglist, stacksize, argptr, argsize);
FreeVec(argptr);
} else
PrintFault(IoErr(), NULL);
} else
rc = RunCommand(seglist, stacksize, "\n", 1);
if (rc == -1) {
rc = RETURN_FAIL;
PutStr(GetLocStr(MSG_NOMEMSTACK));
}
UnLoadSeg(seglist);
} else
PutStr(GetLocStr(MSG_ONLYFROMCLI));
}
Exit:
CloseLibrary((struct Library *)DOSBase);
return(rc);
}