2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: autoinit library - automatic library opening/closing handling
9 #include <aros/debug.h>
10 #include <proto/exec.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>
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
)
28 struct libraryset
*set
;
30 D(bug("[Autoinit] Opening libraries...\n"));
32 ForeachElementInSet(list
, 1, pos
, set
)
34 LONG version
= *set
->versionptr
;
39 version
= -(version
+ 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
);
55 D(bug("[Autoinit] Done\n"));
59 void _set_close_libraries_list(const void * const list
[], struct ExecBase
*SysBase
)
62 struct libraryset
*set
;
64 ForeachElementInSet(list
, 1, pos
, set
)
68 CloseLibrary(*set
->baseptr
);
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
)
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
;
90 void **baseptr
= (void **)((char *)base
+ *set
->baseoffsetptr
);
94 version
= -(version
+ 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
);
110 D(bug("[Autoinit] %s Done\n", ((struct Node
*)base
)->ln_Name
));
114 void _set_close_rellibraries_list(APTR base
, const void * const list
[], struct ExecBase
*SysBase
)
117 struct rellibraryset
*set
;
118 struct Library
**baseptr
;
120 ForeachElementInSet(list
, 1, pos
, set
)
122 baseptr
= (struct Library
**)((char *)base
+ *set
->baseoffsetptr
);
126 CloseLibrary(*baseptr
);