1 /* flac - Command-line FLAC encoder/decoder
2 * Copyright (C) 2002,2003 Josh Coalson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "FLAC/assert.h"
29 static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
37 while('\0' != (c = *s++))
38 if(c >= '0' && c <= '9')
39 ret = ret * 10 + (c - '0');
47 static FLAC__bool local__parse_timecode_(const char *s, double *value)
53 /* parse [0-9][0-9]*: */
55 if(c >= '0' && c <= '9')
59 while(':' != (c = *s++)) {
60 if(c >= '0' && c <= '9')
61 i = i * 10 + (c - '0');
65 ret = (double)i * 60.;
67 /* parse [0-9]*[.]?[0-9]* i.e. a sign-less rational number */
68 if(strspn(s, "1234567890.") != strlen(s))
71 const char *p = strchr(s, '.');
72 if(p && 0 != strchr(++p, '.'))
81 #ifdef FLAC__VALGRIND_TESTING
82 size_t flac__utils_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
84 size_t ret = fwrite(ptr, size, nmemb, stream);
91 FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec)
94 FLAC__bool is_negative = false;
96 FLAC__ASSERT(0 != spec);
98 spec->is_relative = false;
99 spec->value_is_samples = true;
100 spec->value.samples = 0;
105 spec->is_relative = true;
108 else if(s[0] == '+') {
109 spec->is_relative = true;
113 if(local__parse_uint64_(s, &val)) {
114 spec->value_is_samples = true;
115 spec->value.samples = (FLAC__int64)val;
117 spec->value.samples = -(spec->value.samples);
121 if(!local__parse_timecode_(s, &d))
123 spec->value_is_samples = false;
124 spec->value.seconds = d;
126 spec->value.seconds = -(spec->value.seconds);
133 void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, unsigned sample_rate)
135 FLAC__ASSERT(0 != spec);
136 if(!spec->value_is_samples) {
137 spec->value.samples = (FLAC__int64)(spec->value.seconds * (double)sample_rate);
138 spec->value_is_samples = true;