annotate libass/ass_utils.c @ 33527:9f0812ccc421

Cosmetic: Adjust indent.
author ib
date Tue, 14 Jun 2011 17:53:40 +0000
parents ac6e48baa03d
children 88eebbbbd6a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19405
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
3 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
4 * This file is part of libass.
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
5 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
6 * libass is free software; you can redistribute it and/or modify
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
7 * it under the terms of the GNU General Public License as published by
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
9 * (at your option) any later version.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
10 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
11 * libass is distributed in the hope that it will be useful,
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
14 * GNU General Public License for more details.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
15 *
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
16 * You should have received a copy of the GNU General Public License along
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
17 * with libass; if not, write to the Free Software Foundation, Inc.,
26723
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0f892cd714b2 Use standard license header.
diego
parents: 26036
diff changeset
19 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19405
diff changeset
20
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include <stdlib.h>
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
24 #include <stdio.h>
19405
0797e1b4a4be Replace stdint.h with inttypes.h.
eugeni
parents: 19003
diff changeset
25 #include <inttypes.h>
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
26 #include <ft2build.h>
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
27 #include FT_GLYPH_H
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 30200
diff changeset
28 #include <strings.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
30 #include "ass_library.h"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
31 #include "ass.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32 #include "ass_utils.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
34 int mystrtoi(char **p, int *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
36 double temp_res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
37 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
38 temp_res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
39 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
40 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
41 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
42 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
43 return 0;
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
44 }
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
45
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
46 int mystrtoll(char **p, long long *res)
28717
7bbe6626f0e0 Support fractional arguments for some override tags.
eugeni
parents: 26738
diff changeset
47 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 double temp_res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
49 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
50 temp_res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
51 *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
52 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
53 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
54 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
55 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
58 int mystrtou32(char **p, int base, uint32_t *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
60 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
61 *res = strtoll(*p, p, base);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
62 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
63 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
64 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
65 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
68 int mystrtod(char **p, double *res)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
70 char *start = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
71 *res = ass_strtod(*p, p);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
72 if (*p != start)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
73 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
74 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
75 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
76 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
77
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
78 int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
80 uint32_t color = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
81 int result;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
82 char *p = *q;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
83 int base = hex ? 16 : 10;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
84
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
85 if (*p == '&')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
86 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
87 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
88 ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
89
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
90 if (*p == 'H' || *p == 'h') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
91 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
92 result = mystrtou32(&p, 16, &color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
93 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
94 result = mystrtou32(&p, base, &color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
95 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28785
diff changeset
96
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
97 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
98 unsigned char *tmp = (unsigned char *) (&color);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
99 unsigned char b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
100 b = tmp[0];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
101 tmp[0] = tmp[3];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
102 tmp[3] = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
103 b = tmp[1];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
104 tmp[1] = tmp[2];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
105 tmp[2] = b;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
106 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
107 if (*p == '&')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
108 ++p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
109 *q = p;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
111 *res = color;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
112 return result;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114
28785
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
115 // Return a boolean value for a string
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
116 char parse_bool(char *str)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
117 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
118 while (*str == ' ' || *str == '\t')
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
119 str++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
120 if (!strncasecmp(str, "yes", 3))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
122 else if (strtol(str, NULL, 10) > 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
123 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
124 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
128 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
129 va_list va;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
130 va_start(va, fmt);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
131 priv->msg_callback(lvl, fmt, va, priv->msg_callback_data);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
132 va_end(va);
28785
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
133 }
0366ab2c1cb9 Support ScaledBorderAndShadow property.
greg
parents: 28718
diff changeset
134
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
135 unsigned ass_utf8_get_char(char **str)
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
136 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
137 uint8_t *strp = (uint8_t *) * str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 unsigned c = *strp++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 unsigned mask = 0x80;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 int len = -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 while (c & mask) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
142 mask >>= 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
143 len++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
144 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
145 if (len <= 0 || len > 4)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
147 c &= mask - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
148 while ((*strp & 0xc0) == 0x80) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
149 if (len-- <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
150 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
151 c = (c << 6) | (*strp++ & 0x3f);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
152 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
153 if (len)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
154 goto no_utf8;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
155 *str = (char *) strp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
156 return c;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
157
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
158 no_utf8:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
159 strp = (uint8_t *) * str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
160 c = *strp++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
161 *str = (char *) strp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
162 return c;
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
163 }
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
164
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
165 #ifdef CONFIG_ENCA
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
166 void *ass_guess_buffer_cp(ASS_Library *library, unsigned char *buffer,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
167 int buflen, char *preferred_language,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
168 char *fallback)
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
169 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
170 const char **languages;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
171 size_t langcnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
172 EncaAnalyser analyser;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
173 EncaEncoding encoding;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
174 char *detected_sub_cp = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
175 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
176
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
177 languages = enca_get_languages(&langcnt);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
178 ass_msg(library, MSGL_V, "ENCA supported languages");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
179 for (i = 0; i < langcnt; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
180 ass_msg(library, MSGL_V, "lang %s", languages[i]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
181 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
182
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
183 for (i = 0; i < langcnt; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
184 const char *tmp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
185
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
186 if (strcasecmp(languages[i], preferred_language) != 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
187 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
188 analyser = enca_analyser_alloc(languages[i]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
189 encoding = enca_analyse_const(analyser, buffer, buflen);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
190 tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
191 if (tmp && encoding.charset != ENCA_CS_UNKNOWN) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
192 detected_sub_cp = strdup(tmp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
193 ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
194 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
195 enca_analyser_free(analyser);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
196 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
197
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
198 free(languages);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
199
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
200 if (!detected_sub_cp) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
201 detected_sub_cp = strdup(fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
202 ass_msg(library, MSGL_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
203 "ENCA detection failed: fallback to %s", fallback);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
204 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
205
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
206 return detected_sub_cp;
26034
e8289d9a4fec Some debugging routines.
eugeni
parents: 22947
diff changeset
207 }
26036
8d8c52a169ad Comment out dump_glyph(): it is unused and, as it is now, breaks compilation.
eugeni
parents: 26034
diff changeset
208 #endif