diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..031bb46 --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,34 @@ +name: Makefile CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build-os3: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Run the build process with Docker + uses: addnab/docker-run-action@v3 + with: + image: amigadev/crosstools:m68k-amigaos + options: -v ${{ github.workspace }}:/work + run: | + cd mcc + make OS=os3 DEBUG= + cd ../mcp + make OS=os3 DEBUG= + + - uses: actions/upload-artifact@v3 + with: + name: HTMLview_os3 + path: | + bin_os3/HTMLview.mcp + bin_os3/HTMLview-Prefs + bin_os3/HTMLview.mcc + bin_os3/HTMLview-Test diff --git a/build_os3.bat b/build_os3.bat new file mode 100644 index 0000000..a83fd38 --- /dev/null +++ b/build_os3.bat @@ -0,0 +1,2 @@ +@echo off +powershell -ExecutionPolicy Bypass -File "%~dp0build_os3.ps1" diff --git a/build_os3.ps1 b/build_os3.ps1 new file mode 100644 index 0000000..8998e75 --- /dev/null +++ b/build_os3.ps1 @@ -0,0 +1,36 @@ +# PowerShell script to build for AmigaOS 3 using Docker + +$ErrorActionPreference = "Stop" + +# Define the Docker image +$Image = "amigadev/crosstools:m68k-amigaos" + +# Define the build command +# We mirror the steps from .github/workflows/makefile.yml +# 1. cd mcc +# 2. make OS=os3 DEBUG= +# 3. cd ../mcp +# 4. make OS=os3 DEBUG= +$BuildCommand = "mkdir -p mcc/.obj_os3/classes mcc/bin_os3 && cd mcc && make bin_os3/HTMLview.mcc OS=os3 DEBUG= > ../build.log 2>&1 && make bin_os3/SimpleTest OS=os3 DEBUG= >> ../build.log 2>&1 && cd ../mcp && make OS=os3 DEBUG= >> ../build.log 2>&1" + +# Get the current directory (project root) +$WorkDir = Get-Location + +Write-Host "Starting AmigaOS 3 cross-compilation..." +Write-Host "Mounting '$WorkDir' to '/work' in container '$Image'" + +try { + # Run the Docker container + # -v "${WorkDir}:/work" mounts the current directory to /work + # --rm automatically removes the container after exit + # -w /work sets the working directory to /work + docker run --rm -v "${WorkDir}:/work" -w /work $Image /bin/bash -c "$BuildCommand" + + if ($LASTEXITCODE -eq 0) { + Write-Host "Build completed successfully!" + } else { + Write-Error "Build failed with exit code $LASTEXITCODE" + } +} catch { + Write-Error "An error occurred while running Docker: $_" +} diff --git a/include/SDI_hook.h b/include/SDI_hook.h index e0be999..2109b48 100644 --- a/include/SDI_hook.h +++ b/include/SDI_hook.h @@ -305,11 +305,11 @@ // the AmigaOS3 g++ 2.95.3 cannot handle explicit register definitions and // hence requires HookEntry() as gate function #define MakeCppHook(hookname, funcname) struct Hook hookname = {{NULL, NULL}, \ - (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + (ULONG (*)())HookEntry, (ULONG (*)())funcname, NULL} #define MakeCppHookWithData(hookname, funcname, data) struct Hook hookname = \ - {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, (APTR)data} + {{NULL, NULL}, (ULONG (*)())HookEntry, (ULONG (*)())funcname, (APTR)data} #define MakeStaticCppHook(hookname, funcname) static struct Hook hookname = \ - {{NULL, NULL}, (HOOKFUNC)HookEntry, (HOOKFUNC)funcname, NULL} + {{NULL, NULL}, (ULONG (*)())HookEntry, (ULONG (*)())funcname, NULL} #endif #define DISPATCHERPROTO(name) SAVEDS ASM IPTR name(REG(a0, \ diff --git a/include/mccinit.c b/include/mccinit.c index 1cd74d0..bd5b36c 100644 --- a/include/mccinit.c +++ b/include/mccinit.c @@ -184,7 +184,7 @@ struct Interface *INewlib = NULL; #else struct Library *MUIMasterBase = NULL; struct ExecBase *SysBase = NULL; -struct Library *UtilityBase = NULL; +struct UtilityBase *UtilityBase = NULL; struct DosLibrary *DOSBase = NULL; struct GfxBase *GfxBase = NULL; struct IntuitionBase *IntuitionBase = NULL; @@ -198,7 +198,6 @@ extern "C" { // newer OS version can directly take the specified // number for the ramlib process #if defined(MIN_STACKSIZE) - // transforms a define into a string #define STR(x) STR2(x) #define STR2(x) #x @@ -206,6 +205,12 @@ extern "C" { static const char USED_VAR stack_size[] = "$STACK:" STR(MIN_STACKSIZE) "\n"; #endif +// Declared _init/_fini for AmigaOS 3 C++ manual initialization +#if defined(__amigaos3__) +extern void _init(void); +extern void _fini(void); +#endif + /* The name of the class will also become the name of the library. */ /* We need a pointer to this string in our ROMTag (see below). */ static const char UserLibName[] = CLASS; @@ -642,7 +647,7 @@ static ULONG mccLibInit(struct LibraryHeader *base) if((DOSBase = (struct DosLibrary*)OpenLibrary("dos.library", 36)) && (GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 36)) && (IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", 36)) && - (UtilityBase = OpenLibrary("utility.library", 36))) + (UtilityBase = (struct UtilityBase*)OpenLibrary("utility.library", 36))) #endif { // we have to please the internal utilitybase @@ -654,6 +659,11 @@ static ULONG mccLibInit(struct LibraryHeader *base) #endif #endif + #if defined(__amigaos3__) + // Manually call C++ constructors (including InitMem for MemoryPool) + _init(); + #endif + #if defined(DEBUG) SetupDebug(); #endif @@ -948,6 +958,10 @@ static BPTR LIBFUNC LibExpunge(REG(a6, struct LibraryHeader *base)) #endif BPTR rc; + #if defined(__amigaos3__) + _fini(); + #endif + D(DBF_STARTUP, "LibExpunge(%s): %ld", CLASS, base->lh_Library.lib_OpenCnt); // in case our open counter is still > 0, we have diff --git a/mcc/Animation.cpp b/mcc/Animation.cpp index 182ba38..06785c8 100644 --- a/mcc/Animation.cpp +++ b/mcc/Animation.cpp @@ -125,7 +125,9 @@ VOID AnimInfo::Stop (Object *obj, struct AnimInfo *prev) { prev = this; } - prev->Next->Stop(obj, prev); + if (prev && prev->Next) { + prev->Next->Stop(obj, prev); + } } } diff --git a/mcc/Debug.cpp b/mcc/Debug.cpp index 76b9953..79ea8fb 100644 --- a/mcc/Debug.cpp +++ b/mcc/Debug.cpp @@ -20,6 +20,7 @@ ***************************************************************************/ + #ifdef DEBUG #include // vsnprintf @@ -72,7 +73,7 @@ static ULONG debug_classes = DBC_ERROR | DBC_DEBUG | DBC_WARNING | DBC_ASSERT | /****************************************************************************/ -#ifdef __MORPHOS__ +#if defined(__MORPHOS__) #define VNewRawDoFmt(__p0, __p1, __p2, __p3) \ (((STRPTR (*)(void *, CONST_STRPTR , APTR (*)(APTR, UBYTE), STRPTR , va_list ))*(void**)((long)(EXEC_BASE_NAME) - 820))((void*)(EXEC_BASE_NAME), __p0, __p1, __p2, __p3)) @@ -85,6 +86,17 @@ void kprintf(const char *formatString,...) VNewRawDoFmt(formatString,(void * (*)(void *, UBYTE))RAWFMTFUNC_SERIAL,NULL,va); va_end(va); } +#elif defined(__amigaos3__) +extern "C" void KPrintF(const char *fmt, ...); +void kprintf(const char *formatString, ...) +{ + char buf[1024]; + va_list va; + va_start(va, formatString); + vsnprintf(buf, sizeof(buf), formatString, va); + KPrintF("%s", buf); + va_end(va); +} #endif /****************************************************************************/ diff --git a/mcc/HTMLview-Test.c b/mcc/HTMLview-Test.c deleted file mode 100644 index 5e4375b..0000000 --- a/mcc/HTMLview-Test.c +++ /dev/null @@ -1,454 +0,0 @@ -/*************************************************************************** - - HTMLview.mcc - HTMLview MUI Custom Class - Copyright (C) 1997-2000 Allan Odgaard - Copyright (C) 2005-2007 by HTMLview.mcc Open Source Team - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - HTMLview class Support Site: http://www.sf.net/projects/htmlview-mcc/ - - $Id$ - -***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include - -#include "HTMLview_mcc.h" -#include "mcc_common.h" -#include "SDI_hook.h" -#include "Debug.h" -//#include "private.h" -#include "ScrollGroup.h" - -struct MUI_CustomClass* ThisClass = NULL; - -struct Library* LayersBase = NULL; -struct Library* KeymapBase = NULL; -struct Library* CxBase = NULL; -struct Library* CyberGfxBase = NULL; -struct Library* DiskfontBase = NULL; -struct Library* DataTypesBase = NULL; -struct Library* MUIMasterBase = NULL; -struct Library* UtilityBase = NULL; -#if defined(__amigaos4__) -struct Library* IntuitionBase = NULL; -struct Library* GfxBase = NULL; -#else -struct IntuitionBase* IntuitionBase = NULL; -struct GfxBase* GfxBase = NULL; -#endif - -#if defined(__amigaos4__) -struct LayersIFace* ILayers = NULL; -struct KeymapIFace* IKeymap = NULL; -struct CommoditiesIFace* ICommodities = NULL; -struct CyberGfxIFace* ICyberGfx = NULL; -struct DiskfontIFace* IDiskfont = NULL; -struct DataTypesIFace* IDataTypes = NULL; -struct MUIMasterIFace* IMUIMaster = NULL; -struct IntuitionIFace* IIntuition = NULL; -struct GraphicsIFace* IGraphics = NULL; -struct UtilityIFace* IUtility = NULL; -#endif - -extern ULONG GetHTMLviewDataSize(void); - -extern void _init(void); -extern void _fini(void); - -ULONG xget(Object *obj, const ULONG attr); -#if defined(__GNUC__) || ((__STDC__ == 1L) && (__STDC_VERSION__ >= 199901L)) - // please note that we do not evaluate the return value of GetAttr() - // as some attributes (e.g. MUIA_Selected) always return FALSE, even - // when they are supported by the object. But setting b=0 right before - // the GetAttr() should catch the case when attr doesn't exist at all - #define xget(OBJ, ATTR) ({ULONG b=0; GetAttr(ATTR, OBJ, &b); b;}) -#endif - -HOOKPROTONH(GotoURLCode, ULONG, Object* htmlview, STRPTR *url) -{ - STRPTR target = (STRPTR)xget(htmlview, MUIA_HTMLview_Target); - - DoMethod(htmlview, MUIM_HTMLview_GotoURL, *url, target); - - return 0; -} -MakeStaticHook(GotoURLHook, GotoURLCode); - -CPPDISPATCHERGATE(_Dispatcher); -CPPDISPATCHERGATE(ScrollGroupDispatcher); -#ifdef USEMUISTRINGS -CPPDISPATCHERGATE(StringDispatcher); -#endif - -Object *BuildApp(void) -{ - static CONST_STRPTR classes[] = { "HTMLview.mcc", "TextEditor.mcc", "BetterString.mcc", NULL }; - Object *app, *win, *urlstring, *gauge, *htmlview, *vscroll, *hscroll, *infotext; - Object *alien, *mcp, *scalos, *sysspeed, *konsollen, *p96; - Object *searchstr; -// Object *htmlview2, *vscroll2, *hscroll2; - - ENTER(); - - if((app = ApplicationObject, - MUIA_Application_Author, "HTMLview.mcc Open Source Team", - MUIA_Application_Base, "HTMLview-Test", - MUIA_Application_Copyright, "(c) 2000-2007 HTMLview.mcc Open Source Team", - MUIA_Application_Description, "HTML-display custom class", - MUIA_Application_Title, "HTMLview.mcc", - MUIA_Application_Version, "$VER: HTMLview-Test V0.1 (" __DATE__ ")", - MUIA_Application_UsedClasses, classes, - - SubWindow, win = WindowObject, - MUIA_Window_ID, MAKE_ID('M','A','I','N'), - MUIA_Window_Title, "HTMLview-Demo", - //MUIA_Window_DefaultObject, htmlview, - MUIA_Window_UseBottomBorderScroller, TRUE, - MUIA_Window_UseRightBorderScroller, TRUE, - - WindowContents, VGroup, - Child, HGroup, - Child, alien = SimpleButton("Alien Design"), - Child, mcp = SimpleButton("MCP"), - Child, scalos = SimpleButton("Scalos"), - Child, sysspeed = SimpleButton("SysSpeed"), - Child, konsollen = SimpleButton("Konsollen"), - Child, p96 = SimpleButton("Picasso 96"), - End, - Child, urlstring = BetterStringObject, - StringFrame, - MUIA_CycleChain, TRUE, - MUIA_ControlChar, '\r', -// MUIA_String_Contents, "file://DH0:T/«98.07.13»/parcon/index.htm", -// MUIA_String_Contents, "file://Duff's:T/«98.07.05»/TestV.html", -// MUIA_String_Contents, "file://DH0:T/«98.05.29»/frames.html", -// MUIA_String_Contents, "file://Duff's:T/«98.06.27»/page.html", -// MUIA_String_Contents, "file://Duff's:T/«98.05.31»/aminew.html", -// MUIA_String_Contents, "file://Duff's:T/«98.05.19»/jubii.html", -// MUIA_String_Contents, "file://Duff's:T/«98.05.23»/download.html", -// MUIA_String_Contents, "file://Data:Homepage/daywatch/welcome.html", -// MUIA_String_Contents, "file://Duff's:T/«97.12.31»/applist.html", -// MUIA_String_Contents, "file://Duff's:WorkBench/Locale/Help/English/Developer/HTML4.0/cover.html#toc", -// MUIA_String_Contents, "file://progdir:testpages/main.html", -// MUIA_String_Contents, "file://Duff's:I'mOnline/AWeb3/Docs/html.html", -// MUIA_String_Contents, "file://Data:Homepage/htmlview/index.html", -// MUIA_String_Contents, "file://Data:Homepage/texteditor/index.html#Features", -// MUIA_String_Contents, "file://Duff's:Data/C-Sources/HTMLParser/Testpage.html", -// MUIA_String_Contents, "file://Duff's:T/«98.08.28»/alt_os.html", -// MUIA_String_Contents, "file://Data:Homepage/index.html", -// MUIA_String_Contents, "file://Data:Products/IProbe/IProbe.ReadMe", - MUIA_String_Contents, "file://Download:index.html", - End, - Child, gauge = GaugeObject, - GaugeFrame, - MUIA_Gauge_Current, 0, - MUIA_Gauge_Max, 100, - MUIA_Gauge_Horiz, TRUE, - MUIA_Gauge_InfoText, "(no document loaded)", - End, - -/* Child, HGroup, - - Child, ColGroup(2), - MUIA_Group_Spacing, 0, - Child, htmlview2 = (Object *)NewObject(HTMLviewClass->mcc_Class, NULL, - VirtualFrame, - End, - Child, vscroll2 = ScrollbarObject, - End, - Child, hscroll2 = ScrollbarObject, - MUIA_Group_Horiz, TRUE, - End, - Child, RectangleObject, - End, - End, - - Child, BalanceObject, End, -*/ -/* -#ifndef __amigaos4__ -#ifndef __MORPHOS__ -// Child, ScrollgroupObject, - Child, NewObject(ScrollGroupClass->mcc_Class, NULL, - MUIA_ScrollGroup_Contents, htmlview = (Object *)NewObject(ThisClass->mcc_Class, NULL, - End, - End, -#endif -#endif -*/ - - Child, ColGroup(2), - MUIA_Group_Spacing, 0, - Child, htmlview = (Object *)NewObject(ThisClass->mcc_Class, NULL, - VirtualFrame, - MUIA_HTMLview_DiscreteInput, FALSE, - MUIA_HTMLview_Contents, "

