grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / devs / monitors / wrapper / wrapper.c
blob0f439810f34f538d66212db17879cdec0372b81b
1 /*
2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Backwards compatibility display driver loader.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <dos/dosextens.h>
11 #include <oop/oop.h>
12 #include <workbench/startup.h>
13 #include <workbench/workbench.h>
14 #include <proto/dos.h>
15 #include <proto/exec.h>
16 #include <proto/graphics.h>
17 #include <proto/oop.h>
18 #include <proto/icon.h>
20 /************************************************************************/
22 struct MyArgs
24 STRPTR hidd;
25 STRPTR lib;
28 extern struct WBStartup *WBenchMsg;
30 int __nocommandline = 1;
32 int main(void)
34 BPTR olddir = BNULL;
35 STRPTR myname;
36 struct DiskObject *icon;
37 struct RDArgs *rdargs = NULL;
38 int res = RETURN_OK;
39 struct MyArgs args = {NULL};
41 if (WBenchMsg) {
42 olddir = CurrentDir(WBenchMsg->sm_ArgList[0].wa_Lock);
43 myname = WBenchMsg->sm_ArgList[0].wa_Name;
44 } else {
45 struct Process *me = (struct Process *)FindTask(NULL);
47 if (me->pr_CLI) {
48 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
50 myname = AROS_BSTR_ADDR(cli->cli_CommandName);
51 } else
52 myname = me->pr_Task.tc_Node.ln_Name;
54 D(Printf("Command name: %s\n", myname));
56 icon = GetDiskObject(myname);
57 D(Printf("Icon 0x%p\n", icon));
59 if (icon) {
60 args.hidd = FindToolType(icon->do_ToolTypes, "CLASS");
61 args.lib = FindToolType(icon->do_ToolTypes, "LIBRARY");
64 if (!WBenchMsg) {
65 rdargs = ReadArgs("CLASS=HIDD/A,LIBRARY=LIB", (IPTR *)&args, NULL);
66 D(Printf("RDArgs 0x%p\n", rdargs));
69 D(Printf("CLASS=%s, LIBRARY=%s\n", args.hidd ? args.hidd : "<none>",
70 args.lib ? args.lib : "<none>"));
72 if (args.hidd)
74 OOP_Class *cl;
75 struct Library *gfxlib = NULL;
77 cl = OOP_FindClass(args.hidd);
78 if (!cl)
80 if (args.lib)
82 gfxlib = OpenLibrary(args.lib, 0);
83 if (!gfxlib)
84 res = RETURN_ERROR;
87 if (res == RETURN_OK)
89 cl = OOP_FindClass(args.hidd);
90 if (cl)
92 if (AddDisplayDriverA(cl, NULL, NULL))
94 res = RETURN_FAIL;
97 else
98 res = RETURN_ERROR;
100 if ((res != RETURN_OK) && gfxlib)
101 CloseLibrary(gfxlib);
104 } else
105 res = RETURN_ERROR;
107 if (rdargs)
108 FreeArgs(rdargs);
109 if (icon)
110 FreeDiskObject(icon);
111 if (olddir)
112 CurrentDir(olddir);
114 return res;