+ s = ParseSamiSearch( txt, s, ">" );
+ }
+ else if( !strncmp( s, " ", 6 ) )
+ {
+ c = ' ';
+ s += 6;
+ }
+ else if( *s == '\t' )
+ {
+ c = ' ';
+ s++;
+ }
+ else
+ {
+ c = *s;
+ s++;
+ }
+ if( c != '\0' && i_text+1 < sizeof(text) )
+ {
+ text[i_text++] = c;
+ text[i_text] = '\0';
+ }
+ }
+
+ p_subtitle->i_start = i_start * 1000;
+ p_subtitle->i_stop = 0;
+ p_subtitle->psz_text = strdup( text );
+
+ return VLC_SUCCESS;
+}
+
+/* ParseDVDSubtitle
+ * Format
+ * {T h1:m1:s1:c1
+ * Line1
+ * Line2
+ * ...
+ * }
+ * TODO it can have a header
+ * { HEAD
+ * ...
+ * CODEPAGE=...
+ * FORMAT=...
+ * LANG=English
+ * }
+ * LANG support would be cool
+ * CODEPAGE is probably mandatory FIXME
+ */
+static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
+ int i_idx )
+{
+ VLC_UNUSED( i_idx );
+
+ demux_sys_t *p_sys = p_demux->p_sys;
+ text_t *txt = &p_sys->txt;
+ char *psz_text;
+
+ for( ;; )
+ {
+ const char *s = TextGetLine( txt );
+ int h1, m1, s1, c1;
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ if( sscanf( s,
+ "{T %d:%d:%d:%d",
+ &h1, &m1, &s1, &c1 ) == 4 )
+ {
+ p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
+ (int64_t)m1 * 60*1000 +
+ (int64_t)s1 * 1000 +
+ (int64_t)c1 * 10) * 1000;
+ p_subtitle->i_stop = 0;
+ break;
+ }
+ }
+
+ /* Now read text until a line containing "}" */
+ psz_text = strdup("");
+ if( !psz_text )
+ return VLC_ENOMEM;
+ for( ;; )
+ {
+ const char *s = TextGetLine( txt );
+ int i_len;
+ int i_old;
+
+ if( !s )
+ {
+ free( psz_text );
+ return VLC_EGENERIC;
+ }
+
+ i_len = strlen( s );
+ if( i_len == 1 && s[0] == '}')
+ {
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
+ }
+
+ i_old = strlen( psz_text );
+ psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+ strcat( psz_text, s );
+ strcat( psz_text, "\n" );
+ }
+}
+
+/* ParseMPL2
+ * Format
+ * [n1][n2]Line1|Line2|Line3...
+ * where n1 and n2 are the video frame number (n2 can be empty)
+ */
+static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
+{
+ VLC_UNUSED( i_idx );
+
+ demux_sys_t *p_sys = p_demux->p_sys;
+ text_t *txt = &p_sys->txt;
+ char *psz_text;
+ int i;
+
+ for( ;; )
+ {
+ const char *s = TextGetLine( txt );
+ int i_start;
+ int i_stop;
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ psz_text = malloc( strlen(s) + 1 );
+ if( !psz_text )
+ return VLC_ENOMEM;
+
+ i_start = 0;
+ i_stop = 0;
+ if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
+ sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
+ {
+ p_subtitle->i_start = (int64_t)i_start * 100000;
+ p_subtitle->i_stop = (int64_t)i_stop * 100000;
+ break;
+ }
+ free( psz_text );
+ }
+
+ for( i = 0; psz_text[i] != '\0'; )
+ {
+ /* replace | by \n */
+ if( psz_text[i] == '|' )
+ psz_text[i] = '\n';
+
+ /* Remove italic */
+ if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
+ memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
+ else
+ i++;
+ }
+ p_subtitle->psz_text = psz_text;
+ return VLC_SUCCESS;
+}
+
+static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
+{
+ VLC_UNUSED( i_idx );
+
+ demux_sys_t *p_sys = p_demux->p_sys;
+ text_t *txt = &p_sys->txt;
+ char *psz_text = strdup( "" );
+ int i_old = 0;
+ int i_firstline = 1;
+
+ for( ;; )
+ {
+ int t; /* Time */
+
+ const char *s = TextGetLine( txt );
+
+ if( !s )
+ return VLC_EGENERIC;
+
+ /* Data Lines */
+ if( sscanf (s, "-->> %d", &t) == 1)
+ {
+ p_subtitle->i_start = (int64_t)t; /* * FPS*/
+ p_subtitle->i_stop = 0;
+
+ /* Starting of a subtitle */
+ if( i_firstline )