Hej med dig
test", -// MUIA_ContextMenu, TRUE, - End, - Child, vscroll = ScrollbarObject, - MUIA_Prop_UseWinBorder, MUIV_Prop_UseWinBorder_Right, - End, - Child, hscroll = ScrollbarObject, - MUIA_Prop_UseWinBorder, MUIV_Prop_UseWinBorder_Bottom, - MUIA_Group_Horiz, TRUE, - End, - Child, RectangleObject, - End, - End, - -// End, - - Child, infotext = InfoTextObject, - End, - - Child, searchstr = BetterStringObject, - StringFrame, - MUIA_CycleChain, TRUE, - MUIA_ControlChar, 's', - End, - - End, - End, - End)) - { - DoMethod(searchstr, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, htmlview, 3, MUIM_HTMLview_Search, MUIV_TriggerValue, MUIF_HTMLview_Search_Next); - - DoMethod(alien, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/Alien/index.html", NULL); - DoMethod(mcp, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/Alien/programs/mcp/index.html", NULL); - DoMethod(scalos, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/Alien/programs/scalos/index.html", NULL); - DoMethod(sysspeed, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/Alien/programs/sysspeed/index.html", NULL); - DoMethod(konsollen, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/Konsollen/index1.html", NULL); - DoMethod(p96, MUIM_Notify, MUIA_Pressed, FALSE, htmlview, 3, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.07.02»/~etk10317/Picasso96/Picasso96.html", NULL); - - DoMethod(urlstring, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, htmlview, 2, MUIM_HTMLview_GotoURL, MUIV_TriggerValue); - - DoMethod(htmlview, MUIM_Notify, MUIA_Virtgroup_Top, MUIV_EveryTime, vscroll, 3, MUIM_Set, MUIA_Prop_First, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_Height, MUIV_EveryTime, vscroll, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_Virtgroup_Height, MUIV_EveryTime, vscroll, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_Virtgroup_Left, MUIV_EveryTime, hscroll, 3, MUIM_Set, MUIA_Prop_First, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_Width, MUIV_EveryTime, hscroll, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_Virtgroup_Width, MUIV_EveryTime, hscroll, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue); - - DoMethod(htmlview, MUIM_Notify, MUIA_HTMLview_CurrentURL, MUIV_EveryTime, infotext, 3, MUIM_Set, MUIA_Text_Contents, MUIV_TriggerValue); -// DoMethod(htmlview, MUIM_Notify, MUIA_HTMLview_ClickedURL, MUIV_EveryTime, MUIV_Notify_Self, 2, MUIM_HTMLview_GotoURL, MUIV_TriggerValue); - DoMethod(htmlview, MUIM_Notify, MUIA_HTMLview_ClickedURL, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &GotoURLHook, MUIV_TriggerValue); - - DoMethod(vscroll, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, htmlview, 3, MUIM_Set, MUIA_Virtgroup_Top, MUIV_TriggerValue); - DoMethod(hscroll, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, htmlview, 3, MUIM_Set, MUIA_Virtgroup_Left, MUIV_TriggerValue); - -/* DoMethod(htmlview2, MUIM_Notify, MUIA_Virtgroup_Top, MUIV_EveryTime, vscroll2, 3, MUIM_Set, MUIA_Prop_First, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_Notify, MUIA_Height, MUIV_EveryTime, vscroll2, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_Notify, MUIA_Virtgroup_Height, MUIV_EveryTime, vscroll2, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_Notify, MUIA_Virtgroup_Left, MUIV_EveryTime, hscroll2, 3, MUIM_Set, MUIA_Prop_First, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_Notify, MUIA_Width, MUIV_EveryTime, hscroll2, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_Notify, MUIA_Virtgroup_Width, MUIV_EveryTime, hscroll2, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue); - DoMethod(vscroll2, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, htmlview2, 3, MUIM_Set, MUIA_Virtgroup_Top, MUIV_TriggerValue); - DoMethod(hscroll2, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime, htmlview2, 3, MUIM_Set, MUIA_Virtgroup_Left, MUIV_TriggerValue); - DoMethod(htmlview2, MUIM_HTMLview_GotoURL, "Data:Homepage/testpage.html"); -*/ -// set(htmlview, MUIA_HTMLview_Gauge, gauge); - - SetAttrs(vscroll, 0x804236ce, TRUE, TAG_DONE); - SetAttrs(hscroll, 0x804236ce, TRUE, TAG_DONE); - SetAttrs(win, MUIA_Window_DefaultObject, htmlview, TAG_DONE); - - DoMethod(win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit); -// set(app, MUIA_Application_Iconified, TRUE); - SetAttrs(win, MUIA_Window_Open, TRUE, TAG_DONE); -// DoMethod(htmlview, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.09.08»/Log.html", NULL); //Duff's:T/«98.05.31»/aminew.html", NULL); -// DoMethod(htmlview, MUIM_HTMLview_GotoURL, "file://Duff's:T/«98.11.13»/index.html"); -// DoMethod(htmlview, MUIM_HTMLview_GotoURL, "file://Data:Homepage - old/testpage.html"); -// DoMethod(htmlview, MUIM_HTMLview_GotoURL, "file://Duff's:Data/C-Sources/ImageRender/GIFAnims/AllAnims.HTML"); -// DoMethod(htmlview, MUIM_HTMLview_GotoURL, "file://Silvia:Homepage_Real/index.html", NULL); - } - - RETURN(app); - return(app); -} - -VOID MainLoop (Object *app) -{ - ULONG sigs; - - ENTER(); - - while((LONG)DoMethod(app, MUIM_Application_NewInput, &sigs) != MUIV_Application_ReturnID_Quit) - { - if(sigs) - { - sigs = Wait(sigs | SIGBREAKF_CTRL_C); - if(sigs & SIGBREAKF_CTRL_C) - break; - } - } - - LEAVE(); -} - -#if defined(__libnix__) -void *mempool; -#endif - -int main(void) -{ - kprintf("%s\n", __FUNCTION__); - _init(); - - #if defined(__libnix__) - mempool = CreatePool(MEMF_CLEAR | MEMF_SEM_PROTECTED, 12*1024, 6*1024); - #endif - - #if defined(__amigaos4__) - if((IntuitionBase = OpenLibrary("intuition.library", 38)) && - GETINTERFACE(IIntuition, struct IntuitionIFace*, IntuitionBase)) - if((GfxBase = OpenLibrary("graphics.library", 38)) && - GETINTERFACE(IGraphics, struct GraphicsIFace*, GfxBase)) - #else - if((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 38)) && - GETINTERFACE(IIntuition, struct IntuitionIFace*, IntuitionBase)) - if((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 38)) && - GETINTERFACE(IGraphics, struct GraphicsIFace*, GfxBase)) - #endif - if((UtilityBase = OpenLibrary("utility.library", 38)) && - GETINTERFACE(IUtility, struct UtilityIFace*, UtilityBase)) - if((LayersBase = OpenLibrary("layers.library", 36)) && - GETINTERFACE(ILayers, struct LayersIFace*, LayersBase)) - if((KeymapBase = OpenLibrary("keymap.library", 36)) && - GETINTERFACE(IKeymap, struct KeymapIFace*, KeymapBase)) - if((CxBase = OpenLibrary("commodities.library", 36)) && - GETINTERFACE(ICommodities, struct CommoditiesIFace*, CxBase)) - if((DiskfontBase = OpenLibrary("diskfont.library", 36)) && - GETINTERFACE(IDiskfont, struct DiskfontIFace*, DiskfontBase)) - if((DataTypesBase = OpenLibrary("datatypes.library", 36)) && - GETINTERFACE(IDataTypes, struct DataTypesIFace*, DataTypesBase)) - { - // open cybergraphics.library optional! - if((CyberGfxBase = OpenLibrary("cybergraphics.library", 40)) && - GETINTERFACE(ICyberGfx, struct CyberGfxIFace*, CyberGfxBase)) - { } - - #if defined(DEBUG) - SetupDebug(); - #endif - - ENTER(); - - if((MUIMasterBase = OpenLibrary("muimaster.library", MUIMASTER_VMIN)) && - GETINTERFACE(IMUIMaster, struct MUIMasterIFace*, MUIMasterBase)) - { - Object *app; - - ThisClass = MUI_CreateCustomClass(NULL, MUIC_Virtgroup, NULL, GetHTMLviewDataSize(), CPPDISPATCHERENTRY(_Dispatcher)); - ScrollGroupClass = MUI_CreateCustomClass(NULL, MUIC_Virtgroup, NULL, GetScrollGroupDataSize(), CPPDISPATCHERENTRY(ScrollGroupDispatcher)); - - if((app = BuildApp())) - { - MainLoop(app); - MUI_DisposeObject(app); - } - - MUI_DeleteCustomClass(ScrollGroupClass); - MUI_DeleteCustomClass(ThisClass); - } - - if(MUIMasterBase) - { - DROPINTERFACE(IMUIMaster); - CloseLibrary(MUIMasterBase); - MUIMasterBase = NULL; - } - - if(CyberGfxBase) - { - DROPINTERFACE(ICyberGfx); - CloseLibrary(CyberGfxBase); - CyberGfxBase = NULL; - } - - if(DataTypesBase) - { - DROPINTERFACE(IDataTypes); - CloseLibrary(DataTypesBase); - DataTypesBase = NULL; - } - - if(DiskfontBase) - { - DROPINTERFACE(IDiskfont); - CloseLibrary(DiskfontBase); - DiskfontBase = NULL; - } - - if(CxBase) - { - DROPINTERFACE(ICommodities); - CloseLibrary(CxBase); - CxBase = NULL; - } - - if(KeymapBase) - { - DROPINTERFACE(IKeymap); - CloseLibrary(KeymapBase); - KeymapBase = NULL; - } - - if(LayersBase) - { - DROPINTERFACE(ILayers); - CloseLibrary(LayersBase); - LayersBase = NULL; - } - - if(UtilityBase) - { - DROPINTERFACE(IUtility); - CloseLibrary(UtilityBase); - UtilityBase = NULL; - } - - if(GfxBase) - { - DROPINTERFACE(IGraphics); - CloseLibrary((struct Library *)GfxBase); - GfxBase = NULL; - } - - if(IntuitionBase) - { - DROPINTERFACE(IIntuition); - CloseLibrary((struct Library *)IntuitionBase); - IntuitionBase = NULL; - } - } - - _fini(); - - - RETURN(0); - return 0; -} diff --git a/mcc/ImageManager.cpp b/mcc/ImageManager.cpp index 6759a29..a41e060 100644 --- a/mcc/ImageManager.cpp +++ b/mcc/ImageManager.cpp @@ -792,8 +792,8 @@ Object *NewDecoderObjectA(UBYTE *buf,struct TagItem *attrs) if((cl = MakeClass(NULL, NULL, GetImageDecoderClass(decoders->Base), sizeof(DecoderData), 0L))) { #if defined(__amigaos3__) - cl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)ENTRY(DecoderDispatcher); - cl->cl_Dispatcher.h_Entry = (HOOKFUNC)HookEntry; + cl->cl_Dispatcher.h_SubEntry = (ULONG (*)())ENTRY(DecoderDispatcher); + cl->cl_Dispatcher.h_Entry = (ULONG (*)())HookEntry; cl->cl_Dispatcher.h_Data = 0; #else cl->cl_Dispatcher.h_SubEntry = 0; diff --git a/mcc/Makefile b/mcc/Makefile index a6ea900..ff5a974 100644 --- a/mcc/Makefile +++ b/mcc/Makefile @@ -1,467 +1,490 @@ -#/*************************************************************************** -# -# HTMLview.mcc - HTMLview MUI Custom Class -# Copyright (C) 1997-2000 Allan Odgaard -# Copyright (C) 2005-2007 by HTMLview.mcc Open Source Team -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# HTMLview class Support Site: http://www.sf.net/projects/htmlview-mcc/ -# -# $Id: rev.h,v 1.4 2005/04/11 03:04:38 tactica Exp $ -# -#***************************************************************************/ - -########################################################################### -# This makefile is a very generic one. It tries to identify both, the host -# and the target operating system for which YAM should be compiled. -# However, this auto-detection can be easily overridden by directly -# specifying an option on the commandline while calling 'make'. -# -# Example: -# -# # to explicitly compile for AmigaOS3 -# > make OS=os3 -# -# # to compile for AmigaOS4 but with debugging -# > make OS=os4 DEBUG= -# - -############################################# -# find out the HOST operating system -# on which this makefile is run -ifndef (HOST) - HOST = $(shell uname) - ifeq ($(HOST), AmigaOS) - ifeq ($(shell uname -m), powerpc) - HOST = AmigaOS4 - endif - ifeq ($(shell uname -m), ppc) - HOST = AmigaOS4 - endif - endif -endif - -############################################# -# now we find out the target OS for -# which we are going to compile YAM in case -# the caller didn't yet define OS himself -ifndef (OS) - ifeq ($(HOST), AmigaOS4) - OS = os4 - else - ifeq ($(HOST), AmigaOS) - OS = os3 - else - ifeq ($(HOST), MorphOS) - OS = mos - else - ifeq ($(HOST), Aros) - OS = aros - else - OS = os4 - endif - endif - endif - endif -endif - -############################################# -# define common commands we use in this -# makefile. Please note that each of them -# might be overridden on the commandline. - -# common commands -FLEX = flex -FC = flexcat -EXPR = expr -CHMOD = chmod -SED = sed -DATE = date -RM = rm -f -RMDIR = rm -rf -MKDIR = mkdir - -# override commands for native builds -ifeq ($(HOST), AmigaOS4) - # AmigaOS4 host - RM = delete force - RMDIR = delete force all - MKDIR = makedir - DATE = gdate -else -ifeq ($(HOST), AmigaOS) - # AmigaOS3 host - RM = delete force - RMDIR = delete force all - MKDIR = makedir -else -ifeq ($(HOST), MorphOS) - # MorphOS host - RM = delete force - RMDIR = delete force all - MKDIR = makedir -endif -endif -endif - -########################################################################### -# CPU and DEBUG can be defined outside, defaults to above -# using e.g. "make DEBUG= CPU=-mcpu=603e" produces optimized non-debug -# PPC-603e version -# -# OPTFLAGS are disabled by DEBUG normally! -# -# ignored warnings are: -# none - because we want to compile with -Wall all the time - -# Common Directories -OBJDIR = .obj_$(OS) -BINDIR = bin_$(OS) -LOCALE = locale - -# target definition -MCCTARGET = $(BINDIR)/HTMLview.mcc -TESTTARGET= $(BINDIR)/HTMLview-Test - -# Common compiler/linker flags -WARN = -W -Wall -Wwrite-strings -OPTFLAGS = -O3 -fomit-frame-pointer -funroll-loops -DEBUG = -DDEBUG -O0 -DEBUGSYM = -g -gstabs -CFLAGS = -I. -I../mcp -I../include $(CPU) $(WARN) $(OPTFLAGS) \ - $(DEBUG) $(DEBUGSYM) -c -LDFLAGS = $(CPU) $(DEBUGSYM) -LDLIBS = - -# different options per target OS -ifeq ($(OS), os4) - - ############################## - # AmigaOS4 - - # Compiler/link/strip commands - CC = ppc-amigaos-gcc - CXX = ppc-amigaos-g++ - STRIP = ppc-amigaos-strip - OBJDUMP = ppc-amigaos-objdump - - # Compiler/Linker flags - CRT = newlib - CPU = -mcpu=powerpc - WARN += -Wno-unused-parameter -Wno-narrowing -Wno-sign-compare - CFLAGS += -mcrt=$(CRT) -D__USE_INLINE__ -D__NEW_TIMEVAL_DEFINITION_USED__ \ - -D__USE_CLASSIC_MINTERM__ -Wa,-mregnames -DNO_PPCINLINE_STDARG - LDFLAGS += -mcrt=$(CRT) - - # additional object files required - M68KSTUBS = $(OBJDIR)/mccclass_68k.o - -else -ifeq ($(OS), os3) - - ############################## - # AmigaOS3 - - # Compiler/link/strip commands - CC = m68k-amigaos-gcc - CXX = m68k-amigaos-g++ - STRIP = m68k-amigaos-strip - OBJDUMP = m68k-amigaos-objdump - - # Compiler/Linker flags - CPU = -m68020-60 -msoft-float - WARN += -Wno-sign-compare - CFLAGS += -noixemul -DNO_INLINE_STDARG -D__amigaos3__ - LDFLAGS += -noixemul - LDLIBS += -ldebug -lmui - -else -ifeq ($(OS), mos) - - ############################## - # MorphOS - - # Compiler/link/strip commands - CC = ppc-morphos-gcc - CXX = ppc-morphos-g++ - STRIP = ppc-morphos-strip - OBJDUMP = ppc-morphos-objdump - - # Compiler/Linker flags - CPU = -mcpu=powerpc - CFLAGS += -noixemul -DNO_PPCINLINE_STDARG - LDFLAGS += -noixemul - LDLIBS += -ldebug - -else -ifeq ($(OS), aros) - - ############################## - # AROS - - # Compiler/link/strip commands - CC = i686-aros-gcc - CXX = i686-aros-g++ - STRIP = i686-aros-strip - OBJDUMP = i686-aros-objdump - - # Compiler/Linker flags - CPU = - -endif -endif -endif -endif - -########################################################################### -# Here starts all stuff that is common for all target platforms and -# hosts. - -MCCOBJS = \ - $(OBJDIR)/library.o \ - $(OBJDIR)/library_cpp.o \ - $(OBJDIR)/ctor_dtor.o \ - $(OBJDIR)/classes/AClass.o \ - $(OBJDIR)/classes/AreaClass.o \ - $(OBJDIR)/classes/AttrClass.o \ - $(OBJDIR)/classes/BackFillClass.o \ - $(OBJDIR)/classes/BaseClass.o \ - $(OBJDIR)/classes/BlockquoteClass.o \ - $(OBJDIR)/classes/BodyClass.o \ - $(OBJDIR)/classes/BrClass.o \ - $(OBJDIR)/classes/CommentClass.o \ - $(OBJDIR)/classes/DDClass.o \ - $(OBJDIR)/classes/DLClass.o \ - $(OBJDIR)/classes/DTClass.o \ - $(OBJDIR)/classes/DummyClass.o \ - $(OBJDIR)/classes/FontClass.o \ - $(OBJDIR)/classes/FontStyleClass.o \ - $(OBJDIR)/classes/FormClass.o \ - $(OBJDIR)/classes/FrameClass.o \ - $(OBJDIR)/classes/FramesetClass.o \ - $(OBJDIR)/classes/HRClass.o \ - $(OBJDIR)/classes/HostClass.o \ - $(OBJDIR)/classes/ImgClass.o \ - $(OBJDIR)/classes/InputClass.o \ - $(OBJDIR)/classes/IsIndexClass.o \ - $(OBJDIR)/classes/LIClass.o \ - $(OBJDIR)/classes/MapClass.o \ - $(OBJDIR)/classes/MetaClass.o \ - $(OBJDIR)/classes/NoFramesClass.o \ - $(OBJDIR)/classes/OLClass.o \ - $(OBJDIR)/classes/OptionClass.o \ - $(OBJDIR)/classes/PClass.o \ - $(OBJDIR)/classes/ScriptClass.o \ - $(OBJDIR)/classes/SelectClass.o \ - $(OBJDIR)/classes/SuperClass.o \ - $(OBJDIR)/classes/TDClass.o \ - $(OBJDIR)/classes/THClass.o \ - $(OBJDIR)/classes/TRClass.o \ - $(OBJDIR)/classes/TableClass.o \ - $(OBJDIR)/classes/TextAreaClass.o \ - $(OBJDIR)/classes/TextClass.o \ - $(OBJDIR)/classes/TitleClass.o \ - $(OBJDIR)/classes/TreeClass.o \ - $(OBJDIR)/classes/ULClass.o \ - $(OBJDIR)/AllocateColours.o \ - $(OBJDIR)/Animation.o \ - $(OBJDIR)/Classes.o \ - $(OBJDIR)/Colours.o \ - $(OBJDIR)/Config.o \ - $(OBJDIR)/Dispatcher.o \ - $(OBJDIR)/Entities.o \ - $(OBJDIR)/Forms.o \ - $(OBJDIR)/GetSetAttrs.o \ - $(OBJDIR)/HandleMUIEvent.o \ - $(OBJDIR)/IM_ColourManager.o \ - $(OBJDIR)/IM_Dither.o \ - $(OBJDIR)/IM_Output.o \ - $(OBJDIR)/IM_Render.o \ - $(OBJDIR)/IM_Scale.o \ - $(OBJDIR)/ImageManager.o \ - $(OBJDIR)/Layout.o \ - $(OBJDIR)/Mark.o \ - $(OBJDIR)/Memory.o \ - $(OBJDIR)/MinMax.o \ - $(OBJDIR)/ParseMessage.o \ - $(OBJDIR)/ParseThread.o \ - $(OBJDIR)/Render.o \ - $(OBJDIR)/ScanArgs.o \ - $(OBJDIR)/ScrollGroup.o \ - $(OBJDIR)/SharedData.o \ - $(OBJDIR)/TagInfo.o \ - $(OBJDIR)/TernaryTrees.o \ - $(OBJDIR)/URLHandling.o \ - $(OBJDIR)/StringClass.o \ - $(OBJDIR)/Debug.o - -TESTOBJS= $(OBJDIR)/HTMLview-Test.o \ - $(OBJDIR)/library_cpp.o \ - $(OBJDIR)/ctor_dtor.o \ - $(OBJDIR)/classes/AClass.o \ - $(OBJDIR)/classes/AreaClass.o \ - $(OBJDIR)/classes/AttrClass.o \ - $(OBJDIR)/classes/BackFillClass.o \ - $(OBJDIR)/classes/BaseClass.o \ - $(OBJDIR)/classes/BlockquoteClass.o \ - $(OBJDIR)/classes/BodyClass.o \ - $(OBJDIR)/classes/BrClass.o \ - $(OBJDIR)/classes/CommentClass.o \ - $(OBJDIR)/classes/DDClass.o \ - $(OBJDIR)/classes/DLClass.o \ - $(OBJDIR)/classes/DTClass.o \ - $(OBJDIR)/classes/DummyClass.o \ - $(OBJDIR)/classes/FontClass.o \ - $(OBJDIR)/classes/FontStyleClass.o \ - $(OBJDIR)/classes/FormClass.o \ - $(OBJDIR)/classes/FrameClass.o \ - $(OBJDIR)/classes/FramesetClass.o \ - $(OBJDIR)/classes/HRClass.o \ - $(OBJDIR)/classes/HostClass.o \ - $(OBJDIR)/classes/ImgClass.o \ - $(OBJDIR)/classes/InputClass.o \ - $(OBJDIR)/classes/IsIndexClass.o \ - $(OBJDIR)/classes/LIClass.o \ - $(OBJDIR)/classes/MapClass.o \ - $(OBJDIR)/classes/MetaClass.o \ - $(OBJDIR)/classes/NoFramesClass.o \ - $(OBJDIR)/classes/OLClass.o \ - $(OBJDIR)/classes/OptionClass.o \ - $(OBJDIR)/classes/PClass.o \ - $(OBJDIR)/classes/ScriptClass.o \ - $(OBJDIR)/classes/SelectClass.o \ - $(OBJDIR)/classes/SuperClass.o \ - $(OBJDIR)/classes/TDClass.o \ - $(OBJDIR)/classes/THClass.o \ - $(OBJDIR)/classes/TRClass.o \ - $(OBJDIR)/classes/TableClass.o \ - $(OBJDIR)/classes/TextAreaClass.o \ - $(OBJDIR)/classes/TextClass.o \ - $(OBJDIR)/classes/TitleClass.o \ - $(OBJDIR)/classes/TreeClass.o \ - $(OBJDIR)/classes/ULClass.o \ - $(OBJDIR)/AllocateColours.o \ - $(OBJDIR)/Animation.o \ - $(OBJDIR)/Classes.o \ - $(OBJDIR)/Colours.o \ - $(OBJDIR)/Config.o \ - $(OBJDIR)/Dispatcher.o \ - $(OBJDIR)/Entities.o \ - $(OBJDIR)/Forms.o \ - $(OBJDIR)/GetSetAttrs.o \ - $(OBJDIR)/HandleMUIEvent.o \ - $(OBJDIR)/IM_ColourManager.o \ - $(OBJDIR)/IM_Dither.o \ - $(OBJDIR)/IM_Output.o \ - $(OBJDIR)/IM_Render.o \ - $(OBJDIR)/IM_Scale.o \ - $(OBJDIR)/ImageManager.o \ - $(OBJDIR)/Layout.o \ - $(OBJDIR)/Mark.o \ - $(OBJDIR)/Memory.o \ - $(OBJDIR)/MinMax.o \ - $(OBJDIR)/ParseMessage.o \ - $(OBJDIR)/ParseThread.o \ - $(OBJDIR)/Render.o \ - $(OBJDIR)/ScanArgs.o \ - $(OBJDIR)/ScrollGroup.o \ - $(OBJDIR)/SharedData.o \ - $(OBJDIR)/TagInfo.o \ - $(OBJDIR)/TernaryTrees.o \ - $(OBJDIR)/URLHandling.o \ - $(OBJDIR)/StringClass.o \ - $(OBJDIR)/Debug.o - -ifeq ($(OS), os3) -MCCOBJS += \ - $(OBJDIR)/vastubs.o - -TESTOBJS += \ - $(OBJDIR)/vastubs.o -endif - -# available catalog translations -CATALOGS = $(LOCALE)/deutsch.catalog - -# - -all: $(BINDIR) $(OBJDIR) $(MCCTARGET) $(TESTTARGET) - -# make the object directories -$(OBJDIR): - @echo " MKDIR $@" - @$(MKDIR) $(OBJDIR) - @$(MKDIR) $(OBJDIR)/classes - -# make the binary directories -$(BINDIR): - @echo " MKDIR $@" - @$(MKDIR) $(BINDIR) - -# - -$(OBJDIR)/%.o: %.c - @echo " CC $<" - @$(CC) $(CFLAGS) $< -o $@ - -$(OBJDIR)/%.o: %.cpp - @echo " CXX $<" - @$(CXX) $(CFLAGS) $< -o $@ - -$(OBJDIR)/mccclass_68k.o: ../include/mccclass_68k.c - @echo " CC $<" - @$(CC) $(CFLAGS) $< -o $@ - -# - -$(MCCTARGET): $(M68KSTUBS) $(MCCOBJS) - @echo " LD $@" - @$(CXX) -nostartfiles $(LDFLAGS) -o $@.debug $(MCCOBJS) $(M68KSTUBS) $(LDLIBS) -Wl,-Map,$@.map - @$(STRIP) --preserve-dates -R.comment -R.sdata2 -S -o $@ $@.debug - -$(TESTTARGET): $(TESTOBJS) $(OBJDIR)/HTMLview-Test.o - @echo " LD $@" - @$(CXX) $(LDFLAGS) -o $@.debug $(TESTOBJS) $(LDLIBS) -Wl,-Map,$@.map - @$(STRIP) --preserve-dates -R.comment -R.sdata2 -S -o $@ $@.debug - -$(OBJDIR)/library.o: library.c ../include/mccinit.c \ - HTMLview_mcc.h private.h rev.h - -locale.h: locale.c -locale.c: locale/HTMLview_mcc.cd locale_c.sd locale_h.sd - @echo " GN $@" - @$(FC) locale/HTMLview_mcc.cd locale.h=locale_h.sd locale.c=locale_c.sd - -## CATALOG GENERATION ################# - -$(LOCALE)/%.catalog: $(LOCALE)/%.ct - @echo " FC $@" - @$(FC) $(LOCALE)/HTMLview_mcc.cd $< CATALOG $@ - -.IGNORE: $(CATALOGS) - -catalogs: $(CATALOGS) - - -# - -.PHONY: clean -clean: - -$(RM) $(MCCTARGET) $(MCCTARGET).debug $(MCCTARGET).map - -$(RM) $(TESTTARGET) $(TESTTARGET).debug $(TESTTARGET).map - -$(RM) $(MCCOBJS) $(TESTOBJS) $(M68KSTUBS) - -.PHONY: distclean -distclean: clean - -$(RM) locale.? - -$(RMDIR) $(OBJDIR) - -$(RMDIR) $(BINDIR) +#/*************************************************************************** +# +# HTMLview.mcc - HTMLview MUI Custom Class +# Copyright (C) 1997-2000 Allan Odgaard +# Copyright (C) 2005-2007 by HTMLview.mcc Open Source Team +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library 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 +# Lesser General Public License for more details. +# +# HTMLview class Support Site: http://www.sf.net/projects/htmlview-mcc/ +# +# $Id: rev.h,v 1.4 2005/04/11 03:04:38 tactica Exp $ +# +#***************************************************************************/ + +########################################################################### +# This makefile is a very generic one. It tries to identify both, the host +# and the target operating system for which YAM should be compiled. +# However, this auto-detection can be easily overridden by directly +# specifying an option on the commandline while calling 'make'. +# +# Example: +# +# # to explicitly compile for AmigaOS3 +# > make OS=os3 +# +# # to compile for AmigaOS4 but with debugging +# > make OS=os4 DEBUG= +# + +############################################# +# find out the HOST operating system +# on which this makefile is run +ifndef (HOST) + HOST = $(shell uname) + ifeq ($(HOST), AmigaOS) + ifeq ($(shell uname -m), powerpc) + HOST = AmigaOS4 + endif + ifeq ($(shell uname -m), ppc) + HOST = AmigaOS4 + endif + endif +endif + +############################################# +# now we find out the target OS for +# which we are going to compile YAM in case +# the caller didn't yet define OS himself +ifndef (OS) + ifeq ($(HOST), AmigaOS4) + OS = os4 + else + ifeq ($(HOST), AmigaOS) + OS = os3 + else + ifeq ($(HOST), MorphOS) + OS = mos + else + ifeq ($(HOST), Aros) + OS = aros + else + OS = os4 + endif + endif + endif + endif +endif + +############################################# +# define common commands we use in this +# makefile. Please note that each of them +# might be overridden on the commandline. + +# common commands +FLEX = flex +FC = flexcat +EXPR = expr +CHMOD = chmod +SED = sed +DATE = date +RM = rm -f +RMDIR = rm -rf +MKDIR = mkdir + +# override commands for native builds +ifeq ($(HOST), AmigaOS4) + # AmigaOS4 host + RM = delete force + RMDIR = delete force all + MKDIR = makedir + DATE = gdate +else +ifeq ($(HOST), AmigaOS) + # AmigaOS3 host + RM = delete force + RMDIR = delete force all + MKDIR = makedir +else +ifeq ($(HOST), MorphOS) + # MorphOS host + RM = delete force + RMDIR = delete force all + MKDIR = makedir +endif +endif +endif + +########################################################################### +# CPU and DEBUG can be defined outside, defaults to above +# using e.g. "make DEBUG= CPU=-mcpu=603e" produces optimized non-debug +# PPC-603e version +# +# OPTFLAGS are disabled by DEBUG normally! +# +# ignored warnings are: +# none - because we want to compile with -Wall all the time + +# Common Directories +OBJDIR = .obj_$(OS) +BINDIR = bin_$(OS) +LOCALE = locale + +# target definition +MCCTARGET = $(BINDIR)/HTMLview.mcc +TESTTARGET= $(BINDIR)/HTMLview-Test +SIMPLETARGET= $(BINDIR)/SimpleTest + +# Common compiler/linker flags +WARN = -W -Wall -Wwrite-strings +OPTFLAGS = -O3 -fomit-frame-pointer +DEBUG = +DEBUGSYM = + +ifneq ($(DEBUG),) + OPTFLAGS = -O0 + DEBUGSYM = -g -gstabs + CFLAGS = -I. -I../mcp -I../include $(CPU) $(WARN) $(OPTFLAGS) \ + -DDEBUG $(DEBUGSYM) -c +else + CFLAGS = -I. -I../mcp -I../include $(CPU) $(WARN) $(OPTFLAGS) \ + -DNDEBUG -c +endif +LDFLAGS = $(CPU) $(DEBUGSYM) +LDLIBS = + +# different options per target OS +ifeq ($(OS), os4) + + ############################## + # AmigaOS4 + + # Compiler/link/strip commands + CC = ppc-amigaos-gcc + CXX = ppc-amigaos-g++ + STRIP = ppc-amigaos-strip + OBJDUMP = ppc-amigaos-objdump + + # Compiler/Linker flags + CRT = newlib + CPU = -mcpu=powerpc + WARN += -Wno-unused-parameter -Wno-narrowing -Wno-sign-compare + CFLAGS += -mcrt=$(CRT) -D__USE_INLINE__ -D__NEW_TIMEVAL_DEFINITION_USED__ \ + -D__USE_CLASSIC_MINTERM__ -Wa,-mregnames -DNO_PPCINLINE_STDARG + LDFLAGS += -mcrt=$(CRT) + + # additional object files required + M68KSTUBS = $(OBJDIR)/mccclass_68k.o + +else +ifeq ($(OS), os3) + + ############################## + # AmigaOS3 + + # Compiler/link/strip commands + CC = m68k-amigaos-gcc + CXX = m68k-amigaos-g++ + STRIP = m68k-amigaos-strip + OBJDUMP = m68k-amigaos-objdump + + # Compiler/Linker flags + CPU = -m68020-60 -msoft-float + WARN += -Wno-sign-compare + CFLAGS += -noixemul -DNO_INLINE_STDARG -D__amigaos3__ + LDFLAGS += -noixemul -nostartfiles + LDLIBS += -lmui + ifneq ($(DEBUG),) + LDLIBS += -ldebug + endif + + +else +ifeq ($(OS), mos) + + ############################## + # MorphOS + + # Compiler/link/strip commands + CC = ppc-morphos-gcc + CXX = ppc-morphos-g++ + STRIP = ppc-morphos-strip + OBJDUMP = ppc-morphos-objdump + + # Compiler/Linker flags + CPU = -mcpu=powerpc + CFLAGS += -noixemul -DNO_PPCINLINE_STDARG + LDFLAGS += -noixemul + ifneq ($(DEBUG),) + LDLIBS += -ldebug + endif + + +else +ifeq ($(OS), aros) + + ############################## + # AROS + + # Compiler/link/strip commands + CC = i686-aros-gcc + CXX = i686-aros-g++ + STRIP = i686-aros-strip + OBJDUMP = i686-aros-objdump + + # Compiler/Linker flags + CPU = + +endif +endif +endif +endif + +########################################################################### +# Here starts all stuff that is common for all target platforms and +# hosts. + +MCCOBJS = \ + $(OBJDIR)/crtclasses_begin.o \ + $(OBJDIR)/library.o \ + $(OBJDIR)/library_cpp.o \ + $(OBJDIR)/ctor_dtor.o \ + $(OBJDIR)/classes/AClass.o \ + $(OBJDIR)/classes/AreaClass.o \ + $(OBJDIR)/classes/AttrClass.o \ + $(OBJDIR)/classes/BackFillClass.o \ + $(OBJDIR)/classes/BaseClass.o \ + $(OBJDIR)/classes/BlockquoteClass.o \ + $(OBJDIR)/classes/BodyClass.o \ + $(OBJDIR)/classes/BrClass.o \ + $(OBJDIR)/classes/CommentClass.o \ + $(OBJDIR)/classes/DDClass.o \ + $(OBJDIR)/classes/DLClass.o \ + $(OBJDIR)/classes/DTClass.o \ + $(OBJDIR)/classes/DummyClass.o \ + $(OBJDIR)/classes/FontClass.o \ + $(OBJDIR)/classes/FontStyleClass.o \ + $(OBJDIR)/classes/FormClass.o \ + $(OBJDIR)/classes/FrameClass.o \ + $(OBJDIR)/classes/FramesetClass.o \ + $(OBJDIR)/classes/HRClass.o \ + $(OBJDIR)/classes/HostClass.o \ + $(OBJDIR)/classes/ImgClass.o \ + $(OBJDIR)/classes/InputClass.o \ + $(OBJDIR)/classes/IsIndexClass.o \ + $(OBJDIR)/classes/LIClass.o \ + $(OBJDIR)/classes/MapClass.o \ + $(OBJDIR)/classes/MetaClass.o \ + $(OBJDIR)/classes/NoFramesClass.o \ + $(OBJDIR)/classes/OLClass.o \ + $(OBJDIR)/classes/OptionClass.o \ + $(OBJDIR)/classes/PClass.o \ + $(OBJDIR)/classes/ScriptClass.o \ + $(OBJDIR)/classes/SelectClass.o \ + $(OBJDIR)/classes/SuperClass.o \ + $(OBJDIR)/classes/TDClass.o \ + $(OBJDIR)/classes/THClass.o \ + $(OBJDIR)/classes/TRClass.o \ + $(OBJDIR)/classes/TableClass.o \ + $(OBJDIR)/classes/TextAreaClass.o \ + $(OBJDIR)/classes/TextClass.o \ + $(OBJDIR)/classes/TitleClass.o \ + $(OBJDIR)/classes/TreeClass.o \ + $(OBJDIR)/classes/ULClass.o \ + $(OBJDIR)/AllocateColours.o \ + $(OBJDIR)/Animation.o \ + $(OBJDIR)/Classes.o \ + $(OBJDIR)/Colours.o \ + $(OBJDIR)/Config.o \ + $(OBJDIR)/Dispatcher.o \ + $(OBJDIR)/Entities.o \ + $(OBJDIR)/Forms.o \ + $(OBJDIR)/GetSetAttrs.o \ + $(OBJDIR)/HandleMUIEvent.o \ + $(OBJDIR)/IM_ColourManager.o \ + $(OBJDIR)/IM_Dither.o \ + $(OBJDIR)/IM_Output.o \ + $(OBJDIR)/IM_Render.o \ + $(OBJDIR)/IM_Scale.o \ + $(OBJDIR)/ImageManager.o \ + $(OBJDIR)/Layout.o \ + $(OBJDIR)/Mark.o \ + $(OBJDIR)/Memory.o \ + $(OBJDIR)/MinMax.o \ + $(OBJDIR)/ParseMessage.o \ + $(OBJDIR)/ParseThread.o \ + $(OBJDIR)/Render.o \ + $(OBJDIR)/ScanArgs.o \ + $(OBJDIR)/ScrollGroup.o \ + $(OBJDIR)/SharedData.o \ + $(OBJDIR)/TagInfo.o \ + $(OBJDIR)/TernaryTrees.o \ + $(OBJDIR)/URLHandling.o \ + $(OBJDIR)/StringClass.o \ + $(OBJDIR)/Debug.o \ + $(OBJDIR)/crtclasses_end.o + +TESTOBJS= $(OBJDIR)/library_cpp.o \ + $(OBJDIR)/library_cpp.o \ + $(OBJDIR)/ctor_dtor.o \ + $(OBJDIR)/classes/AClass.o \ + $(OBJDIR)/classes/AreaClass.o \ + $(OBJDIR)/classes/AttrClass.o \ + $(OBJDIR)/classes/BackFillClass.o \ + $(OBJDIR)/classes/BaseClass.o \ + $(OBJDIR)/classes/BlockquoteClass.o \ + $(OBJDIR)/classes/BodyClass.o \ + $(OBJDIR)/classes/BrClass.o \ + $(OBJDIR)/classes/CommentClass.o \ + $(OBJDIR)/classes/DDClass.o \ + $(OBJDIR)/classes/DLClass.o \ + $(OBJDIR)/classes/DTClass.o \ + $(OBJDIR)/classes/DummyClass.o \ + $(OBJDIR)/classes/FontClass.o \ + $(OBJDIR)/classes/FontStyleClass.o \ + $(OBJDIR)/classes/FormClass.o \ + $(OBJDIR)/classes/FrameClass.o \ + $(OBJDIR)/classes/FramesetClass.o \ + $(OBJDIR)/classes/HRClass.o \ + $(OBJDIR)/classes/HostClass.o \ + $(OBJDIR)/classes/ImgClass.o \ + $(OBJDIR)/classes/InputClass.o \ + $(OBJDIR)/classes/IsIndexClass.o \ + $(OBJDIR)/classes/LIClass.o \ + $(OBJDIR)/classes/MapClass.o \ + $(OBJDIR)/classes/MetaClass.o \ + $(OBJDIR)/classes/NoFramesClass.o \ + $(OBJDIR)/classes/OLClass.o \ + $(OBJDIR)/classes/OptionClass.o \ + $(OBJDIR)/classes/PClass.o \ + $(OBJDIR)/classes/ScriptClass.o \ + $(OBJDIR)/classes/SelectClass.o \ + $(OBJDIR)/classes/SuperClass.o \ + $(OBJDIR)/classes/TDClass.o \ + $(OBJDIR)/classes/THClass.o \ + $(OBJDIR)/classes/TRClass.o \ + $(OBJDIR)/classes/TableClass.o \ + $(OBJDIR)/classes/TextAreaClass.o \ + $(OBJDIR)/classes/TextClass.o \ + $(OBJDIR)/classes/TitleClass.o \ + $(OBJDIR)/classes/TreeClass.o \ + $(OBJDIR)/classes/ULClass.o \ + $(OBJDIR)/AllocateColours.o \ + $(OBJDIR)/Animation.o \ + $(OBJDIR)/Classes.o \ + $(OBJDIR)/Colours.o \ + $(OBJDIR)/Config.o \ + $(OBJDIR)/Dispatcher.o \ + $(OBJDIR)/Entities.o \ + $(OBJDIR)/Forms.o \ + $(OBJDIR)/GetSetAttrs.o \ + $(OBJDIR)/HandleMUIEvent.o \ + $(OBJDIR)/IM_ColourManager.o \ + $(OBJDIR)/IM_Dither.o \ + $(OBJDIR)/IM_Output.o \ + $(OBJDIR)/IM_Render.o \ + $(OBJDIR)/IM_Scale.o \ + $(OBJDIR)/ImageManager.o \ + $(OBJDIR)/Layout.o \ + $(OBJDIR)/Mark.o \ + $(OBJDIR)/Memory.o \ + $(OBJDIR)/MinMax.o \ + $(OBJDIR)/ParseMessage.o \ + $(OBJDIR)/ParseThread.o \ + $(OBJDIR)/Render.o \ + $(OBJDIR)/ScanArgs.o \ + $(OBJDIR)/ScrollGroup.o \ + $(OBJDIR)/SharedData.o \ + $(OBJDIR)/TagInfo.o \ + $(OBJDIR)/TernaryTrees.o \ + $(OBJDIR)/URLHandling.o \ + $(OBJDIR)/StringClass.o \ + $(OBJDIR)/Debug.o + +ifeq ($(OS), os3) +MCCOBJS += \ + $(OBJDIR)/vastubs.o + +TESTOBJS += \ + $(OBJDIR)/vastubs.o +endif + +# available catalog translations +CATALOGS = $(LOCALE)/deutsch.catalog + +# + +all: $(BINDIR) $(OBJDIR) $(MCCTARGET) $(SIMPLETARGET) + +# make the object directories +$(OBJDIR): + @echo " MKDIR $@" + @$(MKDIR) $(OBJDIR) + @$(MKDIR) $(OBJDIR)/classes + +# make the binary directories +$(BINDIR): + @echo " MKDIR $@" + @$(MKDIR) $(BINDIR) + +# + +$(OBJDIR)/%.o: %.c + @echo " CC $<" + @$(CC) $(CFLAGS) $< -o $@ + +$(OBJDIR)/%.o: %.cpp + @echo " CXX $<" + @$(CXX) $(CFLAGS) $< -o $@ + +$(OBJDIR)/mccclass_68k.o: ../include/mccclass_68k.c + @echo " CC $<" + @$(CC) $(CFLAGS) $< -o $@ + +# + +# Link against all MCC objects EXCEPT library.o (globals conflict) +LIBOBJS = $(filter-out $(OBJDIR)/library.o $(OBJDIR)/crtclasses_begin.o $(OBJDIR)/crtclasses_end.o, $(MCCOBJS)) + + +$(SIMPLETARGET): $(OBJDIR)/SimpleTest.o + @echo " LD $@" + @$(CXX) $(filter-out -nostartfiles,$(LDFLAGS)) -o $@.debug $(OBJDIR)/SimpleTest.o $(LDLIBS) -ldebug -Wl,-Map,$@.map + @$(STRIP) --preserve-dates -R.comment -R.sdata2 -S -o $@ $@.debug + + +$(MCCTARGET) : $(MCCOBJS) + @echo " LD $@" + @$(CXX) $(LDFLAGS) -o $@.debug $(MCCOBJS) $(LDLIBS) -Wl,-Map,$@.map + @$(STRIP) --preserve-dates -R.comment -R.sdata2 -S -o $@ $@.debug + +$(OBJDIR)/library.o: library.c ../include/mccinit.c \ + HTMLview_mcc.h private.h rev.h + +locale.h: locale.c +locale.c: locale/HTMLview_mcc.cd locale_c.sd locale_h.sd + @echo " GN $@" + @$(FC) locale/HTMLview_mcc.cd locale.h=locale_h.sd locale.c=locale_c.sd + +## CATALOG GENERATION ################# + +$(LOCALE)/%.catalog: $(LOCALE)/%.ct + @echo " FC $@" + @$(FC) $(LOCALE)/HTMLview_mcc.cd $< CATALOG $@ + +.IGNORE: $(CATALOGS) + +catalogs: $(CATALOGS) + + +# + +.PHONY: clean +clean: + -$(RM) $(MCCTARGET) $(MCCTARGET).debug $(MCCTARGET).map + -$(RM) $(TESTTARGET) $(TESTTARGET).debug $(TESTTARGET).map + -$(RM) $(MCCOBJS) $(TESTOBJS) $(M68KSTUBS) + +.PHONY: distclean +distclean: clean + -$(RM) locale.? + -$(RMDIR) $(OBJDIR) + -$(RMDIR) $(BINDIR) diff --git a/mcc/Memory.cpp b/mcc/Memory.cpp index 967dee6..8e2f7ce 100644 --- a/mcc/Memory.cpp +++ b/mcc/Memory.cpp @@ -253,7 +253,10 @@ void FreeVecPooled(APTR pool, APTR mem) } #endif -CONSTRUCTOR(InitMem, 10) +extern "C" void kprintf(const char *fmt, ...); + +/* Called explicitly from _init() in ctor_dtor.c */ +extern "C" void InitMemoryPool(void) { #ifndef __MORPHOS__ #if defined(__amigaos4__) @@ -273,7 +276,8 @@ CONSTRUCTOR(InitMem, 10) #endif } -DESTRUCTOR(CleanupMem, 10) +/* Called explicitly from _fini() in ctor_dtor.c */ +extern "C" void CleanupMemoryPool(void) { if(MemoryPool) { diff --git a/mcc/SimpleTest.c b/mcc/SimpleTest.c new file mode 100644 index 0000000..1bfd74d --- /dev/null +++ b/mcc/SimpleTest.c @@ -0,0 +1,106 @@ + +#include +#include +#include +#include +#include +#include + +extern void kprintf(const char *fmt, ...); + +struct Library *MUIMasterBase; +struct IntuitionBase *IntuitionBase; +struct Library *UtilityBase; + +// Simple MUI macros if missing +#ifndef MUI_Set +#define MUI_Set(o,a,v) SetAttrs(o,a,v,TAG_DONE) +#endif +#ifndef MUI_GetVal +#define MUI_GetVal(o,a) ({ ULONG v; GetAttr(a,o,&v); v; }) +#endif + +int main(void) +{ + Object *app, *win, *html; + + IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39); + MUIMasterBase = OpenLibrary("muimaster.library", 19); + + if (!IntuitionBase || !MUIMasterBase) + { + kprintf("SimpleTest: Failed to open libraries\n"); + return 20; + } + + app = MUI_NewObject(MUIC_Application, + MUIA_Application_Title , "HTMLView Simple Test", + MUIA_Application_Version , "$VER: SimpleTest 1.0 (15.12.2025)", + MUIA_Application_SingleTask , TRUE, + MUIA_Application_Window , win = MUI_NewObject(MUIC_Window, + MUIA_Window_Title, "HTMLView Test Window", + MUIA_Window_RootObject, html = MUI_NewObject("HTMLview.mcc", + MUIA_Background, MUII_TextBack, + TAG_DONE), + TAG_DONE), + TAG_DONE); + + if (!app) + { + kprintf("SimpleTest: Failed to create Application object\n"); + } + else + { + SetAttrs(win, MUIA_Window_Open, TRUE, TAG_DONE); + + static const char *test_html = + "" + "

