changeset 19474:07209f48e527

Add public functions for removal of styles and events.
author eugeni
date Mon, 21 Aug 2006 16:33:13 +0000
parents 4bae35431365
children 1f117b5fb5a1
files libass/ass.c libass/ass.h
diffstat 2 files changed, 38 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass.c	Mon Aug 21 16:24:45 2006 +0000
+++ b/libass/ass.c	Mon Aug 21 16:33:13 2006 +0000
@@ -37,25 +37,13 @@
 	if (track->event_format)
 		free(track->event_format);
 	if (track->styles) {
-		for (i = 0; i < track->n_styles; ++i) {
-			ass_style_t* style = track->styles + i;
-			if (style->Name)
-				free(style->Name);
-			if (style->FontName)
-				free(style->FontName);
-		}
+		for (i = 0; i < track->n_styles; ++i)
+			ass_free_style(track, i);
 		free(track->styles);
 	}
 	if (track->events) {
-		for (i = 0; i < track->n_events; ++i) {
-			ass_event_t* event = track->events + i;
-			if (event->Name)
-				free(event->Name);
-			if (event->Effect)
-				free(event->Effect);
-			if (event->Text)
-				free(event->Text);
-		}
+		for (i = 0; i < track->n_events; ++i)
+			ass_free_event(track, i);
 		free(track->events);
 	}
 }
@@ -96,10 +84,22 @@
 	return eid;
 }
 
-static void free_event(ass_track_t* track, int eid) {
-	if (track->n_events > eid + 1) // not last event
-		memcpy(track->events + eid, track->events + eid + 1, sizeof(ass_event_t) * (track->n_events - eid - 1));
-	track->n_events--;
+void ass_free_event(ass_track_t* track, int eid) {
+	ass_event_t* event = track->events + eid;
+	if (event->Name)
+		free(event->Name);
+	if (event->Effect)
+		free(event->Effect);
+	if (event->Text)
+		free(event->Text);
+}
+
+void ass_free_style(ass_track_t* track, int sid) {
+	ass_style_t* style = track->styles + sid;
+	if (style->Name)
+		free(style->Name);
+	if (style->FontName)
+		free(style->FontName);
 }
 
 static int events_compare_f(const void* a_, const void* b_) {
@@ -530,7 +530,8 @@
 //		dump_events(tid);
 	} while (0);
 	// some error
-	free_event(track, eid);
+	ass_free_event(track, eid);
+	track->n_events--;
 	free(str);
 }
 
--- a/libass/ass.h	Mon Aug 21 16:24:45 2006 +0000
+++ b/libass/ass.h	Mon Aug 21 16:33:13 2006 +0000
@@ -110,6 +110,22 @@
 int ass_alloc_event(ass_track_t* track);
 
 /**
+ * \brief delete a style
+ * \param track track
+ * \param sid style id
+ * Deallocates style data. Does not modify track->n_styles.
+ */
+void ass_free_style(ass_track_t* track, int sid);
+
+/**
+ * \brief delete an event
+ * \param track track
+ * \param eid event id
+ * Deallocates event data. Does not modify track->n_events.
+ */
+void ass_free_event(ass_track_t* track, int eid);
+
+/**
  * \brief Process Codec Private section of subtitle stream
  * \param track target track
  * \param data string to parse