diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/lib/libc.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/lib/libc.b')
| -rw-r--r-- | appl/lib/libc.b | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/appl/lib/libc.b b/appl/lib/libc.b new file mode 100644 index 00000000..0acc6f42 --- /dev/null +++ b/appl/lib/libc.b @@ -0,0 +1,141 @@ +implement Libc; + +include "libc.m"; + +islx(c: int): int +{ + return c >= 'a' && c <= 'f'; +} + +isux(c: int): int +{ + return c >= 'A' && c <= 'F'; +} + +isalnum(c: int): int +{ + return isalpha(c) || isdigit(c); +} + +isalpha(c: int): int +{ + return islower(c) || isupper(c); +} + +isascii(c: int): int +{ + return (c&~16r7f) == 0; +} + +iscntrl(c: int): int +{ + return c == 16r7f || (c&~16r1f) == 0; +} + +isdigit(c: int): int +{ + return c >= '0' && c <= '9'; +} + +isgraph(c: int): int +{ + return c >= '!' && c <= '~'; +} + +islower(c: int): int +{ + return c >= 'a' && c <= 'z'; +} + +isprint(c: int): int +{ + return c >= ' ' && c <= '~'; +} + +ispunct(c: int): int +{ + return isascii(c) && !iscntrl(c) && !isspace(c) && !isalnum(c); +} + +isspace(c: int): int +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'; +} + +isupper(c: int): int +{ + return c >= 'A' && c <= 'Z'; +} + +isxdigit(c: int): int +{ + return isdigit(c) || islx(c) || isux(c); +} + +tolower(c: int): int +{ + if(isupper(c)) + return c+'a'-'A'; + return c; +} + +toupper(c: int): int +{ + if(islower(c)) + return c+'A'-'a'; + return c; +} + +toascii(c: int): int +{ + return c&16r7f; +} + +strchr(s: string, n: int): int +{ + l := len s; + for(i := 0; i < l; i++) + if(s[i] == n) + return i; + return -1; +} + +strrchr(s: string, n: int): int +{ + l := len s; + for(i := l-1; i >= 0; i--) + if(s[i] == n) + return i; + return -1; +} + +strncmp(s1: string, s2: string, n: int): int +{ + l1 := len s1; + l2 := len s2; + for(i := 0; i < l1 && i < l2 && i < n; i++) + if(s1[i] != s2[i]) + return s1[i]-int s2[i]; + return l1-l2; +} + +abs(n: int): int +{ + if(n < 0) + return -n; + return n; +} + +min(m: int, n: int): int +{ + if(m < n) + return m; + return n; +} + +max(m: int, n: int): int +{ + if(m > n) + return m; + return n; +} |
