mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
76 lines
3.7 KiB
C
76 lines
3.7 KiB
C
//----------------------------------------------------------------------------//
|
|
// GNU GPL OS/K //
|
|
// //
|
|
// Desc: Character types //
|
|
// //
|
|
// //
|
|
// Copyright © 2018-2020 The OS/K Team //
|
|
// //
|
|
// This file is part of OS/K. //
|
|
// //
|
|
// OS/K is free software: you can redistribute it and/or modify //
|
|
// it under the terms of the GNU General Public License as published by //
|
|
// the Free Software Foundation, either version 3 of the License, or //
|
|
// any later version. //
|
|
// //
|
|
// OS/K is distributed in the hope that it will be useful, //
|
|
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
// GNU General Public License for more details. //
|
|
// //
|
|
// You should have received a copy of the GNU General Public License //
|
|
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#include <libc.h>
|
|
|
|
#define SH(x) (1 << x)
|
|
|
|
enum
|
|
{
|
|
CT = SH(0), // control
|
|
PR = SH(1), // printing
|
|
GR = SH(2)|PR, // graphical
|
|
DX = SH(3)|GR, // hex digit
|
|
DG = SH(4)|DX, // decimal digit
|
|
SP = SH(5), // space
|
|
BK = SH(6)|SP, // blank
|
|
PT = SH(7)|GR, // punctuation
|
|
AL = SH(8)|GR, // alpha
|
|
UP = SH(9)|AL, // upper alpha
|
|
LW = SH(10)|AL // lower alpha
|
|
};
|
|
|
|
int __ctype[] = {
|
|
// ASCII ctype table
|
|
/* 0 */ CT, CT, CT, CT, CT, CT, CT, CT, CT, BK|CT,
|
|
/* 10 */ SP|CT, SP|CT, SP|CT, SP|CT, CT, CT, CT, CT, CT, CT,
|
|
/* 20 */ CT, CT, CT, CT, CT, CT, CT, CT, CT, CT,
|
|
/* 30 */ CT, CT, BK|PR, PT, PT, PT, PT, PT, PT, PT,
|
|
/* 40 */ PT, PT, PT, PT, PT, PT, PT, PT, DG, DG,
|
|
/* 50 */ DG, DG, DG, DG, DG, DG, DG, DG, PT, PT,
|
|
/* 60 */ PT, PT, PT, PT, PT, UP|DX, UP|DX, UP|DX, UP|DX, UP|DX,
|
|
/* 70 */ UP|DX, UP, UP, UP, UP, UP, UP, UP, UP, UP,
|
|
/* 80 */ UP, UP, UP, UP, UP, UP, UP, UP, UP, UP,
|
|
/* 90 */ UP, PT, PT, PT, PT, PT, PT, LW|DX, LW|DX, LW|DX,
|
|
/* 100 */ LW|DX, LW|DX, LW|DX, LW, LW, LW, LW, LW, LW, LW,
|
|
/* 110 */ LW, LW, LW, LW, LW, LW, LW, LW, LW, LW,
|
|
/* 120 */ LW, LW, LW, PT, PT, PT, PT, CT,
|
|
};
|
|
|
|
static_assert(sizeof(__ctype) == 128 * sizeof(int),
|
|
"ctype table: invalid size");
|
|
|
|
int tolower(int c)
|
|
{
|
|
if (isupper(c)) return c + ('a' - 'A');
|
|
return c;
|
|
}
|
|
|
|
int toupper(int c)
|
|
{
|
|
if (islower(c)) return c - ('a' - 'A');
|
|
return c;
|
|
}
|
|
|