Don't call InvertPixelArray with negative width and/or height.
[tangerine.git] / workbench / c / IconX.c
blobb264bd0658a529ac1aa4759b8a301b527d81ddf0
1 /*
2 Copyright © 2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: IconX WB script starter
6 Lang: English
7 */
9 /******************************************************************************
12 NAME
14 IconX
16 SYNOPSIS
19 LOCATION
21 Workbench:C
23 FUNCTION
25 Starts DOS scripts from Workbench. In order to use it you need an icon for
26 your script. Set 'IconX' as default tool.
28 INPUTS
30 Tooltypes for script icon:
31 WINDOW -- Specification of the shell window
32 default: con:0/50//80/IconX/Auto
33 STACK=n -- default: 40960
34 USERSHELL=YES|NO -- default: YES
35 WAIT=n -- Wait n seconds before closing window (default 2)
36 DELAY=n -- Wait n/50 seconds before closing window
38 RESULT
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 HISTORY
52 ******************************************************************************/
54 #define DEBUG 1
56 #include <aros/debug.h>
57 #include <proto/exec.h>
58 #include <proto/dos.h>
59 #include <proto/intuition.h>
60 #include <proto/icon.h>
61 #include <string.h>
62 #include <stdlib.h>
64 /* some default values */
65 #define DEFWINDOW "con:0/50//80/IconX/Auto"
66 #define DEFSTACK (40960)
67 #define DEFWAIT (2 * 50) // two seconds
68 #define DEFUSHELL (TRUE)
70 static const char version[] = "\0$VER: IconX 1.0 (1.11.2006) © by The AROS Development Team";
71 int __forceerrorrequester = 1;
72 static TEXT errbuffer[255];
75 void displayMsg(LONG code)
77 if (code)
79 Fault(code, "IconX", errbuffer, sizeof(errbuffer));
80 struct EasyStruct es = {sizeof(struct EasyStruct), 0,
81 "Error", errbuffer, "OK"};
82 EasyRequest(0, &es, 0);
87 int main(int argc, char **argv)
89 LONG rc = RETURN_FAIL;
90 STRPTR filename;
91 STRPTR path = NULL;
92 LONG pathlen;
93 BPTR oldlock = (BPTR)-1;
94 BPTR dirlock = (BPTR)-1;
95 STRPTR pathPartEnd;
96 struct DiskObject *dobj = NULL;
98 STRPTR ixWindow = DEFWINDOW;
99 LONG ixWait = 0;
100 LONG ixStack = DEFSTACK;
101 BOOL ixUShell = DEFUSHELL;
103 BPTR from = NULL;
104 BPTR window = NULL;
106 D(bug("IconX argc %d\n", argc));
108 if (argc != 2)
110 displayMsg(ERROR_REQUIRED_ARG_MISSING);
111 goto exit;
114 D(bug("IconX argv[1] %s\n", argv[1]));
116 /* get path part and cd into it */
117 pathPartEnd = PathPart(argv[1]);
118 pathlen = pathPartEnd - (STRPTR)argv[1];
119 path = AllocVec( pathlen + 1, MEMF_ANY|MEMF_CLEAR);
120 if (path == NULL)
122 displayMsg(ERROR_NO_FREE_STORE);
123 goto exit;
126 strncpy(path, argv[1], pathlen);
127 dirlock = Lock(path, SHARED_LOCK);
128 if (dirlock == NULL)
130 displayMsg(ERROR_INVALID_LOCK);
131 goto exit;
134 oldlock = CurrentDir(dirlock);
136 filename = FilePart(argv[1]);
138 D(bug("Path %s File %s\n", path, filename));
140 /* queary diskobject for tooltypes */
141 dobj = GetDiskObject(filename);
142 if (dobj == NULL)
144 struct EasyStruct es = {sizeof(struct EasyStruct), 0,
145 "Error", "IconX\nGetDiskObject failed for:\n%s", "OK"};
146 EasyRequest(0, &es, 0, filename);
147 goto exit;
150 if (dobj->do_Type == WBPROJECT)
152 const STRPTR *toolarray = (const STRPTR *)dobj->do_ToolTypes;
153 STRPTR s;
154 if ((s = FindToolType(toolarray, "WINDOW")))
156 ixWindow = s;
158 if ((s = FindToolType(toolarray, "STACK")))
160 ixStack = atol(s);
162 if ((s = FindToolType(toolarray, "USERSHELL")))
164 if (MatchToolValue(s, "NO"))
166 ixUShell = FALSE;
169 if ((s = FindToolType(toolarray, "WAIT")))
171 ixWait += atol(s) * 50;
173 if ((s = FindToolType(toolarray, "DELAY")))
175 ixWait += atol(s);
178 else
180 displayMsg(ERROR_OBJECT_WRONG_TYPE);
181 goto exit;
184 if (ixWait <= 0)
185 ixWait = DEFWAIT;
187 if (ixStack <= 4096)
188 ixStack = DEFSTACK;
190 D(bug("wait %d stack %d usershell %d window %s\n", ixWait, ixStack, ixUShell, ixWindow));
192 from = Open(filename, MODE_OLDFILE);
193 if (from == NULL)
195 displayMsg(IoErr());
196 goto exit;
199 window = Open(ixWindow, MODE_OLDFILE);
200 if (window == NULL)
202 /* try to open default window */
203 window = Open(DEFWINDOW, MODE_OLDFILE);
206 if (window)
208 struct TagItem tags[] =
210 { SYS_Asynch, FALSE },
211 { SYS_Background, TRUE },
212 { SYS_Input, (IPTR)window },
213 { SYS_Output, (IPTR)NULL },
214 { SYS_Error, (IPTR)NULL },
215 { SYS_ScriptInput, (IPTR)from },
216 { SYS_UserShell, ixUShell },
217 { NP_StackSize, ixStack },
218 { TAG_DONE, 0 }
221 rc = SystemTagList("", tags);
222 if (rc == -1)
224 displayMsg(IoErr());
225 rc = RETURN_FAIL;
228 else
230 displayMsg(IoErr());
231 goto exit;
234 Delay(ixWait);
235 rc = RETURN_OK;
237 exit:
238 Close(window);
239 FreeDiskObject(dobj);
240 FreeVec(path);
242 if (oldlock != (BPTR)-1)
243 CurrentDir(oldlock);
245 if (dirlock != (BPTR)-1)
246 UnLock(dirlock);
248 return rc;