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 usr/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 usr/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 2003 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * @(#)i18n.cc 1.3 06/12/12
  27  */
  28 
  29 #pragma ident   "@(#)i18n.cc    1.3     06/12/12"
  30 
  31 /*
  32  *      i18n.cc
  33  *
  34  *      Deal with internationalization conversions
  35  */
  36 
  37 /*
  38  * Included files
  39  */
  40 #include <mksh/i18n.h>
  41 #include <mksh/misc.h>            /* setup_char_semantics() */
  42 #if defined (linux)
  43 #       include <wctype.h>
  44 #       include <wchar.h>
  45 #       define wschr(x,y) wcschr(x,y)
  46 #endif
  47 
  48 /*
  49  *      get_char_semantics_value(ch)
  50  *
  51  *      Return value:
  52  *              The character semantics of ch.
  53  *
  54  *      Parameters:
  55  *              ch              character we want semantics for.
  56  *
  57  */
  58 char
  59 get_char_semantics_value(wchar_t ch)
  60 {
  61         static Boolean  char_semantics_setup;
  62 
  63         if (!char_semantics_setup) {
  64                 setup_char_semantics();
  65                 char_semantics_setup = true;
  66         }
  67         return char_semantics[get_char_semantics_entry(ch)];
  68 }
  69 
  70 /*
  71  *      get_char_semantics_entry(ch)
  72  *
  73  *      Return value:
  74  *              The slot number in the array for special make chars,
  75  *              else the slot number of the last array entry.
  76  *
  77  *      Parameters:
  78  *              ch              The wide character
  79  *
  80  *      Global variables used:
  81  *              char_semantics_char[]   array of special wchar_t chars
  82  *                                      "&*@`\\|[]:$=!>-\n#()%?;^<'\""
  83  */
  84 int
  85 get_char_semantics_entry(wchar_t ch)
  86 {
  87         wchar_t         *char_sem_char;
  88 
  89         char_sem_char = (wchar_t *) wschr(char_semantics_char, ch);
  90         if (char_sem_char == NULL) {
  91                 /*
  92                  * Return the integer entry for the last slot,
  93                  * whose content is empty.
  94                  */
  95                 return (CHAR_SEMANTICS_ENTRIES - 1);
  96         } else {
  97                 return (char_sem_char - char_semantics_char);
  98         }
  99 }
 100