annotate src/libsndfile-1.0.25/programs/sndfile-metadata-get.c @ 84:08ae793730bd

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