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 const IPTR args
[] = {version
, (IPTR
)set
->name
};
52 "Could not open version %ld or higher of library \"%s\".",
60 D(bug("[Autoinit] Done\n"));
64 void _set_close_libraries_list(const void * const list
[], struct ExecBase
*SysBase
)
67 struct libraryset
*set
;
69 ForeachElementInSet(list
, 1, pos
, set
)
73 CloseLibrary(*set
->baseptr
);
81 AROS_MAKE_ASM_SYM(int, dummyrel
, __includerellibrarieshandling
, 0);
82 AROS_EXPORT_ASM_SYM(__includerellibrarieshandling
);
84 int _set_open_rellibraries_list(APTR base
, const void * const list
[], struct ExecBase
*SysBase
)
87 struct rellibraryset
*set
;
89 D(bug("[Autoinit] Opening relative libraries for %s @ 0x%p...\n", ((struct Node
*)base
)->ln_Name
, base
));
91 ForeachElementInSet(list
, 1, pos
, set
)
93 LONG version
= *set
->versionptr
;
95 void **baseptr
= (void **)((char *)base
+ *set
->baseoffsetptr
);
99 version
= -(version
+ 1);
103 D(bug("[Autoinit] Offset %d, %s version %d... ", *set
->baseoffsetptr
, set
->name
, version
));
104 *baseptr
= OpenLibrary(set
->name
, version
);
105 D(bug("0x%p\n", *baseptr
));
107 if (!do_not_fail
&& *baseptr
== NULL
)
109 const IPTR args
[]= {version
, (IPTR
)set
->name
};
112 "Could not open version %ld or higher of library \"%s\".",
120 D(bug("[Autoinit] %s Done\n", ((struct Node
*)base
)->ln_Name
));
124 void _set_close_rellibraries_list(APTR base
, const void * const list
[], struct ExecBase
*SysBase
)
127 struct rellibraryset
*set
;
128 struct Library
**baseptr
;
130 ForeachElementInSet(list
, 1, pos
, set
)
132 baseptr
= (struct Library
**)((char *)base
+ *set
->baseoffsetptr
);
136 CloseLibrary(*baseptr
);