]> arthur.barton.de Git - netatalk.git/blob - include/atalk/unicode.h
fix NetBSD compile problems
[netatalk.git] / include / atalk / unicode.h
1
2 #ifndef _ATALK_UNICODE_H
3 #define _ATALK_UNICODE_H 1
4
5 #include <sys/cdefs.h>
6 #include <netatalk/endian.h>
7 #include <errno.h>
8 #include <sys/param.h>
9
10 #define ucs2_t u_int16_t
11
12 #ifndef MIN
13 #define MIN(a,b)     ((a)<(b)?(a):(b))
14 #endif /* ! MIN */
15
16 #ifndef MAX
17 #define MAX(a,b)     ((a)>(b)?(a):(b))
18 #endif /* ! MIN */
19
20 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
21
22 #ifndef EILSEQ
23 #define EILSEQ       84      /* Illegal byte sequence.  */
24 #endif
25
26 /* generic iconv conversion structure */
27 typedef struct {
28         size_t (*direct)(void *cd, char **inbuf, size_t *inbytesleft,
29                          char **outbuf, size_t *outbytesleft);
30         size_t (*pull)(void *cd, char **inbuf, size_t *inbytesleft,
31                        char **outbuf, size_t *outbytesleft);
32         size_t (*push)(void *cd, char **inbuf, size_t *inbytesleft,
33                        char **outbuf, size_t *outbytesleft);
34         void *cd_direct, *cd_pull, *cd_push;
35         char *from_name, *to_name;
36 } *atalk_iconv_t;
37
38 #define CHARSET_CLIENT 1
39 #define CHARSET_VOLUME 2
40 #define CHARSET_PRECOMPOSED 4
41 #define CHARSET_DECOMPOSED  8
42 #define CHARSET_MULTIBYTE   16
43 #define CHARSET_WIDECHAR    32
44 #define CHARSET_ICONV       64
45
46 #define IGNORE_CHAR     '_'
47
48 /* conversion flags */
49 #define CONV_IGNORE             (1<<0) /* ignore EILSEQ, replace with IGNORE_CHAR */
50 #define CONV_ESCAPEHEX          (1<<1) /* escape unconvertable chars with :[UCS2HEX] */
51 #define CONV_ESCAPEDOTS         (1<<2) /* escape leading dots with :2600 */
52 #define CONV_UNESCAPEHEX        (1<<3) 
53 #define CONV_TOUPPER            (1<<4) /* convert to UPPERcase */
54 #define CONV_TOLOWER            (1<<5) /* convert to lowercase */
55 #define CONV_PRECOMPOSE         (1<<6) /* precompose */
56 #define CONV_DECOMPOSE          (1<<7) /* precompose */
57
58 /* conversion return flags */
59 #define CONV_REQMANGLE  (1<<14) /* mangling of returned name is required */
60 #define CONV_REQESCAPE  (1<<15) /* espace unconvertable chars with :[UCS2HEX] */
61
62 /* this defines the charset types used in samba */
63 typedef enum {CH_UCS2=0, CH_UTF8=1, CH_MAC=2, CH_UNIX=3, CH_UTF8_MAC=4} charset_t;
64
65 #define NUM_CHARSETS 5
66
67 /*
68  *   for each charset we have a function that pulls from that charset to
69  *     a ucs2 buffer, and a function that pushes to a ucs2 buffer
70  *     */
71
72 struct charset_functions {
73         const char *name;
74         const long kTextEncoding;
75         size_t (*pull)(void *, char **inbuf, size_t *inbytesleft,
76                                    char **outbuf, size_t *outbytesleft);
77         size_t (*push)(void *, char **inbuf, size_t *inbytesleft,
78                                    char **outbuf, size_t *outbytesleft);
79         u_int32_t flags;
80         struct charset_functions *prev, *next;
81 };
82
83 /* from iconv.c */
84 extern atalk_iconv_t    atalk_iconv_open __P((const char *, const char *));
85 extern size_t           atalk_iconv __P((atalk_iconv_t, const char **, size_t *, char **, size_t *));
86 extern int              atalk_iconv_close __P((atalk_iconv_t));
87 extern struct charset_functions *find_charset_functions __P((const char *));
88 extern int              atalk_register_charset __P((struct charset_functions *));
89
90 /* from util_unistr.c */
91 extern ucs2_t   toupper_w  __P((ucs2_t));
92 extern ucs2_t   tolower_w  __P((ucs2_t));
93 extern int      strupper_w __P((ucs2_t *));
94 extern int      strlower_w __P((ucs2_t *));
95 extern int      islower_w  __P((ucs2_t));
96 extern int      islower_w  __P((ucs2_t));
97 extern size_t   strlen_w   __P((const ucs2_t *));
98 extern size_t   strnlen_w  __P((const ucs2_t *, size_t));
99 extern ucs2_t*  strchr_w   __P((const ucs2_t *, ucs2_t));
100 extern int      strcmp_w   __P((const ucs2_t *, const ucs2_t *));
101 extern int      strncmp_w  __P((const ucs2_t *, const ucs2_t *, size_t));
102 extern int      strcasecmp_w  __P((const ucs2_t *, const ucs2_t *));
103 extern int      strncasecmp_w __P((const ucs2_t *, const ucs2_t *, size_t));
104 extern ucs2_t   *strcasestr_w __P((const ucs2_t *, const ucs2_t *));
105 extern ucs2_t   *strndup_w __P((const ucs2_t *, size_t));
106 extern ucs2_t   *strdup_w  __P((const ucs2_t *));
107 extern ucs2_t   *strncpy_w __P((ucs2_t *, const ucs2_t *, const size_t));
108 extern ucs2_t   *strncat_w __P((ucs2_t *, const ucs2_t *, const size_t));
109 extern ucs2_t   *strcat_w  __P((ucs2_t *, const ucs2_t *));
110 extern size_t   precompose_w __P((ucs2_t *, size_t, ucs2_t *,size_t *));
111 extern size_t   decompose_w  __P((ucs2_t *, size_t, ucs2_t *,size_t *));
112 extern size_t   utf8_charlen __P(( char* ));
113 extern size_t   utf8_strlen_validate __P(( char *));
114
115 /* from charcnv.c */
116 extern void     init_iconv __P((void));
117 extern size_t   convert_string __P((charset_t, charset_t, void const *, size_t, void *, size_t));
118 extern size_t   convert_string_allocate __P((charset_t, charset_t, void const *, size_t, char **));
119 extern size_t   utf8_strupper __P((const char *, size_t, char *, size_t));
120 extern size_t   utf8_strlower __P((const char *, size_t, char *, size_t));
121 extern size_t   unix_strupper __P((const char *, size_t, char *, size_t));
122 extern size_t   unix_strlower __P((const char *, size_t, char *, size_t));
123 extern size_t   charset_strupper __P((charset_t, const char *, size_t, char *, size_t));
124 extern size_t   charset_strlower __P((charset_t, const char *, size_t, char *, size_t));
125
126 extern size_t   charset_to_ucs2_allocate __P((charset_t, ucs2_t **dest, const char *src));
127 extern size_t   charset_to_utf8_allocate __P((charset_t, char **dest, const char *src));
128 extern size_t   ucs2_to_charset_allocate __P((charset_t, char **dest, const ucs2_t *src));
129 extern size_t   utf8_to_charset_allocate __P((charset_t, char **dest, const char *src));
130 extern size_t   ucs2_to_charset __P((charset_t, const ucs2_t *src, char *dest, size_t));
131
132 extern size_t   convert_charset __P((charset_t, charset_t, charset_t, char *, size_t, char *, size_t, u_int16_t *));
133
134 extern size_t   charset_precompose __P(( charset_t, char *, size_t, char *, size_t));
135 extern size_t   charset_decompose  __P(( charset_t, char *, size_t, char *, size_t));
136 extern size_t   utf8_precompose __P(( char *, size_t, char *, size_t));
137 extern size_t   utf8_decompose  __P(( char *, size_t, char *, size_t));
138
139 extern charset_t add_charset __P((char* name));
140
141
142
143 #endif