-
Notifications
You must be signed in to change notification settings - Fork 2
/
gtk_charset.c
82 lines (72 loc) · 2.76 KB
/
gtk_charset.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "gtk_charset.h"
/* common coded character sets listed with Gnu iconv --list
* and that are regularly encountered.
*/
const gchar *charset[] = { "US-ASCII",
"UTF-8"
"UTF-16"
"UTF-16BE",
"UTF-16LE",
"UTF-32",
"UTF-32BE",
"UTF-32LE",
"UTF-7",
"MACINTOSH",
"MS-ANSI",
"ANSI_X3.4-1968",
"ANSI_X3.4-1986",
"CP1252"};
/* Byte Order Mark strings and definitions */
const gchar *bomstr[] = { "UTF-8 NoBOM",
"UTF-8",
"UTF-16 (BE)",
"UTF-16 (LE)",
"UTF-32 (BE)",
"UTF-32 (LE)",
"UTF-7",
"UTF-7",
"UTF-7",
"UTF-7",
"UTF-7",
"UTF-1",
"UTF-EBCDIC",
"SCSU",
"BOCU-1",
"GB-18030" };
const guchar bomdef[][6] = {{0x3, 0xff, 0xff, 0xff}, /* dummy mark */
{0x3, 0xef, 0xbb, 0xbf},
{0x2, 0xfe, 0xff},
{0x2, 0xff, 0xfe},
{0x4, 0x0, 0x0, 0xfe, 0xff},
{0x4, 0xff, 0xfe, 0x0, 0x0},
{0x4, 0x2b, 0x2f, 0x76, 0x38},
{0x4, 0x2b, 0x2f, 0x76, 0x39},
{0x4, 0x2b, 0x2f, 0x76, 0x2b},
{0x4, 0x2b, 0x2f, 0x76, 0x2f},
{0x4, 0x2b, 0x2f, 0x76, 0x38, 0x2d},
{0x3, 0xf7, 0x64, 0x4c},
{0x4, 0xdd, 0x73, 0x66, 0x73},
{0x3, 0xe, 0xfe, 0xff},
{0x3, 0xfb, 0xee, 0x28},
{0x4, 0x84, 0x31, 0x95, 0x33}};
/** get BOM from file */
gint buffer_file_get_bom (const gchar *buf, gpointer data)
{
mainwin_t *app = data;
guchar bomchk[BOMC] = {0};
gint i, j,
n = 0,
bom = 0;
for (n = 0; buf[n] && n < BOMC; n++)
bomchk[n] = buf[n];
for (i = 0; i < NBOM; i++) {
for (j = 1; j <= n && j <= (gint)bomdef[i][0]; j++)
if (bomdef[i][j] != bomchk[j-1])
goto nextbom;
bom = i;
goto bomdone;
nextbom:;
}
bomdone:;
return (app->bom = bom);
}