X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afh.c;h=ee55cf0e603d1ff0cfa8b4f1bf55eeb8aba10098;hp=c5d7aec296a7a44b2fedfd2532ad838f89654e6c;hb=618a25011420f434f05305a4053a49824d39b4a2;hpb=1c8226eae0e976d940366cd10bd708d8e4d0bca5 diff --git a/afh.c b/afh.c index c5d7aec2..ee55cf0e 100644 --- a/afh.c +++ b/afh.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2011 Andre Noll + * Copyright (C) 2008-2012 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,7 +7,6 @@ /** \file afh.c Paraslash's standalone audio format handler tool. */ #include -#include #include #include "para.h" @@ -16,11 +15,9 @@ #include "fd.h" #include "afh.h" #include "error.h" +#include "version.h" static struct afh_args_info conf; -/** The list of all status items */ -const char *status_item_list[] = {STATUS_ITEM_ARRAY}; - INIT_AFH_ERRLISTS; static int loglevel; @@ -28,34 +25,11 @@ INIT_STDERR_LOGGING(loglevel) 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) @@ -115,12 +89,16 @@ static int cat_file(struct afh_info *afhi, int audio_format_id, return -ERRNO_TO_PARA_ERROR(EINVAL); if (!afhi->chunks_total) return 1; + /* eliminate the possibility of short writes */ + ret = mark_fd_blocking(STDOUT_FILENO); + if (ret < 0) + return ret; if (first_chunk > 0 && !conf.no_header_given) { afh_get_header(afhi, audio_format_id, audio_file_data, audio_file_size, &header, &size); if (size > 0) { PARA_INFO_LOG("writing header (%zu bytes)\n", size); - ret = write(STDOUT_FILENO, header, size); /* FIXME */ + ret = write_all(STDOUT_FILENO, header, size); afh_free_header(header, audio_format_id); if (ret < 0) return ret; @@ -148,7 +126,7 @@ static int cat_file(struct afh_info *afhi, int audio_format_id, if (!size) continue; PARA_INFO_LOG("writing chunk %lu\n", i); - ret = write_all(STDOUT_FILENO, buf, &size); + ret = write_all(STDOUT_FILENO, buf, size); if (ret < 0) return ret; } @@ -183,8 +161,10 @@ int main(int argc, char **argv) int ret2; ret = mmap_full_file(conf.inputs[i], O_RDONLY, &audio_file_data, &audio_file_size, &fd); - if (ret < 0) + if (ret < 0) { + PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf.inputs[i]); goto out; + } ret = compute_afhi(conf.inputs[i], audio_file_data, audio_file_size, fd, &afhi); if (ret < 0) @@ -201,13 +181,7 @@ int main(int argc, char **argv) print_chunk_table(&afhi); printf("\n"); } - free(afhi.techinfo); - free(afhi.tags.artist); - free(afhi.tags.title); - free(afhi.tags.year); - free(afhi.tags.album); - free(afhi.tags.comment); - free(afhi.chunk_table); + clear_afhi(&afhi); ret2 = para_munmap(audio_file_data, audio_file_size); if (ret2 < 0 && ret >= 0) ret = ret2;