Compare commits

...

20 Commits
peek ... main

Author SHA1 Message Date
DTB
f1f5ac1788 Bonsix fork 2024-05-08 08:25:34 -06:00
DTB
7f59c3b617 Remove sleep(1)s man page; see the POSIX man page 2024-05-08 07:56:07 -06:00
DTB
9ef6289e00 Merge remote-tracking branch 'origin/sleep' 2024-05-08 07:53:38 -06:00
DTB
ba55c4c8e7
sleep.1: add copyright header 2024-05-03 21:32:10 -06:00
DTB
003f5aeb1f
Makefile: add sleep to the all recipe 2024-05-03 21:30:39 -06:00
DTB
327c71c8ae
sleep.1: import from trinity/src 2024-05-03 21:29:49 -06:00
DTB
b06c1d5488
sleep(1): reduce dependence on sysexits 2024-05-03 21:22:38 -06:00
DTB
82f6c46b64
Makefile: update sleep recipe 2024-05-03 21:22:07 -06:00
DTB
81c657ec3e
Merge branch 'main' into sleep 2024-05-03 21:19:19 -06:00
9093b06166
Merge branch 'manpage-install' 2024-04-27 12:58:50 -06:00
DTB
6132c9bf47
Merge branch 'main' into scrut-sysexits 2024-04-26 19:37:34 -06:00
DTB
919b171400
scrut(1): conditionally include non-POSIX sysexits.h 2024-04-26 19:35:33 -06:00
DTB
8e38db92c7
scrut(1): update copyright header 2024-04-26 19:33:45 -06:00
DTB
adc9dbded5
scrut(1): changed return status 1 to EXIT_FAILURE 2024-04-26 19:30:33 -06:00
488351da39
scrut(1): changed return status 0 to EXIT_SUCCESS 2024-04-25 16:46:05 -06:00
d8b54fdbf5
Makefile: fixes erroneous whitespace 2024-04-25 12:43:31 -06:00
f6aac60aee
Makefile: fixed manpage install location 2024-04-25 12:40:20 -06:00
DTB
61382c34d9
mm(1): error out when given positional arguments 2024-03-31 22:54:03 -06:00
DTB
82a941eee3
sleep(1): initial implementation 2024-03-21 20:41:05 -06:00
DTB
e674027b3e
Makefile: add sleep(1) 2024-03-21 20:40:19 -06:00
5 changed files with 99 additions and 52 deletions

View File

