#include #include #include #include #include #include #include #include #include Display *pDisplay; Window iWindow; int main (int argc, char *argv[]) { XEvent event; XSelectionEvent eventSelection; int iReturn; if (!setlocale(LC_ALL, "ja_JP.SJIS")) { printf ("setlocale() error\n"); exit (1); } if (XSupportsLocale() == False) { printf ("Locale not supported by X\n"); exit (1); } /* Open the X display */ pDisplay = XOpenDisplay (NULL); if (pDisplay == NULL) { printf ("Could not open display\n"); exit (1); } { char* from[1]; char** to; int n; int i,j; int len; XTextProperty prop; char euc[] = { 0xa4, 0xa2, 0xa4, 0xa4, 0xa4, 0xa6, 0x61, 0x62, 0x63, 0xa4, 0xa2, 0xa4, 0xa4, 0xa4, 0xa6, 0x00 }; char sjis[] = { 0x82, 0xa0, 0x82, 0xa2, 0x82, 0xa4, 0x61, 0x62, 0x63, 0x82, 0xa0, 0x82, 0xa2, 0x82, 0xa4, 0x00 }; #if 1 from[0] = sjis; #else from[0] = euc; #endif prop.value = NULL; printf("from:"); len = strlen(from[0]); for(i = 0; i < len; ++i) { printf("0x%02x ", (unsigned char)from[0][i]); } printf("\n"); printf("%s\n", from[0]); iReturn = XmbTextListToTextProperty (pDisplay, from, 1, XCompoundTextStyle, &prop); if (iReturn == XNoMemory || iReturn == XLocaleNotSupported || iReturn == XConverterNotFound) { printf ("XmbTextListToTextProperty failed: %d\n", iReturn); exit(0); } else { printf ("XmbTextListToTextProperty: %d\n", iReturn); } printf ("%s\n", XGetAtomName(pDisplay, prop.encoding)); printf("CompoundText:"); for(i = 0; i < prop.nitems; ++i) { printf("0x%02x ", (unsigned char)prop.value[i]); } printf(".\n"); iReturn = XmbTextPropertyToTextList(pDisplay, &prop, &to, &n); if (iReturn == XNoMemory || iReturn == XLocaleNotSupported || iReturn == XConverterNotFound) { printf ("XmbTextPropertyToTextList failed: %d\n", iReturn); exit(0); } else { printf ("XmbTextPropertyToTextList: %d\n", iReturn); } printf("%d\n", n); printf("to:"); for(i = 0; i < n; ++i) { len = strlen(to[i]); for(j = 0; j < len; ++j) { printf("0x%02x ", (unsigned char)to[i][j]); } printf("\n"); } printf("%s\n", to[0]); } return 0; }