summaryrefslogtreecommitdiff
path: root/usr/src/lib/libast/common/string/ccmapid.c
blob: fc1e7a071cb00f6f74c60168178165abb9735ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/***********************************************************************
*                                                                      *
*               This software is part of the ast package               *
*          Copyright (c) 1985-2009 AT&T Intellectual Property          *
*                      and is licensed under the                       *
*                  Common Public License, Version 1.0                  *
*                    by AT&T Intellectual Property                     *
*                                                                      *
*                A copy of the License is available at                 *
*            http://www.opensource.org/licenses/cpl1.0.txt             *
*         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
*                                                                      *
*              Information and Software Systems Research               *
*                            AT&T Research                             *
*                           Florham Park NJ                            *
*                                                                      *
*                 Glenn Fowler <gsf@research.att.com>                  *
*                  David Korn <dgk@research.att.com>                   *
*                   Phong Vo <kpv@research.att.com>                    *
*                                                                      *
***********************************************************************/
#pragma prototyped

/*
 * Glenn Fowler
 * AT&T Research
 *
 * 8 bit character code map name/id lookup support
 */

#include <ast.h>
#include <ccode.h>
#include <ctype.h>

static const Ccmap_t	maps[] =
{
	{
	"ascii",
	"a|ascii|?(iso)?(-)646|?(iso)?(-)8859|latin",
	"8 bit ascii",
	"ISO-8859-%s",
	"1",
	CC_ASCII,
	},

	{
	"ebcdic",
	"e|ebcdic?(-)?([1e])",
	"X/Open ebcdic",
	"EBCDIC",
	0,
	CC_EBCDIC_E,
	},

	{
	"ebcdic-o",
	"o|ebcdic?(-)[3o]|?(cp|ibm)1047|open?(-)edition",
	"mvs OpenEdition ebcdic",
	"EBCDIC-O",
	0,
	CC_EBCDIC_O,
	},

	{
	"ebcdic-h",
	"h|ebcdic?(-)h|?(cp|ibm)?(00)37|[oa]s?(/-)400",
	"ibm OS/400 AS/400 ebcdic",
	"EBCDIC-H",
	0,
	CC_EBCDIC_H,
	},

	{
	"ebcdic-s",
	"s|ebcdic?(-)s|siemens|posix-bc",
	"siemens posix-bc ebcdic",
	"EBCDIC-S",
	0,
	CC_EBCDIC_S,
	},

	{
	"ebcdic-i",
	"i|ebcdic?(-)[2i]|ibm",
	"X/Open ibm ebcdic (not idempotent)",
	"EBCDIC-I",
	0,
	CC_EBCDIC_I,
	},

	{
	"ebcdic-m",
	"m|ebcdic?(-)m|mvs",
	"mvs ebcdic",
	"EBCDIC-M",
	0,
	CC_EBCDIC_M,
	},

	{
	"ebcdic-u",
	"u|ebcdic?(-)(u|mf)|microfocus",
	"microfocus cobol ebcdic",
	"EBCDIC-U",
	0,
	CC_EBCDIC_U,
	},

	{
	"native",
	"n|native|local",
	"native code set",
	0,
	0,
	CC_NATIVE,
	},

	{ 0 },
};

/*
 * ccode map list iterator
 */

Ccmap_t*
ccmaplist(Ccmap_t* mp)
{
	return !mp ? (Ccmap_t*)maps : (++mp)->name ? mp : (Ccmap_t*)0;
}

/*
 * return ccode map id given name
 */

int
ccmapid(const char* name)
{
	register const Ccmap_t*	mp;
	register int		c;
	const Ccmap_t*		bp;
	int			n;
	int			sub[2];

	bp = 0;
	n = 0;
	for (mp = maps; mp->name; mp++)
		if (strgrpmatch(name, mp->match, sub, elementsof(sub) / 2, STR_MAXIMAL|STR_LEFT|STR_ICASE))
		{
			if (!(c = name[sub[1]]))
				return mp->ccode;
			if (sub[1] > n && !isalpha(c))
			{
				n = sub[1];
				bp = mp;
			}
		}
	return bp ? bp->ccode : -1;
}

/*
 * return ccode map name given id
 */

char*
ccmapname(register int id)
{
	register const Ccmap_t*	mp;

	for (mp = maps; mp->name; mp++)
		if (id == mp->ccode)
			return (char*)mp->name;
	return 0;
}