add FLAC__METADATA_TYPE_UNDEFINED to FLAC__StreamMetadataType enum for marking beginn...
[platform/upstream/flac.git] / src / metaflac / operations.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 "operations.h"
20 #include "usage.h"
21 #include "utils.h"
22 #include "FLAC/assert.h"
23 #include "FLAC/metadata.h"
24 #include "share/grabbag.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 static void show_version();
30 static FLAC__bool do_major_operation(const CommandLineOptions *options);
31 static FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options);
32 static FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
33 static FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
34 static FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
35 static FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options);
36 static FLAC__bool do_shorthand_operations(const CommandLineOptions *options);
37 static FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options);
38 static FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool utf8_convert);
39 static FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime);
40 static FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write);
41
42 static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number);
43 static void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool raw, FLAC__bool hexdump_application);
44
45 /* from operations_shorthand_seektable.c */
46 extern FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Metadata_Chain *chain, const char *specification, FLAC__bool *needs_write);
47
48 /* from operations_shorthand_streaminfo.c */
49 extern 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);
50
51 /* from operations_shorthand_vorbiscomment.c */
52 extern FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool raw);
53
54 FLAC__bool do_operations(const CommandLineOptions *options)
55 {
56         FLAC__bool ok = true;
57
58         if(options->show_long_help) {
59                 long_usage(0);
60         }
61         if(options->show_version) {
62                 show_version();
63         }
64         else if(options->args.checks.num_major_ops > 0) {
65                 FLAC__ASSERT(options->args.checks.num_shorthand_ops == 0);
66                 FLAC__ASSERT(options->args.checks.num_major_ops == 1);
67                 FLAC__ASSERT(options->args.checks.num_major_ops == options->ops.num_operations);
68                 ok = do_major_operation(options);
69         }
70         else if(options->args.checks.num_shorthand_ops > 0) {
71                 FLAC__ASSERT(options->args.checks.num_shorthand_ops == options->ops.num_operations);
72                 ok = do_shorthand_operations(options);
73         }
74
75         return ok;
76 }
77
78 /*
79  * local routines
80  */
81
82 void show_version()
83 {
84         printf("metaflac %s\n", FLAC__VERSION_STRING);
85 }
86
87 FLAC__bool do_major_operation(const CommandLineOptions *options)
88 {
89         unsigned i;
90         FLAC__bool ok = true;
91
92         /*@@@ to die after first error,  v---  add '&& ok' here */
93         for(i = 0; i < options->num_files; i++)
94                 ok &= do_major_operation_on_file(options->filenames[i], options);
95
96         return ok;
97 }
98
99 FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOptions *options)
100 {
101         FLAC__bool ok = true, needs_write = false;
102         FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
103
104         if(0 == chain)
105                 die("out of memory allocating chain");
106
107         if(!FLAC__metadata_chain_read(chain, filename)) {
108                 fprintf(stderr, "%s: ERROR: reading metadata, status = \"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
109                 return false;
110         }
111
112         switch(options->ops.operations[0].type) {
113                 case OP__LIST:
114                         ok = do_major_operation__list(options->prefix_with_filename? filename : 0, chain, options);
115                         break;
116                 case OP__APPEND:
117                         ok = do_major_operation__append(chain, options);
118                         needs_write = true;
119                         break;
120                 case OP__REMOVE:
121                         ok = do_major_operation__remove(chain, options);
122                         needs_write = true;
123                         break;
124                 case OP__REMOVE_ALL:
125                         ok = do_major_operation__remove_all(chain, options);
126                         needs_write = true;
127                         break;
128                 case OP__MERGE_PADDING:
129                         FLAC__metadata_chain_merge_padding(chain);
130                         needs_write = true;
131                         break;
132                 case OP__SORT_PADDING:
133                         FLAC__metadata_chain_sort_padding(chain);
134                         needs_write = true;
135                         break;
136                 default:
137                         FLAC__ASSERT(0);
138                         return false;
139         }
140
141         if(ok && needs_write) {
142                 if(options->use_padding)
143                         FLAC__metadata_chain_sort_padding(chain);
144                 ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime);
145                 if(!ok)
146                         fprintf(stderr, "%s: ERROR: writing FLAC file, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
147         }
148
149         FLAC__metadata_chain_delete(chain);
150
151         return ok;
152 }
153
154 FLAC__bool do_major_operation__list(const char *filename, FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
155 {
156         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
157         FLAC__StreamMetadata *block;
158         FLAC__bool ok = true;
159         unsigned block_number;
160
161         if(0 == iterator)
162                 die("out of memory allocating iterator");
163
164         FLAC__metadata_iterator_init(iterator, chain);
165
166         block_number = 0;
167         do {
168                 block = FLAC__metadata_iterator_get_block(iterator);
169                 ok &= (0 != block);
170                 if(!ok)
171                         fprintf(stderr, "%s: ERROR: couldn't get block from chain\n", filename);
172                 else if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number))
173                         write_metadata(filename, block, block_number, !options->utf8_convert, options->application_data_format_is_hexdump);
174                 block_number++;
175         } while(ok && FLAC__metadata_iterator_next(iterator));
176
177         FLAC__metadata_iterator_delete(iterator);
178
179         return ok;
180 }
181
182 FLAC__bool do_major_operation__append(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
183 {
184         (void) chain, (void) options;
185         fprintf(stderr, "ERROR: --append not implemented yet\n"); /*@@@*/
186         return false;
187 }
188
189 FLAC__bool do_major_operation__remove(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
190 {
191         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
192         FLAC__bool ok = true;
193         unsigned block_number;
194
195         if(0 == iterator)
196                 die("out of memory allocating iterator");
197
198         FLAC__metadata_iterator_init(iterator, chain);
199
200         block_number = 0;
201         while(ok && FLAC__metadata_iterator_next(iterator)) {
202                 block_number++;
203                 if(passes_filter(options, FLAC__metadata_iterator_get_block(iterator), block_number)) {
204                         ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding);
205                         if(options->use_padding)
206                                 ok &= FLAC__metadata_iterator_next(iterator);
207                 }
208         }
209
210         FLAC__metadata_iterator_delete(iterator);
211
212         return ok;
213 }
214
215 FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, const CommandLineOptions *options)
216 {
217         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
218         FLAC__bool ok = true;
219
220         if(0 == iterator)
221                 die("out of memory allocating iterator");
222
223         FLAC__metadata_iterator_init(iterator, chain);
224
225         while(ok && FLAC__metadata_iterator_next(iterator)) {
226                 ok &= FLAC__metadata_iterator_delete_block(iterator, options->use_padding);
227                 if(options->use_padding)
228                         ok &= FLAC__metadata_iterator_next(iterator);
229         }
230
231         FLAC__metadata_iterator_delete(iterator);
232
233         return ok;
234 }
235
236 FLAC__bool do_shorthand_operations(const CommandLineOptions *options)
237 {
238         unsigned i;
239         FLAC__bool ok = true;
240
241         /* to die after first error,     v---  add '&& ok' here */
242         for(i = 0; i < options->num_files; i++)
243                 ok &= do_shorthand_operations_on_file(options->filenames[i], options);
244
245         /* check if OP__ADD_REPLAY_GAIN requested */
246         if(ok && options->num_files > 0) {
247                 for(i = 0; i < options->ops.num_operations; i++) {
248                         if(options->ops.operations[i].type == OP__ADD_REPLAY_GAIN)
249                                 ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime);
250                 }
251         }
252
253         return ok;
254 }
255
256 FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options)
257 {
258         unsigned i;
259         FLAC__bool ok = true, needs_write = false, use_padding = options->use_padding;
260         FLAC__Metadata_Chain *chain = FLAC__metadata_chain_new();
261
262         if(0 == chain)
263                 die("out of memory allocating chain");
264
265         if(!FLAC__metadata_chain_read(chain, filename)) {
266                 fprintf(stderr, "%s: ERROR: reading metadata, status = \"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
267                 return false;
268         }
269
270         for(i = 0; i < options->ops.num_operations && ok; i++) {
271                 ok &= do_shorthand_operation(filename, options->prefix_with_filename, chain, &options->ops.operations[i], &needs_write, options->utf8_convert);
272
273                 /* The following seems counterintuitive but the meaning
274                  * of 'use_padding' is 'try to keep the overall metadata
275                  * to its original size, adding or truncating extra
276                  * padding if necessary' which is why we need to turn it
277                  * off in this case.  If we don't, the extra padding block
278                  * will just be truncated.
279                  */
280                 if(options->ops.operations[i].type == OP__ADD_PADDING)
281                         use_padding = false;
282         }
283
284         if(ok && needs_write) {
285                 if(use_padding)
286                         FLAC__metadata_chain_sort_padding(chain);
287                 ok = FLAC__metadata_chain_write(chain, use_padding, options->preserve_modtime);
288                 if(!ok)
289                         fprintf(stderr, "%s: ERROR: writing FLAC file, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
290         }
291
292         FLAC__metadata_chain_delete(chain);
293
294         return ok;
295 }
296
297 FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool utf8_convert)
298 {
299         FLAC__bool ok = true;
300
301         switch(operation->type) {
302                 case OP__SHOW_MD5SUM:
303                 case OP__SHOW_MIN_BLOCKSIZE:
304                 case OP__SHOW_MAX_BLOCKSIZE:
305                 case OP__SHOW_MIN_FRAMESIZE:
306                 case OP__SHOW_MAX_FRAMESIZE:
307                 case OP__SHOW_SAMPLE_RATE:
308                 case OP__SHOW_CHANNELS:
309                 case OP__SHOW_BPS:
310                 case OP__SHOW_TOTAL_SAMPLES:
311                 case OP__SET_MD5SUM:
312                 case OP__SET_MIN_BLOCKSIZE:
313                 case OP__SET_MAX_BLOCKSIZE:
314                 case OP__SET_MIN_FRAMESIZE:
315                 case OP__SET_MAX_FRAMESIZE:
316                 case OP__SET_SAMPLE_RATE:
317                 case OP__SET_CHANNELS:
318                 case OP__SET_BPS:
319                 case OP__SET_TOTAL_SAMPLES:
320                         ok = do_shorthand_operation__streaminfo(filename, prefix_with_filename, chain, operation, needs_write);
321                         break;
322                 case OP__SHOW_VC_VENDOR:
323                 case OP__SHOW_VC_FIELD:
324                 case OP__REMOVE_VC_ALL:
325                 case OP__REMOVE_VC_FIELD:
326                 case OP__REMOVE_VC_FIRSTFIELD:
327                 case OP__SET_VC_FIELD:
328                 case OP__IMPORT_VC_FROM:
329                 case OP__EXPORT_VC_TO:
330                         ok = do_shorthand_operation__vorbis_comment(filename, prefix_with_filename, chain, operation, needs_write, !utf8_convert);
331                         break;
332                 case OP__ADD_SEEKPOINT:
333                         ok = do_shorthand_operation__add_seekpoints(filename, chain, operation->argument.add_seekpoint.specification, needs_write);
334                         break;
335                 case OP__ADD_REPLAY_GAIN:
336                         /* this command is always executed last */
337                         ok = true;
338                         break;
339                 case OP__ADD_PADDING:
340                         ok = do_shorthand_operation__add_padding(filename, chain, operation->argument.add_padding.length, needs_write);
341                         break;
342                 default:
343                         ok = false;
344                         FLAC__ASSERT(0);
345                         break;
346         };
347
348         return ok;
349 }
350
351 FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime)
352 {
353         FLAC__StreamMetadata streaminfo;
354         float *title_gains = 0, *title_peaks = 0;
355         float album_gain, album_peak;
356         unsigned sample_rate = 0;
357         unsigned bits_per_sample = 0;
358         unsigned channels = 0;
359         unsigned i;
360         const char *error;
361         FLAC__bool first = true;
362
363         FLAC__ASSERT(num_files > 0);
364
365         for(i = 0; i < num_files; i++) {
366                 FLAC__ASSERT(0 != filenames[i]);
367                 if(!FLAC__metadata_get_streaminfo(filenames[i], &streaminfo)) {
368                         fprintf(stderr, "%s: ERROR: can't open file or get STREAMINFO block\n", filenames[i]);
369                         return false;
370                 }
371                 if(first) {
372                         first = false;
373                         sample_rate = streaminfo.data.stream_info.sample_rate;
374                         bits_per_sample = streaminfo.data.stream_info.bits_per_sample;
375                         channels = streaminfo.data.stream_info.channels;
376                 }
377                 else {
378                         if(sample_rate != streaminfo.data.stream_info.sample_rate) {
379                                 fprintf(stderr, "%s: ERROR: sample rate of %u Hz does not match previous files' %u Hz\n", filenames[i], streaminfo.data.stream_info.sample_rate, sample_rate);
380                                 return false;
381                         }
382                         if(bits_per_sample != streaminfo.data.stream_info.bits_per_sample) {
383                                 fprintf(stderr, "%s: ERROR: resolution of %u bps does not match previous files' %u bps\n", filenames[i], streaminfo.data.stream_info.bits_per_sample, bits_per_sample);
384                                 return false;
385                         }
386                         if(channels != streaminfo.data.stream_info.channels) {
387                                 fprintf(stderr, "%s: ERROR: # channels (%u) does not match previous files' (%u)\n", filenames[i], streaminfo.data.stream_info.channels, channels);
388                                 return false;
389                         }
390                 }
391                 if(!grabbag__replaygain_is_valid_sample_frequency(sample_rate)) {
392                         fprintf(stderr, "%s: ERROR: sample rate of %u Hz is not supported\n", filenames[i], sample_rate);
393                         return false;
394                 }
395                 if(channels != 1 && channels != 2) {
396                         fprintf(stderr, "%s: ERROR: # of channels (%u) is not supported, must be 1 or 2\n", filenames[i], channels);
397                         return false;
398                 }
399         }
400         FLAC__ASSERT(bits_per_sample >= FLAC__MIN_BITS_PER_SAMPLE && bits_per_sample <= FLAC__MAX_BITS_PER_SAMPLE);
401
402         if(!grabbag__replaygain_init(sample_rate))
403                 FLAC__ASSERT(0);
404
405         if(
406                 0 == (title_gains = (float*)malloc(sizeof(float) * num_files)) ||
407                 0 == (title_peaks = (float*)malloc(sizeof(float) * num_files))
408         )
409                 die("out of memory allocating space for title gains/peaks");
410
411         for(i = 0; i < num_files; i++) {
412                 if(0 != (error = grabbag__replaygain_analyze_file(filenames[i], title_gains+i, title_peaks+i))) {
413                         fprintf(stderr, "%s: ERROR: during analysis (%s)\n", filenames[i], error);
414                         free(title_gains);
415                         free(title_peaks);
416                         return false;
417                 }
418         }
419         grabbag__replaygain_get_album(&album_gain, &album_peak);
420
421         for(i = 0; i < num_files; i++) {
422                 if(0 != (error = grabbag__replaygain_store_to_file(filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i], preserve_modtime))) {
423                         fprintf(stderr, "%s: ERROR: writing tags (%s)\n", filenames[i], error);
424                         free(title_gains);
425                         free(title_peaks);
426                         return false;
427                 }
428         }
429
430         free(title_gains);
431         free(title_peaks);
432         return true;
433 }
434
435 FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write)
436 {
437         FLAC__StreamMetadata *padding = 0;
438         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
439
440         if(0 == iterator)
441                 die("out of memory allocating iterator");
442
443         FLAC__metadata_iterator_init(iterator, chain);
444
445         while(FLAC__metadata_iterator_next(iterator))
446                 ;
447
448         padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
449         if(0 == padding)
450                 die("out of memory allocating PADDING block");
451
452         padding->length = length;
453
454         if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) {
455                 fprintf(stderr, "%s: ERROR: adding new PADDING block to metadata, status =\"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
456                 FLAC__metadata_object_delete(padding);
457                 FLAC__metadata_iterator_delete(iterator);
458                 return false;
459         }
460
461         FLAC__metadata_iterator_delete(iterator);
462         *needs_write = true;
463         return true;
464 }
465
466 FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number)
467 {
468         unsigned i, j;
469         FLAC__bool matches_number = false, matches_type = false;
470         FLAC__bool has_block_number_arg = false;
471
472         for(i = 0; i < options->args.num_arguments; i++) {
473                 if(options->args.arguments[i].type == ARG__BLOCK_TYPE || options->args.arguments[i].type == ARG__EXCEPT_BLOCK_TYPE) {
474                         for(j = 0; j < options->args.arguments[i].value.block_type.num_entries; j++) {
475                                 if(options->args.arguments[i].value.block_type.entries[j].type == block->type) {
476                                         if(block->type != FLAC__METADATA_TYPE_APPLICATION || !options->args.arguments[i].value.block_type.entries[j].filter_application_by_id || 0 == memcmp(options->args.arguments[i].value.block_type.entries[j].application_id, block->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
477                                                 matches_type = true;
478                                 }
479                         }
480                 }
481                 else if(options->args.arguments[i].type == ARG__BLOCK_NUMBER) {
482                         has_block_number_arg = true;
483                         for(j = 0; j < options->args.arguments[i].value.block_number.num_entries; j++) {
484                                 if(options->args.arguments[i].value.block_number.entries[j] == block_number)
485                                         matches_number = true;
486                         }
487                 }
488         }
489
490         if(!has_block_number_arg)
491                 matches_number = true;
492
493         if(options->args.checks.has_block_type) {
494                 FLAC__ASSERT(!options->args.checks.has_except_block_type);
495         }
496         else if(options->args.checks.has_except_block_type)
497                 matches_type = !matches_type;
498         else
499                 matches_type = true;
500
501         return matches_number && matches_type;
502 }
503
504 void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned block_number, FLAC__bool raw, FLAC__bool hexdump_application)
505 {
506         unsigned i;
507
508 /*@@@ yuck, should do this with a varargs function or something: */
509 #define PPR if(filename)printf("%s:",filename);
510         PPR; printf("METADATA block #%u\n", block_number);
511         PPR; printf("  type: %u (%s)\n", (unsigned)block->type, block->type < FLAC__METADATA_TYPE_UNDEFINED? FLAC__MetadataTypeString[block->type] : "UNKNOWN");
512         PPR; printf("  is last: %s\n", block->is_last? "true":"false");
513         PPR; printf("  length: %u\n", block->length);
514
515         switch(block->type) {
516                 case FLAC__METADATA_TYPE_STREAMINFO:
517                         PPR; printf("  minumum blocksize: %u samples\n", block->data.stream_info.min_blocksize);
518                         PPR; printf("  maximum blocksize: %u samples\n", block->data.stream_info.max_blocksize);
519                         PPR; printf("  minimum framesize: %u bytes\n", block->data.stream_info.min_framesize);
520                         PPR; printf("  maximum framesize: %u bytes\n", block->data.stream_info.max_framesize);
521                         PPR; printf("  sample_rate: %u Hz\n", block->data.stream_info.sample_rate);
522                         PPR; printf("  channels: %u\n", block->data.stream_info.channels);
523                         PPR; printf("  bits-per-sample: %u\n", block->data.stream_info.bits_per_sample);
524                         PPR; printf("  total samples: %llu\n", block->data.stream_info.total_samples);
525                         PPR; printf("  MD5 signature: ");
526                         for(i = 0; i < 16; i++) {
527                                 printf("%02x", (unsigned)block->data.stream_info.md5sum[i]);
528                         }
529                         printf("\n");
530                         break;
531                 case FLAC__METADATA_TYPE_PADDING:
532                         /* nothing to print */
533                         break;
534                 case FLAC__METADATA_TYPE_APPLICATION:
535                         PPR; printf("  application ID: ");
536                         for(i = 0; i < 4; i++) {
537                                 PPR; printf("%02x", block->data.application.id[i]);
538                         }
539                         PPR; printf("\n");
540                         PPR; printf("  data contents:\n");
541                         if(0 != block->data.application.data) {
542                                 if(hexdump_application)
543                                         hexdump(filename, block->data.application.data, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, "    ");
544                                 else
545                                         (void) fwrite(block->data.application.data, 1, block->length - FLAC__STREAM_METADATA_HEADER_LENGTH, stdout);
546                         }
547                         break;
548                 case FLAC__METADATA_TYPE_SEEKTABLE:
549                         PPR; printf("  seek points: %u\n", block->data.seek_table.num_points);
550                         for(i = 0; i < block->data.seek_table.num_points; i++) {
551                                 if(block->data.seek_table.points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
552                                         PPR; printf("    point %d: sample_number=%llu, stream_offset=%llu, frame_samples=%u\n", i, block->data.seek_table.points[i].sample_number, block->data.seek_table.points[i].stream_offset, block->data.seek_table.points[i].frame_samples);
553                                 }
554                                 else {
555                                         PPR; printf("    point %d: PLACEHOLDER\n", i);
556                                 }
557                         }
558                         break;
559                 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
560                         PPR; printf("  vendor string: ");
561                         write_vc_field(0, &block->data.vorbis_comment.vendor_string, raw, stdout);
562                         PPR; printf("  comments: %u\n", block->data.vorbis_comment.num_comments);
563                         for(i = 0; i < block->data.vorbis_comment.num_comments; i++) {
564                                 PPR; printf("    comment[%u]: ", i);
565                                 write_vc_field(0, &block->data.vorbis_comment.comments[i], raw, stdout);
566                         }
567                         break;
568                 default:
569                         PPR; printf("SKIPPING block of unknown type\n");
570                         break;
571         }
572 #undef PPR
573 }