Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 *   Copyright (C) International Business Machines Corp., 2000-2002
  4 *   Portions Copyright (C) Christoph Hellwig, 2001-2002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6#ifndef _H_JFS_UNICODE
  7#define _H_JFS_UNICODE
  8
  9#include <linux/slab.h>
 10#include <asm/byteorder.h>
 11#include "jfs_types.h"
 12
 13typedef struct {
 14	wchar_t start;
 15	wchar_t end;
 16	signed char *table;
 17} UNICASERANGE;
 18
 19extern signed char UniUpperTable[512];
 20extern UNICASERANGE UniUpperRange[];
 21extern int get_UCSname(struct component_name *, struct dentry *);
 22extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
 23
 24#define free_UCSname(COMP) kfree((COMP)->name)
 25
 26/*
 27 * UniStrcpy:  Copy a string
 28 */
 29static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
 30{
 31	wchar_t *anchor = ucs1;	/* save the start of result string */
 32
 33	while ((*ucs1++ = *ucs2++));
 34	return anchor;
 35}
 36
 37
 38
 39/*
 40 * UniStrncpy:  Copy length limited string with pad
 41 */
 42static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
 43				  size_t n)
 44{
 45	__le16 *anchor = ucs1;
 46
 47	while (n-- && *ucs2)	/* Copy the strings */
 48		*ucs1++ = *ucs2++;
 49
 50	n++;
 51	while (n--)		/* Pad with nulls */
 52		*ucs1++ = 0;
 53	return anchor;
 54}
 55
 56/*
 57 * UniStrncmp_le:  Compare length limited string - native to little-endian
 58 */
 59static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
 60				size_t n)
 61{
 62	if (!n)
 63		return 0;	/* Null strings are equal */
 64	while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
 65		ucs1++;
 66		ucs2++;
 67	}
 68	return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
 69}
 70
 71/*
 72 * UniStrncpy_to_le:  Copy length limited string with pad to little-endian
 73 */
 74static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
 75				       size_t n)
 76{
 77	__le16 *anchor = ucs1;
 78
 79	while (n-- && *ucs2)	/* Copy the strings */
 80		*ucs1++ = cpu_to_le16(*ucs2++);
 81
 82	n++;
 83	while (n--)		/* Pad with nulls */
 84		*ucs1++ = 0;
 85	return anchor;
 86}
 87
 88/*
 89 * UniStrncpy_from_le:  Copy length limited string with pad from little-endian
 90 */
 91static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
 92					  size_t n)
 93{
 94	wchar_t *anchor = ucs1;
 95
 96	while (n-- && *ucs2)	/* Copy the strings */
 97		*ucs1++ = __le16_to_cpu(*ucs2++);
 98
 99	n++;
100	while (n--)		/* Pad with nulls */
101		*ucs1++ = 0;
102	return anchor;
103}
104
105/*
106 * UniToupper:  Convert a unicode character to upper case
107 */
108static inline wchar_t UniToupper(wchar_t uc)
109{
110	UNICASERANGE *rp;
111
112	if (uc < sizeof(UniUpperTable)) {	/* Latin characters */
113		return uc + UniUpperTable[uc];	/* Use base tables */
114	} else {
115		rp = UniUpperRange;	/* Use range tables */
116		while (rp->start) {
117			if (uc < rp->start)	/* Before start of range */
118				return uc;	/* Uppercase = input */
119			if (uc <= rp->end)	/* In range */
120				return uc + rp->table[uc - rp->start];
121			rp++;	/* Try next range */
122		}
123	}
124	return uc;		/* Past last range */
125}
126
127
128/*
129 * UniStrupr:  Upper case a unicode string
130 */
131static inline wchar_t *UniStrupr(wchar_t * upin)
132{
133	wchar_t *up;
134
135	up = upin;
136	while (*up) {		/* For all characters */
137		*up = UniToupper(*up);
138		up++;
139	}
140	return upin;		/* Return input pointer */
141}
142
143#endif				/* !_H_JFS_UNICODE */
v4.10.11
 
  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 <linux/slab.h>
 23#include <asm/byteorder.h>
 24#include "jfs_types.h"
 25
 26typedef struct {
 27	wchar_t start;
 28	wchar_t end;
 29	signed char *table;
 30} UNICASERANGE;
 31
 32extern signed char UniUpperTable[512];
 33extern UNICASERANGE UniUpperRange[];
 34extern int get_UCSname(struct component_name *, struct dentry *);
 35extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *);
 36
 37#define free_UCSname(COMP) kfree((COMP)->name)
 38
 39/*
 40 * UniStrcpy:  Copy a string
 41 */
 42static inline wchar_t *UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
 43{
 44	wchar_t *anchor = ucs1;	/* save the start of result string */
 45
 46	while ((*ucs1++ = *ucs2++));
 47	return anchor;
 48}
 49
 50
 51
 52/*
 53 * UniStrncpy:  Copy length limited string with pad
 54 */
 55static inline __le16 *UniStrncpy_le(__le16 * ucs1, const __le16 * ucs2,
 56				  size_t n)
 57{
 58	__le16 *anchor = ucs1;
 59
 60	while (n-- && *ucs2)	/* Copy the strings */
 61		*ucs1++ = *ucs2++;
 62
 63	n++;
 64	while (n--)		/* Pad with nulls */
 65		*ucs1++ = 0;
 66	return anchor;
 67}
 68
 69/*
 70 * UniStrncmp_le:  Compare length limited string - native to little-endian
 71 */
 72static inline int UniStrncmp_le(const wchar_t * ucs1, const __le16 * ucs2,
 73				size_t n)
 74{
 75	if (!n)
 76		return 0;	/* Null strings are equal */
 77	while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
 78		ucs1++;
 79		ucs2++;
 80	}
 81	return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
 82}
 83
 84/*
 85 * UniStrncpy_to_le:  Copy length limited string with pad to little-endian
 86 */
 87static inline __le16 *UniStrncpy_to_le(__le16 * ucs1, const wchar_t * ucs2,
 88				       size_t n)
 89{
 90	__le16 *anchor = ucs1;
 91
 92	while (n-- && *ucs2)	/* Copy the strings */
 93		*ucs1++ = cpu_to_le16(*ucs2++);
 94
 95	n++;
 96	while (n--)		/* Pad with nulls */
 97		*ucs1++ = 0;
 98	return anchor;
 99}
