static void print_info(int audio_format_num, struct afh_info *afhi)
{
- printf("%s: %dkbit/s\n" /* bitrate */
- "%s: %s\n" /* format */
- "%s: %dHz\n" /* frequency */
- "%s: %d\n" /* channels */
- "%s: %lu\n" /* seconds total */
- "%s: %lu: %lu\n" /* chunk time */
- "%s: %lu\n" /* num chunks */
- "%s: %s\n" /* techinfo */
- "%s: %s\n" /* artist */
- "%s: %s\n" /* title */
- "%s: %s\n" /* year */
- "%s: %s\n" /* album */
- "%s: %s\n", /* comment */
- status_item_list[SI_BITRATE], afhi->bitrate,
- status_item_list[SI_FORMAT], audio_format_name(audio_format_num),
- status_item_list[SI_FREQUENCY], afhi->frequency,
- status_item_list[SI_CHANNELS], afhi->channels,
- status_item_list[SI_SECONDS_TOTAL], afhi->seconds_total,
- status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec,
- (long unsigned)afhi->chunk_tv.tv_usec,
- status_item_list[SI_NUM_CHUNKS], afhi->chunks_total,
- status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "",
- status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "",
- status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "",
- status_item_list[SI_YEAR], afhi->tags.year? afhi->tags.year : "",
- status_item_list[SI_ALBUM], afhi->tags.album? afhi->tags.album : "",
- status_item_list[SI_COMMENT], afhi->tags.comment? afhi->tags.comment : ""
- );
+ char *msg;
+
+ afh_get_afhi_txt(audio_format_num, afhi, &msg);
+ printf("%s", msg);
+ free(msg);
}
static void print_chunk_table(struct afh_info *afhi)
void *map, size_t mapsize, char **buf, size_t *len);
void afh_free_header(char *header_buf, uint8_t audio_format_id);
void clear_afhi(struct afh_info *afhi);
+unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **result);
if (afh->get_header)
free(header_buf);
}
+
+/**
+ * Pretty-print the contents of a struct afh_info into a buffer.
+ *
+ * \param audio_format_num The audio format number.
+ * \param afhi Pointer to the structure that contains the information.
+ * \param result Pretty-printed ahfi is here after the call.
+ *
+ * The \a result buffer is dynamically allocated and should be freed by the
+ * caller.
+ *
+ * \return The number of bytes. This function never fails.
+ */
+unsigned afh_get_afhi_txt(int audio_format_num, struct afh_info *afhi, char **result)
+{
+ return xasprintf(result, "%s: %dkbit/s\n" /* bitrate */
+ "%s: %s\n" /* format */
+ "%s: %dHz\n" /* frequency */
+ "%s: %d\n" /* channels */
+ "%s: %lu\n" /* seconds total */
+ "%s: %lu: %lu\n" /* chunk time */
+ "%s: %lu\n" /* num chunks */
+ "%s: %s\n" /* techinfo */
+ "%s: %s\n" /* artist */
+ "%s: %s\n" /* title */
+ "%s: %s\n" /* year */
+ "%s: %s\n" /* album */
+ "%s: %s\n", /* comment */
+ status_item_list[SI_BITRATE], afhi->bitrate,
+ status_item_list[SI_FORMAT], audio_format_name(audio_format_num),
+ status_item_list[SI_FREQUENCY], afhi->frequency,
+ status_item_list[SI_CHANNELS], afhi->channels,
+ status_item_list[SI_SECONDS_TOTAL], afhi->seconds_total,
+ status_item_list[SI_CHUNK_TIME], (long unsigned)afhi->chunk_tv.tv_sec,
+ (long unsigned)afhi->chunk_tv.tv_usec,
+ status_item_list[SI_NUM_CHUNKS], afhi->chunks_total,
+ status_item_list[SI_TECHINFO], afhi->techinfo? afhi->techinfo : "",
+ status_item_list[SI_ARTIST], afhi->tags.artist? afhi->tags.artist : "",
+ status_item_list[SI_TITLE], afhi->tags.title? afhi->tags.title : "",
+ status_item_list[SI_YEAR], afhi->tags.year? afhi->tags.year : "",
+ status_item_list[SI_ALBUM], afhi->tags.album? afhi->tags.album : "",
+ status_item_list[SI_COMMENT], afhi->tags.comment? afhi->tags.comment : ""
+ );
+}