added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / runcommand.c
blob64a8531eb2102cad7524657ce144b7b06b9ee997
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Execute a loaded command synchonously
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <utility/tagitem.h>
11 #include <dos/filesystem.h>
12 #include <proto/dos.h>
13 #include "dos_intern.h"
15 LONG AROS_SLIB_ENTRY(RunProcess,Dos)
17 struct Process * proc,
18 struct StackSwapStruct * sss,
19 STRPTR argptr,
20 ULONG argsize,
21 LONG_FUNC entry,
22 struct DosLibrary * DOSBase
25 /*****************************************************************************
27 NAME */
28 #include <proto/dos.h>
30 AROS_LH4(LONG, RunCommand,
32 /* SYNOPSIS */
33 AROS_LHA(BPTR, segList, D1),
34 AROS_LHA(ULONG, stacksize, D2),
35 AROS_LHA(STRPTR, argptr, D3),
36 AROS_LHA(ULONG, argsize, D4),
38 /* LOCATION */
39 struct DosLibrary *, DOSBase, 84, Dos)
41 /* FUNCTION
42 RunCommand() will run the command loaded in the |segList| with the
43 arguments specified with a new stack of |stacksize| bytes. Note
44 that the stacksize may be extended if this is required.
46 The return code of the command run will be returned.
48 AROS ONLY: RunCommand() automatically computes argsize
49 automatically if you pass -1.
51 This call will not return until the command has completed.
53 INPUTS
54 segList - segment of program to run.
55 stacksize - size of the stack to use.
56 argptr - pointer to NULL-terminated arguments.
57 argsize - size of the arguments string.
59 RESULT
60 The return code from the program. See also IoErr().
62 NOTES
63 Programs expect the arugment string to end with a newline ('\n')
64 character (ReadArgs() requires it to work properly).
66 EXAMPLE
68 BUGS
70 SEE ALSO
71 SystemTagList()
73 INTERNALS
75 *****************************************************************************/
77 AROS_LIBFUNC_INIT
79 STRPTR oldargs;
80 LONG oldresult;
82 /* Get pointer to process structure */
83 struct Process *me=(struct Process *)FindTask(NULL);
85 UBYTE *stack;
86 LONG ret;
87 struct StackSwapStruct sss;
89 if(stacksize < AROS_STACKSIZE)
90 stacksize = AROS_STACKSIZE;
92 stack=(UBYTE *)AllocMem(stacksize,MEMF_ANY);
93 if(stack==NULL)
94 return -1;
96 sss.stk_Lower=stack;
97 sss.stk_Upper=stack+stacksize;
99 oldresult=me->pr_Result2;
101 me->pr_Result2=oldresult;
103 oldargs=me->pr_Arguments;
104 me->pr_Arguments=argptr;
106 ret=AROS_SLIB_ENTRY(RunProcess,Dos)(me,&sss,argptr,argsize,
107 (LONG_FUNC)((BPTR *)BADDR(segList)+1),DOSBase);
108 me->pr_Arguments=oldargs;
110 oldresult=me->pr_Result2;
112 me->pr_Result2=oldresult;
114 FreeMem(stack,stacksize);
116 return ret;
118 AROS_LIBFUNC_EXIT
120 } /* RunCommand */