initial import
This commit is contained in:
commit
260b73a346
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
BUILDOPTS := --notest
|
||||||
|
|
||||||
|
export PATH := $(PATH):..
|
||||||
|
|
||||||
|
all: xconv.so
|
||||||
|
|
||||||
|
xconv.so: xconv.c
|
||||||
|
../build-jim-ext -I.. -L.. $(BUILDOPTS) $^ -lxconv
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o *.so
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* xconv.c -- A Jim C extension that uses libxconv to convert from
|
||||||
|
* ISO 6937 to UTF-8.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <jim.h>
|
||||||
|
#include <jim-config.h>
|
||||||
|
#include <xconv.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
Xconv_Cmd(Jim_Interp *j, int argc, Jim_Obj *const argv[])
|
||||||
|
{
|
||||||
|
const char *src, *dst;
|
||||||
|
size_t dstlen, len;
|
||||||
|
Jim_Obj *ret;
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
Jim_WrongNumArgs(j, 1, argv, "<ISO 6937 string>");
|
||||||
|
return JIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
src = Jim_GetString(argv[1], NULL);
|
||||||
|
dstlen = strlen(src) * 2;
|
||||||
|
dst = (char *)Jim_Alloc(dstlen + 1);
|
||||||
|
|
||||||
|
if ((len = xconv(src, dst, dstlen)))
|
||||||
|
{
|
||||||
|
#ifdef JIM_UTF8
|
||||||
|
int chars;
|
||||||
|
|
||||||
|
chars = utf8_strlen(dst, len);
|
||||||
|
ret = Jim_NewStringObjUtf8(j, dst, chars);
|
||||||
|
#else
|
||||||
|
ret = Jim_NewStringObjNoAlloc(j, dst, len);
|
||||||
|
#endif
|
||||||
|
Jim_SetResult(j, ret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Jim_Free(dst);
|
||||||
|
Jim_SetResult(j, argv[1]); // Increments ref count.
|
||||||
|
}
|
||||||
|
return JIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Jim_xconvInit(Jim_Interp *j)
|
||||||
|
{
|
||||||
|
Jim_CreateCommand(j, "xconv", Xconv_Cmd, NULL, NULL);
|
||||||
|
return JIM_OK;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue