Compare commits
1 Commits
main
...
getopt-for
Author | SHA1 | Date | |
---|---|---|---|
a3bbad467e |
23
Makefile
23
Makefile
@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2023–2025 Emma Tebibyte <emma@tebibyte.media>
|
# Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
# Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
# Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||||
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
# Copyright (c) 2023 Sasha Koshka <sashakoshka@tebibyte.media>
|
||||||
# Copyright (c) 2024 Aaditya Aryal <aryalaadi123@gmail.com>
|
# Copyright (c) 2024 Aaditya Aryal <aryalaadi123@gmail.com>
|
||||||
@ -42,7 +42,7 @@ BIN = build/bin
|
|||||||
default: all test
|
default: all test
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: dj false fileis fop hru intcmp mm npc peek rpn str strcmp 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
|
# keep build/include until bindgen(1) has stdin support
|
||||||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
||||||
@ -62,12 +62,7 @@ dist: all docs
|
|||||||
install: dist
|
install: dist
|
||||||
cp -r $(DESTDIR)/* /
|
cp -r $(DESTDIR)/* /
|
||||||
|
|
||||||
TESTFILES != for file in tests/*.mk; do printf '%s ' "$$file"; done
|
include tests/tests.mk
|
||||||
|
|
||||||
TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \
|
|
||||||
| sed 's/\.mk/_tests/g'
|
|
||||||
|
|
||||||
include $(TESTFILES)
|
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: all $(TESTS) /tmp/getopt
|
test: all $(TESTS) /tmp/getopt
|
||||||
@ -100,7 +95,7 @@ build/o/libstrerror.rlib: build src/libstrerror.rs
|
|||||||
src/libstrerror.rs
|
src/libstrerror.rs
|
||||||
|
|
||||||
build/o/libsysexits.rlib: build/include/sysexits.h
|
build/o/libsysexits.rlib: build/include/sysexits.h
|
||||||
bindgen --fit-macro-constant-types --default-macro-constant-type unsigned --use-core --formatter=none \
|
bindgen --default-macro-constant-type signed --use-core --formatter=none \
|
||||||
build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ -
|
||||||
|
|
||||||
# bandage solution until bindgen(1) gets stdin support
|
# bandage solution until bindgen(1) gets stdin support
|
||||||
@ -117,11 +112,6 @@ false: build/bin/false
|
|||||||
build/bin/false: src/false.c build
|
build/bin/false: src/false.c build
|
||||||
$(CC) $(CFLAGS) -o $@ src/false.c
|
$(CC) $(CFLAGS) -o $@ src/false.c
|
||||||
|
|
||||||
.PHONY: fileis
|
|
||||||
fileis: build/bin/fileis
|
|
||||||
build/bin/fileis: src/fileis.rs build rustlibs
|
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/fileis.rs
|
|
||||||
|
|
||||||
.PHONY: fop
|
.PHONY: fop
|
||||||
fop: build/bin/fop
|
fop: build/bin/fop
|
||||||
build/bin/fop: src/fop.rs build rustlibs
|
build/bin/fop: src/fop.rs build rustlibs
|
||||||
@ -157,6 +147,11 @@ rpn: build/bin/rpn
|
|||||||
build/bin/rpn: src/rpn.rs build rustlibs
|
build/bin/rpn: src/rpn.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) -o $@ src/rpn.rs
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/rpn.rs
|
||||||
|
|
||||||
|
.PHONY: scrut
|
||||||
|
scrut: build/bin/scrut
|
||||||
|
build/bin/scrut: src/scrut.c build
|
||||||
|
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
||||||
|
|
||||||
.PHONY: str
|
.PHONY: str
|
||||||
str: build/bin/str
|
str: build/bin/str
|
||||||
build/bin/str: src/str.c build
|
build/bin/str: src/str.c build
|
||||||
|
254
STYLE
254
STYLE
@ -1,51 +1,11 @@
|
|||||||
“Everyone knows that debugging is twice as hard as writing a program in the
|
|
||||||
first place. So if you’re as clever as you can be when you write it, how
|
|
||||||
will you ever debug it?”
|
|
||||||
– Brian Kernighan, The Elements of Programming Style
|
|
||||||
|
|
||||||
|
|
||||||
The following guidelines are conducive to clear and readable code that is
|
The following guidelines are conducive to clear and readable code that is
|
||||||
consistent with the style of the rest of the Bonsai Computer System.
|
consistent with the style of the rest of the Bonsai Computer System.
|
||||||
|
|
||||||
|
0. Braces are mandatory for all control flow.
|
||||||
|
|
||||||
Use
|
1. Nested indentation should be kept to a minimum.
|
||||||
===
|
|
||||||
|
|
||||||
0. A single line for control flow statements short enough to be easily
|
2. Empty lines should be placed between different kinds of statements:
|
||||||
understood at a glance:
|
|
||||||
|
|
||||||
if !(argc < 0) { usage(program_name); }
|
|
||||||
|
|
||||||
This applies to C switch statements and cases and Rust match statements, as
|
|
||||||
well:
|
|
||||||
|
|
||||||
switch (value) { /* aligning stuff to make it easier to read is fine */
|
|
||||||
case possibility: variable = foo; break;
|
|
||||||
default: variable = NULL; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
1. Switch cases in C and match arms in Rust should start another level of
|
|
||||||
indentation:
|
|
||||||
|
|
||||||
switch (value) {
|
|
||||||
case possibility:
|
|
||||||
statement;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
statement;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(n) => variable = n,
|
|
||||||
Err(e) => error = e,
|
|
||||||
}
|
|
||||||
|
|
||||||
2. Braces in control flow where their inclusion is left optional in C:
|
|
||||||
|
|
||||||
if (condition) { statement; }
|
|
||||||
|
|
||||||
3. Empty lines between different kinds of statements:
|
|
||||||
|
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
@ -65,57 +25,56 @@ Use
|
|||||||
|
|
||||||
return io;
|
return io;
|
||||||
|
|
||||||
4. Compiler options that yield the most useful warnings, such as -Wpedantic in
|
3. Each block of code should be indented once more than the keyword which
|
||||||
a lot of C compilers. Fix the warnings, too [0].
|
initiated the block:
|
||||||
|
|
||||||
5. One more level of indentation and one argument per line when a function
|
switch (c) {
|
||||||
call or statement header is too long to fit on one line:
|
case 'e': mode |= EQUAL; break;
|
||||||
|
case 'g': mode |= GREATER; break;
|
||||||
|
case 'l': mode |= LESS; break;
|
||||||
|
default: return usage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
4. In C, spaces should be placed in control flow statements after the keyword
|
||||||
|
and before the opening brace:
|
||||||
|
|
||||||
|
for (i = 2; i < argc; ++i) {
|
||||||
|
|
||||||
|
5. If a function, a C control flow statement, or a Rust macro has arguments that
|
||||||
|
cause the statement to be broken into multiple lines, this should be done by
|
||||||
|
placing the arguments on a new line inside the parentheses:
|
||||||
|
|
||||||
let usage = format!(
|
let usage = format!(
|
||||||
"Usage: {} [-d delimiter] index command [args...]",
|
"Usage: {} [-d delimiter] index command [args...]",
|
||||||
argv[0],
|
argv[0],
|
||||||
);
|
);
|
||||||
|
|
||||||
6. One more level of indentation than the keyword that initiated a multi-line
|
6. If Rust function arguments or fields are on their own lines, they should
|
||||||
block.
|
always have a trailing comma:
|
||||||
|
|
||||||
if (condition) {
|
|
||||||
statement;
|
|
||||||
statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
7. The return value of all non-void functions, or explicitly ignore them (like
|
|
||||||
casting to void in C) [0]:
|
|
||||||
|
|
||||||
if ((a = malloc(sizeof char)) == NULL) { /* handle this error */
|
|
||||||
(void)fprintf(stderr, "oh noes!"); /* explicitly ignore this one */
|
|
||||||
return EX_OSERR; /* ...because the program is exiting anyway */
|
|
||||||
}
|
|
||||||
|
|
||||||
8. The smallest possible scope for data [0].
|
|
||||||
|
|
||||||
9. Comments noting all the symbols and macros used from a C header file, next
|
|
||||||
to its include macro:
|
|
||||||
|
|
||||||
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
|
||||||
(space-aligned) * optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
|
||||||
|
|
||||||
10. Spaces in control flow statements, after the keyword and before the
|
|
||||||
opening brace:
|
|
||||||
|
|
||||||
for (i = 2; i < argc; ++i) {
|
|
||||||
|
|
||||||
|
|
||||||
11. In Rust, a trailing comma on all arguments or fields that are on their own
|
|
||||||
lines:
|
|
||||||
|
|
||||||
return Err(EvaluationError {
|
return Err(EvaluationError {
|
||||||
message: format!("{}: Invalid token", i),
|
message: format!("{}: Invalid token", i),
|
||||||
code: EX_DATAERR,
|
code: EX_DATAERR,
|
||||||
})
|
})
|
||||||
|
|
||||||
12. In Rust, place extern statements after use statements that include standard
|
7. If text is on the same line as a brace, spaces should be placed after an
|
||||||
library crates. Group like statements:
|
opening curly brace and before a closing one:
|
||||||
|
|
||||||
|
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
||||||
|
|
||||||
|
8. If a control flow statement is short enough to be easily understood in a
|
||||||
|
glance, it may be placed on a single line:
|
||||||
|
|
||||||
|
if !(argc < 0) { usage(program_name); }
|
||||||
|
|
||||||
|
9. In C, note everything you use from a library in a comment subsequent to its
|
||||||
|
#include statement:
|
||||||
|
|
||||||
|
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
||||||
|
* optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
||||||
|
|
||||||
|
10. In Rust, place extern statements after use statements that include standard
|
||||||
|
library crates. Group alike statements:
|
||||||
|
|
||||||
use std::fs::Path;
|
use std::fs::Path;
|
||||||
|
|
||||||
@ -125,129 +84,40 @@ Use
|
|||||||
use strerror::StrError;
|
use strerror::StrError;
|
||||||
use sysexits::{ EX_OSERR, EX_USAGE };
|
use sysexits::{ EX_OSERR, EX_USAGE };
|
||||||
|
|
||||||
13. If text is on the same line as a brace, spaces after an opening brace and
|
11. Do not use do while loops in C.
|
||||||
before a closing one:
|
|
||||||
|
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
12. Adhere to the following rules from the paper The Power of 10: Rules for
|
||||||
|
Developing Safety-Critical Code [0]:
|
||||||
|
1. Avoid complex flow constructs, such as goto and recursion.
|
||||||
|
2. All loops must have fixed bounds. This prevents runaway code.
|
||||||
|
3. Avoid heap memory allocation.
|
||||||
|
4. Restrict functions to the length of a single printed page.
|
||||||
|
|
||||||
14. Alphabetic sorting, where applicable:
|
6. Restrict the scope of data to the smallest possible.
|
||||||
|
7. Check the return value of all non-void functions, or cast to void to
|
||||||
|
indicate the return value is useless (such as in the case of using
|
||||||
|
fprintf(3p) to print to the standard error).
|
||||||
|
8. Use the preprocessor sparingly.
|
||||||
|
9. Limit pointer use to a single dereference, and do not use function
|
||||||
|
pointers.
|
||||||
|
10. Compile with all possible warnings active; all warnings should then be
|
||||||
|
addressed before release of the software (for C compilers, compile with
|
||||||
|
-Wpedantic).
|
||||||
|
|
||||||
use std::io::{ BufWriter, Read, Write, stderr, stdin, stdout }
|
13. Remember this quote from The Elements of Programming Style by Brian
|
||||||
|
Kernighan:
|
||||||
15. In Rust, use the to_owned() method on string types (str, OsStr, CStr, etc.)
|
Everyone knows that debugging is twice as hard as writing a program in the
|
||||||
and the to_string() method on other types.
|
first place. So if you're as clever as you can be when you write it, how
|
||||||
|
will you ever debug it?
|
||||||
|
|
||||||
Avoid
|
|
||||||
=====
|
|
||||||
|
|
||||||
16. Unbounded loops [0].
|
|
||||||
|
|
||||||
17. Function pointers [0].
|
|
||||||
|
|
||||||
18. Heap memory allocation [0].
|
|
||||||
|
|
||||||
19. Using too much nested logic (within reason).
|
|
||||||
|
|
||||||
20. Too many levels of dereferences [0]:
|
|
||||||
|
|
||||||
/* do not do this */
|
|
||||||
for (size_t i = 0; i < sizeof a / sizeof *a; ++i) {
|
|
||||||
if (a[i].id == MATCH) { a[i].val = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do this */
|
|
||||||
for (struct MadeUp *s = &a[0]; *s != NULL; s = &s[1]) {
|
|
||||||
if (s->id == MATCH) { s->val = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
21. Using C preprocessor macros; the fewer, the better [0].
|
|
||||||
|
|
||||||
22. The exit(3p) and std::process::exit() functions; returning from the main
|
|
||||||
function skips a system call.
|
|
||||||
|
|
||||||
|
|
||||||
Do Not Use
|
|
||||||
==========
|
|
||||||
|
|
||||||
23. More than the length of one printed page for a function [0].
|
|
||||||
|
|
||||||
24. Recursion, as it’s complex and can unexpectedly overflow the stack [0].
|
|
||||||
|
|
||||||
25. Any functionality not in the POSIX C specification and language features not
|
|
||||||
in C99.
|
|
||||||
|
|
||||||
26. Do-while loops, as they’re unique to C and confusing for casual programmers.
|
|
||||||
|
|
||||||
27. Labels and goto statements; use sensible flow control [0].
|
|
||||||
|
|
||||||
28. Pointer arithmetic, as it tends to be confusing and unnecessary; use
|
|
||||||
index-reference patterns like &p[1] instead of p + 1. &p[n] is the address at
|
|
||||||
p + sizeof p * n, not p + n, like pointer arithmetic suggests.
|
|
||||||
|
|
||||||
29. C struct bitfields in unions, to access certain bits of bigger data types,
|
|
||||||
as it’s poorly defined in the C standards; use bit arithmetic.
|
|
||||||
|
|
||||||
30. C trigraphs.
|
|
||||||
|
|
||||||
31. Inclusions in C header files, to prevent multiple file inclusions.
|
|
||||||
|
|
||||||
32. C preprocessor variables to prevent multiple inclusions of the same file,
|
|
||||||
such as:
|
|
||||||
|
|
||||||
#ifdef _FILE
|
|
||||||
#define _FILE
|
|
||||||
/* file body */
|
|
||||||
#endif /* ifdef _FILE */
|
|
||||||
|
|
||||||
Instead, take the time to ensure other files aren’t including any files twice.
|
|
||||||
|
|
||||||
33. The gets(3p) function from <stdio.h>, as it’s impossible to prevent buffer
|
|
||||||
overflows when it's used; use fgets(3p) from <stdio.h>.
|
|
||||||
|
|
||||||
34. The scanf(3p) function from <stdio.h> [1].
|
|
||||||
|
|
||||||
35. Any functionality not described in the latest POSIX make(1) specification.
|
|
||||||
|
|
||||||
36. Macros which panic on failure in Rust (such as the print!() and println!()
|
|
||||||
macros). Use a function and handle any errors. However, do use the eprintln!()
|
|
||||||
macro for error messages. Handling an error for writing an error message is
|
|
||||||
redundant.
|
|
||||||
|
|
||||||
|
|
||||||
Usage Text
|
|
||||||
==========
|
|
||||||
|
|
||||||
This section is adapted from the NetBSD style guide [2].
|
|
||||||
|
|
||||||
When programs are invoked incorrectly and in the synopsis of manual pages, uasge
|
|
||||||
text should be provided to the user. The following is the format used by this
|
|
||||||
project for this purpose:
|
|
||||||
|
|
||||||
All optional arguments are to be placed in square brackets (U+005B, U+005D).
|
|
||||||
Mutually exclusive arguments can be separated by a vertical line (U+007C).
|
|
||||||
Groups of arguments should be specified in alphabetical order in most cases. The
|
|
||||||
order of arguments and an example of these rules follows:
|
|
||||||
|
|
||||||
0. Options with no option arguments.
|
|
||||||
1. Options with option arguments. Arguments should be specified inside the same
|
|
||||||
square brackets as the options.
|
|
||||||
3. Non-option arguments.
|
|
||||||
|
|
||||||
"usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
|
|
||||||
"usage: f [-a | -b] [-c [-de] [-n number]]\n"
|
|
||||||
|
|
||||||
|
|
||||||
References
|
References
|
||||||
==========
|
==========
|
||||||
|
|
||||||
[0] <https://web.eecs.umich.edu/~imarkov/10rules.pdf>
|
[0] <https://web.eecs.umich.edu/~imarkov/10rules.pdf>
|
||||||
[1] <http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html>
|
|
||||||
[2] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
|
||||||
|
|
||||||
--
|
--
|
||||||
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
Copyright © 2024 DTB <trinity@trinity.moe>
|
|
||||||
Copyright © Wikipedia contributors
|
Copyright © Wikipedia contributors
|
||||||
|
|
||||||
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
.\" Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
.\" 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,
|
.\" 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/>.
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
.\"
|
.\"
|
||||||
.TH FILEIS 1 2025-02-24 "Harakit X.X.X"
|
.TH SCRUT 1 2024-06-06 "Harakit X.X.X"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fileis \(en scrutinize file properties
|
scrut \(en scrutinize file properties
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
|
||||||
fileis
|
scrut
|
||||||
.RB [ -LSbcdefgkprsuwx ]
|
.RB [ -LSbcdefgkprsuwx ]
|
||||||
.B file...
|
.B file...
|
||||||
.\"
|
.\"
|
||||||
@ -82,6 +82,5 @@ Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
|||||||
.\"
|
.\"
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR access (3p),
|
.BR access (3p),
|
||||||
.BR chown (1p),
|
|
||||||
.BR lstat (3p),
|
.BR lstat (3p),
|
||||||
.BR test (1p)
|
.BR test (1p)
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
(void)pledge("stdio", "");
|
pledge(NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2024 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
|
|
||||||
* 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,
|
|
||||||
fs::metadata,
|
|
||||||
os::unix::fs::{ FileTypeExt, MetadataExt },
|
|
||||||
process::ExitCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
extern crate getopt;
|
|
||||||
extern crate strerror;
|
|
||||||
extern crate sysexits;
|
|
||||||
|
|
||||||
use getopt::GetOpt;
|
|
||||||
use strerror::StrError;
|
|
||||||
use sysexits::EX_USAGE;
|
|
||||||
|
|
||||||
const OPTS: &str = "bcdefgkprsuwxLS";
|
|
||||||
|
|
||||||
fn usage(argv0: &str) -> ExitCode {
|
|
||||||
eprintln!("Usage: {} [-{}] file...", argv0, OPTS);
|
|
||||||
ExitCode::from(EX_USAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
|
||||||
let argv = args().collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let mut sel = String::with_capacity(OPTS.len()); // selected options
|
|
||||||
let mut optind: usize = 1; // argv[0]
|
|
||||||
|
|
||||||
while let Some(opt) = argv.getopt(OPTS) {
|
|
||||||
if let Ok(optchr) = opt.opt() { sel.push_str(optchr); }
|
|
||||||
else { return usage(&argv[0]); }
|
|
||||||
|
|
||||||
optind = opt.ind();
|
|
||||||
}
|
|
||||||
|
|
||||||
if optind == argv.len() { return usage(&argv[0]); }
|
|
||||||
|
|
||||||
for arg in argv.iter().skip(optind) {
|
|
||||||
let fmeta = match metadata(arg) {
|
|
||||||
Ok(m) => m,
|
|
||||||
Err(e) => { // no perms or nonexistent
|
|
||||||
eprintln!("{}: {}: {}", argv[0], arg, e.strerror());
|
|
||||||
return ExitCode::FAILURE;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let fmode = fmeta.mode();
|
|
||||||
let ftype = fmeta.file_type();
|
|
||||||
|
|
||||||
for selection in sel.chars() { // run all selected tests
|
|
||||||
match selection {
|
|
||||||
'b' if ftype.is_block_device() => (),
|
|
||||||
'c' if ftype.is_char_device() => (),
|
|
||||||
'e' => (), // exists or metadata would have errored
|
|
||||||
'd' if fmeta.is_dir() => (),
|
|
||||||
'f' if fmeta.is_file() => (),
|
|
||||||
'g' if fmode & 0o2000 /* S_ISGID */ != 0 => (), // setgid
|
|
||||||
'k' if fmode & 0o1000 /* S_ISVTX */ != 0 => (), // setvtx
|
|
||||||
'p' if ftype.is_fifo() => (),
|
|
||||||
'r' if fmode & 0o0400 /* S_IRUSR */ != 0 => (), // read access
|
|
||||||
'u' if fmode & 0o4000 /* S_ISUID */ != 0 => (), // setuid
|
|
||||||
'w' if fmode & 0o0200 /* S_IWUSR */ != 0 => (), // write access
|
|
||||||
'x' if fmode & 0o0100 /* S_IXUSR */ != 0 => (), // exec access
|
|
||||||
'L' if fmeta.is_symlink() => (),
|
|
||||||
'S' if ftype.is_socket() => (),
|
|
||||||
_ => { return ExitCode::FAILURE; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
|
||||||
}
|
|
71
src/fop.rs
71
src/fop.rs
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
io::{ Error, Read, Write, stdin, stdout },
|
io::{ Read, stdin, stdout, Write },
|
||||||
process::{ Command, ExitCode, Stdio, exit },
|
process::{ Command, exit, Stdio },
|
||||||
};
|
};
|
||||||
|
|
||||||
extern crate getopt;
|
extern crate getopt;
|
||||||
@ -32,36 +32,25 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
|||||||
|
|
||||||
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
||||||
#[cfg(target_os="openbsd")] extern crate openbsd;
|
#[cfg(target_os="openbsd")] extern crate openbsd;
|
||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge, unveil };
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
|
|
||||||
fn err(argv0: &String, e: Error) {
|
fn main() {
|
||||||
eprintln!("{}: {}", argv0, e.strerror());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage(argv0: &String) -> u8 {
|
|
||||||
eprintln!("Usage: {} [-d delimiter] index command [args...]", argv0);
|
|
||||||
EX_USAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
let mut d = '\u{1E}'.to_string(); /* ASCII record separator */
|
let mut d = '\u{1E}'.to_string(); /* ASCII record separator */
|
||||||
let mut optind = 1;
|
let mut optind = 1;
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
let promises = Promises::new("exec proc stdio unveil");
|
let promises = Promises::new("stdio proc exec");
|
||||||
if let Err(e) = pledge(Some(promises), None) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
err(&argv[0], e);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
return ExitCode::from(EX_OSERR);
|
exit(EX_OSERR);
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
|
||||||
err(&argv[0], e);
|
|
||||||
return ExitCode::from(EX_OSERR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.len() == 1 { return ExitCode::from(usage(&argv[0])); }
|
let usage = format!(
|
||||||
|
"Usage: {} [-d delimiter] index command [args...]",
|
||||||
|
argv[0],
|
||||||
|
);
|
||||||
|
|
||||||
while let Some(opt) = argv.getopt("d:") {
|
while let Some(opt) = argv.getopt("d:") {
|
||||||
match opt.opt() {
|
match opt.opt() {
|
||||||
@ -71,7 +60,8 @@ fn main() -> ExitCode {
|
|||||||
optind = opt.ind();
|
optind = opt.ind();
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
return ExitCode::from(usage(&argv[0]));
|
eprintln!("{}", usage);
|
||||||
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -79,7 +69,7 @@ fn main() -> ExitCode {
|
|||||||
/* parse the specified index as a number we can use */
|
/* parse the specified index as a number we can use */
|
||||||
let index = argv[optind].parse::<usize>().unwrap_or_else(|e| {
|
let index = argv[optind].parse::<usize>().unwrap_or_else(|e| {
|
||||||
eprintln!("{}: {}: {}", argv[0], argv[1], e);
|
eprintln!("{}: {}: {}", argv[0], argv[1], e);
|
||||||
exit(EX_DATAERR.into());
|
exit(EX_DATAERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* index of the argv[0] for the operator command */
|
/* index of the argv[0] for the operator command */
|
||||||
@ -87,14 +77,15 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
/* argv[0] of the operator command */
|
/* argv[0] of the operator command */
|
||||||
let operator = argv.get(command_arg).unwrap_or_else(|| {
|
let operator = argv.get(command_arg).unwrap_or_else(|| {
|
||||||
exit(usage(&argv[0]).into());
|
eprintln!("{}", usage);
|
||||||
|
exit(EX_USAGE);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* read entire standard input into memory */
|
/* read entire standard input into memory */
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Err(e) = stdin().read_to_string(&mut buf) {
|
if let Err(e) = stdin().read_to_string(&mut buf) {
|
||||||
err(&argv[0], e);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* split the buffer by the delimiter (by default, '\u{1E}') */
|
/* split the buffer by the delimiter (by default, '\u{1E}') */
|
||||||
@ -114,14 +105,18 @@ fn main() -> ExitCode {
|
|||||||
.stdout(Stdio::piped()) /* piped stdout to handle output ourselves */
|
.stdout(Stdio::piped()) /* piped stdout to handle output ourselves */
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap_or_else( |e| {
|
.unwrap_or_else( |e| {
|
||||||
err(&argv[0], e);
|
eprintln!("{}: {}: {}", argv[0], argv[command_arg], e.strerror());
|
||||||
exit(EX_UNAVAILABLE.into());
|
exit(EX_UNAVAILABLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get field we want to pipe into spawned program */
|
/* get field we want to pipe into spawned program */
|
||||||
let field = fields.get(index).unwrap_or_else(|| {
|
let field = fields.get(index).unwrap_or_else(|| {
|
||||||
eprintln!("{}: {}: no such index in input", argv[0], index);
|
eprintln!(
|
||||||
exit(EX_DATAERR.into());
|
"{}: {}: No such index in input",
|
||||||
|
argv[0],
|
||||||
|
index.to_string(),
|
||||||
|
);
|
||||||
|
exit(EX_DATAERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get the stdin of the newly spawned program and feed it the field val */
|
/* get the stdin of the newly spawned program and feed it the field val */
|
||||||
@ -131,8 +126,8 @@ fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
||||||
err(&argv[0], e);
|
eprintln!("{}: {}: {}", argv[0], argv[command_arg], e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get the output with which the original field will be replaced */
|
/* get the output with which the original field will be replaced */
|
||||||
@ -148,8 +143,8 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
/* convert the output of the program to UTF-8 */
|
/* convert the output of the program to UTF-8 */
|
||||||
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
||||||
eprintln!("{}: {}", argv[0], e);
|
eprintln!("{}: {}: {}", argv[0], argv[command_arg], e);
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* store the new field in the old fields vector */
|
/* store the new field in the old fields vector */
|
||||||
@ -159,9 +154,7 @@ fn main() -> ExitCode {
|
|||||||
stdout().write_all(
|
stdout().write_all(
|
||||||
fields.join(&d.to_string()).as_bytes()
|
fields.join(&d.to_string()).as_bytes()
|
||||||
).unwrap_or_else(|e| {
|
).unwrap_or_else(|e| {
|
||||||
err(&argv[0], e);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
});
|
});
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
|
||||||
}
|
}
|
||||||
|
63
src/hru.rs
63
src/hru.rs
@ -19,7 +19,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
env::args,
|
env::args,
|
||||||
io::{ Write, stdin, stdout },
|
io::{ stdin, stdout, Write },
|
||||||
process::{ ExitCode, exit },
|
process::{ ExitCode, exit },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE, EX_USAGE };
|
|||||||
|
|
||||||
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
||||||
#[cfg(target_os="openbsd")] extern crate openbsd;
|
#[cfg(target_os="openbsd")] extern crate openbsd;
|
||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge, unveil };
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
|
|
||||||
/* list of SI prefixes */
|
/* list of SI prefixes */
|
||||||
const LIST: [(u32, &str); 10] = [
|
const LIST: [(u32, &str); 10] = [
|
||||||
@ -47,16 +47,6 @@ const LIST: [(u32, &str); 10] = [
|
|||||||
(30, "Q"), /* quetta */
|
(30, "Q"), /* quetta */
|
||||||
];
|
];
|
||||||
|
|
||||||
fn err(argv0: &String, message: String, code: Option<u8>) -> ExitCode {
|
|
||||||
eprintln!("{}: {}", argv0, message);
|
|
||||||
ExitCode::from(code.unwrap_or(1 /* unknown error */))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage(argv0: &String) -> ExitCode {
|
|
||||||
eprintln!("Usage: {}", argv0);
|
|
||||||
ExitCode::from(EX_USAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
|
fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
|
||||||
/* preserve decimal places in output by casting to a float */
|
/* preserve decimal places in output by casting to a float */
|
||||||
let mut out = (input as f64, (0_u32, ""));
|
let mut out = (input as f64, (0_u32, ""));
|
||||||
@ -91,25 +81,22 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
|
|||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
if let Some(_) = argv.get(1) { return usage(&argv[0]); }
|
if let Some(_) = argv.get(1) {
|
||||||
|
eprintln!("Usage: {}", argv[0]);
|
||||||
#[cfg(target_os="openbsd")] {
|
return ExitCode::from(EX_USAGE as u8);
|
||||||
let promises = Promises::new("stdio unveil");
|
|
||||||
if let Err(e) = pledge(Some(promises), Some(Promises::default())) {
|
|
||||||
return err(&argv[0], e.strerror(), Some(EX_OSERR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
#[cfg(target_os="openbsd")] {
|
||||||
return err(&argv[0], e.strerror(), Some(EX_OSERR));
|
let promises = Promises::new("stdio");
|
||||||
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
if let Err(e) = stdin().read_line(&mut buf) {
|
while let Ok(_) = stdin().read_line(&mut buf) {
|
||||||
return err(&argv[0], e.strerror(), Some(EX_IOERR));
|
|
||||||
}
|
|
||||||
|
|
||||||
if buf.is_empty() { return ExitCode::SUCCESS; }
|
if buf.is_empty() { return ExitCode::SUCCESS; }
|
||||||
|
|
||||||
let n: u128 = match buf.trim().parse() {
|
let n: u128 = match buf.trim().parse() {
|
||||||
@ -117,22 +104,30 @@ fn main() -> ExitCode {
|
|||||||
buf.clear();
|
buf.clear();
|
||||||
f
|
f
|
||||||
},
|
},
|
||||||
Err(e) => return err(&argv[0], e.to_string(), Some(EX_DATAERR)),
|
Err(err) => {
|
||||||
|
eprintln!("{}: {}", argv[0], err);
|
||||||
|
return ExitCode::from(EX_DATAERR as u8);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let (number, prefix) = convert(n).unwrap_or_else(|e| {
|
let (number, prefix) = match convert(n) {
|
||||||
let _ = err(&argv[0], e.to_string(), None);
|
Ok(x) => x,
|
||||||
exit(EX_SOFTWARE.into());
|
Err(err) => {
|
||||||
});
|
eprintln!("{}: {}", argv[0], err);
|
||||||
|
return ExitCode::from(EX_SOFTWARE as u8);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let si_prefix = prefix.1.to_owned() + "B";
|
let si_prefix = format!("{}B", prefix.1);
|
||||||
|
|
||||||
/* round output number to one decimal place */
|
/* round output number to one decimal place */
|
||||||
let rounded = (number * 10.0).round() / 10.0;
|
let out = ((number * 10.0).round() / 10.0).to_string();
|
||||||
let out = rounded.to_string() + " " + &si_prefix + &'\n'.to_string();
|
|
||||||
|
|
||||||
if let Err(e) = stdout().write_all(out.as_bytes()) {
|
stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes())
|
||||||
return err(&argv[0], e.strerror(), Some(EX_IOERR));
|
.unwrap_or_else(|e| {
|
||||||
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
exit(EX_IOERR);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
|
@ -26,35 +26,27 @@ extern crate getopt;
|
|||||||
extern crate sysexits;
|
extern crate sysexits;
|
||||||
|
|
||||||
use getopt::GetOpt;
|
use getopt::GetOpt;
|
||||||
use sysexits::{ EX_DATAERR, EX_USAGE };
|
use sysexits::EX_USAGE;
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
||||||
#[cfg(target_os="openbsd")] extern crate openbsd;
|
#[cfg(target_os="openbsd")] extern crate openbsd;
|
||||||
#[cfg(target_os="openbsd")] extern crate strerror;
|
#[cfg(target_os="openbsd")] extern crate strerror;
|
||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge, unveil };
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
#[cfg(target_os="openbsd")] use strerror::StrError;
|
#[cfg(target_os="openbsd")] use strerror::StrError;
|
||||||
|
|
||||||
fn err(argv0: &String, e: String, code: u8) -> ExitCode {
|
fn usage(s: &str) -> ExitCode {
|
||||||
eprintln!("{}: {}", argv0, e);
|
eprintln!("Usage: {} [-egl] integer integer...", s);
|
||||||
ExitCode::from(code)
|
ExitCode::from(EX_USAGE as u8)
|
||||||
}
|
|
||||||
|
|
||||||
fn usage(argv0: &String) -> ExitCode {
|
|
||||||
eprintln!("Usage: {} [-egl] integer integer...", argv0);
|
|
||||||
ExitCode::from(EX_USAGE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
let promises = Promises::new("stdio unveil");
|
let promises = Promises::new("stdio");
|
||||||
if let Err(e) = pledge(Some(promises), Some(Promises::default())) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
return err(&argv[0], e.strerror(), EX_OSERR);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
}
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
|
||||||
return err(&argv[0], e.strerror(), EX_OSERR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,8 +78,8 @@ fn main() -> ExitCode {
|
|||||||
match arg.parse::<usize>() { /* parse current operand */
|
match arg.parse::<usize>() { /* parse current operand */
|
||||||
Ok(n) => currn = n,
|
Ok(n) => currn = n,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let error = arg.to_owned() + ": " + &e.to_string();
|
eprintln!("{}: {}: {}", &argv[0], arg, e);
|
||||||
return err(&argv[0], error, EX_DATAERR);
|
return ExitCode::from(EX_USAGE as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +43,6 @@ impl Promises {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Promises {
|
|
||||||
fn default() -> Self { Promises::new("") }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pledge(
|
pub fn pledge(
|
||||||
promises: Option<Promises>, execpromises: Option<Promises>
|
promises: Option<Promises>, execpromises: Option<Promises>
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -69,12 +65,14 @@ pub fn pledge(
|
|||||||
pub struct UnveilPerms(CString);
|
pub struct UnveilPerms(CString);
|
||||||
|
|
||||||
impl UnveilPerms {
|
impl UnveilPerms {
|
||||||
pub fn new<T: IntoIterator<Item = char>>(permissions: T) -> Self {
|
pub fn new(permissions: Vec<char>) -> Self {
|
||||||
let perms = CString::new(
|
if permissions.is_empty() {
|
||||||
permissions.into_iter().collect::<String>()
|
return UnveilPerms(CString::new("").unwrap());
|
||||||
).unwrap();
|
}
|
||||||
|
|
||||||
UnveilPerms(perms)
|
UnveilPerms(
|
||||||
|
CString::new(permissions.iter().collect::<String>()).unwrap()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +83,9 @@ pub fn unveil(
|
|||||||
let path_c = path.map(CString::new).map(Result::unwrap);
|
let path_c = path.map(CString::new).map(Result::unwrap);
|
||||||
let arg1 = path_c.map(|p| p.into_raw() as *const c_char).unwrap_or(null());
|
let arg1 = path_c.map(|p| p.into_raw() as *const c_char).unwrap_or(null());
|
||||||
|
|
||||||
let arg2 = permissions.map(|p| {
|
let arg2 = permissions
|
||||||
p.0.into_raw() as *const c_char
|
.map(|p| p.0.into_raw() as *const c_char)
|
||||||
}).unwrap_or(null());
|
.unwrap_or(null());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
match openbsd::unveil(arg1, arg2) {
|
match openbsd::unveil(arg1, arg2) {
|
||||||
|
57
src/mm.rs
57
src/mm.rs
@ -20,9 +20,9 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{ Error, BufWriter, Read, Write, stderr, stdin, stdout },
|
io::{ stdin, stdout, stderr, BufWriter, Read, Write },
|
||||||
os::fd::{ AsRawFd, FromRawFd },
|
os::fd::{ AsRawFd, FromRawFd },
|
||||||
process::{ ExitCode, exit},
|
process::{ exit, ExitCode },
|
||||||
};
|
};
|
||||||
|
|
||||||
extern crate getopt;
|
extern crate getopt;
|
||||||
@ -47,23 +47,15 @@ use ArgMode::*;
|
|||||||
|
|
||||||
enum ArgMode { In, Out }
|
enum ArgMode { In, Out }
|
||||||
|
|
||||||
fn err(argv0: &String, e: Error, code: Option<u8>) -> ExitCode {
|
|
||||||
eprintln!("{}: {}", argv0, e.strerror());
|
|
||||||
ExitCode::from(code.unwrap_or(1 /* unknown error */))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage(argv0: &String) -> ExitCode {
|
|
||||||
eprintln!("Usage: {} [-aetu] [-i input] [-o output]", argv0);
|
|
||||||
ExitCode::from(EX_USAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<_>>();
|
let argv = args().collect::<Vec<_>>();
|
||||||
|
let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]);
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
let promises = Promises::new("cpath rpath stdio unveil wpath");
|
let promises = Promises::new("cpath rpath stdio unveil wpath");
|
||||||
if let Err(e) = pledge(Some(promises), Some(Promises::default())) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
return err(&argv[0], e, Some(EX_OSERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +85,8 @@ fn main() -> ExitCode {
|
|||||||
mode = Some(Out); /* latest argument == -o */
|
mode = Some(Out); /* latest argument == -o */
|
||||||
},
|
},
|
||||||
Err(_) | Ok(_) => {
|
Err(_) | Ok(_) => {
|
||||||
return usage(&argv[0]);
|
eprintln!("{}", usage);
|
||||||
|
return ExitCode::from(EX_USAGE as u8);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,28 +108,32 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
for input in &ins {
|
for input in &ins {
|
||||||
let perms = UnveilPerms::new(['r']);
|
let perms = UnveilPerms::new(vec!['r']);
|
||||||
|
|
||||||
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
||||||
return err(&argv[0], e, Some(EX_OSERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for output in &outs {
|
for output in &outs {
|
||||||
let perms = UnveilPerms::new(['c', 'w']);
|
let perms = UnveilPerms::new(vec!['c', 'w']);
|
||||||
|
|
||||||
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
||||||
return err(&argv[0], e, Some(EX_OSERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
if let Err(e) = unveil(None, None) {
|
||||||
return err(&argv[0], e, Some(EX_OSERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ins.is_empty() && outs.is_empty() && argv.len() > optind {
|
if ins.is_empty() && outs.is_empty() && argv.len() > optind {
|
||||||
return usage(&argv[0]);
|
eprintln!("Usage: {}", usage);
|
||||||
|
return ExitCode::from(EX_USAGE as u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* use stdin if no inputs are specified */
|
/* use stdin if no inputs are specified */
|
||||||
@ -156,8 +153,8 @@ fn main() -> ExitCode {
|
|||||||
match File::open(file) {
|
match File::open(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
eprintln!("{}: {}: {}", argv[0], file, e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
@ -183,8 +180,8 @@ fn main() -> ExitCode {
|
|||||||
match options {
|
match options {
|
||||||
Ok(f) => return f,
|
Ok(f) => return f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
eprintln!("{}: {}: {}", argv[0], file, e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
@ -208,19 +205,21 @@ fn main() -> ExitCode {
|
|||||||
for file in inputs {
|
for file in inputs {
|
||||||
for byte in file.bytes().map(|b| {
|
for byte in file.bytes().map(|b| {
|
||||||
b.unwrap_or_else(|e| {
|
b.unwrap_or_else(|e| {
|
||||||
let _ = err(&argv[0], e, None);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR);
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
for out in &mut outputs {
|
for out in &mut outputs {
|
||||||
if let Err(e) = out.write(&[byte]) {
|
if let Err(e) = out.write(&[byte]) {
|
||||||
return err(&argv[0], e, Some(EX_IOERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_IOERR as u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if u {
|
if u {
|
||||||
/* immediately flush the output for -u */
|
/* immediately flush the output for -u */
|
||||||
if let Err(e) = out.flush() {
|
if let Err(e) = out.flush() {
|
||||||
return err(&argv[0], e, Some(EX_IOERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
|
return ExitCode::from(EX_IOERR as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), perror(3), putc(3), stdin,
|
#include <stdio.h> /* fprintf(3), fputs(3), getc(3), perror(3), putc(3), stdin,
|
||||||
* stdout, EOF */
|
* stdout, EOF */
|
||||||
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */
|
#include <sysexits.h> /* EX_IOERR, EX_OK, EX_OSERR, EX_USAGE */
|
||||||
#include <unistd.h> /* NULL, getopt(3), pledge(2), unveil(2) */
|
#include <unistd.h> /* pledge(2), getopt(3) */
|
||||||
|
|
||||||
char *program_name = "npc";
|
char *program_name = "npc";
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ int main(int argc, char *argv[]) {
|
|||||||
char showtab = 0; /* prints tab characters in caret notation */
|
char showtab = 0; /* prints tab characters in caret notation */
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("stdio unveil", "") == -1 || unveil(NULL, NULL)) {
|
if (pledge("stdio", NULL) == -1) {
|
||||||
perror(argv[0] == NULL ? program_name : argv[0]);
|
perror(argv[0] == NULL ? program_name : argv[0]);
|
||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}
|
}
|
||||||
|
185
src/rpn.rs
185
src/rpn.rs
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
@ -46,21 +46,21 @@ use std::{
|
|||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
env::args,
|
env::args,
|
||||||
fmt::{ self, Display, Formatter },
|
fmt::{ self, Display, Formatter },
|
||||||
io::{ Error, Write, stdin, stdout },
|
io::stdin,
|
||||||
process::ExitCode,
|
process::ExitCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use CalcType::*;
|
use CalcType::*;
|
||||||
|
|
||||||
extern crate strerror;
|
|
||||||
extern crate sysexits;
|
extern crate sysexits;
|
||||||
|
|
||||||
use strerror::StrError;
|
use sysexits::EX_DATAERR;
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR };
|
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
#[cfg(target_os="openbsd")] use sysexits::EX_OSERR;
|
||||||
|
#[cfg(target_os="openbsd")] extern crate strerror;
|
||||||
#[cfg(target_os="openbsd")] extern crate openbsd;
|
#[cfg(target_os="openbsd")] extern crate openbsd;
|
||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge, unveil };
|
#[cfg(target_os="openbsd")] use strerror::StrError;
|
||||||
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, PartialOrd, Debug)]
|
#[derive(Clone, PartialEq, PartialOrd, Debug)]
|
||||||
/* enum CalcType is a type containing operations used in the calculator */
|
/* enum CalcType is a type containing operations used in the calculator */
|
||||||
@ -120,46 +120,12 @@ impl Display for CalcType {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct EvaluationError {
|
struct EvaluationError {
|
||||||
message: String,
|
message: String,
|
||||||
code: u8,
|
code: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StrError for EvaluationError {
|
/* I’m no math nerd but I want the highest possible approximation of 0.9
|
||||||
fn strerror(&self) -> String {
|
* repeating and it seems this can give it to me */
|
||||||
self.message.clone()
|
const PRECISION_MOD: f64 = 0.9 + f64::EPSILON * 100.0;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn err<T: StrError>(argv0: &String, e: &T, code: Option<u8>) -> ExitCode {
|
|
||||||
eprintln!("{}: {}", argv0, e.strerror());
|
|
||||||
ExitCode::from(code.unwrap_or(1 /* unknown error */))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn operate(
|
|
||||||
mut stack: VecDeque<f64>,
|
|
||||||
op: CalcType,
|
|
||||||
) -> Result<VecDeque<f64>, EvaluationError> {
|
|
||||||
let vals = (stack.pop_back(), stack.pop_back());
|
|
||||||
|
|
||||||
if let (Some(x), Some(y)) = vals {
|
|
||||||
match op {
|
|
||||||
Add => stack.push_back(y + x),
|
|
||||||
Subtract => stack.push_back(y - x),
|
|
||||||
Multiply => stack.push_back(y * x),
|
|
||||||
Divide => stack.push_back(y / x),
|
|
||||||
Power => stack.push_back(y.powf(x)),
|
|
||||||
Floor => stack.push_back((y / x).floor()),
|
|
||||||
Modulo => stack.push_back(y % x),
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return Err(EvaluationError {
|
|
||||||
message: format!("{}: unexpected operation", op),
|
|
||||||
code: EX_DATAERR,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(stack)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn eval(
|
fn eval(
|
||||||
input: &str,
|
input: &str,
|
||||||
@ -179,7 +145,6 @@ fn eval(
|
|||||||
.rev()
|
.rev()
|
||||||
.map(|t| CalcType::from(t))
|
.map(|t| CalcType::from(t))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut ops: VecDeque<CalcType> = VecDeque::new();
|
let mut ops: VecDeque<CalcType> = VecDeque::new();
|
||||||
|
|
||||||
while let Some(n) = toks.pop_back() {
|
while let Some(n) = toks.pop_back() {
|
||||||
@ -187,15 +152,36 @@ fn eval(
|
|||||||
Val(v) => stack.push_back(v),
|
Val(v) => stack.push_back(v),
|
||||||
Invalid(i) => {
|
Invalid(i) => {
|
||||||
return Err(EvaluationError {
|
return Err(EvaluationError {
|
||||||
message: format!("{}: invalid token", i),
|
message: format!("{}: Invalid token", i),
|
||||||
code: EX_DATAERR,
|
code: EX_DATAERR,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
op => {
|
op => {
|
||||||
ops.push_back(op.clone());
|
ops.push_back(op.clone());
|
||||||
|
oper = true;
|
||||||
|
|
||||||
oper = true; /* this is an operation */
|
let vals = (
|
||||||
return operate(stack, op).map(|s| (s, oper));
|
stack.pop_back(),
|
||||||
|
stack.pop_back(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if let (Some(x), Some(y)) = vals {
|
||||||
|
match op {
|
||||||
|
Add => stack.push_back(y + x),
|
||||||
|
Subtract => stack.push_back(y - x),
|
||||||
|
Multiply => stack.push_back(y * x),
|
||||||
|
Divide => stack.push_back(y / x),
|
||||||
|
Power => stack.push_back(y.powf(x)),
|
||||||
|
Floor => stack.push_back((y / x).floor()),
|
||||||
|
Modulo => stack.push_back(y % x),
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return Err(EvaluationError {
|
||||||
|
message: format!("{}: Unexpected operation", op),
|
||||||
|
code: EX_DATAERR,
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -204,46 +190,51 @@ fn eval(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Round a float to the given precision level */
|
/* Round a float to the given precision level */
|
||||||
fn round_precise(value: &f64) -> f64 {
|
fn round_precise(value: &f64, precision: usize) -> f64 {
|
||||||
/* Set floating-point precision for correcting rounding errors based on
|
let multiplier = 10_f64.powi(precision as i32);
|
||||||
* machine epsilon */
|
|
||||||
let precision = (-f64::EPSILON.log10()).floor() as i32;
|
|
||||||
let multiplier = 10_f64.powi(precision);
|
|
||||||
|
|
||||||
(value * multiplier).round() / multiplier
|
(value * multiplier).round() / multiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print the stack and let the caller know if evaluation should continue */
|
|
||||||
fn unstack(stack: VecDeque<f64>, op: bool) -> Result<bool, Error> {
|
|
||||||
if let Some(val) = stack.iter().last() {
|
|
||||||
if !op { return Ok(true); }
|
|
||||||
|
|
||||||
let out = round_precise(val).to_string() + &'\n'.to_string();
|
|
||||||
|
|
||||||
return stdout().write_all(out.as_bytes()).map(|_| true);
|
|
||||||
} else {
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
let promises = Promises::new("stdio unveil");
|
let promises = Promises::new("stdio");
|
||||||
if let Err(e) = pledge(Some(promises), Some(Promises::default())) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
return err(&argv[0], &e, Some(EX_OSERR));
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
}
|
return ExitCode::from(EX_OSERR as u8);
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
|
||||||
return err(&argv[0], &e, Some(EX_OSERR));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stack = VecDeque::new();
|
let mut stack = VecDeque::new();
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
/* Set floating-point precision for correcting rounding errors based on
|
||||||
|
* machine epsilon */
|
||||||
|
let precision = (-f64::EPSILON.log10() * PRECISION_MOD).ceil() as usize;
|
||||||
|
|
||||||
if argv.get(1).is_some() { /* read expressions from argv */
|
if argv.get(1).is_none() { /* read from stdin */
|
||||||
|
while let Ok(_) = stdin().read_line(&mut buf) {
|
||||||
|
match eval(&buf.trim(), stack) {
|
||||||
|
Ok(s) => {
|
||||||
|
buf.clear();
|
||||||
|
stack = s.0.clone();
|
||||||
|
|
||||||
|
let val = match stack.iter().last() {
|
||||||
|
Some(v) => v,
|
||||||
|
None => break,
|
||||||
|
};
|
||||||
|
|
||||||
|
if s.1 == false { continue; }
|
||||||
|
|
||||||
|
println!("{}", round_precise(val, precision).to_string());
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("{}: {}", argv[0], err.message);
|
||||||
|
return ExitCode::from(err.code as u8);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else { /* read from argv */
|
||||||
/* join argv into an owned String joined by spaces minus argv[0] */
|
/* join argv into an owned String joined by spaces minus argv[0] */
|
||||||
let input = argv
|
let input = argv
|
||||||
.iter()
|
.iter()
|
||||||
@ -254,44 +245,20 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
match eval(&input, stack) {
|
match eval(&input, stack) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
/* we can ignore the return value of unstack() because we are
|
stack = s.0.clone();
|
||||||
* not continually evaluating from stdin */
|
|
||||||
if let Err(e) = unstack(s.0.clone(), s.1.clone()) {
|
|
||||||
return err(&argv[0], &e, Some(EX_IOERR));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExitCode::SUCCESS;
|
let val = match stack.iter().last() {
|
||||||
|
Some(v) => v,
|
||||||
|
None => return ExitCode::SUCCESS,
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{}", round_precise(val, precision).to_string())
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(err) => {
|
||||||
return err(&argv[0], &e, Some(e.code));
|
eprintln!("{}: {}", argv[0], err.message);
|
||||||
|
return ExitCode::from(err.code as u8);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* else, read from stdin */
|
|
||||||
loop { /* take input until EOF */
|
|
||||||
if let Err(e) = stdin().read_line(&mut buf) {
|
|
||||||
return err(&argv[0], &e, Some(EX_IOERR));
|
|
||||||
}
|
|
||||||
|
|
||||||
match eval(&buf.trim(), stack) {
|
|
||||||
Ok(s) => {
|
|
||||||
buf.clear();
|
|
||||||
stack = s.0.clone(); /* out with the old, in with the new */
|
|
||||||
|
|
||||||
match unstack(s.0, s.1) {
|
|
||||||
Ok(b) if b => continue,
|
|
||||||
Ok(_) => break,
|
|
||||||
Err(e) => {
|
|
||||||
return err(&argv[0], &e, Some(EX_IOERR))
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
return err(&argv[0], &e, Some(e.code));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
|
|||||||
program_name = argv[0] == NULL ? program_name : argv[0];
|
program_name = argv[0] == NULL ? program_name : argv[0];
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("rpath stdio unveil", "") == -1) {
|
if (pledge("rpath stdio unveil", NULL) == -1) {
|
||||||
perror(program_name);
|
perror(program_name);
|
||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
|
|||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (unveil(*argv, "rw") == -1) {
|
if (unveil(*argv, "r") == -1) {
|
||||||
perror(program_name);
|
perror(program_name);
|
||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <sysexits.h> /* EX_OSERR, EX_USAGE */
|
#include <sysexits.h> /* EX_OSERR, EX_USAGE */
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
# include <unistd.h> /* pledge(2), unveil(2) */
|
# include <unistd.h> /* pledge(2) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *program_name = "str";
|
char *program_name = "str";
|
||||||
@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
|
|||||||
program_name = argv[0] == NULL ? program_name : argv[0];
|
program_name = argv[0] == NULL ? program_name : argv[0];
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("stdio unveil", "") == -1 || unveil(NULL, NULL) == -1) {
|
if (pledge("stdio", NULL) == -1) {
|
||||||
perror(program_name);
|
perror(program_name);
|
||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <sysexits.h> /* EX_OK, EX_OSERR, EX_USAGE */
|
#include <sysexits.h> /* EX_OK, EX_OSERR, EX_USAGE */
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
# include <unistd.h> /* pledge(2), unveil(2) */
|
# include <unistd.h> /* pledge(2) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *program_name = "strcmp";
|
char *program_name = "strcmp";
|
||||||
@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("stdio unveil", "") == -1 || unveil(NULL, NULL) == -1) {
|
if (pledge("stdio", NULL) == -1) {
|
||||||
perror(argv[0] == NULL ? program_name : argv[0]);
|
perror(argv[0] == NULL ? program_name : argv[0]);
|
||||||
|
|
||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
|
34
src/swab.rs
34
src/swab.rs
@ -33,29 +33,31 @@ use sysexits::{ EX_IOERR, EX_OK, EX_OSERR, EX_USAGE };
|
|||||||
use strerror::StrError;
|
use strerror::StrError;
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] extern crate openbsd;
|
#[cfg(target_os="openbsd")] extern crate openbsd;
|
||||||
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge, unveil };
|
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
|
||||||
|
|
||||||
fn err(argv0: &String, e: Error, code: u8) -> ExitCode {
|
|
||||||
|
fn oserr(argv0: &str, e: Error) -> ExitCode {
|
||||||
eprintln!("{}: {}", argv0, e.strerror());
|
eprintln!("{}: {}", argv0, e.strerror());
|
||||||
ExitCode::from(code)
|
ExitCode::from(EX_OSERR as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(s: &String) -> ExitCode {
|
fn ioerr(argv0: &str, e: Error) -> ExitCode {
|
||||||
|
eprintln!("{}: {}", argv0, e.strerror());
|
||||||
|
ExitCode::from(EX_IOERR as u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(s: &str) -> ExitCode {
|
||||||
eprintln!("Usage: {} [-w word_size]", s);
|
eprintln!("Usage: {} [-w word_size]", s);
|
||||||
ExitCode::from(EX_USAGE)
|
ExitCode::from(EX_USAGE as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
#[cfg(target_os="openbsd")] {
|
#[cfg(target_os="openbsd")] {
|
||||||
let promises = Promises::new("stdio unveil");
|
let promises = Promises::new("stdio");
|
||||||
if let Err(e) = pledge(Some(promises), Some(Promises::default())) {
|
if let Err(e) = pledge(Some(promises), None) {
|
||||||
return err(&argv[0], e, EX_OSERR);
|
return oserr(&argv[0], e);
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = unveil(None, None) {
|
|
||||||
return err(&argv[0], e, EX_OSERR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,22 +88,22 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match input.read(&mut buf) {
|
match input.read(&mut buf) {
|
||||||
Ok(0) => break ExitCode::from(EX_OK), // read nothing; bye
|
Ok(0) => break ExitCode::from(EX_OK as u8), // read nothing; bye
|
||||||
Ok(v) if v == wordsize => { // read full block; swab
|
Ok(v) if v == wordsize => { // read full block; swab
|
||||||
let (left, right) = buf.split_at(v/2);
|
let (left, right) = buf.split_at(v/2);
|
||||||
|
|
||||||
if let Err(e) = output.write(&right)
|
if let Err(e) = output.write(&right)
|
||||||
.and_then(|_| output.write(&left)) {
|
.and_then(|_| output.write(&left)) {
|
||||||
break err(&argv[0], e, EX_IOERR);
|
break ioerr(&argv[0], e);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
Ok(v) => { // partial read; partially write
|
Ok(v) => { // partial read; partially write
|
||||||
if let Err(e) = output.write(&buf[..v]) {
|
if let Err(e) = output.write(&buf[..v]) {
|
||||||
break err(&argv[0], e, EX_IOERR);
|
break ioerr(&argv[0], e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => break err(&argv[0], e, EX_OSERR)
|
Err(e) => break oserr(&argv[0], e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
(void)pledge("stdio", "");
|
pledge(NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
31
tests/README
31
tests/README
@ -1,13 +1,24 @@
|
|||||||
Tests
|
The testing suite contains two trees: the Bonsai tree and the POSIX tree:
|
||||||
=====
|
|
||||||
|
|
||||||
The Harakit testing suite verifies the functionality of Harakit utilities
|
.
|
||||||
and checks for regressions and other issues relating to compliance to our
|
├── README
|
||||||
standards of practice.
|
├── bonsai/
|
||||||
|
│ ├── dj.mk
|
||||||
|
│ ├── false.mk
|
||||||
|
│ ├── fop.mk
|
||||||
|
│ └── ...
|
||||||
|
├── posix/
|
||||||
|
└── tests.mk
|
||||||
|
|
||||||
Tests inherit the environment set by the top-level Makefile, which sets the BIN
|
The Bonsai tree tests the functionality of Harakit utilities for regressions and
|
||||||
variable to the build/bin directory at the root of the project; therefore, each
|
other issues relating to compliance to our standards of practice.
|
||||||
binary is located at $(BIN)/tool for idiomatic access.
|
|
||||||
|
The POSIX tests are currently a work-in-progress. Their status in this
|
||||||
|
repository is uncertain.
|
||||||
|
|
||||||
|
Both sets of tests also inherit the environment set by the top-level Makefile,
|
||||||
|
which sets the BIN variable to the build/bin directory at the root of the
|
||||||
|
project; therefore, each binary is located at $(BIN)/tool for idiomatic access.
|
||||||
|
|
||||||
Each test contains a set of PHONY targets which are prefixed with the name of
|
Each test contains a set of PHONY targets which are prefixed with the name of
|
||||||
the tool being tested and an underscore. The first target is tests, which
|
the tool being tested and an underscore. The first target is tests, which
|
||||||
@ -16,10 +27,10 @@ included in the top Makefile, so they can be called from the root of the
|
|||||||
repository. This also means that BIN can be set manually so that tests can be
|
repository. This also means that BIN can be set manually so that tests can be
|
||||||
run using make(1) inside of the tests directory:
|
run using make(1) inside of the tests directory:
|
||||||
|
|
||||||
$ make -f dj.mk BIN=../build/bin dj_tests
|
$ make -f tests.mk BIN=../build/bin dj_tests
|
||||||
|
|
||||||
--
|
--
|
||||||
Copyright © 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
|
||||||
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
||||||
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
|
@ -24,7 +24,6 @@ fop_fail: $(BIN)/fop
|
|||||||
! printf 'test\n' | $(BIN)/fop 1 cat
|
! printf 'test\n' | $(BIN)/fop 1 cat
|
||||||
! printf 'test\n' | $(BIN)/fop 'test' cat
|
! printf 'test\n' | $(BIN)/fop 'test' cat
|
||||||
! printf 'test\n' | $(BIN)/fop -d'test' cat
|
! printf 'test\n' | $(BIN)/fop -d'test' cat
|
||||||
! $(BIN)/fop
|
|
||||||
|
|
||||||
.PHONY: fop_functionality
|
.PHONY: fop_functionality
|
||||||
fop_functionality: $(BIN)/fop
|
fop_functionality: $(BIN)/fop
|
@ -6,7 +6,7 @@
|
|||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: mm_tests
|
.PHONY: mm_tests
|
||||||
mm_tests: mm_args mm_help mm_stderr mm_remaining mm_remaining_options
|
mm_tests: mm_args mm_help mm_stderr mm_remaining
|
||||||
|
|
||||||
.PHONY: mm_none
|
.PHONY: mm_none
|
||||||
mm_none: $(BIN)/mm
|
mm_none: $(BIN)/mm
|
||||||
@ -32,9 +32,3 @@ mm_remaining: $(BIN)/mm
|
|||||||
test "$$($(BIN)/mm -i README COPYING)" = "$$(cat README COPYING)"
|
test "$$($(BIN)/mm -i README COPYING)" = "$$(cat README COPYING)"
|
||||||
$(BIN)/mm -i README -o /tmp/mm_test0 /tmp/mm_test1
|
$(BIN)/mm -i README -o /tmp/mm_test0 /tmp/mm_test1
|
||||||
diff /tmp/mm_test0 /tmp/mm_test1
|
diff /tmp/mm_test0 /tmp/mm_test1
|
||||||
|
|
||||||
.PHONY: mm_remaining_options
|
|
||||||
# check to make sure mm -i with trailing arguments interprets -o as one
|
|
||||||
mm_remaining_options:
|
|
||||||
! $(BIN)/mm -i README COPYING -o - 2>&1 | cut -d: -f2 \
|
|
||||||
| xargs test " -o" =
|
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
# Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
@ -26,7 +26,7 @@ npc_args:
|
|||||||
|
|
||||||
.PHONY: npc_ascii
|
.PHONY: npc_ascii
|
||||||
# Test 0x00 to 0x7f in input; in other words, the full 7b ASCII range.
|
# Test 0x00 to 0x7f in input; in other words, the full 7b ASCII range.
|
||||||
npc_ascii: npc_ascii_controls npc_ascii_uppers # npc_ascii_symbols \
|
npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \
|
||||||
# npc_ascii_lowers
|
# npc_ascii_lowers
|
||||||
|
|
||||||
.PHONY: npc_ascii_controls
|
.PHONY: npc_ascii_controls
|
||||||
@ -63,18 +63,14 @@ npc_ascii_controls:
|
|||||||
| tail -n 1 \
|
| tail -n 1 \
|
||||||
| xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_"
|
| xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_"
|
||||||
|
|
||||||
# This test is broken on Linux and will need closer inspection along with GNU
|
.PHONY: npc_ascii_symbols
|
||||||
# xargs(1).
|
# ASCII 0x1f to 0x3f (^_ and symbols)
|
||||||
# .PHONY: npc_ascii_symbols
|
npc_ascii_symbols:
|
||||||
# # ASCII 0x1f to 0x3f (^_ and symbols)
|
# shell quoting olympics
|
||||||
# npc_ascii_symbols:
|
awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }' \
|
||||||
# # shell quoting olympics
|
| $(BIN)/npc \
|
||||||
# c="$(awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }')"
|
| sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \
|
||||||
#
|
| xargs -I out test "^_ !\"#$$%&'()*+,-./0123456789:;<=>?" = out
|
||||||
# printf '%s\n' "$c" | $(BIN)/npc \
|
|
||||||
# | sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \
|
|
||||||
# | tr -d '\n' \
|
|
||||||
# | xargs -I out test "^_ !\"#$$%&\'()*+,-./0123456789:;<=>?" = out
|
|
||||||
|
|
||||||
.PHONY: npc_ascii_uppers
|
.PHONY: npc_ascii_uppers
|
||||||
# ASCII 0x40 to 0x5f (uppercases)
|
# ASCII 0x40 to 0x5f (uppercases)
|
@ -6,7 +6,7 @@
|
|||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: rpn_tests
|
.PHONY: rpn_tests
|
||||||
rpn_tests: rpn_help rpn_add rpn_sub rpn_mul rpn_div rpn_mod rpn_flr rpn_stdin
|
rpn_tests: rpn_help rpn_add rpn_sub rpn_mul rpn_div rpn_mod rpn_flr
|
||||||
|
|
||||||
.PHONY: rpn_help
|
.PHONY: rpn_help
|
||||||
rpn_help: $(BIN)/rpn
|
rpn_help: $(BIN)/rpn
|
||||||
@ -41,8 +41,3 @@ rpn_mod: $(BIN)/rpn
|
|||||||
rpn_flr: $(BIN)/rpn
|
rpn_flr: $(BIN)/rpn
|
||||||
test "$$($(BIN)/rpn 12 5 //)" -eq 2
|
test "$$($(BIN)/rpn 12 5 //)" -eq 2
|
||||||
test "$$($(BIN)/rpn 9 4 //)" -eq 2
|
test "$$($(BIN)/rpn 9 4 //)" -eq 2
|
||||||
|
|
||||||
# done last because all operations have been tested
|
|
||||||
.PHONY: rpn_stdin
|
|
||||||
rpn_stdin: $(BIN)/rpn
|
|
||||||
test "$$(printf '1\n2\n+\n3\n-\n' | $(BIN)/rpn | tail -n1)" -eq 0
|
|
@ -8,20 +8,20 @@
|
|||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
.PHONY: fileis_tests
|
.PHONY: scrut_tests
|
||||||
fileis_tests: fileis_help fileis_options
|
scrut_tests: scrut_help scrut_options
|
||||||
|
|
||||||
.PHONY: fileis_help
|
.PHONY: scrut_help
|
||||||
fileis_help: $(BIN)/fileis
|
scrut_help: $(BIN)/scrut
|
||||||
! $(BIN)/fileis -h
|
! $(BIN)/scrut -h
|
||||||
|
|
||||||
.PHONY: fileis_options
|
.PHONY: scrut_options
|
||||||
# fileis tests file attributes, but files of a certain attribute aren't
|
# scrut tests file attributes, but files of a certain attribute aren't
|
||||||
# guaranteed to be present on a system. This test checks all of the files in
|
# guaranteed to be present on a system. This test checks all of the files in
|
||||||
# harakit and, if test(1p) says a file matches a certain attribute, then checks
|
# harakit and, if test(1p) says a file matches a certain attribute, then checks
|
||||||
# fileis.
|
# scrut.
|
||||||
# opts are space-delimited (for command splitting), sel is not
|
# opts are space-delimited (for command splitting), sel is not
|
||||||
fileis_options: $(BIN)/fileis
|
scrut_options: $(BIN)/scrut
|
||||||
set -e; \
|
set -e; \
|
||||||
opts="b c d e f g k p r s u w x L S"; \
|
opts="b c d e f g k p r s u w x L S"; \
|
||||||
sel=; \
|
sel=; \
|
||||||
@ -30,12 +30,12 @@ fileis_options: $(BIN)/fileis
|
|||||||
for opt in $$opts; \
|
for opt in $$opts; \
|
||||||
do if ! printf "%s\n" $$sel | grep $$opt >/dev/null; then \
|
do if ! printf "%s\n" $$sel | grep $$opt >/dev/null; then \
|
||||||
if test -$$opt "$$f"; then \
|
if test -$$opt "$$f"; then \
|
||||||
if ! $(BIN)/fileis -$$opt "$$f"; \
|
if ! $(BIN)/scrut -$$opt "$$f"; \
|
||||||
then printf "[!!] fileis -%s failed on %s.\n" \
|
then printf "[!!] scrut -%s failed on %s.\n" \
|
||||||
$$opt "$$f"; \
|
$$opt "$$f"; \
|
||||||
fi; \
|
fi; \
|
||||||
sel="$$sel$$opt"; \
|
sel="$$sel$$opt"; \
|
||||||
printf "[OK] Tested fileis -%s using %s\n" \
|
printf "[OK] Tested scrut -%s using %s\n" \
|
||||||
$$opt "$$f"; \
|
$$opt "$$f"; \
|
||||||
fi; \
|
fi; \
|
||||||
fi; \
|
fi; \
|
22
tests/posix/bin/cat
Executable file
22
tests/posix/bin/cat
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
# Strictly POSIX-compliant cat(1) implementation. See cat(1p)
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
-u) args="$(printf '%s %s\n' "$args" "$arg")" ;;
|
||||||
|
*) args="$(printf -- '%s -i %s\n' "$args" "$arg")" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# See IEEE Std 1003.1-2017 3.282
|
||||||
|
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282
|
||||||
|
IFS=' '
|
||||||
|
|
||||||
|
mm $args
|
12
tests/posix/bin/false
Executable file
12
tests/posix/bin/false
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
# Strictly POSIX-compliant false(1) implementation. See false(1p)
|
||||||
|
|
||||||
|
false "$@"
|
11
tests/posix/bin/true
Executable file
11
tests/posix/bin/true
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
# Strictly POSIX-compliant true(1) implementation. See true(1p)
|
||||||
|
true "$@"
|
5
tests/posix/posix_env
Normal file
5
tests/posix/posix_env
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
PATH="$PWD/bin:$PATH"
|
15
tests/tests.mk
Normal file
15
tests/tests.mk
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
|
||||||
|
#TESTFILES != for file in tests/bonsai/*.mk tests/posix/*.mk; do printf '%s ' "$$file"; done;
|
||||||
|
TESTFILES != for file in tests/bonsai/*.mk; do printf '%s ' "$$file"; done;
|
||||||
|
|
||||||
|
TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \
|
||||||
|
| sed 's/\.mk/_tests/g'
|
||||||
|
|
||||||
|
include $(TESTFILES)
|
Loading…
Reference in New Issue
Block a user