NetSurf
encoding.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Ole Loots <ole@monochrom.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdlib.h>
20
21#include "utils/errors.h"
22#include "netsurf/utf8.h"
23
24#include "atari/encoding.h"
25
26
27/* TODO: this need a rework..., encoding to atari st doesn|t always work.
28( gui_add_to_clipboard...) */
30 size_t len,
31 char **result)
32{
33 nserror r;
34 r = utf8_to_enc(string, "ATARIST", len, result);
35 if (r != NSERROR_OK) {
36 r = utf8_to_enc(string, "UTF-8", len, result);
37 assert( r == NSERROR_OK );
38 }
39 return r;
40}
41
42
43nserror utf8_from_local_encoding(const char *string, size_t len, char **result)
44{
45 return utf8_from_enc(string, "ATARIST", len, result, NULL);
46}
47
48
49/* borrowed from highwire project: */
50static const uint16_t Atari_to_Unicode[] = {
51 /* .0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .A .B .C .D .E .F */
52 /* 7F */ 0x0394,
53 /* 8. */ 0x00C7,0x00FC,0x00E9,0x00E2,0x00E4,0x00E0,0x00E5,0x00E7,0x00EA,0x00EB,0x00E8,0x00EF,0x00EE,0x00EC,0x00C4,0x00C5,
54 /* 9. */ 0x00C9,0x00E6,0x00C6,0x00F4,0x00F6,0x00F2,0x00FB,0x00F9,0x00FF,0x00D6,0x00DC,0x00A2,0x00A3,0x00A5,0x00DF,0x0192,
55 /* A. */ 0x00E1,0x00ED,0x00F3,0x00FA,0x00F1,0x00D1,0x00AA,0x00BA,0x00BF,0x2310,0x00AC,0x00BD,0x00BC,0x00A1,0x00AB,0x00BB,
56 /* B. */ 0x00C3,0x00F5,0x00D8,0x00F8,0x0153,0x0152,0x00C0,0x00C3,0x00D5,0x00A8,0x00B4,0x2020,0x00B6,0x00A9,0x00AE,0x2122,
57 /* C. */ 0x0133,0x0132,0x05D0,0x05D1,0x05D2,0x05D3,0x05D4,0x05D5,0x05D6,0x05D7,0x05D8,0x05D9,0x05DB,0x05DC,0x05DE,0x05E0,
58 /* D. */ 0x05E1,0x05E2,0x05E4,0x05E6,0x05E7,0x05E8,0x05E9,0x05EA,0x05DF,0x05DA,0x05DD,0x05E3,0x05E5,0x00A7,0x2038,0x221E,
59 /* E. */ 0x03B1,0x03B2,0x0393,0x03C0,0x03A3,0x03C3,0x00B5,0x03C4,0x03A6,0x0398,0x03A9,0x03B4,0x222E,0x03C6,0x2208,0x2229,
60 /* F. */ 0x2261,0x00B1,0x2265,0x2264,0x2320,0x2321,0x00F7,0x2248,0x00B0,0x2022,0x00B7,0x221A,0x207F,0x00B2,0x00B3,0x00AF
61};
62#define BEG_Atari_to_Unicode 0x7F
63
64int atari_to_ucs4(unsigned char atari)
65{
66 uint32_t ucs4 = 0xfffd;
67 if ( atari >= BEG_Atari_to_Unicode && atari <= 0xFE ) {
68 ucs4 = (int)Atari_to_Unicode[(short)atari - BEG_Atari_to_Unicode];
69 } else {
70 ucs4 = (int)atari;
71 }
72 return( ucs4 );
73}
74
75
76static struct gui_utf8_table utf8_table = {
78 .local_to_utf8 = utf8_from_local_encoding,
79};
80
STATIC char result[100]
Definition: arexx.c:77
int atari_to_ucs4(unsigned char atari)
Definition: encoding.c:64
#define BEG_Atari_to_Unicode
Definition: encoding.c:62
static struct gui_utf8_table utf8_table
Definition: encoding.c:76
struct gui_utf8_table * atari_utf8_table
Definition: encoding.c:81
static const uint16_t Atari_to_Unicode[]
Definition: encoding.c:50
nserror utf8_to_local_encoding(const char *string, size_t len, char **result)
Definition: encoding.c:29
nserror utf8_from_local_encoding(const char *string, size_t len, char **result)
Definition: encoding.c:43
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
Interface to platform-specific utf8 operations.
User interface utf8 characterset conversion routines.
Definition: utf8.h:31
nserror(* utf8_to_local)(const char *string, size_t len, char **result)
Convert a UTF-8 encoded string into the system local encoding.
Definition: utf8.h:40
nserror utf8_from_enc(const char *string, const char *encname, size_t len, char **result, size_t *result_len)
Convert a string in the named encoding into a UTF-8 string.
Definition: utf8.c:321
nserror utf8_to_enc(const char *string, const char *encname, size_t len, char **result)
Convert a UTF8 string into the named encoding.
Definition: utf8.c:314