100
101/*
102 * UniStrncpy_from_le:  Copy length limited string with pad from little-endian
103 */
104static inline wchar_t *UniStrncpy_from_le(wchar_t * ucs1, const __le16 * ucs2,
105					  size_t n)
106{
107	wchar_t *anchor = ucs1;
108
109	while (n-- && *ucs2)	/* Copy the strings */
110		*ucs1++ = __le16_to_cpu(*ucs2++);
111
112	n++;
113	while (n--)		/* Pad with nulls */
114		*ucs1++ = 0;
115	return anchor;
116}
117
118/*
119 * UniToupper:  Convert a unicode character to upper case
120 */
121static inline wchar_t UniToupper(wchar_t uc)
122{
123	UNICASERANGE *rp;
124
125	if (uc < sizeof(UniUpperTable)) {	/* Latin characters */
126		return uc + UniUpperTable[uc];	/* Use base tables */
127	} else {
128		rp = UniUpperRange;	/* Use range tables */
129		while (rp->start) {
130			if (uc < rp->start)	/* Before start of range */
131				return uc;	/* Uppercase = input */
132			if (uc <= rp->end)	/* In range */
133				return uc + rp->table[uc - rp->start];
134			rp++;	/* Try next range */
135		}
136	}
137	return uc;		/* Past last range */
138}
139
140
141/*
142 * UniStrupr:  Upper case a unicode string
143 */
144static inline wchar_t *UniStrupr(wchar_t * upin)
145{
146	wchar_t *up;
147
148	up = upin;
149	while (*up) {		/* For all characters */
150		*up = UniToupper(*up);
151		up++;
152	}
153	return upin;		/* Return input pointer */
154}
155
156#endif				/* !_H_JFS_UNICODE */