netsurf/amiga/libs.c

312 lines
11 KiB
C
Raw Normal View History

/*
* Copyright 2014 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2015-01-19 00:11:00 +03:00
#include "amiga/os3support.h"
2014-11-08 22:25:53 +03:00
#include "amiga/libs.h"
#include "amiga/misc.h"
2014-11-08 22:57:36 +03:00
#include "utils/utils.h"
2014-11-09 02:53:01 +03:00
#include "utils/log.h"
2014-11-08 22:25:53 +03:00
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/utility.h>
2015-01-25 04:06:46 +03:00
#ifndef __amigaos4__
/* OS3 needs these for the XXXX_GetClass() functions */
#include <proto/arexx.h>
#include <proto/bevel.h>
#include <proto/bitmap.h>
2015-01-26 03:13:44 +03:00
#include <proto/button.h>
2015-01-25 04:06:46 +03:00
#include <proto/chooser.h>
#include <proto/checkbox.h>
#include <proto/clicktab.h>
#include <proto/fuelgauge.h>
#include <proto/getfile.h>
#include <proto/getfont.h>
#include <proto/getscreenmode.h>
#include <proto/integer.h>
#include <proto/label.h>
#include <proto/layout.h>
#include <proto/listbrowser.h>
#include <proto/radiobutton.h>
#include <proto/scroller.h>
#include <proto/space.h>
#include <proto/speedbar.h>
#include <proto/string.h>
#include <proto/window.h>
#endif
2015-01-19 00:11:00 +03:00
#ifdef __amigaos4__
#define AMINS_LIB_OPEN(LIB, LIBVER, PREFIX, INTERFACE, INTVER, FAIL) \
2014-11-09 02:53:01 +03:00
LOG(("Opening %s v%d", LIB, LIBVER)); \
if((PREFIX##Base = (struct PREFIX##Base *)OpenLibrary(LIB, LIBVER))) { \
I##PREFIX = (struct PREFIX##IFace *)GetInterface((struct Library *)PREFIX##Base, INTERFACE, INTVER, NULL); \
if(I##PREFIX == NULL) { \
LOG(("Failed to get %s interface v%d of %s", INTERFACE, INTVER, LIB)); \
} \
2014-11-08 22:40:23 +03:00
} else { \
LOG(("Failed to open %s v%d", LIB, LIBVER)); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", LIB, LIBVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
return false; \
} \
}
2014-11-08 22:57:36 +03:00
#define AMINS_LIB_CLOSE(PREFIX) \
if(I##PREFIX) DropInterface((struct Interface *)I##PREFIX); \
if(PREFIX##Base) CloseLibrary((struct Library *)PREFIX##Base);
2014-11-08 22:57:36 +03:00
#define AMINS_LIB_STRUCT(PREFIX) \
struct PREFIX##Base *PREFIX##Base; \
2014-11-08 22:57:36 +03:00
struct PREFIX##IFace *I##PREFIX;
#define AMINS_CLASS_OPEN(CLASS, CLASSVER, PREFIX, CLASSGET, NEEDINTERFACE) \
LOG(("Opening %s v%d", CLASS, CLASSVER)); \
if((PREFIX##Base = OpenClass(CLASS, CLASSVER, &PREFIX##Class))) { \
if(NEEDINTERFACE == true) { \
LOG((" + interface")); \
I##PREFIX = (struct PREFIX##IFace *)GetInterface((struct Library *)PREFIX##Base, "main", 1, NULL); \
if(I##PREFIX == NULL) { \
LOG(("Failed to get main interface v1 of %s", CLASS)); \
} \
} \
2015-01-25 04:12:45 +03:00
} \
if(PREFIX##Class == NULL) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
return false; \
}
#define AMINS_CLASS_CLOSE(PREFIX) \
if(I##PREFIX) DropInterface((struct Interface *)I##PREFIX); \
if(PREFIX##Base) CloseClass(PREFIX##Base);
#define AMINS_CLASS_STRUCT(PREFIX) \
struct ClassLibrary *PREFIX##Base = NULL; \
struct PREFIX##IFace *I##PREFIX = NULL; \
Class *PREFIX##Class = NULL;
2015-01-19 00:11:00 +03:00
#else
#define AMINS_LIB_OPEN(LIB, LIBVER, PREFIX, INTERFACE, INTVER, FAIL) \
LOG(("Opening %s v%d", LIB, LIBVER)); \
if((PREFIX##Base = (struct PREFIX##Base *)OpenLibrary(LIB, LIBVER))) { \
2015-01-19 00:11:00 +03:00
} else { \
LOG(("Failed to open %s v%d", LIB, LIBVER)); \
if(FAIL == true) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", LIB, LIBVER); \
2015-01-19 00:11:00 +03:00
ami_misc_fatal_error(error); \
FreeVec(error); \
return false; \
} \
}
#define AMINS_LIB_CLOSE(PREFIX) \
2015-01-25 04:06:46 +03:00
if(PREFIX##Base) CloseLibrary((struct Library *)PREFIX##Base);
2015-01-19 00:11:00 +03:00
#define AMINS_LIB_STRUCT(PREFIX) \
struct PREFIX##Base *PREFIX##Base;
#define AMINS_CLASS_OPEN(CLASS, CLASSVER, PREFIX, CLASSGET, NEEDINTERFACE) \
LOG(("Opening %s v%d", CLASS, CLASSVER)); \
2015-01-25 04:06:46 +03:00
if((PREFIX##Base = OpenLibrary(CLASS, CLASSVER))) { \
PREFIX##Class = CLASSGET##_GetClass(); \
2015-01-25 04:12:45 +03:00
} \
if(PREFIX##Class == NULL) { \
STRPTR error = ASPrintf("Unable to open %s v%d (fatal error)", CLASS, CLASSVER); \
ami_misc_fatal_error(error); \
FreeVec(error); \
return false; \
}
#define AMINS_CLASS_CLOSE(PREFIX) \
2015-01-25 04:06:46 +03:00
if(PREFIX##Base) CloseLibrary(PREFIX##Base);
#define AMINS_CLASS_STRUCT(PREFIX) \
2015-01-25 04:12:45 +03:00
struct Library *PREFIX##Base = NULL; \
Class *PREFIX##Class = NULL;
2015-01-19 00:11:00 +03:00
#endif
2014-11-08 22:57:36 +03:00
2014-11-09 02:43:52 +03:00
#define GraphicsBase GfxBase /* graphics.library is a bit weird */
2014-11-09 01:00:15 +03:00
2015-01-19 02:29:49 +03:00
#ifdef __amigaos4__
2014-11-08 22:57:36 +03:00
AMINS_LIB_STRUCT(Application);
2015-01-19 02:29:49 +03:00
#else
AMINS_LIB_STRUCT(Utility)
2015-01-19 02:29:49 +03:00
#endif
2014-11-08 22:57:36 +03:00
AMINS_LIB_STRUCT(Asl);
2014-11-09 02:43:52 +03:00
AMINS_LIB_STRUCT(DataTypes);
2014-11-08 22:57:36 +03:00
AMINS_LIB_STRUCT(Diskfont);
AMINS_LIB_STRUCT(Graphics);
2014-11-09 02:43:52 +03:00
AMINS_LIB_STRUCT(GadTools);
AMINS_LIB_STRUCT(Icon);
AMINS_LIB_STRUCT(IFFParse);
2014-11-08 22:57:36 +03:00
AMINS_LIB_STRUCT(Intuition);
AMINS_LIB_STRUCT(Keymap);
2014-11-09 02:43:52 +03:00
AMINS_LIB_STRUCT(Layers);
AMINS_LIB_STRUCT(Locale);
AMINS_LIB_STRUCT(P96);
2014-11-09 02:43:52 +03:00
AMINS_LIB_STRUCT(Workbench);
AMINS_CLASS_STRUCT(ARexx);
AMINS_CLASS_STRUCT(Bevel);
AMINS_CLASS_STRUCT(BitMap);
AMINS_CLASS_STRUCT(Button);
AMINS_CLASS_STRUCT(Chooser);
AMINS_CLASS_STRUCT(CheckBox);
AMINS_CLASS_STRUCT(ClickTab);
AMINS_CLASS_STRUCT(FuelGauge);
AMINS_CLASS_STRUCT(GetFile);
AMINS_CLASS_STRUCT(GetFont);
AMINS_CLASS_STRUCT(GetScreenMode);
AMINS_CLASS_STRUCT(Integer);
AMINS_CLASS_STRUCT(Label);
AMINS_CLASS_STRUCT(Layout);
AMINS_CLASS_STRUCT(ListBrowser);
AMINS_CLASS_STRUCT(RadioButton);
AMINS_CLASS_STRUCT(Scroller);
AMINS_CLASS_STRUCT(Space);
AMINS_CLASS_STRUCT(SpeedBar);
AMINS_CLASS_STRUCT(String);
AMINS_CLASS_STRUCT(Window);
2014-11-09 02:43:52 +03:00
2014-11-08 22:40:23 +03:00
bool ami_libs_open(void)
2014-11-08 22:40:23 +03:00
{
2015-01-19 02:29:49 +03:00
#ifdef __amigaos4__
/* Libraries only needed on OS4 */
AMINS_LIB_OPEN("application.library", 53, Application, "application", 2, false)
2015-01-19 02:29:49 +03:00
#else
/* Libraries we get automatically on OS4 but not OS3 */
AMINS_LIB_OPEN("utility.library", 37, Utility, "main", 1, true)
#endif
/* Standard libraries for both versions */
AMINS_LIB_OPEN("asl.library", 37, Asl, "main", 1, true)
AMINS_LIB_OPEN("datatypes.library", 39, DataTypes, "main", 1, true)
2015-01-18 23:07:15 +03:00
AMINS_LIB_OPEN("diskfont.library", 40, Diskfont, "main", 1, true)
AMINS_LIB_OPEN("gadtools.library", 37, GadTools, "main", 1, true)
2015-01-18 23:07:15 +03:00
AMINS_LIB_OPEN("graphics.library", 40, Graphics, "main", 1, true)
AMINS_LIB_OPEN("icon.library", 44, Icon, "main", 1, true)
AMINS_LIB_OPEN("iffparse.library", 37, IFFParse, "main", 1, true)
2015-01-18 23:07:15 +03:00
AMINS_LIB_OPEN("intuition.library", 40, Intuition, "main", 1, true)
AMINS_LIB_OPEN("keymap.library", 37, Keymap, "main", 1, true)
AMINS_LIB_OPEN("layers.library", 37, Layers, "main", 1, true)
AMINS_LIB_OPEN("locale.library", 38, Locale, "main", 1, true)
AMINS_LIB_OPEN("workbench.library", 37, Workbench, "main", 1, true)
2014-11-09 02:43:52 +03:00
/*\todo This is down here as we need to check the graphics.library version
* before opening. If it is sufficiently new enough we can avoid using P96
*/
AMINS_LIB_OPEN("Picasso96API.library", 0, P96, "main", 1, false)
2014-11-29 22:56:54 +03:00
/* NB: timer.device is opened in schedule.c (ultimately by the scheduler process).
* The library base and interface are obtained there, rather than here, due to
* the additional complexities of opening devices, which aren't important here
* (as we only need the library interface), but are important for the scheduler
* (as it also uses the device interface). We trust that the scheduler has
* initialised before any other code requires the timer's library interface
* (this is ensured by waiting for the scheduler to start up) and that it is
* OK to use a child process' timer interface, to avoid opening it twice.
*/
2014-11-09 02:43:52 +03:00
/* BOOPSI classes.
* Opened using class functions rather than the old-fashioned method.
* We get the class pointer once and used our stored copy.
* On OS4 these must be opened *after* intuition.library.
* NB: the last argument should be "true" only if the class also has
* library functions we use.
2014-11-29 22:56:54 +03:00
*/
2014-11-09 02:43:52 +03:00
AMINS_CLASS_OPEN("arexx.class", 44, ARexx, AREXX, false)
AMINS_CLASS_OPEN("images/bevel.image", 44, Bevel, BEVEL, false)
AMINS_CLASS_OPEN("images/bitmap.image", 44, BitMap, BITMAP, false)
AMINS_CLASS_OPEN("gadgets/button.gadget", 44, Button, BUTTON, false)
AMINS_CLASS_OPEN("gadgets/checkbox.gadget", 44, CheckBox, CHECKBOX, false)
AMINS_CLASS_OPEN("gadgets/chooser.gadget", 44, Chooser, CHOOSER, true)
AMINS_CLASS_OPEN("gadgets/clicktab.gadget", 44, ClickTab, CLICKTAB, true)
AMINS_CLASS_OPEN("gadgets/fuelgauge.gadget", 44, FuelGauge, FUELGAUGE, false)
AMINS_CLASS_OPEN("gadgets/getfile.gadget", 44, GetFile, GETFILE, false)
AMINS_CLASS_OPEN("gadgets/getfont.gadget", 44, GetFont, GETFONT, false)
AMINS_CLASS_OPEN("gadgets/getscreenmode.gadget", 44, GetScreenMode, GETSCREENMODE, false)
AMINS_CLASS_OPEN("gadgets/integer.gadget", 44, Integer, INTEGER, false)
AMINS_CLASS_OPEN("images/label.image", 44, Label, LABEL, false)
AMINS_CLASS_OPEN("gadgets/layout.gadget", 44, Layout, LAYOUT, true)
AMINS_CLASS_OPEN("gadgets/listbrowser.gadget", 44, ListBrowser, LISTBROWSER, true)
AMINS_CLASS_OPEN("gadgets/radiobutton.gadget", 44, RadioButton, RADIOBUTTON, false)
AMINS_CLASS_OPEN("gadgets/scroller.gadget", 44, Scroller, SCROLLER, false)
AMINS_CLASS_OPEN("gadgets/space.gadget", 44, Space, SPACE, false)
AMINS_CLASS_OPEN("gadgets/speedbar.gadget", 44, SpeedBar, SPEEDBAR, false)
AMINS_CLASS_OPEN("gadgets/string.gadget", 44, String, STRING, false)
AMINS_CLASS_OPEN("window.class", 44, Window, WINDOW, false)
return true;
}
void ami_libs_close(void)
{
/* BOOPSI Classes.
* On OS4 these must be closed *before* intuition.library
*/
AMINS_CLASS_CLOSE(ARexx)
AMINS_CLASS_CLOSE(Bevel)
AMINS_CLASS_CLOSE(BitMap)
AMINS_CLASS_CLOSE(Button)
AMINS_CLASS_CLOSE(CheckBox)
AMINS_CLASS_CLOSE(Chooser)
AMINS_CLASS_CLOSE(ClickTab)
AMINS_CLASS_CLOSE(FuelGauge)
AMINS_CLASS_CLOSE(GetFile)
AMINS_CLASS_CLOSE(GetFont)
AMINS_CLASS_CLOSE(GetScreenMode)
AMINS_CLASS_CLOSE(Integer)
AMINS_CLASS_CLOSE(Label)
AMINS_CLASS_CLOSE(Layout)
AMINS_CLASS_CLOSE(ListBrowser)
AMINS_CLASS_CLOSE(RadioButton)
AMINS_CLASS_CLOSE(Scroller)
AMINS_CLASS_CLOSE(Space)
AMINS_CLASS_CLOSE(SpeedBar)
AMINS_CLASS_CLOSE(String)
AMINS_CLASS_CLOSE(Window)
/* Libraries */
AMINS_LIB_CLOSE(Asl)
AMINS_LIB_CLOSE(DataTypes)
AMINS_LIB_CLOSE(Diskfont)
AMINS_LIB_CLOSE(GadTools)
AMINS_LIB_CLOSE(Graphics)
AMINS_LIB_CLOSE(Icon)
AMINS_LIB_CLOSE(IFFParse)
AMINS_LIB_CLOSE(Intuition)
AMINS_LIB_CLOSE(Keymap)
AMINS_LIB_CLOSE(Layers)
AMINS_LIB_CLOSE(Locale)
AMINS_LIB_CLOSE(P96)
AMINS_LIB_CLOSE(Workbench)
2015-01-19 02:29:49 +03:00
#ifdef __amigaos4__
AMINS_LIB_CLOSE(Application)
#else
AMINS_LIB_CLOSE(Utility)
#endif
}