mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
consolidate chain error reporting in a single function, add extra explanation for common errors
This commit is contained in:
@@ -109,7 +109,7 @@ FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOpt
|
||||
die("out of memory allocating chain");
|
||||
|
||||
if(!FLAC__metadata_chain_read(chain, filename)) {
|
||||
fprintf(stderr, "%s: ERROR: reading metadata, status = \"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: reading metadata", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ FLAC__bool do_major_operation_on_file(const char *filename, const CommandLineOpt
|
||||
FLAC__metadata_chain_sort_padding(chain);
|
||||
ok = FLAC__metadata_chain_write(chain, options->use_padding, options->preserve_modtime);
|
||||
if(!ok)
|
||||
fprintf(stderr, "%s: ERROR: writing FLAC file, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: writing FLAC file", filename);
|
||||
}
|
||||
|
||||
FLAC__metadata_chain_delete(chain);
|
||||
@@ -267,7 +267,7 @@ FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLi
|
||||
die("out of memory allocating chain");
|
||||
|
||||
if(!FLAC__metadata_chain_read(chain, filename)) {
|
||||
fprintf(stderr, "%s: ERROR: reading metadata, status = \"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: reading metadata", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLi
|
||||
FLAC__metadata_chain_sort_padding(chain);
|
||||
ok = FLAC__metadata_chain_write(chain, use_padding, options->preserve_modtime);
|
||||
if(!ok)
|
||||
fprintf(stderr, "%s: ERROR: writing FLAC file, error = %s\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: writing FLAC file", filename);
|
||||
}
|
||||
|
||||
FLAC__metadata_chain_delete(chain);
|
||||
@@ -478,7 +478,7 @@ FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metad
|
||||
padding->length = length;
|
||||
|
||||
if(!FLAC__metadata_iterator_insert_block_after(iterator, padding)) {
|
||||
fprintf(stderr, "%s: ERROR: adding new PADDING block to metadata, status =\"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: adding new PADDING block to metadata", filename);
|
||||
FLAC__metadata_object_delete(padding);
|
||||
FLAC__metadata_iterator_delete(iterator);
|
||||
return false;
|
||||
|
||||
@@ -75,7 +75,7 @@ FLAC__bool do_shorthand_operation__cuesheet(const char *filename, FLAC__Metadata
|
||||
while(FLAC__metadata_iterator_next(iterator))
|
||||
;
|
||||
if(!FLAC__metadata_iterator_insert_block_after(iterator, cuesheet)) {
|
||||
fprintf(stderr, "%s: ERROR: adding new CUESHEET block to metadata, status =\"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: adding new CUESHEET block to metadata", filename);
|
||||
FLAC__metadata_object_delete(cuesheet);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ FLAC__bool do_shorthand_operation__add_seekpoints(const char *filename, FLAC__Me
|
||||
while(FLAC__metadata_iterator_prev(iterator))
|
||||
;
|
||||
if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) {
|
||||
fprintf(stderr, "%s: ERROR: adding new SEEKTABLE block to metadata, status =\"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: adding new SEEKTABLE block to metadata", filename);
|
||||
FLAC__metadata_object_delete(block);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bo
|
||||
while(FLAC__metadata_iterator_next(iterator))
|
||||
;
|
||||
if(!FLAC__metadata_iterator_insert_block_after(iterator, block)) {
|
||||
fprintf(stderr, "%s: ERROR: adding new VORBIS_COMMENT block to metadata, status =\"%s\"\n", filename, FLAC__Metadata_ChainStatusString[FLAC__metadata_chain_status(chain)]);
|
||||
print_error_with_chain_status(chain, "%s: ERROR: adding new VORBIS_COMMENT block to metadata", filename);
|
||||
return false;
|
||||
}
|
||||
/* iterator is left pointing to new block */
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "FLAC/assert.h"
|
||||
#include "share/utf8.h"
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -119,6 +120,61 @@ void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const
|
||||
}
|
||||
}
|
||||
|
||||
void print_error_with_chain_status(FLAC__Metadata_Chain *chain, const char *format, ...)
|
||||
{
|
||||
const FLAC__Metadata_ChainStatus status = FLAC__metadata_chain_status(chain);
|
||||
va_list args;
|
||||
|
||||
FLAC__ASSERT(0 != format);
|
||||
|
||||
va_start(args, format);
|
||||
|
||||
(void) vfprintf(stderr, format, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, ", status = \"%s\"\n", FLAC__Metadata_ChainStatusString[status]);
|
||||
|
||||
if(status == FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE) {
|
||||
fprintf(stderr, "\n"
|
||||
"The FLAC file could not be opened. Most likely the file does not exist\n"
|
||||
"or is not readable.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE) {
|
||||
fprintf(stderr, "\n"
|
||||
"The file does not appear to be a FLAC file.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE) {
|
||||
fprintf(stderr, "\n"
|
||||
"The FLAC file does not have write permissions.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_BAD_METADATA) {
|
||||
fprintf(stderr, "\n"
|
||||
"The metadata to be writted does not conform to the FLAC metadata\n"
|
||||
"specifications.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_READ_ERROR) {
|
||||
fprintf(stderr, "\n"
|
||||
"There was an error while reading the FLAC file.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR) {
|
||||
fprintf(stderr, "\n"
|
||||
"There was an error while writing FLAC file; most probably the disk is\n"
|
||||
"full.\n"
|
||||
);
|
||||
}
|
||||
else if(status == FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR) {
|
||||
fprintf(stderr, "\n"
|
||||
"There was an error removing the temporary FLAC file.\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation)
|
||||
{
|
||||
static const char * const violations[] = {
|
||||
|
||||
@@ -31,6 +31,7 @@ size_t local_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
char *local_strdup(const char *source);
|
||||
void local_strcat(char **dest, const char *source);
|
||||
void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent);
|
||||
void print_error_with_chain_status(FLAC__Metadata_Chain *chain, const char *format, ...);
|
||||
|
||||
FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user