"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "charsets.c" between
links-1.03.tar.gz and links-1.04.tar.gz

About: Links is a Lynx-like text WWW browser (table support and pop-up dialog boxes).

charsets.c  (links-1.03):charsets.c  (links-1.04)
skipping to change at line 19 skipping to change at line 19
unsigned char *name; unsigned char *name;
unsigned char **aliases; unsigned char **aliases;
struct table_entry *table; struct table_entry *table;
}; };
#include "codepage.inc" #include "codepage.inc"
#include "uni_7b.inc" #include "uni_7b.inc"
#include "entity.inc" #include "entity.inc"
#include "upcase.inc" #include "upcase.inc"
char strings[256][2] = { unsigned char strings[256][2] = {
"\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007", "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017", "\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\033", "\020", "\021", "\022", "\023", "\024", "\025", "\026", "\033",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\033", "\030", "\031", "\032", "\033", "\034", "\035", "\036", "\033",
"\040", "\041", "\042", "\043", "\044", "\045", "\046", "\047", "\040", "\041", "\042", "\043", "\044", "\045", "\046", "\047",
"\050", "\051", "\052", "\053", "\054", "\055", "\056", "\057", "\050", "\051", "\052", "\053", "\054", "\055", "\056", "\057",
"\060", "\061", "\062", "\063", "\064", "\065", "\066", "\067", "\060", "\061", "\062", "\063", "\064", "\065", "\066", "\067",
"\070", "\071", "\072", "\073", "\074", "\075", "\076", "\077", "\070", "\071", "\072", "\073", "\074", "\075", "\076", "\077",
"\100", "\101", "\102", "\103", "\104", "\105", "\106", "\107", "\100", "\101", "\102", "\103", "\104", "\105", "\106", "\107",
"\110", "\111", "\112", "\113", "\114", "\115", "\116", "\117", "\110", "\111", "\112", "\113", "\114", "\115", "\116", "\117",
skipping to change at line 61 skipping to change at line 61
"\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377", "\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377",
}; };
void free_translation_table(struct conv_table *p) void free_translation_table(struct conv_table *p)
{ {
int i; int i;
for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl); for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl);
mem_free(p); mem_free(p);
} }
unsigned char *no_str = NULL; unsigned char no_str[] = "*";
void new_translation_table(struct conv_table *p) void new_translation_table(struct conv_table *p)
{ {
int i; int i;
for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl); for (i = 0; i < 256; i++) if (p[i].t) free_translation_table(p[i].u.tbl);
for (i = 0; i < 128; i++) p[i].t = 0, p[i].u.str = strings[i]; for (i = 0; i < 128; i++) p[i].t = 0, p[i].u.str = strings[i];
for (; i < 256; i++) p[i].t = 0, p[i].u.str = no_str; for (; i < 256; i++) p[i].t = 0, p[i].u.str = no_str;
} }
#define BIN_SEARCH(table, entry, entries, key, result) \ #define BIN_SEARCH(table, entry, entries, key, result) \
{ \ { \
int _s = 0, _e = (entries) - 1; \ int s_ = 0, e_ = (entries) - 1; \
while (_s <= _e || !((result) = -1)) { \ while (s_ <= e_ || !((result) = -1)) { \
int _m = (_s + _e) / 2; \ int m_ = ((unsigned)s_ + (unsigned)e_) / 2; \
if ((table)[_m].entry == (key)) { \ if ((table)[m_].entry == (key)) { \
(result) = _m; \ (result) = m_; \
break; \ break; \
} \ } \
if ((table)[_m].entry > (key)) _e = _m - 1; \ if ((table)[m_].entry > (key)) e_ = m_ - 1; \
if ((table)[_m].entry < (key)) _s = _m + 1; \ if ((table)[m_].entry < (key)) s_ = m_ + 1; \
} \ } \
} \ } \
int strange_chars[32] = { int strange_chars[32] = {
0x20ac, 0x0000, 0x002a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac, 0x0000, 0x002a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021,
0x005e, 0x2030, 0x0160, 0x003c, 0x0152, 0x0000, 0x0000, 0x0000, 0x005e, 0x2030, 0x0160, 0x003c, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x0060, 0x0027, 0x0022, 0x0022, 0x002a, 0x2013, 0x2014, 0x0000, 0x0060, 0x0027, 0x0022, 0x0022, 0x002a, 0x2013, 0x2014,
0x007e, 0x2122, 0x0161, 0x003e, 0x0153, 0x0000, 0x0000, 0x0000, 0x007e, 0x2122, 0x0161, 0x003e, 0x0153, 0x0000, 0x0000, 0x0000,
}; };
static inline unsigned char *u2cp(int u, int to, int fallback) static inline unsigned char *u2cp(int u, int to, int fallback)
{ {
int j, s; int j, s;
again: again:
if (u < 128) return strings[u]; if (u < 128) return strings[u];
if (u == 0xa0) return "\001"; if (u == 0xa0) return strings[1];
if (u == 0xad) return ""; if (u == 0xad) return strings[0];
if (u < 0xa0) { if (u < 0xa0) {
u = strange_chars[u - 0x80]; u = strange_chars[u - 0x80];
if (!u) return NULL; if (!u) return NULL;
goto again; goto again;
} }
for (j = 0; codepages[to].table[j].c; j++) for (j = 0; codepages[to].table[j].c; j++)
if (codepages[to].table[j].u == u) if (codepages[to].table[j].u == u)
return strings[codepages[to].table[j].c]; return strings[codepages[to].table[j].c];
if (!fallback) return NULL; if (!fallback) return NULL;
BIN_SEARCH(unicode_7b, x, N_UNICODE_7B, u, s); BIN_SEARCH(unicode_7b, x, N_UNICODE_7B, u, s);
skipping to change at line 196 skipping to change at line 196
int i; int i;
for (i = 128; i < 256; i++) mem_free(utf_table[i].u.str); for (i = 128; i < 256; i++) mem_free(utf_table[i].u.str);
} }
struct conv_table *get_translation_table_to_utf_8(int from) struct conv_table *get_translation_table_to_utf_8(int from)
{ {
int i; int i;
static int lfr = -1; static int lfr = -1;
if (from == -1) return NULL; if (from == -1) return NULL;
if (from == lfr) return utf_table; if (from == lfr) return utf_table;
lfr = from;
if (utf_table_init) memset(utf_table, 0, sizeof(struct conv_table) * 256) , utf_table_init = 0; if (utf_table_init) memset(utf_table, 0, sizeof(struct conv_table) * 256) , utf_table_init = 0;
else free_utf_table(); else free_utf_table();
for (i = 0; i < 128; i++) utf_table[i].u.str = strings[i]; for (i = 0; i < 128; i++) utf_table[i].u.str = strings[i];
if (codepages[from].table == table_utf_8) { if (codepages[from].table == table_utf_8) {
for (i = 128; i < 256; i++) utf_table[i].u.str = stracpy(strings[ i]); for (i = 128; i < 256; i++) utf_table[i].u.str = stracpy(strings[ i]);
return utf_table; return utf_table;
} }
for (i = 128; i < 256; i++) utf_table[i].u.str = NULL; for (i = 128; i < 256; i++) utf_table[i].u.str = NULL;
for (i = 0; codepages[from].table[i].c; i++) { for (i = 0; codepages[from].table[i].c; i++) {
int u = codepages[from].table[i].u; int u = codepages[from].table[i].u;
skipping to change at line 222 skipping to change at line 223
} }
struct conv_table table[256]; struct conv_table table[256];
static int first = 1; static int first = 1;
void free_conv_table() void free_conv_table()
{ {
if (!utf_table_init) free_utf_table(); if (!utf_table_init) free_utf_table();
if (first) memset(table, 0, sizeof(struct conv_table) * 256), first = 0; if (first) memset(table, 0, sizeof(struct conv_table) * 256), first = 0;
new_translation_table(table); new_translation_table(table);
if (no_str) mem_free(no_str), no_str = NULL;
} }
struct conv_table *get_translation_table(int from, int to) struct conv_table *get_translation_table(int from, int to)
{ {
int i; int i;
static int lfr = -1; static int lfr = -1;
static int lto = -1; static int lto = -1;
if (!no_str) no_str = stracpy("*");
if (first) memset(table, 0, sizeof(struct conv_table) * 256), first = 0; if (first) memset(table, 0, sizeof(struct conv_table) * 256), first = 0;
if (/*from == to ||*/ from == -1 || to == -1) return NULL; if (/*from == to ||*/ from == -1 || to == -1) return NULL;
if (codepages[to].table == table_utf_8) return get_translation_table_to_u tf_8(from); if (codepages[to].table == table_utf_8) return get_translation_table_to_u tf_8(from);
if (from == lfr && to == lto) return table; if (from == lfr && to == lto) return table;
lfr = from; lto = to; lfr = from; lto = to;
new_translation_table(table); new_translation_table(table);
if (codepages[from].table == table_utf_8) { if (codepages[from].table == table_utf_8) {
int j; int j;
for (j = 0; codepages[to].table[j].c; j++) add_utf_8(table, codep ages[to].table[j].u, codepages[to].table[j].u == 0xa0 ? "\001" : codepages[to].t able[j].u == 0xad ? "" : strings[codepages[to].table[j].c]); for (j = 0; codepages[to].table[j].c; j++) add_utf_8(table, codep ages[to].table[j].u, codepages[to].table[j].u == 0xa0 ? strings[1] : codepages[t o].table[j].u == 0xad ? strings[0] : strings[codepages[to].table[j].c]);
for (i = 0; unicode_7b[i].x != -1; i++) if (unicode_7b[i].x >= 0x 80) add_utf_8(table, unicode_7b[i].x, unicode_7b[i].s); for (i = 0; unicode_7b[i].x != -1; i++) if (unicode_7b[i].x >= 0x 80) add_utf_8(table, unicode_7b[i].x, unicode_7b[i].s);
} else for (i = 128; i < 256; i++) { } else for (i = 128; i < 256; i++) {
int j; int j;
char *u; char *u;
for (j = 0; codepages[from].table[j].c; j++) { for (j = 0; codepages[from].table[j].c; j++) {
if (codepages[from].table[j].c == i) goto f; if (codepages[from].table[j].c == i) goto f;
} }
continue; continue;
f: f:
u = u2cp(codepages[from].table[j].u, to, 1); u = u2cp(codepages[from].table[j].u, to, 1);
 End of changes. 9 change blocks. 
14 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)