+static int update_item(int item_num, char *buf)
+{
+ char **c = stat_content + item_num;
+
+ free(*c);
+ if (buf && buf[0])
+ goto dup;
+ switch (item_num) {
+ case SI_ARTIST:
+ *c = para_strdup("(artist tag not set)");
+ goto print;
+ case SI_TITLE:
+ *c = para_strdup("(title tag not set)");
+ goto print;
+ case SI_YEAR:
+ *c = para_strdup("????");
+ goto print;
+ case SI_ALBUM:
+ *c = para_strdup("(album tag not set)");
+ goto print;
+ case SI_COMMENT:
+ *c = para_strdup("(comment tag not set)");
+ goto print;
+ }
+dup:
+ *c = para_strdup(buf);
+print:
+ print_stat_item(item_num);
+ return 1;
+}
+
+static int read_audiod_pipe(int fd)
+{
+ static char *buf;
+ static int bufsize, loaded;
+ int ret;
+
+ if (loaded >= bufsize) {
+ if (bufsize > 1000 * 1000) {
+ loaded = 0;
+ return 0;
+ }
+ bufsize += bufsize + 1000;
+ buf = para_realloc(buf, bufsize);
+ }
+ assert(loaded < bufsize);
+ ret = read(fd, buf + loaded, bufsize - loaded);
+ if (ret <= 0)
+ return ret;
+ loaded += ret;
+ ret = for_each_stat_item(buf, loaded, update_item);
+ if (ret < 0)
+ return ret;
+ loaded = ret;
+ return 1;
+}
+