+
+static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ text_t *txt = &p_sys->txt;
+
+ /*
+ * {T h1:m1:s1:c1
+ * Line1
+ * Line2
+ * ...
+ * }
+ *
+ */
+ char *s;
+ char buffer_text[ 10 * MAX_LINE];
+ int i_buffer_text;
+ int64_t i_start;
+
+ p_subtitle->i_start = 0;
+ p_subtitle->i_stop = 0;
+ p_subtitle->psz_text = NULL;
+
+ for( ;; )
+ {
+ int h1, m1, s1, c1;
+ if( ( s = TextGetLine( txt ) ) == NULL )
+ {
+ return( VLC_EGENERIC );
+ }
+ if( sscanf( s,
+ "{T %d:%d:%d:%d",
+ &h1, &m1, &s1, &c1 ) == 4 )
+ {
+ i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 +
+ (int64_t)c1 * 10) * 1000;
+
+ /* Now read text until a line containing "}" */
+ for( i_buffer_text = 0;; )
+ {
+ int i_len;
+ if( ( s = TextGetLine( txt ) ) == NULL )
+ {
+ return( VLC_EGENERIC );
+ }
+
+ i_len = strlen( s );
+ if( i_len == 1 && s[0] == '}' )
+ {
+ /* "}" -> end of this subtitle */
+ buffer_text[__MAX( i_buffer_text - 1, 0 )] = '\0';
+ p_subtitle->i_start = i_start;
+ p_subtitle->i_stop = 0;
+ p_subtitle->psz_text = strdup( buffer_text );
+ return 0;
+ }
+ else
+ {
+ if( i_buffer_text + i_len + 1 < 10 * MAX_LINE )
+ {
+ memcpy( buffer_text + i_buffer_text,
+ s,
+ i_len );
+ i_buffer_text += i_len;
+
+ buffer_text[i_buffer_text] = '\n';
+ i_buffer_text++;
+ }
+ }
+ }
+ }
+ }
+}
+