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