1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
9 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 last mod: $Id: vorbis_comments.c,v 1.3 2003/06/24 12:37:52 giles Exp $
16 ********************************************************************/
27 #include <vorbis/codec.h>
28 #include <vorbis/vorbisfile.h>
34 /* Vorbis comment keys that need special formatting. */
36 char *key
; /* includes the '=' for programming convenience */
37 char *formatstr
; /* formatted output */
38 } vorbis_comment_keys
[] = {
39 {"TRACKNUMBER=", N_("Track number:")},
40 {"REPLAYGAIN_TRACK_GAIN=", N_("ReplayGain (Track):")},
41 {"REPLAYGAIN_ALBUM_GAIN=", N_("ReplayGain (Album):")},
42 {"REPLAYGAIN_TRACK_PEAK=", N_("ReplayGain Peak (Track):")},
43 {"REPLAYGAIN_ALBUM_PEAK=", N_("ReplayGain Peak (Album):")},
44 {"COPYRIGHT=", N_("Copyright")},
45 {"=", N_("Comment:")},
46 {NULL
, N_("Comment:")}
50 char *lookup_comment_prettyprint (char *comment
, int *offset
)
55 /* Search for special-case formatting */
56 for (i
= 0; vorbis_comment_keys
[i
].key
!= NULL
; i
++) {
58 if ( !strncasecmp (vorbis_comment_keys
[i
].key
, comment
,
59 strlen(vorbis_comment_keys
[i
].key
)) ) {
61 *offset
= strlen(vorbis_comment_keys
[i
].key
);
62 s
= malloc(strlen(vorbis_comment_keys
[i
].formatstr
) + 1);
64 fprintf(stderr
, _("Error: Out of memory.\n"));
67 strcpy(s
, vorbis_comment_keys
[i
].formatstr
);
73 /* Use default formatting */
74 j
= strcspn(comment
, "=");
79 fprintf(stderr
, _("Error: Out of memory.\n"));
82 strncpy(s
, comment
, j
);
87 for (i
= 1; i
< j
; i
++) {
93 /* Unrecognized comment, use last format string */
95 s
= malloc(strlen(vorbis_comment_keys
[i
].formatstr
) + 1);
97 fprintf(stderr
, _("Error: Out of memory.\n"));
100 strcpy(s
, vorbis_comment_keys
[i
].formatstr
);
104 void print_vorbis_comment (char *comment
, decoder_callbacks_t
*cb
,
107 char *comment_prettyprint
;
111 if (cb
== NULL
|| cb
->printf_metadata
== NULL
)
114 comment_prettyprint
= lookup_comment_prettyprint(comment
, &offset
);
116 if (utf8_decode(comment
+ offset
, &decoded_value
) >= 0) {
117 cb
->printf_metadata(callback_arg
, 1, "%s %s", comment_prettyprint
,
121 cb
->printf_metadata(callback_arg
, 1, "%s %s", comment_prettyprint
,
123 free(comment_prettyprint
);