minor formatting
[flac.git] / src / libFLAC / metadata_object.c
index 371b33b..12f6b90 100644 (file)
@@ -1,5 +1,5 @@
 /* libFLAC - Free Lossless Audio Codec library
- * Copyright (C) 2001,2002  Josh Coalson
+ * Copyright (C) 2001,2002,2003  Josh Coalson
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -207,6 +207,7 @@ static void cuesheet_calculate_length_(FLAC__StreamMetadata *object)
        object->length = (
                FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
                FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
+               FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
                FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
                FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
        ) / 8;
@@ -293,7 +294,6 @@ static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__Stream
        FLAC__ASSERT(0 != src);
        FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
        FLAC__ASSERT((0 != src->indices && src->num_indices > 0) || (0 == src->indices && src->num_indices == 0));
-       /*@@@@ for docs, note that there is no "&& copy == false" at the end here ^^^ which will filter up */
 
        save = dest->indices;
 
@@ -331,11 +331,22 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type
                                object->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
                                break;
                        case FLAC__METADATA_TYPE_PADDING:
+                               /* calloc() took care of this for us:
+                               object->length = 0;
+                               */
                                break;
                        case FLAC__METADATA_TYPE_APPLICATION:
                                object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
+                               /* calloc() took care of this for us:
+                               object->data.application.data = 0;
+                               */
                                break;
                        case FLAC__METADATA_TYPE_SEEKTABLE:
+                               /* calloc() took care of this for us:
+                               object->length = 0;
+                               object->data.seek_table.num_points = 0;
+                               object->data.seek_table.points = 0;
+                               */
                                break;
                        case FLAC__METADATA_TYPE_VORBIS_COMMENT:
                                {
@@ -351,10 +362,11 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type
                                cuesheet_calculate_length_(object);
                                break;
                        default:
-                               /* double protection: */
-                               FLAC__ASSERT(0);
-                               free(object);
-                               return 0;
+                               /* calloc() took care of this for us:
+                               object->length = 0;
+                               object->data.unknown.data = 0;
+                               */
+                               break;
                }
        }
 
@@ -392,8 +404,10 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMet
                                }
                                break;
                        case FLAC__METADATA_TYPE_VORBIS_COMMENT:
-                               if(0 != to->data.vorbis_comment.vendor_string.entry)
+                               if(0 != to->data.vorbis_comment.vendor_string.entry) {
                                        free(to->data.vorbis_comment.vendor_string.entry);
+                                       to->data.vorbis_comment.vendor_string.entry = 0;
+                               }
                                if(!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) {
                                        FLAC__metadata_object_delete(to);
                                        return 0;
@@ -427,10 +441,11 @@ FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMet
                                }
                                break;
                        default:
-                               /* double protection: */
-                               FLAC__ASSERT(0);
-                               free(to);
-                               return 0;
+                               if(!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) {
+                                       FLAC__metadata_object_delete(to);
+                                       return 0;
+                               }
+                               break;
                }
        }
 
@@ -446,16 +461,22 @@ void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object)
                case FLAC__METADATA_TYPE_PADDING:
                        break;
                case FLAC__METADATA_TYPE_APPLICATION:
-                       if(0 != object->data.application.data)
+                       if(0 != object->data.application.data) {
                                free(object->data.application.data);
+                               object->data.application.data = 0;
+                       }
                        break;
                case FLAC__METADATA_TYPE_SEEKTABLE:
-                       if(0 != object->data.seek_table.points)
+                       if(0 != object->data.seek_table.points) {
                                free(object->data.seek_table.points);
+                               object->data.seek_table.points = 0;
+                       }
                        break;
                case FLAC__METADATA_TYPE_VORBIS_COMMENT:
-                       if(0 != object->data.vorbis_comment.vendor_string.entry)
+                       if(0 != object->data.vorbis_comment.vendor_string.entry) {
                                free(object->data.vorbis_comment.vendor_string.entry);
+                               object->data.vorbis_comment.vendor_string.entry = 0;
+                       }
                        if(0 != object->data.vorbis_comment.comments) {
                                FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
                                vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
@@ -468,7 +489,11 @@ void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object)
                        }
                        break;
                default:
-                       FLAC__ASSERT(0);
+                       if(0 != object->data.unknown.data) {
+                               free(object->data.unknown.data);
+                               object->data.unknown.data = 0;
+                       }
+                       break;
        }
 }
 
@@ -578,6 +603,9 @@ static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueShe
        if(block1->lead_in != block2->lead_in)
                return false;
 
+       if(block1->is_cd != block2->is_cd)
+               return false;
+
        if(block1->num_tracks != block2->num_tracks)
                return false;
 
@@ -614,6 +642,17 @@ static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueShe
        return true;
 }
 
+static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, unsigned block_length)
+{
+       FLAC__ASSERT(0 != block1);
+       FLAC__ASSERT(0 != block2);
+
+       if(0 != block1->data && 0 != block2->data)
+               return 0 == memcmp(block1->data, block2->data, block_length);
+       else
+               return block1->data == block2->data;
+}
+
 FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2)
 {
        FLAC__ASSERT(0 != block1);
@@ -642,8 +681,7 @@ FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *b
                case FLAC__METADATA_TYPE_CUESHEET:
                        return compare_block_data_cuesheet_(&block1->data.cue_sheet, &block2->data.cue_sheet);
                default:
-                       FLAC__ASSERT(0);
-                       return false;
+                       return compare_block_data_unknown_(&block1->data.unknown, &block2->data.unknown, block1->length);
        }
 }
 
@@ -1125,6 +1163,13 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__Stre
        return true;
 }
 
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
+{
+       FLAC__StreamMetadata_CueSheet_Index index;
+       memset(&index, 0, sizeof(index));
+       return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, index);
+}
+
 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
 {
        FLAC__StreamMetadata_CueSheet_Track *track;
@@ -1137,7 +1182,7 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__Stre
        track = &object->data.cue_sheet.tracks[track_num];
 
        /* move all indices > index_num backward one space */
-       memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(track->num_indices-index_num-1));
+       memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1));
 
        FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1);
        cuesheet_calculate_length_(object);
@@ -1214,6 +1259,13 @@ FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMeta
        return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy);
 }
 
+FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num)
+{
+       FLAC__StreamMetadata_CueSheet_Track track;
+       memset(&track, 0, sizeof(track));
+       return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false);
+}
+
 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num)
 {
        FLAC__StreamMetadata_CueSheet *cs;