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. 78
      src/xutf8/is_right2left.c
  3. 109
      src/xutf8/is_spacing.c
  4. 6
      src/xutf8/keysym2Ucs.c
  5. 379
      src/xutf8/test.c
  6. 285
      src/xutf8/test2.c
  7. 13
      src/xutf8/ucs2fontmap.c
  8. 649
      src/xutf8/utf8Input.c
  9. 333
      src/xutf8/utf8Utils.c
  10. 1509
      src/xutf8/utf8Wrap.c
  11. 268
      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 @@
#include "headers/case.h" #include "headers/case.h"
#include <stdlib.h> #include <stdlib.h>
int int
XUtf8Tolower( XUtf8Tolower(int ucs) {
int ucs) int ret;
{ if (ucs <= 0x02B6) {
int ret; if (ucs >= 0x0041) {
ret = ucs_table_0041[ucs - 0x0041];
if (ucs <= 0x02B6) { if (ret > 0) return ret;
if (ucs >= 0x0041) { }
ret = ucs_table_0041[ucs - 0x0041]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x0556) {
} if (ucs >= 0x0386) {
ret = ucs_table_0386[ucs - 0x0386];
if (ucs <= 0x0556) { if (ret > 0) return ret;
if (ucs >= 0x0386) { }
ret = ucs_table_0386[ucs - 0x0386]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x10C5) {
} if (ucs >= 0x10A0) {
ret = ucs_table_10A0[ucs - 0x10A0];
if (ucs <= 0x10C5) { if (ret > 0) return ret;
if (ucs >= 0x10A0) { }
ret = ucs_table_10A0[ucs - 0x10A0]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x1FFC) {
} if (ucs >= 0x1E00) {
ret = ucs_table_1E00[ucs - 0x1E00];
if (ucs <= 0x1FFC) { if (ret > 0) return ret;
if (ucs >= 0x1E00) { }
ret = ucs_table_1E00[ucs - 0x1E00]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x2133) {
} if (ucs >= 0x2102) {
ret = ucs_table_2102[ucs - 0x2102];
if (ucs <= 0x2133) { if (ret > 0) return ret;
if (ucs >= 0x2102) { }
ret = ucs_table_2102[ucs - 0x2102]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x24CF) {
} if (ucs >= 0x24B6) {
ret = ucs_table_24B6[ucs - 0x24B6];
if (ucs <= 0x24CF) { if (ret > 0) return ret;
if (ucs >= 0x24B6) { }
ret = ucs_table_24B6[ucs - 0x24B6]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0x33CE) {
} if (ucs >= 0x33CE) {
ret = ucs_table_33CE[ucs - 0x33CE];
if (ucs <= 0x33CE) { if (ret > 0) return ret;
if (ucs >= 0x33CE) { }
ret = ucs_table_33CE[ucs - 0x33CE]; return ucs;
if (ret > 0) return ret; }
}
return ucs; if (ucs <= 0xFF3A) {
} if (ucs >= 0xFF21) {
ret = ucs_table_FF21[ucs - 0xFF21];
if (ucs <= 0xFF3A) { if (ret > 0) return ret;
if (ucs >= 0xFF21) { }
ret = ucs_table_FF21[ucs - 0xFF21]; return ucs;
if (ret > 0) return ret; }
}
return ucs; return ucs;
}
return ucs;
} }
int int
XUtf8Toupper( XUtf8Toupper(int ucs) {
int ucs) int i;
{ static unsigned short *table = NULL;
int i;
static unsigned short *table = NULL; if (!table) {
table = (unsigned short*) malloc(sizeof(unsigned short) * 0x10000);
if (!table) { for (i = 0; i < 0x10000; i++) {
table = (unsigned short*) malloc( table[i] = (unsigned short) i;
sizeof(unsigned short) * 0x10000); }
for (i = 0; i < 0x10000; i++) { for (i = 0; i < 0x10000; i++) {
table[i] = (unsigned short) i; int l;
} l = XUtf8Tolower(i);
for (i = 0; i < 0x10000; i++) { if (l != i) table[l] = (unsigned short) i;
int l; }
l = XUtf8Tolower(i); }
if (l != i) table[l] = (unsigned short) i; if (ucs >= 0x10000 || ucs < 0) return ucs;
} return table[ucs];
}
if (ucs >= 0x10000 || ucs < 0) return ucs;
return table[ucs];
} }
/* /*
* End of "$Id$". * End of "$Id$".
*/ */

78
src/xutf8/is_right2left.c

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

109
src/xutf8/is_spacing.c

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

6
src/xutf8/keysym2Ucs.c

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

379
src/xutf8/test.c

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

285
src/xutf8/test2.c

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

649
src/xutf8/utf8Input.c

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

333
src/xutf8/utf8Utils.c

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

1509
src/xutf8/utf8Wrap.c

File diff suppressed because it is too large Load Diff

268
src/xutf8/utils/conv_gen.c

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

260
src/xutf8/utils/convert_map.c

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

179
src/xutf8/utils/create_table.c

@ -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 <wchar.h>
#include <stdio.h> #include <stdio.h>
char buffer[1000000]; char buffer[1000000];
@ -5,85 +30,83 @@ char buffer[1000000];
/*** you can try to modifie this value to have better performences **/ /*** you can try to modifie this value to have better performences **/
#define MAX_DELTA 0x80 #define MAX_DELTA 0x80
int main(int argc, char **argv) int main(int argc, char **argv) {
{ char buf[80];
char buf[80]; int len;
int len; unsigned int i = 0;
unsigned int i = 0; unsigned char *ptr;
unsigned char *ptr; size_t nb;
size_t nb; int nbb = 0;
int nbb = 0; len = fread(buffer, 1, 1000000, stdin);
len = fread(buffer, 1, 1000000, stdin);
buffer[len] = '\0'; buffer[len] = '\0';
ptr = (unsigned char *)buffer; ptr = (unsigned char *)buffer;
while (*ptr != '\n') ptr++; while (*ptr != '\n') ptr++;
ptr++; ptr++;
while (*ptr != '\n') { while (*ptr != '\n') {
if (*ptr == ',') nbb++; if (*ptr == ',') nbb++;
ptr++; 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; if (strcmp(argv[1], "spacing")) {
printf("/* %s */\n", argv[1]); printf("\nstatic const char unicode_to_%s_%db_%04X[] = {\n",
while (len > 0) { argv[1], nbb, ucs);
unsigned int ucs = 0; fprintf(stderr, "unicode_to_%s_%db_%04X[]; ",
char *p = ptr; argv[1], nbb, ucs);
char pp[20]; } else {
nb = 0; printf("\nstatic const unsigned short"
pp[0] = '\0'; " ucs_table_%04X[]"
while (*p != 'U') p++; " = {\n", ucs);
strncat(pp, p, 6); fprintf(stderr, "ucs_table_%04X[]; ", ucs);
*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--;
} }
printf("};\n"); } else {
fprintf(stderr, "\t/* end: U+%04X */\n", i); while (i < ucs - 1) {
return 0; 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 @@
char uni[0x10000]; char uni[0x10000];
#include "../utf8Utils.c" #include "../utf8Utils.c"
int main(int argc, char **argv) int main(int argc, char **argv) {
{
iconv_t cd; iconv_t cd;
int i; int i;
cd = iconv_open("EUC-TW", "UTF16"); cd = iconv_open("EUC-TW", "UTF16");
for(i = 0; i < 0x10000; i++) uni[i] = 0; for(i = 0; i < 0x10000; i++) uni[i] = 0;
for(i = 0x00000000; i < 0xFFFFFFFF; i++) { for(i = 0x00000000; i < 0xFFFFFFFF; i++) {
char buf[4], ob[6]; char buf[4], ob[6];
char *b = buf; char *b = buf;
int ucs = -1; int ucs = -1;
int l1 = 4, l2 = 6; int l1 = 4, l2 = 6;
char *o = ob ; char *o = ob ;
buf[0] = i & 0xff; buf[0] = i & 0xff;
buf[1] = (i >> 8) & 0xFF; buf[1] = (i >> 8) & 0xFF;
buf[2] = (i >> 16) & 0xFF; buf[2] = (i >> 16) & 0xFF;
buf[3] = (i >> 24) & 0xFF; buf[3] = (i >> 24) & 0xFF;
iconv(cd, NULL, NULL, NULL, NULL); iconv(cd, NULL, NULL, NULL, NULL);
iconv(cd, &b, &l1, &o, &l2); iconv(cd, &b, &l1, &o, &l2);
if (l2 != 6) { if (l2 != 6) {
ucs = (unsigned)ob[0]; ucs = (unsigned)ob[0];
ucs += (unsigned) (ob[1] << 8); ucs += (unsigned) (ob[1] << 8);
//XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs); //XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
printf ("%x --> %X\n", i, ucs & 0xFFFF); printf ("%x --> %X\n", i, ucs & 0xFFFF);
} }
}
} iconv_close(cd);
iconv_close(cd); return 0;
return 0;
} }
/* /*

Loading…
Cancel
Save