Compare commits
8 Commits
ac0f9e4019
...
manpage-pr
| Author | SHA1 | Date | |
|---|---|---|---|
|
78eeb081d9
|
|||
|
4512590ffc
|
|||
|
25da591f9e
|
|||
|
8cde453f7b
|
|||
|
c8c308134c
|
|||
|
9d8d9d6e47
|
|||
|
be6bd5386d
|
|||
|
3b44ddeedd
|
@@ -4,7 +4,12 @@
|
||||
.\" 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 DJ 1 2024-07-14 "Harakit X.X.X"
|
||||
.TH DJ 1 2024-10-02 "Harakit X.X.X"
|
||||
.SH PROLOGUE
|
||||
\(lqSpin that track, catboy.\(rq
|
||||
|
||||
\(en DTB
|
||||
.\"
|
||||
.SH NAME
|
||||
dj \(en disk jockey
|
||||
.\"
|
||||
@@ -207,7 +212,7 @@ which are not reported.
|
||||
|
||||
This program was based on the
|
||||
.BR dd (1p)
|
||||
utility as specified in POSIX. While character conversion may have been the
|
||||
utility as specified in \*(Px. While character conversion may have been the
|
||||
original intent of
|
||||
.BR dd (1p),
|
||||
it is irrelevant to its modern use. Because of this, this program eschews
|
||||
|
||||
12
docs/false.1
12
docs/false.1
@@ -4,7 +4,15 @@
|
||||
.\" 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 FALSE 1 2024-06-06 "Harakit X.X.X"
|
||||
.TH FALSE 1 2024-10-02 "Harakit X.X.X"
|
||||
.SH PROLOGUE
|
||||
\(lqA monk asked Joshu, a Chinese Zen master: \(oqHas a dog Buddha-nature or
|
||||
not?\(cq
|
||||
|
||||
Joshu answered: \(oqMu.\(cq\(rq
|
||||
|
||||
\(en Mumon, The Gateless Gate, trans. Nyogen Senzaki & Paul Reps
|
||||
.\"
|
||||
.SH NAME
|
||||
false \(en do nothing, unsuccessfully
|
||||
.\"
|
||||
@@ -15,7 +23,7 @@ always be returned.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
In POSIX.1-2017,
|
||||
In \*(Px.1-2024,
|
||||
.BR false (1p)
|
||||
exists for the construction of control flow and loops based on a failure. This
|
||||
implementation functions as described in that standard.
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH FOP 1 2024-06-17 "Harakit X.X.X"
|
||||
.SH PROLOGUE
|
||||
\(lqTwist it! Pull it! [Fop] it!\(rq
|
||||
|
||||
\(en \fIBop It\fP
|
||||
.SH NAME
|
||||
fop \(en field operator
|
||||
.\"
|
||||
|
||||
@@ -4,6 +4,13 @@
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH HRU 1 2024-06-17 "Harakit X.X.X"
|
||||
.SH PROLOGUE
|
||||
\(lq\(oqHuman rights.\(cq Even the name is racist. The Federation is basically
|
||||
a \fIhomo sapiens\fP-only club...\(rq
|
||||
|
||||
\(en Azetbur, daughter of Chancellor Gorkon, \fIStar Trek VI: The Undiscovered
|
||||
Country\fP
|
||||
.\"
|
||||
.SH NAME
|
||||
hru \(en human readable units
|
||||
.\"
|
||||
|
||||
@@ -75,7 +75,7 @@ this is elegant but unintuitive.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
The traditional tool for integer comparisons in POSIX and other Unix shells has
|
||||
The traditional tool for integer comparisons in \*(Px and other Unix shells has
|
||||
been
|
||||
.BR test (1).
|
||||
This tool also handles string comparisons and file scrutiny. These parts of its
|
||||
|
||||
@@ -57,7 +57,7 @@ The
|
||||
.BR cat (1p)
|
||||
and
|
||||
.BR tee (1p)
|
||||
programs specified in POSIX together provide similar functionality. The
|
||||
programs specified in \*(Px together provide similar functionality. The
|
||||
separation of the two sets of functionality into separate APIs seemed
|
||||
unncessary.
|
||||
.\"
|
||||
|
||||
@@ -45,7 +45,7 @@ The program operates in single-byte chunks regardless of intended encoding.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
POSIX currently lacks a way to display non-printing characters in the terminal
|
||||
\*(Px currently lacks a way to display non-printing characters in the terminal
|
||||
using a standard tool. A popular extension to
|
||||
.BR cat (1p),
|
||||
the
|
||||
|
||||
@@ -58,7 +58,7 @@ hardware of any given machine.
|
||||
|
||||
An infix notation calculation utility,
|
||||
.BR bc (1p),
|
||||
is included in the POSIX standard, but does not accept expressions as arguments;
|
||||
is included in the \*(Px standard, but does not accept expressions as arguments;
|
||||
in scripts, any predefined, non-interactive input must be piped into the
|
||||
program. A
|
||||
.BR dc (1)
|
||||
|
||||
@@ -47,13 +47,13 @@ visual similarity and not byte similarity.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
The traditional tool for string comparisons in POSIX and other Unix shells has
|
||||
The traditional tool for string comparisons in \*(Px and other Unix shells has
|
||||
been
|
||||
.BR test (1).
|
||||
This tool also handles integer comparisons and file scrutiny. These parts of its
|
||||
functionality have been broken out into multiple utilities.
|
||||
|
||||
This program\(cqs functionality may be performed on a POSIX-compliant system
|
||||
This program\(cqs functionality may be performed on a \*(Px-compliant system
|
||||
with
|
||||
.BR test (1p).
|
||||
.\"
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
.\"
|
||||
.TH TRUE 1 2024-06-06 "Harakit X.X.X"
|
||||
.SH PROLOGUE
|
||||
\(lqThe truth is one, there is no second about which a person who knows it
|
||||
would argue with one who knows.\(rq
|
||||
|
||||
\(en The Buddha, Sutta Nip\[u0101]ta, trans. \[u1E6C]h\[u0101]nissaro Bhikkhu
|
||||
.SH NAME
|
||||
true \(en do nothing, successfully
|
||||
.\"
|
||||
@@ -15,7 +20,7 @@ always be returned.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
In \fIPOSIX.1-2017\fP,
|
||||
In \fI\*(Px.1-2024\fP,
|
||||
.BR true (1p)
|
||||
exists for the construction of control flow and loops based on a success. This
|
||||
implementation functions as described in that standard.
|
||||
|
||||
116
src/scrut.c
116
src/scrut.c
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023–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/.
|
||||
*/
|
||||
|
||||
#include <assert.h> /* assert(3) */
|
||||
#include <stdio.h> /* fprintf(3), stderr, NULL */
|
||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
||||
#include <string.h> /* memset(3), strchr(3) */
|
||||
#include <sysexits.h> /* EX_OSERR, EX_USAGE */
|
||||
#include <unistd.h> /* access(3), getopt(3), pledge(2), unveil(2), F_OK, R_OK,
|
||||
* W_OK, X_OK */
|
||||
#include <sys/stat.h> /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR,
|
||||
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
||||
* S_ISUID, S_ISVTX */
|
||||
|
||||
char *program_name = "scrut";
|
||||
#define OPTS "bcdefgkprsuwxLS"
|
||||
/* this is an array so main:sel's size can be known at compile time */
|
||||
static char opts[] = OPTS;
|
||||
|
||||
static int
|
||||
usage(char *argv0) {
|
||||
(void)fprintf(stderr, "Usage: %s [-" OPTS "] file...\n", argv0);
|
||||
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char sel[(sizeof opts) / (sizeof *opts)];
|
||||
|
||||
program_name = argv[0] == NULL ? program_name : argv[0];
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("rpath stdio unveil", "") == -1) {
|
||||
perror(program_name);
|
||||
return EX_OSERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc < 2) { return usage(program_name); }
|
||||
|
||||
{ /* option parsing */
|
||||
char *p;
|
||||
|
||||
memset(sel, '\0', sizeof sel);
|
||||
for (int c; (c = getopt(argc, argv, opts)) != -1;) {
|
||||
if ((p = strchr(opts, c)) == NULL) { return usage(argv[0]); }
|
||||
else {
|
||||
assert(p - opts < sizeof sel / sizeof *sel); /* bounds check */
|
||||
sel[p - opts] = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* straighten out selections; permute out nulls */
|
||||
p = sel;
|
||||
for (size_t i = 0; i < (sizeof sel) / (sizeof *sel); ++i) {
|
||||
if (sel[i] != '\0') {
|
||||
*p = sel[i];
|
||||
if (&sel[i] != p++) { sel[i] = '\0'; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc) { return usage(argv[0]); }
|
||||
|
||||
for (argv += optind ; *argv != NULL; argv = &argv[1]) {
|
||||
struct stat buf;
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
if (unveil(*argv, "rw") == -1) {
|
||||
perror(program_name);
|
||||
return EX_OSERR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1) {
|
||||
return EXIT_FAILURE; /* doesn't exist or isn't stattable */
|
||||
}
|
||||
|
||||
for (size_t i = 0; sel[i] != '\0'; ++i) {
|
||||
if (
|
||||
(sel[i] == 'b' && !S_ISBLK(buf.st_mode))
|
||||
|| (sel[i] == 'c' && !S_ISCHR(buf.st_mode))
|
||||
|| (sel[i] == 'd' && !S_ISDIR(buf.st_mode))
|
||||
|| (sel[i] == 'e' && 0)
|
||||
|| (sel[i] == 'f' && !S_ISREG(buf.st_mode))
|
||||
|| (sel[i] == 'g' && !(buf.st_mode & S_ISGID))
|
||||
|| (sel[i] == 'k' && !(buf.st_mode & S_ISVTX))
|
||||
|| (sel[i] == 'p' && !S_ISFIFO(buf.st_mode))
|
||||
|| (sel[i] == 'r' && access(*argv, R_OK) != 0)
|
||||
|| (sel[i] == 'u' && !(buf.st_mode & S_ISUID))
|
||||
|| (sel[i] == 'w' && access(*argv, W_OK) != 0)
|
||||
|| (sel[i] == 'x' && access(*argv, X_OK) != 0)
|
||||
|| (sel[i] == 'L' && !S_ISLNK(buf.st_mode))
|
||||
|| (sel[i] == 'S' && !S_ISSOCK(buf.st_mode))
|
||||
) { return EXIT_FAILURE; }
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user