OSDN Git Service

Rename cygWFMO to cygwait throughout and use the magic of polymorphism to "wait
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / ctype.cc
1 #include "winsup.h"
2 extern "C" {
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <wctype.h>
6
7 extern char _ctype_b[128 + 256];
8
9 /* Called from newlib's setlocale().  What we do here is to copy the
10    128 bytes of charset specific ctype data into the array at _ctype_b.
11    Given that the functionality is usually implemented locally in the
12    application, that's the only backward compatible way to do it.
13    Setlocale is usually only called once in an application, so this isn't
14    time-critical anyway. */
15 extern int __iso_8859_index (const char *charset_ext);  /* Newlib */
16 extern int __cp_index (const char *charset_ext);        /* Newlib */
17 extern const char __ctype_cp[22][128 + 256];            /* Newlib */
18 extern const char __ctype_iso[15][128 + 256];           /* Newlib */
19
20 void
21 __set_ctype (const char *charset)
22 {
23   int idx;
24
25   switch (*charset)
26     {
27     case 'I':
28       idx = __iso_8859_index (charset + 9);
29       /* Our ctype table has a leading ISO-8859-1 element. */
30       if (idx < 0)
31         idx = 0;
32       else
33         ++idx;
34       if (CYGWIN_VERSION_CHECK_FOR_OLD_CTYPE)
35         {
36           memcpy (_ctype_b, __ctype_iso[idx], 128);
37           memcpy (_ctype_b + 256, __ctype_iso[idx] + 256, 128);
38         }
39       __ctype_ptr__ = (char *) (__ctype_iso[idx] + 127);
40       return;
41     case 'C':
42       idx = __cp_index (charset + 2);
43       if (idx < 0)
44         break;
45       if (CYGWIN_VERSION_CHECK_FOR_OLD_CTYPE)
46         {
47           memcpy (_ctype_b, __ctype_cp[idx], 128);
48           memcpy (_ctype_b + 256, __ctype_cp[idx] + 256, 128);
49         }
50       __ctype_ptr__ = (char *) (__ctype_cp[idx] + 127);
51       return;
52     default:
53       break;
54     }
55   if (CYGWIN_VERSION_CHECK_FOR_OLD_CTYPE)
56     {
57       memset (_ctype_b, 0, 128);
58       memset (_ctype_b + 256, 0, 128);
59     }
60   __ctype_ptr__ = (char *) _ctype_b + 127;
61 }
62
63 } /* extern "C" */
64
65 /*
66  * Copyright (c) 1989 The Regents of the University of California.
67  * All rights reserved.
68  *
69  * Redistribution and use in source and binary forms, with or without
70  * modification, are permitted provided that the following conditions
71  * are met:
72  * 1. Redistributions of source code must retain the above copyright
73  *    notice, this list of conditions and the following disclaimer.
74  * 2. Redistributions in binary form must reproduce the above copyright
75  *    notice, this list of conditions and the following disclaimer in the
76  *    documentation and/or other materials provided with the distribution.
77  *
78  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
79  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
80  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
81  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88  * SUCH DAMAGE.
89  */
90