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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [ctype/] [iswprint.c] - Blame information for rev 520

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 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
#ifdef _MB_CAPABLE
73
  unsigned const char *table;
74
  unsigned char *ptr;
75
  unsigned char ctmp;
76
  int size;
77
  wint_t x;
78
 
79
  c = _jp2uc (c);
80
 
81
  x = (c >> 8);
82
  /* for some large sections, all characters are printuation so handle them here */
83
  if ((x >= 0x34 && x <= 0x4c) ||
84
      (x >= 0x4e && x <= 0x9e) ||
85
      (x >= 0xac && x <= 0xd6) ||
86
      (x >= 0xe0 && x <= 0xf9) ||
87
      (x >= 0x200 && x <= 0x2a5) ||
88
      (x >= 0xf00 && x <= 0xffe) ||
89
      (x >= 0x1000 && x <= 0x10fe))
90
    return 1;
91
 
92
  switch (x)
93
    {
94
    case 0x01:
95
    case 0x15:
96
    case 0x22:
97
    case 0x25:
98
    case 0x28:
99
    case 0x29:
100
    case 0x2a:
101
    case 0xa0:
102
    case 0xa1:
103
    case 0xa2:
104
    case 0xa3:
105
    case 0xfc:
106
    case 0x2f8:
107
    case 0x2f9:
108
      return 1;
109
    case 0x00:
110
      table = u0;
111
      size = sizeof(u0);
112
      break;
113
    case 0x02:
114
      table = u2;
115
      size = sizeof(u2);
116
      break;
117
    case 0x03:
118
      table = u3;
119
      size = sizeof(u3);
120
      break;
121
    case 0x04:
122
      table = u4;
123
      size = sizeof(u4);
124
      break;
125
    case 0x05:
126
      table = u5;
127
      size = sizeof(u5);
128
      break;
129
    case 0x06:
130
      table = u6;
131
      size = sizeof(u6);
132
      break;
133
    case 0x07:
134
      table = u7;
135
      size = sizeof(u7);
136
      break;
137
    case 0x09:
138
      table = u9;
139
      size = sizeof(u9);
140
      break;
141
    case 0x0a:
142
      table = ua;
143
      size = sizeof(ua);
144
      break;
145
    case 0x0b:
146
      table = ub;
147
      size = sizeof(ub);
148
      break;
149
    case 0x0c:
150
      table = uc;
151
      size = sizeof(uc);
152
      break;
153
    case 0x0d:
154
      table = ud;
155
      size = sizeof(ud);
156
      break;
157
    case 0x0e:
158
      table = ue;
159
      size = sizeof(ue);
160
      break;
161
    case 0x0f:
162
      table = uf;
163
      size = sizeof(uf);
164
      break;
165
    case 0x10:
166
      table = u10;
167
      size = sizeof(u10);
168
      break;
169
    case 0x11:
170
      table = u11;
171
      size = sizeof(u11);
172
      break;
173
    case 0x12:
174
      table = u12;
175
      size = sizeof(u12);
176
      break;
177
    case 0x13:
178
      table = u13;
179
      size = sizeof(u13);
180
      break;
181
    case 0x14:
182
      table = u14;
183
      size = sizeof(u14);
184
      break;
185
    case 0x16:
186
      table = u16;
187
      size = sizeof(u16);
188
      break;
189
    case 0x17:
190
      table = u17;
191
      size = sizeof(u17);
192
      break;
193
    case 0x18:
194
      table = u18;
195
      size = sizeof(u18);
196
      break;
197
    case 0x1e:
198
      table = u1e;
199
      size = sizeof(u1e);
200
      break;
201
    case 0x1f:
202
      table = u1f;
203
      size = sizeof(u1f);
204
      break;
205
    case 0x20:
206
      table = u20;
207
      size = sizeof(u20);
208
      break;
209
    case 0x21:
210
      table = u21;
211
      size = sizeof(u21);
212
      break;
213
    case 0x23:
214
      table = u23;
215
      size = sizeof(u23);
216
      break;
217
    case 0x24:
218
      table = u24;
219
      size = sizeof(u24);
220
      break;
221
    case 0x26:
222
      table = u26;
223
      size = sizeof(u26);
224
      break;
225
    case 0x27:
226
      table = u27;
227
      size = sizeof(u27);
228
      break;
229
    case 0x2e:
230
      table = u2e;
231
      size = sizeof(u2e);
232
      break;
233
    case 0x2f:
234
      table = u2f;
235
      size = sizeof(u2f);
236
      break;
237
    case 0x30:
238
      table = u30;
239
      size = sizeof(u30);
240
      break;
241
    case 0x31:
242
      table = u31;
243
      size = sizeof(u31);
244
      break;
245
    case 0x32:
246
      table = u32;
247
      size = sizeof(u32);
248
      break;
249
    case 0x33:
250
      table = u33;
251
      size = sizeof(u33);
252
      break;
253
    case 0x4d:
254
      table = u4d;
255
      size = sizeof(u4d);
256
      break;
257
    case 0x9f:
258
      table = u9f;
259
      size = sizeof(u9f);
260
      break;
261
    case 0xa4:
262
      table = ua4;
263
      size = sizeof(ua4);
264
      break;
265
    case 0xd7:
266
      table = ud7;
267
      size = sizeof(ud7);
268
      break;
269
    case 0xfa:
270
      table = ufa;
271
      size = sizeof(ufa);
272
      break;
273
    case 0xfb:
274
      table = ufb;
275
      size = sizeof(ufb);
276
      break;
277
    case 0xfd:
278
      table = ufd;
279
      size = sizeof(ufd);
280
      break;
281
    case 0xfe:
282
      table = ufe;
283
      size = sizeof(ufe);
284
      break;
285
    case 0xff:
286
      table = uff;
287
      size = sizeof(uff);
288
      break;
289
    case 0x103:
290
      table = u103;
291
      size = sizeof(u103);
292
      break;
293
    case 0x104:
294
      table = u104;
295
      size = sizeof(u104);
296
      break;
297
    case 0x1d0:
298
      table = u1d0;
299
      size = sizeof(u1d0);
300
      break;
301
    case 0x1d1:
302
      table = u1d1;
303
      size = sizeof(u1d1);
304
      break;
305
    case 0x1d4:
306
      table = u1d4;
307
      size = sizeof(u1d4);
308
      break;
309
    case 0x1d5:
310
      table = u1d5;
311
      size = sizeof(u1d5);
312
      break;
313
    case 0x1d6:
314
      table = u1d6;
315
      size = sizeof(u1d6);
316
      break;
317
    case 0x1d7:
318
      table = u1d7;
319
      size = sizeof(u1d7);
320
      break;
321
    case 0x2a6:
322
      table = u2a6;
323
      size = sizeof(u2a6);
324
      break;
325
    case 0x2fa:
326
      table = u2fa;
327
      size = sizeof(u2fa);
328
      break;
329
    case 0xe00:
330
      table = ue00;
331
      size = sizeof(ue00);
332
      break;
333
    case 0xfff:
334
      table = ufff;
335
      size = sizeof(ufff);
336
      break;
337
    case 0x10ff:
338
      table = u10ff;
339
      size = sizeof(u10ff);
340
      break;
341
    default:
342
      return 0;
343
    }
344
  /* we have narrowed down to a section of 256 characters to check */
345
  /* now check if c matches the printuation wide-chars within that section */
346
  ptr = (unsigned char *)table;
347
  ctmp = (unsigned char)c;
348
  while (ptr < table + size)
349
    {
350
      if (ctmp == *ptr)
351
        return 1;
352
      if (ctmp < *ptr)
353
        return 0;
354
      /* otherwise c > *ptr */
355
      /* look for 0x0 as next element which indicates a range */
356
      ++ptr;
357
      if (*ptr == 0x0)
358
        {
359
          /* we have a range..see if c falls within range */
360
          ++ptr;
361
          if (ctmp <= *ptr)
362
            return 1;
363
          ++ptr;
364
        }
365
    }
366
  /* not in table */
367
  return 0;
368
#else
369
  return (c < (wint_t)0x100 ? isprint (c) : 0);
370
#endif /* _MB_CAPABLE */
371
}
372
 

powered by: WebSVN 2.1.0

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