- Updates to entry selection behaviour to accommodate multiselection test
[AROS.git] / compiler / autoinit / libraries.c
blob880dc14a3dc083f9db312822bcf53b3a13a2eab4
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: autoinit library - automatic library opening/closing handling
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include <dos/dos.h>
12 #include <aros/symbolsets.h>
13 #include <aros/autoinit.h>
14 #include <intuition/intuition.h>
15 #include <dos/dosextens.h>
16 #include <proto/intuition.h>
17 #include <proto/dos.h>
18 #include <stdlib.h>
20 DEFINESET(LIBS);
22 AROS_MAKE_ASM_SYM(int, dummy, __includelibrarieshandling, 0);
23 AROS_EXPORT_ASM_SYM(__includelibrarieshandling);
25 int _set_open_libraries_list(const void * const list[], struct ExecBase *SysBase)
27 int pos;
28 struct libraryset *set;
30 D(bug("[Autoinit] Opening libraries...\n"));
32 ForeachElementInSet(list, 1, pos, set)
34 LONG version = *set->versionptr;
35 BOOL do_not_fail = 0;
37 if (version < 0)
39 version = -(version + 1);
40 do_not_fail = 1;
43 D(bug("[Autoinit] %s version %d... ", set->name, version));
44 *set->baseptr = OpenLibrary(set->name, version);
45 D(bug("0x%p\n", *set->baseptr));
47 if (!do_not_fail && *set->baseptr == NULL)
49 __showerror("Could not open version %ld or higher of library \"%s\".", version, set->name);
51 return 0;
55 D(bug("[Autoinit] Done\n"));
56 return 1;
59 void _set_close_libraries_list(const void * const list[], struct ExecBase *SysBase)
61 int pos;
62 struct libraryset *set;
64 ForeachElementInSet(list, 1, pos, set)
66 if (*set->baseptr)
68 CloseLibrary(*set->baseptr);
69 *set->baseptr = NULL;
74 DEFINESET(RELLIBS);
76 AROS_MAKE_ASM_SYM(int, dummyrel, __includerellibrarieshandling, 0);
77 AROS_EXPORT_ASM_SYM(__includerellibrarieshandling);
79 int _set_open_rellibraries_list(APTR base, const void * const list[], struct ExecBase *SysBase)
81 int pos;
82 struct rellibraryset *set;
84 D(bug("[Autoinit] Opening relative libraries for %s @ 0x%p...\n", ((struct Node *)base)->ln_Name, base));
86 ForeachElementInSet(list, 1, pos, set)
88 LONG version = *set->versionptr;
89 BOOL do_not_fail = 0;
90 void **baseptr = (void **)((char *)base + *set->baseoffsetptr);
92 if (version < 0)
94 version = -(version + 1);
95 do_not_fail = 1;
98 D(bug("[Autoinit] Offset %d, %s version %d... ", *set->baseoffsetptr, set->name, version));
99 *baseptr = OpenLibrary(set->name, version);
100 D(bug("0x%p\n", *baseptr));
102 if (!do_not_fail && *baseptr == NULL)
104 __showerror("Could not open version %ld or higher of library \"%s\".", version, set->name);
106 return 0;
110 D(bug("[Autoinit] %s Done\n", ((struct Node *)base)->ln_Name));
111 return 1;
114 void _set_close_rellibraries_list(APTR base, const void * const list[], struct ExecBase *SysBase)
116 int pos;
117 struct rellibraryset *set;
118 struct Library **baseptr;
120 ForeachElementInSet(list, 1, pos, set)
122 baseptr = (struct Library **)((char *)base + *set->baseoffsetptr);
124 if (*baseptr)
126 CloseLibrary(*baseptr);
127 *baseptr = NULL;