2 Copyright © 2006-2007, The AROS Development Team. All rights reserved.
5 Desc: IconX WB script starter
9 /******************************************************************************
26 Starts DOS scripts from Workbench. In order to use it you need an icon for
27 your script. Set 'IconX' as default tool.
31 FILE - The script filename to execute.
33 Tooltypes for script icon:
34 WINDOW -- Specification of the shell window
35 default: con:0/50//80/IconX/Auto
36 STACK=n -- default: 40960
37 USERSHELL=YES|NO -- default: YES
38 WAIT=n -- Wait n seconds before closing window (default 2)
39 DELAY=n -- Wait n/50 seconds before closing window
57 ******************************************************************************/
61 #include <aros/debug.h>
62 #include <proto/exec.h>
63 #include <proto/dos.h>
64 #include <proto/intuition.h>
65 #include <proto/icon.h>
67 #include <workbench/startup.h>
72 /* some default values */
73 #define DEFWINDOW "con:0/50//80/IconX/Auto"
74 #define DEFSTACK (40960)
75 #define DEFWAIT (2 * 50) // two seconds
76 #define DEFUSHELL (TRUE)
78 const TEXT version
[] = "\0$VER: IconX 41.1 (8.12.2007)";
79 int __forceerrorrequester
= 1;
80 static TEXT errbuffer
[255];
83 void displayMsg(LONG code
)
87 Fault(code
, "IconX", errbuffer
, sizeof(errbuffer
));
88 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
89 "Error", errbuffer
, "OK"};
90 EasyRequest(0, &es
, 0);
95 int main(int argc
, char **argv
)
97 LONG rc
= RETURN_FAIL
;
99 BPTR oldlock
= (BPTR
)-1;
100 BPTR dirlock
= (BPTR
)-1;
101 struct DiskObject
*dobj
= NULL
;
103 STRPTR ixWindow
= DEFWINDOW
;
105 LONG ixStack
= DEFSTACK
;
106 BOOL ixUShell
= DEFUSHELL
;
111 D(bug("IconX argc %d\n", argc
));
115 displayMsg(ERROR_REQUIRED_ARG_MISSING
);
119 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
120 if (startup
->sm_NumArgs
!= 2)
122 displayMsg(ERROR_REQUIRED_ARG_MISSING
);
126 dirlock
= startup
->sm_ArgList
[1].wa_Lock
;
127 filename
= startup
->sm_ArgList
[1].wa_Name
;
129 oldlock
= CurrentDir(dirlock
);
131 /* query diskobject for tooltypes */
132 dobj
= GetDiskObject(filename
);
135 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
136 "Error", "IconX\nGetDiskObject failed for:\n%s", "OK"};
137 EasyRequest(0, &es
, 0, filename
);
141 if (dobj
->do_Type
== WBPROJECT
)
143 const STRPTR
*toolarray
= (const STRPTR
*)dobj
->do_ToolTypes
;
145 if ((s
= FindToolType(toolarray
, "WINDOW")))
149 if ((s
= FindToolType(toolarray
, "STACK")))
153 if ((s
= FindToolType(toolarray
, "USERSHELL")))
155 if (MatchToolValue(s
, "NO"))
160 if ((s
= FindToolType(toolarray
, "WAIT")))
162 ixWait
+= atol(s
) * 50;
164 if ((s
= FindToolType(toolarray
, "DELAY")))
171 displayMsg(ERROR_OBJECT_WRONG_TYPE
);
181 D(bug("wait %d stack %d usershell %d window %s\n", ixWait
, ixStack
, ixUShell
, ixWindow
));
183 from
= Open(filename
, MODE_OLDFILE
);
190 window
= Open(ixWindow
, MODE_OLDFILE
);
193 /* try to open default window */
194 window
= Open(DEFWINDOW
, MODE_OLDFILE
);
199 struct TagItem tags
[] =
201 { SYS_Asynch
, FALSE
},
202 { SYS_Background
, TRUE
},
203 { SYS_Input
, (IPTR
)window
},
204 { SYS_Output
, (IPTR
)NULL
},
205 { SYS_Error
, (IPTR
)NULL
},
206 { SYS_ScriptInput
, (IPTR
)from
},
207 { SYS_UserShell
, ixUShell
},
208 { NP_StackSize
, ixStack
},
212 rc
= SystemTagList("", tags
);
230 FreeDiskObject(dobj
);
232 if (oldlock
!= (BPTR
)-1)