Print MSG_EXIT packet exit code in debug output
[abduco.git] / debug.c
blobede5addda946cdccdc616391fc59129a0c39902d
1 #ifdef NDEBUG
2 static void debug(const char *errstr, ...) { }
3 static void print_packet(const char *prefix, Packet *pkt) { }
4 #else
6 static void debug(const char *errstr, ...) {
7 va_list ap;
8 va_start(ap, errstr);
9 vfprintf(stderr, errstr, ap);
10 va_end(ap);
13 static void print_packet(const char *prefix, Packet *pkt) {
14 static const char *msgtype[] = {
15 [MSG_CONTENT] = "CONTENT",
16 [MSG_ATTACH] = "ATTACH",
17 [MSG_DETACH] = "DETACH",
18 [MSG_RESIZE] = "RESIZE",
19 [MSG_REDRAW] = "REDRAW",
20 [MSG_EXIT] = "EXIT",
22 const char *type = "UNKNOWN";
23 if (pkt->type < countof(msgtype) && msgtype[pkt->type])
24 type = msgtype[pkt->type];
26 fprintf(stderr, "%s: %s ", prefix, type);
27 switch (pkt->type) {
28 case MSG_CONTENT:
29 fwrite(pkt->u.msg, pkt->len, 1, stderr);
30 break;
31 case MSG_RESIZE:
32 fprintf(stderr, "%"PRIu16"x%"PRIu16, pkt->u.ws.cols, pkt->u.ws.rows);
33 break;
34 case MSG_ATTACH:
35 fprintf(stderr, "readonly: %d low-priority: %d",
36 pkt->u.i & CLIENT_READONLY,
37 pkt->u.i & CLIENT_LOWPRIORITY);
38 break;
39 case MSG_EXIT:
40 fprintf(stderr, "status: %"PRIu32, pkt->u.i);
41 break;
42 default:
43 fprintf(stderr, "len: %"PRIu32, pkt->len);
44 break;
46 fprintf(stderr, "\n");
49 #endif /* NDEBUG */