| 1 |
/* wcmisc.c - replace wcXXXX routines |
| 2 |
Copyright (C) 2011 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 3, or (at your option) |
| 7 |
any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., |
| 17 |
51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA */ |
| 18 |
|
| 19 |
#if !defined(HAVE_WCTYPE) || !defined(HAVE_ISWCTYPE) |
| 20 |
static const char *classes[] = { |
| 21 |
"<dummy>", |
| 22 |
"alnum", |
| 23 |
"alpha", |
| 24 |
"blank", |
| 25 |
"cntrl", |
| 26 |
"digit", |
| 27 |
"graph", |
| 28 |
"lower", |
| 29 |
"print", |
| 30 |
"punct", |
| 31 |
"space", |
| 32 |
"upper", |
| 33 |
"xdigit", |
| 34 |
NULL |
| 35 |
}; |
| 36 |
#endif |
| 37 |
|
| 38 |
#ifndef HAVE_ISWCTYPE |
| 39 |
static int is_blank (int c) |
| 40 |
{ |
| 41 |
return (c == ' ' || c == '\t'); |
| 42 |
} |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifndef HAVE_WCTYPE |
| 46 |
wctype_t wctype(const char *name) |
| 47 |
{ |
| 48 |
int i; |
| 49 |
|
| 50 |
for (i = 1; classes[i] != NULL; i++) |
| 51 |
if (strcmp(name, classes[i]) == 0) |
| 52 |
return i; |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |
| 56 |
#endif |
| 57 |
|
| 58 |
#ifndef HAVE_ISWCTYPE |
| 59 |
int iswctype(wint_t wc, wctype_t desc) |
| 60 |
{ |
| 61 |
int j = sizeof(classes) / sizeof(classes[0]); |
| 62 |
|
| 63 |
if (desc >= j || desc == 0) |
| 64 |
return 0; |
| 65 |
|
| 66 |
switch (desc) { |
| 67 |
case 1: return isalnum(wc); |
| 68 |
case 2: return isalpha(wc); |
| 69 |
case 3: return is_blank(wc); |
| 70 |
case 4: return iscntrl(wc); |
| 71 |
case 5: return isdigit(wc); |
| 72 |
case 6: return isgraph(wc); |
| 73 |
case 7: return islower(wc); |
| 74 |
case 8: return isprint(wc); |
| 75 |
case 9: return ispunct(wc); |
| 76 |
case 10: return isspace(wc); |
| 77 |
case 11: return isupper(wc); |
| 78 |
case 12: return isxdigit(wc); |
| 79 |
default: return 0; |
| 80 |
} |
| 81 |
} |
| 82 |
#endif |
| 83 |
|
| 84 |
#ifndef HAVE_WCSCOLL |
| 85 |
int wcscoll(const wchar_t *ws1, const wchar_t *ws2) |
| 86 |
{ |
| 87 |
size_t i; |
| 88 |
|
| 89 |
for (i = 0; ws1[i] != 0 && ws2[i] != 0; i++) { |
| 90 |
if (ws1[i] < ws2[i]) |
| 91 |
return -1; |
| 92 |
else if (ws1[i] > ws2[i]) |
| 93 |
return 1; |
| 94 |
} |
| 95 |
|
| 96 |
return (ws1[i] - ws2[i]); |
| 97 |
} |
| 98 |
#endif |
| 99 |
|
| 100 |
/*wcmisc.c*/ |