27
33
static FLAC__bool remove_vc_field(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write);
28
34
static FLAC__bool remove_vc_firstfield(const char *filename, FLAC__StreamMetadata *block, const char *field_name, FLAC__bool *needs_write);
29
35
static FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const Argument_VcField *field, FLAC__bool *needs_write, FLAC__bool raw);
30
static FLAC__bool import_vc_from(const char *filename, FLAC__StreamMetadata *block, const Argument_Filename *vc_filename, FLAC__bool *needs_write, FLAC__bool raw);
31
static FLAC__bool export_vc_to(const char *filename, FLAC__StreamMetadata *block, const Argument_Filename *vc_filename, FLAC__bool raw);
36
static FLAC__bool import_vc_from(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool *needs_write, FLAC__bool raw);
37
static FLAC__bool export_vc_to(const char *filename, FLAC__StreamMetadata *block, const Argument_String *vc_filename, FLAC__bool raw);
33
39
FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool raw)
172
178
FLAC__StreamMetadata_VorbisComment_Entry entry;
174
FLAC__bool needs_free = false;
176
181
FLAC__ASSERT(0 != block);
177
182
FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
178
183
FLAC__ASSERT(0 != field);
179
184
FLAC__ASSERT(0 != needs_write);
182
entry.entry = (FLAC__byte *)field->field;
184
else if(utf8_encode(field->field, &converted) >= 0) {
185
entry.entry = (FLAC__byte *)converted;
189
fprintf(stderr, "%s: ERROR: couldn't convert comment to UTF-8\n", filename);
193
entry.length = strlen((const char *)entry.entry);
195
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
186
if(field->field_value_from_file) {
187
/* read the file into 'data' */
190
const off_t size = grabbag__file_get_filesize(field->field_value);
192
fprintf(stderr, "%s: ERROR: can't open file '%s' for '%s' tag value\n", filename, field->field_value, field->field_name);
195
if(size >= 0x100000) { /* magic arbitrary limit, actual format limit is near 16MB */
196
fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value is too large\n", filename, field->field_value, field->field_name);
199
if(0 == (data = malloc(size+1)))
200
die("out of memory allocating tag value");
202
if(0 == (f = fopen(field->field_value, "rb")) || fread(data, 1, size, f) != (size_t)size) {
203
fprintf(stderr, "%s: ERROR: while reading file '%s' for '%s' tag value: %s\n", filename, field->field_value, field->field_name, strerror(errno));
210
if(strlen(data) != (size_t)size) {
212
fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value has embedded NULs\n", filename, field->field_value, field->field_name);
216
/* move 'data' into 'converted', converting to UTF-8 if necessary */
220
else if(utf8_encode(data, &converted) >= 0) {
225
fprintf(stderr, "%s: ERROR: converting file '%s' contents to UTF-8 for tag value\n", filename, field->field_value);
229
/* create and entry and append it */
230
if(!FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(&entry, field->field_name, converted)) {
198
fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename);
232
fprintf(stderr, "%s: ERROR: file '%s' for '%s' tag value is not valid UTF-8\n", filename, field->field_value, field->field_name);
236
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/false)) {
237
fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename);
245
FLAC__bool needs_free = false;
247
entry.entry = (FLAC__byte *)field->field;
249
else if(utf8_encode(field->field, &converted) >= 0) {
250
entry.entry = (FLAC__byte *)converted;
254
fprintf(stderr, "%s: ERROR: converting comment '%s' to UTF-8\n", filename, field->field);
257
entry.length = strlen((const char *)entry.entry);
258
if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) {
262
* our previous parsing has already established that the field
263
* name is OK, so it must be the field value
265
fprintf(stderr, "%s: ERROR: tag value for '%s' is not valid UTF-8\n", filename, field->field_name);
269
if(!FLAC__metadata_object_vorbiscomment_append_comment(block, entry, /*copy=*/true)) {
272
fprintf(stderr, "%s: ERROR: memory allocation failure\n", filename);
202
276
*needs_write = true;