@ -17,6 +17,8 @@
DESTDIR ?= dist
PREFIX ?= /usr/local
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|| printf '/share/man\n'
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
| sed -n 's/sysexits\.h//p' || printf 'include\n'
@ -28,7 +30,7 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
CFLAGS += -I$(SYSEXITS)
.PHONY: all
all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
all: dj false fop hru intcmp mm npc rpn scrut sleep str strcmp swab true
build:
# keep build/include until bindgen(1) has stdin support
@ -42,7 +44,7 @@ clean:
dist: all
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
cp docs/*.1 $(DESTDIR)/$(PREFIX)/share/man/man1
cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
.PHONY: install
install: dist
@ -102,7 +104,6 @@ mm: build/bin/mm
build/bin/mm: src/mm.c build
$(CC) $(CFLAGS) -o $@ src/mm.c
.PHONY: npc
npc: build/bin/npc
build/bin/npc: src/npc.c build
@ -118,6 +119,13 @@ scrut: build/bin/scrut
build/bin/scrut: src/scrut.c build
$(CC) $(CFLAGS) -o $@ src/scrut.c
.PHONY: sleep
sleep: build/bin/sleep
build/bin/sleep: src/sleep.rs build rustlibs
$(RUSTC) $(RUSTFLAGS) \
--extern sysexits=build/o/libsysexits.rlib \
-o $@ src/sleep.rs
.PHONY: str
str: build/bin/str
build/bin/str: src/str.c build

57
README
View File

@ -1,27 +1,27 @@
“Seek not to walk the path of the masters; seek what they sought.”
Matsuo Basho
For the Bonsai coreutils, a better Unix toolset, please visit
<https://git.tebibyte.media/bonsai/coreutils>.
The Bonsai core utilities are the result of the careful examination of the
current state of POSIX and Unix utilies. The Unix Philosophy, “do one thing and
do it well” is its core but these tools do not cling to the names of the past.
wwwww /
wWWWWWw /_ _____ _ * "It's not a very good tree, but
w|||w / \/ \ / | /\ / /|/ occasionally it bears fruit!"
_,|||._ _/\__/|__// /_/_|_/_//|__
bonsix : "BOHN zix" : "Bonsai" but "POSIX"
The era of the original Unix tools has been long and fruitful, but they have
their flaws. The new, non-POSIX era of this project started with frustration
with the way certain tools work and how other projects that extend POSIX dont
make anything better.
The excellent Bonsai core utilities are the result of the careful examination
of the current state of POSIX and Unix utilities, ironing out wrinkles in the
implementations that ended up being worn by the POSIX standard. Bonsai's
guiding quote is this one from Matsuo Basho:
This project will not follow in the footsteps of GNU; extensions of POSIX will
not be found here. GNU extensions are a gateway to the misuse of the shell. The
Bonsai core utilities will intentionally discourage use of the shell for
purposes beyond its scope.
"Seek not to walk the path of the masters; seek what they sought."
See docs/ for more on the specific utilities currently implemented.
Unlike Bonsai, Bonsix intends to walk the path of the masters, implementing a
POSIX userland under an AGPLv3 license and taking inspiration from the
practices used by Bonsai.
Building
The coreutils require a POSIX-compliant environment to compile, including a C
compiler and preprocessor (cc(1) and cpp(1) by default) with the -idirafter
flag, a Rust compiler (rustc(1) by default), bindgen(1), and a POSIX-compliant
Bonsix requires an existing POSIX-compliant environment to compile, including a
C compiler and preprocessor (cc(1) and cpp(1) by default) and a POSIX-compliant
make(1) utility.
To build and install:
@ -32,29 +32,6 @@ $ make PREFIX="/your/preferred/location" install
To build with a different compiler than the default:
$ make CC=clang
$ make RUSTC=gccrs
To test the utilities:
$ make test
To remove all untracked files:
$ make clean
Read More
An Introduction to the Unix Shell
<https://porkmail.org/era/unix/shell>
Master Foo and the Ten Thousand Lines
<http://www.catb.org/~esr/writings/unix-koans/ten-thousand.html>
Master Foo Discourses on the Unix-Nature
<http://www.catb.org/~esr/writings/unix-koans/unix-nature.html>
Shell Programming!
<https://tldp.org/LDP/abs/html/why-shell.html>
--
Copyright © 20232024 Emma Tebibyte <emma@tebibyte.media>

View File

@ -106,6 +106,15 @@ oserr(char *s, char *r){
} \
return retval
/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and
* returns an exit status appropriate for a usage error. */
int usage(char *s){
fprintf(stderr, "Usage: %s (-aenu) (-i [input])... (-o [output])...\n", s);
return EX_USAGE;
}
int main(int argc, char *argv[]){
int c;
struct Files files[2]; /* {read, write} */
@ -178,12 +187,15 @@ int main(int argc, char *argv[]){
k = 1;
break;
default:
fprintf(stderr, "Usage: %s (-aenu) (-i [input])..."
" (-o [output])...\n", argv[0]);
retval = EX_USAGE;
retval = usage(argv[0]);
terminate;
}
if(optind != argc){
retval = usage(argv[0]);
terminate;
}
files[0].s += files[0].s == 0;
files[1].s += files[1].s == 0;

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2023 DTB <trinity@trinity.moe>
* Copyright (c) 20232024 DTB <trinity@trinity.moe>
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify it under
@ -17,13 +18,15 @@
*/
#include <stdio.h> /* fprintf(3), stderr, NULL */
#include <stdlib.h> /* EXIT_FAILURE */
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
#include <string.h> /* memset(3), strchr(3) */
#ifndef EX_USAGE
# include <sysexits.h>
#endif
#include <unistd.h> /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */
#include <sys/stat.h> /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR,
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
* S_ISUID, S_ISVTX */
#include <sysexits.h>
static char args[] = "bcdefghkprsuwxLS";
static char ops[(sizeof args) / (sizeof *args)];
@ -57,7 +60,7 @@ int main(int argc, char *argv[]){
argv += optind;
do{ if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1)
return 1; /* doesn't exist or isn't stattable */
return EXIT_FAILURE; /* doesn't exist or isn't stattable */
for(i = 0; ops[i] != '\0'; ++i)
if(ops[i] == 'e')
@ -97,8 +100,8 @@ usage: fprintf(stderr, "Usage: %s (-%s) [file...]\n",
&& !S_ISLNK(buf.st_mode))
|| (ops[i] == 'S'
&& !S_ISSOCK(buf.st_mode)))
return 1;
return EXIT_FAILURE;
}while(*++argv != NULL);
return 0;
return EXIT_SUCCESS;
}

47
src/sleep.rs Normal file
View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 DTB <trinity@trinity.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero 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 Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
use std::{
env::args,
process::ExitCode,
thread::sleep,
time::Duration
};
extern crate sysexits;
use sysexits::EX_USAGE;
fn usage(s: &str) -> ExitCode {
eprintln!("Usage: {} [seconds]", s);
ExitCode::from(EX_USAGE as u8)
}
fn main() -> ExitCode {
let argv = args().collect::<Vec<String>>();
if argv.len() == 2 {
if let Ok(s) = argv[1].parse::<u64>() {
sleep(Duration::from_secs(s));
ExitCode::SUCCESS
} else {
usage(&argv[0])
}
} else {
usage(&argv[0])
}
}