abduco

Fork of abduco for persistent terminal sessions
git clone git://git.laack.co/abduco.git
Log | Files | Refs | README | LICENSE

debug.c (1273B)


      1 #ifdef NDEBUG
      2 static void debug(const char *errstr, ...) { }
      3 static void print_packet(const char *prefix, Packet *pkt) { }
      4 #else
      5 
      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);
     11 }
     12 
     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_EXIT]    = "EXIT",
     20 		[MSG_PID]     = "PID",
     21 	};
     22 	const char *type = "UNKNOWN";
     23 	if (pkt->type < countof(msgtype) && msgtype[pkt->type])
     24 		type = msgtype[pkt->type];
     25 
     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 	case MSG_PID:
     43 		fprintf(stderr, "pid: %"PRIu32, pkt->u.i);
     44 		break;
     45 	default:
     46 		fprintf(stderr, "len: %"PRIu32, pkt->len);
     47 		break;
     48 	}
     49 	fprintf(stderr, "\n");
     50 }
     51 
     52 #endif /* NDEBUG */