Browse Source

xutf8 files code conformance:

o C files containing C++ "//" comments -> C style "/* */" comments
    o Converted unintended doxygen style comments to regular C comments
    o FLTK brace/indent coding standard conformance
    o Tested linux + sgi
    o Avoided mods to xutf8/lcUniConv [libiconv/FSF code]
      to avoid unwanted diffs with future updates of that lib
      as per Fabien's fltk.dev request 03/14/09.
      (Those files already compliant anyway)



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6698 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Greg Ercolano 16 years ago
parent
commit
6cbde8909b
  1. 180
      src/xutf8/case.c
  2. 74
      src/xutf8/is_right2left.c
  3. 109
      src/xutf8/is_spacing.c
  4. 6
      src/xutf8/keysym2Ucs.c
  5. 377
      src/xutf8/test.c
  6. 285
      src/xutf8/test2.c
  7. 13
      src/xutf8/ucs2fontmap.c
  8. 647
      src/xutf8/utf8Input.c
  9. 317
      src/xutf8/utf8Utils.c
  10. 1501
      src/xutf8/utf8Wrap.c
  11. 264
      src/xutf8/utils/conv_gen.c
  12. 260
      src/xutf8/utils/convert_map.c
  13. 179
      src/xutf8/utils/create_table.c
  14. 54
      src/xutf8/utils/euc_tw.c

180
src/xutf8/case.c

