OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [ctype/] [iswprint.c] - Blame information for rev 194

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

Line No. Rev Author Line
1 148 jeremybenn
/* Copyright (c) 2002 Red Hat Incorporated.
2
   All rights reserved.
3
 
4
   Redistribution and use in source and binary forms, with or without
5
   modification, are permitted provided that the following conditions are met:
6
 
7
     Redistributions of source code must retain the above copyright
8
     notice, this list of conditions and the following disclaimer.
9
 
10
     Redistributions in binary form must reproduce the above copyright
11
     notice, this list of conditions and the following disclaimer in the
12
     documentation and/or other materials provided with the distribution.
13
 
14
     The name of Red Hat Incorporated may not be used to endorse
15
     or promote products derived from this software without specific
16
     prior written permission.
17
 
18
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
   ARE DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
22
   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
*/
29
 
30
/*
31
FUNCTION
32
        <<iswprint>>---printable wide character test
33
 
34
INDEX
35
        iswprint
36
 
37
ANSI_SYNOPSIS
38
        #include <wctype.h>
39
        int iswprint(wint_t <[c]>);
40
 
41
TRAD_SYNOPSIS
42
        #include <wctype.h>
43
        int iswprint(<[c]>)
44
        wint_t <[c]>;
45
 
46
DESCRIPTION
47
<<iswprint>> is a function which classifies wide-character values that
48
are printable.
49
 
50
RETURNS
51
<<iswprint>> returns non-zero if <[c]> is a printable wide character.
52
 
53
PORTABILITY
54
<<iswprint>> is C99.
55
 
56
No supporting OS subroutines are required.
57
*/
58
#include <_ansi.h>
59
#include <newlib.h>
60
#include <wctype.h>
61
#include <string.h>
62
#include <ctype.h>
63
#include "local.h"
64
 
65
#ifdef _MB_CAPABLE
66
#include "utf8print.h"
67
#endif /* _MB_CAPABLE */
68
 
