Make sure that clients are informed about session termination
[abduco.git] / debug.c
blobb65006c18935cf87d407a115df7f1d01dee8895c
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 for (size_t i = 0; i < pkt->len && i < sizeof(pkt->u.msg); i++)
30 fprintf(stderr, "%c", pkt->u.msg[i]);
31 break;
32 case MSG_RESIZE:
33 fprintf(stderr, "%dx%d", pkt->u.ws.ws_col, pkt->u.ws.ws_row);
34 break;
35 default:
36 fprintf(stderr, "len: %d", pkt->len);
37 break;
39 fprintf(stderr, "\n");
42 #endif /* NDEBUG */