+FLAC__bool canonicalize_until_specification(utils__SkipUntilSpecification *spec, const char *inbasefilename, unsigned sample_rate, FLAC__uint64 skip, FLAC__uint64 total_samples_in_input)
+{
+ /* convert from mm:ss.sss to sample number if necessary */
+ flac__utils_canonicalize_skip_until_specification(spec, sample_rate);
+
+ /* special case: if "--until=-0", use the special value '0' to mean "end-of-stream" */
+ if(spec->is_relative && spec->value.samples == 0) {
+ spec->is_relative = false;
+ return true;
+ }
+
+ /* in any other case the total samples in the input must be known */
+ if(total_samples_in_input == 0) {
+ fprintf(stderr, "%s: ERROR, cannot use --until when FLAC metadata has total sample count of 0\n", inbasefilename);
+ return false;
+ }
+
+ FLAC__ASSERT(spec->value_is_samples);
+
+ /* convert relative specifications to absolute */
+ if(spec->is_relative) {
+ if(spec->value.samples <= 0)
+ spec->value.samples += (FLAC__int64)total_samples_in_input;
+ else
+ spec->value.samples += skip;
+ spec->is_relative = false;
+ }
+
+ /* error check */
+ if(spec->value.samples < 0) {
+ fprintf(stderr, "%s: ERROR, --until value is before beginning of input\n", inbasefilename);
+ return false;
+ }
+ if((FLAC__uint64)spec->value.samples <= skip) {
+ fprintf(stderr, "%s: ERROR, --until value is before --skip point\n", inbasefilename);
+ return false;
+ }
+ if((FLAC__uint64)spec->value.samples > total_samples_in_input) {
+ fprintf(stderr, "%s: ERROR, --until value is after end of input\n", inbasefilename);
+ return false;
+ }
+
+ return true;
+}
+