2 Copyright © 2006, The AROS Development Team. All rights reserved.
5 Desc: IconX WB script starter
9 /******************************************************************************
25 Starts DOS scripts from Workbench. In order to use it you need an icon for
26 your script. Set 'IconX' as default tool.
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
52 ******************************************************************************/
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>
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
)
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
;
93 BPTR oldlock
= (BPTR
)-1;
94 BPTR dirlock
= (BPTR
)-1;
96 struct DiskObject
*dobj
= NULL
;
98 STRPTR ixWindow
= DEFWINDOW
;
100 LONG ixStack
= DEFSTACK
;
101 BOOL ixUShell
= DEFUSHELL
;
106 D(bug("IconX argc %d\n", argc
));
110 displayMsg(ERROR_REQUIRED_ARG_MISSING
);
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
);
122 displayMsg(ERROR_NO_FREE_STORE
);
126 strncpy(path
, argv
[1], pathlen
);
127 dirlock
= Lock(path
, SHARED_LOCK
);
130 displayMsg(ERROR_INVALID_LOCK
);
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
);
144 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
145 "Error", "IconX\nGetDiskObject failed for:\n%s", "OK"};
146 EasyRequest(0, &es
, 0, filename
);
150 if (dobj
->do_Type
== WBPROJECT
)
152 const STRPTR
*toolarray
= (const STRPTR
*)dobj
->do_ToolTypes
;
154 if ((s
= FindToolType(toolarray
, "WINDOW")))
158 if ((s
= FindToolType(toolarray
, "STACK")))
162 if ((s
= FindToolType(toolarray
, "USERSHELL")))
164 if (MatchToolValue(s
, "NO"))
169 if ((s
= FindToolType(toolarray
, "WAIT")))
171 ixWait
+= atol(s
) * 50;
173 if ((s
= FindToolType(toolarray
, "DELAY")))
180 displayMsg(ERROR_OBJECT_WRONG_TYPE
);
190 D(bug("wait %d stack %d usershell %d window %s\n", ixWait
, ixStack
, ixUShell
, ixWindow
));
192 from
= Open(filename
, MODE_OLDFILE
);
199 window
= Open(ixWindow
, MODE_OLDFILE
);
202 /* try to open default window */
203 window
= Open(DEFWINDOW
, MODE_OLDFILE
);
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
},
221 rc
= SystemTagList("", tags
);
239 FreeDiskObject(dobj
);
242 if (oldlock
!= (BPTR
)-1)
245 if (dirlock
!= (BPTR
)-1)