Libs/iconv: Untied from Libc, export table added
Signed-off-by: Maxim Logaev <maxlogaev@proton.me>
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
if tup.getconfig("NO_GCC") ~= "" then return end
|
||||
tup.rule("iconv.c", "kos32-gcc -c -I../../../../contrib/sdk/sources/newlib/libc/include/ -fno-ident -Os -c -o %o %f " .. tup.getconfig("KPACK_CMD"), "iconv.obj")
|
||||
tup.rule("iconv.c", "kos32-gcc -D_KOLIBRI -Os -fno-ident -fno-leading-underscore -fno-pie -c -o %o %f && kos32-strip %o --strip-unneeded " .. tup.getconfig("KPACK_CMD"), "iconv.obj")
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifdef _KOLIBRI
|
||||
#include "libc_stub.h"
|
||||
#else
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
typedef int conv_t;
|
||||
typedef unsigned int ucs4_t;
|
||||
@@ -39,6 +43,7 @@ typedef int iconv_t;
|
||||
|
||||
int encoding(const char *someencoding) {
|
||||
|
||||
#if 0
|
||||
char *what = strdup(someencoding);
|
||||
/* Ignore //TRANSLIT or //IGNORE for now. */
|
||||
int i;
|
||||
@@ -48,6 +53,9 @@ int encoding(const char *someencoding) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
const char *what = someencoding;
|
||||
#endif
|
||||
|
||||
if (!strcasecmp(what,"CP866")) return CP866;
|
||||
if (!strcasecmp(what,"CP1251")) return CP1251;
|
||||
@@ -190,6 +198,23 @@ size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
|
||||
return count1;
|
||||
}
|
||||
|
||||
char *iconv_strerr(void)
|
||||
{
|
||||
switch (errno)
|
||||
{
|
||||
case 0:
|
||||
return "Success";
|
||||
case EINVAL:
|
||||
return "Invalid argument";
|
||||
case EILSEQ:
|
||||
return "Illegal byte sequence";
|
||||
case E2BIG:
|
||||
return "Arg list too long";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
/* int main() */
|
||||
/* { */
|
||||
/* char *s;// ="вертолет"; */
|
||||
@@ -248,22 +273,26 @@ size_t iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
|
||||
/* //for (;s<s+strlen(s);s++) {cp866_mbtowc (0, &pwc, s, 1);printf("%c=%u\n",*s,pwc);} */
|
||||
/* } */
|
||||
|
||||
/* typedef struct */
|
||||
/* { */
|
||||
/* char *name; */
|
||||
/* void *f; */
|
||||
/* } export_t; */
|
||||
#ifdef _KOLIBRI
|
||||
|
||||
/* char szStart[] = "START"; */
|
||||
/* char szVersion[] = "version"; */
|
||||
/* char sziconv_open[] = "iconv_open"; */
|
||||
/* char sziconv[] = "iconv"; */
|
||||
typedef struct {
|
||||
char *name;
|
||||
void *f;
|
||||
} export_t;
|
||||
|
||||
/* export_t EXPORTS[] __asm__("EXPORTS") = */
|
||||
/* { */
|
||||
/* { szStart, (void*)0x0 }, */
|
||||
/* { szVersion, (void*)0x00010001 }, */
|
||||
/* { sziconv_open, iconv_open }, */
|
||||
/* { sziconv, iconv }, */
|
||||
/* { NULL, NULL }, */
|
||||
/* }; */
|
||||
char szStart[] = "START";
|
||||
char szVersion[] = "version";
|
||||
char sziconv_open[] = "iconv_open";
|
||||
char sziconv[] = "iconv";
|
||||
char sziconv_err[] = "iconv_strerr";
|
||||
|
||||
export_t EXPORTS[] = {
|
||||
{ szStart, (void*)0x0 },
|
||||
{ szVersion, (void*)0x00010001 },
|
||||
{ sziconv_open, iconv_open },
|
||||
{ sziconv, iconv },
|
||||
{ sziconv_err, iconv_strerr },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
32
programs/develop/libraries/iconv/libc_stub.h
Normal file
32
programs/develop/libraries/iconv/libc_stub.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _LIBC_STUB_
|
||||
#define _LIBC_STUB_
|
||||
|
||||
#define NULL (void*)0
|
||||
|
||||
static int errno = 0;
|
||||
|
||||
#define EINVAL 1 /* Invalid argument */
|
||||
#define EILSEQ 2 /* Illegal byte sequence */
|
||||
#define E2BIG 3 /* Arg list too long */
|
||||
|
||||
typedef unsigned long size_t;
|
||||
|
||||
static inline int isupper(int c)
|
||||
{
|
||||
return (unsigned)c-'A' < 26;
|
||||
}
|
||||
|
||||
static inline int tolower(int c)
|
||||
{
|
||||
if (isupper(c)) return c | 32;
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline int strcasecmp(const char *_l, const char *_r)
|
||||
{
|
||||
const unsigned char *l=(unsigned char*)_l, *r=(unsigned char*)_r;
|
||||
for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++);
|
||||
return tolower(*l) - tolower(*r);
|
||||
}
|
||||
|
||||
#endif // _LIBC_STUB_
|
||||
Reference in New Issue
Block a user