aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c')
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c186
1 files changed, 113 insertions, 73 deletions
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c
index 942719d8ee..2a5c854494 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_textlist.c
@@ -8,40 +8,59 @@
# define CODESET "INVALID"
#endif
-static int _ecore_xcb_textlist_get_buffer_size(Eina_Bool is_wide, void *list, int count);
-static int _ecore_xcb_textlist_get_wc_len(wchar_t *wstr);
-static void *_ecore_xcb_textlist_alloc_list(Eina_Bool is_wide, int count, int nitems);
-static void _ecore_xcb_textlist_copy_list(Eina_Bool is_wide, void *text, char **list, int count);
-static wchar_t *_ecore_xcb_textlist_copy_wchar(wchar_t *str1, wchar_t *str2);
-static int _ecore_xcb_textlist_len_wchar(wchar_t *str);
+static int _ecore_xcb_textlist_get_buffer_size(Eina_Bool is_wide,
+ void *list,
+ int count);
+static int _ecore_xcb_textlist_get_wc_len(wchar_t *wstr);
+static void *_ecore_xcb_textlist_alloc_list(Eina_Bool is_wide,
+ int count,
+ int nitems);
+static void _ecore_xcb_textlist_copy_list(Eina_Bool is_wide,
+ void *text,
+ char **list,
+ int count);
+static wchar_t *_ecore_xcb_textlist_copy_wchar(wchar_t *str1,
+ wchar_t *str2);
+static int _ecore_xcb_textlist_len_wchar(wchar_t *str);
#ifdef HAVE_ICONV
-Eina_Bool
-_ecore_xcb_utf8_textlist_to_textproperty(char **list, int count, Ecore_Xcb_Encoding_Style style, Ecore_Xcb_Textproperty *ret)
+Eina_Bool
+_ecore_xcb_utf8_textlist_to_textproperty(char **list,
+ int count,
+ Ecore_Xcb_Encoding_Style style,
+ Ecore_Xcb_Textproperty *ret)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
- return _ecore_xcb_textlist_to_textproperty("utf8string", list, count,
+ return _ecore_xcb_textlist_to_textproperty("utf8string", list, count,
style, ret);
}
+
#endif
-Eina_Bool
-_ecore_xcb_mb_textlist_to_textproperty(char **list, int count, Ecore_Xcb_Encoding_Style style, Ecore_Xcb_Textproperty *ret)
+Eina_Bool
+_ecore_xcb_mb_textlist_to_textproperty(char **list,
+ int count,
+ Ecore_Xcb_Encoding_Style style,
+ Ecore_Xcb_Textproperty *ret)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
- return _ecore_xcb_textlist_to_textproperty("multiByte", list, count,
+ return _ecore_xcb_textlist_to_textproperty("multiByte", list, count,
style, ret);
}
-/* NB: This Function May Not Be Correct !!!
+/* NB: This Function May Not Be Correct !!!
* (as I do not know text conversion, locales, etc, etc very well)
- *
+ *
* Portions were ripped from libX11 XTextListToTextProperty
*/
-Eina_Bool
-_ecore_xcb_textlist_to_textproperty(const char *type, char **list, int count, Ecore_Xcb_Encoding_Style style, Ecore_Xcb_Textproperty *ret)
+Eina_Bool
+_ecore_xcb_textlist_to_textproperty(const char *type,
+ char **list,
+ int count,
+ Ecore_Xcb_Encoding_Style style,
+ Ecore_Xcb_Textproperty *ret)
{
Eina_Bool is_wide = EINA_FALSE;
Ecore_X_Atom encoding;
@@ -62,7 +81,7 @@ _ecore_xcb_textlist_to_textproperty(const char *type, char **list, int count, Ec
len = _ecore_xcb_textlist_get_buffer_size(is_wide, list, count);
if (!(buff = (char *)malloc(len * sizeof(char)))) return EINA_FALSE;
from_type = nl_langinfo(CODESET);
- switch (style)
+ switch (style)
{
case XcbStringStyle:
case XcbStdICCTextStyle:
@@ -70,25 +89,28 @@ _ecore_xcb_textlist_to_textproperty(const char *type, char **list, int count, Ec
to_type = nl_langinfo(CODESET);
// to_type = "string";
break;
+
case XcbUTF8StringStyle:
encoding = ECORE_X_ATOM_UTF8_STRING;
to_type = "UTF-8";
break;
+
case XcbCompoundTextStyle:
encoding = ECORE_X_ATOM_COMPOUND_TEXT;
to_type = nl_langinfo(CODESET);
// to_type = "compoundText";
break;
+
case XcbTextStyle:
encoding = ECORE_X_ATOM_TEXT;
to_type = nl_langinfo(CODESET);
// to_type = "multiByte";
- if (!is_wide)
+ if (!is_wide)
{
nitems = 0;
mb = (char **)list;
to = buff;
- for (i = 0; ((i < count) && (len > 0)); i++)
+ for (i = 0; ((i < count) && (len > 0)); i++)
{
if (*mb) strcpy(to, *mb);
else *to = '\0';
@@ -101,13 +123,14 @@ _ecore_xcb_textlist_to_textproperty(const char *type, char **list, int count, Ec
goto done;
}
break;
+
default:
free(buff);
return EINA_FALSE;
break;
}
- if (count < 1)
+ if (count < 1)
{
nitems = 0;
goto done;
@@ -126,15 +149,15 @@ retry:
to = buff;
to_left = len;
unconv_num = 0;
- for (i = 1; to_left > 0; i++)
+ for (i = 1; to_left > 0; i++)
{
- if (is_wide)
+ if (is_wide)
{
from = (char *)*wc;
from_left = _ecore_xcb_textlist_get_wc_len(*wc);
wc++;
}
- else
+ else
{
from = *mb;
from_left = (*mb ? strlen(*mb) : 0);
@@ -145,8 +168,8 @@ retry:
val = iconv(conv, &from, &from_left, &to, &to_left);
#endif
if (val < 0) continue;
- if ((val > 0) && (style == XcbStdICCTextStyle) &&
- (encoding == ECORE_X_ATOM_STRING))
+ if ((val > 0) && (style == XcbStdICCTextStyle) &&
+ (encoding == ECORE_X_ATOM_STRING))
{
#ifdef HAVE_ICONV
iconv_close(conv);
@@ -157,7 +180,7 @@ retry:
unconv_num += val;
*to++ = '\0';
- to_left --;
+ to_left--;
if (i >= count) break;
}
@@ -168,12 +191,12 @@ retry:
done:
if (nitems <= 0) nitems = 1;
- if (!(value = (char *)malloc(nitems * sizeof(char))))
+ if (!(value = (char *)malloc(nitems * sizeof(char))))
{
free(buff);
return EINA_FALSE;
}
- if (nitems == 1)
+ if (nitems == 1)
*value = 0;
else
memcpy(value, buff, nitems);
@@ -189,27 +212,35 @@ done:
}
#ifdef HAVE_ICONV
-Eina_Bool
-_ecore_xcb_utf8_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, char ***list_ret, int *count_ret)
+Eina_Bool
+_ecore_xcb_utf8_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
+ char ***list_ret,
+ int *count_ret)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
- return _ecore_xcb_textproperty_to_textlist(text_prop, "utf8String",
+ return _ecore_xcb_textproperty_to_textlist(text_prop, "utf8String",
list_ret, count_ret);
}
+
#endif
-Eina_Bool
-_ecore_xcb_mb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, char ***list_ret, int *count_ret)
+Eina_Bool
+_ecore_xcb_mb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
+ char ***list_ret,
+ int *count_ret)
{
LOGFN(__FILE__, __LINE__, __FUNCTION__);
- return _ecore_xcb_textproperty_to_textlist(text_prop, "multiByte",
+ return _ecore_xcb_textproperty_to_textlist(text_prop, "multiByte",
list_ret, count_ret);
}
-Eina_Bool
-_ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, const char *type, char ***list_ret, int *count_ret)
+Eina_Bool
+_ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop,
+ const char *type,
+ char ***list_ret,
+ int *count_ret)
{
Eina_Bool is_wide = EINA_FALSE;
Eina_Bool do_strcpy = EINA_FALSE;
@@ -237,7 +268,7 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
if (is_wide)
len = (text_prop->nitems + 1) * sizeof(wchar_t);
- else
+ else
{
if (!strcmp(type, "utf8String"))
len = text_prop->nitems * 6 + 1;
@@ -253,12 +284,12 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
if (!strcmp(from_type, type))
do_strcpy = EINA_TRUE;
- else
+ else
{
#ifdef HAVE_ICONV
conv = iconv_open(type, from_type);
#endif
- if (!conv)
+ if (!conv)
{
free(buff);
return EINA_FALSE;
@@ -267,14 +298,14 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
lptr = sptr = text_prop->value;
num = *count_ret = 0;
- while (1)
+ while (1)
{
- if ((nitems == 0) || (*sptr == 0))
+ if ((nitems == 0) || (*sptr == 0))
{
from = lptr;
from_left = sptr - lptr;
lptr = sptr;
- if (do_strcpy)
+ if (do_strcpy)
{
int l = 0;
@@ -294,13 +325,13 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
(*count_ret)++;
if (nitems == 0) break;
lptr = ++sptr;
- if (is_wide)
+ if (is_wide)
{
*((wchar_t *)to) = (wchar_t)0;
to += sizeof(wchar_t);
to_left -= sizeof(wchar_t);
}
- else
+ else
{
*((char *)to) = '\0';
to++;
@@ -317,20 +348,20 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
if (!do_strcpy) iconv_close(conv);
#endif
- if (is_wide)
+ if (is_wide)
{
*((wchar_t *)to) = (wchar_t)0;
to_left -= sizeof(wchar_t);
}
- else
+ else
{
*((char *)to) = '\0';
to_left--;
}
- *list_ret =
+ *list_ret =
_ecore_xcb_textlist_alloc_list(is_wide, *count_ret, (len - to_left));
- if (*list_ret)
+ if (*list_ret)
_ecore_xcb_textlist_copy_list(is_wide, buff, *list_ret, *count_ret);
free(buff);
@@ -338,22 +369,24 @@ _ecore_xcb_textproperty_to_textlist(const Ecore_Xcb_Textproperty *text_prop, con
return EINA_TRUE;
}
-static int
-_ecore_xcb_textlist_get_buffer_size(Eina_Bool is_wide, void *list, int count)
+static int
+_ecore_xcb_textlist_get_buffer_size(Eina_Bool is_wide,
+ void *list,
+ int count)
{
int len = 0;
char **mb;
wchar_t **wc;
if (!list) return 0;
- if (is_wide)
+ if (is_wide)
{
wc = (wchar_t **)list;
- for (; count-- > 0; wc++)
- if (*wc) len += _ecore_xcb_textlist_get_wc_len(*wc) + 1;
+ for (; count-- > 0; wc++)
+ if (*wc) len += _ecore_xcb_textlist_get_wc_len(*wc) + 1;
len *= 5;
}
- else
+ else
{
mb = (char **)list;
for (; count-- > 0; mb++)
@@ -364,8 +397,8 @@ _ecore_xcb_textlist_get_buffer_size(Eina_Bool is_wide, void *list, int count)
return len;
}
-static int
-_ecore_xcb_textlist_get_wc_len(wchar_t *wstr)
+static int
+_ecore_xcb_textlist_get_wc_len(wchar_t *wstr)
{
wchar_t *ptr;
@@ -373,34 +406,36 @@ _ecore_xcb_textlist_get_wc_len(wchar_t *wstr)
while (*ptr)
ptr++;
- return (ptr - wstr);
+ return ptr - wstr;
}
static void *
-_ecore_xcb_textlist_alloc_list(Eina_Bool is_wide, int count, int nitems)
+_ecore_xcb_textlist_alloc_list(Eina_Bool is_wide,
+ int count,
+ int nitems)
{
- if (is_wide)
+ if (is_wide)
{
wchar_t **list;
list = (wchar_t **)malloc(count * sizeof(wchar_t *));
if (!list) return NULL;
*list = (wchar_t *)malloc(nitems * sizeof(wchar_t));
- if (!*list)
+ if (!*list)
{
free(list);
return NULL;
}
return *list;
}
- else
+ else
{
char **list;
list = (char **)malloc(count * sizeof(char *));
if (!list) return NULL;
*list = (char *)malloc(nitems * sizeof(char));
- if (!*list)
+ if (!*list)
{
free(list);
return NULL;
@@ -409,18 +444,21 @@ _ecore_xcb_textlist_alloc_list(Eina_Bool is_wide, int count, int nitems)
}
}
-static void
-_ecore_xcb_textlist_copy_list(Eina_Bool is_wide, void *text, char **list, int count)
+static void
+_ecore_xcb_textlist_copy_list(Eina_Bool is_wide,
+ void *text,
+ char **list,
+ int count)
{
int len = 0;
- if (is_wide)
+ if (is_wide)
{
wchar_t *txt, *str, **wlist;
txt = (wchar_t *)text;
wlist = (wchar_t **)list;
- for (str = *wlist; count > 0; count--, wlist++)
+ for (str = *wlist; count > 0; count--, wlist++)
{
_ecore_xcb_textlist_copy_wchar(str, txt);
*wlist = str;
@@ -429,13 +467,13 @@ _ecore_xcb_textlist_copy_list(Eina_Bool is_wide, void *text, char **list, int co
txt += len;
}
}
- else
+ else
{
char *txt, *str, **slist;
txt = (char *)text;
slist = (char **)list;
- for (str = *slist; count > 0; count--, slist++)
+ for (str = *slist; count > 0; count--, slist++)
{
strcpy(str, txt);
*slist = str;
@@ -447,7 +485,8 @@ _ecore_xcb_textlist_copy_list(Eina_Bool is_wide, void *text, char **list, int co
}
static wchar_t *
-_ecore_xcb_textlist_copy_wchar(wchar_t *str1, wchar_t *str2)
+_ecore_xcb_textlist_copy_wchar(wchar_t *str1,
+ wchar_t *str2)
{
wchar_t *tmp;
@@ -457,13 +496,14 @@ _ecore_xcb_textlist_copy_wchar(wchar_t *str1, wchar_t *str2)
return tmp;
}
-static int
-_ecore_xcb_textlist_len_wchar(wchar_t *str)
+static int
+_ecore_xcb_textlist_len_wchar(wchar_t *str)
{
wchar_t *ptr;
ptr = str;
- while (*ptr)
+ while (*ptr)
ptr++;
- return (ptr - str);
+ return ptr - str;
}
+