OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [i18n/] [v2_0/] [src/] [wctomb_jp.cxx] - Blame information for rev 249

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//===========================================================================
2
//
3
//      wctomb_jp.cxx
4
//
5
//      Internal __wctombc_jp() routine 
6
//
7
//===========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//===========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     jjohnstn
44
// Contributors:  jjohnstn
45
// Date:          2000-11-16
46
// Purpose:       Provide internal use __wctomb_jp() routine
47
// Description:   Japanese locale version of wctomb()
48
// Usage:       
49
//
50
//####DESCRIPTIONEND####
51
//
52
//===========================================================================
53
//
54
// This code was taken from newlib/libc/stdlib/wctomb_r.c
55
//
56
 
57
// CONFIGURATION
58
 
59
#include <pkgconf/libc_i18n.h>     // Configuration header
60
 
61
// INCLUDES
62
 
63
#include <cyg/infra/cyg_type.h>    // Common type definitions
64
#include <cyg/infra/cyg_trac.h>    // Tracing support
65
#include <cyg/infra/cyg_ass.h>     // Assertion support
66
#include <locale.h>
67
#include <stdlib.h>                // Header for this file
68
#include <string.h>                // strcmp definition
69
#include <stddef.h>                // size_t definition
70
#include "internal.h"              // internal _isxxxx macros
71
 
72
#ifdef CYGSEM_LIBC_STDLIB_PER_THREAD_WCTOMB
73
# include <pkgconf/kernel.h>       // kernel configuration
74
# include <cyg/kernel/thread.hxx>  // per-thread data
75
# include <cyg/kernel/thread.inl>  // per-thread data
76
# include <cyg/kernel/mutex.hxx>   // mutexes
77
#endif
78
 
79
// TRACE
80
 
81
#if defined(CYGDBG_USE_TRACING) && defined(CYGNUM_LIBC_STDLIB_WCTOMB_TRACE_LEVEL)
82
static int wctomb_trace = CYGNUM_LIBC_STDLIB_WCTOMB_TRACE_LEVEL;
83
# define TL1 (0 < wctomb_trace)
84
#else
85
# define TL1 (0)
86
#endif
87
 
88
// FUNCTIONS
89
 
90
int
91
__wctomb_jp ( char *s, wchar_t wchar, int *state )
92
{
93
  const char *cur_locale = __current_ctype_locale->name;
94
  int         retval;
95
 
96
  CYG_REPORT_FUNCNAMETYPE( "__wctomb_jp", "returning %d" );
97
  CYG_REPORT_FUNCARG3( "s=%08x, wchar=%08x, state=%08x", s, wchar, state );
98
 
99
  if (s != NULL)
100
    CYG_CHECK_DATA_PTR( s, "s is not a valid pointer!" );
101
  CYG_CHECK_DATA_PTR( state, "state is not a valid pointer!" );
102
 
103
  if (strlen (cur_locale) <= 1)
104
    { /* fall-through */ }
105
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_SJIS
106
  else if (!strcmp (cur_locale, "C-SJIS"))
107
    {
108
      unsigned char char2 = (unsigned char)wchar;
109
      unsigned char char1 = (unsigned char)(wchar >> 8);
110
 
111
      if (s == NULL)
112
        {
113
          retval =  0;  /* not state-dependent */
114
          CYG_REPORT_RETVAL( retval );
115
          return retval;
116
        }
117
 
118
      if (char1 != 0x00)
119
        {
120
        /* first byte is non-zero..validate multi-byte char */
121
          if (_issjis1(char1) && _issjis2(char2))
122
            {
123
              *s++ = (char)char1;
124
              *s = (char)char2;
125
              retval = 2;
126
            }
127
          else
128
            retval = -1;
129
 
130
          CYG_REPORT_RETVAL( retval );
131
          return retval;
132
        }
133
    }
134
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_SJIS */
135
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_EUCJP
136
  else if (!strcmp (cur_locale, "C-EUCJP"))
137
    {
138
      unsigned char char2 = (unsigned char)wchar;
139
      unsigned char char1 = (unsigned char)(wchar >> 8);
140
 
141
      if (s == NULL)
142
        {
143
          retval =  0;  /* not state-dependent */
144
          CYG_REPORT_RETVAL( retval );
145
          return retval;
146
        }
147
 
148
      if (char1 != 0x00)
149
        {
150
        /* first byte is non-zero..validate multi-byte char */
151
          if (_iseucjp (char1) && _iseucjp (char2))
152
            {
153
              *s++ = (char)char1;
154
              *s = (char)char2;
155
              retval = 2;
156
            }
157
          else
158
            retval = -1;
159
 
160
          CYG_REPORT_RETVAL( retval );
161
          return retval;
162
        }
163
    }
164
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_EUCJP */
165
#ifdef CYGFUN_LIBC_I18N_LOCALE_C_JIS
166
  else if (!strcmp (cur_locale, "C-JIS"))
167
    {
168
      int cnt = 0;
169
      unsigned char char2 = (unsigned char)wchar;
170
      unsigned char char1 = (unsigned char)(wchar >> 8);
171
 
172
      if (s == NULL)
173
        {
174
          retval = 1;  /* state-dependent */
175
          CYG_REPORT_RETVAL( retval );
176
          return retval;
177
        }
178
 
179
      if (char1 != 0x00)
180
        {
181
        /* first byte is non-zero..validate multi-byte char */
182
          if (_isjis (char1) && _isjis (char2))
183
            {
184
              if (*state == 0)
185
                {
186
                  /* must switch from ASCII to JIS state */
187
                  *state = 1;
188
                  *s++ = ESC_CHAR;
189
                  *s++ = '$';
190
                  *s++ = 'B';
191
                  cnt = 3;
192
                }
193
              *s++ = (char)char1;
194
              *s = (char)char2;
195
              retval = cnt + 2;
196
            }
197
          else
198
            retval = -1;
199
        }
200
      else
201
        {
202
          if (*state != 0)
203
            {
204
              /* must switch from JIS to ASCII state */
205
              *state = 0;
206
              *s++ = ESC_CHAR;
207
              *s++ = '(';
208
              *s++ = 'B';
209
              cnt = 3;
210
            }
211
          *s = (char)char2;
212
          retval = cnt + 1;
213
        }
214
 
215
      CYG_REPORT_RETVAL( retval );
216
      return retval;
217
    }
218
#endif /* CYGFUN_LIBC_I18N_LOCALE_C_JIS */
219
 
220
  if (s == NULL)
221
    retval = 0;
222
  else
223
    {
224
      *s = (char) wchar;
225
      retval = 1;
226
    }
227
 
228
  CYG_REPORT_RETVAL( retval );
229
  return retval;
230
 
231
} // __wctomb_jp()
232
 
233
// EOF wctomb_jp.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.