2 ** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** Copyright (C) 2008-2010 George Blood Audio
5 ** All rights reserved.
7 ** Redistribution and use in source and binary forms, with or without
8 ** modification, are permitted provided that the following conditions are
11 ** * Redistributions of source code must retain the above copyright
12 ** notice, this list of conditions and the following disclaimer.
13 ** * Redistributions in binary form must reproduce the above copyright
14 ** notice, this list of conditions and the following disclaimer in
15 ** the documentation and/or other materials provided with the
17 ** * Neither the author nor the names of any contributors may be used
18 ** to endorse or promote products derived from this software without
19 ** specific prior written permission.
21 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 #define BUFFER_LEN (1 << 16)
48 static void usage_exit (const char *progname
, int exit_code
) ;
49 static void process_args (SNDFILE
* file
, const SF_BROADCAST_INFO_2K
* binfo
, int argc
, char * argv
[]) ;
52 main (int argc
, char *argv
[])
55 SF_BROADCAST_INFO_2K binfo
;
56 const char *progname
;
57 const char * filename
= NULL
;
60 /* Store the program name. */
61 progname
= program_name (argv
[0]) ;
63 /* Check if we've been asked for help. */
64 if (argc
<= 2 || strcmp (argv
[1], "--help") == 0 || strcmp (argv
[1], "-h") == 0)
65 usage_exit (progname
, 0) ;
67 if (argv
[argc
- 1][0] != '-')
68 { filename
= argv
[argc
- 1] ;
71 else if (argv
[1][0] != '-')
72 { filename
= argv
[1] ;
76 { printf ("Error : Either the first or the last command line parameter should be a filename.\n\n") ;
80 /* Get the time in case we need it later. */
81 memset (&sfinfo
, 0, sizeof (sfinfo
)) ;
82 if ((file
= sf_open (filename
, SFM_READ
, &sfinfo
)) == NULL
)
83 { printf ("Error : Open of file '%s' failed : %s\n\n", filename
, sf_strerror (file
)) ;
87 memset (&binfo
, 0, sizeof (binfo
)) ;
88 if (sf_command (file
, SFC_GET_BROADCAST_INFO
, &binfo
, sizeof (binfo
)) == 0)
89 memset (&binfo
, 0, sizeof (binfo
)) ;
91 process_args (file
, &binfo
, argc
- 2, argv
+ start
) ;
97 /*==============================================================================
98 ** Print version and usage.
102 usage_exit (const char *progname
, int exit_code
)
103 { printf ("\nUsage :\n %s [options] <file>\n\nOptions:\n", progname
) ;
106 " --bext-description Print the 'bext' description.\n"
107 " --bext-originator Print the 'bext; originator info.\n"
108 " --bext-orig-ref Print the 'bext' origination reference.\n"
109 " --bext-umid Print the 'bext' UMID.\n"
110 " --bext-orig-date Print the 'bext' origination date.\n"
111 " --bext-orig-time Print the 'bext' origination time.\n"
112 " --bext-coding-hist Print the 'bext' coding history.\n"
116 " --str-title Print the title metadata.\n"
117 " --str-copyright Print the copyright metadata.\n"
118 " --str-artist Print the artist metadata.\n"
119 " --str-comment Print the comment metadata.\n"
120 " --str-date Print the creation date metadata.\n"
121 " --str-album Print the album metadata.\n"
122 " --str-license Print the license metadata.\n"
125 printf ("Using %s.\n\n", sf_version_string ()) ;
130 process_args (SNDFILE
* file
, const SF_BROADCAST_INFO_2K
* binfo
, int argc
, char * argv
[])
134 #define HANDLE_BEXT_ARG(cmd,name,field) \
135 if (do_all || strcmp (argv [k], cmd) == 0) \
136 { printf ("%-20s : %.*s\n", name, (int) sizeof (binfo->field), binfo->field) ; \
141 #define HANDLE_STR_ARG(cmd,name,id) \
142 if (do_all || strcmp (argv [k], cmd) == 0) \
143 { str = sf_get_string (file, id) ; \
144 printf ("%-20s : %s\n", name, str ? str : "") ; \
145 if (! do_all) continue ; \
148 for (k
= 0 ; k
< argc
; k
++)
149 { if (do_all
|| strcmp (argv
[k
], "--all") == 0)
152 HANDLE_BEXT_ARG ("--bext-description", "Description", description
) ;
153 HANDLE_BEXT_ARG ("--bext-originator", "Originator", originator
) ;
154 HANDLE_BEXT_ARG ("--bext-orig-ref", "Origination ref", originator_reference
) ;
155 HANDLE_BEXT_ARG ("--bext-umid", "UMID", umid
) ;
156 HANDLE_BEXT_ARG ("--bext-orig-date", "Origination date", origination_date
) ;
157 HANDLE_BEXT_ARG ("--bext-orig-time", "Origination time", origination_time
) ;
158 HANDLE_BEXT_ARG ("--bext-coding-hist", "Coding history", coding_history
) ;
160 HANDLE_STR_ARG ("--str-title", "Name", SF_STR_TITLE
) ;
161 HANDLE_STR_ARG ("--str-copyright", "Copyright", SF_STR_COPYRIGHT
) ;
162 HANDLE_STR_ARG ("--str-artist", "Artist", SF_STR_ARTIST
) ;
163 HANDLE_STR_ARG ("--str-comment", "Comment", SF_STR_COMMENT
) ;
164 HANDLE_STR_ARG ("--str-date", "Create date", SF_STR_DATE
) ;
165 HANDLE_STR_ARG ("--str-album", "Album", SF_STR_ALBUM
) ;
166 HANDLE_STR_ARG ("--str-license", "License", SF_STR_LICENSE
) ;
169 { printf ("Error : Don't know what to do with command line arg '%s'.\n\n", argv
[k
]) ;