Skip to content

Commit

Permalink
Improve support for properties with COMPOUND_TEXT in icesh.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Jun 30, 2024
1 parent 7c5ff31 commit e4a32f3
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/icesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>(), type(),
Expand All @@ -744,6 +749,11 @@ class YStringProperty : public YProperty {
}
}

public:
YStringProperty(const YProperty& prop) : YProperty(prop) {
checkString(AnyPropertyType);
}

const char* operator&() const { return data<char>(); }
bool operator==(const char* str) { return *this && !strcmp(&*this, str); }
bool operator!=(const char* str) { return !operator==(str); }
Expand Down Expand Up @@ -3661,7 +3671,7 @@ void IceSh::showProperty(Window window, Atom atom, const char* prefix) {
if (prop.status() == Success && prop.data<void>()) {
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<unsigned char>(0);
if (inrange(1 + gev, 1, NUM_GUI_EVENTS)) {
Expand All @@ -3672,21 +3682,21 @@ void IceSh::showProperty(Window window, Atom atom, const char* prefix) {
char* s = prop.data<char>();
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<unsigned char>(i);
if (ch == '\0') {
if (i + 1 == prop.count()) {
break;
}
}
putchar(isPrint(ch) ? ch : '.');
YStringProperty strp(prop);
char* s = strp.data<char>();
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) {
Expand Down

0 comments on commit e4a32f3

Please sign in to comment.