Compare commits
39 Commits
stris
...
getopt-for
| Author | SHA1 | Date | |
|---|---|---|---|
|
a3bbad467e
|
|||
|
07a2f1efc2
|
|||
|
accec33301
|
|||
|
444e682f02
|
|||
|
fde682a10e
|
|||
|
87c9e29932
|
|||
|
1037e32e6e
|
|||
|
5c70852890
|
|||
|
8ec18ccf75
|
|||
|
3bfdc62035
|
|||
|
7d174c1f7c
|
|||
|
3f41110617
|
|||
|
7a69e1d516
|
|||
|
64e943f64a
|
|||
|
16dcd4da37
|
|||
|
d892fa1cac
|
|||
|
3862a95151
|
|||
|
264ae2e82c
|
|||
|
1634761593
|
|||
|
0b40360e7e
|
|||
|
590d98d7f7
|
|||
|
07aa9a9abc
|
|||
|
fce49bed85
|
|||
|
62b38a6765
|
|||
|
23521bade5
|
|||
|
3b774cab27
|
|||
|
e889159619
|
|||
|
fbacfecce8
|
|||
|
579ff65b67
|
|||
|
334433536b
|
|||
|
e9058803d3
|
|||
|
71d4d6ba05
|
|||
|
821f5d09e9
|
|||
|
a4a556a5b6
|
|||
|
e2c03842a3
|
|||
|
0fd66bff38
|
|||
|
0c4923016e
|
|||
|
d2f8fb8106
|
|||
|
cd875df547
|
40
CONTRIBUTING
40
CONTRIBUTING
@@ -1,26 +1,29 @@
|
||||
Make sure to read our code of conduct in the CONDUCT file.
|
||||
|
||||
When contributing a pull request to the main branch, please sign your commits
|
||||
with a PGP key and add your name and the year to the bottom of the list of
|
||||
copyright holders for the file. For example, an existing copyright header might
|
||||
read:
|
||||
|
||||
Copyright Information
|
||||
=====================
|
||||
|
||||
When editing a file, create a copyright statement correlated to your
|
||||
identity so that it is easier to keep track of who has touched what file.
|
||||
Pseudonymous contributions are welcome (and encouraged). Place new copyright
|
||||
information below existing copyright information. If there is an existing
|
||||
copyright statement:
|
||||
|
||||
* Copyright (c) 2022–2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
|
||||
You would add your name below it like this:
|
||||
you would add your name below it like this:
|
||||
|
||||
* Copyright (c) 2022–2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
* Copyright (c) 20XX Your Name <your e-mail address or website>
|
||||
|
||||
We accept contributions from people using aliases.
|
||||
|
||||
Only list years in which you modified the source file. For example:
|
||||
|
||||
* Copyright (c) 2020–2021, 2023 Your Name <your-address@example.com>
|
||||
|
||||
This header shows that “Your Name” worked on this source file in 2020, 2021, and
|
||||
2023. Please use the en dash (“–”) to separate the years in the copyright
|
||||
notice.
|
||||
2023. Please use the en dash (“–”, U+2013) to separate consecutive years in the
|
||||
copyright notice.
|
||||
|
||||
If you are contributing a new file, please prepend the following license header
|
||||
text to it, replacing the proper text on the copyright line:
|
||||
@@ -92,6 +95,10 @@ notice:
|
||||
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
Style
|
||||
=====
|
||||
|
||||
Make sure lines never exceed 80 columns in width when using four-character
|
||||
indentation steps. This helps contributors with smaller screens, those using
|
||||
side-by-side editor windows or panes, and those who have no text wrapping in
|
||||
@@ -104,8 +111,13 @@ style guide for the usage text’s output format [0].
|
||||
If committing a new utility, please include tests and documentation (see
|
||||
tests/ and docs/) for the new tool.
|
||||
|
||||
If committing a new source file, format the commit message following these
|
||||
guidelines:
|
||||
Committing
|
||||
==========
|
||||
|
||||
When contributing to Bonsai, please sign your commit with a PGP key and create
|
||||
the commit with an identity which can be easily contacted.
|
||||
|
||||
Format commit messages following these guidelines:
|
||||
|
||||
$ git commit -m 'tool(1): add feature x'
|
||||
|
||||
@@ -131,7 +143,13 @@ $ git commit -m 'tool(1): fix #42 & add feature x'
|
||||
|
||||
Commit messages should be written in the present tense.
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
||||
[0] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
||||
|
||||
|
||||
--
|
||||
This work © 2023–2024 by Emma Tebibyte is licensed under CC BY-SA 4.0. To view a
|
||||
copy of this license, visit <http://creativecommons.org/licenses/by-sa/4.0/>
|
||||
|
||||
27
Makefile
27
Makefile
@@ -19,12 +19,12 @@ PREFIX ?= /usr/local
|
||||
# for conditionally compiling OS features
|
||||
OS != uname
|
||||
OS_INCLUDE != test -e include/$(OS).mk && printf 'include/$(OS).mk\n' \
|
||||
|| include/None.mk
|
||||
|| printf '/dev/null\n'
|
||||
|
||||
# normalized prefix
|
||||
PREFIX_N != dirname $(PREFIX)/.
|
||||
PREFIX_N != realpath $(PREFIX)
|
||||
MANDIR != test $(PREFIX_N) = / && printf '/usr/share/man\n' \
|
||||
|| printf '/share/man\n'
|
||||
|| printf '$(PREFIX_N)/man\n'
|
||||
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | tr ' ' '\n' \
|
||||
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
||||
|
||||
@@ -42,7 +42,7 @@ BIN = build/bin
|
||||
default: all test
|
||||
|
||||
.PHONY: all
|
||||
all: dj false fop hru intcmp mm npc rpn scrut strcmp stris swab true
|
||||
all: dj false fop hru intcmp mm npc peek rpn scrut str strcmp swab true
|
||||
|
||||
# keep build/include until bindgen(1) has stdin support
|
||||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
||||
@@ -54,9 +54,9 @@ clean:
|
||||
rm -rf build dist
|
||||
|
||||
dist: all docs
|
||||
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
||||
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
||||
cp build/docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
||||
mkdir -p $(DESTDIR)/$(PREFIX_N)/bin $(DESTDIR)/$(MANDIR)/man1
|
||||
cp build/bin/* $(DESTDIR)/$(PREFIX_N)/bin
|
||||
cp build/docs/*.1 $(DESTDIR)/$(MANDIR)/man1
|
||||
|
||||
.PHONY: install
|
||||
install: dist
|
||||
@@ -137,6 +137,11 @@ npc: build/bin/npc
|
||||
build/bin/npc: src/npc.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/npc.c
|
||||
|
||||
.PHONY: peek
|
||||
peek: build/bin/peek
|
||||
build/bin/peek: src/peek.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/peek.c
|
||||
|
||||
.PHONY: rpn
|
||||
rpn: build/bin/rpn
|
||||
build/bin/rpn: src/rpn.rs build rustlibs
|
||||
@@ -147,10 +152,10 @@ scrut: build/bin/scrut
|
||||
build/bin/scrut: src/scrut.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
||||
|
||||
.PHONY: stris
|
||||
stris: build/bin/stris
|
||||
build/bin/stris: src/stris.rs build rustlibs
|
||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/stris.rs
|
||||
.PHONY: str
|
||||
str: build/bin/str
|
||||
build/bin/str: src/str.c build
|
||||
$(CC) $(CFLAGS) -o $@ src/str.c
|
||||
|
||||
.PHONY: strcmp
|
||||
strcmp: build/bin/strcmp
|
||||
|
||||
49
README
49
README
@@ -1,24 +1,28 @@
|
||||
“Seek not to walk the path of the masters; seek what they sought.”
|
||||
– Matsuo Basho
|
||||
|
||||
The Bonsai harakit utilities are a replacement for standard POSIX utilities
|
||||
which aim to fill its niche while expanding on their capabilities. These new
|
||||
tools are the result of the careful examination of the current state of POSIX
|
||||
and Unix utilies. The Unix Philosophy of “do one thing and do it well” are their
|
||||
core but they avoid clinging to the past.
|
||||
Bonsai’s Harakit is an alternative to the standard POSIX utilities that aims to
|
||||
be simpler, easier, and more powerful. These tools are the result of careful
|
||||
examination of the current state common Unix utilities, POSIX-compliant and
|
||||
otherwise, following frustrations with design decisions and implementation
|
||||
details. They represent a vision of accomplishing everyday use cases with tools
|
||||
that follow the Unix philosophy of “do one thing and do it well” without
|
||||
clinging to the past.
|
||||
|
||||
The era of the original Unix tools has been long and fruitful, but they have
|
||||
their flaws. This project originated from frustrations with the way certain
|
||||
tools work and how other projects that extend POSIX don’t make anything better.
|
||||
|
||||
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
|
||||
harakit utilities will intentionally discourage use of the shell for purposes
|
||||
beyond its scope.
|
||||
The intent of Harakit is not to conform to or extend POSIX, like the GNU or BSD
|
||||
utilities do, but to invent new utilities to perform the same tasks in more
|
||||
intuitive ways. GNU and BSD extensions are convenient but often unhealthy,
|
||||
forgetting the purposes of the tools they extend, or building into existing
|
||||
utilities features that would be more useful as their own tools to be used
|
||||
anywhere. Other utility sets aim to provide a number of fully-featured
|
||||
programs to be used individually, Harakit utilities are meant to be easily
|
||||
composable and work together in pipelines.
|
||||
|
||||
See docs/ for more on the specific utilities currently implemented.
|
||||
|
||||
|
||||
Building
|
||||
========
|
||||
|
||||
Harakit utilities require a POSIX-compliant environment to compile, including a
|
||||
C compiler and preprocessor (cc(1) and cpp(1) by default), an edition 2023 Rust
|
||||
@@ -43,7 +47,22 @@ To remove all build and distributable files:
|
||||
|
||||
$ make clean
|
||||
|
||||
|
||||
Contributing
|
||||
============
|
||||
|
||||
See the CONTRIBUTING file for contribution guidelines.
|
||||
|
||||
|
||||
Community
|
||||
=========
|
||||
|
||||
xmpp://bonsai@covenant.murderu.us
|
||||
irc://feeling.murderu.us/#bonsai
|
||||
|
||||
|
||||
Read More
|
||||
=========
|
||||
|
||||
An Introduction to the Unix Shell
|
||||
<https://porkmail.org/era/unix/shell>
|
||||
@@ -57,6 +76,10 @@ Master Foo Discourses on the Unix-Nature
|
||||
Shell Programming!
|
||||
<https://tldp.org/LDP/abs/html/why-shell.html>
|
||||
|
||||
UNIX Style, or cat -v Considered Harmful
|
||||
<http://harmful.cat-v.org/cat-v/>
|
||||
|
||||
|
||||
--
|
||||
Copyright © 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
Copyright © 2024 DTB <trinity@trinity.moe>
|
||||
|
||||
111
docs/peek.1
Normal file
111
docs/peek.1
Normal file
@@ -0,0 +1,111 @@
|
||||
.\" Copyright (c) 2023-2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH PEEK 1 2024-08-14 "Harakit X.X.X"
|
||||
.SH NAME
|
||||
peek \(en read from the standard input, furtively
|
||||
.\"
|
||||
.SH SYNOPSIS
|
||||
|
||||
peek
|
||||
.RB [ -i ]
|
||||
.\"
|
||||
.SH DESCRIPTION
|
||||
|
||||
Read input from the standard input with terminal echo disabled.
|
||||
.\"
|
||||
.SH OPTIONS
|
||||
|
||||
.IP \fB-i\fP
|
||||
Allows input to come from sources other than terminals (pipes).
|
||||
.\"
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
In the event of an error, a debug message will be printed and the program will
|
||||
exit with the appropriate
|
||||
.BR sysexits.h (3)
|
||||
error code.
|
||||
|
||||
In order to ensure the user\(cqs terminal is still usable after premature
|
||||
termination, the program attempts to handle the SIGINT signal; if it cannot,
|
||||
an error message is printed and execution continues. If the program is
|
||||
interrupted, it exits unsuccessfully without an error message.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
This tool was originally written to accept passwords in shell scripts as an
|
||||
extremely simple alternative to the GNU Privacy Guard project\(cqs
|
||||
.BR pinentry (1)
|
||||
utility.
|
||||
|
||||
Accepting input without showing what is being typed is useful when keying in
|
||||
secrets in public settings or in places where surveillance cameras are
|
||||
installed.
|
||||
.\"
|
||||
.SH CAVEATS
|
||||
|
||||
This program does nothing to prevent others from seeing the key presses input to
|
||||
a keyboard. It also does not protect against the sound of typing being analyzed
|
||||
to determine what was input without needing to see screen or keyboard.
|
||||
|
||||
Accepting secrets in shell scripts is probably not advisable.
|
||||
|
||||
On systems that support it, the
|
||||
.BR ioctl (2)
|
||||
command TIOCSTI can be used to insert characters into the standard input. This
|
||||
doesn't allow snooping but can be used for general mischief.
|
||||
.\"
|
||||
.SH EXAMPLES
|
||||
|
||||
This is an
|
||||
.BR sh (1p)
|
||||
command line that hashes a given password. It uses
|
||||
.BR head (1p)
|
||||
to only accept one line of input,
|
||||
.BR xargs (1p)
|
||||
and
|
||||
.BR printf (1p)
|
||||
to strip the trailing newline,
|
||||
.BR htpasswd (1)
|
||||
from Apache\(cqs utilities to hash the input with the bcrypt algorithm, and
|
||||
.BR cut (1p)
|
||||
to print only the resulting hash:
|
||||
|
||||
.RS
|
||||
$ peek | head -n 1 | xargs printf '%s' | htpasswd -nBi _ | cut -d : -f 2
|
||||
.RE
|
||||
|
||||
This is an
|
||||
.BR sh (1p)
|
||||
command line that allows a user to write blindly into a text file but displaying
|
||||
only written lines. Some writers have the habit of prematurely revising their
|
||||
work and use tools with functionality similar to this to prevent it.
|
||||
It uses
|
||||
.BR mm (1)
|
||||
to pipe the output of the program to both the standard error and the regular
|
||||
file writing.txt:
|
||||
|
||||
.RS
|
||||
$ echo Input ^D to quit. && peek | mm -eo - >writing.txt
|
||||
.RE
|
||||
.\"
|
||||
.SH AUTHOR
|
||||
|
||||
Written by DTB
|
||||
.MT trinity@trinity.moe
|
||||
.ME .
|
||||
.\"
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright \(co 2023-2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
.\"
|
||||
.SH SEE ALSO
|
||||
.BR ioctl (2),
|
||||
.BR ioctl_tty (2),
|
||||
.BR read (1p),
|
||||
.BR sh (1p),
|
||||
.BR stty (1p)
|
||||
59
docs/str.1
Normal file
59
docs/str.1
Normal file
@@ -0,0 +1,59 @@
|
||||
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH STR 1 2024-06-17 "Harakit X.X.X"
|
||||
.SH NAME
|
||||
str \(en test string arguments
|
||||
.\"
|
||||
.SH SYNOPSIS
|
||||
|
||||
str
|
||||
.B type string...
|
||||
.\"
|
||||
.SH DESCRIPTION
|
||||
|
||||
Test the character types of string arguments.
|
||||
|
||||
The tests in this program are equivalent to the functions with the same names in
|
||||
.BR ctype.h (0p)
|
||||
and are the methods by which string arguments are tested.
|
||||
.\"
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
If all tests pass, the program will exit successfully. If any of the tests fail,
|
||||
the program will exit unsuccessfully with an error code of 1.
|
||||
|
||||
When invoked incorrectly, a debug message will be printed and the program will
|
||||
exit with the appropriate
|
||||
.BR sysexits.h (3)
|
||||
error code.
|
||||
.\"
|
||||
.SH CAVEATS
|
||||
|
||||
None of an empty string\(cqs contents pass any of the tests, so the program will
|
||||
exit unsuccessfully if one is specified.
|
||||
|
||||
There\(cqs no way of knowing which argument failed the test without re-testing
|
||||
arguments individually.
|
||||
|
||||
If a character in a string isn\(cqt valid ASCII, the program will exit
|
||||
unsuccessfully.
|
||||
.\"
|
||||
.SH AUTHOR
|
||||
|
||||
Written by DTB
|
||||
.MT trinity@trinity.moe
|
||||
.ME .
|
||||
.\"
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
.\"
|
||||
.SH SEE ALSO
|
||||
.BR ctype (3p),
|
||||
.BR strcmp(1),
|
||||
.BR ascii(7)
|
||||
104
docs/stris.1
104
docs/stris.1
@@ -1,104 +0,0 @@
|
||||
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH STRIS 1 2024-10-22 "Harakit X.X.X"
|
||||
.SH NAME
|
||||
stris \(en test the character types of string arguments
|
||||
.\"
|
||||
.SH SYNOPSIS
|
||||
|
||||
stris
|
||||
.RB [ -7bcdlu ]
|
||||
.RB [ -i\ inclusions ]
|
||||
.RB strings...
|
||||
.\"
|
||||
.SH DESCRIPTION
|
||||
|
||||
Test each character in any number of string arguments, ensuring each meets any
|
||||
of the parameters specified by program options.
|
||||
.\"
|
||||
.SH OPTIONS
|
||||
|
||||
.IP \fB-7\fP
|
||||
Tests if the character encoding is ASCII.
|
||||
.IP \fB-b\fP
|
||||
Tests if characters are whitespace.
|
||||
.IP \fB-c\fP
|
||||
Tests if characters are control characters.
|
||||
.IP \fB-d\fP
|
||||
Tests if characters are numeric.
|
||||
.IP \fB-i\fP \fIinclusions...\fP
|
||||
In addition to specified options, also permits characters in
|
||||
.IR inclusions .
|
||||
.IP \fB-l\fP
|
||||
Tests if characters are in lower case.
|
||||
.IP \fB-u\fP
|
||||
Tests if characters are in upper case.
|
||||
.\"
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
If no test cases pass for a character in
|
||||
.IR strings ,
|
||||
the program will exit unsuccessfully.
|
||||
|
||||
.SH CAVEATS
|
||||
|
||||
If no options are specified, the program will exit successfully as long as the
|
||||
input
|
||||
.I strings
|
||||
are legibly encoded.
|
||||
|
||||
Neither which test failed nor which of the
|
||||
.I strings
|
||||
failed a test cannot be known without further invocations of the program.
|
||||
|
||||
Characters that can be encoded losslessly into ASCII from UTF-8 but which
|
||||
are in an \(lqoverlong encoding\(rq, where the character was encoded with
|
||||
unnecessary leading zeroes causing it to span multiple bytes, won\(cqt be
|
||||
detected as ASCII.
|
||||
.\"
|
||||
.SH EXAMPLES
|
||||
|
||||
This is an
|
||||
.BR sh (1p)
|
||||
snippet which tests if an environment variable is an ASCII digit.
|
||||
|
||||
.RS
|
||||
stris -7 "$v" && stris -d "$v" && echo ASCII digit.
|
||||
.RE
|
||||
|
||||
This is an
|
||||
.BR sh (1p)
|
||||
snippet that tests if an environment variable is a hexadecimal number.
|
||||
|
||||
.RS
|
||||
stris -7 "$v" && stris -di ABCDEFabcdef "$v" && echo Hexadecimal number.
|
||||
.RE
|
||||
.\"
|
||||
.SH AUTHOR
|
||||
|
||||
Written by DTB
|
||||
.MT trinity@trinity.moe
|
||||
.ME .
|
||||
.\"
|
||||
.SH HISTORY
|
||||
|
||||
This program replaces the former str(1) which took the name of a function from
|
||||
.BR ctype (3p)
|
||||
as its first argument and checked the following strings against it;
|
||||
.BR str (1)
|
||||
exited unsuccessfully when it encountered any non-ASCII characters and could
|
||||
only have one parameter specified.
|
||||
.\"
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright \(co 2023\(en2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
.\"
|
||||
.SH SEE ALSO
|
||||
.BR ascii (7),
|
||||
.BR ctype (3p),
|
||||
.BR strcmp (1)
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: CC0
|
||||
*
|
||||
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
||||
@@ -10,9 +11,9 @@
|
||||
# include <unistd.h> /* pledge(2) */
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
#ifdef __OpenBSD__
|
||||
pledge(NULL, NULL);
|
||||
#endif
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ fn main() {
|
||||
let mut d = '\u{1E}'.to_string(); /* ASCII record separator */
|
||||
let mut optind = 1;
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("stdio proc exec");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
|
||||
@@ -86,7 +86,7 @@ fn main() -> ExitCode {
|
||||
return ExitCode::from(EX_USAGE as u8);
|
||||
}
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("stdio");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
|
||||
@@ -34,7 +34,6 @@ use sysexits::EX_USAGE;
|
||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||
#[cfg(target_os="openbsd")] use strerror::StrError;
|
||||
|
||||
|
||||
fn usage(s: &str) -> ExitCode {
|
||||
eprintln!("Usage: {} [-egl] integer integer...", s);
|
||||
ExitCode::from(EX_USAGE as u8)
|
||||
@@ -43,7 +42,7 @@ fn usage(s: &str) -> ExitCode {
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("stdio");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
|
||||
@@ -79,8 +79,8 @@ pub trait GetOpt {
|
||||
}
|
||||
|
||||
impl GetOpt for Vec<String> {
|
||||
fn getopt(&self, optstring: &str) -> Option<Opt> {
|
||||
let c_strings: Vec<_> = self
|
||||
fn getopt(&self, optstring: &str) -> Option<Opt> {
|
||||
let c_strings: Vec<_> = self
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|x| CString::new(x).unwrap().into_raw())
|
||||
@@ -91,11 +91,11 @@ impl GetOpt for Vec<String> {
|
||||
let argv = boxed as *const *mut c_char;
|
||||
|
||||
/* operations are separated out so that everything lives long enough */
|
||||
let opts = CString::new(optstring).unwrap().into_raw();
|
||||
let len = self.len() as c_int;
|
||||
let opts = CString::new(optstring).unwrap().into_raw();
|
||||
let len = self.len() as c_int;
|
||||
|
||||
unsafe {
|
||||
let ret = match getopt(len, argv, opts) {
|
||||
unsafe {
|
||||
let ret = match getopt(len, argv, opts) {
|
||||
/* From getopt(3p):
|
||||
*
|
||||
* The getopt() function shall return the next option character
|
||||
@@ -141,8 +141,8 @@ impl GetOpt for Vec<String> {
|
||||
* argv[optind] points to the string "--"
|
||||
*
|
||||
* getopt() shall return -1 after incrementing optind. */
|
||||
-1 => return None,
|
||||
opt => {
|
||||
-1 => return None,
|
||||
opt => {
|
||||
let arg: Option<String>;
|
||||
|
||||
if optarg.is_null() { arg = None; }
|
||||
@@ -162,13 +162,13 @@ impl GetOpt for Vec<String> {
|
||||
opt: Ok((opt as u8 as char).to_string()),
|
||||
})
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/* delloc argv (something online said I should do this) */
|
||||
let _ = Box::from_raw(boxed);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* tests (good) */
|
||||
|
||||
44
src/mm.rs
44
src/mm.rs
@@ -51,8 +51,8 @@ fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<_>>();
|
||||
let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]);
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
let promises = Promises::new("rpath stdio unveil");
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("cpath rpath stdio unveil wpath");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
@@ -76,29 +76,11 @@ fn main() -> ExitCode {
|
||||
Ok("t") => t = false,
|
||||
Ok("i") => { /* add inputs */
|
||||
let input = opt.arg().unwrap();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
let perms = UnveilPerms::new(vec!['r']);
|
||||
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
}
|
||||
}
|
||||
|
||||
ins.push(input);
|
||||
mode = Some(In); /* latest argument == -i */
|
||||
},
|
||||
Ok("o") => { /* add output */
|
||||
let output = opt.arg().unwrap();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
let perms = UnveilPerms::new(vec!['w', 'c']);
|
||||
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
}
|
||||
}
|
||||
|
||||
let output = opt.arg().unwrap();
|
||||
outs.push(output);
|
||||
mode = Some(Out); /* latest argument == -o */
|
||||
},
|
||||
@@ -124,7 +106,25 @@ fn main() -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
for input in &ins {
|
||||
let perms = UnveilPerms::new(vec!['r']);
|
||||
|
||||
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
}
|
||||
}
|
||||
|
||||
for output in &outs {
|
||||
let perms = UnveilPerms::new(vec!['c', 'w']);
|
||||
|
||||
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = unveil(None, None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
return ExitCode::from(EX_OSERR as u8);
|
||||
|
||||
147
src/peek.c
Normal file
147
src/peek.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2023–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/.
|
||||
*/
|
||||
|
||||
#include <signal.h> /* sigaction(2), signal(2), struct sigaction, SIGINT */
|
||||
#include <stdbool.h> /* bool */
|
||||
#include <stdio.h> /* fprintf(3), fgetc(3), perror(3), fputc(3), stderr, stdin,
|
||||
* stdout, EOF, NULL */
|
||||
#include <stdlib.h> /* exit(3), EXIT_FAILURE */
|
||||
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_USAGE */
|
||||
#include <termios.h> /* tcgetattr(3), tcsetattr(3), struct termios, ECHO */
|
||||
#include <unistd.h> /* getopt(3), isatty(3), pledge(2), unveil(2),
|
||||
* STDIN_FILENO */
|
||||
|
||||
char *program_name = "peek";
|
||||
|
||||
/* Restores terminal echo; otherwise when a user ^Cs the terminal would
|
||||
* continue to not display typed text. If sig isn't zero, this will terminate
|
||||
* the program. */
|
||||
static void
|
||||
restore_echo(int sig) {
|
||||
static struct termios t;
|
||||
|
||||
/* Failure isn't reported because this is the termination routine anyway;
|
||||
* errors will be obvious. */
|
||||
if (tcgetattr(STDIN_FILENO, &t) == 0) {
|
||||
t.c_lflag |= ECHO;
|
||||
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &t);
|
||||
}
|
||||
|
||||
if (sig != 0) { exit(EXIT_FAILURE); } /* Terminated by signal. */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int
|
||||
ioerr(char *argv0) {
|
||||
perror(argv0);
|
||||
restore_echo(0);
|
||||
return EX_IOERR;
|
||||
}
|
||||
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(stderr, "Usage: %s [-i]\n", argv0);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
bool is_term; /* Is stdin a terminal? */
|
||||
bool must_be_term = 1; /* Must it be? */
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio tty unveil", "") != 0 || unveil(NULL, NULL) != 0) {
|
||||
/* This isn't fatal; these return values could be cast to void just as
|
||||
* easily. */
|
||||
(void)perror(argv[0] == NULL ? argv[0] : program_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
is_term = isatty(STDIN_FILENO);
|
||||
|
||||
if (argc > 0) { /* option parsing */
|
||||
int c;
|
||||
|
||||
program_name = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "i")) != -1) {
|
||||
switch (c) {
|
||||
case 'i': must_be_term = 0; break;
|
||||
default: return usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > optind) { return usage(argv[0]); }
|
||||
}
|
||||
|
||||
if (!is_term && must_be_term) {
|
||||
(void)fprintf(
|
||||
stderr,
|
||||
"%s: Must be run in a terminal (specify -i to skip this check)\n",
|
||||
argv[0]
|
||||
);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
if (is_term) {
|
||||
{ /* Install signal handler */
|
||||
/* There isn't a difference in functionality between the signal(2)
|
||||
* and sigaction(2) methods. sigaction(2) is vastly preferred for
|
||||
* portability but some older systems only have signal(2). */
|
||||
/* Errors aren't terminating because the worst that happens is some
|
||||
* terminal phooeyness if things go awry. */
|
||||
#if defined _POSIX_C_SOURCE
|
||||
struct sigaction act = { 0 };
|
||||
|
||||
act.sa_handler = restore_echo;
|
||||
if (sigaction(SIGINT, &act, NULL) != 0) { perror(program_name); }
|
||||
#else
|
||||
if (signal(SIGINT, restore_echo) == SIG_ERR) {
|
||||
perror(program_name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
{ /* Banish terminal echo */
|
||||
/* This terminates when it fails because it's the whole point of
|
||||
* the program. */
|
||||
struct termios t;
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &t) != 0) {
|
||||
return ioerr(program_name);
|
||||
}
|
||||
t.c_lflag ^= ECHO;
|
||||
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &t) != 0) {
|
||||
return ioerr(program_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ /* Input loop */
|
||||
int c;
|
||||
|
||||
while ((c = fgetc(stdin)) != EOF) {
|
||||
if (fputc(c, stdout) == EOF) { return ioerr(program_name); }
|
||||
}
|
||||
}
|
||||
|
||||
if (is_term) { restore_echo(0); }
|
||||
|
||||
return EX_OK;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ fn round_precise(value: &f64, precision: usize) -> f64 {
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("stdio");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
|
||||
96
src/str.c
Normal file
96
src/str.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2023 Marceline Cramer <mars@tebibyte.media>
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <stdio.h> /* fprintf(3), perror(3) */
|
||||
#include <stdlib.h> /* size_t, EXIT_FAILURE */
|
||||
#include <string.h> /* strcmp(3) */
|
||||
#include <sysexits.h> /* EX_OSERR, EX_USAGE */
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
# include <unistd.h> /* pledge(2) */
|
||||
#endif
|
||||
|
||||
char *program_name = "str";
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
int (*f)(int);
|
||||
} ctypes[] = {
|
||||
{ "isalnum", isalnum },
|
||||
{ "isalpha", isalpha },
|
||||
{ "isblank", isblank },
|
||||
{ "iscntrl", iscntrl },
|
||||
{ "isdigit", isdigit },
|
||||
{ "isxdigit", isxdigit },
|
||||
{ "isgraph", isgraph },
|
||||
{ "islower", islower },
|
||||
{ "isprint", isprint },
|
||||
{ "ispunct", ispunct },
|
||||
{ "isspace", isspace },
|
||||
{ "isupper", isupper },
|
||||
{ NULL, NULL } /* marks end */
|
||||
};
|
||||
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(stderr, "Usage: %s type string...\n", argv0);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
size_t ctype; // selected from ctypes.h; index of ctype
|
||||
int retval; // initially fail but becomes success on the first valid char
|
||||
program_name = argv[0] == NULL ? program_name : argv[0];
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio", NULL) == -1) {
|
||||
perror(program_name);
|
||||
return EX_OSERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc < 3) { return usage(program_name); }
|
||||
|
||||
for ( /* iterate ctypes */
|
||||
ctype = 0;
|
||||
ctypes[ctype].f != NULL /* break at the end of ctypes */
|
||||
&& strcmp(argv[1], ctypes[ctype].name) != 0; /* break at match */
|
||||
++ctype
|
||||
);
|
||||
|
||||
if (ctypes[ctype].f == NULL) { return usage(argv[0]); }
|
||||
|
||||
/* iterate args */
|
||||
for (argv += 2, retval = EXIT_FAILURE; *argv != NULL; ++argv) {
|
||||
for (size_t i = 0; argv[0][i] != '\0'; ++i) { /* iterate arg bytes */
|
||||
/* First checks if argv[0][i] is valid ASCII; ctypes(3) don't
|
||||
* handle non-ASCII. This is bad. */
|
||||
if(
|
||||
(unsigned char)argv[0][i] < 0x80 // argv[0][i] is ASCII,
|
||||
&& !ctypes[ctype].f(argv[0][i]) // so use ctypes(3)
|
||||
) { return EXIT_FAILURE; }
|
||||
else { retval = EXIT_SUCCESS; }
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
87
src/stris.rs
87
src/stris.rs
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
* Copyright (c) 2023 Marceline Cramer <mars@tebibyte.media>
|
||||
* 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,
|
||||
};
|
||||
|
||||
extern crate getopt;
|
||||
extern crate sysexits;
|
||||
|
||||
use getopt::GetOpt;
|
||||
use sysexits::EX_USAGE;
|
||||
|
||||
struct Reqs {
|
||||
ascii: bool, blank: bool, cntrl: bool, digit: bool, lower: bool,
|
||||
upper: bool, inuse: bool, extra: String
|
||||
}
|
||||
|
||||
fn usage(s: &str) -> ExitCode {
|
||||
eprintln!("Usage: {} [-7bcdlu] [-i inclusions] [strings...]", s);
|
||||
ExitCode::from(EX_USAGE as u8)
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
let mut optind = 1;
|
||||
let mut reqs = Reqs {
|
||||
ascii: false, blank: false, cntrl: false, digit: false, lower: false,
|
||||
upper: false, inuse: false, extra: String::default()
|
||||
};
|
||||
|
||||
while let Some(opt) = argv.getopt("7bcdi:lu") {
|
||||
match opt.opt() {
|
||||
Ok("7") => reqs.ascii = true,
|
||||
Ok("b") => reqs.blank = true,
|
||||
Ok("c") => reqs.cntrl = true,
|
||||
Ok("d") => reqs.digit = true,
|
||||
Ok("i") => reqs.extra = opt.arg().unwrap(),
|
||||
Ok("l") => reqs.lower = true,
|
||||
Ok("u") => reqs.upper = true,
|
||||
_ => { return usage(&argv[0]); }
|
||||
}
|
||||
optind = opt.ind();
|
||||
reqs.inuse = true;
|
||||
}
|
||||
|
||||
if argv.len() == optind { return usage(&argv[0]); }
|
||||
|
||||
drop(argv);
|
||||
|
||||
if reqs.inuse {
|
||||
for arg in args().skip(optind) {
|
||||
for c in arg.chars() {
|
||||
if (reqs.ascii && c.is_ascii())
|
||||
|| (reqs.blank && c.is_whitespace())
|
||||
|| (reqs.cntrl && c.is_control())
|
||||
|| (reqs.digit && c.is_numeric())
|
||||
|| (reqs.lower && c.is_lowercase())
|
||||
|| (reqs.upper && c.is_uppercase())
|
||||
|| reqs.extra.contains(c) {
|
||||
continue;
|
||||
} else {
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fn usage(s: &str) -> ExitCode {
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
#[cfg(target_os="openbsd")] {
|
||||
let promises = Promises::new("stdio");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
return oserr(&argv[0], e);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
* SPDX-License-Identifier: CC0
|
||||
*
|
||||
* This work is marked with CC0 1.0. To view a copy of this license, visit
|
||||
@@ -10,7 +11,7 @@
|
||||
# include <unistd.h> /* pledge(2) */
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
int main(void) {
|
||||
#ifdef __OpenBSD__
|
||||
pledge(NULL, NULL);
|
||||
#endif
|
||||
|
||||
@@ -19,7 +19,7 @@ dj_tests: dj_help dj_full dj_null # dj_skip_stdin
|
||||
dj_full: $(BIN)/dj /dev/full
|
||||
case "$$(uname)" in \
|
||||
Linux) \
|
||||
$(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \
|
||||
! $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \
|
||||
| tee /dev/stderr \
|
||||
| xargs -I out test '1+0 > 0+0; 1024 > 0' = out \
|
||||
;; \
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2024 E$(NAME)a Tebibyte <e$(NAME)a@tebibyte.media>
|
||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||
# SPDX-License-Identifier: FSFAP
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
@@ -6,7 +6,7 @@
|
||||
# notice are preserved. This file is offered as-is, without any warranty.
|
||||
|
||||
.PHONY: mm_tests
|
||||
mm_tests: mm_args mm_help mm_stderr
|
||||
mm_tests: mm_args mm_help mm_stderr mm_remaining
|
||||
|
||||
.PHONY: mm_none
|
||||
mm_none: $(BIN)/mm
|
||||
@@ -25,3 +25,10 @@ mm_help: $(BIN)/mm
|
||||
# check if stderr is empty upon specifying -e
|
||||
mm_stderr: $(BIN)/mm
|
||||
test "$$(printf 'test\n' | $(BIN)/mm -e 2>&1 >/dev/null )" = "test"
|
||||
|
||||
.PHONY: mm_remaining
|
||||
# check to make sure remaining arguments are used
|
||||
mm_remaining: $(BIN)/mm
|
||||
test "$$($(BIN)/mm -i README COPYING)" = "$$(cat README COPYING)"
|
||||
$(BIN)/mm -i README -o /tmp/mm_test0 /tmp/mm_test1
|
||||
diff /tmp/mm_test0 /tmp/mm_test1
|
||||
|
||||
@@ -32,11 +32,29 @@ npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \
|
||||
.PHONY: npc_ascii_controls
|
||||
# (control characters)
|
||||
npc_ascii_controls:
|
||||
# The following test prints the bytes 0x00 (inclusive) through 0x20
|
||||
# (exclusive) and pipes them through npc(1). npc(1) should then replace all
|
||||
# non-printing, non-space (in the isspace(3p) sense) characters with their
|
||||
# graphical carat-char counterparts (see the npc(1) man page). The head(1p)
|
||||
# invocation then strips off everything past the first line (or past the
|
||||
# first newline byte, 0x0A) and xargs(1p) is used to test(1p) the output
|
||||
# against the known good answer.
|
||||
|
||||
# Immediately before that newline, 0x09 is printed - in ASCII, the
|
||||
# horizontal tab. If xargs' -I option is used, tr(1p) should used to delete
|
||||
# that tab. If the tab is left as part of input, OpenBSD's xargs(1)
|
||||
# implementation has been observed to strip it along with the other
|
||||
# trailing whitespace (the newline), but Busybox's and GNU's xargs(1)
|
||||
# implementations have been observed to leave the tab in. All three
|
||||
# implementations strip off the trailing tab if `-I` is not used. The POSIX
|
||||
# specification for `-I` is ambiguous as to which behavior is correct.
|
||||
# This comment is the result of much bewilderment and debugging.
|
||||
|
||||
# ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues)
|
||||
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \
|
||||
| $(BIN)/npc \
|
||||
| head -n 1 \
|
||||
| xargs -I out test "^@^A^B^C^D^E^F^G^H" = out
|
||||
| xargs test "^@^A^B^C^D^E^F^G^H" =
|
||||
|
||||
# ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f
|
||||
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \
|
||||
|
||||
24
tests/bonsai/peek.mk
Executable file
24
tests/bonsai/peek.mk
Executable file
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||
# SPDX-License-Identifier: FSFAP
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty provided the copyright notice and this
|
||||
# notice are preserved. This file is offered as-is, without any warranty.
|
||||
|
||||
# Testing peek is hard as it requires visual confirmation that text isn't being
|
||||
# echoed. These tests don't go that far but are a start, and have already
|
||||
# caught a bug in -i behavior.
|
||||
|
||||
.PHONY: peek_tests
|
||||
peek_tests: peek_help peek_stdio
|
||||
|
||||
.PHONY: peek_help
|
||||
peek_help: $(BIN)/peek
|
||||
! $(BIN)/peek -h
|
||||
|
||||
.PHONY: peek_stdio
|
||||
# Test peek -i
|
||||
peek_stdio: $(BIN)/peek
|
||||
printf 'Test.\n' \
|
||||
| $(BIN)/peek -i \
|
||||
| xargs test 'Test.' =
|
||||
@@ -30,7 +30,7 @@ rpn_mul: $(BIN)/rpn
|
||||
.PHONY: rpn_div
|
||||
rpn_div: $(BIN)/rpn
|
||||
test "$$($(BIN)/rpn 12 5 /)" = 2.4
|
||||
test "$$($(BIN)/rpn 3 0 /)" -eq inf
|
||||
test "$$($(BIN)/rpn 3 0 /)" = inf
|
||||
|
||||
.PHONY: rpn_mod
|
||||
rpn_mod: $(BIN)/rpn
|
||||
|
||||
@@ -7,19 +7,14 @@
|
||||
|
||||
.PRAGMA: command_comment
|
||||
|
||||
.PHONY: stris_tests
|
||||
stris_tests: stris_help stris_7 stris_b
|
||||
.PHONY: str_tests
|
||||
str_tests: str_help str_isalpha
|
||||
|
||||
.PHONY: stris_help
|
||||
stris_help: $(BIN)/stris
|
||||
! $(BIN)/stris -h
|
||||
.PHONY: str_help
|
||||
str_help: $(BIN)/str
|
||||
! $(BIN)/str -h
|
||||
|
||||
.PHONY: stris_7
|
||||
stris_7: $(BIN)/stris
|
||||
$(BIN)/stris -7 !1Aa' '
|
||||
! $(BIN)/stris -7 今日は
|
||||
|
||||
.PHONY: stris_b
|
||||
stris_b: $(BIN)/stris
|
||||
$(BIN)/stris -b "$(printf ' \t\v\r\n')"
|
||||
! $(BIN)/stris -b !1Aa
|
||||
.PHONY: str_isalpha
|
||||
str_isalpha: $(BIN)/str
|
||||
$(BIN)/str isalpha c
|
||||
! $(BIN)/str isalpha 3
|
||||
Reference in New Issue
Block a user