forked from github/abduco
Clean up debug packet printing code
This commit is contained in:
parent
6000bc6240
commit
3aa08a2d89
49
debug.c
49
debug.c
|
|
@ -11,39 +11,32 @@ static void debug(const char *errstr, ...) {
|
|||
}
|
||||
|
||||
static void print_packet(const char *prefix, Packet *pkt) {
|
||||
// XXX: look up table
|
||||
char *s = "UNKNOWN";
|
||||
static const char *msgtype[] = {
|
||||
[MSG_CONTENT] = "CONTENT",
|
||||
[MSG_ATTACH] = "ATTACH",
|
||||
[MSG_DETACH] = "DETACH",
|
||||
[MSG_RESIZE] = "RESIZE",
|
||||
[MSG_REDRAW] = "REDRAW",
|
||||
[MSG_EXIT] = "EXIT",
|
||||
};
|
||||
const char *type = "UNKNOWN";
|
||||
if (pkt->type < countof(msgtype) && msgtype[pkt->type])
|
||||
type = msgtype[pkt->type];
|
||||
|
||||
fprintf(stderr, "%s: %s ", prefix, type);
|
||||
switch (pkt->type) {
|
||||
case MSG_CONTENT:
|
||||
s = "CONTENT";
|
||||
break;
|
||||
case MSG_ATTACH:
|
||||
s = "ATTACH";
|
||||
break;
|
||||
case MSG_DETACH:
|
||||
s = "DETACH";
|
||||
break;
|
||||
case MSG_RESIZE:
|
||||
s = "RESIZE";
|
||||
break;
|
||||
case MSG_REDRAW:
|
||||
s = "REDRAW";
|
||||
break;
|
||||
case MSG_EXIT:
|
||||
s = "EXIT";
|
||||
break;
|
||||
}
|
||||
|
||||
if (pkt->type == MSG_CONTENT) {
|
||||
fprintf(stderr, "%s %s len: %d content: ", prefix, s, pkt->len);
|
||||
for (size_t i = 0; i < pkt->len && i < sizeof(pkt->u.msg); i++)
|
||||
fprintf(stderr, "%c", pkt->u.msg[i]);
|
||||
fprintf(stderr, "\n");
|
||||
} else if (pkt->type == MSG_RESIZE) {
|
||||
fprintf(stderr, "%s %s %d x %d\n", prefix, s, pkt->u.ws.ws_col, pkt->u.ws.ws_row);
|
||||
} else {
|
||||
fprintf(stderr, "%s %s len: %d\n", prefix, s, pkt->len);
|
||||
break;
|
||||
case MSG_RESIZE:
|
||||
fprintf(stderr, "%dx%d", pkt->u.ws.ws_col, pkt->u.ws.ws_row);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "len: %d", pkt->len);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#endif /* NDEBUG */
|
||||
|
|
|
|||
Loading…
Reference in New Issue