69
int
70
_DEFUN(iswprint,(c), wint_t c)
71
{
72
  int unicode = 0;
73
  if (__lc_ctype[0] == 'C' && __lc_ctype[1] == '\0')
74
    {
75
      unicode = 0;
76
      /* fall-through */
77
    }
78
#ifdef _MB_CAPABLE
79
  else if (!strcmp (__lc_ctype, "C-JIS"))
80
    {
81
      c = __jp2uc (c, JP_JIS);
82
      unicode = 1;
83
    }
84
  else if (!strcmp (__lc_ctype, "C-SJIS"))
85
    {
86
      c = __jp2uc (c, JP_SJIS);
87
      unicode = 1;
88
    }
89
  else if (!strcmp (__lc_ctype, "C-EUCJP"))
90
    {
91
      c = __jp2uc (c, JP_EUCJP);
92
      unicode = 1;
93
    }
94
  else if (!strcmp (__lc_ctype, "C-UTF-8"))
95
    {
96
      unicode = 1;
97
    }
98
 
99
  if (unicode)
100
    {
101
      unsigned const char *table;
102
      unsigned char *ptr;
103
      unsigned char ctmp;
104
      int size;
105
      wint_t x = (c >> 8);
106
 
107
      /* for some large sections, all characters are printuation so handle them here */
108
      if ((x >= 0x34 && x <= 0x4c) ||
109
          (x >= 0x4e && x <= 0x9e) ||
110
          (x >= 0xac && x <= 0xd6) ||
111
          (x >= 0xe0 && x <= 0xf9) ||
112
          (x >= 0x200 && x <= 0x2a5) ||
113
          (x >= 0xf00 && x <= 0xffe) ||
114
          (x >= 0x1000 && x <= 0x10fe))
115
        return 1;
116
 
117
      switch (x)
118
        {
119
        case 0x01:
120
        case 0x15:
121
        case 0x22:
122
        case 0x25:
123
        case 0x28:
124
        case 0x29:
125
        case 0x2a:
126
        case 0xa0:
127
        case 0xa1:
128
        case 0xa2:
129
        case 0xa3:
130
        case 0xfc:
131
        case 0x2f8:
132
        case 0x2f9:
133
          return 1;
134
        case 0x00:
135
          table = u0;
136
          size = sizeof(u0);
137
          break;
138
        case 0x02:
139
          table = u2;
140
          size = sizeof(u2);
141
          break;
142
        case 0x03:
143
          table = u3;
144
          size = sizeof(u3);
145
          break;
146
        case 0x04:
147
          table = u4;
148
          size = sizeof(u4);
149
          break;
150
        case 0x05:
151
          table = u5;
152
          size = sizeof(u5);
153
          break;
154
        case 0x06:
155
          table = u6;
156
          size = sizeof(u6);
157
          break;
158
        case 0x07:
159
          table = u7;
160
          size = sizeof(u7);
161
          break;
162
        case 0x09:
163
          table = u9;
164
          size = sizeof(u9);
165
          break;
166
        case 0x0a:
167
          table = ua;
168
          size = sizeof(ua);
169
          break;
170
        case 0x0b:
171
          table = ub;
172
          size = sizeof(ub);
173
          break;
174
        case 0x0c:
175
          table = uc;
176
          size = sizeof(uc);
177
          break;
178
        case 0x0d:
179
          table = ud;
180
          size = sizeof(ud);
181
          break;
182
        case 0x0e:
183
          table = ue;
184
          size = sizeof(ue);
185
          break;
186
        case 0x0f:
187
          table = uf;
188
          size = sizeof(uf);
189
          break;
190
        case 0x10:
191
          table = u10;
192
          size = sizeof(u10);
193
          break;
194
        case 0x11:
195
          table = u11;
196
          size = sizeof(u11);
197
          break;
198
        case 0x12:
199
          table = u12;
200
          size = sizeof(u12);
201
          break;
202
        case 0x13:
203
          table = u13;
204
          size = sizeof(u13);
205
          break;
206
        case 0x14:
207
          table = u14;
208
          size = sizeof(u14);
209
          break;
210
        case 0x16:
211
          table = u16;
212
          size = sizeof(u16);
213
          break;
214
        case 0x17:
215
          table = u17;
216
          size = sizeof(u17);
217
          break;
218
        case 0x18:
219
          table = u18;
220
          size = sizeof(u18);
221
          break;
222
        case 0x1e:
223
          table = u1e;
224
          size = sizeof(u1e);
225
          break;
226
        case 0x1f:
227
          table = u1f;
228
          size = sizeof(u1f);
229
          break;
230
        case 0x20:
231
          table = u20;
232
          size = sizeof(u20);
233
          break;
234
        case 0x21:
235
          table = u21;
236
          size = sizeof(u21);
237
          break;
238
        case 0x23:
239
          table = u23;
240
          size = sizeof(u23);
241
          break;
242
        case 0x24:
243
          table = u24;
244
          size = sizeof(u24);
245
          break;
246
        case 0x26:
247
          table = u26;
248
          size = sizeof(u26);
249
          break;
250
        case 0x27:
251
          table = u27;
252
          size = sizeof(u27);
253
          break;
254
        case 0x2e:
255
          table = u2e;
256
          size = sizeof(u2e);
257
          break;
258
        case 0x2f:
259
          table = u2f;
260
          size = sizeof(u2f);
261
          break;
262
        case 0x30:
263
          table = u30;
264
          size = sizeof(u30);
265
          break;
266
        case 0x31:
267
          table = u31;
268
          size = sizeof(u31);
269
          break;
270
        case 0x32:
271
          table = u32;
272
          size = sizeof(u32);
273
          break;
274
        case 0x33:
275
          table = u33;
276
          size = sizeof(u33);
277
          break;
278
        case 0x4d:
279
          table = u4d;
280
          size = sizeof(u4d);
281
          break;
282
        case 0x9f:
283
          table = u9f;
284
          size = sizeof(u9f);
285
          break;
286
        case 0xa4:
287
          table = ua4;
288
          size = sizeof(ua4);
289
          break;
290
        case 0xd7:
291
          table = ud7;
292
          size = sizeof(ud7);
293
          break;
294
        case 0xfa:
295
          table = ufa;
296
          size = sizeof(ufa);
297
          break;
298
        case 0xfb:
299
          table = ufb;
300
          size = sizeof(ufb);
301
          break;
302
        case 0xfd:
303
          table = ufd;
304
          size = sizeof(ufd);
305
          break;
306
        case 0xfe:
307
          table = ufe;
308
          size = sizeof(ufe);
309
          break;
310
        case 0xff:
311
          table = uff;
312
          size = sizeof(uff);
313
          break;
314
        case 0x103:
315
          table = u103;
316
          size = sizeof(u103);
317
          break;
318
        case 0x104:
319
          table = u104;
320
          size = sizeof(u104);
321
          break;
322
        case 0x1d0:
323
          table = u1d0;
324
          size = sizeof(u1d0);
325
          break;
326
        case 0x1d1:
327
          table = u1d1;
328
          size = sizeof(u1d1);
329
          break;
330
        case 0x1d4:
331
          table = u1d4;
332
          size = sizeof(u1d4);
333
          break;
334
        case 0x1d5:
335
          table = u1d5;
336
          size = sizeof(u1d5);
337
          break;
338
        case 0x1d6:
339
          table = u1d6;
340
          size = sizeof(u1d6);
341
          break;
342
        case 0x1d7:
343
          table = u1d7;
344
          size = sizeof(u1d7);
345
          break;
346
        case 0x2a6:
347
          table = u2a6;
348
          size = sizeof(u2a6);
349
          break;
350
        case 0x2fa:
351
          table = u2fa;
352
          size = sizeof(u2fa);
353
          break;
354
        case 0xe00:
355
          table = ue00;
356
          size = sizeof(ue00);
357
          break;
358
        case 0xfff:
359
          table = ufff;
360
          size = sizeof(ufff);
361
          break;
362
        case 0x10ff:
363
          table = u10ff;
364
          size = sizeof(u10ff);
365
          break;
366
        default:
367
          return 0;
368
        }
369
      /* we have narrowed down to a section of 256 characters to check */
370
      /* now check if c matches the printuation wide-chars within that section */
371
      ptr = (unsigned char *)table;
372
      ctmp = (unsigned char)c;
373
      while (ptr < table + size)
374
        {
375
          if (ctmp == *ptr)
376
            return 1;
377
          if (ctmp < *ptr)
378
            return 0;
379
          /* otherwise c > *ptr */
380
          /* look for 0x0 as next element which indicates a range */
381
          ++ptr;
382
          if (*ptr == 0x0)
383
            {
384
              /* we have a range..see if c falls within range */
385
              ++ptr;
386
              if (ctmp <= *ptr)
387
                return 1;
388
              ++ptr;
389
            }
390
        }
391
      /* not in table */
392
      return 0;
393
    }
394
#endif /* _MB_CAPABLE */
395
 
396
  return (c < (wint_t)0x100 ? isprint (c) : 0);
397
}
398
 

powered by: WebSVN 2.1.0

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