From 519488decdfe224c79e7f2f18e36d2ecae2166a2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 15 Jul 2012 12:54:38 -0700 Subject: Add support for printing more types of property value Prints atoms, cardinals, integers, and windows as formatted values instead of lists of bytes. Signed-off-by: Alan Coopersmith --- prtype.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/prtype.c b/prtype.c index 8a16bfb..b1ba8ce 100644 --- a/prtype.c +++ b/prtype.c @@ -1053,8 +1053,48 @@ int PrintPropertyValues(const unsigned char *buf, uint32_t type /* atom */, uint8_t unit, uint32_t num, const char *name) { - if (type == 31 /* string */) + short fieldType = 0; + + switch (type) { + case 4: /* XA_ATOM */ + fieldType = ATOM; + break; + case 6: /* XA_CARDINAL */ + switch (unit) { + case 4: fieldType = CARD32; break; + case 2: fieldType = CARD16; break; + case 1: fieldType = CARD8; break; + default: + goto rawbytes; + } + break; + case 19: /* XA_INTEGER */ + switch (unit) { + case 4: fieldType = INT32; break; + case 2: fieldType = INT16; break; + case 1: fieldType = INT8; break; + default: + goto rawbytes; + } + break; + case 31: /* XA_STRING */ return PrintString8(buf, num * unit, name); + case 33: /* XA_WINDOW */ + fieldType = WINDOW; + break; + default: + /* Fall through to check for known non-builtin types below */ + break; + } + + if (fieldType != 0) { + if (num == 1) { + PrintField(buf, 0, unit, fieldType, name); + return unit; + } + else + return PrintList(buf, num, fieldType, name); + } else { const char *typename = FindAtomName(type); @@ -1063,11 +1103,12 @@ PrintPropertyValues(const unsigned char *buf, uint32_t type /* atom */, if (IsUTF8locale) return PrintString8(buf, num * unit, name); else - return PrintBytes(buf, num * unit, name); + goto rawbytes; } } } + rawbytes: /* When all else fails, print raw bytes */ return PrintBytes(buf, num * unit, name); } -- cgit v1.2.1