@ -30,104 +30,96 @@ @@ -30,104 +30,96 @@
#include "headers/case.h"
#include <stdlib.h>
int
XUtf8Tolower(
int ucs)
{
int ret;
if (ucs <= 0x02B6) {
if (ucs >= 0x0041) {
ret = ucs_table_0041[ucs - 0x0041];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x0556) {
if (ucs >= 0x0386) {
ret = ucs_table_0386[ucs - 0x0386];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x10C5) {
if (ucs >= 0x10A0) {
ret = ucs_table_10A0[ucs - 0x10A0];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x1FFC) {
if (ucs >= 0x1E00) {
ret = ucs_table_1E00[ucs - 0x1E00];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x2133) {
if (ucs >= 0x2102) {
ret = ucs_table_2102[ucs - 0x2102];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x24CF) {
if (ucs >= 0x24B6) {
ret = ucs_table_24B6[ucs - 0x24B6];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x33CE) {
if (ucs >= 0x33CE) {
ret = ucs_table_33CE[ucs - 0x33CE];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0xFF3A) {
if (ucs >= 0xFF21) {
ret = ucs_table_FF21[ucs - 0xFF21];
if (ret > 0) return ret;
}
return ucs;
}
return ucs;
XUtf8Tolower(int ucs) {
int ret;
if (ucs <= 0x02B6) {
if (ucs >= 0x0041) {
ret = ucs_table_0041[ucs - 0x0041];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x0556) {
if (ucs >= 0x0386) {
ret = ucs_table_0386[ucs - 0x0386];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x10C5) {
if (ucs >= 0x10A0) {
ret = ucs_table_10A0[ucs - 0x10A0];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x1FFC) {
if (ucs >= 0x1E00) {
ret = ucs_table_1E00[ucs - 0x1E00];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x2133) {
if (ucs >= 0x2102) {
ret = ucs_table_2102[ucs - 0x2102];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x24CF) {
if (ucs >= 0x24B6) {
ret = ucs_table_24B6[ucs - 0x24B6];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0x33CE) {
if (ucs >= 0x33CE) {
ret = ucs_table_33CE[ucs - 0x33CE];
if (ret > 0) return ret;
}
return ucs;
}
if (ucs <= 0xFF3A) {
if (ucs >= 0xFF21) {
ret = ucs_table_FF21[ucs - 0xFF21];
if (ret > 0) return ret;
}
return ucs;
}
return ucs;
}
int
XUtf8Toupper(
int ucs)
{
int i;
static unsigned short *table = NULL;
if (!table) {
table = (unsigned short*) malloc(
sizeof(unsigned short) * 0x10000);
for (i = 0; i < 0x10000; i++) {
table[i] = (unsigned short) i;
}
for (i = 0; i < 0x10000; i++) {
int l;
l = XUtf8Tolower(i);
if (l != i) table[l] = (unsigned short) i;
}
}
if (ucs >= 0x10000 || ucs < 0) return ucs;
return table[ucs];
XUtf8Toupper(int ucs) {
int i;
static unsigned short *table = NULL;
if (!table) {
table = (unsigned short*) malloc(sizeof(unsigned short) * 0x10000);
for (i = 0; i < 0x10000; i++) {
table[i] = (unsigned short) i;
}
for (i = 0; i < 0x10000; i++) {
int l;
l = XUtf8Tolower(i);
if (l != i) table[l] = (unsigned short) i;
}
}
if (ucs >= 0x10000 || ucs < 0) return ucs;
return table[ucs];
}
/*
* End of "$Id$".
*/
* End of "$Id$".
*/

74
src/xutf8/is_right2left.c

@ -28,57 +28,55 @@ @@ -28,57 +28,55 @@
*/
unsigned short
XUtf8IsRightToLeft(
unsigned int ucs)
{
XUtf8IsRightToLeft(unsigned int ucs) {
#if 0
/* for debug only */
if (ucs <= 0x005A) {
if (ucs >= 0x0041) return 1;
return 0;
}
/* for debug only */
if (ucs <= 0x005A) {
if (ucs >= 0x0041) return 1;
return 0;
}
#endif
/* HEBREW */
if (ucs <= 0x05F4) {
if (ucs >= 0x0591) return 1;
return 0;
}
/* HEBREW */
if (ucs <= 0x05F4) {
if (ucs >= 0x0591) return 1;
return 0;
}
/* ARABIC */
if (ucs <= 0x06ED) {
if (ucs >= 0x060C) return 1;
return 0;
}
/* ARABIC */
if (ucs <= 0x06ED) {
if (ucs >= 0x060C) return 1;
return 0;
}
if (ucs <= 0x06F9) {
if (ucs >= 0x06F0) return 1;
return 0;
}
if (ucs <= 0x06F9) {
if (ucs >= 0x06F0) return 1;
return 0;
}
if (ucs == 0x200F) return 1;
if (ucs == 0x200F) return 1;
if (ucs == 0x202B) return 1;
if (ucs == 0x202B) return 1;
if (ucs == 0x202E) return 1;
if (ucs == 0x202E) return 1;
if (ucs <= 0xFB4F) {
if (ucs >= 0xFB1E) return 1;
return 0;
}
if (ucs <= 0xFB4F) {
if (ucs >= 0xFB1E) return 1;
return 0;
}
if (ucs <= 0xFDFB) {
if (ucs >= 0xFB50) return 1;
return 0;
}
if (ucs <= 0xFDFB) {
if (ucs >= 0xFB50) return 1;
return 0;
}
if (ucs <= 0xFEFC) {
if (ucs >= 0xFE70) return 1;
return 0;
}
if (ucs <= 0xFEFC) {
if (ucs >= 0xFE70) return 1;
return 0;
}
return 0;
return 0;
}
/*

109
src/xutf8/is_spacing.c

@ -29,63 +29,60 @@ @@ -29,63 +29,60 @@
#include "headers/spacing.h"
unsigned short
XUtf8IsNonSpacing(
unsigned int ucs)
{
if (ucs <= 0x0361) {
if (ucs >= 0x0300) return ucs_table_0300[ucs - 0x0300];
return 0;
}
if (ucs <= 0x0486) {
if (ucs >= 0x0483) return ucs_table_0483[ucs - 0x0483];
return 0;
}
if (ucs <= 0x05C4) {
if (ucs >= 0x0591) return ucs_table_0591[ucs - 0x0591];
return 0;
}
if (ucs <= 0x06ED) {
if (ucs >= 0x064B) return ucs_table_064B[ucs - 0x064B];
return 0;
}
if (ucs <= 0x0D4D) {
if (ucs >= 0x0901) return ucs_table_0901[ucs - 0x0901];
return 0;
}
if (ucs <= 0x0FB9) {
if (ucs >= 0x0E31) return ucs_table_0E31[ucs - 0x0E31];
return 0;
}
if (ucs <= 0x20E1) {
if (ucs >= 0x20D0) return ucs_table_20D0[ucs - 0x20D0];
return 0;
}
if (ucs <= 0x309A) {
if (ucs >= 0x302A) return ucs_table_302A[ucs - 0x302A];
return 0;
}
if (ucs <= 0xFB1E) {
if (ucs >= 0xFB1E) return ucs_table_FB1E[ucs - 0xFB1E];
return 0;
}
if (ucs <= 0xFE23) {
if (ucs >= 0xFE20) return ucs_table_FE20[ucs - 0xFE20];
return 0;
}
return 0;
XUtf8IsNonSpacing(unsigned int ucs) {
if (ucs <= 0x0361) {
if (ucs >= 0x0300) return ucs_table_0300[ucs - 0x0300];
return 0;
}
if (ucs <= 0x0486) {
if (ucs >= 0x0483) return ucs_table_0483[ucs - 0x0483];
return 0;
}
if (ucs <= 0x05C4) {
if (ucs >= 0x0591) return ucs_table_0591[ucs - 0x0591];
return 0;
}
if (ucs <= 0x06ED) {
if (ucs >= 0x064B) return ucs_table_064B[ucs - 0x064B];
return 0;
}
if (ucs <= 0x0D4D) {
if (ucs >= 0x0901) return ucs_table_0901[ucs - 0x0901];
return 0;
}
if (ucs <= 0x0FB9) {
if (ucs >= 0x0E31) return ucs_table_0E31[ucs - 0x0E31];
return 0;
}
if (ucs <= 0x20E1) {
if (ucs >= 0x20D0) return ucs_table_20D0[ucs - 0x20D0];
return 0;
}
if (ucs <= 0x309A) {
if (ucs >= 0x302A) return ucs_table_302A[ucs - 0x302A];
return 0;
}
if (ucs <= 0xFB1E) {
if (ucs >= 0xFB1E) return ucs_table_FB1E[ucs - 0xFB1E];
return 0;
}
if (ucs <= 0xFE23) {
if (ucs >= 0xFE20) return ucs_table_FE20[ucs - 0xFE20];
return 0;
}
return 0;
}
/*

6
src/xutf8/keysym2Ucs.c

@ -30,10 +30,8 @@ @@ -30,10 +30,8 @@
#include "../../FL/Xutf8.h"
#include "imKStoUCS.c"
long XKeysymToUcs(KeySym keysym)
{
return (long) KeySymToUcs4(keysym);
long XKeysymToUcs(KeySym keysym) {
return (long) KeySymToUcs4(keysym);
}
#endif /* X11 only */

377
src/xutf8/test.c

@ -26,7 +26,9 @@ @@ -26,7 +26,9 @@
/*
* UTF-8 X test program (It contains MINIMAL code to support XIM !!!)
*
To test it do :
****************
* To test it do:
****************
kinput2 -canna
XMODIFIERS="@im=kinput2"; export XMODIFIERS
@ -51,7 +53,7 @@ export LANG=ko_KR; export XMODIFIERS="@im=Ami" @@ -51,7 +53,7 @@ export LANG=ko_KR; export XMODIFIERS="@im=Ami"
export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_TW"
export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_CN"
export LANG=C; export XMODIFIERS="@im=interxim"
*/
**********************************************************/
#include <stdlib.h>
#include <string.h>
@ -80,208 +82,209 @@ GC gc; @@ -80,208 +82,209 @@ GC gc;
int x = 2;
int y = 40;
int main(int argc, char**argv)
{
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
unsigned long mask;
Display* dpy;
int scr;
Window w, root;
XSetWindowAttributes set_attr;
int i;
XIMStyle *style;
static char buf[128];
KeySym keysym = 0;
Status status;
XWMHints wm_hints;
XClassHint class_hints;
XIMStyle input_style = 0;
char **font_name_list;
char *def_string;
XFontStruct **font_struct_list;
char **font_encoding_list;
int nb_font;
int len = 0;
int no_xim = 0;
int main(int argc, char**argv) {
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
unsigned long mask;
Display* dpy;
int scr;
Window w, root;
XSetWindowAttributes set_attr;
int i;
XIMStyle *style;
static char buf[128];
KeySym keysym = 0;
Status status;
XWMHints wm_hints;
XClassHint class_hints;
XIMStyle input_style = 0;
char **font_name_list;
char *def_string;
XFontStruct **font_struct_list;
char **font_encoding_list;
int nb_font;
int len = 0;
int no_xim = 0;
printf ("A -> %c \n", XUtf8Tolower('A'));
if (!setlocale(LC_ALL, ""))
puts("locale not supported by C library, locale unchanged");
printf ("A -> %c \n", XUtf8Tolower('A'));
if (!setlocale(LC_ALL, ""))
puts("locale not supported by C library, locale unchanged");
if (!XSetLocaleModifiers(""))
puts("X locale modifiers not supported, using default");
if (!XSetLocaleModifiers(""))
puts("X locale modifiers not supported, using default");
dpy = XOpenDisplay(0);
if (!dpy) { puts("cannot open display.\n"); exit(-1); }
scr = DefaultScreen(dpy);
root = RootWindow(dpy, scr);
set_attr.event_mask = KeyPressMask|FocusChangeMask;
set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
w = XCreateWindow(dpy, root, 10,10,200,100,0,
DefaultDepth(dpy, DefaultScreen(dpy)),
InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
if (!w) { puts("cannot creat window.\n"); exit(-1); }
dpy = XOpenDisplay(0);
if (!dpy) { puts("cannot open display.\n"); exit(-1); }
scr = DefaultScreen(dpy);
root = RootWindow(dpy, scr);
set_attr.event_mask = KeyPressMask|FocusChangeMask;
set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
w = XCreateWindow(dpy, root, 10,10,200,100,0,
DefaultDepth(dpy, DefaultScreen(dpy)),
InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
if (!w) {
puts("cannot creat window.\n");
exit(-1);
}
class_hints.res_name = "test";
class_hints.res_class = "Test";
wm_hints.input = True;
wm_hints.flags = InputHint;
class_hints.res_name = "test";
class_hints.res_class = "Test";
wm_hints.input = True;
wm_hints.flags = InputHint;
XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
NULL, &wm_hints, &class_hints);
XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
NULL, &wm_hints, &class_hints);
XMapWindow(dpy, w);
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (!xim_im) {
puts("cannot Open Input Manager: Try default.\n");
XSetLocaleModifiers("@im=");
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (!xim_im) { puts("Failed exiting.\n"); exit(-1); }
}
XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
for (i = 0, style = xim_styles->supported_styles;
i < xim_styles->count_styles; i++, style++)
{
if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
}
printf("input style : 0x%X\n", *style);
}
XMapWindow(dpy, w);
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (!xim_im) {
puts("cannot Open Input Manager: Try default.\n");
XSetLocaleModifiers("@im=");
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (!xim_im) {
puts("Failed exiting.\n");
exit(-1);
}
}
XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
for (i = 0, style = xim_styles->supported_styles;
i < xim_styles->count_styles; i++, style++) {
if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
}
printf("input style : 0x%X\n", *style);
}
xim_ic = XCreateIC(xim_im,
XNInputStyle,
(XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
if (!xim_ic) { puts("cannot create Input Context.\n"); exit(-1);}
XFree(xim_styles);
XSetICFocus(xim_ic);
/***************************************************************/
/** I don't recommand to use a font base name list similar
* to the following one in a real application ;-)
* You should use an iso8859-1 font, plus a single font for
* your language. */
/***************************************************************/
fontset = XCreateUtf8FontStruct(dpy,
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
"-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0,"
"-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
/* THIS PART IS NOT REQUIERED */
nb_font = fontset->nb_font;
xim_ic = XCreateIC(xim_im,
XNInputStyle,
(XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
if (!xim_ic) {
puts("cannot create Input Context.\n");
exit(-1);
}
XFree(xim_styles);
XSetICFocus(xim_ic);
while (nb_font > 0) {
nb_font--;
if (fontset->fonts[nb_font]) {
printf("encoding=\"\" fid=%d \n %s\n",
// fontset->encodings[nb_font],
fontset->fonts[nb_font]->fid,
fontset->font_name_list[nb_font]);
}
}
/* END OF NOT REQUIERED PART*/
/***************************************************************
* I don't recommend to use a font base name list similar
* to the following one in a real application ;-)
* You should use an iso8859-1 font, plus a single font for
* your language.
***************************************************************/
fontset = XCreateUtf8FontStruct(dpy,
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
"-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0,"
"-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
mask = (GCForeground | GCBackground);
xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
/* THIS PART IS NOT REQUIERED */
nb_font = fontset->nb_font;
gc = XCreateGC(dpy, w, mask, &xgcv);
if (!gc) { puts("cannot create Graphic Context.\n"); exit(-1);}
while (nb_font > 0) {
nb_font--;
if (fontset->fonts[nb_font]) {
printf("encoding=\"\" fid=%d \n %s\n",
// fontset->encodings[nb_font],
fontset->fonts[nb_font]->fid,
fontset->font_name_list[nb_font]);
}
}
/* END OF NOT REQUIERED PART*/
mask = (GCForeground | GCBackground);
xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
/***************************************************************/
while (1) {
int filtered;
static XEvent xevent;
static XVaNestedList list1 = 0;
int r;
gc = XCreateGC(dpy, w, mask, &xgcv);
if (!gc) {
puts("cannot create Graphic Context.\n");
exit(-1);
}
XNextEvent(dpy, &xevent);
if (xevent.type == KeyPress) {
XKeyEvent *e = (XKeyEvent*) &xevent;
printf ("0x%X %d\n", e->state, e->keycode);
}
if (xevent.type == DestroyNotify) {
/* XIM server has crashed */
no_xim = 1;
XSetLocaleModifiers("@im=");
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (xim_im) {
xim_ic = XCreateIC(xim_im,
XNInputStyle, (XIMPreeditNothing |
XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
} else {
xim_ic = NULL;
}
if (!xim_ic) {
puts("Crash recovery failed. exiting.\n");
exit(-1);
}
}
if (xevent.type != DestroyNotify) {
filtered = XFilterEvent(&xevent, 0);
}
if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic);
if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic);
if (xevent.type == KeyPress && !filtered) {
len = XUtf8LookupString(xim_ic, &xevent.xkey,
buf, 127, &keysym, &status);
if (len == 1 && buf[0] == '\b') {
x -= XUtf8TextWidth(fontset, buf, len);
XUtf8DrawImageString(dpy, w, fontset, gc,
x, y, buf, len);
} else if (len == 1 && buf[0] == '\r') {
y += fontset->ascent + fontset->descent;
x = 0;
XCloseIM(xim_im);
} else {
XUtf8DrawImageString(dpy, w, fontset, gc,
x, y, buf, len);
x += XUtf8TextWidth(fontset, buf, len);
}
/***************************************************************/
while (1) {
int filtered;
static XEvent xevent;
static XVaNestedList list1 = 0;
int r;
XNextEvent(dpy, &xevent);
if (xevent.type == KeyPress) {
XKeyEvent *e = (XKeyEvent*) &xevent;
printf ("0x%X %d\n", e->state, e->keycode);
}
if (xevent.type == DestroyNotify) {
/* XIM server has crashed */
no_xim = 1;
XSetLocaleModifiers("@im=");
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (xim_im) {
xim_ic = XCreateIC(xim_im,
XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
} else {
xim_ic = NULL;
}
if (!xim_ic) {
puts("Crash recovery failed. exiting.\n");
exit(-1);
}
}
if (xevent.type != DestroyNotify) {
filtered = XFilterEvent(&xevent, 0);
}
if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic);
if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic);
XUtf8DrawString(dpy, w, fontset, gc, 0, 20,
jp_txt, strlen(jp_txt));
if (xevent.type == KeyPress && !filtered) {
len = XUtf8LookupString(xim_ic, &xevent.xkey,
buf, 127, &keysym, &status);
XUtf8DrawString(dpy, w, fontset, gc, 50, 90,
rtl_txt, strlen(rtl_txt));
XUtf8DrawRtlString(dpy, w, fontset, gc,
50, 90, rtl_txt, strlen(rtl_txt));
buf[len] = 0;
printf("'%s' %d %x\n", buf, keysym, keysym);
buf[0] = 0;
if (len == 1 && buf[0] == '\b') {
x -= XUtf8TextWidth(fontset, buf, len);
XUtf8DrawImageString(dpy, w, fontset, gc,
x, y, buf, len);
} else if (len == 1 && buf[0] == '\r') {
y += fontset->ascent + fontset->descent;
x = 0;
XCloseIM(xim_im);
} else {
XUtf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
x += XUtf8TextWidth(fontset, buf, len);
}
}
if (filtered) {
printf("Dead key\n");
}
}
XFreeUtf8FontStruct(dpy, fontset);
return 0;
XUtf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
XUtf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
XUtf8DrawRtlString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
buf[len] = 0;
printf("'%s' %d %x\n", buf, keysym, keysym);
buf[0] = 0;
}
if (filtered) {
printf("Dead key\n");
}
}
XFreeUtf8FontStruct(dpy, fontset);
return 0;
}
/*

285
src/xutf8/test2.c

@ -26,7 +26,9 @@ @@ -26,7 +26,9 @@
/*
* UTF-8 X test program
*
To test it do :
*****************
* To test it do :
*****************
kinput2 -canna
XMODIFIERS="@im=kinput2"; export XMODIFIERS
@ -68,9 +70,9 @@ export LD_PRELOAD="/usr/src/x11/xc/exports/lib/libX11.so /usr/src/x11/xc/exports @@ -68,9 +70,9 @@ export LD_PRELOAD="/usr/src/x11/xc/exports/lib/libX11.so /usr/src/x11/xc/exports
#include <X11/Xmd.h>
char *jp_txt = "é UTF-8 e\xCC\x82=\xC3\xAA"
" \357\274\270\357\274\254\357\274\246\357\274"
"\244\345\220\215\343\201\247\346\214\207 \345\256\232"
"\343\201\231\343\202\213";
" \357\274\270\357\274\254\357\274\246\357\274"
"\244\345\220\215\343\201\247\346\214\207 \345\256\232"
"\343\201\231\343\202\213";
char *rtl_txt = "->e\xCC\x82=\xC3\xAA";
@ -82,149 +84,138 @@ GC gc; @@ -82,149 +84,138 @@ GC gc;
int x = 2;
int y = 40;
int main(int argc, char**argv)
{
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
unsigned long mask;
Display* dpy;
int scr;
Window w, root;
XSetWindowAttributes set_attr;
int i;
XIMStyle *style;
static char buf[128];
KeySym keysym = 0;
Status status;
XWMHints wm_hints;
XClassHint class_hints;
XIMStyle input_style = 0;
char **font_name_list;
char *def_string;
XFontStruct **font_struct_list;
char **font_encoding_list;
int nb_font;
int len = 0;
int no_xim = 0;
char **missing_charset_list_return;
int missing_charset_count_return;
char *def_string_return;
if (!setlocale(LC_ALL, ""))
puts("locale not supported by C library, locale unchanged");
if (!XSetLocaleModifiers(""))
puts("X locale modifiers not supported, using default");
dpy = XOpenDisplay(0);
scr = DefaultScreen(dpy);
root = RootWindow(dpy, scr);
set_attr.event_mask = KeyPressMask|FocusChangeMask;
set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
w = XCreateWindow(dpy, root, 10,10,200,100,0,
DefaultDepth(dpy, DefaultScreen(dpy)),
InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
class_hints.res_name = "test";
class_hints.res_class = "Test";
wm_hints.input = True;
wm_hints.flags = InputHint;
XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
NULL, &wm_hints, &class_hints);
XMapWindow(dpy, w);
xim_im = XOpenIM(dpy, NULL, "test", "Test");
XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
for (i = 0, style = xim_styles->supported_styles;
i < xim_styles->count_styles; i++, style++)
{
if (*style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
}
printf("input style : 0x%X\n", *style);
}
XFree(xim_styles);
xim_ic = XCreateIC(xim_im,
XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
XSetICFocus(xim_ic);
/***************************************************************/
/** I don't recommand to use a font base name list similar
* to the following one in a real application ;-) */
/***************************************************************/
fontset = XCreateFontSet(dpy,
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
"-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
&missing_charset_list_return,
&missing_charset_count_return,
&def_string_return);
mask = (GCForeground | GCBackground);
xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
gc = XCreateGC(dpy, w, mask, &xgcv);
/***************************************************************/
while (1) {
int filtered;
static XEvent xevent;
static XVaNestedList list1 = 0;
int r;
XNextEvent(dpy, &xevent);
if (xevent.type == KeyPress) {
XKeyEvent *e = (XKeyEvent*) &xevent;
printf ("0x%X %d\n", e->state, e->keycode);
}
filtered = XFilterEvent(&xevent, w);
if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
if (xevent.type == FocusIn) XSetICFocus(xim_ic);
if (xevent.type == KeyPress && !filtered) {
len = Xutf8LookupString(xim_ic, &xevent.xkey,
buf, 127, &keysym, &status);
Xutf8DrawImageString(dpy, w, fontset, gc,
x, y, buf, len);
Xutf8DrawString(dpy, w, fontset, gc, 0, 20,
jp_txt, strlen(jp_txt));
Xutf8DrawString(dpy, w, fontset, gc, 50, 90,
rtl_txt, strlen(rtl_txt));
buf[len] = 0;
printf("'%s' %d\n", buf, keysym);
buf[0] = 0;
XCloseIM(xim_im);
}
if (filtered) {
printf("Dead key\n");
}
}
XFreeFontSet(dpy, fontset);
return 0;
int main(int argc, char**argv) {
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
unsigned long mask;
Display* dpy;
int scr;
Window w, root;
XSetWindowAttributes set_attr;
int i;
XIMStyle *style;
static char buf[128];
KeySym keysym = 0;
Status status;
XWMHints wm_hints;
XClassHint class_hints;
XIMStyle input_style = 0;
char **font_name_list;
char *def_string;
XFontStruct **font_struct_list;
char **font_encoding_list;
int nb_font;
int len = 0;
int no_xim = 0;
char **missing_charset_list_return;
int missing_charset_count_return;
char *def_string_return;
if (!setlocale(LC_ALL, ""))
puts("locale not supported by C library, locale unchanged");
if (!XSetLocaleModifiers(""))
puts("X locale modifiers not supported, using default");
dpy = XOpenDisplay(0);
scr = DefaultScreen(dpy);
root = RootWindow(dpy, scr);
set_attr.event_mask = KeyPressMask|FocusChangeMask;
set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
w = XCreateWindow(dpy, root, 10,10,200,100,0,
DefaultDepth(dpy, DefaultScreen(dpy)),
InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
class_hints.res_name = "test";
class_hints.res_class = "Test";
wm_hints.input = True;
wm_hints.flags = InputHint;
XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
NULL, &wm_hints, &class_hints);
XMapWindow(dpy, w);
xim_im = XOpenIM(dpy, NULL, "test", "Test");
XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
for (i = 0, style = xim_styles->supported_styles;
i < xim_styles->count_styles; i++, style++) {
if (*style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
}
printf("input style : 0x%X\n", *style);
}
XFree(xim_styles);
xim_ic = XCreateIC(xim_im,
XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
XSetICFocus(xim_ic);
/***************************************************************
* I don't recommend to use a font base name list similar
* to the following one in a real application ;-)
***************************************************************/
fontset = XCreateFontSet(dpy,
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
"-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
"-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
"-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
"-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
&missing_charset_list_return,
&missing_charset_count_return,
&def_string_return);
mask = (GCForeground | GCBackground);
xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
gc = XCreateGC(dpy, w, mask, &xgcv);
/***************************************************************/
while (1) {
int filtered;
static XEvent xevent;
static XVaNestedList list1 = 0;
int r;
XNextEvent(dpy, &xevent);
if (xevent.type == KeyPress) {
XKeyEvent *e = (XKeyEvent*) &xevent;
printf ("0x%X %d\n", e->state, e->keycode);
}
filtered = XFilterEvent(&xevent, w);
if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
if (xevent.type == FocusIn) XSetICFocus(xim_ic);
if (xevent.type == KeyPress && !filtered) {
len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status);
Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
buf[len] = 0;
printf("'%s' %d\n", buf, keysym);
buf[0] = 0;
XCloseIM(xim_im);
}
if (filtered) {
printf("Dead key\n");
}
}
XFreeFontSet(dpy, fontset);
return 0;
}
/*

13
src/xutf8/ucs2fontmap.c

@ -32,8 +32,8 @@ @@ -32,8 +32,8 @@
#define conv_t void*
#define ucs4_t unsigned int
typedef struct {
unsigned short indx;
unsigned short used;
unsigned short indx;
unsigned short used;
} Summary16;
@ -62,10 +62,10 @@ typedef struct { @@ -62,10 +62,10 @@ typedef struct {
#include "headers/symbol_.h"
#include "headers/dingbats_.h"
/*************** conv_gen.c ************/
/*************** conv_gen.c ************/
/*const*/
int ucs2fontmap(char *s, unsigned int ucs, int enc)
{
int ucs2fontmap(char *s, unsigned int ucs, int enc) {
switch(enc) {
case 0: /* iso10646-1 */
s[0] = (char) ((ucs & 0xFF00) >> 8);
@ -302,8 +302,7 @@ int ucs2fontmap(char *s, unsigned int ucs, int enc) @@ -302,8 +302,7 @@ int ucs2fontmap(char *s, unsigned int ucs, int enc)
};
/*const*/
int encoding_number(const char *enc)
{
int encoding_number(const char *enc) {
if (!enc || !strncmp(enc, "iso10646-1", 10)) {
return 0;
} else if (!strcmp(enc, "iso8859-1")) {

647
src/xutf8/utf8Input.c

@ -48,8 +48,8 @@ @@ -48,8 +48,8 @@
#define conv_t void*
#define ucs4_t unsigned int
typedef struct {
unsigned short indx;
unsigned short used;
unsigned short indx;
unsigned short used;
} Summary16;
#include "lcUniConv/big5.h"
@ -60,376 +60,347 @@ typedef struct { @@ -60,376 +60,347 @@ typedef struct {
#include "lcUniConv/ksc5601.h"
int
XConvertEucTwToUtf8(
char* buffer_return,
int len)
{
/* FIXME */
XConvertEucTwToUtf8(char* buffer_return, int len) {
/* FIXME */
#if HAVE_LIBC_ICONV
iconv_t cd;
int cdl;
iconv_t cd;
int cdl;
#else
int i = 0;
int i = 0;
#endif
int l = 0;
char *buf, *b;
int l = 0;
char *buf, *b;
if (len < 1) return 0;
b = buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned) len);
if (len < 1) return 0;
b = buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned) len);
#if HAVE_LIBC_ICONV
l = cdl = len;
cd = iconv_open("EUC-TW", "UTF-8");
iconv(cd, &b, &len, &buffer_return, &cdl);
iconv_close(cd);
l -= cdl;
l = cdl = len;
cd = iconv_open("EUC-TW", "UTF-8");
iconv(cd, &b, &len, &buffer_return, &cdl);
iconv_close(cd);
l -= cdl;
#else
while (i < len) {
unsigned int ucs;
unsigned char c;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xa1 && c < 0xff && len - i > 1 ) {
unsigned char b[2];
b[0] = (unsigned char) c - 0x80;
b[1] = (unsigned char) buf[i + 1] - 0x80;
ucs = ' '; i += 2;
} else if (c == 0x8e && len - i > 3) {
unsigned char b[2];
unsigned char c1 = buf[i + 1];
unsigned char c2 = buf[i + 2];
unsigned char c3 = buf[i + 3];
b[0] = (unsigned char) buf[i + 2] - 0x80;
b[1] = (unsigned char) buf[i + 3] - 0x80;
if (c1 >= 0xa1 && c1 <= 0xb0) {
if (c2 >= 0xa1 && c2 < 0xff && c3 >= 0xa1 &&
c3 < 0xff)
{
ucs = ' '; i += 4;
} else {
ucs = '?'; i++;
}
} else {
ucs = '?'; i++;
}
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
while (i < len) {
unsigned int ucs;
unsigned char c;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xa1 && c < 0xff && len - i > 1 ) {
unsigned char b[2];
b[0] = (unsigned char) c - 0x80;
b[1] = (unsigned char) buf[i + 1] - 0x80;
ucs = ' '; i += 2;
} else if (c == 0x8e && len - i > 3) {
unsigned char b[2];
unsigned char c1 = buf[i + 1];
unsigned char c2 = buf[i + 2];
unsigned char c3 = buf[i + 3];
b[0] = (unsigned char) buf[i + 2] - 0x80;
b[1] = (unsigned char) buf[i + 3] - 0x80;
if (c1 >= 0xa1 && c1 <= 0xb0) {
if (c2 >= 0xa1 && c2 < 0xff && c3 >= 0xa1 && c3 < 0xff) {
ucs = ' '; i += 4;
} else {
ucs = '?'; i++;
}
} else {
ucs = '?'; i++;
}
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
#endif
free(buf);
return l;
free(buf);
return l;
}
int
XConvertEucKrToUtf8(
char* buffer_return,
int len)
{
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (ksc5601_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else {
ucs = '?';
}
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
XConvertEucKrToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (ksc5601_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
free(buf);
return l;
} else {
ucs = '?';
}
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
}
int
XConvertBig5ToUtf8(
char* buffer_return,
int len)
{
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
if (len == 1) {
l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
}
while (i + 1 < len) {
unsigned int ucs;
unsigned char b[2];
b[0] = (unsigned char) buf[i];
b[1] = (unsigned char) buf[i + 1];
if (big5_mbtowc(NULL, &ucs, b, 2) == 2) {
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
XConvertBig5ToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
if (len == 1) {
l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
}
while (i + 1 < len) {
unsigned int ucs;
unsigned char b[2];
b[0] = (unsigned char) buf[i];
b[1] = (unsigned char) buf[i + 1];
if (big5_mbtowc(NULL, &ucs, b, 2) == 2) {
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
}
int
XConvertGb2312ToUtf8(
char* buffer_return,
int len)
{
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
if (len == 1) {
l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
}
while (i + 1 < len) {
unsigned int ucs;
unsigned char b[2];
b[0] = (unsigned char) buf[i];
b[1] = (unsigned char) buf[i + 1];
if (gb2312_mbtowc(NULL, &ucs, b, 2) == 2) {
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
XConvertGb2312ToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
if (len == 1) {
l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
}
while (i + 1 < len) {
unsigned int ucs;
unsigned char b[2];
b[0] = (unsigned char) buf[i];
b[1] = (unsigned char) buf[i + 1];
if (gb2312_mbtowc(NULL, &ucs, b, 2) == 2) {
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
}
int
XConvertEucCnToUtf8(
char* buffer_return,
int len)
{
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = (unsigned char) c;
b[1] = (unsigned char) c1;
if (gb2312_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else {
ucs = '?';
}
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
XConvertEucCnToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = (unsigned char) c;
b[1] = (unsigned char) c1;
if (gb2312_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
free(buf);
return l;
} else {
ucs = '?';
}
i += 2;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
}
int
XConvertEucJpToUtf8(
char* buffer_return,
int len)
{
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c < 0xF5 && c1 >= 0xa1) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (jisx0208_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else if (c1 >= 0xA1 && c1 < 0xFF) {
ucs = 0xE000 + 94 * (c - 0xF5) + (c1 - 0xA1);
} else {
ucs = '?';
}
i += 2;
} else if (c == 0x8E && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 <= 0xe0) {
if (jisx0201_mbtowc(NULL, &ucs, &c1, 1) != 1) {
ucs = '?';
}
} else {
ucs = '?';
}
i += 2;
} else if (c == 0x8F && len - i > 2) {
c = (unsigned char) buf[i + 1];
c1 = (unsigned char) buf[i + 2];
if (c >= 0xa1 && c < 0xff) {
if (c < 0xf5 && c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (jisx0212_mbtowc(NULL, &ucs, b, 2)
< 1)
{
ucs = '?';
}
} else {
ucs = '?';
}
} else {
if (c1 >= 0xa1 && c1 < 0xff) {
ucs = 0xe3ac + 94 * (c - 0xF5) +
(c1 - 0xA1);
} else {
ucs = '?';
}
}
i += 3;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
XConvertEucJpToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
if (len < 1) return 0;
buf = (char*) malloc((unsigned)len);
memcpy(buf, buffer_return, (unsigned)len);
while (i < len) {
unsigned int ucs;
unsigned char c, c1;
c = (unsigned char) buf[i];
if (c < 0x80) {
ucs = c;
i++;
} else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c < 0xF5 && c1 >= 0xa1) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (jisx0208_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else if (c1 >= 0xA1 && c1 < 0xFF) {
ucs = 0xE000 + 94 * (c - 0xF5) + (c1 - 0xA1);
} else {
ucs = '?';
}
i += 2;
} else if (c == 0x8E && len - i > 1) {
c1 = (unsigned char) buf[i + 1];
if (c1 >= 0xa1 && c1 <= 0xe0) {
if (jisx0201_mbtowc(NULL, &ucs, &c1, 1) != 1) {
ucs = '?';
}
} else {
ucs = '?';
}
i += 2;
} else if (c == 0x8F && len - i > 2) {
c = (unsigned char) buf[i + 1];
c1 = (unsigned char) buf[i + 2];
if (c >= 0xa1 && c < 0xff) {
if (c < 0xf5 && c1 >= 0xa1 && c1 < 0xff) {
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (jisx0212_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else {
ucs = '?';
}
free(buf);
return l;
} else {
if (c1 >= 0xa1 && c1 < 0xff) {
ucs = 0xe3ac + 94 * (c - 0xF5) + (c1 - 0xA1);
} else {
ucs = '?';
}
}
i += 3;
} else {
ucs = '?';
i++;
}
l += XConvertUcsToUtf8(ucs, buffer_return + l);
}
free(buf);
return l;
}
int
XConvertEucToUtf8(
const char* locale,
char* buffer_return,
int len,
int bytes_buffer)
{
if (!locale/* || strstr(locale, "UTF") || strstr(locale, "utf")*/) {
return len;
}
XConvertEucToUtf8(const char* locale,
char* buffer_return,
int len,
int bytes_buffer) {
if (strstr(locale, "ja")) {
return XConvertEucJpToUtf8(buffer_return, len);
} else if (strstr(locale, "Big5") || strstr(locale, "big5")) { /* BIG5 */
return XConvertBig5ToUtf8(buffer_return, len);
} else if (strstr(locale, "zh") || strstr(locale, "chinese-")) {
if (strstr(locale, "TW") || strstr(locale, "chinese-t")) {
if (strstr(locale, "EUC") || strstr(locale, "euc") ||
strstr(locale, "chinese-t"))
{
return XConvertEucTwToUtf8(buffer_return, len);
}
return XConvertBig5ToUtf8(buffer_return, len);
}
if (strstr(locale, "EUC") || strstr(locale, "euc")) {
return XConvertEucCnToUtf8(buffer_return, len);
}
return XConvertGb2312ToUtf8(buffer_return, len);
} else if (strstr(locale, "ko")) {
return XConvertEucKrToUtf8(buffer_return, len);
}
return len;
}
if (!locale/* || strstr(locale, "UTF") || strstr(locale, "utf")*/) {
return len;
}
if (strstr(locale, "ja")) {
return XConvertEucJpToUtf8(buffer_return, len);
} else if (strstr(locale, "Big5") || strstr(locale, "big5")) { /* BIG5 */
return XConvertBig5ToUtf8(buffer_return, len);
} else if (strstr(locale, "zh") || strstr(locale, "chinese-")) {
if (strstr(locale, "TW") || strstr(locale, "chinese-t")) {
if (strstr(locale, "EUC") || strstr(locale, "euc") || strstr(locale, "chinese-t")) {
return XConvertEucTwToUtf8(buffer_return, len);
}
return XConvertBig5ToUtf8(buffer_return, len);
}
if (strstr(locale, "EUC") || strstr(locale, "euc")) {
return XConvertEucCnToUtf8(buffer_return, len);
}
return XConvertGb2312ToUtf8(buffer_return, len);
} else if (strstr(locale, "ko")) {
return XConvertEucKrToUtf8(buffer_return, len);
}
return len;
}
int
XUtf8LookupString(
XIC ic,
XKeyPressedEvent* event,
char* buffer_return,
int bytes_buffer,
KeySym* keysym,
Status* status_return)
{
long ucs = -1;
int len;
len = XmbLookupString(ic, event, buffer_return, bytes_buffer / 5,
keysym, status_return);
if (*status_return == XBufferOverflow) {
return len * 5;
}
if (*keysym > 0 && *keysym < 0x100 && len == 1) {
if (*keysym < 0x80) {
ucs = (unsigned char)buffer_return[0];
} else {
ucs = *keysym;
}
} else if (((*keysym >= 0x100 && *keysym <= 0xf000) ||
(*keysym & 0xff000000U) == 0x01000000))
{
ucs = XKeysymToUcs(*keysym);
} else {
ucs = -2;
}
if (ucs > 0) {
len = XConvertUcsToUtf8((unsigned)ucs, (char *)buffer_return);
} else if (len > 0) {
XIM im;
if (!ic) return 0;
im = XIMOfIC(ic);
if (!im) return 0;
len = XConvertEucToUtf8(XLocaleOfIM(im),
buffer_return, len, bytes_buffer);
}
return len;
XUtf8LookupString(XIC ic,
XKeyPressedEvent* event,
char* buffer_return,
int bytes_buffer,
KeySym* keysym,
Status* status_return) {
long ucs = -1;
int len;
len = XmbLookupString(ic, event, buffer_return, bytes_buffer / 5,
keysym, status_return);
if (*status_return == XBufferOverflow) {
return len * 5;
}
if (*keysym > 0 && *keysym < 0x100 && len == 1) {
if (*keysym < 0x80) {
ucs = (unsigned char)buffer_return[0];
} else {
ucs = *keysym;
}
} else if (((*keysym >= 0x100 && *keysym <= 0xf000) ||
(*keysym & 0xff000000U) == 0x01000000))
{
ucs = XKeysymToUcs(*keysym);
} else {
ucs = -2;
}
if (ucs > 0) {
len = XConvertUcsToUtf8((unsigned)ucs, (char *)buffer_return);
} else if (len > 0) {
XIM im;
if (!ic) return 0;
im = XIMOfIC(ic);
if (!im) return 0;
len = XConvertEucToUtf8(XLocaleOfIM(im), buffer_return, len, bytes_buffer);
}
return len;
}
#endif /* X11 only */

317
src/xutf8/utf8Utils.c

@ -39,73 +39,69 @@ @@ -39,73 +39,69 @@
* Returns -1 if the UTF-8 string is not valid
*/
int
XConvertUtf8ToUcs(
const unsigned char *buf,
int len,
unsigned int *ucs)
{
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {
if (buf[0] & 0x10) {
if (buf[0] & 0x08) {
if (buf[0] & 0x04) {
if (buf[0] & 0x02) {
/* bad UTF-8 string */
} else {
/* 0x04000000 - 0x7FFFFFFF */
}
} else if (len > 4
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80
&& (buf[4] & 0xC0) == 0x80)
{
/* 0x00200000 - 0x03FFFFFF */
*ucs = ((buf[0] & ~0xF8) << 24) +
((buf[1] & ~0x80) << 18) +
((buf[2] & ~0x80) << 12) +
((buf[3] & ~0x80) << 6) +
(buf[4] & ~0x80);
if (*ucs > 0x001FFFFF && *ucs < 0x01000000) return 5;
}
} else if (len > 3
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80)
{
/* 0x00010000 - 0x001FFFFF */
*ucs = ((buf[0] & ~0xF0) << 18) +
((buf[1] & ~0x80) << 12) +
((buf[2] & ~0x80) << 6) +
(buf[3] & ~0x80);
if (*ucs > 0x0000FFFF) return 4;
}
} else if (len > 2 &&
(buf[1] & 0xC0) == 0x80 &&
(buf[2] & 0xC0) == 0x80)
{
/* 0x00000800 - 0x0000FFFF */
*ucs = ((buf[0] & ~0xE0) << 12) +
((buf[1] & ~0x80) << 6) +
(buf[2] & ~0x80);
if (*ucs > 0x000007FF) return 3;
XConvertUtf8ToUcs(const unsigned char *buf,
int len,
unsigned int *ucs) {
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {
if (buf[0] & 0x10) {
if (buf[0] & 0x08) {
if (buf[0] & 0x04) {
if (buf[0] & 0x02) {
/* bad UTF-8 string */
} else {
/* 0x04000000 - 0x7FFFFFFF */
}
} else if (len > 4
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80
&& (buf[4] & 0xC0) == 0x80) {
/* 0x00200000 - 0x03FFFFFF */
*ucs = ((buf[0] & ~0xF8) << 24) +
((buf[1] & ~0x80) << 18) +
((buf[2] & ~0x80) << 12) +
((buf[3] & ~0x80) << 6) +
(buf[4] & ~0x80);
if (*ucs > 0x001FFFFF && *ucs < 0x01000000) return 5;
}
} else if (len > 1 && (buf[1] & 0xC0) == 0x80) {
/* 0x00000080 - 0x000007FF */
*ucs = ((buf[0] & ~0xC0) << 6) +
(buf[1] & ~0x80);
if (*ucs > 0x0000007F) return 2;
} else if (len > 3
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80) {
/* 0x00010000 - 0x001FFFFF */
*ucs = ((buf[0] & ~0xF0) << 18) +
((buf[1] & ~0x80) << 12) +
((buf[2] & ~0x80) << 6) +
(buf[3] & ~0x80);
if (*ucs > 0x0000FFFF) return 4;
}
} else if (len > 2
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80) {
/* 0x00000800 - 0x0000FFFF */
*ucs = ((buf[0] & ~0xE0) << 12) +
((buf[1] & ~0x80) << 6) +
(buf[2] & ~0x80);
if (*ucs > 0x000007FF) return 3;
}
} else if (len > 0) {
/* 0x00000000 - 0x0000007F */
*ucs = buf[0];
return 1;
} else if (len > 1 && (buf[1] & 0xC0) == 0x80) {
/* 0x00000080 - 0x000007FF */
*ucs = ((buf[0] & ~0xC0) << 6) +
(buf[1] & ~0x80);
if (*ucs > 0x0000007F) return 2;
}
}
} else if (len > 0) {
/* 0x00000000 - 0x0000007F */
*ucs = buf[0];
return 1;
}
*ucs = (unsigned int) '?'; /* bad utf-8 string */
return -1;
*ucs = (unsigned int) '?'; /* bad utf-8 string */
return -1;
}
/*
@ -113,38 +109,37 @@ XConvertUtf8ToUcs( @@ -113,38 +109,37 @@ XConvertUtf8ToUcs(
* NOTE : the buffer (buf) must be at least 5 bytes long !!!
*/
int
XConvertUcsToUtf8(
unsigned int ucs,
char *buf)
{
if (ucs < 0x000080) {
buf[0] = ucs;
return 1;
} else if (ucs < 0x000800) {
buf[0] = 0xC0 | (ucs >> 6);
buf[1] = 0x80 | (ucs & 0x3F);
return 2;
} else if (ucs < 0x010000) {
buf[0] = 0xE0 | (ucs >> 12);
buf[1] = 0x80 | ((ucs >> 6) & 0x3F);
buf[2] = 0x80 | (ucs & 0x3F);
return 3;
} else if (ucs < 0x00200000) {
buf[0] = 0xF0 | (ucs >> 18);
buf[1] = 0x80 | ((ucs >> 12) & 0x3F);
buf[2] = 0x80 | ((ucs >> 6) & 0x3F);
buf[3] = 0x80 | (ucs & 0x3F);
return 4;
} else if (ucs < 0x01000000) {
buf[0] = 0xF8 | (ucs >> 24);
buf[1] = 0x80 | ((ucs >> 18) & 0x3F);
buf[2] = 0x80 | ((ucs >> 12) & 0x3F);
buf[3] = 0x80 | ((ucs >> 6) & 0x3F);
buf[4] = 0x80 | (ucs & 0x3F);
return 5;
}
buf[0] = '?';
return -1;
XConvertUcsToUtf8(unsigned int ucs,
char *buf) {
if (ucs < 0x000080) {
buf[0] = ucs;
return 1;
} else if (ucs < 0x000800) {
buf[0] = 0xC0 | (ucs >> 6);
buf[1] = 0x80 | (ucs & 0x3F);
return 2;
} else if (ucs < 0x010000) {
buf[0] = 0xE0 | (ucs >> 12);
buf[1] = 0x80 | ((ucs >> 6) & 0x3F);
buf[2] = 0x80 | (ucs & 0x3F);
return 3;
} else if (ucs < 0x00200000) {
buf[0] = 0xF0 | (ucs >> 18);
buf[1] = 0x80 | ((ucs >> 12) & 0x3F);
buf[2] = 0x80 | ((ucs >> 6) & 0x3F);
buf[3] = 0x80 | (ucs & 0x3F);
return 4;
} else if (ucs < 0x01000000) {
buf[0] = 0xF8 | (ucs >> 24);
buf[1] = 0x80 | ((ucs >> 18) & 0x3F);
buf[2] = 0x80 | ((ucs >> 12) & 0x3F);
buf[3] = 0x80 | ((ucs >> 6) & 0x3F);
buf[4] = 0x80 | (ucs & 0x3F);
return 5;
}
buf[0] = '?';
return -1;
}
/*
@ -152,92 +147,88 @@ XConvertUcsToUtf8( @@ -152,92 +147,88 @@ XConvertUcsToUtf8(
* (returns -1 if not valid)
*/
int
XUtf8CharByteLen(
const unsigned char *buf,
int len)
{
unsigned int ucs;
return XConvertUtf8ToUcs(buf, len, &ucs);
XUtf8CharByteLen(const unsigned char *buf,
int len) {
unsigned int ucs;
return XConvertUtf8ToUcs(buf, len, &ucs);
}
/*
* returns the quantity of Unicode chars in the UTF-8 string
*/
int
XCountUtf8Char(
const unsigned char *buf,
int len)
{
int i = 0;
int nbc = 0;
while (i < len) {
int cl = XUtf8CharByteLen(buf + i, len - i);
if (cl < 1) cl = 1;
nbc++;
i += cl;
}
return nbc;
XCountUtf8Char(const unsigned char *buf,
int len) {
int i = 0;
int nbc = 0;
while (i < len) {
int cl = XUtf8CharByteLen(buf + i, len - i);
if (cl < 1) cl = 1;
nbc++;
i += cl;
}
return nbc;
}
/*
* Same as XConvertUtf8ToUcs but no sanity check is done.
*/
int
XFastConvertUtf8ToUcs(
const unsigned char *buf,
int len,
unsigned int *ucs)
{
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {
if (buf[0] & 0x10) {
if (buf[0] & 0x08) {
if (buf[0] & 0x04) {
if (buf[0] & 0x02) {
/* bad UTF-8 string */
} else {
/* 0x04000000 - 0x7FFFFFFF */
}
} else if (len > 4) {
/* 0x00200000 - 0x03FFFFFF */
*ucs = ((buf[0] & ~0xF8) << 24) +
((buf[1] & ~0x80) << 18) +
((buf[2] & ~0x80) << 12) +
((buf[3] & ~0x80) << 6) +
(buf[4] & ~0x80);
return 5;
}
} else if (len > 3) {
/* 0x00010000 - 0x001FFFFF */
*ucs = ((buf[0] & ~0xF0) << 18) +
((buf[1] & ~0x80) << 12) +
((buf[2] & ~0x80) << 6) +
(buf[3] & ~0x80);
return 4;
}
} else if (len > 2) {
/* 0x00000800 - 0x0000FFFF */
*ucs = ((buf[0] & ~0xE0) << 12) +
((buf[1] & ~0x80) << 6) +
(buf[2] & ~0x80);
return 3;
XFastConvertUtf8ToUcs(const unsigned char *buf,
int len,
unsigned int *ucs) {
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {
if (buf[0] & 0x10) {
if (buf[0] & 0x08) {
if (buf[0] & 0x04) {
if (buf[0] & 0x02) {
/* bad UTF-8 string */
} else {
/* 0x04000000 - 0x7FFFFFFF */
}
} else if (len > 4) {
/* 0x00200000 - 0x03FFFFFF */
*ucs = ((buf[0] & ~0xF8) << 24) +
((buf[1] & ~0x80) << 18) +
((buf[2] & ~0x80) << 12) +
((buf[3] & ~0x80) << 6) +
(buf[4] & ~0x80);
return 5;
}
} else if (len > 1) {
/* 0x00000080 - 0x000007FF */
*ucs = ((buf[0] & ~0xC0) << 6) +
(buf[1] & ~0x80);
return 2;
} else if (len > 3) {
/* 0x00010000 - 0x001FFFFF */
*ucs = ((buf[0] & ~0xF0) << 18) +
((buf[1] & ~0x80) << 12) +
((buf[2] & ~0x80) << 6) +
(buf[3] & ~0x80);
return 4;
}
} else if (len > 2) {
/* 0x00000800 - 0x0000FFFF */
*ucs = ((buf[0] & ~0xE0) << 12) +
((buf[1] & ~0x80) << 6) +
(buf[2] & ~0x80);
return 3;
}
} else if (len > 0) {
/* 0x00000000 - 0x0000007F */
*ucs = buf[0];
return 1;
} else if (len > 1) {
/* 0x00000080 - 0x000007FF */
*ucs = ((buf[0] & ~0xC0) << 6) +
(buf[1] & ~0x80);
return 2;
}
}
} else if (len > 0) {
/* 0x00000000 - 0x0000007F */
*ucs = buf[0];
return 1;
}
*ucs = (unsigned int) '?'; /* bad utf-8 string */
return -1;
*ucs = (unsigned int) '?'; /* bad utf-8 string */
return -1;
}
#endif /* X11 only */

1501
src/xutf8/utf8Wrap.c

File diff suppressed because it is too large Load Diff

264
src/xutf8/utils/conv_gen.c

@ -30,147 +30,143 @@ @@ -30,147 +30,143 @@
#include <stdio.h>
char buffer[1000000];
int main(int argc, char **argv)
{
char buf[80];
int len;
char *encode[256];
int encode_number = 0;
unsigned int i = 0;
unsigned char *ptr;
unsigned char *lst = "";
size_t nb;
int nbb = 0;
len = fread(buffer, 1, 1000000, stdin);
int main(int argc, char **argv) {
char buf[80];
int len;
char *encode[256];
int encode_number = 0;
unsigned int i = 0;
unsigned char *ptr;
unsigned char *lst = "";
size_t nb;
int nbb = 0;
len = fread(buffer, 1, 1000000, stdin);
puts(" ");
puts(" /*************** conv_gen.c ************/");
buffer[len] = '\0';
ptr = buffer;
puts(" ");
puts(" /*************** conv_gen.c ************/");
buffer[len] = '\0';
ptr = buffer;
printf("const int ucs2fontmap"
"(char *s, unsigned int ucs, int enc)\n");
printf("{\n");
printf(" switch(enc) {\n");
printf(" case 0:\n");
printf(" s[0] = (char) ((ucs & 0xFF00) >> 8);\n");
printf(" s[1] = (char) (ucs & 0xFF);\n");
printf(" return 0;");
while (len > 0) {
unsigned char *p = ptr;
unsigned char *f, *t;
printf("const int ucs2fontmap"
"(char *s, unsigned int ucs, int enc)\n");
printf("{\n");
printf(" switch(enc) {\n");
printf(" case 0:\n");
printf(" s[0] = (char) ((ucs & 0xFF00) >> 8);\n");
printf(" s[1] = (char) (ucs & 0xFF);\n");
printf(" return 0;");
while (len > 0) {
unsigned char *p = ptr;
unsigned char *f, *t;
while (*p != ']') {
i++;
p++;
}
*(p - 1) = '\0';
*(p - 6) = '\0';
f = p - 5;
while (*p != '+') { i++; p++;}
p++;
t = p;
*(p + 4) = '\0';
if (strcmp(lst, ptr)) {
encode_number++;
encode[encode_number] = ptr;
printf("\n break;");
printf("\n case %d:\n", encode_number);
printf(" ");
} else {
printf(" else ");
}
lst = ptr;
printf("if (ucs <= 0x%s) {\n", t);
printf(" if (ucs >= 0x%s) {\n", f);
if (*(f - 3) == '2') {
printf(" int i = (ucs - 0x%s) * 2;\n", f);
printf(" s[0] = %s_%s[i++];\n", ptr, f, f);
printf(" s[1] = %s_%s[i];\n", ptr, f, f);
printf(" if (s[0] || s[1]) return %d;\n",
encode_number);
} else {
printf(" s[0] = 0;\n");
printf(" s[1] = %s_%s[ucs - 0x%s];\n",
ptr, f, f);
printf(" if (s[1]) return %d;\n", encode_number);
}
printf(" }\n");
printf(" }");
while (*ptr != '\n') {
ptr++;
len--;
}
ptr++;
len--;
}
printf("\n break;\n");
printf("\n default:\n");
printf(" break;\n");
printf(" };\n");
printf(" return -1;\n");
printf("};\n\n");
while (*p != ']') {
i++;
p++;
}
*(p - 1) = '\0';
*(p - 6) = '\0';
f = p - 5;
while (*p != '+') { i++; p++;}
p++;
t = p;
*(p + 4) = '\0';
if (strcmp(lst, ptr)) {
encode_number++;
encode[encode_number] = ptr;
printf("\n break;");
printf("\n case %d:\n", encode_number);
printf(" ");
} else {
printf(" else ");
}
lst = ptr;
printf("if (ucs <= 0x%s) {\n", t);
printf(" if (ucs >= 0x%s) {\n", f);
if (*(f - 3) == '2') {
printf(" int i = (ucs - 0x%s) * 2;\n", f);
printf(" s[0] = %s_%s[i++];\n", ptr, f, f);
printf(" s[1] = %s_%s[i];\n", ptr, f, f);
printf(" if (s[0] || s[1]) return %d;\n", encode_number);
} else {
printf(" s[0] = 0;\n");
printf(" s[1] = %s_%s[ucs - 0x%s];\n", ptr, f, f);
printf(" if (s[1]) return %d;\n", encode_number);
}
printf(" }\n");
printf(" }");
while (*ptr != '\n') {
ptr++;
len--;
}
ptr++;
len--;
}
printf("\n break;\n");
printf("\n default:\n");
printf(" break;\n");
printf(" };\n");
printf(" return -1;\n");
printf("};\n\n");
printf("const int encoding_number(const char *enc)\n{\n");
printf(" if (!enc || !strcmp(enc, \"iso10646-1\")) {\n");
printf(" return 0;\n");
i = 1;
while (i <= encode_number) {
int l;
char *ptr;
l = strlen(encode[i]) - 3;
ptr = encode[i] + l;
*(ptr) = '\0';
ptr--;
while (ptr != encode[i]) {
if (*ptr == '_') {
*ptr = '-';
ptr--;
break;
}
ptr--;
}
while (ptr != encode[i]) {
if (*ptr == '_') {
*ptr = '.';
}
ptr--;
}
printf(" } else if (!strcmp(enc, \"%s\")", encode[i] +11);
printf("const int encoding_number(const char *enc)\n{\n");
printf(" if (!enc || !strcmp(enc, \"iso10646-1\")) {\n");
printf(" return 0;\n");
i = 1;
while (i <= encode_number) {
int l;
char *ptr;
l = strlen(encode[i]) - 3;
ptr = encode[i] + l;
*(ptr) = '\0';
ptr--;
while (ptr != encode[i]) {
if (*ptr == '_') {
*ptr = '-';
ptr--;
break;
}
ptr--;
}
while (ptr != encode[i]) {
if (*ptr == '_') {
*ptr = '.';
}
ptr--;
}
printf(" } else if (!strcmp(enc, \"%s\")", encode[i] +11);
if (!strcmp(encode[i] + 11, "big5-0")) {
printf(" || !strcmp(enc, \"big5.eten-0\")");
} else if (!strcmp(encode[i] + 11, "dingbats")) {
printf(" || !strcmp(enc, \"zapfdingbats\")");
printf(" || !strcmp(enc, \"zapf dingbats\")");
printf(" || !strcmp(enc, \"itc zapf dingbats\")");
} else if (!strcmp(encode[i] + 11, "jisx0208.1983-0")) {
printf(" || !strcmp(enc, \"jisx0208.1990-0\")");
}
if (!strcmp(encode[i] + 11, "big5-0")) {
printf(" || !strcmp(enc, \"big5.eten-0\")");
} else if (!strcmp(encode[i] + 11, "dingbats")) {
printf(" || !strcmp(enc, \"zapfdingbats\")");
printf(" || !strcmp(enc, \"zapf dingbats\")");
printf(" || !strcmp(enc, \"itc zapf dingbats\")");
} else if (!strcmp(encode[i] + 11, "jisx0208.1983-0")) {
printf(" || !strcmp(enc, \"jisx0208.1990-0\")");
}
printf(") {\n");
printf(" return %d;\n", i);
i++;
}
printf(" };\n");
printf(" return -1;\n");
printf("};\n\n");
printf(") {\n");
printf(" return %d;\n", i);
i++;
}
printf(" };\n");
printf(" return -1;\n");
printf("};\n\n");
printf("/*\n");
printf("const char *encoding_name(int num)\n{\n");
printf(" switch (num) {\n");
i = 1;
while (i <= encode_number) {
printf(" case %d:\n", i);
printf(" return \"%s\";\n", encode[i] + 11);
i++;
}
printf(" };\n");
printf(" return \"iso10646-1\";\n");
printf("};\n\n");
printf("*/\n");
return 0;
printf("/*\n");
printf("const char *encoding_name(int num)\n{\n");
printf(" switch (num) {\n");
i = 1;
while (i <= encode_number) {
printf(" case %d:\n", i);
printf(" return \"%s\";\n", encode[i] + 11);
i++;
}
printf(" };\n");
printf(" return \"iso10646-1\";\n");
printf("};\n\n");
printf("*/\n");
return 0;
}
/*

260
src/xutf8/utils/convert_map.c

@ -33,149 +33,145 @@ @@ -33,149 +33,145 @@
char buffer[1000000];
int JIS0208(unsigned char * ptr)
{
int i = 0;
unsigned int fmap;
unsigned int ucs;
while(*ptr != '\t') { ptr++; i++; }
ptr++; i++; *(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (ucs) printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
int JIS0208(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
while(*ptr != '\t') { ptr++; i++; }
ptr++; i++; *(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int JIS0201(unsigned char * ptr)
{
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
int JIS0201(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int ADOBE(unsigned char * ptr)
{
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+2) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
if (fmap < 1) {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
int ADOBE(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+2) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
if (fmap < 1) {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int JIS0212(unsigned char * ptr)
{
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
ptr += 7;
i += 7;
while(*ptr == ' ') { ptr++; i++; }
//i++; ptr++;
*(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
int JIS0212(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
ptr += 7;
i += 7;
while(*ptr == ' ') { ptr++; i++; }
//i++; ptr++;
*(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int main(int argc, char **argv)
{
char buf[80];
int len;
int i;
unsigned char *ptr;
size_t nb;
len = fread(buffer, 1, 1000000, stdin);
int main(int argc, char **argv) {
char buf[80];
int len;
int i;
unsigned char *ptr;
size_t nb;
len = fread(buffer, 1, 1000000, stdin);
buffer[len] = '\0';
ptr = (unsigned char *)buffer;
while (*ptr !='\n') {ptr++; len--;};
ptr++; len--;
while (*ptr == '#') {
while (*ptr !='\n') {
ptr++;
len--;
}
ptr++;
len--;
}
buffer[len] = '\0';
ptr = (unsigned char *)buffer;
while (*ptr !='\n') {ptr++; len--;};
ptr++; len--;
while (*ptr == '#') {
while (*ptr !='\n') {
ptr++;
len--;
}
ptr++;
len--;
}
while (len > 0) {
nb = 0;
if (!strcmp("jisx0208.1983-0", argv[1])) {
nb = JIS0208(ptr);
} else if (!strcmp("jisx0201.1976-0", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("jisx0212.1990-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("gb2312.1980-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("ksc5601.1987-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("big5-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strncmp("iso8859", argv[1], 7)) {
nb = JIS0201(ptr);
} else if (!strcmp("koi8-1", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("dingbats", argv[1]) ||
!strcmp("symbol", argv[1]))
{
nb = ADOBE(ptr);
} else {
len = 0;
}
ptr += nb;
len = len - nb;
}
return 0;
while (len > 0) {
nb = 0;
if (!strcmp("jisx0208.1983-0", argv[1])) {
nb = JIS0208(ptr);
} else if (!strcmp("jisx0201.1976-0", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("jisx0212.1990-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("gb2312.1980-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("ksc5601.1987-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("big5-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strncmp("iso8859", argv[1], 7)) {
nb = JIS0201(ptr);
} else if (!strcmp("koi8-1", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("dingbats", argv[1]) ||
!strcmp("symbol", argv[1]))
{
nb = ADOBE(ptr);
} else {
len = 0;
}
ptr += nb;
len = len - nb;
}
return 0;
}
/*

179
src/xutf8/utils/create_table.c

@ -1,3 +1,28 @@ @@ -1,3 +1,28 @@
/* "$Id: $"
*
* Author: Jean-Marc Lienher ( http://oksid.ch )
* Copyright 2000-2003 by O'ksi'D.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems on the following page:
*
* http://www.fltk.org/str.php
*/
#include <wchar.h>
#include <stdio.h>
char buffer[1000000];
@ -5,85 +30,83 @@ char buffer[1000000]; @@ -5,85 +30,83 @@ char buffer[1000000];
/*** you can try to modifie this value to have better performences **/
#define MAX_DELTA 0x80
int main(int argc, char **argv)
{
char buf[80];
int len;
unsigned int i = 0;
unsigned char *ptr;
size_t nb;
int nbb = 0;
len = fread(buffer, 1, 1000000, stdin);
int main(int argc, char **argv) {
char buf[80];
int len;
unsigned int i = 0;
unsigned char *ptr;
size_t nb;
int nbb = 0;
len = fread(buffer, 1, 1000000, stdin);
buffer[len] = '\0';
ptr = (unsigned char *)buffer;
while (*ptr != '\n') ptr++;
ptr++;
while (*ptr != '\n') {
if (*ptr == ',') nbb++;
ptr++;
buffer[len] = '\0';
ptr = (unsigned char *)buffer;
while (*ptr != '\n') ptr++;
ptr++;
while (*ptr != '\n') {
if (*ptr == ',') nbb++;
ptr++;
}
ptr = (unsigned char *)buffer;
printf("/* %s */\n", argv[1]);
while (len > 0) {
unsigned int ucs = 0;
char *p = ptr;
char pp[20];
nb = 0;
pp[0] = '\0';
while (*p != 'U') p++;
strncat(pp, p, 6);
*pp = '0';
*(pp+1) = 'x';
ucs = (unsigned int)strtoul(pp, NULL, 16);;
if (ucs < 1) {
printf("ERROR %d %d\n", len, ucs);
abort();
}
if (i != ucs - 1 || !i) {
if ((ucs - i) > MAX_DELTA || !i) {
if (i) {
printf("};\n");
fprintf(stderr, "\t/* end: U+%04X */\n", i);
}
ptr = (unsigned char *)buffer;
printf("/* %s */\n", argv[1]);
while (len > 0) {
unsigned int ucs = 0;
char *p = ptr;
char pp[20];
nb = 0;
pp[0] = '\0';
while (*p != 'U') p++;
strncat(pp, p, 6);
*pp = '0';
*(pp+1) = 'x';
ucs = (unsigned int)strtoul(pp, NULL, 16);;
if (ucs < 1) {
printf("ERROR %d %d\n", len, ucs);
abort();
}
if (i != ucs - 1 || !i) {
if ((ucs - i) > MAX_DELTA || !i) {
if (i) {
printf("};\n");
fprintf(stderr, "\t/* end: U+%04X */\n",
i);
}
if (strcmp(argv[1], "spacing")) {
printf("\nstatic const char"
" unicode_to_%s_%db_%04X[]"
" = {\n", argv[1], nbb, ucs);
fprintf(stderr,
"unicode_to_%s_%db_%04X[]; ",
argv[1], nbb, ucs);
} else {
printf("\nstatic const unsigned short"
" ucs_table_%04X[]"
" = {\n", ucs);
fprintf(stderr,
"ucs_table_%04X[]; ",
ucs);
}
} else {
while (i < ucs - 1) {
i++;
if (nbb == 1) {
printf("0x00,\n");
} else {
printf("0x00, 0x00,\n");
}
};
}
}
i = ucs;
while (*ptr != '\n') {
printf("%c", *ptr);
ptr++;
len--;
}
printf("\n");
ptr++;
len--;
if (strcmp(argv[1], "spacing")) {
printf("\nstatic const char unicode_to_%s_%db_%04X[] = {\n",
argv[1], nbb, ucs);
fprintf(stderr, "unicode_to_%s_%db_%04X[]; ",
argv[1], nbb, ucs);
} else {
printf("\nstatic const unsigned short"
" ucs_table_%04X[]"
" = {\n", ucs);
fprintf(stderr, "ucs_table_%04X[]; ", ucs);
}
printf("};\n");
fprintf(stderr, "\t/* end: U+%04X */\n", i);
return 0;
} else {
while (i < ucs - 1) {
i++;
if (nbb == 1) {
printf("0x00,\n");
} else {
printf("0x00, 0x00,\n");
}
};
}
}
i = ucs;
while (*ptr != '\n') {
printf("%c", *ptr);
ptr++;
len--;
}
printf("\n");
ptr++;
len--;
}
printf("};\n");
fprintf(stderr, "\t/* end: U+%04X */\n", i);
return 0;
}
/*
* End of "$Id$".
*/

54
src/xutf8/utils/euc_tw.c

@ -32,36 +32,34 @@ @@ -32,36 +32,34 @@
char uni[0x10000];
#include "../utf8Utils.c"
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
iconv_t cd;
iconv_t cd;
int i;
cd = iconv_open("EUC-TW", "UTF16");
for(i = 0; i < 0x10000; i++) uni[i] = 0;
for(i = 0x00000000; i < 0xFFFFFFFF; i++) {
char buf[4], ob[6];
char *b = buf;
int ucs = -1;
int l1 = 4, l2 = 6;
char *o = ob ;
buf[0] = i & 0xff;
buf[1] = (i >> 8) & 0xFF;
buf[2] = (i >> 16) & 0xFF;
buf[3] = (i >> 24) & 0xFF;
iconv(cd, NULL, NULL, NULL, NULL);
iconv(cd, &b, &l1, &o, &l2);
if (l2 != 6) {
ucs = (unsigned)ob[0];
ucs += (unsigned) (ob[1] << 8);
//XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
printf ("%x --> %X\n", i, ucs & 0xFFFF);
}
}
iconv_close(cd);
return 0;
int i;
cd = iconv_open("EUC-TW", "UTF16");
for(i = 0; i < 0x10000; i++) uni[i] = 0;
for(i = 0x00000000; i < 0xFFFFFFFF; i++) {
char buf[4], ob[6];
char *b = buf;
int ucs = -1;
int l1 = 4, l2 = 6;
char *o = ob ;
buf[0] = i & 0xff;
buf[1] = (i >> 8) & 0xFF;
buf[2] = (i >> 16) & 0xFF;
buf[3] = (i >> 24) & 0xFF;
iconv(cd, NULL, NULL, NULL, NULL);
iconv(cd, &b, &l1, &o, &l2);
if (l2 != 6) {
ucs = (unsigned)ob[0];
ucs += (unsigned) (ob[1] << 8);
//XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
printf ("%x --> %X\n", i, ucs & 0xFFFF);
}
}
iconv_close(cd);
return 0;
}
/*

Loading…
Cancel
Save