Mercurial > mplayer.hg
comparison subreader.c @ 31280:17db8e56de4c
Extract duplicated code into a separate function.
author | reimar |
---|---|
date | Mon, 07 Jun 2010 19:01:15 +0000 |
parents | 0fc579d95340 |
children | 91b713df588f |
comparison
equal
deleted
inserted
replaced
31279:0fc579d95340 | 31280:17db8e56de4c |
---|---|
109 } | 109 } |
110 | 110 |
111 return NULL; | 111 return NULL; |
112 } | 112 } |
113 | 113 |
114 static void sami_add_line(subtitle *current, char *buffer, char **pos) { | |
115 char *p = *pos; | |
116 *p = 0; | |
117 trail_space(buffer); | |
118 if (*buffer && current->lines < SUB_MAX_TEXT) | |
119 current->text[current->lines++] = strdup(buffer); | |
120 *pos = buffer; | |
121 } | |
122 | |
114 static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, int utf16) { | 123 static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, int utf16) { |
115 static char line[LINE_LEN+1]; | 124 static char line[LINE_LEN+1]; |
116 static char *s = NULL, *slacktime_s; | 125 static char *s = NULL, *slacktime_s; |
117 char text[LINE_LEN+1], *p=NULL, *q; | 126 char text[LINE_LEN+1], *p=NULL, *q; |
118 int state; | 127 int state; |
160 break; | 169 break; |
161 | 170 |
162 case 3: /* get all text until '<' appears */ | 171 case 3: /* get all text until '<' appears */ |
163 if (*s == '\0') break; | 172 if (*s == '\0') break; |
164 else if (!strncasecmp (s, "<br>", 4)) { | 173 else if (!strncasecmp (s, "<br>", 4)) { |
165 *p = '\0'; p = text; trail_space (text); | 174 sami_add_line(current, text, &p); |
166 if (text[0] != '\0' && current->lines < SUB_MAX_TEXT) | |
167 current->text[current->lines++] = strdup (text); | |
168 s += 4; | 175 s += 4; |
169 } | 176 } |
170 else if ((*s == '{') && !sub_no_text_pp) { state = 5; ++s; continue; } | 177 else if ((*s == '{') && !sub_no_text_pp) { state = 5; ++s; continue; } |
171 else if (*s == '<') { state = 4; } | 178 else if (*s == '<') { state = 4; } |
172 else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; } | 179 else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; } |
241 } while (state != 99); | 248 } while (state != 99); |
242 | 249 |
243 // For the last subtitle | 250 // For the last subtitle |
244 if (current->end <= 0) { | 251 if (current->end <= 0) { |
245 current->end = current->start + sub_slacktime; | 252 current->end = current->start + sub_slacktime; |
246 *p = '\0'; trail_space (text); | 253 sami_add_line(current, text, &p); |
247 if (text[0] != '\0' && current->lines < SUB_MAX_TEXT) | |
248 current->text[current->lines++] = strdup (text); | |
249 } | 254 } |
250 | 255 |
251 return current; | 256 return current; |
252 } | 257 } |
253 | 258 |