grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / LoadResource / main.c
blob2a35b948ab262c549f21bd4f4ed5e9c9775ac1cb
1 /*
2 Copyright © 2004-2013, The AROS Development Team. All rights reserved.
3 This file is part of the LoadResource program, which is distributed under
4 the terms of version 2 of the GNU General Public License.
6 FIXME:
7 + Implement LOCK and UNLOCK options. Argument template should then be
8 changed to "NAME/M,LOCK/S,UNLOCK/S"; if the user doesn't provide NAME,
9 then all currently locked resources shall be listed.
10 + Implement support for loading devices, fonts and catalogs.
13 #include <exec/io.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
17 #include <string.h>
19 #include "locale.h"
21 enum
23 ARG_NAME,
24 ARG_COUNT
27 #define TEMPLATE "NAME/M/A"
28 #define ERROR_HEADER "LoadResource"
30 BOOL process(CONST_STRPTR name);
31 BOOL dev_process(CONST_STRPTR name);
33 int main(void)
35 int rc = RETURN_OK;
36 struct RDArgs *rdargs = NULL;
37 IPTR args[ARG_COUNT] = { 0 };
39 if ((rdargs = ReadArgs(TEMPLATE, args, NULL)) != NULL)
41 if (args[ARG_NAME] != 0)
43 CONST_STRPTR *names = (CONST_STRPTR *) args[ARG_NAME],
44 name = NULL;
46 while ((name = *names++) != NULL)
48 BOOL res;
49 int len = strlen(name);
51 if ((len > 7) && (!strcmp(&name[len-7], ".device")))
52 res = dev_process(name);
53 else
54 res = process(name);
56 if (!res)
58 rc = RETURN_WARN;
62 else
64 // FIXME: List currently locked resources.
67 FreeArgs(rdargs);
69 else
71 PrintFault(IoErr(), ERROR_HEADER);
72 rc = RETURN_FAIL;
75 return rc;
78 BOOL process(CONST_STRPTR name)
80 struct Library *lb = OpenLibrary(name, 0L);
82 if (lb != NULL)
84 CloseLibrary(lb);
85 return TRUE;
87 else
89 PutStr(ERROR_HEADER": ");
90 Printf(_(MSG_ERROR_OPEN_LIBRARY), name);
91 PutStr("\n");
92 return FALSE;
96 BOOL dev_process(CONST_STRPTR name)
98 struct IORequest req;
100 memset(&req, 0, sizeof(req));
101 req.io_Message.mn_Length = sizeof(req);
103 if (!OpenDevice(name, 0, &req, 0))
105 CloseDevice(&req);
106 return TRUE;
109 /* There can different errors, but if the device was loaded, it's OK */
110 if (FindName(&SysBase->DeviceList, name))
111 return TRUE;
113 PutStr(ERROR_HEADER": ");
114 Printf(_(MSG_ERROR_OPEN_DEVICE), name);
115 PutStr("\n");
117 return FALSE;