annotate src/libsndfile-1.0.25/programs/sndfile-metadata-get.c @ 85:545efbb81310

Import initial set of sources
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 18 Mar 2013 14:12:14 +0000
parents
children
rev   line source
cannam@85 1 /*
cannam@85 2 ** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@85 3 ** Copyright (C) 2008-2010 George Blood Audio
cannam@85 4 **
cannam@85 5 ** All rights reserved.
cannam@85 6 **
cannam@85 7 ** Redistribution and use in source and binary forms, with or without
cannam@85 8 ** modification, are permitted provided that the following conditions are
cannam@85 9 ** met:
cannam@85 10 **
cannam@85 11 ** * Redistributions of source code must retain the above copyright
cannam@85 12 ** notice, this list of conditions and the following disclaimer.
cannam@85 13 ** * Redistributions in binary form must reproduce the above copyright
cannam@85 14 ** notice, this list of conditions and the following disclaimer in
cannam@85 15 ** the documentation and/or other materials provided with the
cannam@85 16 ** distribution.
cannam@85 17 ** * Neither the author nor the names of any contributors may be used
cannam@85 18 ** to endorse or promote products derived from this software without
cannam@85 19 ** specific prior written permission.
cannam@85 20 **
cannam@85 21 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
cannam@85 22 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
cannam@85 23 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
cannam@85 24 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
cannam@85 25 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
cannam@85 26 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
cannam@85 27 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
cannam@85 28 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
cannam@85 29 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
cannam@85 30 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
cannam@85 31 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cannam@85 32 */
cannam@85 33
cannam@85 34 #include <config.h>
cannam@85 35
cannam@85 36 #include <stdio.h>
cannam@85 37 #include <stdlib.h>
cannam@85 38 #include <string.h>
cannam@85 39 #include <ctype.h>
cannam@85 40 #include <time.h>
cannam@85 41
cannam@85 42 #include <sndfile.h>
cannam@85 43
cannam@85 44 #include "common.h"
cannam@85 45
cannam@85 46 #define BUFFER_LEN (1 << 16)
cannam@85 47
cannam@85 48 static void usage_exit (const char *progname, int exit_code) ;
cannam@85 49 static void process_args (SNDFILE * file, const SF_BROADCAST_INFO_2K * binfo, int argc, char * argv []) ;
cannam@85 50
cannam@85 51 int
cannam@85 52 main (int argc, char *argv [])
cannam@85 53 { SNDFILE *file ;
cannam@85 54 SF_INFO sfinfo ;
cannam@85 55 SF_BROADCAST_INFO_2K binfo ;
cannam@85 56 const char *progname ;
cannam@85 57 const char * filename = NULL ;
cannam@85 58 int start ;
cannam@85 59
cannam@85 60 /* Store the program name. */
cannam@85 61 progname = program_name (argv [0]) ;
cannam@85 62
cannam@85 63 /* Check if we've been asked for help. */
cannam@85 64 if (argc <= 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
cannam@85 65 usage_exit (progname, 0) ;
cannam@85 66
cannam@85 67 if (argv [argc - 1][0] != '-')
cannam@85 68 { filename = argv [argc - 1] ;
cannam@85 69 start = 1 ;
cannam@85 70 }
cannam@85 71 else if (argv [1][0] != '-')
cannam@85 72 { filename = argv [1] ;
cannam@85 73 start = 2 ;
cannam@85 74 }
cannam@85 75 else
cannam@85 76 { printf ("Error : Either the first or the last command line parameter should be a filename.\n\n") ;
cannam@85 77 exit (1) ;
cannam@85 78 } ;
cannam@85 79
cannam@85 80 /* Get the time in case we need it later. */
cannam@85 81 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@85 82 if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
cannam@85 83 { printf ("Error : Open of file '%s' failed : %s\n\n", filename, sf_strerror (file)) ;
cannam@85 84 exit (1) ;
cannam@85 85 } ;
cannam@85 86
cannam@85 87 memset (&binfo, 0, sizeof (binfo)) ;
cannam@85 88 if (sf_command (file, SFC_GET_BROADCAST_INFO, &binfo, sizeof (binfo)) == 0)
cannam@85 89 memset (&binfo, 0, sizeof (binfo)) ;
cannam@85 90
cannam@85 91 process_args (file, &binfo, argc - 2, argv + start) ;
cannam@85 92
cannam@85 93 sf_close (file) ;
cannam@85 94 return 0 ;
cannam@85 95 } /* main */
cannam@85 96
cannam@85 97 /*==============================================================================
cannam@85 98 ** Print version and usage.
cannam@85 99 */
cannam@85 100
cannam@85 101 static void
cannam@85 102 usage_exit (const char *progname, int exit_code)
cannam@85 103 { printf ("\nUsage :\n %s [options] <file>\n\nOptions:\n", progname) ;
cannam@85 104
cannam@85 105 puts (
cannam@85 106 " --bext-description Print the 'bext' description.\n"
cannam@85 107 " --bext-originator Print the 'bext; originator info.\n"
cannam@85 108 " --bext-orig-ref Print the 'bext' origination reference.\n"
cannam@85 109 " --bext-umid Print the 'bext' UMID.\n"
cannam@85 110 " --bext-orig-date Print the 'bext' origination date.\n"
cannam@85 111 " --bext-orig-time Print the 'bext' origination time.\n"
cannam@85 112 " --bext-coding-hist Print the 'bext' coding history.\n"
cannam@85 113 ) ;
cannam@85 114
cannam@85 115 puts (
cannam@85 116 " --str-title Print the title metadata.\n"
cannam@85 117 " --str-copyright Print the copyright metadata.\n"
cannam@85 118 " --str-artist Print the artist metadata.\n"
cannam@85 119 " --str-comment Print the comment metadata.\n"
cannam@85 120 " --str-date Print the creation date metadata.\n"
cannam@85 121 " --str-album Print the album metadata.\n"
cannam@85 122 " --str-license Print the license metadata.\n"
cannam@85 123 ) ;
cannam@85 124
cannam@85 125 printf ("Using %s.\n\n", sf_version_string ()) ;
cannam@85 126 exit (exit_code) ;
cannam@85 127 } /* usage_exit */
cannam@85 128
cannam@85 129 static void
cannam@85 130 process_args (SNDFILE * file, const SF_BROADCAST_INFO_2K * binfo, int argc, char * argv [])
cannam@85 131 { const char * str ;
cannam@85 132 int k, do_all = 0 ;
cannam@85 133
cannam@85 134 #define HANDLE_BEXT_ARG(cmd,name,field) \
cannam@85 135 if (do_all || strcmp (argv [k], cmd) == 0) \
cannam@85 136 { printf ("%-20s : %.*s\n", name, (int) sizeof (binfo->field), binfo->field) ; \
cannam@85 137 if (! do_all) \
cannam@85 138 continue ; \
cannam@85 139 } ;
cannam@85 140
cannam@85 141 #define HANDLE_STR_ARG(cmd,name,id) \
cannam@85 142 if (do_all || strcmp (argv [k], cmd) == 0) \
cannam@85 143 { str = sf_get_string (file, id) ; \
cannam@85 144 printf ("%-20s : %s\n", name, str ? str : "") ; \
cannam@85 145 if (! do_all) continue ; \
cannam@85 146 } ;
cannam@85 147
cannam@85 148 for (k = 0 ; k < argc ; k++)
cannam@85 149 { if (do_all || strcmp (argv [k], "--all") == 0)
cannam@85 150 do_all = 1 ;
cannam@85 151
cannam@85 152 HANDLE_BEXT_ARG ("--bext-description", "Description", description) ;
cannam@85 153 HANDLE_BEXT_ARG ("--bext-originator", "Originator", originator) ;
cannam@85 154 HANDLE_BEXT_ARG ("--bext-orig-ref", "Origination ref", originator_reference) ;
cannam@85 155 HANDLE_BEXT_ARG ("--bext-umid", "UMID", umid) ;
cannam@85 156 HANDLE_BEXT_ARG ("--bext-orig-date", "Origination date", origination_date) ;
cannam@85 157 HANDLE_BEXT_ARG ("--bext-orig-time", "Origination time", origination_time) ;
cannam@85 158 HANDLE_BEXT_ARG ("--bext-coding-hist", "Coding history", coding_history) ;
cannam@85 159
cannam@85 160 HANDLE_STR_ARG ("--str-title", "Name", SF_STR_TITLE) ;
cannam@85 161 HANDLE_STR_ARG ("--str-copyright", "Copyright", SF_STR_COPYRIGHT) ;
cannam@85 162 HANDLE_STR_ARG ("--str-artist", "Artist", SF_STR_ARTIST) ;
cannam@85 163 HANDLE_STR_ARG ("--str-comment", "Comment", SF_STR_COMMENT) ;
cannam@85 164 HANDLE_STR_ARG ("--str-date", "Create date", SF_STR_DATE) ;
cannam@85 165 HANDLE_STR_ARG ("--str-album", "Album", SF_STR_ALBUM) ;
cannam@85 166 HANDLE_STR_ARG ("--str-license", "License", SF_STR_LICENSE) ;
cannam@85 167
cannam@85 168 if (! do_all)
cannam@85 169 { printf ("Error : Don't know what to do with command line arg '%s'.\n\n", argv [k]) ;
cannam@85 170 exit (1) ;
cannam@85 171 } ;
cannam@85 172 break ;
cannam@85 173 } ;
cannam@85 174
cannam@85 175 return ;
cannam@85 176 } /* process_args */