Morphos codesets fixes and more

This commit is contained in:
George Sokianos 2024-02-23 21:11:13 +00:00
parent 6807a8e29a
commit a7971556d4
6 changed files with 111 additions and 19 deletions

View File

@ -9,17 +9,17 @@ LiteXL_OBJ := \
src/api/api.o src/api/dirmonitor.o \ src/api/api.o src/api/dirmonitor.o \
src/api/regex.o src/api/renderer.o src/api/system.o \ src/api/regex.o src/api/renderer.o src/api/system.o \
src/api/utf8.o src/platform/morphos.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 outfile := lite-xl
compiler := gcc compiler := ppc-morphos-gcc-11
cxxcompiler := g++ 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 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__ DFLAGS := -D__USE_INLINE__
CFLAGS := -Wall -Wwrite-strings -O2 -noixemul -g -std=gnu11 -fno-strict-aliasing 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 .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/api/dirmonitor/mos.o: src/api/dirmonitor/mos.c
src/platform/codesets.o: src/platform/codesets.c
release: clean LiteXL release: clean LiteXL
@echo "Creating release files..." @echo "Creating release files..."
@mkdir -p release/LiteXL2 @mkdir -p release/LiteXL2
@cp resources/amiga/* release/LiteXL2/ -r @cp -r resources/amiga/* release/LiteXL2/
@mv release/LiteXL2/LiteXL2.info release/ @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 changelog.md release/LiteXL2/
@cp $(outfile) release/LiteXL2/ @cp $(outfile) release/LiteXL2/
@strip release/LiteXL2/$(outfile) @strip release/LiteXL2/$(outfile)
@cp README.md release/LiteXL2/ @cp README.md release/LiteXL2/
@cp README_Amiga.md release/LiteXL2/ @cp README_Amiga.md release/LiteXL2/
@cp LICENSE release/LiteXL2/ @cp LICENSE release/LiteXL2/
@cp -r licenses release/LiteXL2/
@echo "Creating release archive..." @echo "Creating release archive..."
@lha -aeqr3 a LiteXL2_MOS.lha release/ @lha -aeqr3 a LiteXL2_MOS.lha release/
@echo "Clean release files..." @echo "Clean release files..."

View File

@ -239,6 +239,7 @@ https://git.walkero.gr/walkero/lite-xl/issues
in AmigaOS 4, with a more secure way in AmigaOS 4, with a more secure way
- Did a lot of code cleanup in sync with the upstream, and parts of code - Did a lot of code cleanup in sync with the upstream, and parts of code
that were left over that were left over
- Compiled with pcre2 10.42 (MorphOS version only)
### Fixed ### Fixed
- I did a lot of changes on path manipulation and usage, fixing scanning - I did a lot of changes on path manipulation and usage, fixing scanning

View File

@ -7,7 +7,7 @@ int luaopen_regex(lua_State *L);
int luaopen_dirmonitor(lua_State* L); int luaopen_dirmonitor(lua_State* L);
int luaopen_utf8extra(lua_State* L); int luaopen_utf8extra(lua_State* L);
#if defined(__amigaos4__) #if defined(__amigaos4__) || defined(__morphos__)
int luaopen_codesets(lua_State* L); int luaopen_codesets(lua_State* L);
#endif #endif
@ -18,7 +18,7 @@ static const luaL_Reg libs[] = {
// { "process", luaopen_process }, // { "process", luaopen_process },
{ "dirmonitor", luaopen_dirmonitor }, { "dirmonitor", luaopen_dirmonitor },
{ "utf8extra", luaopen_utf8extra }, { "utf8extra", luaopen_utf8extra },
#if defined(__amigaos4__) #if defined(__amigaos4__) || defined(__morphos__)
{ "codesetsextra", luaopen_codesets }, { "codesetsextra", luaopen_codesets },
#endif #endif
{ NULL, NULL } { NULL, NULL }
@ -29,4 +29,3 @@ void api_load_libs(lua_State *L) {
for (int i = 0; libs[i].name; i++) for (int i = 0; libs[i].name; i++)
luaL_requiref(L, libs[i].name, libs[i].func, 1); luaL_requiref(L, libs[i].name, libs[i].func, 1);
} }

View File

@ -25,6 +25,7 @@
static CONST_STRPTR stack USED = "$STACK:102400"; static CONST_STRPTR stack USED = "$STACK:102400";
static CONST_STRPTR version USED = VERSTAG; static CONST_STRPTR version USED = VERSTAG;
#elif defined(__morphos__) #elif defined(__morphos__)
#include "platform/codesets.h"
#include "platform/morphos.h" #include "platform/morphos.h"
unsigned long __stack = 1000000; unsigned long __stack = 1000000;
UBYTE VString[] = VERSTAG; UBYTE VString[] = VERSTAG;
@ -146,9 +147,11 @@ int main(int argc, char **argv) {
#if defined(__amigaos4__) || defined(__morphos__) #if defined(__amigaos4__) || defined(__morphos__)
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
#endif int libsOpened = OpenLibs();
#if defined(__amigaos4__) if (libsOpened != RETURN_OK)
OpenLibs(); {
return libsOpened;
}
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
@ -302,8 +305,8 @@ init_lua:
ren_free_window_resources(&window_renderer); ren_free_window_resources(&window_renderer);
lua_close(L); lua_close(L);
#if defined(__amigaos4__) #if defined(__amigaos4__) || defined(__morphos__)
CleanExit("JustExit"); CleanExit("FineExit");
#endif #endif
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -5,7 +5,7 @@
* Heavily inspired from the encoding plugin * Heavily inspired from the encoding plugin
* https://github.com/jgmdev/lite-xl-encoding * https://github.com/jgmdev/lite-xl-encoding
*/ */
#include <SDL2/SDL_stdinc.h> #include <SDL_stdinc.h>
#include <stdbool.h> #include <stdbool.h>
#include <lua.h> #include <lua.h>
@ -14,8 +14,14 @@
#include "codesets.h" #include "codesets.h"
#if defined(__amigaos4__)
struct Library *CodesetsBase = NULL; struct Library *CodesetsBase = NULL;
struct CodesetsIFace *ICodesets = NULL; struct CodesetsIFace *ICodesets = NULL;
#endif
#if defined(__morphos__)
struct Library *CharsetsBase = NULL;
#endif
typedef struct { typedef struct {
const char* charset; const char* charset;
@ -87,6 +93,7 @@ static const char* encoding_charset_from_bom(
// Lua methods for codesets // Lua methods for codesets
int Lcodesets_detect(lua_State *L) { int Lcodesets_detect(lua_State *L) {
#if defined(__amigaos4__)
const char* filename = luaL_checkstring(L, 1); const char* filename = luaL_checkstring(L, 1);
BPTR fileHandle = FOpen(filename, MODE_OLDFILE, 0); BPTR fileHandle = FOpen(filename, MODE_OLDFILE, 0);
@ -134,12 +141,25 @@ int Lcodesets_detect(lua_State *L) {
} }
return 1; return 1;
#endif
#if defined(__morphos__)
lua_pushstring(L, "could not detect the file encoding");
return 2;
#endif
} }
int Lcodesets_systemCodeset(lua_State *L) { int Lcodesets_systemCodeset(lua_State *L) {
#if defined(__amigaos4__)
struct codeset *systemCodeset; struct codeset *systemCodeset;
systemCodeset = CodesetsFindA(NULL, NULL); systemCodeset = CodesetsFindA(NULL, NULL);
lua_pushstring(L, systemCodeset->name); lua_pushstring(L, systemCodeset->name);
#endif
#if defined(__morphos__)
char buf[16];
GetSystemCharset(buf, 16);
lua_pushstring(L, buf);
#endif
return 1; return 1;
} }
@ -148,7 +168,13 @@ int Lcodesets_convert(lua_State *L) {
const char* to = luaL_checkstring(L, 1); const char* to = luaL_checkstring(L, 1);
const char* from = luaL_checkstring(L, 2); const char* from = luaL_checkstring(L, 2);
size_t text_len = 0; size_t text_len = 0;
#if defined(__amigaos4__)
const char* text = luaL_checklstring(L, 3, &text_len); const char* text = luaL_checklstring(L, 3, &text_len);
#endif
#if defined(__morphos__)
APTR text = luaL_checklstring(L, 3, &text_len);
#endif
/* conversion options */ /* conversion options */
bool strict = false; bool strict = false;
bool handle_to_bom = 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); encoding_charset_from_bom(text, text_len, &bom_len);
} }
#if defined(__amigaos4__)
char *output; char *output;
ULONG output_len; ULONG output_len;
struct codeset *srcCodeset;
struct codeset *destCodeset;
ULONG errNum = 0; ULONG errNum = 0;
struct codeset *srcCodeset;
struct codeset *destCodeset;
srcCodeset = CodesetsFind(from, CSA_FallbackToDefault, FALSE, TAG_DONE); srcCodeset = CodesetsFind(from, CSA_FallbackToDefault, FALSE, TAG_DONE);
// srcCodeset = CodesetsFindBest(CSA_Source, text, // srcCodeset = CodesetsFindBest(CSA_Source, text,
// CSA_ErrPtr, &errNum, // CSA_ErrPtr, &errNum,
@ -212,6 +239,39 @@ int Lcodesets_convert(lua_State *L) {
CSA_Source, text, CSA_Source, text,
CSA_DestLenPtr, &output_len, CSA_DestLenPtr, &output_len,
TAG_DONE); 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) // if (!output)
// { // {
// lua_pushnil(L); // lua_pushnil(L);
@ -251,12 +311,22 @@ int Lcodesets_convert(lua_State *L) {
} else if (!output) { } else if (!output) {
lua_pushnil(L); lua_pushnil(L);
lua_pushfstring(L, "failed converting from '%s' to '%s'", from, to); lua_pushfstring(L, "failed converting from '%s' to '%s'", from, to);
#if defined(__amigaos4__)
CodesetsFreeA(output, NULL); CodesetsFreeA(output, NULL);
#endif
#if defined(__morphos__)
free(output);
#endif
return 2; return 2;
} }
lua_pushlstring(L, output, output_len); lua_pushlstring(L, output, output_len);
#if defined(__amigaos4__)
CodesetsFreeA(output, NULL); CodesetsFreeA(output, NULL);
#endif
#if defined(__morphos__)
free(output);
#endif
return 1; return 1;
} }
@ -360,21 +430,32 @@ int luaopen_codesets (lua_State *L) {
int OpenLibs(void) int OpenLibs(void)
{ {
#if defined(__amigaos4__)
if ((CodesetsBase = OpenLibrary( "codesets.library", 6 ))) if ((CodesetsBase = OpenLibrary( "codesets.library", 6 )))
{ {
ICodesets = (struct CodesetsIFace *)GetInterface( CodesetsBase, "main", 1L, NULL ); ICodesets = (struct CodesetsIFace *)GetInterface( CodesetsBase, "main", 1L, NULL );
if(!ICodesets) return CleanExit("Can't open codesets.library Interface"); if(!ICodesets) return CleanExit("Can't open codesets.library Interface");
} }
else return CleanExit("Can't open codesets.library version 6"); 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; return RETURN_OK;
} }
int CleanExit(const char *str) int CleanExit(const char *str)
{ {
#if defined(__amigaos4__)
if(ICodesets) DropInterface((struct Interface *) ICodesets); if(ICodesets) DropInterface((struct Interface *) ICodesets);
if(CodesetsBase) CloseLibrary(CodesetsBase); 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); printf("Error::%s\n", str);
return RETURN_ERROR; return RETURN_ERROR;

View File

@ -3,10 +3,14 @@
#include <proto/dos.h> #include <proto/dos.h>
#include <proto/exec.h> #include <proto/exec.h>
#if defined(__amigaos4__)
#include <proto/codesets.h> #include <proto/codesets.h>
#endif
#if defined(__morphos__)
#include <proto/charsets.h>
#endif
int OpenLibs(void); int OpenLibs(void);
int CleanExit(const char *); int CleanExit(const char *);
#endif #endif