annotate src/libsndfile-1.0.27/programs/sndfile-metadata-get.c @ 83:ae30d91d2ffe

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