diff options
author | pommicket <pommicket@gmail.com> | 2022-02-15 16:36:52 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-15 16:36:52 -0500 |
commit | 23198d16f445e3596e6d309a5d36b144fb32e058 (patch) | |
tree | 20487184c9c0235493e7829665056a9e51a3039c /05/ctype.h | |
parent | f973ff8cb898aafd95673cb632ac83ebbcf820c7 (diff) |
ctype.h, getenv
Diffstat (limited to '05/ctype.h')
-rw-r--r-- | 05/ctype.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/05/ctype.h b/05/ctype.h new file mode 100644 index 0000000..ed6833d --- /dev/null +++ b/05/ctype.h @@ -0,0 +1,92 @@ +#ifndef _CTYPE_H +#define _CTYPE_H + +#include <stdc_common.h> + +int islower(int c) { + return c >= 'a' && c <= 'z'; +} + +int isupper(int c) { + return c >= 'A' && c <= 'Z'; +} + +int isalpha(int c) { + return isupper(c) || islower(c); +} + +int isalnum(int c) { + return isalpha(c) || isdigit(c); +} + +int isprint(int c) { + if (isalnum(c)) return 1; + switch (c) { + case '!': return 1; + case '@': return 1; + case '#': return 1; + case '$': return 1; + case '%': return 1; + case '^': return 1; + case '&': return 1; + case '*': return 1; + case '(': return 1; + case ')': return 1; + case '-': return 1; + case '=': return 1; + case '_': return 1; + case '+': return 1; + case '`': return 1; + case '~': return 1; + case '[': return 1; + case '{': return 1; + case ']': return 1; + case '}': return 1; + case '\\': return 1; + case '|': return 1; + case ';': return 1; + case ':': return 1; + case '\'': return 1; + case '"': return 1; + case ',': return 1; + case '<': return 1; + case '.': return 1; + case '>': return 1; + case '/': return 1; + case '?': return 1; + } + return 0; +} + +int iscntrl(int c) { + return !isprint(c); +} + +int isgraph(int c) { + return isprint(c) && c != ' '; +} + +int ispunct(int c) { + return isprint(c) && c != ' ' && !isalnum(c); +} + +int isxdigit(int c) { + if (isdigit(c)) return 1; + if (c >= 'a' && c <= 'f') return 1; + if (c >= 'A' && c <= 'F') return 1; + return 0; +} + +int tolower(int c) { + if (c >= 'A' && c <= 'Z') + return c - 'A' + 'a'; + return c; +} + +int toupper(int c) { + if (c >= 'a' && c <= 'z') + return c - 'a' + 'A'; + return c; +} + +#endif // _CTYPE_H |