Home | History | Annotate | Download | only in lddat
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright (c) 1999 by Sun Microsystems, Inc.
     23  * All rights reserved.
     24  *
     25  * This program genarates ldterm.dat file that can be placed as
     26  * /usr/lib/locale/<locale>/LC_CTYPE/ldterm.dat file and provide necessary
     27  * line discipline data to ldterm STREAMS module when user invokes
     28  * 'stty -defeucw'. The ldterm.dat file contains a ldterm_cs_data_user_t data
     29  * structure and will take 300 bytes. See section 2.1 of PSARC/1999/140 design
     30  * memo, ldterm-csi.txt, for the descriptions on the data fields of
     31  * the ldterm_cs_data_user_t data structure.
     32  *
     33  * The ldterm.dat file is only for non-EUC locales; you don't need to
     34  * supply the ldterm.dat file if your locale is an EUC locale.
     35  * In case if you want to, you can do so and in that case, the EUC
     36  * supplementary codeset 2 and 3's byte lengths do not include single
     37  * shift 2 (SS2) and 3 (SS3) bytes as like getwidth(3C), euclen(3C),
     38  * cswidth definition at the localedef(1) source file, and so on.
     39  *
     40  * This is a template program that you can alter and generate your own
     41  * locale's ldterm.dat file.
     42  */
     43 
     44 #pragma ident	"@(#)ldterm-data.c	1.1	99/10/21 SMI"
     45 
     46 #include <sys/eucioctl.h>
     47 #include <sys/param.h>
     48 #include <sys/types.h>
     49 #include <sys/termio.h>
     50 #include <sys/stream.h>
     51 #include <sys/conf.h>
     52 #include <sys/stropts.h>
     53 #include <sys/strtty.h>
     54 #include <sys/signal.h>
     55 #include <sys/errno.h>
     56 #include <sys/debug.h>
     57 #include <sys/cmn_err.h>
     58 #include <sys/ptms.h>
     59 #include <sys/ldterm.h>
     60 #include <sys/stat.h>
     61 #include <fcntl.h>
     62 #include <unistd.h>
     63 #include <stdio.h>
     64 
     65 /*
     66  * Here are a few sample codeset data definition. Please see and update
     67  * appropriately for your locale's codeset.
     68  */
     69 #if	defined(PCK)
     70 static const ldterm_cs_data_user_t csdata = {
     71 	LDTERM_DATA_VERSION,
     72 	LDTERM_CS_TYPE_PCCS,
     73 	(uchar_t)4,
     74 	(uchar_t)0,
     75 	{
     76 		'j',  'a',  '_',  'J',  'P',  '.',  'P',  'C',  'K',  '\0',
     77 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     78 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     79 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     80 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     81 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     82 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     83 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     84 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     85 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     86 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     87 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     88 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     89 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     90 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     91 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     92 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     93 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     94 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     95 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     96 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     97 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     98 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
     99 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    100 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    101 		'\0', '\0', '\0', '\0', '\0', '\0'
    102 	},
    103 	{
    104                 '\2', '\2', (uchar_t)'\x81', (uchar_t)'\x9f',
    105                 '\1', '\1', (uchar_t)'\xa1', (uchar_t)'\xdf',
    106                 '\2', '\2', (uchar_t)'\xe0', (uchar_t)'\xef',
    107                 '\2', '\2', (uchar_t)'\xf0', (uchar_t)'\xfc',
    108                 '\0', '\0', '\0', '\0',
    109                 '\0', '\0', '\0', '\0',
    110                 '\0', '\0', '\0', '\0',
    111                 '\0', '\0', '\0', '\0',
    112                 '\0', '\0', '\0', '\0',
    113                 '\0', '\0', '\0', '\0'
    114 	}
    115 };
    116 #elif	defined(BIG5)
    117 static const ldterm_cs_data_user_t csdata = {
    118 	LDTERM_DATA_VERSION,
    119 	LDTERM_CS_TYPE_PCCS,
    120 	(uchar_t)3,
    121 	(uchar_t)0,
    122 	{
    123 		'z',  'h',  '_',  'T',  'W',  '.',  'B',  'I',  'G',  '5',
    124 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    125 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    126 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    127 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    128 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    129 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    130 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    131 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    132 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    133 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    134 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    135 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    136 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    137 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    138 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    139 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    140 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    141 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    142 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    143 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    144 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    145 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    146 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    147 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    148 		'\0', '\0', '\0', '\0', '\0', '\0'
    149 	},
    150 	{
    151                 '\2', '\2', (uchar_t)'\xa1', (uchar_t)'\xa3',
    152                 '\2', '\2', (uchar_t)'\xa4', (uchar_t)'\xc2',
    153                 '\2', '\2', (uchar_t)'\xc9', (uchar_t)'\xf9',
    154                 '\0', '\0', '\0', '\0',
    155                 '\0', '\0', '\0', '\0',
    156                 '\0', '\0', '\0', '\0',
    157                 '\0', '\0', '\0', '\0',
    158                 '\0', '\0', '\0', '\0',
    159                 '\0', '\0', '\0', '\0',
    160                 '\0', '\0', '\0', '\0'
    161 	}
    162 };
    163 #elif	defined(UTF8)
    164 static const ldterm_cs_data_user_t csdata = {
    165 	LDTERM_DATA_VERSION,
    166 	LDTERM_CS_TYPE_UTF8,
    167 	(uchar_t)4,
    168 	(uchar_t)0,
    169 	{
    170 		'e',  'n',  '_',  'U',  'S',  '.',  'U',  'T',  'F',  '-',
    171 		'8',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    172 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    173 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    174 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    175 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    176 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    177 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    178 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    179 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    180 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    181 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    182 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    183 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    184 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    185 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    186 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    187 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    188 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    189 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    190 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    191 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    192 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    193 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    194 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    195 		'\0', '\0', '\0', '\0', '\0', '\0'
    196 	},
    197 	{
    198                 '\0', '\0', '\0', '\0',
    199                 '\0', '\0', '\0', '\0',
    200                 '\0', '\0', '\0', '\0',
    201                 '\0', '\0', '\0', '\0',
    202                 '\0', '\0', '\0', '\0',
    203                 '\0', '\0', '\0', '\0',
    204                 '\0', '\0', '\0', '\0',
    205                 '\0', '\0', '\0', '\0',
    206                 '\0', '\0', '\0', '\0',
    207                 '\0', '\0', '\0', '\0'
    208 	}
    209 };
    210 #elif	defined(EUCKR)
    211 static const ldterm_cs_data_user_t csdata = {
    212 	LDTERM_DATA_VERSION,
    213 	LDTERM_CS_TYPE_EUC,
    214 	(uchar_t)1,
    215 	(uchar_t)0,
    216 	{
    217 		'k',  'o',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    218 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    219 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    220 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    221 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    222 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    223 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    224 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    225 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    226 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    227 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    228 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    229 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    230 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    231 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    232 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    233 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    234 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    235 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    236 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    237 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    238 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    239 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    240 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    241 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    242 		'\0', '\0', '\0', '\0', '\0', '\0'
    243 	},
    244 	{
    245                 '\2', '\2', '\0', '\0',
    246                 '\0', '\0', '\0', '\0',
    247                 '\0', '\0', '\0', '\0',
    248                 '\0', '\0', '\0', '\0',
    249                 '\0', '\0', '\0', '\0',
    250                 '\0', '\0', '\0', '\0',
    251                 '\0', '\0', '\0', '\0',
    252                 '\0', '\0', '\0', '\0',
    253                 '\0', '\0', '\0', '\0',
    254                 '\0', '\0', '\0', '\0'
    255 	}
    256 };
    257 #elif	defined(EUCJP)
    258 static const ldterm_cs_data_user_t csdata = {
    259 	LDTERM_DATA_VERSION,
    260 	LDTERM_CS_TYPE_EUC,
    261 	(uchar_t)3,
    262 	(uchar_t)0,
    263 	{
    264 		'j',  'a',  '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    265 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    266 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    267 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    268 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    269 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    270 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    271 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    272 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    273 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    274 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    275 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    276 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    277 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    278 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    279 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    280 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    281 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    282 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    283 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    284 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    285 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    286 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    287 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    288 		'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
    289 		'\0', '\0', '\0', '\0', '\0', '\0'
    290 	},
    291 	{
    292                 '\2', '\2', '\0', '\0',
    293                 '\1', '\1', '\0', '\0',
    294                 '\2', '\2', '\0', '\0',
    295                 '\0', '\0', '\0', '\0',
    296                 '\0', '\0', '\0', '\0',
    297                 '\0', '\0', '\0', '\0',
    298                 '\0', '\0', '\0', '\0',
    299                 '\0', '\0', '\0', '\0',
    300                 '\0', '\0', '\0', '\0',
    301                 '\0', '\0', '\0', '\0'
    302 	}
    303 };
    304 #else
    305 #error	"Error: no known codeset type macro definition has been given."
    306 #endif
    307 
    308 int
    309 main(int ac, char **av)
    310 {
    311 	int fd;
    312 	ssize_t sz;
    313 
    314 	fd = open("./ldterm.dat", O_CREAT|O_WRONLY|O_TRUNC, 0444);
    315 	if (fd < 0) {
    316 		fprintf(stderr, "%s: unable to create ldterm.dat file err\n",
    317 			av[0]);
    318 		exit(1);
    319 	}
    320 
    321 	sz = write(fd, (void *)&csdata, sizeof (ldterm_cs_data_user_t));
    322 	if (sz < sizeof (ldterm_cs_data_user_t)) {
    323 		fprintf(stderr, "%s: unable to write to ldterm.dat file err\n",
    324 			av[0]);
    325 		exit(1);
    326 	}
    327 
    328 	close(fd);
    329 
    330 	exit(0);
    331 }
    332