annotate src/libsndfile-1.0.27/programs/sndfile-metadata-get.c @ 127:7867fa7e1b6b

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