X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afh.c;h=c896a7d1eff4a843e2e61a4ec8b6dac4982ed197;hp=8279c577b9afde0354b2a9b8a8f6744c83523905;hb=e65afce0dd0b070ea03ae778fef54e7c3d477d15;hpb=37fa57410c415be3b00d99c373b004959c6586fe diff --git a/afh.c b/afh.c index 8279c577..c896a7d1 100644 --- a/afh.c +++ b/afh.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2008 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2008 Andre Noll , see file COPYING. */ /** \file afh.c Paraslash's standalone audio format handler tool. */ @@ -20,7 +16,7 @@ /** Array of error strings. */ DEFINE_PARA_ERRLIST; -struct lls_parse_result *lpr; +static struct lls_parse_result *lpr; #define CMD_PTR (lls_cmd(0, afh_suite)) #define OPT_RESULT(_name) (lls_opt_result(LSG_AFH_PARA_AFH_OPT_ ## _name, lpr)) @@ -117,6 +113,24 @@ static int rewrite_tags(const char *name, int input_fd, void *map, goto out; } ret = xrename(tmp_name, name); + if (ret < 0) + goto out; + if (OPT_GIVEN(PRESERVE)) { + struct timespec times[2]; /* [0]: atime, [1]: mtime */ + times[0].tv_nsec = UTIME_OMIT; + times[1] = sb.st_mtim; + /* + * We might well have written a file of identical size. If we + * keep the mtime as well, we might fool backup applications + * like rsync which skip files whose size and mtime haven't + * changed. So we change the mtime slightly. + */ + times[1].tv_sec++; + if (futimens(output_fd, times) < 0) { + ret = -ERRNO_TO_PARA_ERROR(errno); + goto out; + } + } out: if (ret < 0 && output_fd >= 0) unlink(tmp_name); /* ignore errors */ @@ -135,29 +149,38 @@ static void print_info(int audio_format_num, struct afh_info *afhi) free(msg); } -static void print_chunk_table(struct afh_info *afhi) +static void print_chunk_table(struct afh_info *afhi, int audio_format_id, + const void *map, size_t mapsize) { - int i; + int i, ret; + void *ctx = NULL; - if (OPT_GIVEN(PARSER_FRIENDLY)) { - printf("chunk_table: "); - for (i = 0; i <= afhi->chunks_total; i++) - printf("%u ", afhi->chunk_table[i]); - printf("\n"); - return; - } - for (i = 1; i <= afhi->chunks_total; i++) { + for (i = 0; i < afhi->chunks_total; i++) { struct timeval tv; long unsigned from, to; - tv_scale(i - 1, &afhi->chunk_tv, &tv); - from = tv2ms(&tv); + const char *buf; + size_t len; tv_scale(i, &afhi->chunk_tv, &tv); + from = tv2ms(&tv); + tv_scale(i + 1, &afhi->chunk_tv, &tv); to = tv2ms(&tv); - printf("%d [%lu.%03lu - %lu.%03lu] %u - %u (%u)\n", i - 1, - from / 1000, from % 1000, to / 1000, to % 1000, - afhi->chunk_table[i - 1], afhi->chunk_table[i], - afhi->chunk_table[i] - afhi->chunk_table[i - 1]); + ret = afh_get_chunk(i, afhi, audio_format_id, map, mapsize, + &buf, &len, &ctx); + if (ret < 0) { + PARA_ERROR_LOG("fatal: chunk %d: %s\n", i, + para_strerror(-ret)); + return; + } + if (!OPT_GIVEN(PARSER_FRIENDLY)) + printf("%d [%lu.%03lu - %lu.%03lu] ", i, from / 1000, + from % 1000, to / 1000, to % 1000); + printf("%td - %td", buf - (const char *)map, + buf + len - (const char *)map); + if (!OPT_GIVEN(PARSER_FRIENDLY)) + printf(" (%zu)", len); + printf("\n"); } + afh_close(ctx, audio_format_id); } static void handle_help_flags(void) @@ -198,7 +221,6 @@ int main(int argc, char **argv) loglevel = OPT_UINT32_VAL(LOGLEVEL); version_handle_flag("afh", OPT_GIVEN(VERSION)); handle_help_flags(); - afh_init(); for (i = 0; i < lls_num_inputs(lpr); i++) { int ret2; const char *path = lls_input(i, lpr); @@ -219,8 +241,8 @@ int main(int argc, char **argv) printf("File %d: %s\n", i + 1, path); print_info(audio_format_num, &afhi); if (OPT_GIVEN(CHUNK_TABLE)) - print_chunk_table(&afhi); - printf("\n"); + print_chunk_table(&afhi, audio_format_num, + audio_file_data, audio_file_size); } clear_afhi(&afhi); } @@ -236,5 +258,6 @@ out: PARA_ERROR_LOG("%s\n", errctx); if (ret < 0) PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + lls_free_parse_result(lpr, CMD_PTR); return ret < 0? EXIT_FAILURE : EXIT_SUCCESS; }