Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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