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