1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/* Copyright 2011 Kevin Ryde
This file is part of X11-Protocol-Other.
X11-Protocol-Other is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your option)
any later version.
X11-Protocol-Other 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 General
Public License for more details.
You should have received a copy of the GNU General Public License along
with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
int
main (void)
{
Display *display;
static char ubuf[500000];
size_t ulen;
static char cbuf[500000];
size_t clen;
static XTextProperty text_prop;
int ret;
char **tlist;
int tcount;
display = XOpenDisplay(NULL);
if (! display) { printf ("cannot open DISPLAY\n"); abort(); }
{
FILE *fp = fopen ("../tempfile.utf8","r");
if (! fp) { printf ("cannot open tempfile.utf8\n"); abort(); }
ulen = fread (ubuf, 1, sizeof(ubuf)-1, fp);
if (fclose(fp) != 0) { abort(); }
ubuf[ulen] = '\0';
}
{
FILE *fp = fopen ("../tempfile.ctext","r");
if (! fp) { printf ("cannot open tempfile.ctext\n"); abort(); }
clen = fread (cbuf, 1, sizeof(cbuf)-1, fp);
if (fclose(fp) != 0) { abort(); }
cbuf[clen] = '\0';
}
printf ("ulen %d\n", ulen);
printf ("clen %d\n", clen);
text_prop.encoding = XInternAtom(display,"COMPOUND_TEXT",0);
text_prop.format = 8;
text_prop.nitems = clen;
text_prop.value = (unsigned char *) cbuf;
ret = Xutf8TextPropertyToTextList (display,
&text_prop,
&tlist,
&tcount);
printf ("tcount %d\n", tcount);
if (ret != Success) {
printf ("Xutf8TextPropertyToTextList ret %d\n", ret);
{
FILE *fp = fopen ("../tempfile-xlib.utf8","w");
if (! fp) { printf ("cannot create ../tempfile-xlib.utf8\n"); abort(); }
if (fputs (tlist[0], fp) == EOF) { abort (); }
if (fclose(fp) != 0) { abort(); }
}
abort();
}
/* printf ("text nitems %lu\n", text_prop.nitems); */
/* printf ("text value: "); */
/* /\* for (i = 0; i < text_prop.nitems; i++) { *\/ */
/* /\* printf (" %02X", text_prop.value[i]); *\/ */
/* /\* } *\/ */
/* /\* printf ("\n"); *\/ */
/* */
return 0;
}
|