diff --git a/libc/Makefile b/libc/Makefile index 689a0ab6..54a65edc 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -20,7 +20,20 @@ FREEOBJS=\ assert/__assert.o \ aux/c++.o \ aux/op-new.o \ -ctype/ctype.o \ +ctype/isalnum.o \ +ctype/isalpha.o \ +ctype/isblank.o \ +ctype/iscntrl.o \ +ctype/isdigit.o \ +ctype/isgraph.o \ +ctype/islower.o \ +ctype/isprint.o \ +ctype/ispunct.o \ +ctype/isspace.o \ +ctype/isupper.o \ +ctype/isxdigit.o \ +ctype/tolower.o \ +ctype/toupper.o \ dirent/alphasort.o \ dirent/closedir.o \ dirent/dclearerr.o \ diff --git a/libc/ctype/ctype.cpp b/libc/ctype/ctype.cpp deleted file mode 100644 index 5e27218d..00000000 --- a/libc/ctype/ctype.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2011. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library 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 Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - ctype/ctype.cpp - Character types. - -*******************************************************************************/ - -#include - -// TODO: Support other locales than ASCII. - -extern "C" int isalnum(int c) -{ - return isalpha(c) || isdigit(c); -} - -extern "C" int isalpha(int c) -{ - return isupper(c) || islower(c); -} - -extern "C" int isblank(int c) -{ - return c == ' ' || c == '\t'; -} - -extern "C" int iscntrl(int c) -{ - return 0 <= c && c < 32; -} - -extern "C" int isdigit(int c) -{ - return '0' <= c && c <= '9'; -} - -extern "C" int isgraph(int c) -{ - return '!' <= c && c <= '~'; -} - -extern "C" int islower(int c) -{ - return 'a' <= c && c <= 'z'; -} - -extern "C" int isprint(int c) -{ - return isgraph(c) || c == ' '; -} - -extern "C" int ispunct(int c) -{ - return isprint(c) && c != ' ' && !isalnum(c); -} - -extern "C" int isspace(int c) -{ - return c == '\t' || c == '\n' || c == '\v' || - c == '\f' || c == '\r' || c == ' '; -} - -extern "C" int isupper(int c) -{ - return 'A' <= c && c <= 'Z'; -} - -extern "C" int isxdigit(int c) -{ - if ( isdigit(c) ) - return 1; - if ( 'a' <= c && c <= 'f' ) return 1; - if ( 'A' <= c && c <= 'F' ) return 1; - return 0; -} - -extern "C" int tolower(int c) -{ - if ( 'A' <= c && c <= 'Z' ) - return 'a' + c - 'A'; - return c; -} - -extern "C" int toupper(int c) -{ - if ( 'a' <= c && c <= 'z' ) - return 'A' + c - 'a'; - return c; -} diff --git a/libc/ctype/isalnum.cpp b/libc/ctype/isalnum.cpp new file mode 100644 index 00000000..e65638ca --- /dev/null +++ b/libc/ctype/isalnum.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isalnum.cpp + Returns whether the character is a letter or a digit. + +*******************************************************************************/ + +#include + +extern "C" int isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} diff --git a/libc/ctype/isalpha.cpp b/libc/ctype/isalpha.cpp new file mode 100644 index 00000000..76541567 --- /dev/null +++ b/libc/ctype/isalpha.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isalpha.cpp + Returns whether the character is a letter. + +*******************************************************************************/ + +#include + +extern "C" int isalpha(int c) +{ + return isupper(c) || islower(c); +} diff --git a/libc/ctype/isblank.cpp b/libc/ctype/isblank.cpp new file mode 100644 index 00000000..7693d5d4 --- /dev/null +++ b/libc/ctype/isblank.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isblank.cpp + Returns whether the character is blank. + +*******************************************************************************/ + +#include + +extern "C" int isblank(int c) +{ + return c == ' ' || c == '\t'; +} diff --git a/libc/ctype/iscntrl.cpp b/libc/ctype/iscntrl.cpp new file mode 100644 index 00000000..e4f0455b --- /dev/null +++ b/libc/ctype/iscntrl.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/iscntrl.cpp + Returns whether the character is a control character. + +*******************************************************************************/ + +#include + +extern "C" int iscntrl(int c) +{ + return 0 <= c && c < 32; +} diff --git a/libc/ctype/isdigit.cpp b/libc/ctype/isdigit.cpp new file mode 100644 index 00000000..868ac997 --- /dev/null +++ b/libc/ctype/isdigit.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isdigit.cpp + Returns whether the character is a digit. + +*******************************************************************************/ + +#include + +extern "C" int isdigit(int c) +{ + return '0' <= c && c <= '9'; +} diff --git a/libc/ctype/isgraph.cpp b/libc/ctype/isgraph.cpp new file mode 100644 index 00000000..7c329896 --- /dev/null +++ b/libc/ctype/isgraph.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isgraph.cpp + Returns whether the character is graphical. + +*******************************************************************************/ + +#include + +extern "C" int isgraph(int c) +{ + return '!' <= c && c <= '~'; +} diff --git a/libc/ctype/islower.cpp b/libc/ctype/islower.cpp new file mode 100644 index 00000000..ba437443 --- /dev/null +++ b/libc/ctype/islower.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/islower.cpp + Returns whether the character is lower-case. + +*******************************************************************************/ + +#include + +extern "C" int islower(int c) +{ + return 'a' <= c && c <= 'z'; +} diff --git a/libc/ctype/isprint.cpp b/libc/ctype/isprint.cpp new file mode 100644 index 00000000..dbdccc76 --- /dev/null +++ b/libc/ctype/isprint.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isprint.cpp + Returns whether the character is printable. + +*******************************************************************************/ + +#include + +extern "C" int isprint(int c) +{ + return isgraph(c) || c == ' '; +} diff --git a/libc/ctype/ispunct.cpp b/libc/ctype/ispunct.cpp new file mode 100644 index 00000000..ae01456a --- /dev/null +++ b/libc/ctype/ispunct.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/ispunct.cpp + Returns whether the character is punctuational. + +*******************************************************************************/ + +#include + +extern "C" int ispunct(int c) +{ + return isprint(c) && c != ' ' && !isalnum(c); +} diff --git a/libc/ctype/isspace.cpp b/libc/ctype/isspace.cpp new file mode 100644 index 00000000..8601e74e --- /dev/null +++ b/libc/ctype/isspace.cpp @@ -0,0 +1,31 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isspace.cpp + Returns whether the character is white-space. + +*******************************************************************************/ + +#include + +extern "C" int isspace(int c) +{ + return c == '\t' || c == '\n' || c == '\v' || + c == '\f' || c == '\r' || c == ' '; +} diff --git a/libc/ctype/isupper.cpp b/libc/ctype/isupper.cpp new file mode 100644 index 00000000..cb384221 --- /dev/null +++ b/libc/ctype/isupper.cpp @@ -0,0 +1,30 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isupper.cpp + Returns whether the character is upper-case. + +*******************************************************************************/ + +#include + +extern "C" int isupper(int c) +{ + return 'A' <= c && c <= 'Z'; +} diff --git a/libc/ctype/isxdigit.cpp b/libc/ctype/isxdigit.cpp new file mode 100644 index 00000000..e5a042f9 --- /dev/null +++ b/libc/ctype/isxdigit.cpp @@ -0,0 +1,36 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/isxdigit.cpp + Returns whether the character is a hexadecimal digit. + +*******************************************************************************/ + +#include + +extern "C" int isxdigit(int c) +{ + if ( isdigit(c) ) + return 1; + if ( 'a' <= c && c <= 'f' ) + return 1; + if ( 'A' <= c && c <= 'F' ) + return 1; + return 0; +} diff --git a/libc/ctype/tolower.cpp b/libc/ctype/tolower.cpp new file mode 100644 index 00000000..114602db --- /dev/null +++ b/libc/ctype/tolower.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/tolower.cpp + Converts the character to lower-case if it is upper-case. + +*******************************************************************************/ + +#include + +extern "C" int tolower(int c) +{ + if ( 'A' <= c && c <= 'Z' ) + return 'a' + c - 'A'; + return c; +} diff --git a/libc/ctype/toupper.cpp b/libc/ctype/toupper.cpp new file mode 100644 index 00000000..49851877 --- /dev/null +++ b/libc/ctype/toupper.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + ctype/toupper.cpp + Converts the character to upper-case if it is lower-case. + +*******************************************************************************/ + +#include + +extern "C" int toupper(int c) +{ + if ( 'a' <= c && c <= 'z' ) + return 'A' + c - 'a'; + return c; +}