From dc6a1021f7f36f5c4379f75492cab82f74e1609d Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 5 Apr 2008 23:52:03 +0200 Subject: [PATCH] para_afh: Accept negative values for begin_chunk and end_chunk. Negative values are interpreted as offsets counted from the end of the audio file. --- afh.c | 26 +++++++++++++++++--------- afh.ggo | 14 ++++++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/afh.c b/afh.c index 86f34ace..dd69d9e4 100644 --- a/afh.c +++ b/afh.c @@ -64,18 +64,26 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi) size_t size; - if (conf.begin_chunk_arg < 0) - return -ERRNO_TO_PARA_ERROR(EINVAL); - first_chunk = conf.begin_chunk_arg; - - if (conf.end_chunk_given) { - if (conf.end_chunk_arg < 0) - return -ERRNO_TO_PARA_ERROR(EINVAL); - if (conf.end_chunk_arg >= afhi->chunks_total) + if (conf.begin_chunk_arg < 0) { + if (-conf.begin_chunk_arg > afhi->chunks_total) return -ERRNO_TO_PARA_ERROR(EINVAL); - last_chunk = conf.end_chunk_arg; + first_chunk = afhi->chunks_total + conf.begin_chunk_arg; + } else + first_chunk = conf.begin_chunk_arg; + if (conf.end_chunk_given) { + if (conf.end_chunk_arg < 0) { + if (-conf.end_chunk_arg > afhi->chunks_total) + return -ERRNO_TO_PARA_ERROR(EINVAL); + last_chunk = afhi->chunks_total + conf.end_chunk_arg; + } else { + if (conf.end_chunk_arg >= afhi->chunks_total) + return -ERRNO_TO_PARA_ERROR(EINVAL); + last_chunk = conf.end_chunk_arg; + } } else last_chunk = afhi->chunks_total - 1; + if (first_chunk >= last_chunk) + return -ERRNO_TO_PARA_ERROR(EINVAL); if (!afhi->chunks_total) return 1; afh_get_header(afhi, audio_file_data, &buf, &size); diff --git a/afh.ggo b/afh.ggo index 7fb9d5ac..c7552ef9 100644 --- a/afh.ggo +++ b/afh.ggo @@ -75,8 +75,14 @@ default="0" dependon="stream" optional details=" - The chunk_num argument must be non-negative as chunks start - at zero. + The chunk_num argument must be between -num_chunks and + num_chunks - 1 inclusively where num_chunks is the total number + of chunks which is printed when using the --info option. If + chunk_num is negative, the given number of chunks are counted + backwards from the end of the file. For example --begin_chunk + -100 instructs para_afh to start output at chunk num_chunks + - 100. This is mainly useful for cutting off the end of an + audio file. " option "end_chunk" e @@ -86,8 +92,8 @@ int typestr="chunk_num" dependon="stream" optional details=" - The chunk_num argument must be less than the total number of - chunks. The default is to write up to the last chunk. + For the chunk_num argument the same rules as for --begin_chunk + apply. The default is to write up to the last chunk. " option "just_in_time" j -- 2.39.5