fix bug passing filename around
[platform/upstream/flac.git] / src / metaflac / operations_shorthand_streaminfo.c
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001,2002  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,
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.
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.
17  */
18
19 #include "options.h"
20 #include "utils.h"
21 #include "FLAC/assert.h"
22 #include "FLAC/metadata.h"
23 #include <string.h>
24
25 FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
26 {
27         unsigned i;
28         FLAC__bool ok = true;
29         FLAC__StreamMetadata *block;
30         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
31
32         if(0 == iterator)
33                 die("out of memory allocating iterator");
34
35         FLAC__metadata_iterator_init(iterator, chain);
36
37         block = FLAC__metadata_iterator_get_block(iterator);
38
39         FLAC__ASSERT(0 != block);
40         FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
41
42         if(prefix_with_filename)
43                 printf("%s:", filename);
44
45         switch(operation->type) {
46                 case OP__SHOW_MD5SUM:
47                         for(i = 0; i < 16; i++)
48                                 printf("%02x", block->data.stream_info.md5sum[i]);
49                         printf("\n");
50                         break;
51                 case OP__SHOW_MIN_BLOCKSIZE:
52                         printf("%u\n", block->data.stream_info.min_blocksize);
53                         break;
54                 case OP__SHOW_MAX_BLOCKSIZE:
55                         printf("%u\n", block->data.stream_info.max_blocksize);
56                         break;
57                 case OP__SHOW_MIN_FRAMESIZE:
58                         printf("%u\n", block->data.stream_info.min_framesize);
59                         break;
60                 case OP__SHOW_MAX_FRAMESIZE:
61                         printf("%u\n", block->data.stream_info.max_framesize);
62                         break;
63                 case OP__SHOW_SAMPLE_RATE:
64                         printf("%u\n", block->data.stream_info.sample_rate);
65                         break;
66                 case OP__SHOW_CHANNELS:
67                         printf("%u\n", block->data.stream_info.channels);
68                         break;
69                 case OP__SHOW_BPS:
70                         printf("%u\n", block->data.stream_info.bits_per_sample);
71                         break;
72                 case OP__SHOW_TOTAL_SAMPLES:
73                         printf("%llu\n", block->data.stream_info.total_samples);
74                         break;
75                 case OP__SET_MD5SUM:
76                         memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16);
77                         *needs_write = true;
78                         break;
79                 case OP__SET_MIN_BLOCKSIZE:
80                         block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value;
81                         *needs_write = true;
82                         break;
83                 case OP__SET_MAX_BLOCKSIZE:
84                         block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value;
85                         *needs_write = true;
86                         break;
87                 case OP__SET_MIN_FRAMESIZE:
88                         block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value;
89                         *needs_write = true;
90                         break;
91                 case OP__SET_MAX_FRAMESIZE:
92                         block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value;
93                         *needs_write = true;
94                         break;
95                 case OP__SET_SAMPLE_RATE:
96                         block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value;
97                         *needs_write = true;
98                         break;
99                 case OP__SET_CHANNELS:
100                         block->data.stream_info.channels = operation->argument.streaminfo_uint32.value;
101                         *needs_write = true;
102                         break;
103                 case OP__SET_BPS:
104                         block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value;
105                         *needs_write = true;
106                         break;
107                 case OP__SET_TOTAL_SAMPLES:
108                         block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value;
109                         *needs_write = true;
110                         break;
111                 default:
112                         ok = false;
113                         FLAC__ASSERT(0);
114                         break;
115         };
116
117         FLAC__metadata_iterator_delete(iterator);
118
119         return ok;
120 }