Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/locale/mskanji.c
          +++ new/usr/src/lib/libc/port/locale/mskanji.c
   1    1  /*
        2 + * Copyright 2013 Garrett D'Amore <garrett@damore.org>
   2    3   * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
   3    4   * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
   4    5   *
   5    6   *    ja_JP.SJIS locale table for BSD4.4/rune
   6    7   *    version 1.0
   7    8   *    (C) Sin'ichiro MIYATANI / Phase One, Inc
   8    9   *    May 12, 1995
   9   10   *
  10   11   * Redistribution and use in source and binary forms, with or without
  11   12   * modification, are permitted provided that the following conditions
↓ open down ↓ 18 lines elided ↑ open up ↑
  30   31   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31   32   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32   33   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33   34   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34   35   * SUCH DAMAGE.
  35   36   */
  36   37  
  37   38  #include "lint.h"
  38   39  #include <sys/types.h>
  39   40  #include <errno.h>
  40      -#include "runetype.h"
  41   41  #include <stdlib.h>
  42   42  #include <string.h>
  43   43  #include <wchar.h>
  44   44  #include "mblocal.h"
       45 +#include "lctype.h"
  45   46  
  46   47  static size_t   _MSKanji_mbrtowc(wchar_t *_RESTRICT_KYWD,
  47   48                      const char *_RESTRICT_KYWD,
  48   49                      size_t, mbstate_t *_RESTRICT_KYWD);
  49   50  static int      _MSKanji_mbsinit(const mbstate_t *);
  50   51  static size_t   _MSKanji_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
  51   52                      mbstate_t *_RESTRICT_KYWD);
       53 +static size_t   _MSKanji_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
       54 +                    const char **_RESTRICT_KYWD, size_t, size_t,
       55 +                    mbstate_t *_RESTRICT_KYWD);
       56 +static size_t   _MSKanji_wcsnrtombs(char *_RESTRICT_KYWD,
       57 +                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
       58 +                    mbstate_t *_RESTRICT_KYWD);
  52   59  
  53   60  typedef struct {
  54   61          wchar_t ch;
  55   62  } _MSKanjiState;
  56   63  
  57      -int
  58      -_MSKanji_init(_RuneLocale *rl)
       64 +void
       65 +_MSKanji_init(struct lc_ctype *lct)
  59   66  {
  60   67  
  61      -        __mbrtowc = _MSKanji_mbrtowc;
  62      -        __wcrtomb = _MSKanji_wcrtomb;
  63      -        __mbsinit = _MSKanji_mbsinit;
  64      -        _CurrentRuneLocale = rl;
  65      -        __ctype[520] = 2;
  66      -        charset_is_ascii = 0;
  67      -        return (0);
       68 +        lct->lc_mbrtowc = _MSKanji_mbrtowc;
       69 +        lct->lc_wcrtomb = _MSKanji_wcrtomb;
       70 +        lct->lc_mbsnrtowcs = _MSKanji_mbsnrtowcs;
       71 +        lct->lc_wcsnrtombs = _MSKanji_wcsnrtombs;
       72 +        lct->lc_mbsinit = _MSKanji_mbsinit;
       73 +        lct->lc_max_mblen = 2;
       74 +        lct->lc_is_ascii = 0;
  68   75  }
  69   76  
  70   77  static int
  71   78  _MSKanji_mbsinit(const mbstate_t *ps)
  72   79  {
  73   80  
  74   81          return (ps == NULL || ((const _MSKanjiState *)ps)->ch == 0);
  75   82  }
  76   83  
  77   84  static size_t
↓ open down ↓ 68 lines elided ↑ open up ↑
 146  153                  return ((size_t)-1);
 147  154          }
 148  155  
 149  156          if (s == NULL)
 150  157                  /* Reset to initial shift state (no-op) */
 151  158                  return (1);
 152  159          len = (wc > 0x100) ? 2 : 1;
 153  160          for (i = len; i-- > 0; )
 154  161                  *s++ = wc >> (i << 3);
 155  162          return (len);
      163 +}
      164 +
      165 +static size_t
      166 +_MSKanji_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
      167 +    const char **_RESTRICT_KYWD src, size_t nms,
      168 +    size_t len, mbstate_t *_RESTRICT_KYWD ps)
      169 +{
      170 +        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _MSKanji_mbrtowc));
      171 +}
      172 +
      173 +static size_t
      174 +_MSKanji_wcsnrtombs(char *_RESTRICT_KYWD dst,
      175 +    const wchar_t **_RESTRICT_KYWD src, size_t nwc,
      176 +    size_t len, mbstate_t *_RESTRICT_KYWD ps)
      177 +{
      178 +        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _MSKanji_wcrtomb));
 156  179  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX