Chris@0: /* Chris@0: ** Copyright (C) 2008-2011 Erik de Castro Lopo Chris@0: ** Copyright (C) 2008-2010 George Blood Audio Chris@0: ** Chris@0: ** All rights reserved. Chris@0: ** Chris@0: ** Redistribution and use in source and binary forms, with or without Chris@0: ** modification, are permitted provided that the following conditions are Chris@0: ** met: Chris@0: ** Chris@0: ** * Redistributions of source code must retain the above copyright Chris@0: ** notice, this list of conditions and the following disclaimer. Chris@0: ** * Redistributions in binary form must reproduce the above copyright Chris@0: ** notice, this list of conditions and the following disclaimer in Chris@0: ** the documentation and/or other materials provided with the Chris@0: ** distribution. Chris@0: ** * Neither the author nor the names of any contributors may be used Chris@0: ** to endorse or promote products derived from this software without Chris@0: ** specific prior written permission. Chris@0: ** Chris@0: ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@0: ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED Chris@0: ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR Chris@0: ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR Chris@0: ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@0: ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@0: ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; Chris@0: ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, Chris@0: ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR Chris@0: ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF Chris@0: ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@0: */ Chris@0: Chris@0: #include Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "common.h" Chris@0: Chris@0: #define BUFFER_LEN (1 << 16) Chris@0: Chris@0: static void usage_exit (const char *progname, int exit_code) ; Chris@0: static void process_args (SNDFILE * file, const SF_BROADCAST_INFO_2K * binfo, int argc, char * argv []) ; Chris@0: Chris@0: int Chris@0: main (int argc, char *argv []) Chris@0: { SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: SF_BROADCAST_INFO_2K binfo ; Chris@0: const char *progname ; Chris@0: const char * filename = NULL ; Chris@0: int start ; Chris@0: Chris@0: /* Store the program name. */ Chris@0: progname = program_name (argv [0]) ; Chris@0: Chris@0: /* Check if we've been asked for help. */ Chris@0: if (argc <= 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0) Chris@0: usage_exit (progname, 0) ; Chris@0: Chris@0: if (argv [argc - 1][0] != '-') Chris@0: { filename = argv [argc - 1] ; Chris@0: start = 1 ; Chris@0: } Chris@0: else if (argv [1][0] != '-') Chris@0: { filename = argv [1] ; Chris@0: start = 2 ; Chris@0: } Chris@0: else Chris@0: { printf ("Error : Either the first or the last command line parameter should be a filename.\n\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* Get the time in case we need it later. */ Chris@0: memset (&sfinfo, 0, sizeof (sfinfo)) ; Chris@0: if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL) Chris@0: { printf ("Error : Open of file '%s' failed : %s\n\n", filename, sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: memset (&binfo, 0, sizeof (binfo)) ; Chris@0: if (sf_command (file, SFC_GET_BROADCAST_INFO, &binfo, sizeof (binfo)) == 0) Chris@0: memset (&binfo, 0, sizeof (binfo)) ; Chris@0: Chris@0: process_args (file, &binfo, argc - 2, argv + start) ; Chris@0: Chris@0: sf_close (file) ; Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: /*============================================================================== Chris@0: ** Print version and usage. Chris@0: */ Chris@0: Chris@0: static void Chris@0: usage_exit (const char *progname, int exit_code) Chris@0: { printf ("\nUsage :\n %s [options] \n\nOptions:\n", progname) ; Chris@0: Chris@0: puts ( Chris@0: " --bext-description Print the 'bext' description.\n" Chris@0: " --bext-originator Print the 'bext; originator info.\n" Chris@0: " --bext-orig-ref Print the 'bext' origination reference.\n" Chris@0: " --bext-umid Print the 'bext' UMID.\n" Chris@0: " --bext-orig-date Print the 'bext' origination date.\n" Chris@0: " --bext-orig-time Print the 'bext' origination time.\n" Chris@0: " --bext-coding-hist Print the 'bext' coding history.\n" Chris@0: ) ; Chris@0: Chris@0: puts ( Chris@0: " --str-title Print the title metadata.\n" Chris@0: " --str-copyright Print the copyright metadata.\n" Chris@0: " --str-artist Print the artist metadata.\n" Chris@0: " --str-comment Print the comment metadata.\n" Chris@0: " --str-date Print the creation date metadata.\n" Chris@0: " --str-album Print the album metadata.\n" Chris@0: " --str-license Print the license metadata.\n" Chris@0: ) ; Chris@0: Chris@0: printf ("Using %s.\n\n", sf_version_string ()) ; Chris@0: exit (exit_code) ; Chris@0: } /* usage_exit */ Chris@0: Chris@0: static void Chris@0: process_args (SNDFILE * file, const SF_BROADCAST_INFO_2K * binfo, int argc, char * argv []) Chris@0: { const char * str ; Chris@0: int k, do_all = 0 ; Chris@0: Chris@0: #define HANDLE_BEXT_ARG(cmd,name,field) \ Chris@0: if (do_all || strcmp (argv [k], cmd) == 0) \ Chris@0: { printf ("%-20s : %.*s\n", name, (int) sizeof (binfo->field), binfo->field) ; \ Chris@0: if (! do_all) \ Chris@0: continue ; \ Chris@0: } ; Chris@0: Chris@0: #define HANDLE_STR_ARG(cmd,name,id) \ Chris@0: if (do_all || strcmp (argv [k], cmd) == 0) \ Chris@0: { str = sf_get_string (file, id) ; \ Chris@0: printf ("%-20s : %s\n", name, str ? str : "") ; \ Chris@0: if (! do_all) continue ; \ Chris@0: } ; Chris@0: Chris@0: for (k = 0 ; k < argc ; k++) Chris@0: { if (do_all || strcmp (argv [k], "--all") == 0) Chris@0: do_all = 1 ; Chris@0: Chris@0: HANDLE_BEXT_ARG ("--bext-description", "Description", description) ; Chris@0: HANDLE_BEXT_ARG ("--bext-originator", "Originator", originator) ; Chris@0: HANDLE_BEXT_ARG ("--bext-orig-ref", "Origination ref", originator_reference) ; Chris@0: HANDLE_BEXT_ARG ("--bext-umid", "UMID", umid) ; Chris@0: HANDLE_BEXT_ARG ("--bext-orig-date", "Origination date", origination_date) ; Chris@0: HANDLE_BEXT_ARG ("--bext-orig-time", "Origination time", origination_time) ; Chris@0: HANDLE_BEXT_ARG ("--bext-coding-hist", "Coding history", coding_history) ; Chris@0: Chris@0: HANDLE_STR_ARG ("--str-title", "Name", SF_STR_TITLE) ; Chris@0: HANDLE_STR_ARG ("--str-copyright", "Copyright", SF_STR_COPYRIGHT) ; Chris@0: HANDLE_STR_ARG ("--str-artist", "Artist", SF_STR_ARTIST) ; Chris@0: HANDLE_STR_ARG ("--str-comment", "Comment", SF_STR_COMMENT) ; Chris@0: HANDLE_STR_ARG ("--str-date", "Create date", SF_STR_DATE) ; Chris@0: HANDLE_STR_ARG ("--str-album", "Album", SF_STR_ALBUM) ; Chris@0: HANDLE_STR_ARG ("--str-license", "License", SF_STR_LICENSE) ; Chris@0: Chris@0: if (! do_all) Chris@0: { printf ("Error : Don't know what to do with command line arg '%s'.\n\n", argv [k]) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: break ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* process_args */