New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Execute.c
blob54a75a57409285669f6e2f22dc5ae61a72c0479f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang:
7 */
9 /******************************************************************************
11 NAME
13 Execute <script> [{<arguments>}]
15 SYNOPSIS
17 FILE/A
19 LOCATION
21 Workbench:C
23 FUNCTION
25 Executes a script with DOS commands.
27 INPUTS
29 FILE -- file to execute
31 RESULT
33 NOTES
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
43 HISTORY
45 ******************************************************************************/
47 #include <proto/exec.h>
48 #include <dos/filesystem.h>
49 #include <dos/dos.h>
50 #include <dos/bptr.h>
51 #include <proto/dos.h>
52 #include <proto/alib.h>
53 #include <string.h>
55 #define SH_GLOBAL_SYSBASE 1
57 #include <aros/shcommands.h>
61 AROS_SH1(Execute, 41.1,
62 AROS_SHA(STRPTR, ,NAME,/A,NULL))
64 AROS_SHCOMMAND_INIT
66 BPTR from;
67 struct CommandLineInterface *cli = Cli();
70 if (!cli)
72 return RETURN_ERROR;
75 from = Open(SHArg(NAME), FMF_READ);
77 if (!from)
79 IPTR data[] = { (IPTR)SHArg(NAME) };
80 VFPrintf(Error(), "EXECUTE: can't open %s\n", data);
81 PrintFault(IoErr(), NULL);
83 return RETURN_FAIL;
86 if (!cli->cli_Interactive)
88 struct DateStamp ds;
89 BYTE tmpname[2+3+10+10+2+2+1];
90 BPTR tmpfile;
91 DateStamp(&ds);
93 __sprintf(tmpname, "T:Tmp%lu%lu%lu%lu",
94 ((struct Process *)FindTask(NULL))->pr_TaskNum,
95 ds.ds_Days, ds.ds_Minute, ds.ds_Tick);
97 tmpfile = Open(tmpname, FMF_WRITE|FMF_READ|FMF_CREATE|FMF_CLEAR);
99 if (tmpfile)
101 LONG c;
103 while((c = FGetC(from)) != -1 && FPutC(tmpfile, c) != -1);
105 c = IoErr();
106 Close(from);
108 if (c)
110 FPuts(Error(),
111 "EXECUTE: error while creating temporary file\n");
112 PrintFault(c, NULL);
113 Close(tmpfile);
114 DeleteFile(tmpname);
116 return RETURN_FAIL;
119 c = '\n';
120 FPutC(tmpfile, c);
122 while((c = FGetC(cli->cli_CurrentInput)) != -1 && FPutC(tmpfile, c) != -1);
124 c = IoErr();
126 if (c)
128 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
129 PrintFault(c, NULL);
130 Close(tmpfile);
131 DeleteFile(tmpname);
133 return RETURN_FAIL;
137 Close(cli->cli_CurrentInput);
138 if (AROS_BSTR_strlen(cli->cli_CommandFile))
139 DeleteFile(BADDR(cli->cli_CommandFile));
142 LONG len = strlen(tmpname);
143 CopyMem(tmpname, BADDR(cli->cli_CommandFile), len);
144 AROS_BSTR_setstrlen(cli->cli_CommandFile, len);
147 cli->cli_CurrentInput = tmpfile;
149 Seek(tmpfile, 0, OFFSET_BEGINNING);
151 else
154 we should try to open ":T", but since ":"
155 is not handled correctly yet, we just give up
157 LONG c = IoErr();
158 FPuts(Error(), "EXECUTE: error while creating temporary file\n");
159 PrintFault(c, NULL);
160 Close(from);
162 return RETURN_FAIL;
165 else
167 cli->cli_Interactive = FALSE;
168 cli->cli_CurrentInput = from;
171 return RETURN_OK;
173 AROS_SHCOMMAND_EXIT