~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/intl/charsets.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 08:57:43 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630085743-l81fgbw9dehvl1ds
Tags: 0.11.1-1ubuntu1
* Merge to Debian unstable.
* Removed gnutls12 porting, this is upstream now.
* Only Ubuntu changes left:
  - Killed type-handling.
  - Add X-Ubuntu-Gettext-Domain to .desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Charsets convertor */
2
 
/* $Id: charsets.c,v 1.108.4.2 2005/09/14 12:07:14 jonas Exp $ */
3
2
 
4
3
#ifdef HAVE_CONFIG_H
5
4
#include "config.h"
21
20
#include "util/fastfind.h"
22
21
#include "util/memory.h"
23
22
#include "util/string.h"
24
 
#include "util/types.h"
25
23
 
26
24
 
27
25
/* Fix namespace clash on MacOS. */
29
27
 
30
28
struct table_entry {
31
29
        unsigned char c;
32
 
        unicode_val u;
 
30
        unicode_val_T u;
33
31
};
34
32
 
35
33
struct codepage_desc {
38
36
        struct table_entry *table;
39
37
};
40
38
 
41
 
#include "codepage.inc"
42
 
#include "uni_7b.inc"
43
 
#include "entity.inc"
 
39
#include "intl/codepage.inc"
 
40
#include "intl/uni_7b.inc"
 
41
#include "intl/entity.inc"
44
42
 
45
43
 
46
44
static char strings[256][2] = {
126
124
        }                                                                               \
127
125
}                                                                                       \
128
126
 
129
 
static const unicode_val strange_chars[32] = {
 
127
static const unicode_val_T strange_chars[32] = {
130
128
0x20ac, 0x0000, 0x002a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021,
131
129
0x005e, 0x2030, 0x0160, 0x003c, 0x0152, 0x0000, 0x0000, 0x0000,
132
130
0x0000, 0x0060, 0x0027, 0x0022, 0x0022, 0x002a, 0x2013, 0x2014,
136
134
#define SYSTEM_CHARSET_FLAG 128
137
135
 
138
136
unsigned char *
139
 
u2cp_(unicode_val u, int to, int no_nbsp_hack)
 
137
u2cp_(unicode_val_T u, int to, int no_nbsp_hack)
140
138
{
141
139
        int j;
142
140
        int s;
147
145
        if (u == 0xad) return "";
148
146
 
149
147
        if (u < 0xa0) {
150
 
                unicode_val strange = strange_chars[u - 0x80];
 
148
                unicode_val_T strange = strange_chars[u - 0x80];
151
149
 
152
150
                if (!strange) return NULL;
153
151
                return u2cp_(strange, to, no_nbsp_hack);
168
166
static unsigned char utf_buffer[7];
169
167
 
170
168
static unsigned char *
171
 
encode_utf_8(unicode_val u)
 
169
encode_utf_8(unicode_val_T u)
172
170
{
173
171
        memset(utf_buffer, 0, 7);
174
172
 
221
219
}
222
220
 
223
221
static void
224
 
add_utf_8(struct conv_table *ct, unicode_val u, unsigned char *str)
 
222
add_utf_8(struct conv_table *ct, unicode_val_T u, unsigned char *str)
225
223
{
226
224
        unsigned char *p = encode_utf_8(u);
227
225
 
290
288
                utf_table[i].u.str = NULL;
291
289
 
292
290
        for (i = 0; codepages[from].table[i].c; i++) {
293
 
                unicode_val u = codepages[from].table[i].u;
 
291
                unicode_val_T u = codepages[from].table[i].u;
294
292
 
295
293
                if (!utf_table[codepages[from].table[i].c].u.str)
296
294
                        utf_table[codepages[from].table[i].c].u.str =
494
492
        if (*str == '#') { /* Numeric entity. */
495
493
                int l = (int) strlen;
496
494
                unsigned char *st = (unsigned char *) str;
497
 
                unicode_val n = 0;
 
495
                unicode_val_T n = 0;
498
496
 
499
497
                if (l == 1) goto end; /* &#; ? */
500
498
                st++, l--;
522
520
                                else
523
521
                                        goto end; /* Bad char. */
524
522
                                /* Limit to 0xFFFFFFFF. */
525
 
                                if (n == (unicode_val) 0xFFFFFFFFu)
 
523
                                if (n >= (unicode_val_T) 0xFFFFFFFFu)
526
524
                                        goto end;
527
525
                        } while (--l);
528
526
                }
559
557
                if (nb_entity_cache[slen] < ENTITY_CACHE_SIZE) nb_entity_cache[slen]++;
560
558
 
561
559
#ifdef DEBUG_ENTITY_CACHE
562
 
                fprintf(stderr, "Added in [%d]: l=%d st='%s'\n", slen,
 
560
                fprintf(stderr, "Added in [%u]: l=%d st='%s'\n", slen,
563
561
                                entity_cache[slen][0].strlen, entity_cache[slen][0].str);
564
562
 
565
563
#endif
573
571
        {
574
572
                unsigned int i;
575
573
 
576
 
                fprintf(stderr, "- Cache entries [%d] -\n", slen);
 
574
                fprintf(stderr, "- Cache entries [%u] -\n", slen);
577
575
                for (i = 0; i < nb_entity_cache[slen] ; i++)
578
 
                        fprintf(stderr, "%d: hits=%d l=%d st='%s'\n", i,
 
576
                        fprintf(stderr, "%d: hits=%u l=%d st='%s'\n", i,
579
577
                                entity_cache[slen][i].hits, entity_cache[slen][i].strlen,
580
578
                                entity_cache[slen][i].str);
581
579
                fprintf(stderr, "-----------------\n");
587
585
 
588
586
unsigned char *
589
587
convert_string(struct conv_table *convert_table,
590
 
               unsigned char *chars, int charslen,
 
588
               unsigned char *chars, int charslen, int cp,
591
589
               enum convert_string_mode mode, int *length,
592
590
               void (*callback)(void *data, unsigned char *buf, int buflen),
593
591
               void *callback_data)
659
657
                            && i > start
660
658
                            && !isasciialpha(chars[i]) && !isdigit(chars[i])) {
661
659
                                translit = get_entity_string(&chars[start], i - start,
662
 
                                                      global_doc_opts->cp);
 
660
                                                      cp);
663
661
                                if (chars[i] != ';') {
664
662
                                        /* Eat &nbsp &nbsp<foo> happily, but
665
663
                                         * pull back from the character after