2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1996, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Implementation of the mks M_INVARIANT family of mapping macros.
2N/A * Based on the IBM C/370 getsyntx() and variant.h implementation.
2N/A *
2N/A * Copyright 1993 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char const rcsID[] = "$Header: /rd/src/libc/mks/rcs/m_varian.c 1.14 1994/12/08 23:14:58 ross Exp $";
2N/A#endif /* lint */
2N/A#endif /* M_RCSID */
2N/A
2N/A#include <mks.h>
2N/A#include <m_invari.h>
2N/A
2N/A#ifdef M_VARIANTS
2N/A
2N/A#include <variant.h>
2N/A
2N/A#define SHORT_STRING_LEN 100
2N/A
2N/Avoid __m_setinvariant(void);
2N/A
2N/Achar __m_invariant[M_CSETSIZE] = {
2N/A 0, 1, 2, 3, 4, 5, 6, 7,
2N/A 8, 9, 10, 11, 12, 13, 14, 15,
2N/A 16, 17, 18, 19, 20, 21, 22, 23,
2N/A 24, 25, 26, 27, 28, 29, 30, 31,
2N/A 32, 33, 34, 35, 36, 37, 38, 39,
2N/A 40, 41, 42, 43, 44, 45, 46, 47,
2N/A 48, 49, 50, 51, 52, 53, 54, 55,
2N/A 56, 57, 58, 59, 60, 61, 62, 63,
2N/A 64, 65, 66, 67, 68, 69, 70, 71,
2N/A 72, 73, 74, 75, 76, 77, 78, 79,
2N/A 80, 81, 82, 83, 84, 85, 86, 87,
2N/A 88, 89, 90, 91, 92, 93, 94, 95,
2N/A 96, 97, 98, 99, 100, 101, 102, 103,
2N/A 104, 105, 106, 107, 108, 109, 110, 111,
2N/A 112, 113, 114, 115, 116, 117, 118, 119,
2N/A 120, 121, 122, 123, 124, 125, 126, 127,
2N/A 128, 129, 130, 131, 132, 133, 134, 135,
2N/A 136, 137, 138, 139, 140, 141, 142, 143,
2N/A 144, 145, 146, 147, 148, 149, 150, 151,
2N/A 152, 153, 154, 155, 156, 157, 158, 159,
2N/A 160, 161, 162, 163, 164, 165, 166, 167,
2N/A 168, 169, 170, 171, 172, 173, 174, 175,
2N/A 176, 177, 178, 179, 180, 181, 182, 183,
2N/A 184, 185, 186, 187, 188, 189, 190, 191,
2N/A 192, 193, 194, 195, 196, 197, 198, 199,
2N/A 200, 201, 202, 203, 204, 205, 206, 207,
2N/A 208, 209, 210, 211, 212, 213, 214, 215,
2N/A 216, 217, 218, 219, 220, 221, 222, 223,
2N/A 224, 225, 226, 227, 228, 229, 230, 231,
2N/A 232, 233, 234, 235, 236, 237, 238, 239,
2N/A 240, 241, 242, 243, 244, 245, 246, 247,
2N/A 248, 249, 250, 251, 252, 253, 254, 255,
2N/A#if M_CSETSIZE > 256
2N/A 256, 257, 258, 259, 260, 261, 262, 263,
2N/A 264, 265, 266, 267, 268, 269, 270, 271,
2N/A 272, 273, 274, 275, 276, 277, 278, 279,
2N/A 280, 281, 282, 283, 284, 285, 286, 287,
2N/A 288, 289, 290, 291, 292, 293, 294, 295,
2N/A 296, 297, 298, 299, 300, 301, 302, 303,
2N/A 304, 305, 306, 307, 308, 309, 310, 311,
2N/A 312, 313, 314, 315, 316, 317, 318, 319,
2N/A 320, 321, 322, 323, 324, 325, 326, 327,
2N/A 328, 329, 330, 331, 332, 333, 334, 335,
2N/A 336, 337, 338, 339, 340, 341, 342, 343,
2N/A 344, 345, 346, 347, 348, 349, 350, 351,
2N/A 352, 353, 354, 355, 356, 357, 358, 359,
2N/A 360, 361, 362, 363, 364, 365, 366, 367,
2N/A 368, 369, 370, 371, 372, 373, 374, 375,
2N/A 376, 377, 378, 379, 380, 381, 382, 383,
2N/A 384, 385, 386, 387, 388, 389, 390, 391,
2N/A 392, 393, 394, 395, 396, 397, 398, 399,
2N/A 400, 401, 402, 403, 404, 405, 406, 407,
2N/A 408, 409, 410, 411, 412, 413, 414, 415,
2N/A 416, 417, 418, 419, 420, 421, 422, 423,
2N/A 424, 425, 426, 427, 428, 429, 430, 431,
2N/A 432, 433, 434, 435, 436, 437, 438, 439,
2N/A 440, 441, 442, 443, 444, 445, 446, 447,
2N/A 448, 449, 450, 451, 452, 453, 454, 455,
2N/A 456, 457, 458, 459, 460, 461, 462, 463,
2N/A 464, 465, 466, 467, 468, 469, 470, 471,
2N/A 472, 473, 474, 475, 476, 477, 478, 479,
2N/A 480, 481, 482, 483, 484, 485, 486, 487,
2N/A 488, 489, 490, 491, 492, 493, 494, 495,
2N/A 496, 497, 498, 499, 500, 501, 502, 503,
2N/A 504, 505, 506, 507, 508, 509, 510, 511
2N/A#endif
2N/A#if M_CSETSIZE > 512
2N/A#error __m_invariant table needs to be extended
2N/A#endif
2N/A};
2N/Achar __m_unvariant[M_CSETSIZE] = {
2N/A 0, 1, 2, 3, 4, 5, 6, 7,
2N/A 8, 9, 10, 11, 12, 13, 14, 15,
2N/A 16, 17, 18, 19, 20, 21, 22, 23,
2N/A 24, 25, 26, 27, 28, 29, 30, 31,
2N/A 32, 33, 34, 35, 36, 37, 38, 39,
2N/A 40, 41, 42, 43, 44, 45, 46, 47,
2N/A 48, 49, 50, 51, 52, 53, 54, 55,
2N/A 56, 57, 58, 59, 60, 61, 62, 63,
2N/A 64, 65, 66, 67, 68, 69, 70, 71,
2N/A 72, 73, 74, 75, 76, 77, 78, 79,
2N/A 80, 81, 82, 83, 84, 85, 86, 87,
2N/A 88, 89, 90, 91, 92, 93, 94, 95,
2N/A 96, 97, 98, 99, 100, 101, 102, 103,
2N/A 104, 105, 106, 107, 108, 109, 110, 111,
2N/A 112, 113, 114, 115, 116, 117, 118, 119,
2N/A 120, 121, 122, 123, 124, 125, 126, 127,
2N/A 128, 129, 130, 131, 132, 133, 134, 135,
2N/A 136, 137, 138, 139, 140, 141, 142, 143,
2N/A 144, 145, 146, 147, 148, 149, 150, 151,
2N/A 152, 153, 154, 155, 156, 157, 158, 159,
2N/A 160, 161, 162, 163, 164, 165, 166, 167,
2N/A 168, 169, 170, 171, 172, 173, 174, 175,
2N/A 176, 177, 178, 179, 180, 181, 182, 183,
2N/A 184, 185, 186, 187, 188, 189, 190, 191,
2N/A 192, 193, 194, 195, 196, 197, 198, 199,
2N/A 200, 201, 202, 203, 204, 205, 206, 207,
2N/A 208, 209, 210, 211, 212, 213, 214, 215,
2N/A 216, 217, 218, 219, 220, 221, 222, 223,
2N/A 224, 225, 226, 227, 228, 229, 230, 231,
2N/A 232, 233, 234, 235, 236, 237, 238, 239,
2N/A 240, 241, 242, 243, 244, 245, 246, 247,
2N/A 248, 249, 250, 251, 252, 253, 254, 255,
2N/A#if M_CSETSIZE > 256
2N/A 256, 257, 258, 259, 260, 261, 262, 263,
2N/A 264, 265, 266, 267, 268, 269, 270, 271,
2N/A 272, 273, 274, 275, 276, 277, 278, 279,
2N/A 280, 281, 282, 283, 284, 285, 286, 287,
2N/A 288, 289, 290, 291, 292, 293, 294, 295,
2N/A 296, 297, 298, 299, 300, 301, 302, 303,
2N/A 304, 305, 306, 307, 308, 309, 310, 311,
2N/A 312, 313, 314, 315, 316, 317, 318, 319,
2N/A 320, 321, 322, 323, 324, 325, 326, 327,
2N/A 328, 329, 330, 331, 332, 333, 334, 335,
2N/A 336, 337, 338, 339, 340, 341, 342, 343,
2N/A 344, 345, 346, 347, 348, 349, 350, 351,
2N/A 352, 353, 354, 355, 356, 357, 358, 359,
2N/A 360, 361, 362, 363, 364, 365, 366, 367,
2N/A 368, 369, 370, 371, 372, 373, 374, 375,
2N/A 376, 377, 378, 379, 380, 381, 382, 383,
2N/A 384, 385, 386, 387, 388, 389, 390, 391,
2N/A 392, 393, 394, 395, 396, 397, 398, 399,
2N/A 400, 401, 402, 403, 404, 405, 406, 407,
2N/A 408, 409, 410, 411, 412, 413, 414, 415,
2N/A 416, 417, 418, 419, 420, 421, 422, 423,
2N/A 424, 425, 426, 427, 428, 429, 430, 431,
2N/A 432, 433, 434, 435, 436, 437, 438, 439,
2N/A 440, 441, 442, 443, 444, 445, 446, 447,
2N/A 448, 449, 450, 451, 452, 453, 454, 455,
2N/A 456, 457, 458, 459, 460, 461, 462, 463,
2N/A 464, 465, 466, 467, 468, 469, 470, 471,
2N/A 472, 473, 474, 475, 476, 477, 478, 479,
2N/A 480, 481, 482, 483, 484, 485, 486, 487,
2N/A 488, 489, 490, 491, 492, 493, 494, 495,
2N/A 496, 497, 498, 499, 500, 501, 502, 503,
2N/A 504, 505, 506, 507, 508, 509, 510, 511
2N/A#endif
2N/A#if M_CSETSIZE > 512
2N/A#error __m_unvariant table needs to be extended
2N/A#endif
2N/A};
2N/A
2N/A/*f
2N/A * Initialize the variant <--> invariant tables.
2N/A * May be called more than once -- successive calls ignored.
2N/A * Void return -- can't fail.
2N/A */
2N/Avoid
2N/Am_invariantinit(void)
2N/A{
2N/A static int first = 1;
2N/A
2N/A if (!first)
2N/A return;
2N/A first = 0;
2N/A __m_setinvariant();
2N/A return;
2N/A}
2N/A
2N/A/*f
2N/A * Initialize the variant -> invariant tables.
2N/A * Void return -- can't fail.
2N/A */
2N/Avoid
2N/A__m_setinvariant(void)
2N/A{
2N/A int i;
2N/A struct variant *v;
2N/A
2N/A /* Initialize to identity mappings */
2N/A for (i = 0; i < M_CSETSIZE; i++) {
2N/A __m_invariant[i] = i;
2N/A __m_unvariant[i] = i;
2N/A }
2N/A
2N/A /*
2N/A * Find the set of variant characters
2N/A * On error, return success -- i.e. assume it wasn't specified, and
2N/A * hence it is the identity.
2N/A */
2N/A if ((v = getsyntx()) == NULL)
2N/A return;
2N/A
2N/A /*
2N/A * Build the invariant mapping tables: map from current codeset's
2N/A * variant locations, to the location that we were compiled in.
2N/A */
2N/A __m_invariant[v->backslash] = '\\';
2N/A __m_invariant[v->right_bracket] = ']';
2N/A __m_invariant[v->left_bracket] = '[';
2N/A __m_invariant[v->right_brace] = '}';
2N/A __m_invariant[v->left_brace] = '{';
2N/A __m_invariant[v->circumflex] = '^';
2N/A __m_invariant[v->tilde] = '~';
2N/A __m_invariant[v->exclamation_mark] = '!';
2N/A __m_invariant[v->number_sign] = '#';
2N/A __m_invariant[v->vertical_line] = '|';
2N/A __m_invariant[v->dollar_sign] = '$';
2N/A __m_invariant[v->commercial_at] = '@';
2N/A __m_invariant[v->grave_accent] = '`';
2N/A
2N/A /*
2N/A * Build the unvariant mapping tables: map from compiled codeset
2N/A * to that of the current codeset.
2N/A */
2N/A __m_unvariant['\\'] = v->backslash;
2N/A __m_unvariant[']'] = v->right_bracket;
2N/A __m_unvariant['['] = v->left_bracket;
2N/A __m_unvariant['}'] = v->right_brace;
2N/A __m_unvariant['{'] = v->left_brace;
2N/A __m_unvariant['^'] = v->circumflex;
2N/A __m_unvariant['~'] = v->tilde;
2N/A __m_unvariant['!'] = v->exclamation_mark;
2N/A __m_unvariant['#'] = v->number_sign;
2N/A __m_unvariant['|'] = v->vertical_line;
2N/A __m_unvariant['$'] = v->dollar_sign;
2N/A __m_unvariant['@'] = v->commercial_at;
2N/A __m_unvariant['`'] = v->grave_accent;
2N/A
2N/A return;
2N/A}
2N/A
2N/A/*f
2N/A * Convert a compiled in string to the external form. Assumes a fixed
2N/A * length short string which is available until another call to m_unvariantstr.
2N/A * Uses 10 alternating strings to allow multiple calls on a printf.
2N/A * The extra buffers are probably only required by yacc.
2N/A */
2N/Achar *
2N/Am_unvariantstr(char const *s)
2N/A{
2N/A static char str[10][SHORT_STRING_LEN];
2N/A static int buf = 0;
2N/A char *ret;
2N/A char c;
2N/A int i = 0;
2N/A
2N/A ret = str[buf++];
2N/A if (buf >= 10)
2N/A buf = 0;
2N/A
2N/A while((ret[i++] = M_UNVARIANT(*s)) != '\0') {
2N/A s++;
2N/A if (i >= SHORT_STRING_LEN) {
2N/A fprintf(stderr, "m_unvariantstr: internal error.\n"),
2N/A abort();
2N/A }
2N/A }
2N/A ret[i] = '\0';
2N/A return ret;
2N/A}
2N/A
2N/A/*f
2N/A * Ditto, for wchar's
2N/A */
2N/Awchar_t *
2N/Am_wunvariantstr(wchar_t const *s)
2N/A{
2N/A static wchar_t str[SHORT_STRING_LEN];
2N/A static wchar_t * const strend = str + sizeof(str);
2N/A wchar_t *s1;
2N/A int i = 0;
2N/A
2N/A for (s1 = str ; *s != '\0'; s++) {
2N/A *s1++ = M_UNVARIANT(*s);
2N/A if (str == strend) {
2N/A fprintf(stderr, "m_wunvariantstr: internal error.\n"),
2N/A abort();
2N/A }
2N/A }
2N/A *s1 = '\0';
2N/A
2N/A return str;
2N/A}
2N/A#endif /* M_VARIANTS */