~ubuntu-branches/ubuntu/precise/flac/precise-updates

« back to all changes in this revision

Viewing changes to src/flac/utils.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
/* flac - Command-line FLAC encoder/decoder
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
22
22
 
23
23
#include "utils.h"
24
24
#include "FLAC/assert.h"
 
25
#include "FLAC/metadata.h"
25
26
#include <math.h>
26
27
#include <stdarg.h>
 
28
#include <stdio.h>
27
29
#include <stdlib.h>
28
30
#include <string.h>
29
31
 
 
32
const char *CHANNEL_MASK_TAG = "WAVEFORMATEXTENSIBLE_CHANNEL_MASK";
 
33
 
30
34
int flac__utils_verbosity_ = 2;
31
35
 
32
36
static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
67
71
        }
68
72
        ret = (double)i * 60.;
69
73
 
70
 
        /* parse [0-9]*[.]?[0-9]* i.e. a sign-less rational number */
71
 
        if(strspn(s, "1234567890.") != strlen(s))
 
74
        /* parse [0-9]*[.,]?[0-9]* i.e. a sign-less rational number (. or , OK for fractional seconds, to support different locales) */
 
75
        if(strspn(s, "1234567890.,") != strlen(s))
72
76
                return false;
73
77
        {
74
 
                const char *p = strchr(s, '.');
75
 
                if(p && 0 != strchr(++p, '.'))
 
78
                const char *p = strpbrk(s, ".,");
 
79
                if(p && 0 != strpbrk(++p, ".,"))
76
80
                        return false;
77
81
        }
78
82
        ret += atof(s);
113
117
}
114
118
 
115
119
/*
116
 
 * @@@ this only works with sorted cuesheets (the spec strongly recommends but
 
120
 * this only works with sorted cuesheets (the spec strongly recommends but
117
121
 * does not require sorted cuesheets).  but if it's not sorted, picking a
118
122
 * nearest cue point has no significance.
119
123
 */
269
273
        else
270
274
                until_spec->value.samples = total_samples;
271
275
}
 
276
 
 
277
FLAC__bool flac__utils_set_channel_mask_tag(FLAC__StreamMetadata *object, FLAC__uint32 channel_mask)
 
278
{
 
279
        FLAC__StreamMetadata_VorbisComment_Entry entry = { 0, 0 };
 
280
        char tag[128];
 
281
 
 
282
        FLAC__ASSERT(object);
 
283
        FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
284
        FLAC__ASSERT(strlen(CHANNEL_MASK_TAG+1+2+16+1) <= sizeof(tag)); /* +1 for =, +2 for 0x, +16 for digits, +1 for NUL */
 
285
        entry.entry = (FLAC__byte*)tag;
 
286
#if defined _MSC_VER || defined __MINGW32__
 
287
        if((entry.length = _snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
 
288
#else
 
289
        if((entry.length = snprintf(tag, sizeof(tag), "%s=0x%04X", CHANNEL_MASK_TAG, (unsigned)channel_mask)) >= sizeof(tag))
 
290
#endif
 
291
                return false;
 
292
        if(!FLAC__metadata_object_vorbiscomment_replace_comment(object, entry, /*all=*/true, /*copy=*/true))
 
293
                return false;
 
294
        return true;
 
295
}
 
296
 
 
297
FLAC__bool flac__utils_get_channel_mask_tag(const FLAC__StreamMetadata *object, FLAC__uint32 *channel_mask)
 
298
{
 
299
        int offset;
 
300
        unsigned val;
 
301
        char *p;
 
302
        FLAC__ASSERT(object);
 
303
        FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
304
        if(0 > (offset = FLAC__metadata_object_vorbiscomment_find_entry_from(object, /*offset=*/0, CHANNEL_MASK_TAG)))
 
305
                return false;
 
306
        if(object->data.vorbis_comment.comments[offset].length < strlen(CHANNEL_MASK_TAG)+4)
 
307
                return false;
 
308
        if(0 == (p = strchr((const char *)object->data.vorbis_comment.comments[offset].entry, '='))) /* should never happen, but just in case */
 
309
                return false;
 
310
        if(strncmp(p, "=0x", 3))
 
311
                return false;
 
312
        if(sscanf(p+3, "%x", &val) != 1)
 
313
                return false;
 
314
        *channel_mask = val;
 
315
        return true;
 
316
}