summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atom.c30
-rw-r--r--src/text.c98
2 files changed, 27 insertions, 101 deletions
diff --git a/src/atom.c b/src/atom.c
index 127716f..9ca307c 100644
--- a/src/atom.c
+++ b/src/atom.c
@@ -104,8 +104,8 @@ XkbcInitAtoms(void)
nodeTable[None] = NULL;
}
-char *
-XkbcAtomGetString(Atom atom)
+static char *
+_XkbcAtomGetString(Atom atom)
{
NodePtr node;
@@ -113,7 +113,31 @@ XkbcAtomGetString(Atom atom)
return NULL;
if (!(node = nodeTable[atom]))
return NULL;
- return strdup(node->string);
+ return node->string;
+}
+
+char *
+XkbcAtomGetString(Atom atom)
+{
+ char *ret = _XkbcAtomGetString(atom);
+ return ret ? strdup(ret) : NULL;
+}
+
+char *
+XkbcAtomText(Atom atom)
+{
+ char *tmp, *ret;
+
+ tmp = _XkbcAtomGetString(atom);
+ if (!tmp)
+ return "";
+
+ ret = tbGetBuffer(strlen(tmp) + 1);
+ if (!ret)
+ return "";
+
+ strcpy(ret, tmp);
+ return ret;
}
static Atom
diff --git a/src/text.c b/src/text.c
index c5804f6..0c641a5 100644
--- a/src/text.c
+++ b/src/text.c
@@ -56,104 +56,6 @@ tbGetBuffer(unsigned int size)
return rtrn;
}
-static char *
-XkbStringText(char *str)
-{
- char *buf, *in, *out;
- int len;
- Bool ok;
-
- if (!str) {
- buf = tbGetBuffer(2);
- buf[0] = '\0';
- return buf;
- }
-
- /* Find if there are any non-printable characters */
- for (ok = True, len = 0, in = str; *in != '\0'; in++, len++) {
- if (isprint(*in))
- continue;
-
- ok = False;
- switch (*in) {
- case '\n': case '\t': case '\v':
- case '\b': case '\r': case '\f':
- len++;
- break;
- default:
- /* octal: \0ooo */
- len += 4;
- break;
- }
- }
-
- if (ok)
- return str;
-
- /* Cleanup non-printable characters */
- buf = tbGetBuffer(len + 1);
- for (in = str, out = buf; *in != '\0'; in++) {
- if (isprint(*in)) {
- *out++ = *in;
- continue;
- }
-
- *out++ = '\\';
- switch (*in) {
- case '\n':
- *out++ = 'n';
- break;
- case '\t':
- *out++ = 't';
- break;
- case '\v':
- *out++ = 'v';
- break;
- case '\b':
- *out++ = 'b';
- break;
- case '\r':
- *out++ = 'r';
- break;
- case '\f':
- *out++ = 'f';
- break;
- default:
- *out++ = '0';
- snprintf(out, 3, "%o", *in);
- while (*out != '\0')
- out++;
- }
- }
-
- *out++ = '\0';
- return buf;
-}
-
-char *
-XkbcAtomText(Atom atm)
-{
- char *tmp, *rtrn;
- int len;
-
- tmp = XkbcAtomGetString(atm);
-
- if (!tmp)
- return "";
-
- len = strlen(tmp) + 1;
- if (len >= BUFFER_SIZE)
- len = BUFFER_SIZE - 2;
-
- rtrn = tbGetBuffer(len);
- strncpy(rtrn, tmp, len);
- rtrn[len] = '\0';
-
- _XkbFree(tmp);
-
- return XkbStringText(rtrn);
-}
-
char *
XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx)
{