Mercurial > mplayer.hg
comparison subreader.c @ 10692:7cb48ef05b02
Support for case insensitive string matching in SAMI subtitle files. Patch by Bruno Lecointre.
author | mosu |
---|---|
date | Mon, 25 Aug 2003 09:12:28 +0000 |
parents | 857a34ff479d |
children | 6c56b4aff706 |
comparison
equal
deleted
inserted
replaced
10691:665fd8af2db7 | 10692:7cb48ef05b02 |
---|---|
72 if (i) strcpy(s, s + i); | 72 if (i) strcpy(s, s + i); |
73 i = strlen(s) - 1; | 73 i = strlen(s) - 1; |
74 while (i > 0 && isspace(s[i])) s[i--] = '\0'; | 74 while (i > 0 && isspace(s[i])) s[i--] = '\0'; |
75 } | 75 } |
76 | 76 |
77 static char *stristr(const char *haystack, const char *needle) { | |
78 int len = 0; | |
79 const char *p = haystack; | |
80 | |
81 if (!(haystack && needle)) return NULL; | |
82 | |
83 len=strlen(needle); | |
84 while (*p != '\0') { | |
85 if (strncasecmp(p, needle, len) == 0) return (char*)p; | |
86 p++; | |
87 } | |
88 | |
89 return NULL; | |
90 } | |
77 | 91 |
78 subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { | 92 subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { |
79 static char line[LINE_LEN+1]; | 93 static char line[LINE_LEN+1]; |
80 static char *s = NULL, *slacktime_s; | 94 static char *s = NULL, *slacktime_s; |
81 char text[LINE_LEN+1], *p=NULL, *q; | 95 char text[LINE_LEN+1], *p=NULL, *q; |
90 | 104 |
91 do { | 105 do { |
92 switch (state) { | 106 switch (state) { |
93 | 107 |
94 case 0: /* find "START=" or "Slacktime:" */ | 108 case 0: /* find "START=" or "Slacktime:" */ |
95 slacktime_s = strstr (s, "Slacktime:"); | 109 slacktime_s = stristr (s, "Slacktime:"); |
96 if (slacktime_s) | 110 if (slacktime_s) |
97 sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10; | 111 sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10; |
98 | 112 |
99 s = strstr (s, "Start="); | 113 s = stristr (s, "Start="); |
100 if (s) { | 114 if (s) { |
101 current->start = strtol (s + 6, &s, 0) / 10; | 115 current->start = strtol (s + 6, &s, 0) / 10; |
102 state = 1; continue; | 116 state = 1; continue; |
103 } | 117 } |
104 break; | 118 break; |
105 | 119 |
106 case 1: /* find "<P" */ | 120 case 1: /* find "<P" */ |
107 if ((s = strstr (s, "<P"))) { s += 2; state = 2; continue; } | 121 if ((s = stristr (s, "<P"))) { s += 2; state = 2; continue; } |
108 break; | 122 break; |
109 | 123 |
110 case 2: /* find ">" */ | 124 case 2: /* find ">" */ |
111 if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; } | 125 if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; } |
112 break; | 126 break; |
129 if (p > text + 2) if (*(p-1) == ' ' && *(p-2) == ' ') p--; | 143 if (p > text + 2) if (*(p-1) == ' ' && *(p-2) == ' ') p--; |
130 | 144 |
131 continue; | 145 continue; |
132 | 146 |
133 case 4: /* get current->end or skip <TAG> */ | 147 case 4: /* get current->end or skip <TAG> */ |
134 q = strstr (s, "Start="); | 148 q = stristr (s, "Start="); |
135 if (q) { | 149 if (q) { |
136 current->end = strtol (q + 6, &q, 0) / 10 - 1; | 150 current->end = strtol (q + 6, &q, 0) / 10 - 1; |
137 *p = '\0'; trail_space (text); | 151 *p = '\0'; trail_space (text); |
138 if (text[0] != '\0') | 152 if (text[0] != '\0') |
139 current->text[current->lines++] = strdup (text); | 153 current->text[current->lines++] = strdup (text); |