1 /*
2 * Copyright (C) International Business Machines Corp., 2000-2002
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * the 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef _H_JFS_UNICODE
20 #define _H_JFS_UNICODE
21
22 #include <asm/byteorder.h>
23 #include "jfs_types.h"
24
25 typedef struct {
26 wchar_t start;
27 wchar_t end;
28 signed char *table;
29 } UNICASERANGE;
30
31 extern signed char UniUpperTable[512];
32 extern UNICASERANGE UniUpperRange[];
33 extern int get_UCSname(struct component_name *, struct dentry *);
34 extern int jfs_strfromUCS_le(char *, const wchar_t *, int, struct nls_table *);
35
36 #define free_UCSname(COMP) kfree((COMP)->name)
37
38 /*
39 * UniStrcpy: Copy a string
40 */
UniStrcpy(wchar_t * ucs1,const wchar_t * ucs2)41 static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
42 {
43 wchar_t *anchor = ucs1; /* save the start of result string */
44
45 while ((*ucs1++ = *ucs2++));
46 return anchor;
47 }
48
49
50
51 /*
52 * UniStrncpy: Copy length limited string with pad
53 */
UniStrncpy(wchar_t * ucs1,const wchar_t * ucs2,size_t n)54 static inline wchar_t *UniStrncpy(wchar_t * ucs1, const wchar_t * ucs2,
55 size_t n)
56 {
57 wchar_t *anchor = ucs1;
58
59 while (n-- && *ucs2) /* Copy the strings */
60 *ucs1++ = *ucs2++;
61
62 n++;
63 while (n--) /* Pad with nulls */
64 *ucs1++ = 0;
65 return anchor;
66 }
67
68 /*
69 * UniStrncmp_le: Compare length limited string - native to little-endian
70 */
UniStrncmp_le(const wchar_t * ucs1,const wchar_t * ucs2,size_t n)71 static inline int UniStrncmp_le(const wchar_t * ucs1, const wchar_t * ucs2,
72 size_t n)
73 {
74 if (!n)
75 return 0; /* Null strings are equal */
76 while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
77 ucs1++;
78 ucs2++;
79 }
80 return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
81 }
82
83 /*
84 * UniStrncpy_le: Copy length limited string with pad to little-endian
85 */
UniStrncpy_le(wchar_t * ucs1,const wchar_t * ucs2,size_t n)86 static inline wchar_t *UniStrncpy_le(wchar_t * ucs1, const wchar_t * ucs2,
87 size_t n)
88 {
89 wchar_t *anchor = ucs1;
90
91 while (n-- && *ucs2) /* Copy the strings */
92 *ucs1++ = __le16_to_cpu(*ucs2++);
93
94 n++;
95 while (n--) /* Pad with nulls */
96 *ucs1++ = 0;
97 return anchor;
98 }
99
100
101 /*
102 * UniToupper: Convert a unicode character to upper case
103 */
UniToupper(wchar_t uc)104 static inline wchar_t UniToupper(wchar_t uc)
105 {
106 UNICASERANGE *rp;
107
108 if (uc < sizeof(UniUpperTable)) { /* Latin characters */
109 return uc + UniUpperTable[uc]; /* Use base tables */
110 } else {
111 rp = UniUpperRange; /* Use range tables */
112 while (rp->start) {
113 if (uc < rp->start) /* Before start of range */
114 return uc; /* Uppercase = input */
115 if (uc <= rp->end) /* In range */
116 return uc + rp->table[uc - rp->start];
117 rp++; /* Try next range */
118 }
119 }
120 return uc; /* Past last range */
121 }
122
123
124 /*
125 * UniStrupr: Upper case a unicode string
126 */
UniStrupr(wchar_t * upin)127 static inline wchar_t *UniStrupr(wchar_t * upin)
128 {
129 wchar_t *up;
130
131 up = upin;
132 while (*up) { /* For all characters */
133 *up = UniToupper(*up);
134 up++;
135 }
136 return upin; /* Return input pointer */
137 }
138
139 #endif /* !_H_JFS_UNICODE */
140