1 | #ifdef FREEBSD_CTYPE␊ |
2 | /*-␊ |
3 | * Copyright (c) 1982, 1988, 1991, 1993␊ |
4 | * The Regents of the University of California. All rights reserved.␊ |
5 | * (c) UNIX System Laboratories, Inc.␊ |
6 | * All or some portions of this file are derived from material licensed␊ |
7 | * to the University of California by American Telephone and Telegraph␊ |
8 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with␊ |
9 | * the permission of UNIX System Laboratories, Inc.␊ |
10 | *␊ |
11 | * Redistribution and use in source and binary forms, with or without␊ |
12 | * modification, are permitted provided that the following conditions␊ |
13 | * are met:␊ |
14 | * 1. Redistributions of source code must retain the above copyright␊ |
15 | * notice, this list of conditions and the following disclaimer.␊ |
16 | * 2. Redistributions in binary form must reproduce the above copyright␊ |
17 | * notice, this list of conditions and the following disclaimer in the␊ |
18 | * documentation and/or other materials provided with the distribution.␊ |
19 | * 4. Neither the name of the University nor the names of its contributors␊ |
20 | * may be used to endorse or promote products derived from this software␊ |
21 | * without specific prior written permission.␊ |
22 | *␊ |
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND␊ |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE␊ |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE␊ |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE␊ |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL␊ |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS␊ |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)␊ |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT␊ |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY␊ |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF␊ |
33 | * SUCH DAMAGE.␊ |
34 | *␊ |
35 | * $FreeBSD$␊ |
36 | */␊ |
37 | ␊ |
38 | #ifndef _SYS_CTYPE_H_␊ |
39 | #define _SYS_CTYPE_H_␊ |
40 | ␊ |
41 | #define isspace(c) ((c) == ' ' || ((c) >= '\t' && (c) <= '\r'))␊ |
42 | #define isascii(c) (((c) & ~0x7f) == 0)␊ |
43 | #define isupper(c) ((c) >= 'A' && (c) <= 'Z')␊ |
44 | #define islower(c) ((c) >= 'a' && (c) <= 'z')␊ |
45 | #define isalpha(c) (isupper(c) || islower(c))␊ |
46 | #define isdigit(c) ((c) >= ' ' && (c) <= '9')␊ |
47 | #define isxdigit(c) (isdigit(c) \␊ |
48 | || ((c) >= 'A' && (c) <= 'F') \␊ |
49 | || ((c) >= 'a' && (c) <= 'f'))␊ |
50 | #define isprint(c) ((c) >= ' ' && (c) <= '~')␊ |
51 | ␊ |
52 | #define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))␊ |
53 | #define tolower(c) ((c) + 0x20 * (((c) >= 'A') && ((c) <= 'Z')))␊ |
54 | ␊ |
55 | /*␊ |
56 | * ctype additions (aserebln)␊ |
57 | */␊ |
58 | #define ispunct(c) (c == '.' || c == '-') //Azi: TODO - add more ponctuation characters as needed; at least these two, i need for PartNo.␊ |
59 | ␊ |
60 | ␊ |
61 | #endif /* !_SYS_CTYPE_H_ */␊ |
62 | ␊ |
63 | #else␊ |
64 | ␊ |
65 | /**␊ |
66 | * @file␊ |
67 | * @brief ISO C99 Standard 7.4: Character handling.␊ |
68 | * @details Contains declarations for character classification functions.␊ |
69 | *␊ |
70 | * @date 14.10.09␊ |
71 | * @author Nikolay Korotky␊ |
72 | */␊ |
73 | ␊ |
74 | #ifndef CTYPE_H_␊ |
75 | #define CTYPE_H_␊ |
76 | ␊ |
77 | #define _U 0x01 /* upper */␊ |
78 | #define _L 0x02 /* lower */␊ |
79 | #define _D 0x04 /* digit */␊ |
80 | #define _C 0x08 /* cntrl */␊ |
81 | #define _P 0x10 /* punct */␊ |
82 | #define _S 0x20 /* white space (space/lf/tab) */␊ |
83 | #define _X 0x40 /* hex digit */␊ |
84 | #define _SP 0x80 /* hard space (0x20) */␊ |
85 | ␊ |
86 | extern unsigned char _ctype[];␊ |
87 | ␊ |
88 | #define __ismask(x) (_ctype[(int)(unsigned char)(x)])␊ |
89 | ␊ |
90 | /* Checks for an alphanumeric character. */␊ |
91 | #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)␊ |
92 | /* Checks for an alphabetic character. */␊ |
93 | #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)␊ |
94 | /* Checks for a control character. */␊ |
95 | #define iscntrl(c) ((__ismask(c)&(_C)) != 0)␊ |
96 | /* Checks for a digit (0 through 9). */␊ |
97 | #define isdigit(c) ((__ismask(c)&(_D)) != 0)␊ |
98 | /* Checks for any printable character except space. */␊ |
99 | #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)␊ |
100 | /* Checks for a lower-case character. */␊ |
101 | #define islower(c) ((__ismask(c)&(_L)) != 0)␊ |
102 | /* Checks for any printable character including space. */␊ |
103 | #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)␊ |
104 | /* Checks for any printable character which is not a space␊ |
105 | * or an alphanumeric character. */␊ |
106 | #define ispunct(c) ((__ismask(c)&(_P)) != 0)␊ |
107 | /* Checks for white-space characters. */␊ |
108 | #define isspace(c) ((__ismask(c)&(_S)) != 0)␊ |
109 | /* Checks for an uppercase letter. */␊ |
110 | #define isupper(c) ((__ismask(c)&(_U)) != 0)␊ |
111 | /* Checks for a hexadecimal digits. */␊ |
112 | #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)␊ |
113 | ␊ |
114 | /* Checks whether c is a 7-bit unsigned char value that␊ |
115 | * fits into the ASCII character set. */␊ |
116 | #define isascii(c) (((unsigned char)(c))<=0x7f)␊ |
117 | #define toascii(c) (((unsigned char)(c))&0x7f)␊ |
118 | ␊ |
119 | static inline unsigned char __tolower(unsigned char c) {␊ |
120 | ␉return isupper(c) ? c - ('A' - 'a') : c;␊ |
121 | }␊ |
122 | ␊ |
123 | static inline unsigned char __toupper(unsigned char c) {␊ |
124 | ␉return islower(c) ? c - ('a' - 'A') : c;␊ |
125 | }␊ |
126 | ␊ |
127 | /* Convert a character to lower case */␊ |
128 | #define tolower(c) __tolower(c)␊ |
129 | ␊ |
130 | /* Convert a character to upper case */␊ |
131 | #define toupper(c) __toupper(c)␊ |
132 | ␊ |
133 | #endif /* CTYPE_H_ */␊ |
134 | ␊ |
135 | ␊ |
136 | #endif |