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