some fixes to accented characters
[tangerine.git] / rom / dos / runcommand.c
bloba7def7cd02710f5415c1365fc7436df57389f2af
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Execute a loaded command synchronously
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include "../exec/etask.h"
10 #include <proto/exec.h>
11 #include <utility/tagitem.h>
12 #include <dos/filesystem.h>
13 #include <proto/dos.h>
14 #include "dos_intern.h"
16 LONG AROS_SLIB_ENTRY(RunProcess,Dos)
18 struct Process * proc,
19 struct StackSwapStruct * sss,
20 CONST_STRPTR argptr,
21 ULONG argsize,
22 LONG_FUNC entry,
23 struct DosLibrary * DOSBase
26 /*****************************************************************************
28 NAME */
29 #include <proto/dos.h>
31 AROS_LH4(LONG, RunCommand,
33 /* SYNOPSIS */
34 AROS_LHA(BPTR, segList, D1),
35 AROS_LHA(ULONG, stacksize, D2),
36 AROS_LHA(CONST_STRPTR, argptr, D3),
37 AROS_LHA(ULONG, argsize, D4),
39 /* LOCATION */
40 struct DosLibrary *, DOSBase, 84, Dos)
42 /* FUNCTION
43 RunCommand() will run the command loaded in the |segList| with the
44 arguments specified with a new stack of |stacksize| bytes. Note
45 that the stacksize may be extended if this is required.
47 The return code of the command run will be returned.
49 AROS ONLY: RunCommand() automatically computes argsize
50 automatically if you pass -1.
52 This call will not return until the command has completed.
54 INPUTS
55 segList - segment of program to run.
56 stacksize - size of the stack to use.
57 argptr - pointer to NULL-terminated arguments.
58 argsize - size of the arguments string.
60 RESULT
61 The return code from the program. See also IoErr().
63 NOTES
64 Programs expect the argument string to end with a newline ('\n')
65 character (ReadArgs() requires it to work properly).
67 EXAMPLE
69 BUGS
71 SEE ALSO
72 SystemTagList()
74 INTERNALS
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 STRPTR oldargs;
81 LONG oldresult;
82 struct aros_startup * oldstartup;
84 /* Get pointer to process structure */
85 struct Process *me=(struct Process *)FindTask(NULL);
87 UBYTE *stack;
88 LONG ret;
89 struct StackSwapStruct sss;
91 if(stacksize < AROS_STACKSIZE)
92 stacksize = AROS_STACKSIZE;
94 stack=(UBYTE *)AllocMem(stacksize,MEMF_ANY);
95 if(stack==NULL)
96 return -1;
98 sss.stk_Lower=stack;
99 sss.stk_Upper=stack+stacksize;
101 oldresult=me->pr_Result2;
102 /* we have to save iet_startup field because it's overwritten in
103 startup code */
104 oldstartup = (struct aros_startup *)GetIntETask(me)->iet_startup;
106 me->pr_Result2=oldresult;
108 oldargs=me->pr_Arguments;
109 me->pr_Arguments=(STRPTR)argptr;
111 ret=AROS_SLIB_ENTRY(RunProcess,Dos)(me,&sss,argptr,argsize,
112 (LONG_FUNC)((BPTR *)BADDR(segList)+1),DOSBase);
113 me->pr_Arguments=oldargs;
115 oldresult=me->pr_Result2;
116 /* restore saved iet_startup */
117 GetIntETask(me)->iet_startup = oldstartup;
119 me->pr_Result2=oldresult;
121 FreeMem(stack,stacksize);
123 return ret;
125 AROS_LIBFUNC_EXIT
127 } /* RunCommand */