Subject: Re: Porting to AmigaOS4 thread by jabirulo on 2020/11/22 10:43:37
@Raziel
Ok, here is code "converted", dunnot if it will crash/GR or make your system burn 
#if defined(__amigaos4__) && defined(USE_SYSDIALOGS)
#include "backends/dialogs/amigaos/amigaos-dialogs.h"
#include "common/config-manager.h"
#include "common/encoding.h"
#include <proto/codesets.h>
//#include <libraries/codesets.h>
#include <proto/asl.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <cstring>
#include <cstdlib>
struct Library *CodesetsBase = NULL;
struct CodesetsIFace *ICodesets = NULL;
char *AmigaOSDialogManager::utf8ToLocal(char *in) {
if (!in) {
return strdup("");
}
CodesetsBase = IExec->OpenLibrary("codesets.library", 6);
if (CodesetsBase) {
ICodesets = (CodesetsIFace *)IExec->GetInterface(CodesetsBase, "main", 1L, NULL);
struct codeset *srcmib = ICodesets->CodesetsFind("ISO-8859-1", CSA_FallbackToDefault,FALSE, TAG_DONE);
//LONG dstmib = CSA_DestCodeset(NULL, 0);
struct codeset *dstmib = ICodesets->CodesetsFind("UTF-8", CSA_FallbackToDefault,FALSE, TAG_DONE);
//if (dstmib != CS_MIBENUM_INVALID) {
if(dstmib != NULL) {
//LONG dstlen = FSGetByteSize((APTR)in, -1, CS_MIBENUM_UTF_8, dstmib);
ULONG dstlen = ICodesets->CodesetsStrLen(in, TAG_END);
char *out = (char *)malloc(dstlen + 1);
if (out) {
if( (out=ICodesets->CodesetsConvertStr(CSA_SourceCodeset, srcmib,
CSA_DestCodeset, dstmib,
CSA_Source, in,
//CSA_DestLenPtr, &dstlen,
TAG_DONE)) != NULL) {
//if (ConvertTagList((APTR)in, -1, (APTR)out, -1, CS_MIBENUM_UTF_8, dstmib, NULL) != -1) {
IExec->DropInterface( (struct Interface *)ICodesets );
ICodesets = NULL;
IExec->CloseLibrary(CodesetsBase);
CodesetsBase = NULL;
return out;
}
free(out);
}
}
IExec->DropInterface( (struct Interface *)ICodesets );
ICodesets = NULL;
IExec->CloseLibrary(CodesetsBase);
CodesetsBase = NULL;
}
return strdup(in);
}
|