Debian Codegraph @

share/libc/ctype.c

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 #include "ctype.h"
24 #include "__fc_builtin.h"
25 __PUSH_FC_STDLIB
26
27 // This file assumes a simple, C-like locale, with no extra characters
28 // or special cases.
29
30 #define ISDIGIT(_c) \
31 ((_c) >= '0' && (_c) <= '9')
32
33 #define ISXDIGIT(_c) \
34 (ISDIGIT(_c) || \
35 ((_c) >= 'a' && (_c) <= 'f') || \
36 ((_c) >= 'A' && (_c) <= 'F'))
37
38 // if locale = "C"
39 #define ISLOWER(_c) \
40 ((_c) >= 'a' && (_c) <= 'z')
41
42 // if locale = "C"
43 #define ISUPPER(_c) \
44 ((_c) >= 'A' && (_c) <= 'Z')
45
46 #define ISALPHA(_c) \
47 (ISUPPER(_c) || \
48 ISLOWER(_c))
49
50 #define ISALNUM(_c) \
51 (ISALPHA(_c) || \
52 ISDIGIT(_c))
53
54 // if locale = "C"
55 #define ISSPACE(_c) \
56 ((_c) == ' ' || \
57 (_c) == '\f' || \
58 (_c) == '\n' || \
59 (_c) == '\r' || \
60 (_c) == '\t' || \
61 (_c) == '\v' )
62
63 // if locale = "C"
64 #define ISBLANK(_c) \
65 ((_c) == ' ' || \
66 (_c) == '\t')
67
68 int isalnum(int c) {
69 return (ISALNUM(c));
70 }
71
72 int isalpha(int c){
73 return (ISALPHA(c));
74 }
75
76 int isblank(int c){
77 return (ISBLANK(c)||ISSPACE(c));
78 }
79
80 int iscntrl(int c) {
81 return (Frama_C_nondet(0,1));
82 }
83
84 int isdigit(int c) {
85 return (ISDIGIT(c));
86 }
87
88 int isgraph(int c) {
89 return (Frama_C_nondet(0,1));
90 }
91
92 int islower(int c) {
93 return (ISLOWER(c));
94 }
95
96 int isprint(int c) {
97 return (Frama_C_nondet(0,1));
98 }
99
100 int ispunct(int c) {
101 return (Frama_C_nondet(0,1));
102 }
103
104 int isspace(int c) {
105 return (ISSPACE(c));
106 }
107
108 int isupper(int c) {
109 return (ISUPPER(c));
110 }
111
112 int isxdigit(int c) {
113 return (ISXDIGIT(c));
114 }
115
116 int tolower(int c) {
117 if ((c >= 'A') && (c <= 'Z'))
118 return c + 0x20;
119 return c;
120 }
121
122 int toupper (int c)
123 {
124 if ((c >= 'a') && (c <= 'z'))
125 return c - 0x20;
126 return c;
127 }
128
129 __POP_FC_STDLIB