diff options
-rw-r--r-- | COPYING.3BSD | 30 | ||||
-rw-r--r-- | COPYING.FBDL | 33 | ||||
-rw-r--r-- | COPYING.GPLv3 | 4 | ||||
-rw-r--r-- | Makefile | 78 | ||||
-rw-r--r-- | README.md | 176 | ||||
-rw-r--r-- | arch/.SRCINFO | 16 | ||||
-rw-r--r-- | arch/PKGBUILD | 36 | ||||
-rw-r--r-- | box-templates/box_1-23.c | 23 | ||||
-rw-r--r-- | box-templates/box_45-49.c | 7 | ||||
-rw-r--r-- | box-templates/box_70-73.c | 6 | ||||
-rw-r--r-- | box-templates/box_94-96.c | 9 | ||||
-rw-r--r-- | box.c | 118 | ||||
-rw-r--r-- | config.mk | 63 | ||||
-rw-r--r-- | core/Makefile | 228 | ||||
l--------- | core/[.c | 1 | ||||
-rw-r--r-- | core/basename.c | 81 | ||||
-rw-r--r-- | core/cat.c | 95 | ||||
-rw-r--r-- | core/chmod.c | 124 | ||||
-rw-r--r-- | core/chown.c | 72 | ||||
-rw-r--r-- | core/date.c | 60 | ||||
-rw-r--r-- | core/dirname.c | 62 | ||||
-rw-r--r-- | core/echo.c | 42 | ||||
-rw-r--r-- | core/ed.c | 164 | ||||
-rw-r--r-- | core/false.c | 31 | ||||
-rw-r--r-- | core/head.c | 92 | ||||
-rw-r--r-- | core/link.c | 59 | ||||
-rw-r--r-- | core/ln.c | 89 | ||||
-rw-r--r-- | core/ls.c | 270 | ||||
-rw-r--r-- | core/mkdir.c | 77 | ||||
-rw-r--r-- | core/more.c | 121 | ||||
-rw-r--r-- | core/mv.c | 83 | ||||
-rw-r--r-- | core/printf.c | 55 | ||||
-rw-r--r-- | core/rm.c | 74 | ||||
-rw-r--r-- | core/sleep.c | 63 | ||||
-rw-r--r-- | core/tail.c | 98 | ||||
-rw-r--r-- | core/test.c | 128 | ||||
-rw-r--r-- | core/true.c | 31 | ||||
-rw-r--r-- | core/uname.c | 90 | ||||
-rw-r--r-- | core/unlink.c | 57 | ||||
-rw-r--r-- | core/vi.c | 242 | ||||
-rw-r--r-- | docs/CODING_STYLE.md | 126 | ||||
-rw-r--r-- | docs/COMPILE.md | 61 | ||||
-rw-r--r-- | docs/FAQ.md | 40 | ||||
-rw-r--r-- | docs/FasesDonationsQR.png | bin | 7547 -> 0 bytes | |||
-rw-r--r-- | docs/MIRRORS.md | 20 | ||||
-rw-r--r-- | docs/STATUS.md | 38 | ||||
-rw-r--r-- | docs/ServerDonationsQR.png | bin | 7547 -> 0 bytes | |||
-rw-r--r-- | docs/TODO.md | 51 | ||||
-rw-r--r-- | extras/Makefile | 51 | ||||
-rw-r--r-- | extras/errno.c | 284 | ||||
-rw-r--r-- | extras/yes.c | 37 | ||||
-rw-r--r-- | man/basename.1 | 32 | ||||
-rw-r--r-- | man/cat.1 | 46 | ||||
-rw-r--r-- | man/dirname.1 | 29 | ||||
-rw-r--r-- | man/echo.1 | 32 | ||||
-rw-r--r-- | man/false.1 | 24 | ||||
-rw-r--r-- | man/sleep.1 | 35 | ||||
-rw-r--r-- | man/true.1 | 24 | ||||
-rw-r--r-- | man/uname.1 | 59 | ||||
-rw-r--r-- | sh/Makefile | 54 | ||||
-rw-r--r-- | sh/commands.c | 50 | ||||
-rw-r--r-- | sh/commands.h | 34 | ||||
-rw-r--r-- | sh/parser.c | 114 | ||||
-rw-r--r-- | sh/parser.h | 35 | ||||
-rw-r--r-- | sh/sh.c | 158 |
65 files changed, 74 insertions, 4548 deletions
diff --git a/COPYING.3BSD b/COPYING.3BSD deleted file mode 100644 index c94d96d..0000000 --- a/COPYING.3BSD +++ /dev/null @@ -1,30 +0,0 @@ -# This license applies to all POSIX utilities fases provides, -# unless stated otherwise. This includes fases sh and fases core -# (core/). - -Copyright (C) 2022 Ferass EL HAFIDI -Copyright (C) 2022 Leah Rowe - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/COPYING.FBDL b/COPYING.FBDL deleted file mode 100644 index 556217b..0000000 --- a/COPYING.FBDL +++ /dev/null @@ -1,33 +0,0 @@ -# This license applies to all documentation, including manpages, unless -# stated otherwise. It is a FreeBSD Documentation-like license, modified -# to replace all occurences of FreeBSD. - -The fases documentation license - -Copyright (C) 2022 Ferass EL HAFIDI - -Redistribution and use in source (Markdown/ROFF) and 'compiled' forms -(HTML, PDF, EPUB and so forth) with or without modification, are -permitted provided that the following conditions are met: - - Redistributions of source code (Markdown/ROFF) must retain the above - copyright notice, this list of conditions and the following - disclaimer as the first lines of this file unmodified. - - Redistributions in compiled form (Converted to PDF, EPUB and other - formats) must reproduce the above copyright notice, this list of - conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS DOCUMENTATION IS PROVIDED BY THE FASES DOCUMENTATION PROJECT -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FASES -DOCUMENTATION PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -DAMAGE diff --git a/COPYING.GPLv3 b/COPYING.GPLv3 index 1927cce..c3401e0 100644 --- a/COPYING.GPLv3 +++ b/COPYING.GPLv3 @@ -1,6 +1,4 @@ -# This license applies to all non-POSIX utilities fases provides, -# unless stated otherwise. This includes fases box and fases extra -# (extra/). +# This license applies to everything in this repository. GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 diff --git a/Makefile b/Makefile deleted file mode 100644 index c675d1b..0000000 --- a/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -# -# Copyright (C) 2022 Ferass EL HAFIDI -# Copyright (C) 2022 Leah Rowe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# - -include ./config.mk - -# Commands -# ======== - -all: clean box - -genbox: - echo "#ifndef VERSION_H" > version.h - echo "#define VERSION_H" >> version.h - echo "#define COMPILETIME \"$$(git show --no-patch --pretty=format:%H)\"" >> version.h - echo >> version.h - echo "#endif" >> version.h - cat "box-templates/box_1-23.c" > box.c - for u in ${CORE}; do echo "int $${u%.c}_main(int, char**);" | sed "s/\[_/test_/g"; done>> box.c - test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo "int $${u%.c}_main(int, char**);"; done>> box.c - cat "box-templates/box_45-49.c" >> box.c - for u in ${CORE}; do echo " else if(!strcmp(basename(argv[0]), \"$${u%.c}\")) return $${u%.c}_main(argc, argv);" | sed "s/\[_/test_/g"; done >> box.c - test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " else if(!strcmp(argv[0], \"$${u%.c}\")) return $${u%.c}_main(argc, argv);"; done >> box.c - cat "box-templates/box_70-73.c" >> box.c - for u in ${CORE}; do echo " printf(\"$${u%.c} \");"; done >> box.c - test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " printf(\"$${u%.c} \");"; done >> box.c - cat "box-templates/box_94-96.c" >> box.c - echo "/* Generated on $$(date) */" >> box.c - -prepbox: - mkdir -p box_tmp - for f in ${CORE}; do sed "s/^int main(/int $$(echo "$$f")_main(/" < "core/"$$f".c" | sed "s/printUsage()/$$(echo "$$f")_printUsage()/g" | sed "s/\[_/test_/g" > "box_tmp/"$$f"_box.c"; done - rm -f "box_tmp/[_box.c" - test ${INCLUDE_EXTRA} == n || for f in ${EXTRA}; do sed "s/^int main(/int $$(echo "$$f")_main(/" < "extras/"$$f".c" | sed "s/printUsage()/$$(echo "$$f")_printUsage()/g" > "box_tmp/"$$f"_box.c"; done - -box: box.o - $(CC) $(CFLAGS) box_tmp/*.c box.o -o box - rm -f version.h - -clean: - rm -f box *.o extras-bin core-bin - rm -Rf box_tmp */bin/* - -install: - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -r core/bin/* $(DESTDIR)$(PREFIX)/bin - -install-box: - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -r box $(DESTDIR)$(PREFIX)/bin - -links: - for u in ${CORE}; do ln -s "$(DESTDIR)$(PREFIX)/bin/box" "$(DESTDIR)$(PREFIX)/bin/$$u"; done - -remove: - rm -f $(DESTDIR)$(PREFIX)/bin/box - for u in ${CORE}; do rm -f "$(DESTDIR)$(PREFIX)/bin/$$u"; done - - -# Utilities -# ========= - -box.o: prepbox - $(CC) $(CFLAGS) $(NOLINKER) box.c -o box.o @@ -1,167 +1,33 @@ -# fases - Ferass' Base System +Packages for popular OSes using the Linux kernel. -*Simple coreutils for a fully functionnal UNIX-like system* +| Distribution | Packaging format | Status | +|------------------|--------------------------|--------| +| Arch Linux | pacman[2] | Done | +| Alpine Linux | Alpine Package Keeper[1] | To do | +| Debian GNU/Linux | APT[3] | To do | -***Project Documentation*** +***(!) This branch does not include packages. It instead includes the tools +required to make them. (!)*** -(!) Please note that documentation is incomplete and can be very outdated (!) +***(!) The final packages only install fases box. If you want separate +binaries you'll have to compile them yourself. (!)*** -- [Compile fases](docs/COMPILE.md) +## Building packages -- [Mirrors](docs/MIRRORS.md) +Please refer to the official documentation of the packaging format you're +using for better documentation. -- [Status](docs/STATUS.md) +### Arch Linux -- [Coding Style](docs/CODING_STYLE.md) - -- [Incomplete TODO list](docs/TODO.md) - -- [FAQ](docs/FAQ.md) - -## Goal - -The `fases` project tries to provide friendly, functionnal and simple core -utilities for a fully functionnal UNIX-like Operating System. It tries to -be entirely portable and working on any UNIX-like Operating System and kernel -such as OpenBSD and Linux. It also tries to be completly modular and as such -one utility should **not** depend on another in order to work. The coreutils -are still a work-in-progress. -The `fases` utilities are currently tested on Artix, Alpine, OpenBSD, OS X and -FreeBSD. We expect all utilities to work on all systems implementing POSIX -due to us using only POSIX-compliant functions. - -## Directory structure +Building a package on Arch Linux and Arch-based OSes is simple. Just run +`makepkg`. ``` -fases.git - ├── box.c - ├── box-templates - │ ├── box_1-23.c - │ ├── box_45-49.c - │ ├── box_70-73.c - │ └── box_94-96.c - ├── config.mk - ├── COPYING.3BSD - ├── COPYING.FBDL - ├── COPYING.GPLv3 - ├── core - │ └── <core utilities> - ├── docs - │ └── <documentation> - ├── extras - │ └── <extra utilities> - ├── Makefile - ├── man - │ └── <manpages> - └── README.md +$ makepkg ``` -## Licensing - -The `fases` project is licensed under 3 separate licenses: - -- POSIX core utilities are licensed under the permissive 3-clause BSD license ; - -- The documentation, including manpages, are licensed under the FreeBSD -documentation license ; - -- Non-POSIX utilities such as box and extras are licensed under the copyleft -GPLv3 license. The `fases` box binary is also licensed under the GPLv3. - -## Chat - -The `fases` project has 2 IRC channels hosted on 2 IRC Networks: - -- `#fases` on `LibreIRC` ([webchat](https://kiwi.andrewyu.org/#fases)): - -server: `irc.andrewyu.org` ; - -ssl: `6697` (recommended) ; - -plain: `6667`. - -- `#fases` on `Libera.Chat` ([webchat](https://web.libera.chat/#fases)): - -server: `irc.libera.chat` ; - -ssl: `6697` (recommended) ; - -plain: `6667`. - -Both of these channels are linked so all messages sent in one of them -is sent on the other Network. - -## Mailing Lists - -(!) The ***fases -at- andrewyu -dot- org*** mailing list is going to be -deprecated soon in favor of the new -***fases-general -at- andrewyu -dot- org*** which includes a new UI and -a mail archive that isn't provided by a third-party. Please use that -mailing list instead. (!) - -The `fases` project also has a mailing list ran by Andrew Yu (thanks!). - -The mailing list's address is: -***fases-general -at- andrewyu -dot- org*** -( -[subscribe](https://mail.andrewyu.org/mailman/listinfo/fases-general)). - -To send patches, please use `git-send-email`. A tutorial on how to use -it can be found [here](https://git-send-email.io/). - -## Donations - -Donations really help this project, no matter how small. People that work -on this project are unpaid volunteers that do it on their freetime. -We currently only accept XMR/Monero. You can use these addresses for -donating. - -Project Donations: -` -83bXvP25H5SX3kfTXMcjdm816KFUapPdN2eUV1gAF3JTNcoqNtG5ZxvfRUF81bZMMWXcX5kES1h1jCJCNyYZmrHGVeQBGNK -` - -![](docs/FasesDonationsQR.png) - -The server hosting the project also costs money. To keep the server up and -running, you can donate to this address: - -Server Donations: -` -85q7XiHDpjYVq3cQ3uBSMN9JchP4mgpBGRc6SY9G6vyjF22QAugJxYAabLt9bQDvj3DcqkDjQKmduCNPVbzq7xVdTLmu2LF -` - -![](docs/ServerDonationsQR.png) - -You can also donate to other contributors separately. Thanks! - -## Thank you! - -I would like to thank a few people there, mainly: - -- Andrew Yu, for making a mirror on their git server at git.andrewyu.org, and -linking the ##fases libera.chat channel to LibreIRC, for testing fases on -OpenBSD and for hosting the mailing list. - -- Leah Rowe, for adding lots of improvements on her -[git repo](https://notabug.org/vimuser/fases) and for testing fases on OpenBSD. -[Donate](https://www.patreon.com/libreleah). - -- Ron Nazarov, for fixing a weird bug in `yes` and adding useful features in -it. - -- Other people I forgot to add there. If I forgot to add you there, do send -a patch or just tell me :D. - -Contributions are very welcome, even if you're not a programmer. You can help -this project by: - -- Testing utilities and reporting bugs ; - -- Talking about fases ; - -- Donating XMR/Monero ; - -- Giving me recommendations. +You can also run it with the `-i` argument to then install the package. -Help is greatly appreciated, thanks! +[1]: https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper +[2]: https://archlinux.org/pacman/ +[3]: https://www.debian.org/doc/manuals/debian-handbook/sect.apt-get.en.html diff --git a/arch/.SRCINFO b/arch/.SRCINFO new file mode 100644 index 0000000..fe3088e --- /dev/null +++ b/arch/.SRCINFO @@ -0,0 +1,16 @@ +pkgbase = fasesbox-git + pkgdesc = Simple utilities for a fully functionnal UNIX-like system. + pkgver = r247.25f1754 + pkgrel = 1 + url = https://git.vitali64.duckdns.org/utils/fases.git + arch = any + license = GPL3, + license = custom:3BSD, + license = custom:FreeBSDDocumentationLicense + makedepends = git + provides = fasesbox-git + conflicts = fasesbox-git + source = /fases::git+https://git.vitali64.duckdns.org/git/utils/fases.git + md5sums = SKIP + +pkgname = fasesbox-git diff --git a/arch/PKGBUILD b/arch/PKGBUILD new file mode 100644 index 0000000..9871717 --- /dev/null +++ b/arch/PKGBUILD @@ -0,0 +1,36 @@ +# fases Arch Linux packages +# Maintainer: Ferass EL HAFIDI <vitali64pmemail@protonmail.com> +pkgname=fasesbox-git # '-bzr', '-git', '-hg' or '-svn' +pkgver=r247.25f1754 +pkgrel=1 +pkgdesc="Simple utilities for a fully functionnal UNIX-like system." +arch=('any') +url="https://git.vitali64.duckdns.org/utils/fases.git" +license=('GPL3', 'custom:3BSD', 'custom:FreeBSDDocumentationLicense') +groups=() +depends=() +makedepends=('git') # 'bzr', 'git', 'mercurial' or 'subversion' +provides=("${pkgname%-VCS}") +conflicts=("${pkgname%-VCS}") +replaces=() +backup=() +options=() +install= +source=("$srcdir/${pkgname%box-git}"::'git+https://git.vitali64.duckdns.org/git/utils/fases.git') +noextract=() +md5sums=('SKIP') + +pkgver() { + cd "$srcdir/${pkgname%box-git}" + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +build() { + cd "$srcdir/${pkgname%box-git}" + make prepbox genbox box +} + +package() { + cd "$srcdir/${pkgname%box-git}" + make DESTDIR="$pkgdir/" install-box +} diff --git a/box-templates/box_1-23.c b/box-templates/box_1-23.c deleted file mode 100644 index eccb4fb..0000000 --- a/box-templates/box_1-23.c +++ /dev/null @@ -1,23 +0,0 @@ -/* fasesiab - Ferass' Base System in a box - * Copyright (C) 2022 Ferass EL HAFIDI - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ -/* START */ - -#include <string.h> -#include <unistd.h> -#include <libgen.h> -#include <stdio.h> -/* END */ diff --git a/box-templates/box_45-49.c b/box-templates/box_45-49.c deleted file mode 100644 index 42bd0e4..0000000 --- a/box-templates/box_45-49.c +++ /dev/null @@ -1,7 +0,0 @@ -/* START */ -int main(int argc, char *argv[]) { - if (!strcmp(basename(argv[0]),"box") && argc > 1) { - argc--; - argv++; - } if(0); -/* END */ diff --git a/box-templates/box_70-73.c b/box-templates/box_70-73.c deleted file mode 100644 index 0f48b18..0000000 --- a/box-templates/box_70-73.c +++ /dev/null @@ -1,6 +0,0 @@ -/* START */ - else if (!strcmp(basename(argv[0]), "box") && argc == 1) { - printf("Ferass' Base System in a box\n\n"); - printf("Usage: box <COMMAND> [ARGS]\n\n"); - printf("Commands available:\n"); -/* END */ diff --git a/box-templates/box_94-96.c b/box-templates/box_94-96.c deleted file mode 100644 index ac381af..0000000 --- a/box-templates/box_94-96.c +++ /dev/null @@ -1,9 +0,0 @@ -/* START */ - printf("\n"); - } - else { - printf("box: %s: Not found or not implemented.\n", argv[0]); - } - return 0; -} -/* END */ @@ -1,118 +0,0 @@ -/* fasesiab - Ferass' Base System in a box - * Copyright (C) 2022 Ferass EL HAFIDI - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ -/* START */ - -#include <string.h> -#include <unistd.h> -#include <libgen.h> -#include <stdio.h> -/* END */ -int test_main(int, char**); -int basename_main(int, char**); -int cat_main(int, char**); -int chmod_main(int, char**); -int chown_main(int, char**); -int date_main(int, char**); -int dirname_main(int, char**); -int echo_main(int, char**); -int false_main(int, char**); -int head_main(int, char**); -int link_main(int, char**); -int ln_main(int, char**); -int ls_main(int, char**); -int mkdir_main(int, char**); -int more_main(int, char**); -int mv_main(int, char**); -int printf_main(int, char**); -int rm_main(int, char**); -int sleep_main(int, char**); -int tail_main(int, char**); -int test_main(int, char**); -int true_main(int, char**); -int uname_main(int, char**); -int unlink_main(int, char**); -/* START */ -int main(int argc, char *argv[]) { - if (!strcmp(basename(argv[0]),"box") && argc > 1) { - argc--; - argv++; - } if(0); -/* END */ - else if(!strcmp(basename(argv[0]), "[")) return test_main(argc, argv); - else if(!strcmp(basename(argv[0]), "basename")) return basename_main(argc, argv); - else if(!strcmp(basename(argv[0]), "cat")) return cat_main(argc, argv); - else if(!strcmp(basename(argv[0]), "chmod")) return chmod_main(argc, argv); - else if(!strcmp(basename(argv[0]), "chown")) return chown_main(argc, argv); - else if(!strcmp(basename(argv[0]), "date")) return date_main(argc, argv); - else if(!strcmp(basename(argv[0]), "dirname")) return dirname_main(argc, argv); - else if(!strcmp(basename(argv[0]), "echo")) return echo_main(argc, argv); - else if(!strcmp(basename(argv[0]), "false")) return false_main(argc, argv); - else if(!strcmp(basename(argv[0]), "head")) return head_main(argc, argv); - else if(!strcmp(basename(argv[0]), "link")) return link_main(argc, argv); - else if(!strcmp(basename(argv[0]), "ln")) return ln_main(argc, argv); - else if(!strcmp(basename(argv[0]), "ls")) return ls_main(argc, argv); - else if(!strcmp(basename(argv[0]), "mkdir")) return mkdir_main(argc, argv); - else if(!strcmp(basename(argv[0]), "more")) return more_main(argc, argv); - else if(!strcmp(basename(argv[0]), "mv")) return mv_main(argc, argv); - else if(!strcmp(basename(argv[0]), "printf")) return printf_main(argc, argv); - else if(!strcmp(basename(argv[0]), "rm")) return rm_main(argc, argv); - else if(!strcmp(basename(argv[0]), "sleep")) return sleep_main(argc, argv); - else if(!strcmp(basename(argv[0]), "tail")) return tail_main(argc, argv); - else if(!strcmp(basename(argv[0]), "test")) return test_main(argc, argv); - else if(!strcmp(basename(argv[0]), "true")) return true_main(argc, argv); - else if(!strcmp(basename(argv[0]), "uname")) return uname_main(argc, argv); - else if(!strcmp(basename(argv[0]), "unlink")) return unlink_main(argc, argv); -/* START */ - else if (!strcmp(basename(argv[0]), "box") && argc == 1) { - printf("Ferass' Base System in a box\n\n"); - printf("Usage: box <COMMAND> [ARGS]\n\n"); - printf("Commands available:\n"); -/* END */ - printf("[ "); - printf("basename "); - printf("cat "); - printf("chmod "); - printf("chown "); - printf("date "); - printf("dirname "); - printf("echo "); - printf("false "); - printf("head "); - printf("link "); - printf("ln "); - printf("ls "); - printf("mkdir "); - printf("more "); - printf("mv "); - printf("printf "); - printf("rm "); - printf("sleep "); - printf("tail "); - printf("test "); - printf("true "); - printf("uname "); - printf("unlink "); -/* START */ - printf("\n"); - } - else { - printf("box: %s: Not found or not implemented.\n", argv[0]); - } - return 0; -} -/* END */ -/* Generated on Sun 23 Oct 19:30:23 CEST 2022 */ diff --git a/config.mk b/config.mk deleted file mode 100644 index 9fb52f8..0000000 --- a/config.mk +++ /dev/null @@ -1,63 +0,0 @@ -# -# Copyright (C) 2022 Ferass EL HAFIDI -# Copyright (C) 2022 Leah Rowe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# - -# Configuration -# ============= - -CC=cc # C Compiler -FORCEC99=-std=c99 # Force POSIX C99 -# OPTIMIZE=-O3 # Experimental optimizations (Disabled by default) -CFLAGS=-D_POSIX_C_SOURCE=200809L -I. -Wall -Wextra -g $(FORCEC99) $(OPTIMIZE) # C Compiler flags -NOLINKER=-c # C Compiler flag to disable the linker -# Core utilities -CORE=\ - [\ - basename\ - cat\ - chmod\ - chown\ - date\ - dirname\ - echo\ - false\ - head\ - link\ - ln\ - ls\ - mkdir\ - more\ - mv\ - printf\ - rm\ - sleep\ - tail\ - test\ - true\ - uname\ - unlink - -INCLUDE_EXTRA=n # Should extra utils be included inside fasesiab? -# Extra utilities -EXTRA=\ - errno\ - yes - -# Destination directory -DESTDIR= -PREFIX=/usr/local -# Prefix diff --git a/core/Makefile b/core/Makefile deleted file mode 100644 index 4207ea3..0000000 --- a/core/Makefile +++ /dev/null @@ -1,228 +0,0 @@ -# -# Copyright (C) 2022 Ferass EL HAFIDI -# Copyright (C) 2022 Leah Rowe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# - -include ../config.mk - -# Commands -# ======== - -all: clean $(CORE) - -ver: - echo "#ifndef VERSION_H" > version.h - echo "#define VERSION_H" >> version.h - echo "#define COMPILETIME \"$$(git show --no-patch --pretty=format:%H)\"" >> version.h - echo >> version.h - echo "#endif" >> version.h - -head: head.o - mkdir -p bin - $(CC) $(CFLAGS) head.o -o bin/head - -cat: cat.o - mkdir -p bin - $(CC) $(CFLAGS) cat.o -o bin/cat - -ls: ls.o - mkdir -p bin - $(CC) $(CFLAGS) ls.o -o bin/ls - -date: date.o - mkdir -p bin - $(CC) $(CFLAGS) date.o -o bin/date - -yes: yes.o - mkdir -p bin - $(CC) $(CFLAGS) yes.o -o bin/yes - -mkdir: mkdir.o - mkdir -p bin - $(CC) $(CFLAGS) mkdir.o -o bin/mkdir - -echo: echo.o - mkdir -p bin - $(CC) $(CFLAGS) echo.o -o bin/echo - -true: true.o - mkdir -p bin - $(CC) $(CFLAGS) true.o -o bin/true - -false: false.o - mkdir -p bin - $(CC) $(CFLAGS) false.o -o bin/false - -sleep: sleep.o - mkdir -p bin - $(CC) $(CFLAGS) sleep.o -o bin/sleep - -printf: printf.o - mkdir -p bin - $(CC) $(CFLAGS) printf.o -o bin/printf - -uname: uname.o - mkdir -p bin - $(CC) $(CFLAGS) uname.o -o bin/uname - -link: link.o - mkdir -p bin - $(CC) $(CFLAGS) link.o -o bin/link - -ln: ln.o - mkdir -p bin - $(CC) $(CFLAGS) ln.o -o bin/ln - -chmod: chmod.o - mkdir -p bin - $(CC) $(CFLAGS) chmod.o -o bin/chmod - -basename: basename.o - mkdir -p bin - $(CC) $(CFLAGS) basename.o -o bin/basename - -unlink: unlink.o - mkdir -p bin - $(CC) $(CFLAGS) unlink.o -o bin/unlink - -mv: mv.o - mkdir -p bin - $(CC) $(CFLAGS) mv.o -o bin/mv - -rm: rm.o - mkdir -p bin - $(CC) $(CFLAGS) rm.o -o bin/rm - -more: more.o - mkdir -p bin - $(CC) $(CFLAGS) more.o -o bin/more - -chown: chown.o - mkdir -p bin - $(CC) $(CFLAGS) chown.o -o bin/chown - -tail: tail.o - mkdir -p bin - $(CC) $(CFLAGS) tail.o -o bin/tail - -[: test.o - mkdir -p bin - $(CC) $(CFLAGS) test.o -o bin/\[ - -test: test.o - mkdir -p bin - $(CC) $(CFLAGS) test.o -o bin/test - -ed: ed.o - mkdir -p bin - $(CC) $(CFLAGS) ed.o -o bin/ed - -dirname: dirname.o - mkdir -p bin - $(CC) $(CFLAGS) dirname.o -o bin/dirname - -vi: vi.o - mkdir -p bin - $(CC) $(CFLAGS) vi.o -o bin/vi - -ex: vi.o - mkdir -p bin - $(CC) $(CFLAGS) vi.o -o bin/ex - -clean: - rm -f *.o version.h - rm -Rf bin - -# Utilities -# ========= - -head.o: ver - $(CC) $(CFLAGS) $(NOLINKER) head.c -o head.o - -cat.o: ver - $(CC) $(CFLAGS) $(NOLINKER) cat.c -o cat.o - -ls.o: ver - $(CC) $(CFLAGS) $(NOLINKER) ls.c -o ls.o - -date.o: ver - $(CC) $(CFLAGS) $(NOLINKER) date.c -o date.o - -yes.o: ver - $(CC) $(CFLAGS) $(NOLINKER) yes.c -o yes.o - -mkdir.o: ver - $(CC) $(CFLAGS) $(NOLINKER) mkdir.c -o mkdir.o - -echo.o: ver - $(CC) $(CFLAGS) $(NOLINKER) echo.c -o echo.o - -true.o: ver - $(CC) $(CFLAGS) $(NOLINKER) true.c -o true.o - -false.o: ver - $(CC) $(CFLAGS) $(NOLINKER) false.c -o false.o - -sleep.o: ver - $(CC) $(CFLAGS) $(NOLINKER) sleep.c -o sleep.o - -printf.o: ver - $(CC) $(CFLAGS) $(NOLINKER) printf.c -o printf.o - -uname.o: ver - $(CC) $(CFLAGS) $(NOLINKER) uname.c -o uname.o - -link.o: ver - $(CC) $(CFLAGS) $(NOLINKER) link.c -o link.o - -ln.o: ver - $(CC) $(CFLAGS) $(NOLINKER) ln.c -o ln.o - -chmod.o: ver - $(CC) $(CFLAGS) $(NOLINKER) chmod.c -o chmod.o - -basename.o: ver - $(CC) $(CFLAGS) $(NOLINKER) basename.c -o basename.o - -unlink.o: ver - $(CC) $(CFLAGS) $(NOLINKER) unlink.c -o unlink.o - -mv.o: ver - $(CC) $(CFLAGS) $(NOLINKER) mv.c -o mv.o - -rm.o: ver - $(CC) $(CFLAGS) $(NOLINKER) rm.c -o rm.o - -more.o: ver - $(CC) $(CFLAGS) $(NOLINKER) more.c -o more.o - -chown.o: ver - $(CC) $(CFLAGS) $(NOLINKER) chown.c -o chown.o - -tail.o: ver - $(CC) $(CFLAGS) $(NOLINKER) tail.c -o tail.o - -test.o: ver - $(CC) $(CFLAGS) $(NOLINKER) test.c -o test.o - -ed.o: ver - $(CC) $(CFLAGS) $(NOLINKER) ed.c -o ed.o - -dirname.o: ver - $(CC) $(CFLAGS) $(NOLINKER) dirname.c -o dirname.o - -vi.o: ver - $(CC) $(CFLAGS) $(NOLINKER) vi.c -o vi.o diff --git a/core/[.c b/core/[.c deleted file mode 120000 index aeebb26..0000000 --- a/core/[.c +++ /dev/null @@ -1 +0,0 @@ -test.c
\ No newline at end of file diff --git a/core/basename.c b/core/basename.c deleted file mode 100644 index 6939a0c..0000000 --- a/core/basename.c +++ /dev/null @@ -1,81 +0,0 @@ -/* basename - return non-directory portion of STRING - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libgen.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *argv[]) { - int argument, status; - long unsigned int i; - char *basenamestr; - - if (argc < 2) { - printUsage(); - return 1; - } - basenamestr = basename(argv[1]); - if (argc == 3) { - for (i = 1; i <= strlen(argv[2]); ++i) { - if (argv[1][strlen(argv[1]) - i] == - argv[2][strlen(argv[2]) - i]) - /* Check */ - status = 0; - else status = 1; - } - - if (status == 0) { - for (i = 1; i <= strlen(argv[2]); ++i) { - if (argv[1][strlen(argv[1]) - i] == - argv[2][strlen(argv[2]) - i]) { - /* Replace with spaces for now ... */ - argv[1][strlen(argv[1]) - i] = ' '; - } // = '\0'; - } - } - } - - printf("%s\n", basenamestr); - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: basename string [suffix]\n\n" - "Return non-directory portion of <string>.\n\n", COMPILETIME); -} diff --git a/core/cat.c b/core/cat.c deleted file mode 100644 index ef0d5d8..0000000 --- a/core/cat.c +++ /dev/null @@ -1,95 +0,0 @@ -/* cat - concatenate a file to stdout - * Copyright (C) 2022 Ferass EL HAFIDI - * Copyright (C) 2022 Leah Rowe - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#define _POSIX_C_SOURCE 200809L -#include <fcntl.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int cat(int flides, int unbuffered); -void printUsage(); - -int main(int argc, char *const argv[]) { - int file, argument, i = 1, unbuffered; - - while ((argument = getopt(argc, argv, "u")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - else if (argument == 'u') - unbuffered = 1; - } - - - if (argc < 2) { - cat(STDIN_FILENO, unbuffered); - } - - for (i = 1; i != argc; i++) { - if (strcmp(argv[i], "-u")) { - if (strcmp(argv[i], "-")) file = open(argv[i], O_RDONLY); - else file = STDIN_FILENO; - if (file == -1) return errno; /* Something went wrong */ - cat(file, unbuffered); - close(file); - } - } - return 0; -} - -int cat(int fildes, int unbuffered) { - char s[4096]; - FILE *filstr; - size_t length; - if (unbuffered) while ((length = read(fildes, s, 4096)) > 0) - write(STDOUT_FILENO, s, length); - else { - filstr = fdopen(fildes, "r"); - while ((length = fread(s, 4096, 1, filstr)) > 0) - fwrite(s, length, 1, stdout); - } - if (errno) return errno; - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: cat [file]\n\n" - "Concatenate <file> to standard output.\n" - "When no file is specified or file is '-', read standard input\n\n" - "\t-u\tPrint unbuffered\n", COMPILETIME); -} diff --git a/core/chmod.c b/core/chmod.c deleted file mode 100644 index f0ca999..0000000 --- a/core/chmod.c +++ /dev/null @@ -1,124 +0,0 @@ -/* chmod - change file modes - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/stat.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 0; - mode_t modes, owner_modes, group_modes, other_modes; - if (argc == 1) { - printUsage(); - return 1; - } - while ((argument = getopt(argc, argv, "")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - } - /* I know there's a better way of doing it, please let me know if you - * know a better way of doing it - */ - if (argv[1][i] == '0') i++; - switch (argv[1][i]) { - /* Owner modes */ - case '7': - owner_modes = S_IRWXU; - break; - case '4': - owner_modes = S_IRUSR; - break; - case '2': - owner_modes = S_IWUSR; - break; - case '1': - owner_modes = S_IXUSR; - break; - default: - printUsage(); - return 1; - } - i++; - switch (argv[1][i]) { - /* Group modes */ - case '7': - group_modes = S_IRWXG; - break; - case '4': - group_modes = S_IRGRP; - break; - case '2': - group_modes = S_IWGRP; - break; - case '1': - group_modes = S_IXGRP; - break; - default: - printUsage(); - return 1; - } - i++; - switch (argv[1][i]) { - /* Other modes */ - case '7': - other_modes = S_IRWXO; - break; - case '4': - other_modes = S_IROTH; - break; - case '2': - other_modes = S_IWOTH; - break; - case '1': - other_modes = S_IXOTH; - break; - default: - printUsage(); - return 1; - } - - chmod(argv[2], owner_modes | group_modes | other_modes); - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: chmod mode file\n\n" - "Change file modes.\n\n", COMPILETIME); -} diff --git a/core/chown.c b/core/chown.c deleted file mode 100644 index 5acd1fd..0000000 --- a/core/chown.c +++ /dev/null @@ -1,72 +0,0 @@ -/* chown - change the file ownership - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <pwd.h> -#include <stdlib.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument; - struct passwd *user; - if (argc == 1) { - printUsage(); - return 1; - } - while ((argument = getopt(argc, argv, "")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - } - if ((user = getpwnam(argv[1])) == NULL && (user = getpwuid(strtol(argv[1], NULL, 10))) == NULL) - return errno; /* User doesn't exist */ - /* User found! */ - else if ((user = getpwnam(argv[1])) != NULL) - chown(argv[2], user->pw_uid, user->pw_gid); - else if ((user = getpwuid(strtol(argv[1], NULL, 10))) != NULL) - chown(argv[2], user->pw_uid, user->pw_gid); - if (errno) return errno; - - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: chown owner file\n\n" - "Change file ownership.\n\n", COMPILETIME); -} diff --git a/core/date.c b/core/date.c deleted file mode 100644 index 6c8af39..0000000 --- a/core/date.c +++ /dev/null @@ -1,60 +0,0 @@ -/* date - Show the date and time. - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <time.h> -#include <stdio.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -void printUsage(); - -int main(int argc, char *argv[]) { - time_t epoch = time(NULL); - struct tm* date = localtime(&epoch); - char date_s[31]; - const char *format; - if (argc == 2 && argv[1][0] == '+') { - argv[1]++; - format = argv[1]; - } - else { - format = "%a %b %e %H:%M:%S %Z %Y"; - } - strftime(date_s, 31, format, date); - printf("%s\n", date_s); - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: date [+format]\n\n" - "Output the date and time.\n\n", COMPILETIME); -} diff --git a/core/dirname.c b/core/dirname.c deleted file mode 100644 index e51f264..0000000 --- a/core/dirname.c +++ /dev/null @@ -1,62 +0,0 @@ -/* dirname - return directory portion of STRING - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libgen.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *argv[]) { - int argument, status; - long unsigned int i; - char *dirnamestr; - - if (argc != 2) { - printUsage(); - return 1; - } - dirnamestr = dirname(argv[1]); - - printf("%s\n", dirnamestr); - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: dirname string\n\n" - "Return directory portion of <string>.\n\n", COMPILETIME); -} diff --git a/core/echo.c b/core/echo.c deleted file mode 100644 index 919501a..0000000 --- a/core/echo.c +++ /dev/null @@ -1,42 +0,0 @@ -/* echo - write strings to stdout - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> - -int getopt(int argc, char *const argv[], const char *optstring); - -int main(int argc, char *const argv[]) { - int argument, i = 1; - - for (i = 1; i != argc; i++) { - printf("%s ", argv[i]); - } - printf("\n"); - return 0; -} diff --git a/core/ed.c b/core/ed.c deleted file mode 100644 index 7a2b37a..0000000 --- a/core/ed.c +++ /dev/null @@ -1,164 +0,0 @@ -/* ed - edit text - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <signal.h> -#include <string.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -void printUsage(); -void print_error(); -size_t c_append(char buffer[4096]); - -int main(int argc, char *argv[]) { - int argument, i = 0, fildes; - char buffer[4096], *edit_pathname, *prompt_string = "", - command_string[4096], *error = ""; - int help_mode = 0; - struct sigaction signal_action; - - while ((argument = getopt(argc, argv, "p:")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - else if (argument == 'p') - prompt_string = optarg; - } - argc -= optind; - argv += optind; - - signal_action.sa_handler = SIG_IGN; - sigemptyset(&signal_action.sa_mask); - sigaction(SIGINT, &signal_action, NULL); - - setvbuf(stdout, NULL, _IONBF, 0); - for (;;) { - write(STDOUT_FILENO, prompt_string, strlen(prompt_string)); - //if (fgets(command_string, 4096, stdin) == NULL) return errno; - if (read(STDIN_FILENO, command_string, 4096) == -1) return errno; - switch (command_string[i]) { /* Addresses */ - case '.': - case '$': - case '\'': - case '+': - case '-': - /* FALLTHROUGH */ - ++i; - print_error((error = "not implemented"), help_mode); - continue; - } - switch (command_string[i]) { /* Commands */ - case 'e': /* Edit Command */ - if (i < 0) { - print_error((error = "unexpected address"), help_mode); - continue; - } - if (strlen(command_string) > 2 && i == 0) { - edit_pathname = command_string + 2; - edit_pathname[strlen(edit_pathname) - 1] = '\0'; - } else if (!edit_pathname) { - print_error((error = "no pathname given"), help_mode); - continue; - } - fildes = open(edit_pathname, O_RDONLY | O_CREAT); - if (errno) return errno; - printf("%ld\n", read(fildes, buffer, 4096)); - if (fildes) close(fildes); - continue; - case 'a': - c_append(buffer); - continue; - case 'w': - if (strtok(command_string, " ") != NULL && strtok(NULL, " ") != NULL - && i == 0) { - edit_pathname = command_string + 2; - edit_pathname[strlen(edit_pathname) - 1] = '\0'; - fildes = open(edit_pathname, O_RDWR | O_CREAT); - } else if (edit_pathname) { - fildes = open(edit_pathname, O_RDWR); - } else { - if (i != 0) - print_error((error = "unexpected address"), help_mode); - else - print_error((error = "no pathname given"), help_mode); - continue; - } - if (errno) return errno; - printf("%ld\n", write(fildes, buffer, strlen(buffer))); - if (fildes) close(fildes); - continue; - case 'q': - if (fildes) close(fildes); - return 0; - case 'H': /* Help mode */ - if (i < 0) { - print_error((error = "unexpected address"), help_mode); - continue; - } - /* If help_mode was equal to 1, set it to 0 and vice-versa. */ - help_mode = !help_mode; - case 'h': /* Help Command */ - /* FALLTHROUGH */ - print_error(error, help_mode + 2); /* Print the last encountered error. */ - continue; - default: /* Invalid/Not implemented command */ - print_error((error = "invalid or not implemented"), help_mode); - } - } -} - -size_t c_append(char buffer[4096]) { - char *tempbuf = NULL; - size_t bufsize = 0, bytes_read = 0; - - while ((bytes_read += getline(&tempbuf, &bufsize, stdin)) > 0) { - if (!strcmp(tempbuf, ".\n")) break; - strcat(buffer, tempbuf); - } - return bytes_read; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: ed [-p prompt_string]\n\n" - "Edit text.\n\n" - "\t-p prompt_string\tAppend a prompt string.\n", COMPILETIME); -} - -void print_error(const char *error, int help_mode) { - if (help_mode <= 1) puts("?"); - if (help_mode) puts(error); -} diff --git a/core/false.c b/core/false.c deleted file mode 100644 index 10f020f..0000000 --- a/core/false.c +++ /dev/null @@ -1,31 +0,0 @@ -/* false - return false value - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -int main() { - return 1; -} diff --git a/core/head.c b/core/head.c deleted file mode 100644 index 236c74d..0000000 --- a/core/head.c +++ /dev/null @@ -1,92 +0,0 @@ -/* head - copy the first part of files - * Copyright (C) 2022 Ferass EL HAFIDI - * Copyright (C) 2022 Leah Rowe - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <fcntl.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -/* Functions Prototypes */ -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1, lines, lines_printed; - FILE *file; - - char s[4096]; - - while ((argument = getopt(argc, argv, "n:")) != -1) { - if (argument == '?' || argument == ':') { - printUsage(); - return 1; - } - else if (argument == 'n') { - lines = strtol(optarg, NULL, 10); - if (errno) return errno; - } - else - lines = 10; - } - if (argc < 2) { - while (read(STDIN_FILENO, s, 4096) > 0) - printf("%s", s); - } - if (!lines) lines = 10; - for (i = 1; i != argc; i++) { - if (strcmp(argv[i], "-n")) { - if (strcmp(argv[i], "-")) file = fopen(argv[i], "r"); - else while (read(STDIN_FILENO, s, 4096) > 0) printf("%s", s); - if (file == NULL) return errno; /* Something went wrong */ - for (lines_printed = 1; lines_printed <= lines; lines_printed++) { - if (fgets(s, 4096, file) != NULL) - printf("%s", s); - else if (errno) return errno; - } - fclose(file); - } - else i++; - } - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: head [-n number] [file]\n\n" - "Copy file to standard output until <number> lines.\n\n" - "\t-n number\tNumber of lines to be copied to standard output\n", - COMPILETIME); -} diff --git a/core/link.c b/core/link.c deleted file mode 100644 index b6fbff2..0000000 --- a/core/link.c +++ /dev/null @@ -1,59 +0,0 @@ -/* link - link 2 files using the link() function - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument; - - if (argc == 1) { - printUsage(); - return 1; - } - if (argc >= 2) { - link(argv[1], argv[2]); - if (errno) return errno; - } - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: link file1 file2\n\n" - "Link <file1> to <file2> using the link() function.\n\n", COMPILETIME); -} diff --git a/core/ln.c b/core/ln.c deleted file mode 100644 index 6852cf6..0000000 --- a/core/ln.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ln - link files - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument; - char param[256], *params = "s", *buffer; - - if (argc == 1) { - printUsage(); - return 1; - } - while ((argument = getopt(argc, argv, params)) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - param[argument] = argument; - } - - for (int i = 1; i < argc - 1; i++) { - if (argv[argc - 1][0] == '-') argc--; - if (argv[i][0] != '-') { - if (param['f']) remove(argv[argc - 1]); - if (param['s']) symlink(argv[i], argv[argc - 1]); - /* The -P option is the default behavior (at least on musl), - * so no if statement. - */ - else if (param['L']) { - readlink(argv[i], buffer, strlen(buffer)); /* Read the link */ - if (errno) return errno; - link(buffer, argv[argc - 1]); - } - else link(argv[i], argv[argc - 1]); - - if (errno) return errno; - } - } - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: ln [-fs] [-P|-L] source_file target_file\n\n" - "Link files.\n\n" - "\t-s\tCreate symbolic links instead of hard links\n" - "\t-f\tIf <target_file> exists, override the file\n" - "\t-P\tIf <source_file> names a symbolic link, create a hard link to the " - "symbolic link itself (default)\n" - "\t-L\tIf <source_file> names a symbolic link, create a hard link to the " - "file referenced by the symbolic link\n", COMPILETIME); -} diff --git a/core/ls.c b/core/ls.c deleted file mode 100644 index 11aa31e..0000000 --- a/core/ls.c +++ /dev/null @@ -1,270 +0,0 @@ -/* ls - list files and directories in the given path - * Copyright (C) 2022 Ferass EL HAFIDI - * Copyright (C) 2022 Leah Rowe - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <string.h> -#include <dirent.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <pwd.h> -#include <grp.h> -#include <time.h> -#include <sys/ioctl.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -char param[256]; -int getopt(int argc, char *const argv[], const char *optstring); -int ls(char *path); -void printUsage(char *params); - -int main(int argc, char *argv[]) { - int status = 0; - int success = 0; - int argument, i; - char* params = "aACR1imlpgno"; - - for(i=0; i<256; i++) { - param[i]=0; - } - - while ((argument = getopt(argc, argv, params)) != -1) { - if (argument == '?') { - printUsage(params); - return 1; - } - param[argument] = argument; - - if (argument=='C') { - param['1'] = 0; - param['m'] = 0; - } - else if (argument=='1' || argument=='g' || argument=='n') { - param['m'] = 0; - param['C'] = 0; - } - else if (argument=='m') { - param['1'] = 0; - param['C'] = 0; - } - if (argument=='o' || argument=='n' || argument=='g') { - param['l'] = 'l'; - } - } - if (status) { - if(!param['1']) printf("\n"); - return status; - } - - if (!param['C'] && !param['m'] && !param['1']) - param['1'] = '1'; - - if (param['l'] || param['g']) { - param['m'] = 0; - param['C'] = 0; - param['1'] = '1'; - } - - for (i = 1; i < argc; i++) { - if ((success |= (argv[i][0] != '-' ? 1 : 0))) { - if (!strcmp(argv[i],".")) status |= ls("./"); - else status |= ls(argv[i]); - } - } - - i = success ? status : ls("./"); - if(!param['1']) - printf("\n"); - - return i; -} - -void printUsage(char *params) { - printf("Ferass' Base System. (%s)\n\n" - "Usage: " - "ls [-%s] [directory] ...\n\n" - "Print <directory>'s contents to standard output.\n\n" - "\t-a\tInclude names starting with a dot, including '.' and '..'\n" - "\t-A\tSame as `-a` but don't include '.' and '..'\n" - "\t-C\tPrint in columns\n" - "\t-1\tPrint in lines\n" - "\t-R\tRecursively list directories\n" - "\t-i\tFor each file, write its serial number\n" - "\t-m\tList names followed by a comma and space character\n" - "\t-l\tDo not follow symbolic links named as operands and " - "write in long format (unfinished)\n" - "\t-p\tShow '/' after each name if that name is a directory\n" - "\t-g\tEnable the -l option but don't print the file owner's name\n" - "\t-n\tEnable the -l option but print the file owner and group's numeric " - "UID and GID instead of their name\n" - "\t-o\tEnable the -l option but don't print the file group's name\n", - COMPILETIME, params); -} - -int ls(char *path) { - int file, dotname, cwdname, prevdir, dot; - long unsigned int cols_used; - DIR *directory, *subdirectory; - struct stat file_status; - struct dirent *dirtree; - struct winsize columns; - char *name, file_moddate[256]; - char file_modes[] = "----------"; - directory = opendir(path); - - if (param['C']) { - ioctl(STDOUT_FILENO, TIOCGWINSZ, &columns); - cols_used = 0; - } - - if (directory == NULL) { - file = open(path, O_RDONLY); - if (file == -1) return errno; - printf("%s\n", path); - close(file); - return errno; - } - - if (param['R']) { - printf("The previous ls -R implementation had so much " - "flaws that it got removed from the ls codebase.\n"); - return 0; - } - while ((dirtree = readdir(directory)) != NULL) { - name = dirtree->d_name; - - cwdname = strcmp(name, ".") ? 0 : 1; - prevdir = strcmp(name, "..") ? 0 : 1; - dotname = (name[0]=='.' && !cwdname && !prevdir) ? 1 : 0; - dot = dotname | prevdir | cwdname; - - if (dot && !param['a'] && !param['A']) continue; - if ((cwdname || prevdir) && param['A']) continue; - - if (param['i']) printf("%lu ", dirtree->d_ino); - if (param['l']) { - char *fullpath = malloc(strlen(path) + strlen(name) + 2); - if (fullpath) { - strcpy(fullpath, path); - if (path[strlen(path) - 1] != '/') strcat(fullpath, "/"); - strcat(fullpath, name); - } - lstat(fullpath, &file_status); - /* File modes */ - /* File type */ - { - if (S_ISBLK(file_status.st_mode)) file_modes[0] = 'b'; - else if (S_ISCHR(file_status.st_mode)) file_modes[0] = 'c'; - else if (S_ISDIR(file_status.st_mode)) file_modes[0] = 'd'; - else if (S_ISFIFO(file_status.st_mode)) file_modes[0] = 'p'; - else if (S_ISREG(file_status.st_mode)) file_modes[0] = '-'; - else if (S_ISLNK(file_status.st_mode)) file_modes[0] = 'l'; - else file_modes[0] = 's'; - } - /* User */ - { - if (file_status.st_mode & S_IRUSR) file_modes[1] = 'r'; - if (file_status.st_mode & S_IWUSR) file_modes[2] = 'w'; - if (file_status.st_mode & S_IXUSR) file_modes[3] = 'x'; - } - /* Group */ - { - if (file_status.st_mode & S_IRGRP) file_modes[4] = 'r'; - if (file_status.st_mode & S_IWGRP) file_modes[5] = 'w'; - if (file_status.st_mode & S_IXGRP) file_modes[6] = 'x'; - } - /* Others */ - { - if (file_status.st_mode & S_IROTH) file_modes[7] = 'r'; - if (file_status.st_mode & S_IWOTH) file_modes[8] = 'w'; - if (file_status.st_mode & S_IXOTH) file_modes[9] = 'x'; - } - printf("%s ", file_modes); - /* Number of links */ - printf("%lu ", file_status.st_nlink); - /* Owner name/uid */ - if (!param['g']) - /* This recursiveness is needed for whatever reason, - * else it doesn't work... - */ - if (!param['n']) - printf("%s ", getpwuid(file_status.st_uid)->pw_name); - if (param['n']) printf("%u ", file_status.st_uid); - /* Group name/gid */ - if (!param['o']) - if (!param['n']) printf("%s ", getgrgid(file_status.st_gid)->gr_name); - if (param['n']) printf("%u ", file_status.st_gid); - /* Size of file */ - printf("%lu ", file_status.st_size); - /* Date and time */ - int strftime_status = strftime(file_moddate, sizeof(file_moddate), - "%b %e %H:%MM", localtime(&file_status.st_mtime)); - /* It should be st_mtim right? */ - file_moddate[strlen(file_moddate) - 1] = 0; /* Remove newline */ - printf("%s ", strftime_status ? file_moddate : "<strftime() returned 0>"); - free(fullpath); - } - printf("%s", name); - if (param['p']) { - char *fullpath = malloc(strlen(path) + strlen(name) + 2); - if (fullpath) { - strcpy(fullpath, path); - if (path[strlen(path) - 1] != '/') strcat(fullpath, "/"); - strcat(fullpath, name); - } - stat(fullpath, &file_status); - if (S_ISDIR(file_status.st_mode)) printf("/"); - free(fullpath); - } - if (param['C']) { - if (cols_used < (long unsigned int)((columns.ws_col) / 12)) { - for (long unsigned int i = strlen(name); i < 11; i++) printf(" "); - cols_used++; - } - if (cols_used == (long unsigned int)((columns.ws_col) / 12)) { - printf("\n"); - cols_used = 0; - } - } - else if (param['1']) - printf("\n"); - else if (param['m']) - printf(", "); - } - closedir(directory); - - return errno; -} diff --git a/core/mkdir.c b/core/mkdir.c deleted file mode 100644 index 609ddc2..0000000 --- a/core/mkdir.c +++ /dev/null @@ -1,77 +0,0 @@ -/* mkdir - create directories - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <sys/stat.h> -#include <errno.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - char param[256]; - int success, argument, i = 1; - char *basenamestr[256]; - - if (argc == 1) { - printUsage(); - return 1; - } - - while ((argument = getopt(argc, argv, "p")) != -1) { - if (argument == '?') { - printUsage(); - return 0; - } - param[argument] = argument; - } - - for (; i < argc; i++) { - printf("Warning: -p ignored.\n"); - if (argv[i][0] != '-') - success = !mkdir(argv[i], S_IRWXU | S_IRWXG | S_IRWXO) ? 0 : 1; - if (success == 1) { - return errno; - } - - } - - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: mkdir [-p] directory ...\n\n" - "Create a directory.\n\n", COMPILETIME); -} diff --git a/core/more.c b/core/more.c deleted file mode 100644 index 2db41c4..0000000 --- a/core/more.c +++ /dev/null @@ -1,121 +0,0 @@ -/* more - display files in a page-by-page basis. - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include <termios.h> -#include <sys/ioctl.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int i = 0, argument, success, read_file; - long int columns, lines; - char buffer[4096], cmd; - struct winsize w; - FILE *file; - struct termios oldattr, newattr; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); - if (getenv("LINES")) lines = strtol(getenv("LINES"), NULL, 10) - 1; - else lines = w.ws_row - 1; - if (getenv("COLUMNS")) columns = strtol(getenv("COLUMNS"), NULL, 10); - else columns = w.ws_col - 1; - - while ((argument = getopt(argc, argv, "")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - } - if (argc != 2) { - printUsage(); return 1; - } - file = fopen(argv[1], "r"); - if (errno) return errno; - success = 0; - while (!success) { - if (!read_file) read_file = 1; /* 1 => read on a page-by-page basis - * 0 => don't read at all - * 2 => read on a line-by-line basis - */ - for (i = 0; i < lines && read_file != 0; i++) { - if (fgets(buffer, 4096, file) != NULL) { - printf("%s", buffer); - } - else if (errno) return errno; - else { - success = 1; - break; - } /* EOF, end while and for loop */ - if (read_file == 2) { - break; - } - } - read_file = 0; - - /* Get a character */ - tcgetattr(0, &oldattr); /* Get previous terminal parameters */ - newattr = oldattr; - newattr.c_lflag &= ~( ICANON | ECHO ); /* Disable ECHO and ICANON */ - tcsetattr( 0, TCSANOW, &newattr); /* Set net parameters */ - cmd = getchar(); - tcsetattr(0, TCSANOW, &oldattr); /* Restore old parameters */ - - if (errno) return errno; - switch (cmd) { - case 'q': - return 0; - case 'h': - printUsage(); - read_file = 0; - break; - case ' ': - read_file = 1; /* page-by-page */ - break; - default: - read_file = 2; /* line-by-line */ - break; - } - } - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: more file ...\n\n" - "Display a file on a page-by-page basis.\n\n", COMPILETIME); -} diff --git a/core/mv.c b/core/mv.c deleted file mode 100644 index 7124c3f..0000000 --- a/core/mv.c +++ /dev/null @@ -1,83 +0,0 @@ -/* mv - move files. - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, file; - char cmd, param[256]; - setvbuf(stdout, NULL, _IONBF, 0); - for (int i = 0; i < 256; i++) param[i] = 0; /* Initialise param, - * very important. */ - while ((argument = getopt(argc, argv, "if")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - param[argument] = argument; - if (argument == 'f') param['i'] = 0; - if (argument == 'i') param['f'] = 0; - } - if (!param['f']) param['i'] = 'i'; - if (argc < 3) { - printUsage(); - return 1; - } - if ((file = open(argv[2], O_RDONLY)) != -1 && param['i']) { - printf("File exists, override it? (y/n) "); - read(STDIN_FILENO, &cmd, 3); - if (cmd == 'n' || cmd == 'N') { - close(file); - return 0; - } - } - close(file); /* In case it hasn't been closed */ - - rename(argv[1], argv[2]); /* Technically, moving files == renaming files */ - if (errno) return errno; - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: mv [-if] file1 file2\n\n" - "Move <file1> to <file2>.\n\n" - "\t-i\tIf <file2> exists, ask for confirmation\n" - "\t-f\tNever ask for confirmation\n", COMPILETIME); -} diff --git a/core/printf.c b/core/printf.c deleted file mode 100644 index a82426c..0000000 --- a/core/printf.c +++ /dev/null @@ -1,55 +0,0 @@ -/* printf - write formatted strings to stdout - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1; - - if (argc == 1) { - printUsage(); - return 1; - } - printf(argv[1], argv[2] ? argv[2] : ""); - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: printf format [string]\n\n" - "Write formatted strings to stdout.\n\n", COMPILETIME); -} diff --git a/core/rm.c b/core/rm.c deleted file mode 100644 index 568f27b..0000000 --- a/core/rm.c +++ /dev/null @@ -1,74 +0,0 @@ -/* rm - remove files. - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1; - char param[256]; - - while ((argument = getopt(argc, argv, "Rr")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - param[argument] = argument; - } - if (argc <= 1) { - printUsage(); - return 1; - } - - for (; i < argc; i++) { - if (!param['r'] || !param['R']) unlink(argv[i]); - else remove(argv[i]); /* TODO: Actually - * recursively remove - * the directory */ - } - - if (errno) return errno; - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: rm [-Rr] file ...\n\n" - "Remove <file>.\n\n" - "\t-R\tRecursively remove the directory tree\n" - "\t-r\tEnable the -R option\n", COMPILETIME); -} diff --git a/core/sleep.c b/core/sleep.c deleted file mode 100644 index 4f36251..0000000 --- a/core/sleep.c +++ /dev/null @@ -1,63 +0,0 @@ -/* sleep - suspend execution for an interval - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -void printUsage(); - -int main(int argc, char *argv[]) { - long unsigned int seconds; - - if (argc == 2) { - seconds = strtol(argv[1], NULL, 10); - if (!seconds) { - printUsage(); - return 1; - } - sleep(seconds); - } - else if (argc == 1) { - printUsage(); - return 1; - } - - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: sleep seconds\n\n" - "Suspend execution for <seconds> seconds.\n\n", COMPILETIME); -} diff --git a/core/tail.c b/core/tail.c deleted file mode 100644 index 0a0cebc..0000000 --- a/core/tail.c +++ /dev/null @@ -1,98 +0,0 @@ -/* tail - copy the last part of files - * Copyright (C) 2022 Ferass EL HAFIDI - * Copyright (C) 2022 Leah Rowe - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <fcntl.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -/* Functions Prototypes & Variables */ -extern char *optarg; -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1, lines, file_lines; - FILE *file; - - char s[4096]; - - while ((argument = getopt(argc, argv, "n:")) != -1) { - if (argument == '?' || argument == ':') { - printUsage(); - return 1; - } - else if (argument == 'n') { - lines = strtol(optarg, NULL, 10); - if (errno) return errno; - } - else - lines = 10; - } - if (argc < 2) { - while (read(STDIN_FILENO, s, 4096) > 0) - printf("%s", s); - } - if (!lines) lines = 10; - for (i = 1; i != argc; i++) { - if (strcmp(argv[i], "-n")) { - if (strcmp(argv[i], "-")) file = fopen(argv[i], "r"); - else while (read(STDIN_FILENO, s, 4096) > 0) printf("%s", s); - if (file == NULL) return errno; /* Something went wrong */ - while (fgets(s, 4096, file) != NULL) - file_lines++; /* Get number of lines */ - fclose(file); - file_lines = file_lines - lines; - if (strcmp(argv[i], "-")) file = fopen(argv[i], "r"); - while (fgets(s, 4096, file) != NULL) { - if (errno) return errno; - if (file_lines == 0) printf("%s", s); - else file_lines--; - } - } - else i++; - } - - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: head [-n number] [file]\n\n" - "Copy file to standard output until <number> lines.\n\n" - "\t-n number\tNumber of lines to be copied to standard output\n", - COMPILETIME); -} diff --git a/core/test.c b/core/test.c deleted file mode 100644 index af4d072..0000000 --- a/core/test.c +++ /dev/null @@ -1,128 +0,0 @@ -/* [ - evaluate expression - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#define _POSIX_C_SOURCE 200809L -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <libgen.h> -#include <sys/stat.h> -#include <stdint.h> -#include <string.h> -#include <stdlib.h> - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -/* For readability reasons, define true, false */ -int true = 0; -int false = 1; - -int main(int argc, char *argv[]) { - int argument; - char param[256]; - struct stat file_status; - - for (int i = 0; i < 256; i++) param[i] = 0; - - if (!strcmp(basename(argv[0]), "[")) { - if (strcmp(argv[argc - 1], "]")) { - /* FIXME: Is printing an error message POSIX-compliant? */ - fprintf(stderr, "[: No matching ]\n"); - return 1; - } - argc--; - argv[argc] = 0; - } - - if (argc < 2) return false; - if (!strcmp(argv[1], "!")) { - true = 1; - false = 0; - argc--; - argv++; - } - if (argc == 3) { - param[(uint8_t)argv[1][1]] = argv[1][1]; - /* Files */ - stat(argv[2], &file_status); - if (!errno) { - if (param['b'] && S_ISBLK(file_status.st_mode) != 0) return true; - else if (param['c'] && S_ISCHR(file_status.st_mode) != 0) return true; - else if (param['d'] && S_ISDIR(file_status.st_mode) != 0) return true; - /* Just return true, if -e is used. If it was false, stat() would - * have failed. If it failed, there's a check about which value - * to return. Return false if -e is used, otherwise, return errno - */ - else if (param['e']) return true; - else if (param['f'] && S_ISREG(file_status.st_mode) != 0) return true; - else if (param['g'] && file_status.st_mode & S_ISGID) return true; - else if ((param['h'] || param['L']) - && S_ISLNK(file_status.st_mode) != 0) return true; - else if (param['p'] && S_ISFIFO(file_status.st_mode) != 0) return true; - /* TODO: Better check for -r/-w. */ - else if (param['r'] && (file_status.st_mode & S_IRUSR - || file_status.st_mode & S_IROTH)) return true; - else if (param['S'] && S_ISSOCK(file_status.st_mode) != 0) return true; - else if (param['s'] && file_status.st_size > 0) return true; - else if (param['u'] && S_ISDIR(file_status.st_mode) - && file_status.st_mode & S_ISUID) return true; - else if (param['w'] && (file_status.st_mode & S_IWUSR - || file_status.st_mode & S_IWOTH)) return true; - else if (param['x'] && (file_status.st_mode & S_IXUSR - || file_status.st_mode & S_IXOTH)) return true; - } - else if (errno && param['e']) return false; - if (param['t']) { - if (isatty(strtol(argv[2], NULL, 10))) return true; - else return false; - } - /* Strings */ - if (param['n'] && strlen(argv[2])) return true; - else if (param['z'] && !strlen(argv[2])) return true; - } - - else if (argc == 4) { - if (!strcmp(argv[2], "=") && !strcmp(argv[1], argv[3])) return true; - else if (!strcmp(argv[2], "!=") && strcmp(argv[1], argv[3])) return true; - else if (!strcmp(argv[2], "-eq") && !strcmp(argv[1], argv[3])) return true; - else if (!strcmp(argv[2], "-ne") && strcmp(argv[1], argv[3])) return true; - else if (!strcmp(argv[2], "-gt") && - strtol(argv[1], NULL, 10) > strtol(argv[3], NULL, 10)) return true; - else if (!strcmp(argv[2], "-ge") && - strtol(argv[1], NULL, 10)>= strtol(argv[3], NULL, 10)) return true; - else if (!strcmp(argv[2], "-lt") && - strtol(argv[1], NULL, 10) < strtol(argv[3], NULL, 10)) return true; - else if (!strcmp(argv[2], "-le") && - strtol(argv[1], NULL, 10)<= strtol(argv[3], NULL, 10)) return true; - } - - /* TODO: Better error handling. */ - return false; -} diff --git a/core/true.c b/core/true.c deleted file mode 100644 index 4eb43cf..0000000 --- a/core/true.c +++ /dev/null @@ -1,31 +0,0 @@ -/* true - return true value - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -int main() { - return 0; -} diff --git a/core/uname.c b/core/uname.c deleted file mode 100644 index db91d50..0000000 --- a/core/uname.c +++ /dev/null @@ -1,90 +0,0 @@ -/* uname - return system name - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <sys/utsname.h> -#include <errno.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument; - struct utsname name; - char param[256]; - for (int i = 0; i < 256; i++) param[i] = 0; - - while ((argument = getopt(argc, argv, "amnrsv")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - param[argument] = argument; - if (argument == 'a') { - param['s'] = 's'; - param['n'] = 'n'; - param['r'] = 'r'; - param['v'] = 'v'; - param['m'] = 'm'; - } - } - - uname(&name); - if (errno) return errno; - if (argc > 1) { - if (param['s']) printf("%s ", name.sysname); - if (param['n']) printf("%s ", name.nodename); - if (param['r']) printf("%s ", name.release); - if (param['v']) printf("%s ", name.version); - if (param['m']) printf("%s", name.machine); - printf("\n"); - } - else - printf("%s\n", name.sysname); - - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: uname [-amnrsv] \n\n" - "Return system name.\n\n" - "\t-a\tSame as -mnrsv\n" - "\t-m\tWrite the hardware's architecture\n" - "\t-n\tWrite the network node hostname\n" - "\t-r\tWrite the operating system release\n" - "\t-s\tWrite the name of the operating system implementation\n" - "\t-v\tWrite the current version of this release of the operating " - "system implementation\n", COMPILETIME); -} diff --git a/core/unlink.c b/core/unlink.c deleted file mode 100644 index 7e2ed6f..0000000 --- a/core/unlink.c +++ /dev/null @@ -1,57 +0,0 @@ -/* unlink - call the unlink() function - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -int getopt(int argc, char *const argv[], const char *optstring); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1; - - if (argc != 2) { - printUsage(); - return 1; - } - unlink(argv[1]); - if (errno) return errno; - return 0; -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: unlink file\n\n" - "Call the unlink() function.\n\n", COMPILETIME); -} diff --git a/core/vi.c b/core/vi.c deleted file mode 100644 index 97fa02f..0000000 --- a/core/vi.c +++ /dev/null @@ -1,242 +0,0 @@ -/* vi/ex - visual/text editor - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <signal.h> -#include <string.h> -#include <time.h> -#include <termios.h> -#include <sys/ioctl.h> -#include <libgen.h> -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -/*** ANSI VT100 escape codes ***/ -/* Colors */ -#define ANSI_WHITEBG "\33[38;5;0;48;5;255m" -#define ANSI_RESET "\33[m" -/* Other escape codes */ -#define ANSI_CLEARLINE "\33[2K\r" -#define ANSI_CLEARALL "\e[1;1H\e[2J" - -/********** Common - used by both vi and ex **********/ -int print_string(char *string); - -int print_string(char *string) { - return write(STDOUT_FILENO, string, strlen(string)); -} - -/********************** ex mode **********************/ -int _ex_main(int argc, char *argv[]); - -int _ex_main(int argc, char *argv[]) { - print_string("<Not implemented>\n"); - return 0; /* Not implemented yet. */ -} - -/********************** vi mode **********************/ -struct cursor_pos { - /* Neat way to keep track of the cursor's position. */ - unsigned int x; - unsigned int y; -}; - -int _vi_main(int argc, char *argv[]); -int _vi_set_cursor_pos(unsigned int x, unsigned int y); -int _vi_init(unsigned int lines, unsigned int columns, - char buffer[BUFSIZ], struct cursor_pos cposition, long int offset_position, - FILE *filstr); -void _vi_printUsage(); -int _vi_print_buffer_line(char s[BUFSIZ], unsigned int numlines); - -int _vi_main(int argc, char *argv[]) { - int argument, offset; - char cmd; - FILE *filstr; - char buffer[BUFSIZ]; - struct sigaction signal_action; - struct termios oldattr, newattr; - struct winsize w; - struct cursor_pos cposition, fposition; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); - unsigned int lines = w.ws_row - 1; - unsigned int columns = w.ws_col - 1; - - while ((argument = getopt(argc, argv, "")) != -1) { - if (argument == '?') { - _vi_printUsage(); - return 1; - } - } - argc -= optind; - argv += optind; - - signal_action.sa_handler = SIG_IGN; - sigemptyset(&signal_action.sa_mask); - sigaction(SIGINT, &signal_action, NULL); - setvbuf(stdout, NULL, _IONBF, 0); - /* Initialise vi */ - if (argv[0]) { - filstr = fopen(argv[0], "r+"); - if (errno) { - if (errno != ENOENT) - return errno; - } - } _vi_init(lines, columns, buffer, cposition, offset, filstr); - for (;;) { - /* Get a character */ - tcgetattr(0, &oldattr); /* Get previous terminal parameters */ - newattr = oldattr; - newattr.c_lflag &= ~( ICANON | ECHO ); /* Disable ECHO and ICANON */ - tcsetattr(0, TCSANOW, &newattr); /* Set net parameters */ - cmd = getchar(); - switch (cmd) { - /*********************** Moving the cursor ***********************/ - case 'k': /* up */ - if (fposition.y > 0) fposition.y--; - else break; - if (cposition.y != 1) - _vi_set_cursor_pos(cposition.x, (cposition.y = cposition.y - 1)); - else if (fposition.y == 0) { - _vi_set_cursor_pos(1, 1); - print_string(ANSI_CLEARALL); /* Clear screen */ - fposition.y--; /* Say, 118 */ - for (unsigned int i = lines - 1 /* 79 */; i > 0; i--) { - _vi_print_buffer_line(buffer, fposition.y - i); /* 120 - 78 */ - } - _vi_set_cursor_pos(cposition.x, cposition.y); - } - break; - case 'j': /* down */ - if (cposition.y != (lines - 1) && fposition.y++) - _vi_set_cursor_pos(cposition.x, (cposition.y = cposition.y + 1)); - else if (cposition.y == lines - 1) { - _vi_set_cursor_pos(1, 1); - print_string(ANSI_CLEARALL); /* Clear screen */ - fposition.y++; /* Say, 120 */ - for (unsigned int i = lines - 1 /* 79 */; i > 0; i--) { - _vi_print_buffer_line(buffer, fposition.y - i); /* 120 - 78 */ - } - _vi_set_cursor_pos(cposition.x, cposition.y); - } - break; - case 'l': /* right */ - if (cposition.x != columns && fposition.x++) - _vi_set_cursor_pos((cposition.x = cposition.x + 1), cposition.y); - break; - case 'h': /* left */ - if (cposition.x != 1 && fposition.x--) - _vi_set_cursor_pos((cposition.x = cposition.x - 1), cposition.y); - break; - /************************* Command mode: *************************/ - case ':': - _vi_set_cursor_pos(1, lines); - print_string(ANSI_CLEARLINE ":"); - tcsetattr(0, TCSANOW, &oldattr); /* Restore old parameters */ - cmd = getchar(); - switch (cmd) { - case '\33': - _vi_set_cursor_pos(1, lines); - print_string(ANSI_CLEARLINE); - break; - case 'q': - print_string(ANSI_CLEARALL); /* Clear screen */ - _vi_set_cursor_pos(1, 1); /* Reset the cursor position */ - if (filstr) fclose(filstr); - return 0; - case '\n': - break; - default: - _vi_set_cursor_pos(1, lines); - print_string("unknown command"); - break; - } - _vi_set_cursor_pos(cposition.x, cposition.y); - } - tcsetattr(0, TCSANOW, &oldattr); /* Restore old parameters */ - } - return 0; -} - -int _vi_init(unsigned int lines, unsigned int columns, - char buffer[BUFSIZ], struct cursor_pos cposition, - long int offset_position, FILE *filstr) { - int status = 0; - print_string(ANSI_CLEARALL); /* Clear screen */ - _vi_set_cursor_pos(1, 1); - if (filstr) { - fread(buffer, BUFSIZ, 1, filstr); - //if (fgets(buffer, 4096, filstr) != NULL) { - // offset_position = ftell(filstr); - // fputs(buffer, stdout); - //} - for (unsigned int i = 0; i < lines - 1; i++) - _vi_print_buffer_line(buffer, i); - } else { - for (unsigned int i = 1; i < (lines ); i++) - fputs("~\n", stdout); - status = 2; /* No file */ - } _vi_set_cursor_pos((cposition.x = 1), (cposition.y = 1)); - return status; -} - -int _vi_set_cursor_pos(unsigned int x, unsigned int y) { - return printf("\033[%u;%uH", (y), (x)); -} - -void _vi_printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: vi [filename]\n\n" - "Visual editor.\n\n", COMPILETIME); -} - -int _vi_print_buffer_line(char s[BUFSIZ], unsigned int numlines) { - unsigned int lines_found, chars; - /* Search for <numlines> - 1 lines and skip them entirely. */ - for (chars = 0, lines_found = 0; - s[chars] && lines_found < numlines; s[chars] == '\n' && lines_found++, chars++) - /* TODO: Use strchr(). */ ; - /* Print the last line found. */ - for (; s[chars] && s[chars] != '\n'; chars++) putchar((int)s[chars]) - /* TODO: Do not print character-by-character. */ ; - putchar((int)'\n'); - return 0; -} - -/************ main() ************/ -int main(int argc, char *argv[]) { - if (!strcmp(basename(argv[0]), "ex")) return _ex_main(argc, argv); - else /* Default to vi */ return _vi_main(argc, argv); - return 0; /* Never reached. */ -} diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md deleted file mode 100644 index a0817ac..0000000 --- a/docs/CODING_STYLE.md +++ /dev/null @@ -1,126 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](/README.md) - -## Coding Style - -The programming language used is ***POSIX C99*** and all code must be written -in ***POSIX C99***, no extensions are used. - -The coding style is as follows: - -### General - -- The code shall be as simple to understand as possible, add comments if -necessary ; - -- For indentation, the code shall use tab characters ; - -- The code shall avoid using GNU-specific functions (as that would make -the program less portable) ; - -- Each line shall not exceed 79 characters ; - -- Utilities shall only implement POSIX-compliant options, if the utility -supports options, and the specified option is invalid, the utility shall -print a help text (this applies only to coreutils) ; - -- Utilities shall only use the **standard C library and POSIX libraries** ; - -- For comments, instead of using `//` (as in `// Comment`), the code shall -use `/*` and `*/` (as in `/* Comment */`) ; - -- For commenting code, use `//` (as in `// printf("broken code")`) ; - -- **Variable names** shall describe the variable's purpose ; - -- The `main()` function shall be placed at the top, after function -prototypes, to increase code readability ; - -### Blocks - -- In a block, do not use `{` and `}` if there's only one instruction inside ; - -``` -for (int i; i != 3; i++) - printf("%d\n", i); -``` - -- When using `{` and `}`, `{` shall not be on it's own line ; - -``` -if (i) { - printf("%d", i); - i = 3; -} -``` - -- The block shall only use 1 line if there's only one instruction ran and -that shall not exceed 79 characters ; - -``` -if (foo[1] == 'a') foo[1] = 'b'; -``` - -### Functions - -- The function type shall be on the same line as the function name and `{` ; - -``` -int main() { - printf("Hello World.\n"); -} -``` - -- Function names shall describe the function's intended purpose ; - -- When exiting, the function shall use `return` instead of `exit()` ; - -``` -int calculate(int i) { - int result; - if (i != 0) - result = 30 / 1; - return 0; - else - return 1; -} -``` - -- Variable declarations shall be at the top of the function ; - -``` -int main() { - int i, result; - char foo; - bool bar; -} -``` - -### Switch - -- In `switch (foo)`, `case` shall be indented ; - -``` -switch (foo) { - case 'b': - break; - case 'a': - printf("bar\n"); - default: - return 0; -} -``` - -### Preprocessor statements - -- The `#define` preprocessor statement shall only be used for setting -constant values ; - -``` -#define FOO 80 -``` - -- Preprocessor statements shall not be indented. diff --git a/docs/COMPILE.md b/docs/COMPILE.md deleted file mode 100644 index fe74b35..0000000 --- a/docs/COMPILE.md +++ /dev/null @@ -1,61 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](/README.md) - -## Compile - -You have 2 choices: - -- compile each utility separately; - -- compile only fasesiab which includes all utilities in a single binary. - -Modify the `config.mk` file to fit your needs in both cases. - -## Compiling each utility separately - -For example to compile `cat`, you have to run the following: - - $ cd core/ - $ make cat - -And to compile a non-POSIX utility such as `yes`, you have to run the -following: - - $ cd extras/ - $ make yes - -## Compiling fasesiab - -Fasesiab stands for Ferass' Base System in a box. It includes the entire -coreutils in a single and tiny binary. - -Before compiling, you have to prepare `fasesiab`. -The `box.c` file should already contain some code but it may be outdated -so it's recommended to regenerate it: - - $ make genbox - -Next, run the following: - - $ make prepbox - -Now you're ready to compile! Run `make` and get a binary! - - $ make box - -## Installation - -For now, you can only install fasesiab and no manpages are being installed. -To install, simply run the following: - - $ doas make install - -Or, if using `sudo`: - - $ sudo make install - -Then, you should have a binary called `box`. Make sure `/usr/local/bin/` or -whatever `DESTDIR` and `PREFIX` you set is in your `$PATH`. diff --git a/docs/FAQ.md b/docs/FAQ.md deleted file mode 100644 index d97d6ad..0000000 --- a/docs/FAQ.md +++ /dev/null @@ -1,40 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](../README.md) - -## FAQ - -Here are questions someone could ask. Read it! It could answer some of your -questions. - -Q: Why another coreutils? There's already GNU, Busybox, OpenBSD's, and some more. - -A: Most coreutils are either non-POSIX or use non-portable functions not -specified by POSIX. The `fases` project separates POSIX and non-POSIX -utilities while others do not. Some have also quite complex code, making it -harder to study the code. - -[We're not trying to trash other coreutils. A lot of them -(Busybox, OpenBSD, ...) are actually really good] - -Q: Is fases going to work on <insert UNIX-like operating system name here>? - -A: Well, it depends on the system itself. If your system implements POSIX -functions in its libc, then it'll work. Utilities are currently tested on -- OpenBSD ; - -- FreeBSD ; - -- OS X/Mac OS X/MacOS (just a little) ; - -- Artix Linux and Arch Linux ; - -- Alpine Linux. - -No. `fases` will never work on Microsoft Windows. - ---- - -More coming soon. diff --git a/docs/FasesDonationsQR.png b/docs/FasesDonationsQR.png Binary files differdeleted file mode 100644 index dc9d5c6..0000000 --- a/docs/FasesDonationsQR.png +++ /dev/null diff --git a/docs/MIRRORS.md b/docs/MIRRORS.md deleted file mode 100644 index 87c065a..0000000 --- a/docs/MIRRORS.md +++ /dev/null @@ -1,20 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](../README.md) - -## Mirrors - -Development of fases is done on git.vitali64.duckdns.org but there are -mirrors made by other people: - -| Protocol | URL | Author | -|----------|-----|--------| -| https,git | [andrewyu.org](https://git.andrewyu.org/vitali64/fases.git) | Andrew Yu | -| https | [notabug.org](https://notabug.org/vitali64/fases) | Ferass | -| http,https,rsync | [mirrors.vern.cc](https://mirrors.vern.cc/fases) | ~vern team | -| https,git | [git.vern.cc](https://git.vern.cc/fases) | ~vern team | - -If you made a mirror too, be sure to let me know so I can add it on this -section too! diff --git a/docs/STATUS.md b/docs/STATUS.md deleted file mode 100644 index baf048b..0000000 --- a/docs/STATUS.md +++ /dev/null @@ -1,38 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](/README.md) - -## Status - -The `fases` project is still incomplete as some utilities are missing, here's -what `fases` currently provides (most of those utilities are incomplete): - -- `ls` - -- `head` - -- `cat` - -- `yes` - -- `date` - -- `mkdir` - -- `echo` - -Other utilities are still in the making. Help is greatly appreciated. - -## Known bugs - -The `fases` project is still a Work-in-progress and as such, there are bugs. -Please do report bugs to me, via IRC, email, or even by using Notabug.org -issues. - -| Bug | Affected utility-ies | -|-------------------------------------------------------------|-------| -| Sometimes, `-l` would show incorrect permissions. | `ls` | -| When there's a lot to print, `-l` fails with a memory error | `ls` | - diff --git a/docs/ServerDonationsQR.png b/docs/ServerDonationsQR.png Binary files differdeleted file mode 100644 index 92cf53a..0000000 --- a/docs/ServerDonationsQR.png +++ /dev/null diff --git a/docs/TODO.md b/docs/TODO.md deleted file mode 100644 index 2ea60f6..0000000 --- a/docs/TODO.md +++ /dev/null @@ -1,51 +0,0 @@ -# fases - Ferass' Base System - -*Simple coreutils for a fully functionnal UNIX-like system* - -[« Go back](/README.md) - -## TODO list - -- Test on lots of unix/unix-like operating systems - -- Add lots of utils - -### chmod.c - -- support "a+rwx" and such and -R - -### chown.c - -- fix - -### date.c - -- support dates as operands - -### ln.c - -- support -L/-P - -- support this: `$ ln [-fs] [-L|-P] src target_dir` - -### ls.c - -- broken permissions, -l follows symlinks - -### mkdir.c - -- implement -p - -### more.c - -- implement more options - -### printf.c - -- fix string formatting - -### rm.c - -- implement all options, rm -R doesn't recursively -remove directories - diff --git a/extras/Makefile b/extras/Makefile deleted file mode 100644 index 1efee9a..0000000 --- a/extras/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright (C) 2022 Ferass EL HAFIDI -# Copyright (C) 2022 Leah Rowe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# - -include ../config.mk - -# Commands -# ======== - -all: clean yes errno - -version: - echo "#ifndef VERSION_H" > version.h - echo "#define VERSION_H" >> version.h - echo "#define COMPILETIME \"$$(git show --no-patch --pretty=format:%H)\"" >> version.h - echo >> version.h - echo "#endif" >> version.h - -yes: yes.o - mkdir -p bin - $(CC) $(CFLAGS) yes.o -o bin/yes - -errno: errno.o - mkdir -p bin - $(CC) $(CFLAGS) errno.o -o bin/errno - -clean: - rm -Rf bin/ *.o - -# Utilities -# ========= - -errno.o: version - $(CC) $(CFLAGS) $(NOLINKER) errno.c -o errno.o - -yes.o: version - $(CC) $(CFLAGS) $(NOLINKER) yes.c -o yes.o diff --git a/extras/errno.c b/extras/errno.c deleted file mode 100644 index 61b1c95..0000000 --- a/extras/errno.c +++ /dev/null @@ -1,284 +0,0 @@ -/* errno - give information about error codes - * Copyright (C) 2022 Ferass EL HAFIDI - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version."); - * - * This program 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 General Public License for more details."); - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>."); - */ - -#include <string.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -void printUsage() { - printf("Ferass' Extra Utilities.\n\n" - "Usage: errno [STRING]\n" - "Give information about error codes.\n\n"); -} - -int main(int argc, char *argv[]) { - long int error_code = 0; - setvbuf(stdout, NULL, _IONBF, 0); - if (argc == 2) { - error_code = strtol(argv[1], NULL, 10); - printf("errno %ld: ", error_code); - switch (error_code) { - case E2BIG: - printf("Argument list too long."); - break; - case EACCES: - printf("Permission denied."); - break; - case EADDRINUSE: - printf("Address in use."); - break; - case EADDRNOTAVAIL: - printf("Address not available."); - break; - case EAFNOSUPPORT: - printf("Address family not supported."); - break; - case EAGAIN: - printf("Resource unavailable, try again."); - break; - case EALREADY: - printf("Connection already in progress."); - break; - case EBADF: - printf("Bad file descriptor."); - break; - case EBADMSG: - printf("Bad message."); - break; - case EBUSY: - printf("Device or resource busy."); - break; - case ECANCELED: - printf("Operation canceled."); - break; - case ECHILD: - printf("No child processes."); - break; - case ECONNABORTED: - printf("Connection aborted."); - break; - case ECONNREFUSED: - printf("Connection refused."); - break; - case ECONNRESET: - printf("Connection reset."); - break; - case EDEADLK: - printf("Resource deadlock would occur."); - break; - case EDESTADDRREQ: - printf("Destination address required."); - break; - case EDOM: - printf("Mathematics argument out of domain of function."); - break; - case EDQUOT: - printf("Reserved."); - break; - case EEXIST: - printf("File exists."); - break; - case EFAULT: - printf("Bad address."); - break; - case EFBIG: - printf("File too large."); - break; - case EHOSTUNREACH: - printf("Host is unreachable."); - break; - case EIDRM: - printf("Identifier removed."); - break; - case EILSEQ: - printf("Illegal byte sequence."); - break; - case EINPROGRESS: - printf("Operation in progress."); - break; - case EINTR: - printf("Interrupted function."); - break; - case EINVAL: - printf("Invalid argument."); - break; - case EIO: - printf("I/O error."); - break; - case EISCONN: - printf("Socket is connected."); - break; - case EISDIR: - printf("Is a directory."); - break; - case ELOOP: - printf("Too many levels of symbolic links."); - break; - case EMFILE: - printf("File descriptor value too large."); - break; - case EMLINK: - printf("Too many links."); - break; - case EMSGSIZE: - printf("Message too large."); - break; - case EMULTIHOP: - printf("Reserved."); - break; - case ENAMETOOLONG: - printf("Filename too long."); - break; - case ENETDOWN: - printf("Network is down."); - break; - case ENETRESET: - printf("Connection aborted by network."); - break; - case ENETUNREACH: - printf("Network unreachable."); - break; - case ENFILE: - printf("Too many files open in system."); - break; - case ENOBUFS: - printf("No buffer space available."); - break; - case ENODATA: - printf("No message is available on the STREAM head read queue."); - break; - case ENODEV: - printf("No such device."); - break; - case ENOENT: - printf("No such file or directory."); - break; - case ENOEXEC: - printf("Executable file format error."); - break; - case ENOLCK: - printf("No locks available."); - break; - case ENOLINK: - printf("Reserved."); - break; - case ENOMEM: - printf("Not enough space."); - break; - case ENOMSG: - printf("No message of the desired type."); - break; - case ENOPROTOOPT: - printf("Protocol not available."); - break; - case ENOSPC: - printf("No space left on device."); - break; - case ENOSR: - printf("No STREAM resources."); - break; - case ENOSTR: - printf("Not a STREAM."); - break; - case ENOSYS: - printf("Functionality not supported."); - break; - case ENOTCONN: - printf("The socket is not connected."); - break; - case ENOTDIR: - printf("Not a directory or a symbolic link to a directory."); - break; - case ENOTEMPTY: - printf("Directory not empty."); - break; - case ENOTRECOVERABLE: - printf("State not recoverable."); - break; - case ENOTSOCK: - printf("Not a socket."); - break; - case ENOTSUP: - printf("Not supported (may be the same value as EOPNOTSUPP)."); - break; - case ENOTTY: - printf("Inappropriate I/O control operation."); - break; - case ENXIO: - printf("No such device or address."); - break; - case EOVERFLOW: - printf("Value too large to be stored in data type."); - break; - case EOWNERDEAD: - printf("Previous owner died."); - break; - case EPERM: - printf("Operation not permitted."); - break; - case EPIPE: - printf("Broken pipe."); - break; - case EPROTO: - printf("Protocol error."); - break; - case EPROTONOSUPPORT: - printf("Protocol not supported."); - break; - case EPROTOTYPE: - printf("Protocol wrong type for socket."); - break; - case ERANGE: - printf("Result too large."); - break; - case EROFS: - printf("Read-only file system."); - break; - case ESPIPE: - printf("Invalid seek."); - break; - case ESRCH: - printf("No such process."); - break; - case ESTALE: - printf("Reserved."); - break; - case ETIME: - printf("Stream ioctl() timeout."); - break; - case ETIMEDOUT: - printf("Connection timed out."); - break; - case ETXTBSY: - printf("Text file busy."); - break; - case EXDEV: - printf("Cross-device link."); - break; - case 0: - printf("No error occured."); - break; - default: - printf("Unknown."); - break; - } - printf("\n"); - } - - return 0; -} diff --git a/extras/yes.c b/extras/yes.c deleted file mode 100644 index 5d3e778..0000000 --- a/extras/yes.c +++ /dev/null @@ -1,37 +0,0 @@ -/* yes - Repeatedly output a line with all specified STRING or 'y'. - * Copyright (C) 2022 Ferass EL HAFIDI - * Copyright (C) 2022 Ron Nazarov - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <string.h> -#include <stdio.h> - -int main(int argc, char *argv[]) { - setvbuf(stdout, NULL, _IONBF, 0); - if (argc > 1) { - if (!strcmp(argv[1], "--")) { - if (--argc == 1) goto yes; - argv = &argv[1]; - } - while(1) { - for (int i = 1; i < argc; i++) printf("%s%c", argv[i], i == argc - 1 ? '\n' : ' '); - } - } else { -yes: - while(1) printf("y\n"); - } - return 0; -} diff --git a/man/basename.1 b/man/basename.1 deleted file mode 100644 index ec8ed83..0000000 --- a/man/basename.1 +++ /dev/null @@ -1,32 +0,0 @@ -BASENAME(1) "Ferass' Base System" - -# NAME - -basename \- Return non-directory portion of a pathname - -# SYNOPSIS - -*basename* _string_ [*suffix*] - -# DESCRIPTION - -Return non-directory portion of the *string* pathname. - -# EXAMPLES - -*basename /bin/sh* - Return non-directory portion ("sh"). - -*basename /usr/bin/basename name* - Remove the suffix "name" from "basename" and return "base". - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project - Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/cat.1 b/man/cat.1 deleted file mode 100644 index 5069093..0000000 --- a/man/cat.1 +++ /dev/null @@ -1,46 +0,0 @@ -CAT(1) "Ferass' Base System" - -# NAME - -cat - concatenate files to stdout - -# SYNOPSIS - -*cat* [*-u*] [*file*] ... - -# DESCRIPTION - -Concatenate files to standard output (stdout). -With no file or when file is -, read and concatenate standard input -to standard output. - -*-u* - Print unbuffered. - -# EXAMPLES - -*cat foobar* - Output foobar's contents to standard output. - -*cat* - Output standard input to standard output. - -*cat -u hello.c* - Output hello.c's contents unbuffered to standard output. - -*cat foo bar baz* - Output foo's contents, then bar's, then baz's to standard output. - -# AUTHOR - -Originally written by Ferass EL HAFIDI as part of the fases -project - Ferass' Base System. Part of the code is written by -Leah Rowe. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI - -Copyright (C) 2022 Leah Rowe diff --git a/man/dirname.1 b/man/dirname.1 deleted file mode 100644 index aec4661..0000000 --- a/man/dirname.1 +++ /dev/null @@ -1,29 +0,0 @@ -DIRNAME(1) "Ferass' Base System" - -# NAME - -dirname - Return directory portion of a pathname - -# SYNOPSIS - -*dirname* _string_ - -# DESCRIPTION - -Return directory portion of the STRING pathname. - -# EXAMPLES - -*dirname /bin/sh* - Return directory portion ("/bin/"). - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project \- Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/echo.1 b/man/echo.1 deleted file mode 100644 index d62b70f..0000000 --- a/man/echo.1 +++ /dev/null @@ -1,32 +0,0 @@ -ECHO(1) "Ferass' Base System" - -# NAME - -echo \- Write a string to standard output - -# SYNOPSIS - -*echo* [*string*] ... - -# DESCRIPTION - -Write a string to standard output (stdout). - -# EXAMPLES - -*echo foobar* - Output the string "foobar" to standard output. - -*echo foo bar baz* - Output the string "foo bar baz" to standard output. - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project - Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/false.1 b/man/false.1 deleted file mode 100644 index 0a0bc92..0000000 --- a/man/false.1 +++ /dev/null @@ -1,24 +0,0 @@ -FALSE(1) "Ferass' Base System" - -# NAME - -false \- Return false value - -# SYNOPSIS - -*false* - -# DESCRIPTION - -Return false value. - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project \- Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/sleep.1 b/man/sleep.1 deleted file mode 100644 index 5d1372f..0000000 --- a/man/sleep.1 +++ /dev/null @@ -1,35 +0,0 @@ -SLEEP(1) "Ferass' Base System" - -# NAME - -sleep \- suspend execution for an interval - -# SYNOPSIS - -*sleep* _time_ - -# DESCRIPTION - -Suspend execution for an interval. - -# EXAMPLES - -*sleep 1* - Suspend execution for one second. - -*sleep 60* - Suspend execution for 1 minute (60 seconds). - -*sleep 90* - Suspend execution for 1 minute and 30 seconds (90 seconds). - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project - Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/true.1 b/man/true.1 deleted file mode 100644 index 422c7e2..0000000 --- a/man/true.1 +++ /dev/null @@ -1,24 +0,0 @@ -TRUE(1) "Ferass' Base System" - -# NAME - -true \- Return true value - -# SYNOPSIS - -*true* - -# DESCRIPTION - -Return true value. - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project \- Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/man/uname.1 b/man/uname.1 deleted file mode 100644 index 9efbdfc..0000000 --- a/man/uname.1 +++ /dev/null @@ -1,59 +0,0 @@ -UNAME(1) "Ferass' Base System" - -# NAME - -uname - return system information - -# SYNOPSIS - -*uname* [-*amnrsv*] - -# DESCRIPTION - -Return system information. - -With no argument, write the operating system name. - -*-a* - Behave as if -mnrsv were specified. - -*-m* - Write the name of the hardware architecture on which the system is running - to standard output. - -*-n* - Write the name of this network hostname node to standard output. - -*-r* - Write the current release level of the operating system implementation. - -*-s* - Write the name of the running operating system implementation. - -*-v* - Write the current version of this release of the operating system - implementation. - -# EXAMPLES - -*uname* - Write the name of the running operating system implementation to standard - output. - -*uname -mnrsv* - Same as uname -a. - -*uname -v* - Write the current version of this release of the operating system - implementation. - -# AUTHOR - -Written by Ferass EL HAFIDI as part of the fases -project - Ferass' Base System. - -Source code is at http://git.vitali64.duckdns.org/utils/fases.git. - -# COPYRIGHT - -Copyright (C) 2022 Ferass EL HAFIDI diff --git a/sh/Makefile b/sh/Makefile deleted file mode 100644 index e2eb1b1..0000000 --- a/sh/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# -# Copyright (C) 2022 Ferass EL HAFIDI -# Copyright (C) 2022 Leah Rowe -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -include ../config.mk - -# Commands -# ======== - -all: clean sh - -sh: sh.o - $(CC) $(CFLAGS) *.o -o sh - rm -f version.h - -clean: - rm -f *.o - rm -Rf sh - -# Utilities -# ========= - -sh.o: - echo "#ifndef VERSION_H" > version.h - echo "#define VERSION_H" >> version.h - echo "#define COMPILETIME \"$$(date)\"" >> version.h - echo >> version.h - echo "#endif" >> version.h - for s in *.c; do $(CC) $(CFLAGS) $(NOLINKER) $$s -o $${s%.c}.o; done diff --git a/sh/commands.c b/sh/commands.c deleted file mode 100644 index 0c91456..0000000 --- a/sh/commands.c +++ /dev/null @@ -1,50 +0,0 @@ -/* sh - the standard command language interpreter - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* POSIX Header Files */ -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <string.h> - -/* sh Header Files */ -#include "commands.h" - -int builtin_cd(int argc, char *argv[]); - -/* *** COMMANDS *** */ - -/* cd - change directory */ - -int builtin_cd(int argc, char *argv[]) { - if (argc > 1 && chdir(argv[1]) == -1 && errno) { - printf("sh: cd: %s\n", strerror(errno)); - return errno; - } - return 0; -} diff --git a/sh/commands.h b/sh/commands.h deleted file mode 100644 index ce35012..0000000 --- a/sh/commands.h +++ /dev/null @@ -1,34 +0,0 @@ -/* sh - the standard command language interpreter - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef COMMANDS_H -#define COMMANDS_H - -int builtin_cd(int argc, char *argv[]); - -#endif /* COMMANDS_H */ diff --git a/sh/parser.c b/sh/parser.c deleted file mode 100644 index f1efddc..0000000 --- a/sh/parser.c +++ /dev/null @@ -1,114 +0,0 @@ -/* sh - the standard command language interpreter - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#define _POSIX_C_SOURCE 200809L - -/* POSIX Header Files */ -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> -#include <signal.h> - -/* sh Header Files */ -#include "parser.h" -#include "commands.h" - -int parseCommand(int, char **); -int splitCommand(char [4096], char *[4096]); - -/* USAGE - * ----- - * parseCommand(name); - * - * DESCRIPTION - * ----------- - * Parse a shell command and determine if the command to run is built-in or - * external. It then runs the command accordinately. - * <It also could in the future handle tokens.> - */ - -int parseCommand(int argc, char *argv[]) { - struct sigaction signal_action; - int status_code = 0, err = 0; - pid_t isparent; - if (argc == 0) return 0; /* There's no argument. */ - if (!strcmp(argv[0], "cd")) return builtin_cd(argc, argv); - /* The command isn't built-in. */ - isparent = fork(); - wait(&status_code); - if (!isparent) { - /* Do not ignore SIGINT when in a child process. */ - signal_action.sa_handler = SIG_DFL; - sigemptyset(&signal_action.sa_mask); - sigaction(SIGINT, &signal_action, NULL); - /* Some sh implementations manually search for the command in PATH. - * This is not needed here because execvp is going to search for - * that command in PATH anyway. - */ - status_code = execvp(argv[0], argv); - /* If the child process is still alive, we know execvp(3) failed. */ - exit(-errno); - } - /* This code may be used to store the exit value in $?. */ - //if (errno != EINTR && WEXITSTATUS(status_code) !=) return WEXITSTATUS(status_code); - //else return 0; - err = WEXITSTATUS(status_code); - if (err-256 == -E2BIG || err-256 == -EACCES || err-256 == -EINVAL || - err-256 == -ELOOP || - err-256 == -ENAMETOOLONG || err-256 == -ENOENT || err-256 == -ENOTDIR) - printf("sh: %s: %s\n", argv[0], strerror(-(err-256))); - return err; -} - -/* USAGE - * ----- - * splitCommand(name, dest); - * - * DESCRIPTION - * ----------- - * This splits a command string in multiple words. - * The array command can then be ran using execvp(3). It - * also returns an int that can be used as argc. - */ - -int splitCommand(char name[4096], char *splitted_name[4096]) { - long unsigned int array_index = 1; - char *token; - if ((token = strtok(name, " ")) != NULL && token[0] != '#') - splitted_name[0] = token; - else return 0; - /* WARNING: Not thread-safe! */ - for (; (token = strtok(NULL, " ")) != NULL && - token[0] != '#' && - (splitted_name[array_index] = token); array_index++) - /* Do nothing. */ ; - return array_index; -} - diff --git a/sh/parser.h b/sh/parser.h deleted file mode 100644 index a006024..0000000 --- a/sh/parser.h +++ /dev/null @@ -1,35 +0,0 @@ -/* sh - the standard command language interpreter - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef PARSER_H -#define PARSER_H - -int parseCommand(int, char **); -int splitCommand(char [4096], char *[4096]); - -#endif /* PARSER_H */ diff --git a/sh/sh.c b/sh/sh.c deleted file mode 100644 index 2e44d9e..0000000 --- a/sh/sh.c +++ /dev/null @@ -1,158 +0,0 @@ -/* sh - the standard command language interpreter - * Copyright (C) 2022 Ferass EL HAFIDI - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* Here's the POSIX specification of sh: */ -/* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html */ - -/* Define feature test macro. It doesn't compile with gcc without that for - * some reason. - */ -#define _POSIX_C_SOURCE 200809L - -/* POSIX Header files */ -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <fcntl.h> -#include <errno.h> -#include <stdint.h> -#include <sys/wait.h> -#include <spawn.h> -#include <libgen.h> -#include <signal.h> - -/* Our own header files */ -#include "parser.h" -#include "version.h" - -#ifndef COMPILETIME -#define COMPILETIME -#endif - -#warning "This shell implementation is really buggy and incomplete. \ - Please don't use this as a /bin/sh replacement." - -void commandLoop(); -int getopt(int argc, char *const argv[], const char *optstring); -char *pathSearch(const char *path, const char *name); -void printUsage(); - -int main(int argc, char *const argv[]) { - int argument, i = 1; - FILE *file; - char param[256]; - struct sigaction signal_action; - signal_action.sa_handler = SIG_IGN; - sigemptyset(&signal_action.sa_mask); - for (; i <= 256; i++) param[i] = 0; - - while ((argument = getopt(argc, argv, "c")) != -1) { - if (argument == '?') { - printUsage(); - return 1; - } - param[(uint8_t)argument] = argument; - } - argc -= optind; - argv += optind; - - sigaction(SIGINT, &signal_action, NULL); - if (errno) return errno; - - if (argv[0]) { - file = fopen(argv[0], "r"); - if (errno) return errno; - commandLoop(file); - } - else commandLoop(stdin); - return 0; -} - -/* USAGE - * ----- - * commandLoop() - * - * DESCRIPTION - * ----------- - * This function is the actual command prompt. - */ - -void commandLoop(FILE *filstr) { - struct sigaction signal_action; - char *prompt = getenv("PS1"); - char *path = getenv("PATH"); - char *token, *tokenstate; - char *command[4096]; - pid_t isparent; - char name[4096], tempstr[4096]; - int return_code; - int command_argc; - if (prompt == NULL) prompt = "$ "; - for (;;) { - for (int i = 0; i <= 4096; i++) { - name[i] = 0; /* (Re)Initialise name and command, - * very important. */ - command[i] = 0; - } - setvbuf(stdout, NULL, _IONBF, 0); - if (filstr == stdin && isatty(STDIN_FILENO)) printf(prompt); - if (fgets(name, 4096, filstr) == NULL) - break; - //read(fildes, name, 4096); - if (!strcmp(name, "\n")) - continue; - else if (*name == 0 || *name == EOF) { - putchar('\n'); - break; - } - name[strlen(name) - 1] = 0; - strcpy(tempstr, name); /* We don't want to override `name`. */ - if (strtok(tempstr, ";") != NULL && strtok(NULL, ";") != NULL) { - /* Hacky wacky hack. */ - strcpy(tempstr, name); - token = strtok_r(tempstr, ";", &tokenstate); - for (; token != NULL;) { - command_argc = splitCommand(token, command); /* See parser.c */ - parseCommand(command_argc, command); /* See parser.c */ - token = strtok_r(NULL, ";", &tokenstate); - } - } - else { - command_argc = splitCommand(name, command); /* See parser.c */ - parseCommand(command_argc, command); /* See parser.c */ - } - } -} - -void printUsage() { - printf("Ferass' Base System. (%s)\n\n" - "Usage: sh [-c command_string]\n\n" - "The standard command language interpreter.\n\n" - "\t-c command_string\tExecute command_string and exit.\n", COMPILETIME); -} |