source: trunk/libs/newlib/src/newlib/libc/ctype/iswprint.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 10.4 KB
Line 
1/* 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/*
31FUNCTION
32        <<iswprint>>, <<iswprint_l>>---printable wide character test
33
34INDEX
35        iswprint
36
37INDEX
38        iswprint_l
39
40SYNOPSIS
41        #include <wctype.h>
42        int iswprint(wint_t <[c]>);
43
44        #include <wctype.h>
45        int iswprint_l(wint_t <[c]>, locale_t <[locale]>);
46
47DESCRIPTION
48<<iswprint>> is a function which classifies wide-character values that
49are printable.
50
51<<iswprint_l>> is like <<iswprint>> but performs the check based on the
52locale specified by the locale object locale.  If <[locale]> is
53LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.
54
55RETURNS
56<<iswprint>>, <<iswprint_l>> return non-zero if <[c]> is a printable wide character.
57
58PORTABILITY
59<<iswprint>> is C99.
60<<iswprint_l>> is POSIX-1.2008.
61
62No supporting OS subroutines are required.
63*/
64#include <_ansi.h>
65#include <newlib.h>
66#include <wctype.h>
67#include <string.h>
68#include <ctype.h>
69#include "local.h"
70
71#ifdef _MB_CAPABLE
72#include "utf8print.h"
73#endif /* _MB_CAPABLE */
74
75int
76iswprint (wint_t c)
77{
78#ifdef _MB_CAPABLE
79  unsigned const char *table;
80  unsigned char *ptr;
81  unsigned char ctmp;
82  int size;
83  wint_t x;
84 
85  c = _jp2uc (c);
86
87  /* Based on and tested against Unicode 5.2
88     See utf8print.h for a description how to fetch the data. */
89  x = (c >> 8);
90  /* for some large sections, all characters are printuation so handle them here */
91  if ((x >= 0x33 && x <= 0x4c) ||
92      (x >= 0x4e && x <= 0x9e) ||
93      (x >= 0xa0 && x <= 0xa3) ||
94      (x >= 0xac && x <= 0xd6) ||
95      (x >= 0xe0 && x <= 0xf9) ||
96      (x >= 0x120 && x <= 0x122) ||
97      (x >= 0x130 && x <= 0x133) ||
98      (x >= 0x200 && x <= 0x2a5) ||
99      (x >= 0x2a7 && x <= 0x2b6) ||
100      (x >= 0xf00 && x <= 0xffe) ||
101      (x >= 0x1000 && x <= 0x10fe))
102    return 1;
103 
104  switch (x)
105    {
106    case 0x01:
107    case 0x02:
108    case 0x04:
109    case 0x11:
110    case 0x14:
111    case 0x15:
112    case 0x1e:
113    case 0x22:
114    case 0x25:
115    case 0x28:
116    case 0x29:
117    case 0x2a:
118    case 0xa5:
119    case 0xfc:
120    case 0x2f8:
121    case 0x2f9:
122      return 1;
123    case 0x00:
124      table = u0;
125      size = sizeof(u0);
126      break;
127    case 0x03:
128      table = u3;
129      size = sizeof(u3);
130      break;
131    case 0x05:
132      table = u5;
133      size = sizeof(u5);
134      break;
135    case 0x06:
136      table = u6;
137      size = sizeof(u6);
138      break;
139    case 0x07:
140      table = u7;
141      size = sizeof(u7);
142      break;
143    case 0x08:
144      table = u8;
145      size = sizeof(u8);
146      break;
147    case 0x09:
148      table = u9;
149      size = sizeof(u9);
150      break;
151    case 0x0a:
152      table = ua;
153      size = sizeof(ua);
154      break;
155    case 0x0b:
156      table = ub;
157      size = sizeof(ub);
158      break;
159    case 0x0c:
160      table = uc;
161      size = sizeof(uc);
162      break;
163    case 0x0d:
164      table = ud;
165      size = sizeof(ud);
166      break;
167    case 0x0e:
168      table = ue;
169      size = sizeof(ue);
170      break;
171    case 0x0f:
172      table = uf;
173      size = sizeof(uf);
174      break;
175    case 0x10:
176      table = u10;
177      size = sizeof(u10);
178      break;
179    case 0x12:
180      table = u12;
181      size = sizeof(u12);
182      break;
183    case 0x13:
184      table = u13;
185      size = sizeof(u13);
186      break;
187    case 0x16:
188      table = u16;
189      size = sizeof(u16);
190      break;
191    case 0x17:
192      table = u17;
193      size = sizeof(u17);
194      break;
195    case 0x18:
196      table = u18;
197      size = sizeof(u18);
198      break;
199    case 0x19:
200      table = u19;
201      size = sizeof(u19);
202      break;
203    case 0x1a:
204      table = u1a;
205      size = sizeof(u1a);
206      break;
207    case 0x1b:
208      table = u1b;
209      size = sizeof(u1b);
210      break;
211    case 0x1c:
212      table = u1c;
213      size = sizeof(u1c);
214      break;
215    case 0x1d:
216      table = u1d;
217      size = sizeof(u1d);
218      break;
219    case 0x1f:
220      table = u1f;
221      size = sizeof(u1f);
222      break;
223    case 0x20:
224      table = u20;
225      size = sizeof(u20);
226      break;
227    case 0x21:
228      table = u21;
229      size = sizeof(u21);
230      break;
231    case 0x23:
232      table = u23;
233      size = sizeof(u23);
234      break;
235    case 0x24:
236      table = u24;
237      size = sizeof(u24);
238      break;
239    case 0x26:
240      table = u26;
241      size = sizeof(u26);
242      break;
243    case 0x27:
244      table = u27;
245      size = sizeof(u27);
246      break;
247    case 0x2b:
248      table = u2b;
249      size = sizeof(u2b);
250      break;
251    case 0x2c:
252      table = u2c;
253      size = sizeof(u2c);
254      break;
255    case 0x2d:
256      table = u2d;
257      size = sizeof(u2d);
258      break;
259    case 0x2e:
260      table = u2e;
261      size = sizeof(u2e);
262      break;
263    case 0x2f:
264      table = u2f;
265      size = sizeof(u2f);
266      break;
267    case 0x30:
268      table = u30;
269      size = sizeof(u30);
270      break;
271    case 0x31:
272      table = u31;
273      size = sizeof(u31);
274      break;
275    case 0x32:
276      table = u32;
277      size = sizeof(u32);
278      break;
279    case 0x4d:
280      table = u4d;
281      size = sizeof(u4d);
282      break;
283    case 0x9f:
284      table = u9f;
285      size = sizeof(u9f);
286      break;
287    case 0xa4:
288      table = ua4;
289      size = sizeof(ua4);
290      break;
291    case 0xa6:
292      table = ua6;
293      size = sizeof(ua6);
294      break;
295    case 0xa7:
296      table = ua7;
297      size = sizeof(ua7);
298      break;
299    case 0xa8:
300      table = ua8;
301      size = sizeof(ua8);
302      break;
303    case 0xa9:
304      table = ua9;
305      size = sizeof(ua9);
306      break;
307    case 0xaa:
308      table = uaa;
309      size = sizeof(uaa);
310      break;
311    case 0xab:
312      table = uab;
313      size = sizeof(uab);
314      break;
315    case 0xd7:
316      table = ud7;
317      size = sizeof(ud7);
318      break;
319    case 0xfa:
320      table = ufa;
321      size = sizeof(ufa);
322      break;
323    case 0xfb:
324      table = ufb;
325      size = sizeof(ufb);
326      break;
327    case 0xfd:
328      table = ufd;
329      size = sizeof(ufd);
330      break;
331    case 0xfe:
332      table = ufe;
333      size = sizeof(ufe);
334      break;
335    case 0xff:
336      table = uff;
337      size = sizeof(uff);
338      break;
339    case 0x100:
340      table = u100;
341      size = sizeof(u100);
342      break;
343    case 0x101:
344      table = u101;
345      size = sizeof(u101);
346      break;
347    case 0x102:
348      table = u102;
349      size = sizeof(u102);
350      break;
351    case 0x103:
352      table = u103;
353      size = sizeof(u103);
354      break;
355    case 0x104:
356      table = u104;
357      size = sizeof(u104);
358      break;
359    case 0x108:
360      table = u108;
361      size = sizeof(u108);
362      break;
363    case 0x109:
364      table = u109;
365      size = sizeof(u109);
366      break;
367    case 0x10a:
368      table = u10a;
369      size = sizeof(u10a);
370      break;
371    case 0x10b:
372      table = u10b;
373      size = sizeof(u10b);
374      break;
375    case 0x10c:
376      table = u10c;
377      size = sizeof(u10c);
378      break;
379    case 0x10e:
380      table = u10e;
381      size = sizeof(u10e);
382      break;
383    case 0x110:
384      table = u110;
385      size = sizeof(u110);
386      break;
387    case 0x123:
388      table = u123;
389      size = sizeof(u123);
390      break;
391    case 0x124:
392      table = u124;
393      size = sizeof(u124);
394      break;
395    case 0x134:
396      table = u134;
397      size = sizeof(u134);
398      break;
399    case 0x1d0:
400      table = u1d0;
401      size = sizeof(u1d0);
402      break;
403    case 0x1d1:
404      table = u1d1;
405      size = sizeof(u1d1);
406      break;
407    case 0x1d2:
408      table = u1d2;
409      size = sizeof(u1d2);
410      break;
411    case 0x1d3:
412      table = u1d3;
413      size = sizeof(u1d3);
414      break;
415    case 0x1d4:
416      table = u1d4;
417      size = sizeof(u1d4);
418      break;
419    case 0x1d5:
420      table = u1d5;
421      size = sizeof(u1d5);
422      break;
423    case 0x1d6:
424      table = u1d6;
425      size = sizeof(u1d6);
426      break;
427    case 0x1d7:
428      table = u1d7;
429      size = sizeof(u1d7);
430      break;
431    case 0x1f0:
432      table = u1f0;
433      size = sizeof(u1f0);
434      break;
435    case 0x1f1:
436      table = u1f1;
437      size = sizeof(u1f1);
438      break;
439    case 0x1f2:
440      table = u1f2;
441      size = sizeof(u1f2);
442      break;
443    case 0x2a6:
444      table = u2a6;
445      size = sizeof(u2a6);
446      break;
447    case 0x2b7:
448      table = u2b7;
449      size = sizeof(u2b7);
450      break;
451    case 0x2fa:
452      table = u2fa;
453      size = sizeof(u2fa);
454      break;
455    case 0xe00:
456      table = ue00;
457      size = sizeof(ue00);
458      break;
459    case 0xe01:
460      table = ue01;
461      size = sizeof(ue01);
462      break;
463    case 0xfff:
464      table = ufff;
465      size = sizeof(ufff);
466      break;
467    case 0x10ff:
468      table = u10ff;
469      size = sizeof(u10ff);
470      break;
471    default:
472      return 0;
473    }
474  /* we have narrowed down to a section of 256 characters to check */
475  /* now check if c matches the printuation wide-chars within that section */
476  ptr = (unsigned char *)table;
477  ctmp = (unsigned char)c;
478  while (ptr < table + size)
479    {
480      if (ctmp == *ptr)
481        return 1;
482      if (ctmp < *ptr)
483        return 0;
484      /* otherwise c > *ptr */
485      /* look for 0x0 as next element which indicates a range */
486      ++ptr;
487      if (*ptr == 0x0)
488        {
489          /* we have a range..see if c falls within range */
490          ++ptr;
491          if (ctmp <= *ptr)
492            return 1;
493          ++ptr;
494        }
495    }
496  /* not in table */
497  return 0;
498#else
499  return (c < (wint_t)0x100 ? isprint (c) : 0);
500#endif /* _MB_CAPABLE */
501}
Note: See TracBrowser for help on using the repository browser.