~ubuntu-branches/ubuntu/raring/flac/raring

« back to all changes in this revision

Viewing changes to src/share/grabbag/seektable.c

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* grabbag - Convenience lib for various routines common to several tools
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
3
 
 *
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.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
10
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.
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
13
13
 *
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.
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 */
18
18
 
 
19
#if HAVE_CONFIG_H
 
20
#  include <config.h>
 
21
#endif
 
22
 
19
23
#include "share/grabbag.h"
20
24
#include "FLAC/assert.h"
21
25
#include <stdlib.h> /* for atoi() */
22
26
#include <string.h>
23
27
 
 
28
#ifdef _MSC_VER
 
29
/* There's no strtoll() in MSVC6 so we just write a specialized one */
 
30
static FLAC__int64 local__strtoll(const char *src, char **endptr)
 
31
{
 
32
        FLAC__bool neg = false;
 
33
        FLAC__int64 ret = 0;
 
34
        int c;
 
35
        FLAC__ASSERT(0 != src);
 
36
        if(*src == '-') {
 
37
                neg = true;
 
38
                src++;
 
39
        }
 
40
        while(0 != (c = *src)) {
 
41
                c -= '0';
 
42
                if(c >= 0 && c <= 9)
 
43
                        ret = (ret * 10) + c;
 
44
                else
 
45
                        break;
 
46
                src++;
 
47
        }
 
48
        if(endptr)
 
49
                *endptr = (char*)src;
 
50
        return neg? -ret : ret;
 
51
}
 
52
#endif
 
53
 
24
54
FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec, FLAC__bool only_explicit_placeholders, FLAC__uint64 total_samples_to_encode, unsigned sample_rate, FLAC__StreamMetadata *seektable_template, FLAC__bool *spec_has_real_points)
25
55
{
26
56
        unsigned i;
47
77
                                        if(0 != spec_has_real_points)
48
78
                                                *spec_has_real_points = true;
49
79
                                        if(!only_explicit_placeholders) {
50
 
                                                if(!FLAC__metadata_object_seektable_template_append_spaced_points(seektable_template, atoi(pt), total_samples_to_encode))
51
 
                                                        return false;
 
80
                                                const int n = (unsigned)atoi(pt);
 
81
                                                if(n > 0)
 
82
                                                        if(!FLAC__metadata_object_seektable_template_append_spaced_points(seektable_template, (unsigned)n, total_samples_to_encode))
 
83
                                                                return false;
52
84
                                        }
53
85
                                }
54
86
                        }
58
90
                                        if(0 != spec_has_real_points)
59
91
                                                *spec_has_real_points = true;
60
92
                                        if(!only_explicit_placeholders) {
61
 
                                                double sec = atof(pt);
 
93
                                                const double sec = atof(pt);
62
94
                                                if(sec > 0.0) {
63
 
#if defined _MSC_VER || defined __MINGW32__
64
 
                                                        /* with MSVC you have to spoon feed it the casting */
65
 
                                                        unsigned n = (unsigned)((double)(FLAC__int64)total_samples_to_encode / (sec * (double)sample_rate));
66
 
#else
67
 
                                                        unsigned n = (unsigned)((double)total_samples_to_encode / (sec * (double)sample_rate));
68
 
#endif
69
 
                                                        if(!FLAC__metadata_object_seektable_template_append_spaced_points(seektable_template, n, total_samples_to_encode))
70
 
                                                                return false;
 
95
                                                        unsigned samples = (unsigned)(sec * (double)sample_rate);
 
96
                                                        if(samples > 0) {
 
97
                                                                /* +1 for the initial point at sample 0 */
 
98
                                                                if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(seektable_template, samples, total_samples_to_encode))
 
99
                                                                        return false;
 
100
                                                        }
71
101
                                                }
72
102
                                        }
73
103
                                }
76
106
                                if(0 != spec_has_real_points)
77
107
                                        *spec_has_real_points = true;
78
108
                                if(!only_explicit_placeholders) {
79
 
                                        FLAC__uint64 n = (unsigned)atoi(pt);
80
 
                                        if(!FLAC__metadata_object_seektable_template_append_point(seektable_template, n))
81
 
                                                return false;
 
109
                                        char *endptr;
 
110
#ifdef _MSC_VER
 
111
                                        const FLAC__int64 n = local__strtoll(pt, &endptr);
 
112
#else
 
113
                                        const FLAC__int64 n = (FLAC__int64)strtoll(pt, &endptr, 10);
 
114
#endif
 
115
                                        if(
 
116
                                                (n > 0 || (endptr > pt && *endptr == ';')) && /* is a valid number (extra check needed for "0") */
 
117
                                                (total_samples_to_encode == 0 || (FLAC__uint64)n < total_samples_to_encode) /* number is not >= the known total_samples_to_encode */
 
118
                                        )
 
119
                                                if(!FLAC__metadata_object_seektable_template_append_point(seektable_template, (FLAC__uint64)n))
 
120
                                                        return false;
82
121
                                }
83
122
                        }
84
123
                }