From e4a32f3d3ba0fa7dfeafedb0c74fd8381c06e0e7 Mon Sep 17 00:00:00 2001 From: Bert Gijsbers Date: Sun, 30 Jun 2024 23:23:09 +0200 Subject: [PATCH] Improve support for properties with COMPOUND_TEXT in icesh. --- src/icesh.cc | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/icesh.cc b/src/icesh.cc index 8571eedf3..889777154 100644 --- a/src/icesh.cc +++ b/src/icesh.cc @@ -725,6 +725,11 @@ class YStringProperty : public YProperty { YStringProperty(Window window, Atom property, Atom kind = AnyPropertyType) : YProperty(window, property, kind, BUFSIZ) { + checkString(kind); + } + +private: + void checkString(Atom kind) { if (status() == Success && kind == AnyPropertyType) { if (type() == ATOM_COMPOUND_TEXT) { XTextProperty text = { data(), type(), @@ -744,6 +749,11 @@ class YStringProperty : public YProperty { } } +public: + YStringProperty(const YProperty& prop) : YProperty(prop) { + checkString(AnyPropertyType); + } + const char* operator&() const { return data(); } bool operator==(const char* str) { return *this && !strcmp(&*this, str); } bool operator!=(const char* str) { return !operator==(str); } @@ -3661,7 +3671,7 @@ void IceSh::showProperty(Window window, Atom atom, const char* prefix) { if (prop.status() == Success && prop.data()) { if (prop.format() == 8) { const char* name(atomName(atom)); - printf("%s%s = ", prefix, (char*) name); + printf("%s%s = ", prefix, name); if (prop.type() == ATOM_GUI_EVENT) { int gev = prop.data(0); if (inrange(1 + gev, 1, NUM_GUI_EVENTS)) { @@ -3672,21 +3682,21 @@ void IceSh::showProperty(Window window, Atom atom, const char* prefix) { char* s = prop.data(); int num = int(prop.count()); for (int i = 0; i < num; ++i) - if (s[i] == '\0') + if (s[i] == '\0' || isWhiteSpace(s[i])) s[i] = ' '; printf("%*.*s\n", num, num, s); } else { - for (int i = 0; i < prop.count(); ++i) { - unsigned char ch = prop.data(i); - if (ch == '\0') { - if (i + 1 == prop.count()) { - break; - } - } - putchar(isPrint(ch) ? ch : '.'); + YStringProperty strp(prop); + char* s = strp.data(); + int num = int(strp.count()); + while (num > 0 && s[num - 1] == '\0') + --num; + for (int i = 0; i < num; ++i) { + if (s[i] == '\0' || isWhiteSpace(s[i])) + s[i] = ' '; } - newline(); + printf("%*.*s\n", num, num, s); } } else if (prop.format() == 32) {