HTMLView Test

" + "

This is a bold paragraph.

" + "

This is an italic paragraph.

" + "

This is a link.

" + ""; + + // Correct ID for HTMLview contents + #define MUIA_HTMLview_Contents 0xad003005 + SetAttrs(html, MUIA_HTMLview_Contents, test_html, TAG_DONE); + + ULONG val = 0; + GetAttr(MUIA_Window_Open, win, &val); + if (val) + { + ULONG sigs = 0; + BOOL running = TRUE; + + DoMethod(win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, + app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit); + + while(running) + { + ULONG id = DoMethod(app, MUIM_Application_NewInput, &sigs); + + if (id == MUIV_Application_ReturnID_Quit) { + running = FALSE; + } + + if (running && sigs) { + ULONG got = Wait(sigs | SIGBREAKF_CTRL_C); + if (got & SIGBREAKF_CTRL_C) { + running = FALSE; + } + } + } + } + else + { + kprintf("SimpleTest: Window failed to open.\n"); + } + + MUI_DisposeObject(app); + } + + if (MUIMasterBase) CloseLibrary(MUIMasterBase); + if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); + + return 0; +} diff --git a/mcc/TernaryTrees.cpp b/mcc/TernaryTrees.cpp index 452f6eb..53f895f 100644 --- a/mcc/TernaryTrees.cpp +++ b/mcc/TernaryTrees.cpp @@ -37,20 +37,18 @@ TNode::TNode(CONST_STRPTR str, CONST_APTR data) TNode::~TNode () { delete Left; - if(SplitChar) - delete Middle; delete Right; } -struct TNode *TNode::TInsert(CONST_STRPTR str, CONST_APTR data) +struct TNode *TNode::STInsert(struct TNode *root, CONST_STRPTR str, CONST_APTR data) { - if (this) + if (root) { - if (*str < SplitChar) Left = Left->TInsert(str, data); - else if (*str > SplitChar) Right = Right->TInsert(str, data); - else if (SplitChar) Middle = Middle->TInsert(str+1, data); + if (*str < root->SplitChar) root->Left = STInsert(root->Left, str, data); + else if (*str > root->SplitChar) root->Right = STInsert(root->Right, str, data); + else if (root->SplitChar) root->Middle = STInsert(root->Middle, str+1, data); - return this; + return root; } else { diff --git a/mcc/TernaryTrees.h b/mcc/TernaryTrees.h index 5453738..a37ed15 100644 --- a/mcc/TernaryTrees.h +++ b/mcc/TernaryTrees.h @@ -28,7 +28,8 @@ struct TNode TNode(CONST_STRPTR str, CONST_APTR data); virtual ~TNode (); - struct TNode *TInsert(CONST_STRPTR str, CONST_APTR data); + // Refactored to static to safely handle NULL root + static struct TNode *STInsert(struct TNode *root, CONST_STRPTR str, CONST_APTR data); struct TNode *Left, *Right; union @@ -47,7 +48,7 @@ ULONG BinaryInsert (struct TNode *&tree, T *elements, ULONG from, ULONG to) { ULONG diff = (to-from) / 2; - tree = tree->TInsert(elements[from+diff].Name, elements[from+diff].GetData()); + tree = TNode::STInsert(tree, elements[from+diff].Name, elements[from+diff].GetData()); if (tree==NULL) return FALSE; if(from < to) diff --git a/mcc/crtclasses_begin.c b/mcc/crtclasses_begin.c new file mode 100644 index 0000000..9ef7484 --- /dev/null +++ b/mcc/crtclasses_begin.c @@ -0,0 +1,11 @@ +#include + +typedef void (*func_ptr)(void); + +/* + * The head of the constructor list. + * Initialized to -1 to indicate the "New Format" (or count sentinel). + * Placed at the very beginning of the .ctors section. + */ +func_ptr __CTOR_LIST__[1] __attribute__((used, section(".ctors"))) = { (func_ptr) -1 }; +func_ptr __DTOR_LIST__[1] __attribute__((used, section(".dtors"))) = { (func_ptr) -1 }; diff --git a/mcc/crtclasses_end.c b/mcc/crtclasses_end.c new file mode 100644 index 0000000..9640b07 --- /dev/null +++ b/mcc/crtclasses_end.c @@ -0,0 +1,11 @@ +#include + +typedef void (*func_ptr)(void); + +/* + * The tail of the constructor list. + * Initialized to 0 (NULL terminator). + * Placed at the very end of the .ctors section. + */ +func_ptr __CTOR_END__[1] __attribute__((used, section(".ctors"))) = { (func_ptr) 0 }; +func_ptr __DTOR_END__[1] __attribute__((used, section(".dtors"))) = { (func_ptr) 0 }; diff --git a/mcc/ctor_dtor.c b/mcc/ctor_dtor.c index 1cda3ea..9a50360 100644 --- a/mcc/ctor_dtor.c +++ b/mcc/ctor_dtor.c @@ -22,8 +22,10 @@ // borrowed from clib2 to be able to intermix C and C++ code with the AmigaOS3 g++ 2.95.3 +#include #include #include +#include #include #if defined(__amigaos4__) @@ -43,119 +45,72 @@ typedef void (*func_ptr)(void); /****************************************************************************/ -struct private_function -{ - func_ptr function; - int priority; -}; - -/****************************************************************************/ +// libnix handles init/exit via these symbols, which might be functions or lists depending on the startup code. +// In this shared library environment with -nostartfiles, the linker script or libnix setup seems to provide +// a code thunk (trampoline) at __INIT_LIST__, not a list of pointers. +// Therefore, we must CALL it, not iterate it. -extern func_ptr __INIT_LIST__[]; -extern func_ptr __EXIT_LIST__[]; - -/****************************************************************************/ +extern void __INIT_LIST__(void); +extern void __INIT_LIST__(void); +extern void __EXIT_LIST__(void); extern func_ptr __CTOR_LIST__[]; extern func_ptr __DTOR_LIST__[]; -/****************************************************************************/ - -static void sort_private_functions(struct private_function * base, size_t count) -{ - struct private_function * a; - struct private_function * b; - size_t i,j; - i = count - 2; +// void exit(int s) { (void)s; while(1); } - do - { - a = base; - - for(j = 0 ; j <= i ; j++) - { - b = a + 1; - - if(a->priority > b->priority) - { - struct private_function t; - - t = (*a); - (*a) = (*b); - (*b) = t; - } - - a = b; - } - } - while(i-- > 0); -} /****************************************************************************/ -/* Sort all the init and exit functions (private library constructors), then - invoke the init functions in descending order. */ +/* Safe iteration of null-terminated INIT list */ static void call_init_functions(void) { - LONG num_init_functions = (LONG)(__INIT_LIST__[0]) / 2; - LONG num_exit_functions = (LONG)(__EXIT_LIST__[0]) / 2; - - if(num_init_functions > 1) - sort_private_functions((struct private_function *)&__INIT_LIST__[1],num_init_functions); - - if(num_exit_functions > 1) - sort_private_functions((struct private_function *)&__EXIT_LIST__[1],num_exit_functions); - - if(num_init_functions > 0) - { - struct private_function * t = (struct private_function *)&__INIT_LIST__[1]; - LONG i,j; - - for(j = 0 ; j < num_init_functions ; j++) - { - i = num_init_functions - (j + 1); - - (*t[i].function)(); - } - } + /* __INIT_LIST__ is not valid in this environment (points to VTable). */ + /* Do nothing. */ } /****************************************************************************/ -/* Call all exit functions in ascending order; this assumes that the function - table was prepared by call_init_functions() above. */ +/* Safe iteration of null-terminated EXIT list */ static void call_exit_functions(void) { - LONG num_exit_functions = (LONG)(__EXIT_LIST__[0]) / 2; - - if(num_exit_functions > 0) - { - STATIC LONG j = 0; - - struct private_function * t = (struct private_function *)&__EXIT_LIST__[1]; - LONG i; - - while(j++ < num_exit_functions) - { - i = j - 1; - - (*t[i].function)(); - } - } + /* __EXIT_LIST__ is legacy/stabs. Not used. */ + // __EXIT_LIST__(); } /****************************************************************************/ static void call_constructors(void) { - ULONG num_ctors = (ULONG)__CTOR_LIST__[0]; - ULONG i; - - /* Call all constructors in reverse order */ - for(i = 0 ; i < num_ctors ; i++) + /* Handle both count-prefixed (Old GCC) and -1 terminated (New GCC) formats */ + if ((long)__CTOR_LIST__[0] == -1) { - __CTOR_LIST__[num_ctors - i](); + /* New format: -1, p1, p2, ... 0. Walk to end, then backwards. */ + ULONG i = 1; + while (__CTOR_LIST__[i]) i++; + + + /* i is now at the 0 terminator. Run backwards until index 1. */ + while (i > 1) { + i--; + if (__CTOR_LIST__[i]) { + __CTOR_LIST__[i](); + } + } + } + else + { + /* Old format: count, p1, p2... */ + ULONG num_ctors = (ULONG)__CTOR_LIST__[0]; + ULONG i; + + + /* Call all constructors in reverse order */ + for(i = 0 ; i < num_ctors ; i++) + { + __CTOR_LIST__[num_ctors - i](); + } } } @@ -163,13 +118,29 @@ static void call_constructors(void) static void call_destructors(void) { - ULONG num_dtors = (ULONG)__DTOR_LIST__[0]; - static ULONG i; - - /* Call all destructors in forward order */ - while(i++ < num_dtors) + if ((long)__DTOR_LIST__[0] == -1) { - __DTOR_LIST__[i](); + /* New format: -1, p1, p2... 0. Run forwards? + Destructors usually run in reverse of constructors? + Standard is: Constructors run End->Start. Destructors run Start->End. + Let's assume Start->End (1..n) for dtors. + */ + ULONG i = 1; + while (__DTOR_LIST__[i]) { + __DTOR_LIST__[i](); + i++; + } + } + else + { + ULONG num_dtors = (ULONG)__DTOR_LIST__[0]; + static ULONG i; /* Start at 0 */ + + /* Call all destructors in forward order */ + while(i++ < num_dtors) + { + __DTOR_LIST__[i](); + } } } #endif @@ -186,6 +157,14 @@ void _init(void) for(j = 0 ; j < num_ctors ; j++) __CTOR_LIST__[num_ctors - j](); #elif defined(__amigaos3__) + + /* Initialize memory pool BEFORE calling C++ constructors + This prevents crashes in constructors that use new/malloc */ + { + extern void InitMemoryPool(void); + InitMemoryPool(); + } + call_init_functions(); call_constructors(); #elif defined(__MORPHOS__) @@ -209,6 +188,12 @@ void _fini(void) #elif defined(__amigaos3__) call_destructors(); call_exit_functions(); + + /* Cleanup memory pool AFTER all C++ destructors run */ + { + extern void CleanupMemoryPool(void); + CleanupMemoryPool(); + } #elif defined(__MORPHOS__) run_destructors(); #endif diff --git a/mcc/library.c b/mcc/library.c index cb751a2..e992bbf 100644 --- a/mcc/library.c +++ b/mcc/library.c @@ -50,7 +50,7 @@ #define CLASSINIT #define CLASSEXPUNGE -#define MIN_STACKSIZE 8192 +//#define MIN_STACKSIZE 8192 struct Library *LayersBase = NULL; struct Library *KeymapBase = NULL; @@ -77,6 +77,9 @@ extern void _init(void); extern void _fini(void); extern ULONG GetHTMLviewDataSize(void); +/* Dummy exit for libnix linkage in shared library. Application links against standard CRT. */ +void exit(int s) { (void)s; while(1); } + CPPDISPATCHERGATE(_Dispatcher); CPPDISPATCHERGATE(ScrollGroupDispatcher); #ifdef USEMUISTRINGS diff --git a/mcc/private.h b/mcc/private.h index 6e60e87..e913617 100644 --- a/mcc/private.h +++ b/mcc/private.h @@ -23,6 +23,15 @@ #ifndef PRIVATE_H #define PRIVATE_H +/* Unconditional C-linkage declaration for debug logging in constructors */ +#if defined(__cplusplus) +extern "C" { +#endif +void kprintf(const char *fmt, ...); +#if defined(__cplusplus) +} +#endif + #ifndef _PROTO_INTUITION_H #include #endif @@ -186,17 +195,25 @@ struct HTMLviewData #else + + +/* Force pointers into .ctors section for our manual scan in ctor_dtor.c. + Add __saveds because these are called via pointer from _init/_fini and need global data access. + Wrap with logging to identify crashes. */ #define CONSTRUCTOR(name,pri) \ - asm(".stabs \"___INIT_LIST__\",22,0,0,___ctor_" #name); \ - asm(".stabs \"___INIT_LIST__\",20,0,0," #pri); \ - extern "C" VOID __ctor_##name##(VOID); \ - extern "C" VOID __ctor_##name##(VOID) + static void __real_ctor_##name(void); \ + static void __ctor_##name(void) __attribute__((saveds)); \ + static void (*__ptr_##name)(void) __attribute__((used, section(".ctors"))) = __ctor_##name; \ + static void __ctor_##name(void) { \ + __real_ctor_##name(); \ + } \ + static void __real_ctor_##name(void) + #define DESTRUCTOR(name,pri) \ - asm(".stabs \"___EXIT_LIST__\",22,0,0,___dtor_" #name); \ - asm(".stabs \"___EXIT_LIST__\",20,0,0," #pri); \ - extern "C" VOID __dtor_##name##(VOID); \ - extern "C" VOID __dtor_##name##(VOID) + static void __dtor_##name(void) __attribute__((saveds)); \ + static void (*__ptr_##name)(void) __attribute__((used, section(".dtors"))) = __dtor_##name; \ + static void __dtor_##name(void) #endif /* __amigaos4__ */ diff --git a/mcc/rev.h b/mcc/rev.h index 8e224d6..b653f9a 100644 --- a/mcc/rev.h +++ b/mcc/rev.h @@ -21,10 +21,10 @@ ***************************************************************************/ #define LIB_VERSION 13 -#define LIB_REVISION 4 +#define LIB_REVISION 5 -#define LIB_REV_STRING "13.4" -#define LIB_DATE "20.12.2007" +#define LIB_REV_STRING "13.5" +#define LIB_DATE "15.12.2025" #if defined(__PPC__) #if defined(__MORPHOS__) @@ -44,4 +44,4 @@ #define CPU "" #endif -#define LIB_COPYRIGHT "Copyright (C) 2005-2007 HTMLview.mcc Open Source Team" +#define LIB_COPYRIGHT "Copyright (C) 2005-2025 HTMLview.mcc Open Source Team" diff --git a/mcp/Makefile b/mcp/Makefile index b7f0580..3fefa87 100644 --- a/mcp/Makefile +++ b/mcp/Makefile @@ -134,11 +134,19 @@ PREFTARGET= $(BINDIR)/HTMLview-Prefs # Common compiler/linker flags WARN = -W -Wall -Wwrite-strings -OPTFLAGS = -O3 -fomit-frame-pointer -funroll-loops -DEBUG = -DDEBUG -O0 -DEBUGSYM = -gstabs -CFLAGS = -I. -I../mcc -I../include $(CPU) $(WARN) $(OPTFLAGS) \ - $(DEBUG) $(DEBUGSYM) -c +OPTFLAGS = -O3 -fomit-frame-pointer +DEBUG = +DEBUGSYM = + +ifneq ($(DEBUG),) + OPTFLAGS = -O0 + DEBUGSYM = -gstabs + CFLAGS = -I. -I../mcc -I../include $(CPU) $(WARN) $(OPTFLAGS) \ + -DDEBUG $(DEBUGSYM) -c +else + CFLAGS = -I. -I../mcc -I../include $(CPU) $(WARN) $(OPTFLAGS) \ + -DNDEBUG -c +endif LDFLAGS = $(CPU) $(DEBUGSYM) LDLIBS = -lm @@ -178,7 +186,10 @@ ifeq ($(OS), os3) CPU = -m68020-60 -msoft-float CFLAGS += -noixemul -DNO_INLINE_STDARG -DUSEHOTKEY -DUSEBETTERSTRING LDFLAGS += -noixemul - LDLIBS += -ldebug -lmui + LDLIBS += -lmui +ifneq ($(DEBUG),) + LDLIBS += -ldebug +endif else ifeq ($(OS), mos) @@ -195,7 +206,10 @@ ifeq ($(OS), mos) CPU = -mcpu=powerpc CFLAGS += -noixemul -DNO_PPCINLINE_STDARG LDFLAGS += -noixemul - LDLIBS += -ldebug + ifneq ($(DEBUG),) + LDLIBS += -ldebug + endif + else ifeq ($(OS), aros) @@ -235,7 +249,7 @@ PREFOBJS= $(OBJDIR)/locale.o \ $(OBJDIR)/Debug.o ifeq ($(OS), os3) -MCPOBJS += $(OBJDIR)/vastubs.o +MCPOBJS += $(OBJDIR)/vastubs.o $(OBJDIR)/exit_stub.o PREFOBJS += $(OBJDIR)/vastubs.o endif diff --git a/mcp/exit_stub.c b/mcp/exit_stub.c new file mode 100644 index 0000000..286e778 --- /dev/null +++ b/mcp/exit_stub.c @@ -0,0 +1,9 @@ +/* + * Dummy exit() to satisfy libnix linkage when -nostartfiles is used. + * We're a shared library/MUI class, we should never call exit(). + */ +void exit(int status) +{ + (void)status; + while(1); +} diff --git a/mcp/library.c b/mcp/library.c index 24d671e..6d0e949 100644 --- a/mcp/library.c +++ b/mcp/library.c @@ -45,6 +45,8 @@ #define SUPERCLASSP MUIC_Mccprefs #define INSTDATAP InstData_MCP +#define INSTDATAPSIZE sizeof(struct InstData_MCP) +#define gate__DispatcherP _DispatcherP #define USERLIBID CLASS " " LIB_REV_STRING CPU " (" LIB_DATE ") " LIB_COPYRIGHT #define MASTERVERSION 19 diff --git a/mcp/private.h b/mcp/private.h index d794747..70ce591 100644 --- a/mcp/private.h +++ b/mcp/private.h @@ -27,6 +27,18 @@ #include +#ifndef INSTDATAPSIZE +#define INSTDATAPSIZE sizeof(struct InstData_MCP) +#endif + +#ifndef SUPERCLASSP +#define SUPERCLASSP "Mccprefs.mcc" +#endif + +#ifndef gate__DispatcherP +#define gate__DispatcherP _DispatcherP +#endif + #ifdef __MORPHOS__ extern struct MUI_CustomClass *PicClass; #define PREFSIMAGEOBJECT \ diff --git a/mcp/rev.h b/mcp/rev.h index 8e224d6..b653f9a 100644 --- a/mcp/rev.h +++ b/mcp/rev.h @@ -21,10 +21,10 @@ ***************************************************************************/ #define LIB_VERSION 13 -#define LIB_REVISION 4 +#define LIB_REVISION 5 -#define LIB_REV_STRING "13.4" -#define LIB_DATE "20.12.2007" +#define LIB_REV_STRING "13.5" +#define LIB_DATE "15.12.2025" #if defined(__PPC__) #if defined(__MORPHOS__) @@ -44,4 +44,4 @@ #define CPU "" #endif -#define LIB_COPYRIGHT "Copyright (C) 2005-2007 HTMLview.mcc Open Source Team" +#define LIB_COPYRIGHT "Copyright (C) 2005-2025 HTMLview.mcc Open Source Team" diff --git a/mcp/vastubs.c b/mcp/vastubs.c index 811cb3a..7be51ba 100644 --- a/mcp/vastubs.c +++ b/mcp/vastubs.c @@ -1,3 +1,4 @@ + /*************************************************************************** HTMLview.mcc - HTMLview MUI Custom Class @@ -43,3 +44,19 @@ ULONG SetAttrs( APTR object, ULONG tag1, ... ) #error "VARGS stubs are only save on m68k systems!" #endif #endif + +#if defined(__amigaos3__) +// Added stubs for libnix/C++ init +// exit() is provided by exit_stub.o +void _init(void) { } +void _fini(void) { } + +#include +#include +void kprintf(const char *formatString, ...) +{ + // Stub for mcp: do nothing. + // We only need logs from the main mcc library. + (void)formatString; +} +#endif