1 /*
2  * Copyright (c) 2008-2015, 2019 Paul Mattes.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the names of Paul Mattes nor the names of his contributors
13  *       may be used to endorse or promote products derived from this software
14  *       without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  *	display_charsets.c
30  *		Display character set lookup.
31  */
32 #include "globals.h"
33 
34 #include "display_charsets.h"
35 
36 typedef struct {
37     const char *name;
38     const char *display_charset;
39 } dcs_t;
40 
41 static dcs_t dcs[] = {
42     { "cp037", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
43     { "cp273", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
44     { "cp275", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
45     { "cp277", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
46     { "cp278", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
47     { "cp280", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
48     { "cp284", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
49     { "cp285", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
50     { "cp297", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
51     { "cp424", "3270cg-8,iso10646-1,iso8859-8" },
52     { "cp500", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
53     { "cp803", "3270cg-8,iso10646-1,iso-8859-8" },
54     { "cp870", "iso10646-1,iso8859-2" },
55     { "cp871", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
56     { "cp875", "3270cg-7,iso10646-1,iso8859-7" },
57     { "cp880", "iso10646-1,koi8-r" },
58     { "cp930", "iso10646-1,jisx0201.1976-0" },
59     { "cp935", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
60     { "cp937", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
61     { "cp939", "iso10646-1,jisx0201.1976-0" },
62     { "cp1026", "iso10646-1,iso8859-9" },
63     { "cp1047", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
64     { "cp1140", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
65     { "cp1141", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
66     { "cp1142", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
67     { "cp1143", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
68     { "cp1144", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
69     { "cp1145", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
70     { "cp1146", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
71     { "cp1147", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
72     { "cp1148", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
73     { "cp1149", "3270cg-1a,3270cg-1,iso10646-1,iso8859-15" },
74     { "cp1160", "iso10646-1,iso8859-11" },
75     { "cp1388", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
76     { "apl", "3270cg-1a,iso10646-1" },
77     { "bracket", "3270cg-1a,3270cg-1,iso10646-1,iso8859-1" },
78     { NULL, NULL }
79 };
80 
81 /**
82  * Return the X11 SBCS display character sets for a given host character set
83  * (code page).
84  *
85  * Does not support aliases. If the user-supplied name is an alias, then the
86  * canonical name must be used instead.
87  *
88  * @param[in] charset_name	Canonical chararcter set name
89  *
90  * @return Comma-separated list of display character sets, or NULL if no match
91  * is found.
92  */
93 const char *
lookup_display_charset(const char * charset_name)94 lookup_display_charset(const char *charset_name)
95 {
96     int i;
97 
98     for (i = 0; dcs[i].name != NULL; i++) {
99 	if (!strcasecmp(charset_name, dcs[i].name)) {
100 	    return dcs[i].display_charset;
101 	}
102     }
103     return NULL;
104 }
105