+/** @brief Convert @p statebits to a string */
+char *disorder_eclient_interpret_state(unsigned long statebits) {
+ struct dynstr d[1];
+ size_t n;
+
+ static const struct {
+ unsigned long bit;
+ const char *name;
+ } bits[] = {
+ { DISORDER_PLAYING_ENABLED, "playing_enabled" },
+ { DISORDER_RANDOM_ENABLED, "random_enabled" },
+ { DISORDER_TRACK_PAUSED, "track_paused" },
+ { DISORDER_PLAYING, "playing" },
+ { DISORDER_CONNECTED, "connected" },
+ };
+#define NBITS (sizeof bits / sizeof *bits)
+
+ dynstr_init(d);
+ if(!statebits)
+ dynstr_append(d, '0');
+ for(n = 0; n < NBITS; ++n)
+ if(statebits & bits[n].bit) {
+ if(d->nvec)
+ dynstr_append(d, '|');
+ dynstr_append_string(d, bits[n].name);
+ statebits ^= bits[n].bit;
+ }
+ if(statebits) {
+ char s[20];
+
+ if(d->nvec)
+ dynstr_append(d, '|');
+ sprintf(s, "%#lx", statebits);
+ dynstr_append_string(d, s);
+ }
+ dynstr_terminate(d);
+ return d->vec;
+}
+