diff --git a/Makefile.mos b/Makefile.mos index 51c2bd16..ed7376a1 100644 --- a/Makefile.mos +++ b/Makefile.mos @@ -9,17 +9,17 @@ LiteXL_OBJ := \ src/api/api.o src/api/dirmonitor.o \ src/api/regex.o src/api/renderer.o src/api/system.o \ src/api/utf8.o src/platform/morphos.o \ - src/api/dirmonitor/mos.o + src/api/dirmonitor/mos.o src/platform/codesets.o outfile := lite-xl -compiler := gcc -cxxcompiler := g++ +compiler := ppc-morphos-gcc-11 +cxxcompiler := ppc-morphos-g++-11 INCPATH := -Isrc -Ilib/dmon -I/sdk/gg/usr/local/include/SDL2 -I/sdk/gg/usr/include/freetype -I/sdk/gg/usr/include/lua5.4 DFLAGS := -D__USE_INLINE__ CFLAGS := -Wall -Wwrite-strings -O2 -noixemul -g -std=gnu11 -fno-strict-aliasing -LFLAGS := -noixemul -lpcre2 -lSDL2 -llua54 -lagg -lfreetype -lm -lc -L/usr/local/lib +LFLAGS := -noixemul -lpcre2-8 -lSDL2 -llua54 -lagg -lfreetype -lm -lc -L/usr/local/lib .PHONY: LiteXL clean release @@ -63,18 +63,22 @@ src/api/utf8.o: src/api/utf8.c src/api/dirmonitor/mos.o: src/api/dirmonitor/mos.c +src/platform/codesets.o: src/platform/codesets.c + release: clean LiteXL @echo "Creating release files..." @mkdir -p release/LiteXL2 - @cp resources/amiga/* release/LiteXL2/ -r + @cp -r resources/amiga/* release/LiteXL2/ @mv release/LiteXL2/LiteXL2.info release/ - @cp data release/LiteXL2/ -r + @rm release/LiteXL2/AutoInstall + @cp -r data release/LiteXL2/ @cp changelog.md release/LiteXL2/ @cp $(outfile) release/LiteXL2/ @strip release/LiteXL2/$(outfile) @cp README.md release/LiteXL2/ @cp README_Amiga.md release/LiteXL2/ @cp LICENSE release/LiteXL2/ + @cp -r licenses release/LiteXL2/ @echo "Creating release archive..." @lha -aeqr3 a LiteXL2_MOS.lha release/ @echo "Clean release files..." diff --git a/README_Amiga.md b/README_Amiga.md index 0da124bc..4cdfc23d 100644 --- a/README_Amiga.md +++ b/README_Amiga.md @@ -239,6 +239,7 @@ https://git.walkero.gr/walkero/lite-xl/issues in AmigaOS 4, with a more secure way - Did a lot of code cleanup in sync with the upstream, and parts of code that were left over +- Compiled with pcre2 10.42 (MorphOS version only) ### Fixed - I did a lot of changes on path manipulation and usage, fixing scanning diff --git a/src/api/api.c b/src/api/api.c index 61828baf..bd22b9fa 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -7,7 +7,7 @@ int luaopen_regex(lua_State *L); int luaopen_dirmonitor(lua_State* L); int luaopen_utf8extra(lua_State* L); -#if defined(__amigaos4__) +#if defined(__amigaos4__) || defined(__morphos__) int luaopen_codesets(lua_State* L); #endif @@ -18,7 +18,7 @@ static const luaL_Reg libs[] = { // { "process", luaopen_process }, { "dirmonitor", luaopen_dirmonitor }, { "utf8extra", luaopen_utf8extra }, -#if defined(__amigaos4__) +#if defined(__amigaos4__) || defined(__morphos__) { "codesetsextra", luaopen_codesets }, #endif { NULL, NULL } @@ -29,4 +29,3 @@ void api_load_libs(lua_State *L) { for (int i = 0; libs[i].name; i++) luaL_requiref(L, libs[i].name, libs[i].func, 1); } - diff --git a/src/main.c b/src/main.c index fd41281a..ef5efd25 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,7 @@ static CONST_STRPTR stack USED = "$STACK:102400"; static CONST_STRPTR version USED = VERSTAG; #elif defined(__morphos__) + #include "platform/codesets.h" #include "platform/morphos.h" unsigned long __stack = 1000000; UBYTE VString[] = VERSTAG; @@ -146,9 +147,11 @@ int main(int argc, char **argv) { #if defined(__amigaos4__) || defined(__morphos__) setlocale(LC_ALL, "C"); -#endif -#if defined(__amigaos4__) - OpenLibs(); + int libsOpened = OpenLibs(); + if (libsOpened != RETURN_OK) + { + return libsOpened; + } #endif #ifndef _WIN32 @@ -302,8 +305,8 @@ init_lua: ren_free_window_resources(&window_renderer); lua_close(L); -#if defined(__amigaos4__) - CleanExit("JustExit"); +#if defined(__amigaos4__) || defined(__morphos__) + CleanExit("FineExit"); #endif return EXIT_SUCCESS; } diff --git a/src/platform/codesets.c b/src/platform/codesets.c index 8405e655..b957fef6 100644 --- a/src/platform/codesets.c +++ b/src/platform/codesets.c @@ -5,7 +5,7 @@ * Heavily inspired from the encoding plugin * https://github.com/jgmdev/lite-xl-encoding */ -#include +#include #include #include @@ -14,8 +14,14 @@ #include "codesets.h" +#if defined(__amigaos4__) struct Library *CodesetsBase = NULL; struct CodesetsIFace *ICodesets = NULL; +#endif + +#if defined(__morphos__) +struct Library *CharsetsBase = NULL; +#endif typedef struct { const char* charset; @@ -87,6 +93,7 @@ static const char* encoding_charset_from_bom( // Lua methods for codesets int Lcodesets_detect(lua_State *L) { +#if defined(__amigaos4__) const char* filename = luaL_checkstring(L, 1); BPTR fileHandle = FOpen(filename, MODE_OLDFILE, 0); @@ -134,12 +141,25 @@ int Lcodesets_detect(lua_State *L) { } return 1; +#endif + +#if defined(__morphos__) + lua_pushstring(L, "could not detect the file encoding"); + return 2; +#endif } int Lcodesets_systemCodeset(lua_State *L) { +#if defined(__amigaos4__) struct codeset *systemCodeset; systemCodeset = CodesetsFindA(NULL, NULL); lua_pushstring(L, systemCodeset->name); +#endif +#if defined(__morphos__) + char buf[16]; + GetSystemCharset(buf, 16); + lua_pushstring(L, buf); +#endif return 1; } @@ -148,7 +168,13 @@ int Lcodesets_convert(lua_State *L) { const char* to = luaL_checkstring(L, 1); const char* from = luaL_checkstring(L, 2); size_t text_len = 0; +#if defined(__amigaos4__) const char* text = luaL_checklstring(L, 3, &text_len); +#endif +#if defined(__morphos__) + APTR text = luaL_checklstring(L, 3, &text_len); +#endif + /* conversion options */ bool strict = false; bool handle_to_bom = false; @@ -182,12 +208,13 @@ int Lcodesets_convert(lua_State *L) { encoding_charset_from_bom(text, text_len, &bom_len); } +#if defined(__amigaos4__) char *output; ULONG output_len; - struct codeset *srcCodeset; - struct codeset *destCodeset; ULONG errNum = 0; + struct codeset *srcCodeset; + struct codeset *destCodeset; srcCodeset = CodesetsFind(from, CSA_FallbackToDefault, FALSE, TAG_DONE); // srcCodeset = CodesetsFindBest(CSA_Source, text, // CSA_ErrPtr, &errNum, @@ -212,6 +239,39 @@ int Lcodesets_convert(lua_State *L) { CSA_Source, text, CSA_DestLenPtr, &output_len, TAG_DONE); +#endif + +#if defined(__morphos__) + // LONG output_len = 0; + + ULONG fromMib = GetCharsetNumber(from, CSF_IANA_MIMENAME); + if (fromMib == 0) + fromMib = GetCharsetNumber(from, CSF_IANA_NAME); + if (fromMib == 0) + fromMib = GetCharsetNumber(from, CSF_IANA_ALIAS); + + ULONG toMib = GetCharsetNumber(to, CSF_IANA_MIMENAME); + if (toMib == 0) + toMib = GetCharsetNumber(to, CSF_IANA_NAME); + if (toMib == 0) + toMib = GetCharsetNumber(to, CSF_IANA_ALIAS); + + LONG output_len = GetByteSize((APTR)text, text_len, fromMib, toMib); + char *output = calloc(output_len, sizeof(char) + 1); + LONG dstEnc = 0; + struct TagItem tags[] = { { CST_DoNotTerminate, FALSE }, { CST_GetDestEncoding, &dstEnc }, { TAG_DONE, 0 } }; + LONG result = ConvertTagList((APTR)text, text_len, (APTR)output, output_len, fromMib, toMib, tags); + + if (result <= 0) + { + lua_pushfstring(L, "failed converting from '%s' to '%s'", from, to); + free(output); + return 2; + } +#endif + + + // if (!output) // { // lua_pushnil(L); @@ -251,12 +311,22 @@ int Lcodesets_convert(lua_State *L) { } else if (!output) { lua_pushnil(L); lua_pushfstring(L, "failed converting from '%s' to '%s'", from, to); +#if defined(__amigaos4__) CodesetsFreeA(output, NULL); +#endif +#if defined(__morphos__) + free(output); +#endif return 2; } lua_pushlstring(L, output, output_len); +#if defined(__amigaos4__) CodesetsFreeA(output, NULL); +#endif +#if defined(__morphos__) + free(output); +#endif return 1; } @@ -360,21 +430,32 @@ int luaopen_codesets (lua_State *L) { int OpenLibs(void) { +#if defined(__amigaos4__) if ((CodesetsBase = OpenLibrary( "codesets.library", 6 ))) { ICodesets = (struct CodesetsIFace *)GetInterface( CodesetsBase, "main", 1L, NULL ); if(!ICodesets) return CleanExit("Can't open codesets.library Interface"); } else return CleanExit("Can't open codesets.library version 6"); +#endif +#if defined(__morphos__) + if ((CharsetsBase = OpenLibrary( "charsets.library", 53 )) == NULL) + return CleanExit("Can't open charsets.library version 53"); +#endif return RETURN_OK; } int CleanExit(const char *str) { +#if defined(__amigaos4__) if(ICodesets) DropInterface((struct Interface *) ICodesets); if(CodesetsBase) CloseLibrary(CodesetsBase); +#endif +#if defined(__morphos__) + if(CharsetsBase) CloseLibrary(CharsetsBase); +#endif - if(strcmp(str, "JustExit")) + if(strcmp(str, "FineExit")) { printf("Error::%s\n", str); return RETURN_ERROR; diff --git a/src/platform/codesets.h b/src/platform/codesets.h index 99773dd7..c9434bce 100644 --- a/src/platform/codesets.h +++ b/src/platform/codesets.h @@ -3,10 +3,14 @@ #include #include +#if defined(__amigaos4__) #include +#endif +#if defined(__morphos__) +#include +#endif int OpenLibs(void); int CleanExit(const char *); #endif -