xref: /titanic_50/usr/src/lib/libast/common/include/ccode.h (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 /*
25  * Glenn Fowler
26  * AT&T Research
27  *
28  * character code map interface
29  *
30  * NOTE: used for mapping between 8-bit character encodings
31  *	 ISO character sets are handled by sfio
32  */
33 
34 #ifndef _CHARCODE_H
35 #define _CHARCODE_H	1
36 
37 #include <ast.h>
38 #include <ast_ccode.h>
39 
40 typedef struct Ccmap_s
41 {
42 	const char*	name;	/* code set name		*/
43 	const char*	match;	/* strmatch() pattern		*/
44 	const char*	desc;	/* code set description		*/
45 	const char*	canon;	/* canonical name format	*/
46 	const char*	index;	/* default index		*/
47 	int		ccode;	/* <ccode.h> code index		*/
48 	void*		data;	/* map specific data		*/
49 } Ccmap_t;
50 
51 #if _BLD_ast && defined(__EXPORT__)
52 #define extern		__EXPORT__
53 #endif
54 
55 extern unsigned char*	_ccmap(int, int);
56 extern void*		_ccmapcpy(unsigned char*, void*, const void*, size_t);
57 extern void*		_ccmapstr(unsigned char*, void*, size_t);
58 
59 extern int		ccmapid(const char*);
60 extern char*		ccmapname(int);
61 extern void*		ccnative(void*, const void*, size_t);
62 extern Ccmap_t*		ccmaplist(Ccmap_t*);
63 
64 #undef	extern
65 
66 #define CCOP(i,o)		((i)==(o)?0:(((o)<<8)|(i)))
67 #define CCIN(x)			((x)&0xFF)
68 #define CCOUT(x)		(((x)>>8)&0xFF)
69 #define CCCONVERT(x)		((x)&0xFF00)
70 
71 #define CCCVT(x)		CCMAP(x,0)
72 #define CCMAP(i,o)		((i)==(o)?(unsigned char*)0:_ccmap(i,o))
73 #define CCMAPCHR(m,c)		((m)?(m)[c]:(c))
74 #define CCMAPCPY(m,t,f,n)	((m)?_ccmapcpy(m,t,f,n):memcpy(t,f,n))
75 #define CCMAPSTR(m,s,n)		((m)?_ccmapstr(m,s,n):(void*)(s))
76 
77 #define ccmap(i,o)		CCMAP(i,o)
78 #define ccmapchr(m,c)		CCMAPCHR(m,c)
79 #define ccmapcpy(m,t,f,n)	CCMAPCPY(m,t,f,n)
80 #define ccmapstr(m,s,n)		CCMAPSTR(m,s,n)
81 
82 #define CCMAPC(c,i,o)		((i)==(o)?(c):CCMAP(i,o)[c])
83 #define CCMAPM(t,f,n,i,o)	((i)==(o)?memcpy(t,f,n):_ccmapcpy(CCMAP(i,o),t,f,n))
84 #define CCMAPS(s,n,i,o)		((i)==(o)?(void*)(s):_ccmapstr(CCMAP(i,o),s,n))
85 
86 #define ccmapc(c,i,o)		CCMAPC(c,i,o)
87 #define ccmapm(t,f,n,i,o)	CCMAPM(t,f,n,i,o)
88 #define ccmaps(s,n,i,o)		CCMAPS(s,n,i,o)
89 
90 #endif
91