From 194b19f94b9e3dd01408bfcf22fbe6717636c818 Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 17 Feb 2024 23:43:22 -0700 Subject: [PATCH 001/134] mm(1): add --- Makefile | 7 +- docs/mm.1 | 76 +++++++++++++++++++ src/mm.c | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 docs/mm.1 create mode 100644 src/mm.c diff --git a/Makefile b/Makefile index 0f269f7..bf55ae7 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ CC=cc RUSTC=rustc .PHONY: all -all: dj false fop intcmp rpn scrut str strcmp true +all: dj false fop intcmp mm rpn scrut str strcmp true build: # keep build/include until bindgen(1) has stdin support @@ -79,6 +79,11 @@ intcmp: build/bin/intcmp build/bin/intcmp: src/intcmp.c build $(CC) $(CFLAGS) -o $@ src/intcmp.c +.PHONY: mm +mm: build/bin/mm +build/bin/mm: src/mm.c build + $(CC) $(CFLAGS) -o $@ src/mm.c + .PHONY: rpn rpn: build/bin/rpn build/bin/rpn: src/rpn.rs build build/o/libsysexits.rlib diff --git a/docs/mm.1 b/docs/mm.1 new file mode 100644 index 0000000..36fb1ba --- /dev/null +++ b/docs/mm.1 @@ -0,0 +1,76 @@ +.\" Copyright (c) 2024 DTB +.\" +.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, +.\" visit . + +.TH mm 1 + +.SH NAME + +mm \(en middleman + +.SH SYNOPSIS + +mm +.RB ( -aenu ) +.RB ( -i +.RB [ input ]) +.RB ( -o +.RB [ output ]) + +.SH DESCRIPTION + +Mm catenates input files and writes them to the start of each output file. + +.SH OPTIONS + +Mm, upon receiving the +.B -a +option, will open subsequent outputs for appending rather than updating. +.PP +The +.B -i +option opens a path as an input. Without any inputs specified mm will use +standard input. Standard input itself can be specified by giving the path '-'. +.PP +The +.B -o +option opens a path as an output. Without any outputs specified mm will use +standard output. Standard output itself can be specified by giving the +path '-'. Standard error itself can be specified with the +.B -e +option. +.PP +The +.B -u +option ensures neither input or output will be buffered. +.PP +The +.B -n +option tells mm to ignore SIGINT signals. + +.SH DIAGNOSTICS + +If an output can no longer be written mm prints a diagnostic message, ceases +writing to that particular output, and if there are more outputs specified, +continues, eventually exiting unsuccessfully. +.PP +On error mm prints a diagnostic message and exits with the appropriate +sysexits.h(3) status. + +.SH BUGS + +Mm does not truncate existing files, which may lead to unexpected results. + +.SH RATIONALE + +Mm was modeled after the cat and tee utilities specified in POSIX. + +.SH COPYRIGHT + +Copyright (C) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +. + +.SH SEE ALSO + +cat(1p), dd(1), dj(1), tee(1p) diff --git a/src/mm.c b/src/mm.c new file mode 100644 index 0000000..6e53c8d --- /dev/null +++ b/src/mm.c @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2024 DTB + * 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 /* errno */ +#include /* signal(2), SIG_ERR, SIG_IGN, SIGINT */ +#include /* fclose(3), fopen(3), fprintf(3), getc(3), putc(3), + * setvbuf(3), size_t, _IONBF, NULL */ +#include /* free(3), realloc(3) */ +#include /* strcmp(3), strerror(3) */ +#include /* getopt(3) */ +#if !defined EX_OSERR || !defined EX_USAGE +# include +#endif +extern int errno; + +/* This structure is how open files are tracked. */ +struct Files{ + size_t a; /* allocation */ + size_t s; /* used size */ + char *mode; /* file opening mode */ + char **names; /* file names */ + FILE **files; /* file pointers */ +}; + +/* How much to grow the allocation when it's saturated. */ +#ifndef ALLOC_INCREMENT +# define ALLOC_INCREMENT 1 +#endif + +/* How much to grow the allocation at program start. */ +#ifndef ALLOC_INITIAL +# define ALLOC_INITIAL 10 +#endif + +/* pre-allocated strings */ +static char *program_name = ""; +static char *stdin_name = ""; +static char *stdout_name = ""; +static char *stderr_name = ""; +static char *(fmode[]) = { (char []){"rb"}, (char []){"rb+"} }; +static char *wharsh = "wb"; + +/* Adds the open FILE pointer for the file at the path s to the files struct, + * returning the FILE if successful and NULL if not, allocating more memory in + * the files buffers as needed. */ +static FILE * +Files_append(struct Files *files, FILE *file, char *name){ + + if(file == NULL || (files->s == files->a + && ((files->files = realloc(files->files, + (files->a += (files->a == 0) + ? ALLOC_INITIAL + : ALLOC_INCREMENT) + * sizeof *(files->files))) == NULL + || (files->names = realloc(files->names, + files->a * sizeof *(files->names))) == NULL))) + return NULL; + + files->names[files->s] = name; + return files->files[files->s++] = file; +} + +/* Opens the file at the path p and puts it in the files struct, returning NULL + * if either the opening or the placement of the open FILE pointer fail. */ +#define Files_open(files, p) \ + Files_append((files), fopen((p), (files)->mode), (p)) + +/* Prints a diagnostic message based on errno and returns an exit status + * appropriate for an OS error. */ +static int +oserr(char *s, char *r){ + + fprintf(stderr, "%s: %s: %s\n", s, r, strerror(errno)); + + return EX_OSERR; +} + +/* Hijacks i and j from main and destructs the files[2] struct used by main by + * closing its files and freeing its files and names arrays, returning retval + * from main. */ +#define terminate \ + for(i = 0; i < 2; ++i){ \ + for(j = 0; j < files[i].s; ++j) \ + if(files[i].files[j] != stdin \ + && files[i].files[j] != stdout \ + && files[i].files[j] != stderr) \ + fclose(files[i].files[j]); \ + free(files[i].files); \ + free(files[i].names); \ + } \ + return retval + +int main(int argc, char *argv[]){ + int c; + struct Files files[2]; /* {read, write} */ + size_t i; + size_t j; + size_t k; /* loop index but also unbuffer status */ + int retval; + + /* Initializes the files structs with their default values, standard + * input and standard output. If an input or an output is specified + * these initial values will be overwritten, so to, say, use mm(1) + * equivalently to tee(1p), -o - will need to be specified before + * additional files to ensure standard output is still written. */ + for(i = 0; i < 2; ++i){ + files[i].a = 0; + files[i].s = 0; + files[i].mode = fmode[i]; + files[i].files = NULL; + files[i].names = NULL; + Files_append(&files[i], i == 0 ? stdin : stdout, + i == 0 ? stdin_name : stdout_name); + files[i].s = 0; + } + + k = 0; + + while((c = getopt(argc, argv, "aehi:no:u")) != -1) + switch(c){ + case 'a': /* "rb+" -> "ab" */ + files[1].mode[0] = 'a'; + files[1].mode[2] = '\0'; + break; + case 'e': + if(Files_append(&files[1], stderr, stderr_name) != NULL) + break; + retval = oserr(argv[0], "-e"); + terminate; + case 'i': + if((strcmp(optarg, "-") == 0 && Files_append(&files[0], + stdin, stdin_name) != NULL) + || Files_open(&files[0], optarg) != NULL) + break; + retval = oserr(argv[0], optarg); + terminate; + case 'o': + if((strcmp(optarg, "-") == 0 && Files_append(&files[1], + stdout, stdout_name) != NULL) + || Files_open(&files[1], optarg) != NULL) + break; + /* does not exist, so try to create it */ + if(errno == ENOENT){ + files[1].mode = wharsh; + if(Files_open(&files[1], optarg) != NULL){ + files[1].mode = fmode[1]; + break; + } + } + retval = oserr(argv[0], optarg); + terminate; + case 'n': + if(signal(SIGINT, SIG_IGN) != SIG_ERR) + break; + retval = oserr(argv[0], "-n"); + terminate; + case 'u': + k = 1; + break; + default: + fprintf(stderr, "Usage: %s (-aenu) (-i [input])..." + " (-o [output])...\n", argv[0]); + retval = EX_USAGE; + terminate; + } + + files[0].s += files[0].s == 0; + files[1].s += files[1].s == 0; + + /* Unbuffer files. */ + if(k){ + for(i = 0; + i < files[0].s; + setvbuf(files[0].files[i++], NULL, _IONBF, 0)); + for(i = 0; + i < files[1].s; + setvbuf(files[1].files[i++], NULL, _IONBF, 0)); + } + + retval = 0; + + /* Actual program loop. */ + for(i = 0; i < files[0].s; ++i) /* iterate ins */ + while((c = getc(files[0].files[i])) != EOF) /* iterate chars */ + for(j = 0; j < files[1].s; ++j) /* iterate outs */ + if(putc(c, files[1].files[j]) == EOF){ + /* notebook's full */ + retval = 1; + if(fclose(files[1].files[j]) == EOF) + fprintf(stderr, "%s: %s: %s\n", + program_name, files[1].names[j], strerror(errno)); + /* massage out the tense muscle */ + for(k = j; k < files[1].s - 1; ++k){ + files[1].files[k] = files[1].files[k+1]; + files[1].names[k] = files[1].names[k+1]; + } + if(--files[i].s == 0) + terminate; + } + + terminate; +} From 395205d4c61cf94be98dda93af6a9289a9d21e4a Mon Sep 17 00:00:00 2001 From: DTB Date: Thu, 22 Feb 2024 19:14:38 -0700 Subject: [PATCH 002/134] mm.1: fix case in copyright thingy --- docs/mm.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mm.1 b/docs/mm.1 index 36fb1ba..e84ac66 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -68,7 +68,7 @@ Mm was modeled after the cat and tee utilities specified in POSIX. .SH COPYRIGHT -Copyright (C) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .SH SEE ALSO From 58245c9484ca74ad2d71d0dbe63b861820c65db9 Mon Sep 17 00:00:00 2001 From: DTB Date: Thu, 22 Feb 2024 19:27:14 -0700 Subject: [PATCH 003/134] dj(1): remove function pointer hijinks (fixes #66) --- src/dj.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/dj.c b/src/dj.c index d5bd59c..8a6732c 100644 --- a/src/dj.c +++ b/src/dj.c @@ -203,28 +203,28 @@ Io_fdseek(struct Io *io){ if(!fdisstd(io->fd) && lseek(io->fd, io->seek, SEEK_SET) != -1) return -1; - else if(io->fl == write_flags){ - memset(io->buf, '\0', io->bs); - /* This is a dirty trick; rather than testing conditions and operating - * likewise, because the parameters to read or write are going to be - * the same either way, just use a function pointer to keep track of - * the intended operation. */ - op = (int (*)(int, void *, size_t))&write; - /* Function pointer casts are risky; this works because the difference - * is in the second parameter and only that write(2) makes the buffer - * const whereas read(2) does not. To avoid even the slightest - * undefined behavior comment out the cast, just be ready for a - * -Wincompatible-function-pointer-types if your compiler notices it. - */ - }else - op = &read; - /* We're going to cheat and use bufuse as the retval for write(2), which is - * fine because it'll be zeroed as this function returns anyway. */ - do{ if( (io->bufuse = (*op)(io->fd, io->buf, MIN(io->bs, io->seek))) == 0) - /* second chance */ - io->bufuse = (*op)(io->fd, io->buf, MIN(io->bs, io->seek)); - }while((io->seek -= io->bufuse) > 0 && io->bufuse != 0); + /* repeated code to get the condition out of the loop */ + if(io->fl == write_flags){ + memset(io->buf, '\0', io->bs); + /* We're going to cheat and use bufuse as the retval for write(2), + * which is fine because it'll be zeroed as this function returns + * anyway. */ + do{ + if((io->bufuse = write(io->fd, io->buf, MIN(io->bs, io->seek))) + == 0) + /* second chance */ + io->bufuse = write(io->fd, io->buf, MIN(io->bs, io->seek)); + }while((io->seek -= io->bufuse) > 0 && io->bufuse != 0); + }else if(io->fl == read_flags){ + do{ + if((io->bufuse = read(io->fd, io->buf, MIN(io->bs, io->seek))) + == 0) + /* second chance */ + io->bufuse = read(io->fd, io->buf, MIN(io->bs, io->seek)); + }while((io->seek -= io->bufuse) > 0 && io->bufuse != 0); + }else + return EX_SOFTWARE; io->bufuse = 0; From 3f0d95fe8fe87cd3b3c6ba766e1ec643d6f7faa6 Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 23 Feb 2024 20:49:24 -0700 Subject: [PATCH 004/134] swab(1): minimum viable program --- Makefile | 7 +++++++ src/swab.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/swab.rs diff --git a/Makefile b/Makefile index 46fd88e..d8c0c59 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,13 @@ strcmp: build/bin/strcmp build/bin/strcmp: src/strcmp.c build $(CC) $(CFLAGS) -o $@ src/strcmp.c +.PHONY: swab +swab: build/bin/swab +build/bin/swab: src/swab.rs build build/o/libsysexits.rlib + $(RUSTC) $(RUSTFLAGS) \ + --extern sysexits=build/o/libsysexits.rlib \ + -o $@ src/swab.rs + .PHONY: true true: build/bin/true build/bin/true: src/true.c build diff --git a/src/swab.rs b/src/swab.rs new file mode 100644 index 0000000..26104eb --- /dev/null +++ b/src/swab.rs @@ -0,0 +1,47 @@ +use std::{ + env::args, + io::{ stdin, stdout, Error, ErrorKind, Read, Write }, + process::ExitCode, + vec::Vec +}; + +extern crate sysexits; + +use sysexits::{ EX_OK, EX_OSERR }; + +fn oserr(s: &str, e: Error) -> ExitCode { + eprintln!("{}: {}", s, e); + ExitCode::from(EX_OSERR as u8) +} + +fn main() -> ExitCode { + let argv = args().collect::>(); + let mut buf: Vec = Vec::new(); + let mut input = stdin(); + let mut output = stdout().lock(); + + let wordsize: usize = 2; + let force = false; + + buf.resize(wordsize, 0); + + loop { + match input.read(&mut buf) { + Ok(0) => break ExitCode::from(EX_OK as u8), + Ok(v) if v == wordsize => { + let (left, right) = buf.split_at(v/2); + if let Err(e) = output.write(&right) + .and_then(|_| output.write(&left)) { + break oserr(&argv[0], e) + } + }, + Ok(v) => { + if let Err(e) = output.write(&buf[..v]) { + break oserr(&argv[0], e) + } + }, + Err(e) if e.kind() == ErrorKind::Interrupted && force => continue, + Err(e) => break oserr(&argv[0], e) + } + } +} From e788947fc4adfd2084b7fb1af0cf7aee7acbee0a Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 24 Feb 2024 03:04:05 -0700 Subject: [PATCH 005/134] swab(1): add argument parsing --- Makefile | 2 +- src/swab.rs | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d8c0c59..3c4f52e 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ build/bin/strcmp: src/strcmp.c build .PHONY: swab swab: build/bin/swab build/bin/swab: src/swab.rs build build/o/libsysexits.rlib - $(RUSTC) $(RUSTFLAGS) \ + $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \ --extern sysexits=build/o/libsysexits.rlib \ -o $@ src/swab.rs diff --git a/src/swab.rs b/src/swab.rs index 26104eb..f48842c 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -5,23 +5,48 @@ use std::{ vec::Vec }; -extern crate sysexits; +extern crate getopt; +use getopt::{ Opt, Parser }; -use sysexits::{ EX_OK, EX_OSERR }; +extern crate sysexits; +use sysexits::{ EX_OK, EX_OSERR, EX_USAGE }; fn oserr(s: &str, e: Error) -> ExitCode { eprintln!("{}: {}", s, e); ExitCode::from(EX_OSERR as u8) } +fn usage(s: &str) -> ExitCode { + eprintln!("Usage: {} (-f) (-w [wordsize])", s); + ExitCode::from(EX_USAGE as u8) +} + fn main() -> ExitCode { let argv = args().collect::>(); let mut buf: Vec = Vec::new(); let mut input = stdin(); let mut output = stdout().lock(); - let wordsize: usize = 2; - let force = false; + let mut opts = Parser::new(&argv, "fw:"); + let mut force = false; + let mut wordsize: usize = 2; + + loop { + match opts.next() { + None => break, + Some(opt) => + match opt { + Ok(Opt('f', None)) => force = true, + Ok(Opt('w', Some(arg))) => { + match arg.parse::() { + Ok(w) if w % 2 == 0 => { wordsize = w; () }, + _ => { return usage(&argv[0]); }, + } + }, + _ => { return usage(&argv[0]); } + } + } + } buf.resize(wordsize, 0); From 1e041a52a2eab165af03a157c83ce388c05bd73c Mon Sep 17 00:00:00 2001 From: DTB Date: Sat, 24 Feb 2024 03:21:20 -0700 Subject: [PATCH 006/134] swab.1: add swab(1) man page --- docs/swab.1 | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 docs/swab.1 diff --git a/docs/swab.1 b/docs/swab.1 new file mode 100644 index 0000000..a0c1be3 --- /dev/null +++ b/docs/swab.1 @@ -0,0 +1,71 @@ +.\" Copyright (c) 2024 DTB +.\" +.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, +.\" visit . + +.TH swab 1 + +.SH NAME + +swab \(en swap bytes + +.SH SYNOPSIS + +swab +.RB ( -f ) +.RB ( -w +.R [ +.B word size +.R ]) + +.SH USAGE + +Swab swaps the latter and former halves of a block of bytes. + +.SH EXAMPLES + +The following sh(1p) line: + +.R printf 'hello world!\n' | swab + +Produces the following output: + +.R ehll oowlr!d + +.SH OPTIONS + +The +.B -f +option ignores system call interruptions. +.PP +The +.B -w +option configures the word size; that is, the size in bytes of the block size +on which to operate. By default the word size is 2. The word size must be +cleanly divisible by 2, otherwise the block of bytes being processed can't be +halved. + +.SH DIAGNOSTICS + +If an error is encountered in input, output, or invocation, a diagnostic +message will be written to standard error and swab will exit with the +appropriate status from sysexits.h(3). + +.SH RATIONALE + +Swab was modeled after the +.R conv=swab +functionality specified in the POSIX dd utility but additionally allows the +word size to be configured. +.PP +Swab is useful for fixing the endianness of binary files produced on other +machines. + +.SH COPYRIGHT + +Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +. + +.SH SEE ALSO + +dd(1p) From bbac85daf8439c5b1ea9aebb6fe018066817cc12 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 26 Feb 2024 08:42:06 -0700 Subject: [PATCH 007/134] swab(1): add copyright notice --- src/swab.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/swab.rs b/src/swab.rs index f48842c..ca944d9 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024 DTB + * 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, io::{ stdin, stdout, Error, ErrorKind, Read, Write }, From f14877118dd2206ab3d7d0914ba3a8a41c73a3cc Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 26 Feb 2024 08:43:03 -0700 Subject: [PATCH 008/134] Makefile: add swab(1) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c4f52e..a630e09 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ CC=cc RUSTC=rustc .PHONY: all -all: dj false fop intcmp rpn scrut str strcmp true +all: dj false fop intcmp rpn scrut str strcmp swab true build: # keep build/include until bindgen(1) has stdin support From d74bc715cf951352ae66d65403ebff55ab4e53c4 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 26 Feb 2024 09:02:58 -0700 Subject: [PATCH 009/134] mm(1): fix full file handling --- src/mm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mm.c b/src/mm.c index 6e53c8d..5e81f7f 100644 --- a/src/mm.c +++ b/src/mm.c @@ -23,7 +23,8 @@ #include /* free(3), realloc(3) */ #include /* strcmp(3), strerror(3) */ #include /* getopt(3) */ -#if !defined EX_OSERR || !defined EX_USAGE +#if !defined EX_IOERR || !defined EX_OK || !defined EX_OSERR \ + || !defined EX_USAGE # include #endif extern int errno; @@ -192,7 +193,7 @@ int main(int argc, char *argv[]){ setvbuf(files[1].files[i++], NULL, _IONBF, 0)); } - retval = 0; + retval = EX_OK; /* Actual program loop. */ for(i = 0; i < files[0].s; ++i) /* iterate ins */ @@ -200,16 +201,16 @@ int main(int argc, char *argv[]){ for(j = 0; j < files[1].s; ++j) /* iterate outs */ if(putc(c, files[1].files[j]) == EOF){ /* notebook's full */ - retval = 1; + retval = EX_IOERR; if(fclose(files[1].files[j]) == EOF) fprintf(stderr, "%s: %s: %s\n", program_name, files[1].names[j], strerror(errno)); /* massage out the tense muscle */ - for(k = j; k < files[1].s - 1; ++k){ + for(k = j--; k < files[1].s - 1; ++k){ files[1].files[k] = files[1].files[k+1]; files[1].names[k] = files[1].names[k+1]; } - if(--files[i].s == 0) + if(--files[1].s == 0) terminate; } From 135bf2a8ebf7b08bf10acb16e2ebb51d2395a682 Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 26 Feb 2024 09:11:47 -0700 Subject: [PATCH 010/134] mm(1), mm.1: bring source in line with documentation --- docs/mm.1 | 2 +- src/mm.c | 92 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index e84ac66..2244588 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -56,7 +56,7 @@ writing to that particular output, and if there are more outputs specified, continues, eventually exiting unsuccessfully. .PP On error mm prints a diagnostic message and exits with the appropriate -sysexits.h(3) status. +sysexits.h(3) status. .SH BUGS diff --git a/src/mm.c b/src/mm.c index 5e81f7f..ff62148 100644 --- a/src/mm.c +++ b/src/mm.c @@ -132,53 +132,57 @@ int main(int argc, char *argv[]){ k = 0; - while((c = getopt(argc, argv, "aehi:no:u")) != -1) - switch(c){ - case 'a': /* "rb+" -> "ab" */ - files[1].mode[0] = 'a'; - files[1].mode[2] = '\0'; - break; - case 'e': - if(Files_append(&files[1], stderr, stderr_name) != NULL) + if(argc > 0) + program_name = argv[0]; + + if(argc > 1) + while((c = getopt(argc, argv, "aehi:no:u")) != -1) + switch(c){ + case 'a': /* "rb+" -> "ab" */ + files[1].mode[0] = 'a'; + files[1].mode[2] = '\0'; break; - retval = oserr(argv[0], "-e"); - terminate; - case 'i': - if((strcmp(optarg, "-") == 0 && Files_append(&files[0], - stdin, stdin_name) != NULL) - || Files_open(&files[0], optarg) != NULL) - break; - retval = oserr(argv[0], optarg); - terminate; - case 'o': - if((strcmp(optarg, "-") == 0 && Files_append(&files[1], - stdout, stdout_name) != NULL) - || Files_open(&files[1], optarg) != NULL) - break; - /* does not exist, so try to create it */ - if(errno == ENOENT){ - files[1].mode = wharsh; - if(Files_open(&files[1], optarg) != NULL){ - files[1].mode = fmode[1]; + case 'e': + if(Files_append(&files[1], stderr, stderr_name) != NULL) break; + retval = oserr(argv[0], "-e"); + terminate; + case 'i': + if((strcmp(optarg, "-") == 0 && Files_append(&files[0], + stdin, stdin_name) != NULL) + || Files_open(&files[0], optarg) != NULL) + break; + retval = oserr(argv[0], optarg); + terminate; + case 'o': + if((strcmp(optarg, "-") == 0 && Files_append(&files[1], + stdout, stdout_name) != NULL) + || Files_open(&files[1], optarg) != NULL) + break; + /* does not exist, so try to create it */ + if(errno == ENOENT){ + files[1].mode = wharsh; + if(Files_open(&files[1], optarg) != NULL){ + files[1].mode = fmode[1]; + break; + } } - } - retval = oserr(argv[0], optarg); - terminate; - case 'n': - if(signal(SIGINT, SIG_IGN) != SIG_ERR) + retval = oserr(argv[0], optarg); + terminate; + case 'n': + if(signal(SIGINT, SIG_IGN) != SIG_ERR) + break; + retval = oserr(argv[0], "-n"); + terminate; + case 'u': + k = 1; break; - retval = oserr(argv[0], "-n"); - terminate; - case 'u': - k = 1; - break; - default: - fprintf(stderr, "Usage: %s (-aenu) (-i [input])..." - " (-o [output])...\n", argv[0]); - retval = EX_USAGE; - terminate; - } + default: + fprintf(stderr, "Usage: %s (-aenu) (-i [input])..." + " (-o [output])...\n", argv[0]); + retval = EX_USAGE; + terminate; + } files[0].s += files[0].s == 0; files[1].s += files[1].s == 0; @@ -202,6 +206,8 @@ int main(int argc, char *argv[]){ if(putc(c, files[1].files[j]) == EOF){ /* notebook's full */ retval = EX_IOERR; + fprintf(stderr, "%s: %s: %s\n", + program_name, files[1].names[j], strerror(errno)); if(fclose(files[1].files[j]) == EOF) fprintf(stderr, "%s: %s: %s\n", program_name, files[1].names[j], strerror(errno)); From e81703c6e1555586d20cfafbf972f61c890635f1 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:04:53 -0700 Subject: [PATCH 011/134] sterror(3): added library for C-like error messages; Makefile: some efficiency changes --- Makefile | 43 ++++++++++++++++++++++++------------------- src/strerror.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 src/strerror.rs diff --git a/Makefile b/Makefile index f181e20..cb6bca6 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,11 @@ PREFIX=/usr/local -CC=cc -RUSTC=rustc +CC != command -v "$$CC" || printf 'cc\n' +RUSTC != command -v "$$RUSTC" || printf 'rustc\n' +RUSTLIBS=--extern getopt=build/o/libgetopt.rlib \ + --extern sysexits=build/o/libsysexits.rlib \ + --extern strerror=build/o/libstrerror.rlib .PHONY: all all: dj false fop hru intcmp rpn scrut str strcmp true @@ -43,6 +46,18 @@ test: build tests/posix-compat.sh $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt +.PHONY: rustlibs +rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ + build/o/libstrerror.rlib + +build/o/libgetopt.rlib: build src/getopt-rs/lib.rs + $(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \ + -o $@ src/getopt-rs/lib.rs + +build/o/libstrerror.rlib: build src/strerror.rs + $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ + src/strerror.rs + build/o/libsysexits.rlib: build # bandage solution until bindgen(1) gets stdin support printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \ @@ -51,11 +66,7 @@ build/o/libsysexits.rlib: build "$$(printf '#include \n' \ | cpp -M -idirafter "build/include" - \ | sed 's/ /\n/g' | grep sysexits.h)" \ - | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o build/o/libsysexits.rlib - - -build/o/libgetopt.rlib: src/getopt-rs/lib.rs - $(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \ - -o build/o/libgetopt.rlib src/getopt-rs/lib.rs + | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ - .PHONY: dj dj: build/bin/dj @@ -69,17 +80,13 @@ build/bin/false: src/false.c build .PHONY: fop fop: build/bin/fop -build/bin/fop: src/fop.rs build build/o/libgetopt.rlib build/o/libsysexits.rlib - $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \ - --extern sysexits=build/o/libsysexits.rlib \ - -o $@ src/fop.rs +build/bin/fop: src/fop.rs build rustlibs + $(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/fop.rs .PHONY: hru hru: build/bin/hru -build/bin/hru: src/hru.rs build build/o/libgetopt.rlib build/o/libsysexits.rlib - $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \ - --extern sysexits=build/o/libsysexits.rlib \ - -o $@ src/hru.rs +build/bin/hru: src/hru.rs build rustlibs + $(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/hru.rs .PHONY: intcmp intcmp: build/bin/intcmp @@ -88,10 +95,8 @@ build/bin/intcmp: src/intcmp.c build .PHONY: rpn rpn: build/bin/rpn -build/bin/rpn: src/rpn.rs build build/o/libsysexits.rlib - $(RUSTC) $(RUSTFLAGS) \ - --extern sysexits=build/o/libsysexits.rlib \ - -o $@ src/rpn.rs +build/bin/rpn: src/rpn.rs build rustlibs + $(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/rpn.rs .PHONY: scrut scrut: build/bin/scrut diff --git a/src/strerror.rs b/src/strerror.rs new file mode 100644 index 0000000..0939df9 --- /dev/null +++ b/src/strerror.rs @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Emma Tebibyte + * 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. + */ + +use std::ffi::{ c_int, c_char, CStr }; + +/* binding to strerror(3p) */ +extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } + +/* wrapper function for use in Rust */ +pub fn c_error(err: std::io::Error) -> String { + /* Get the raw OS error. If it’s None, what the hell is going on‽ */ + let error = err.raw_os_error().unwrap_or_else(|| { panic!() }) as c_int; + + /* Get a CStr from the error message so that it’s referenced and then + * convert it to an owned value. If the string is not valid UTF-8, return + * that error instead. */ + match unsafe { CStr::from_ptr(strerror(error)) }.to_str() { + Ok(s) => s.to_owned(), // yay!! :D + Err(e) => e.to_string(), // awww :( + } +} From 8f956d775c4006b688e3a194ecdff3d629c1c8e0 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:10:28 -0700 Subject: [PATCH 012/134] fop(1): changed to use strerror(3) --- src/fop.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index c9a767e..0e0b059 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -22,10 +22,12 @@ use std::{ process::{ Command, exit, Stdio }, }; -extern crate sysexits; extern crate getopt; +extern crate strerror; +extern crate sysexits; use getopt::{ Opt, Parser }; +use strerror::c_error; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { @@ -55,7 +57,7 @@ fn main() { }); let index = argv[index_arg].parse::().unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[1], e); + eprintln!("{}: {}: {}", argv[0], argv[1], e); exit(EX_DATAERR); }); @@ -75,13 +77,13 @@ fn main() { .stdout(Stdio::piped()) .spawn() .unwrap_or_else( |e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); exit(EX_UNAVAILABLE); }); let field = fields.get(index).unwrap_or_else(|| { eprintln!( - "{}: {}: No such index in input.", + "{}: {}: No such index in input", argv[0], index.to_string(), ); @@ -94,7 +96,7 @@ fn main() { } let output = spawned.wait_with_output().unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); exit(EX_IOERR); }); @@ -103,7 +105,7 @@ fn main() { if replace.pop() != Some(b'\n') { replace = output.stdout; } let new_field = String::from_utf8(replace).unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], e); exit(EX_IOERR); }); @@ -111,8 +113,8 @@ fn main() { stdout().write_all( fields.join(&d.to_string()).as_bytes() - ).unwrap_or_else(|e|{ - eprintln!("{}: {}.", argv[0], e); + ).unwrap_or_else(|e| { + eprintln!("{}: {}", argv[0], c_error(e)); exit(EX_IOERR); }); } From cf1d16f8609c531e69cce229b4d4719c75854275 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:12:44 -0700 Subject: [PATCH 013/134] hru(1): changed to use strerror(3) --- src/hru.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hru.rs b/src/hru.rs index 0e0b25d..ad73070 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -23,8 +23,10 @@ use std::{ process::{ ExitCode, exit }, }; +extern crate strerror; extern crate sysexits; +use strerror::c_error; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; const LIST: [(u32, &str); 10] = [ @@ -49,7 +51,7 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> { let c = match 10_u128.checked_pow(n) { Some(c) => c, None => { - return Err(format!("10^{}: Integer overflow.", n.to_string())); + return Err(format!("10^{}: Integer overflow", n.to_string())); }, }; @@ -79,7 +81,7 @@ fn main() -> ExitCode { f }, Err(err) => { - eprintln!("{}: {}.", argv[0], err); + eprintln!("{}: {}", argv[0], err); return ExitCode::from(EX_DATAERR as u8); }, }; @@ -87,7 +89,7 @@ fn main() -> ExitCode { let (number, prefix) = match convert(n) { Ok(x) => x, Err(err) => { - eprintln!("{}: {}.", argv[0], err); + eprintln!("{}: {}", argv[0], err); return ExitCode::from(EX_SOFTWARE as u8); }, }; @@ -98,7 +100,7 @@ fn main() -> ExitCode { stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) .unwrap_or_else(|e| { - eprintln!("{}: {}.", argv[0], e); + eprintln!("{}: {}", argv[0], c_error(e)); exit(EX_IOERR); }); } From 3e6dc5cc46114ba19077e6a0486b635ffdb49805 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:14:18 -0700 Subject: [PATCH 014/134] rpn(1): make error messages consistent with other tools --- src/rpn.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpn.rs b/src/rpn.rs index 0cb23b8..8ccf5d6 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -52,8 +52,10 @@ use std::{ use CalcType::*; +extern crate strerror; extern crate sysexits; +use strerror::c_error; use sysexits::EX_DATAERR; #[derive(Clone, PartialEq, PartialOrd, Debug)] @@ -172,7 +174,7 @@ fn eval( }; } else { return Err(EvaluationError { - message: format!("{}: Unexpected operation.", op), + message: format!("{}: Unexpected operation", op), code: EX_DATAERR, }) } From ca01ca407496f68f71d7d8dd34310b5da1c3e3a3 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:14:58 -0700 Subject: [PATCH 015/134] rpn(1): remove erroneous strerror(3) dependency --- src/rpn.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpn.rs b/src/rpn.rs index 8ccf5d6..2bfbbf5 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -52,10 +52,8 @@ use std::{ use CalcType::*; -extern crate strerror; extern crate sysexits; -use strerror::c_error; use sysexits::EX_DATAERR; #[derive(Clone, PartialEq, PartialOrd, Debug)] From 898044cd43915600da69be7d7c9f48fa6bcd36da Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:51:36 -0700 Subject: [PATCH 016/134] Makefile: better macro assignment --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index cb6bca6..8c22903 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,8 @@ PREFIX=/usr/local -CC != command -v "$$CC" || printf 'cc\n' -RUSTC != command -v "$$RUSTC" || printf 'rustc\n' +CC?=cc +RUSTC?=rustc RUSTLIBS=--extern getopt=build/o/libgetopt.rlib \ --extern sysexits=build/o/libsysexits.rlib \ --extern strerror=build/o/libstrerror.rlib From c392dbc680d56d9e6f7338fe5cc0e47fd910782b Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 2 Mar 2024 10:16:32 -0700 Subject: [PATCH 017/134] Makefile: better deps; fop(1), hru(1), strerror(3): changed strerror wrapper function name --- Makefile | 2 +- src/fop.rs | 8 ++++---- src/hru.rs | 4 ++-- src/strerror.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8c22903..d5203f5 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ build/o/libstrerror.rlib: build src/strerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ src/strerror.rs -build/o/libsysexits.rlib: build +build/o/libsysexits.rlib: build include/sysexits.h # bandage solution until bindgen(1) gets stdin support printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \ > build/include/sysexits.h diff --git a/src/fop.rs b/src/fop.rs index 0e0b059..65ee738 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -27,7 +27,7 @@ extern crate strerror; extern crate sysexits; use getopt::{ Opt, Parser }; -use strerror::c_error; +use strerror::raw_message; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { @@ -77,7 +77,7 @@ fn main() { .stdout(Stdio::piped()) .spawn() .unwrap_or_else( |e| { - eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], raw_message(e)); exit(EX_UNAVAILABLE); }); @@ -96,7 +96,7 @@ fn main() { } let output = spawned.wait_with_output().unwrap_or_else(|e| { - eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], raw_message(e)); exit(EX_IOERR); }); @@ -114,7 +114,7 @@ fn main() { stdout().write_all( fields.join(&d.to_string()).as_bytes() ).unwrap_or_else(|e| { - eprintln!("{}: {}", argv[0], c_error(e)); + eprintln!("{}: {}", argv[0], raw_message(e)); exit(EX_IOERR); }); } diff --git a/src/hru.rs b/src/hru.rs index ad73070..29e1e49 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -26,7 +26,7 @@ use std::{ extern crate strerror; extern crate sysexits; -use strerror::c_error; +use strerror::raw_message; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; const LIST: [(u32, &str); 10] = [ @@ -100,7 +100,7 @@ fn main() -> ExitCode { stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) .unwrap_or_else(|e| { - eprintln!("{}: {}", argv[0], c_error(e)); + eprintln!("{}: {}", argv[0], raw_message(e)); exit(EX_IOERR); }); } diff --git a/src/strerror.rs b/src/strerror.rs index 0939df9..117ed0b 100644 --- a/src/strerror.rs +++ b/src/strerror.rs @@ -13,7 +13,7 @@ use std::ffi::{ c_int, c_char, CStr }; extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } /* wrapper function for use in Rust */ -pub fn c_error(err: std::io::Error) -> String { +pub fn raw_message(err: std::io::Error) -> String { /* Get the raw OS error. If it’s None, what the hell is going on‽ */ let error = err.raw_os_error().unwrap_or_else(|| { panic!() }) as c_int; From 8193e471f01f176590bd66ce1269d5a974a40f67 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 3 Mar 2024 17:26:40 -0700 Subject: [PATCH 018/134] changes redundant .unwrap_or_else(panic!()) to .unwrap() --- src/strerror.rs | 4 ++-- src/test.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/test.rs diff --git a/src/strerror.rs b/src/strerror.rs index 117ed0b..01d98e2 100644 --- a/src/strerror.rs +++ b/src/strerror.rs @@ -15,12 +15,12 @@ extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } /* wrapper function for use in Rust */ pub fn raw_message(err: std::io::Error) -> String { /* Get the raw OS error. If it’s None, what the hell is going on‽ */ - let error = err.raw_os_error().unwrap_or_else(|| { panic!() }) as c_int; + let errno = err.raw_os_error().unwrap() as c_int; /* Get a CStr from the error message so that it’s referenced and then * convert it to an owned value. If the string is not valid UTF-8, return * that error instead. */ - match unsafe { CStr::from_ptr(strerror(error)) }.to_str() { + match unsafe { CStr::from_ptr(strerror(errno)) }.to_str() { Ok(s) => s.to_owned(), // yay!! :D Err(e) => e.to_string(), // awww :( } diff --git a/src/test.rs b/src/test.rs new file mode 100644 index 0000000..4a602b1 --- /dev/null +++ b/src/test.rs @@ -0,0 +1,10 @@ +extern crate strerror; + +use strerror::raw_message; + +fn main() { + stdout.write_all(b"meow\n").unwrap_or_else(|e| { + eprintln!("{}", raw_message(e)); + std::process::exit(1); + }); +} From 2ad7140e1ea8fcc3151c7716805af62719519756 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 9 Mar 2024 11:53:03 -0700 Subject: [PATCH 019/134] Makefile: DESTDIR --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d5203f5..66572fc 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,12 @@ # notice are preserved. This file is offered as-is, without any warranty. .POSIX: + +# if using BSD make(1), remove these pragmas because they break it .PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1) .PRAGMA: command_comment # breaks without this? +DESTDIR=./dist PREFIX=/usr/local CC?=cc @@ -32,14 +35,13 @@ clean: rm -rf build/ dist/ dist: all - mkdir -p dist/bin dist/share/man/man1 - cp build/bin/* dist/bin/ - cp docs/*.1 dist/share/man/man1/ + mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/share/man/man1 + cp build/bin/* $(DESTDIR)$(PREFIX)/bin/ + cp docs/*.1 $(DESTDIR)$(PREFIX)/share/man/man1/ .PHONY: install install: dist - mkdir -p $(PREFIX) - cp -r dist/* $(PREFIX)/ + cp -r $(DESTDIR)/* / .PHONY: test test: build From b2d56bbc9abd4f8fc8a991bcd230b713a9575d9f Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 9 Mar 2024 22:02:19 -0700 Subject: [PATCH 020/134] Makefile: even more changes --- Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 66572fc..dd77985 100644 --- a/Makefile +++ b/Makefile @@ -16,11 +16,15 @@ DESTDIR=./dist PREFIX=/usr/local +SYSEXITS!=printf '\043include \n' | cpp -M - | sed 's/ /\n/g' \ + | sed -n 's/sysexits\.h//p' || printf 'include/\n' + CC?=cc RUSTC?=rustc RUSTLIBS=--extern getopt=build/o/libgetopt.rlib \ --extern sysexits=build/o/libsysexits.rlib \ --extern strerror=build/o/libstrerror.rlib +CFLAGS+=-I$(SYSEXITS) .PHONY: all all: dj false fop hru intcmp rpn scrut str strcmp true @@ -60,15 +64,12 @@ build/o/libstrerror.rlib: build src/strerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ src/strerror.rs -build/o/libsysexits.rlib: build include/sysexits.h +build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h # bandage solution until bindgen(1) gets stdin support - printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \ + printf '#define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \ > build/include/sysexits.h bindgen --default-macro-constant-type signed --use-core --formatter=none \ - "$$(printf '#include \n' \ - | cpp -M -idirafter "build/include" - \ - | sed 's/ /\n/g' | grep sysexits.h)" \ - | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ - + build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ - .PHONY: dj dj: build/bin/dj From b356ac522fe9168337669f3c2a9e0b30163a5803 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 18 Mar 2024 20:45:53 -0600 Subject: [PATCH 021/134] strerror(3): changed panic to 0 --- src/strerror.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/strerror.rs b/src/strerror.rs index 01d98e2..e5a2a95 100644 --- a/src/strerror.rs +++ b/src/strerror.rs @@ -15,7 +15,7 @@ extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } /* wrapper function for use in Rust */ pub fn raw_message(err: std::io::Error) -> String { /* Get the raw OS error. If it’s None, what the hell is going on‽ */ - let errno = err.raw_os_error().unwrap() as c_int; + let errno = err.raw_os_error().unwrap_or(0) as c_int; /* Get a CStr from the error message so that it’s referenced and then * convert it to an owned value. If the string is not valid UTF-8, return From 1891c3e1aa83c92c8bd644541d13441f30b55c0c Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 18 Mar 2024 21:30:43 -0600 Subject: [PATCH 022/134] strerror(3): created strerror() method --- src/strerror.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/strerror.rs b/src/strerror.rs index e5a2a95..e306e7a 100644 --- a/src/strerror.rs +++ b/src/strerror.rs @@ -9,19 +9,23 @@ use std::ffi::{ c_int, c_char, CStr }; -/* binding to strerror(3p) */ -extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } +pub trait StrError { fn strerror(&self) -> String; } -/* wrapper function for use in Rust */ -pub fn raw_message(err: std::io::Error) -> String { - /* Get the raw OS error. If it’s None, what the hell is going on‽ */ - let errno = err.raw_os_error().unwrap_or(0) as c_int; +impl StrError for std::io::Error { + /* wrapper function for use in Rust */ + fn strerror(&self) -> String { + /* Get the raw OS error. If it’s None, what the hell is going on‽ */ + let errno = self.raw_os_error().unwrap_or(0) as c_int; - /* Get a CStr from the error message so that it’s referenced and then - * convert it to an owned value. If the string is not valid UTF-8, return - * that error instead. */ - match unsafe { CStr::from_ptr(strerror(errno)) }.to_str() { - Ok(s) => s.to_owned(), // yay!! :D - Err(e) => e.to_string(), // awww :( + /* Get a CStr from the error message so that it’s referenced and then + * convert it to an owned value. If the string is not valid UTF-8, + * return that error instead. */ + match unsafe { CStr::from_ptr(strerror(errno)) }.to_str() { + Ok(s) => s.to_owned(), // yay!! :D + Err(e) => e.to_string(), // awww :( + } } } + +/* binding to strerror(3p) */ +extern "C" { fn strerror(errnum: c_int) -> *mut c_char; } From d87b5d095870cb0874629ebcda13f069e1c4014f Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 18 Mar 2024 21:31:25 -0600 Subject: [PATCH 023/134] hru(1), fop(1): changed to reflect strerror changes --- src/fop.rs | 8 ++++---- src/hru.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index 65ee738..b829602 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -27,7 +27,7 @@ extern crate strerror; extern crate sysexits; use getopt::{ Opt, Parser }; -use strerror::raw_message; +use strerror::StrError; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { @@ -77,7 +77,7 @@ fn main() { .stdout(Stdio::piped()) .spawn() .unwrap_or_else( |e| { - eprintln!("{}: {}: {}", argv[0], argv[command_arg], raw_message(e)); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], e.strerror()); exit(EX_UNAVAILABLE); }); @@ -96,7 +96,7 @@ fn main() { } let output = spawned.wait_with_output().unwrap_or_else(|e| { - eprintln!("{}: {}: {}", argv[0], argv[command_arg], raw_message(e)); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], e.strerror()); exit(EX_IOERR); }); @@ -114,7 +114,7 @@ fn main() { stdout().write_all( fields.join(&d.to_string()).as_bytes() ).unwrap_or_else(|e| { - eprintln!("{}: {}", argv[0], raw_message(e)); + eprintln!("{}: {}", argv[0], e.strerror()); exit(EX_IOERR); }); } diff --git a/src/hru.rs b/src/hru.rs index 29e1e49..b7937f7 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -26,7 +26,7 @@ use std::{ extern crate strerror; extern crate sysexits; -use strerror::raw_message; +use strerror::StrError; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE }; const LIST: [(u32, &str); 10] = [ @@ -100,7 +100,7 @@ fn main() -> ExitCode { stdout().write_all(format!("{} {}\n", out, si_prefix).as_bytes()) .unwrap_or_else(|e| { - eprintln!("{}: {}", argv[0], raw_message(e)); + eprintln!("{}: {}", argv[0], e.strerror()); exit(EX_IOERR); }); } From d05d2fae052e9cba42f26457d79c9d5e819c7a5d Mon Sep 17 00:00:00 2001 From: Aaditya Aryal Date: Tue, 26 Mar 2024 17:19:21 +0545 Subject: [PATCH 024/134] Makefile: add a missing build target for npc(1) --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cbfe3a7..c7ff901 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ CC=cc RUSTC=rustc .PHONY: all -all: dj false fop hru intcmp mm rpn scrut str strcmp swab true +all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true build: # keep build/include until bindgen(1) has stdin support @@ -91,6 +91,12 @@ mm: build/bin/mm build/bin/mm: src/mm.c build $(CC) $(CFLAGS) -o $@ src/mm.c + +.PHONY: npc +npc: build/bin/npc +build/bin/npc: src/npc.c build + $(CC) $(CFLAGAS) -o $@ src/npc.c + .PHONY: rpn rpn: build/bin/rpn build/bin/rpn: src/rpn.rs build build/o/libsysexits.rlib From a6fd1108c606f782e707de31d24e5d84214809c6 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 18:26:51 -0600 Subject: [PATCH 025/134] docs: fixed formatting of many manpages --- docs/dj.1 | 156 ++++++++++++++++++++++++++++++-------------------- docs/intcmp.1 | 49 ++++++++++------ docs/npc.1 | 31 +++++----- docs/scrut.1 | 107 +++++++++++++++++++++------------- docs/str.1 | 8 +-- docs/strcmp.1 | 2 +- 6 files changed, 218 insertions(+), 135 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 1e286f5..c94845e 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -1,4 +1,5 @@ .\" Copyright (c) 2024 DTB +.\" Copyright (c) 2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -46,84 +47,117 @@ dj .SH USAGE -The -.B -i -option takes a path as an argument to open and use in place of standard input. -The -.B -o -option does the same in place of standard output. Dj does not truncate output -files and instead writes over the bytes in the existing file. -.PP -The -.B -b -option takes a numeric argument as the size in bytes of the input buffer and -the +.B -A +.RS +Takes no arguments and pads with nuls. +.RE + .B -B -option does the same for the output buffer, the default for both being 1024 -bytes, or one kibibyte (KiB). -.PP -The -.B -s -option takes a numeric argument as the number of bytes to skip into the input -before starting to read, and the +.RS +Does the same as +.B -b +but for the output buffer. +.RE + +.B -H +.RS +Prints diagnostics messages in an alternate manner as described in the +DIAGNOSTICS section below. +.RE + .B -S -option skips a number of bytes through the output before starting to write from +.RS +Skips a number of bytes through the output before starting to write from the input. If the input is a stream the bytes are read and discarded. If the output is a stream, nul characters are printed. -.PP -The +.RE + .B -a -option takes one argument of one byte in length and pads the input buffer with -that byte in the event that a read doesn't fill the input buffer, and the -.B -A -option takes no arguments and pads with nuls. -The +.RS +Takes one argument of one byte in length and pads the input buffer with +that byte in the event that a read doesn’t fill the input buffer, and the +.RE + +.B -b +.RS +Takes a numeric argument as the size in bytes of the input buffer, with the +default being 1024 bytes or one kibibyte (KiB). +.RE + .B -c -option specifies an amount of reads to make, and if 0 (the default) dj will +.RS +Specifies an amount of reads to make, and if 0 (the default) dj will continue reading until a partial or empty read. -.PP +.RE + +.B -d +.RS +Prints all debug information, user-specified or otherwise, before program +execution. +.RE + +.B -i +.RS +Takes a path as an argument to open and use in place of standard input. +.RE + +.B -n +.RS +Causes dj to exit on two consecutive empty reads instead of one. +.RE + +.B -o +.RS +Does the same as +.B -i +but in place of standard output. Dj does not truncate output +files and instead writes over the bytes in the existing file. +.RE + +.B -s +.RS +Takes a numeric argument as the number of bytes to skip into the input +before starting to read. +.RE + +.B -q +.RS +Suppresses error messages which print when a read or write is partial or +empty. When +.B -q +is specified twice suppresses diagnostic output entirely. +.RE + +.SH DIAGNOSTICS + On a partial or empty read, dj prints a diagnostic message (unless the .B -q option is specified) and exits (unless the .B -n -option is specified, in which case only two consecutive empty reads will cause -dj to exit). -At exit, usage statistics are printed unless the option -.B -q -is specified a second time. The -.B -H -option will make these diagnostics human-readable. +option is specified. -.SH DIAGNOSTICS +By default statistics are printed for input and output to the standard error in +the following format: -The -.B -d -option prints all information, user-specified or otherwise, before program -execution. -.PP -When dj exits, by default statistics are printed for input and output to -standard error in the following format: -.PP +.RS .R {records read} {ASCII unit separator} {partial records read} .R {ASCII record separator} {records written} {ASCII unit separator} .R {partial records written} {ASCII group separator} {bytes read} .R {ASCII record separator} {bytes written} {ASCII file separator} -.PP +.RE + If the .B -H -option is specified dj instead uses this following format: -.PP +option is specified, dj instead uses the following format: + +.RS .R {records read} '+' {partial records read} '>' {records written} .R '+' {partial records written} ';' {bytes read} '>' {bytes written} .R {ASCII line feed} -.PP -The -.B -q -option suppresses error messages which print when a read or write is partial or -empty and when used twice suppresses diagnostic output entirely. -.PP -In non-recoverable errors that don't pertain to dj's read-write cycle, a -diagnostic message is printed and dj exits with the appropriate sysexits(3) +.RE + +In non-recoverable errors that don’t pertain to dj’s read-write cycle, a +diagnostic message is printed and dj exits with the appropriate sysexits.h(3) status. .SH BUGS @@ -136,7 +170,7 @@ expected (the product of the count multiplied by the input block size). If the or .B -A options are used this could make data written nonsensical. -.PP + Many lowercase options have capitalized variants and vice-versa which can be confusing. Capitalized options tend to affect output or are more intense versions of lowercase options. @@ -146,15 +180,15 @@ versions of lowercase options. Dj was modeled after the dd utility specified in POSIX but adds additional features: typical option formatting, allowing seeks to be specified in bytes rather than in blocks, allowing arbitrary bytes as padding, and printing in a -format that's easy to parse for machines. It also neglects character -conversion, which may be dd's original intent but is irrelevant to its modern +format that’s easy to parse for machines. It also neglects character +conversion, which may be dd’s original intent but is irrelevant to its modern use. .SH COPYRIGHT -Copyright (C) 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .SH SEE ALSO -dd(1) +dd(1p) diff --git a/docs/intcmp.1 b/docs/intcmp.1 index f370755..e3c0bcc 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2023–2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -13,7 +13,7 @@ intcmp \(en compare integers .SH SYNOPSIS intcmp -.RB ( -eghl ) +.RB ( -egl ) .RB [ integer ] .RB [ integer... ] @@ -23,35 +23,52 @@ Intcmp compares integers. .SH USAGE -The -e option permits given integers to be equal to each other. If combined -with -g or -l, only adjacent integers in the argument sequence can be equal. -.PP -The -g option permits a given integer to be greater than the following integer. -.PP -The -l option permits a given integer to be less than the following integer. -.PP +.B -e +.RS +Permits given integers to be equal to each other. If combined with +.B -g +or +.B -l +, only adjacent integers in the argument sequence can be equal. +.RE + +.B -g +.RS +Permits a given integer to be greater than the following integer. +.RE + +.B -l +.RS +Permits a given integer to be less than the following integer. +.RE + +.SH EXAMPLES + It may help to think of the -e, -g, and -l options as equivalent to the infix algebraic “=”, “>”, and “<” operators respectively, with each option -putting its symbol between every given integer. For example, +putting its symbol between every given integer. The following example is +equivalent to evaluating “1 < 2 < 3”: + +.RS .R intcmp -l 1 2 3 -is equivalent to evaluating "1 < 2 < 3". +.RE .SH DIAGNOSTICS Intcmp exits 0 for a valid expression and 1 for an invalid expression. -.PP -Intcmp prints a debug message and exits with the appropriate sysexits(3) error + +Intcmp prints a debug message and exits with the appropriate sysexits.h(3) error code in the event of an error. .SH BUGS There are multiple ways to express compound comparisons; “less than or equal to” can be -le or -el, for example. -.PP + The inequality comparison is -gl or -lg for “less than or greater than”; this is elegant but unintuitive. -.PP --egl, "equal to or less than or greater than", exits 0 no matter what for valid + +-egl, “equal to or less than or greater than”, exits 0 no matter what for valid program usage and may be abused to function as an integer validator. Use str(1) instead. diff --git a/docs/npc.1 b/docs/npc.1 index 7f66c3d..e524f29 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2023–2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -13,29 +13,31 @@ npc \(en show non-printing characters .SH SYNOPSIS npc -.RB ( -eht ) +.RB ( -et ) .SH DESCRIPTION Npc reads from standard input and writes to standard output, replacing non- printing characters with printable equivalents. Control characters print as a -carat ('^') followed by the character '@' through '_' corresponding to the -character replaced (e.g. control-X becomes "^X"). The delete character (0x7F) -becomes "^?". Characters with the high bit set (>127) are printed as "M-" +carat (“^”) followed by the character “@” through “_” corresponding to the +character replaced (e.g. control-X becomes “^X”). The delete character (0x7F) +becomes “^?”. Characters with the high bit set (>127) are printed as “M-” followed by the graphical representation for the same character without the high bit set. -.PP -The + .B -e -option prints a currency sign ('$') before each line ending. -.PP -The +.RS +Prints a currency sign (“$”) before each line ending. +.RE + .B -t -option prints tab characters as "^I" rather than a literal horizontal tab. +.RS +Prints tab characters as “^I” rather than a literal horizontal tab. +.RE .SH DIAGNOSTICS -Npc prints a debug message and exits with the appropriate sysexits(3) error +Npc prints a debug message and exits with the appropriate sysexits.h(3) error code in the event of an error, otherwise it exits successfully. .SH BUGS @@ -45,8 +47,9 @@ Npc operates in single-byte chunks regardless of intended encoding. .SH RATIONALE POSIX currently lacks a way to display non-printing characters in the terminal -using a standard tool. A popular extension to cat(1p), the -v option, is the -bandage solution GNU and other software suites use. +using a standard tool. A popular extension to cat(1p), the +.B -v +option, is the bandage solution GNU and other software suites use. This functionality should be a separate tool because its usefulness extends beyond that of cat(1p). diff --git a/docs/scrut.1 b/docs/scrut.1 index 7a5107a..2f0955b 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -1,4 +1,5 @@ .\" Copyright (c) 2024 DTB +.\" Copyright (c) 2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -21,47 +22,75 @@ Scrut determines if given files comply with the opted requirements. .SH OPTIONS -.B -b -requires the given files to exist and be block special files. -.PP -.B -c -requires the given files to exist and be character special files. -.PP -.B -d -requires the given files to exist and be directories. -.PP -.B -e -requires the given files to exist, and is redundant to any other option. -.PP -.B -e -requires the given files to exist and be regular files. -.PP -.B -g -requires the given files to exist and have their set group ID flags set. -.PP -.B -k -requires the given files to exist and have their sticky bit set. -.PP -.B -p -requires the given files to exist and be named pipes. -.PP -.B -r -requires the given files to exist and be readable. -.PP -.B -u -requires the given files to exist and have their set user ID flags set. -.PP -.B -w -requires the given files to exist and be writable. -.PP -.B -x -requires the given files to exist and be executable. -.PP .B -L -requires the given files to exist and be symbolic links. -.PP +.RS +Requires the given files to exist and be symbolic links. +.RE + .B -S -requires the given files to exist and be sockets. +.RS +Requires the given files to exist and be sockets. +.RE + +.B -b +.RS +Requires the given files to exist and be block special files. +.RE + +.B -c +.RS +Requires the given files to exist and be character special files. +.RE + +.B -d +.RS +Requires the given files to exist and be directories. +.RE + +.B -e +.RS +Requires the given files to exist, and is redundant to any other option. +.RE + +.B -e +.RS +Requires the given files to exist and be regular files. +.RE + +.B -g +.RS +Requires the given files to exist and have their set group ID flags set. +.RE + +.B -k +.RS +Requires the given files to exist and have their sticky bit set. +.RE + +.B -p +.RS +Requires the given files to exist and be named pipes. +.RE + +.B -r +.RS +Requires the given files to exist and be readable. +.RE + +.B -u +.RS +Requires the given files to exist and have their set user ID flags set. +.RE + +.B -w +.RS +Requires the given files to exist and be writable. +.RE + +.B -x +.RS +Requires the given files to exist and be executable. +.RE .SH EXIT STATUS diff --git a/docs/str.1 b/docs/str.1 index ecf71ee..08137fb 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2023–2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -24,10 +24,10 @@ the function of the same name within ctype(3). .SH DIAGNOSTICS Str exits successfully if all tests pass and unsuccessfully if a test failed. -.PP + Str will exit unsuccessfully if a string is empty, as none of its contents passed the test. -.PP + Str will print a message to standard error and exit unsuccessfully if used improperly. @@ -41,7 +41,7 @@ removed in favor of using strcmp(1) to compare strings against the empty string There's no way of knowing which argument failed the test without re-testing arguments individually. -.PP + If a character in a string isn't valid ASCII str will exit unsuccessfully. .SH AUTHOR diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 14c0d0d..56e2ec9 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2023–2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . From cf76fa94e6574ca5b7ab7ec456d98543171bb6cd Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 18:44:05 -0600 Subject: [PATCH 026/134] mm.1: updated man page --- docs/mm.1 | 61 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index 2244588..c8cc5dc 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -20,51 +20,60 @@ mm .SH DESCRIPTION -Mm catenates input files and writes them to the start of each output file. +Catenate input files and write them to the start of each output file or stream. .SH OPTIONS -Mm, upon receiving the .B -a -option, will open subsequent outputs for appending rather than updating. -.PP -The -.B -i -option opens a path as an input. Without any inputs specified mm will use -standard input. Standard input itself can be specified by giving the path '-'. -.PP -The -.B -o -option opens a path as an output. Without any outputs specified mm will use -standard output. Standard output itself can be specified by giving the -path '-'. Standard error itself can be specified with the +.RS +Opens subsequent outputs for appending rather than updating. +.RE + .B -e -option. -.PP -The +.RS +Set the output to the standard error. +.RE + +.B -i +.RS +Opens a path as an input. Without any inputs specified mm will use the +standard input. +.RE + +.B -o +.RS +Opens a path as an output. Without any outputs specified mm will use the +standard output. +.RE + .B -u -option ensures neither input or output will be buffered. -.PP -The +.RS +Ensures neither input or output will be buffered. +.RE + .B -n -option tells mm to ignore SIGINT signals. +.RS +Causes SIGINT signals to be ignored. +.RE .SH DIAGNOSTICS If an output can no longer be written mm prints a diagnostic message, ceases writing to that particular output, and if there are more outputs specified, continues, eventually exiting unsuccessfully. -.PP -On error mm prints a diagnostic message and exits with the appropriate -sysexits.h(3) status. + +When an error is encountered, diagnostic message is printed and the program +exits with the appropriate sysexits.h(3) status. .SH BUGS -Mm does not truncate existing files, which may lead to unexpected results. +Existing files are not truncated, which may lead to unexpected results. .SH RATIONALE -Mm was modeled after the cat and tee utilities specified in POSIX. +The cat(1p) and tee(1p) programs specified in POSIX provide equivalent +functionality. The separation of the two sets of functionality into separate +APIs seemed unncessary. .SH COPYRIGHT From 63a0c683f9803fe8b5023e07ceac1fc0bd922e51 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 19:22:30 -0600 Subject: [PATCH 027/134] docs: remove unnecessary references to the name of each program --- docs/dj.1 | 21 +++++++++++---------- docs/false.1 | 11 +++++------ docs/hru.1 | 22 ++++++++++++---------- docs/intcmp.1 | 11 ++++++----- docs/npc.1 | 20 ++++++++++++-------- docs/rpn.1 | 23 ++++++++++++++--------- docs/scrut.1 | 14 ++++++++------ docs/str.1 | 25 ++++++++++++++----------- docs/strcmp.1 | 25 +++++++++++++------------ docs/swab.1 | 52 ++++++++++++++++++++++++++++----------------------- docs/true.1 | 11 +++++------ 11 files changed, 129 insertions(+), 106 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index c94845e..3c57155 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -148,7 +148,7 @@ the following format: If the .B -H -option is specified, dj instead uses the following format: +option is specified, the following format is used instead: .RS .R {records read} '+' {partial records read} '>' {records written} @@ -156,9 +156,9 @@ option is specified, dj instead uses the following format: .R {ASCII line feed} .RE -In non-recoverable errors that don’t pertain to dj’s read-write cycle, a -diagnostic message is printed and dj exits with the appropriate sysexits.h(3) -status. +In non-recoverable errors that don’t pertain to the read-write cycle, a +diagnostic message is printed and the program exits with the appropriate +sysexits.h(3) status. .SH BUGS @@ -177,12 +177,13 @@ versions of lowercase options. .SH RATIONALE -Dj was modeled after the dd utility specified in POSIX but adds additional -features: typical option formatting, allowing seeks to be specified in bytes -rather than in blocks, allowing arbitrary bytes as padding, and printing in a -format that’s easy to parse for machines. It also neglects character -conversion, which may be dd’s original intent but is irrelevant to its modern -use. +The dd(1p) utility specified in POSIX was the basis of this program. + +It includes additional features: typical option formatting, allowing seeks to be +specified in bytes rather than in blocks, allowing arbitrary bytes as padding, +and printing in a format that’s easy to parse for machines. It also neglects +character conversion. This may have been the original intent of dd(1p) but it is +irrelevant to its modern use as a disk utility. .SH COPYRIGHT diff --git a/docs/false.1 b/docs/false.1 index 6883802..b8463ae 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2022, 2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -12,14 +12,13 @@ false \(en do nothing, unsuccessfully .SH DESCRIPTION -False does nothing regardless of operands or standard input. -False will always return an exit code of 1. +Do nothing regardless of operands or standard input. +An exit code of 1 will always be returned. .SH RATIONALE -False exists for the construction of control flow and loops based on a failure. - -False functions as described in POSIX.1-2017. +In POSIX.1-2017, false(1p) exists for the construction of control flow and loops +based on a failure. This implementation functions as described in that standard. .SH AUTHOR diff --git a/docs/hru.1 b/docs/hru.1 index c75cb73..1ffc00e 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . -.TH rpn 1 +.TH hru 1 .SH NAME @@ -15,18 +15,20 @@ hru .SH DESCRIPTION -Hru reads byte counts in the form of whole numbers from the standard input and -writes to the standard output the same number converted one of the units of data -defined by the International System of Units. +Convert counts to higher units. + +The program will read byte counts in the form of whole numbers from the standard +input and write to the standard output the same number converted to a higher +unit of data as defined by the International System of Units. The program will convert the byte count to the highest unit possible where the value is greater than one. .SH DIAGNOSTICS -If encountering non-integer characters in the standard input, hru will exit with -the appropriate error code as defined by sysexits.h(3) and print an error -message. +If encountering non-integer characters in the standard input, the program will +exit with the appropriate error code as defined by sysexits.h(3) and print an +error message. .SH RATIONALE @@ -39,9 +41,9 @@ program. .SH STANDARDS -Hru follows the standard unit prefixes as specified by the Bureau International -des Poids et Mesures (BIPM) in the ninth edition of The International System of -Units (SI). +The standard unit prefixes as specified by the Bureau International des Poids +et Mesures (BIPM) in the ninth edition of The International System of Units +(SI) are utilized for the ouput of conversions. .SH AUTHOR diff --git a/docs/intcmp.1 b/docs/intcmp.1 index e3c0bcc..209b2d8 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -19,7 +19,7 @@ intcmp .SH DESCRIPTION -Intcmp compares integers. +Compare integers. .SH USAGE @@ -55,10 +55,11 @@ equivalent to evaluating “1 < 2 < 3”: .SH DIAGNOSTICS -Intcmp exits 0 for a valid expression and 1 for an invalid expression. +The program will exit with a status code of 0 for a valid expression and with a +code of 1 for an invalid expression. -Intcmp prints a debug message and exits with the appropriate sysexits.h(3) error -code in the event of an error. +In the event of an error, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH BUGS @@ -78,7 +79,7 @@ The traditional tool for integer comparisons in POSIX and other Unix shells has been test(1). This tool also handles string comparisons and file scrutiny. These parts of its functionality have been broken out into multiple utilities. -Strcmp’s functionality may be performed on a POSIX-compliant system with +This program’s functionality may be performed on a POSIX-compliant system with test(1p). .SH AUTHOR diff --git a/docs/npc.1 b/docs/npc.1 index e524f29..daad9f1 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -17,14 +17,18 @@ npc .SH DESCRIPTION -Npc reads from standard input and writes to standard output, replacing non- -printing characters with printable equivalents. Control characters print as a -carat (“^”) followed by the character “@” through “_” corresponding to the +Print normally non-printing characters. + +The program reads from standard input and writes to standard output, replacing +non-printing characters with printable equivalents. Control characters print as +a carat (“^”) followed by the character “@” through “_” corresponding to the character replaced (e.g. control-X becomes “^X”). The delete character (0x7F) becomes “^?”. Characters with the high bit set (>127) are printed as “M-” followed by the graphical representation for the same character without the high bit set. +.SH USAGE + .B -e .RS Prints a currency sign (“$”) before each line ending. @@ -37,12 +41,12 @@ Prints tab characters as “^I” rather than a literal horizontal tab. .SH DIAGNOSTICS -Npc prints a debug message and exits with the appropriate sysexits.h(3) error -code in the event of an error, otherwise it exits successfully. +In the event of an error, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH BUGS -Npc operates in single-byte chunks regardless of intended encoding. +The program operates in single-byte chunks regardless of intended encoding. .SH RATIONALE @@ -51,8 +55,8 @@ using a standard tool. A popular extension to cat(1p), the .B -v option, is the bandage solution GNU and other software suites use. -This functionality should be a separate tool because its usefulness extends -beyond that of cat(1p). +This functionality is a separate tool because its usefulness extends beyond that +of cat(1p). .SH AUTHOR diff --git a/docs/rpn.1 b/docs/rpn.1 index 2197fbe..0b6b264 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -17,10 +17,13 @@ rpn .SH DESCRIPTION -Rpn evaluates reverse polish notation expressions either read from the standard -input or parsed from provided arguments. See the STANDARD INPUT section. +Evaluate reverse polish notation. -Upon evaluation, rpn will print the resulting number on the stack to the +The program evaluates reverse polish notation expressions either read from the +standard input or parsed from provided arguments. See the STANDARD INPUT +section. + +Upon evaluation, the program will print the resulting number on the stack to the standard output. Any further specified numbers will be placed at the end of the stack. @@ -28,14 +31,16 @@ For information on for reverse polish notation syntax, see rpn(7). .SH STANDARD INPUT -If arguments are passed to rpn, it interprets them as an expression to be -evaluated. Otherwise, it reads whitespace-delimited numbers and operations from -the standard input. +If arguments are passed , they are interpreted as an expression to be evaluated. +Otherwise, it reads whitespace-delimited numbers and operations from the +standard input. .SH DIAGNOSTICS -If encountering a syntax error, rpn will exit with the appropriate error code -as defined by sysexits.h(3) and print an error message. +In the event of a syntax error, the program will print an + +In the event of an error, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH CAVEATS @@ -44,7 +49,7 @@ with the IEEE Standard for Floating Point Arithmetic (IEEE 754), floating-point arithmetic has rounding errors. This is somewhat curbed by using the machine epsilon as provided by the Rust standard library to which to round numbers. Because of this, variation is expected in the number of decimal places -rpn can handle based on the platform and hardware of any given machine. +the program can handle based on the platform and hardware of any given machine. .SH RATIONALE diff --git a/docs/scrut.1 b/docs/scrut.1 index 2f0955b..4c0b75b 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -18,7 +18,7 @@ scrut .SH DESCRIPTION -Scrut determines if given files comply with the opted requirements. +Determine if files comply with requirements. .SH OPTIONS @@ -94,14 +94,16 @@ Requires the given files to exist and be executable. .SH EXIT STATUS -Scrut prints a debug message and exits unsuccessfully with the appropriate -sysexits.h(3) error code if invoked incorrectly. Scrut exits successfully if -the given files comply with their requirements and unsuccessfully otherwise. +If the given files comply with the specified requirements, the program will exit +successfully. If not, it exits unsuccessfully. + +When invoked incorrectly, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH STANDARDS -Scrut is nearly compatible with POSIX's test utility though it is narrower in -scope. Notably, the +The test(1p) utility contains functionality that was broken out into separate +programs. Thus, the scope of this program is narrower than it. Notably, the .B -h option is now invalid and therefore shows usage information instead of being an alias to the modern diff --git a/docs/str.1 b/docs/str.1 index 08137fb..e671ecd 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -18,28 +18,31 @@ str .SH DESCRIPTION -Str tests each character in an arbitrary quantity of string arguments against -the function of the same name within ctype(3). +Test string arguments against each other. + +The tests in this program are equivalent to the functions with the same names in +ctype.h(0p) and are the methods by which string arguments are tested. .SH DIAGNOSTICS -Str exits successfully if all tests pass and unsuccessfully if a test failed. +If all tests pass, the program will exit with an exit code of 0. If any of the +tests fail, the program will exit unsuccessfully with an error code of 1. -Str will exit unsuccessfully if a string is empty, as none of its contents -passed the test. +An empty string will cause an unsuccessful exit as none of its contents pass any +tests. -Str will print a message to standard error and exit unsuccessfully if used -improperly. +When invoked incorrectly, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH DEPRECATED FEATURES -Str used to have an "isvalue" type as an extension to ctype(3). This was -removed in favor of using strcmp(1) to compare strings against the empty string -(''). +Originally, there was an isvalue type as an extension to ctype.h(3), but it +was removed in favor of using strcmp(1) to compare strings against the empty +string (''). .SH BUGS -There's no way of knowing which argument failed the test without re-testing +There’s no way of knowing which argument failed the test without re-testing arguments individually. If a character in a string isn't valid ASCII str will exit unsuccessfully. diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 56e2ec9..c2103dd 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -18,26 +18,27 @@ strcmp .SH DESCRIPTION -Strcmp checks whether the given strings are the same. -Strcmp exits successfully if the strings are identical. Otherwise, strcmp exits -with the value 1 if an earlier string has a greater byte value than a later -string (e.g. +Check whether string arguments are the same. + +.SH DIAGNOSTICS + +The program will exit successfully if the strings are identical. Otherwise, it +exits with the value 1 if an earlier string has a greater byte value than a +later string (e.g. .R strcmp b a ) and 255 if an earlier string has a lesser byte value (e.g. .R strcmp a b ). -.SH DIAGNOSTICS - -Strcmp will print an error message and exit unsuccessfully with a status -described in sysexits(3) if used incorrectly (given less than two operands). +When invoked incorrectly, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH UNICODE -Strcmp will exit unsuccessfully if the given strings are not identical; -Unicode strings may need to be normalized if the intent is to check visual -similarity and not byte similarity. +The program will exit unsuccessfully if the given strings are not identical; +therefore, unicode strings may need to be normalized if the intent is to check +visual similarity and not byte similarity. .SH RATIONALE @@ -45,7 +46,7 @@ The traditional tool for string comparisons in POSIX and other Unix shells has been test(1). This tool also handles integer comparisons and file scrutiny. These parts of its functionality have been broken out into multiple utilities. -Strcmp’s functionality may be performed on a POSIX-compliant system with +This program’s functionality may be performed on a POSIX-compliant system with test(1p). .SH AUTHOR diff --git a/docs/swab.1 b/docs/swab.1 index a0c1be3..f7e10b0 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -1,4 +1,5 @@ .\" Copyright (c) 2024 DTB +.\" Copyright (c) 2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -20,46 +21,51 @@ swab .SH USAGE -Swab swaps the latter and former halves of a block of bytes. +Swap the latter and former halves of a block of bytes. + +.SH OPTIONS + +.B -f +.RS +Ignore system call interruptions. +.RE + +.B -w +.RS +Configures the word size; that is, the size in bytes of the block size +on which to operate. By default the word size is 2. The word size must be +cleanly divisible by 2, otherwise the block of bytes being processed can't be +halved. +.RE .SH EXAMPLES The following sh(1p) line: +.RS .R printf 'hello world!\n' | swab +.RE Produces the following output: +.RS .R ehll oowlr!d - -.SH OPTIONS - -The -.B -f -option ignores system call interruptions. -.PP -The -.B -w -option configures the word size; that is, the size in bytes of the block size -on which to operate. By default the word size is 2. The word size must be -cleanly divisible by 2, otherwise the block of bytes being processed can't be -halved. +.RE .SH DIAGNOSTICS -If an error is encountered in input, output, or invocation, a diagnostic -message will be written to standard error and swab will exit with the -appropriate status from sysexits.h(3). +In the event of an error, a debug message will be printed and the program will +exit with the appropriate sysexits.h(3) error code. .SH RATIONALE -Swab was modeled after the +This program was modeled and named after the .R conv=swab -functionality specified in the POSIX dd utility but additionally allows the -word size to be configured. -.PP -Swab is useful for fixing the endianness of binary files produced on other -machines. +functionality specified in the dd(1p) utility. It additionally allows the word +size to be configured. + +This functionality is useful for fixing the endianness of binary files produced +on other machines. .SH COPYRIGHT diff --git a/docs/true.1 b/docs/true.1 index 3c292d8..9b02fdd 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -1,5 +1,5 @@ .\" Copyright (c) 2022, 2024 DTB -.\" Copyright (c) 2023 Emma Tebibyte +.\" Copyright (c) 2023–2024 Emma Tebibyte .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . @@ -12,14 +12,13 @@ true \(en do nothing, successfully .SH DESCRIPTION -True does nothing regardless of operands or standard input. -True will always return an exit code of 0. +Do nothing regardless of operands or standard input. +An exit code of 0 will always be returned. .SH RATIONALE -True exists for the construction of control flow and loops based on a success. - -True functions as described in POSIX.1-2017. +In POSIX.1-2017, true(1p) exists for the construction of control flow and loops +based on a success. This implementation functions as described in that standard. .SH AUTHOR From b562898a74bf70f92583809dc68f53f9d4b2a3e7 Mon Sep 17 00:00:00 2001 From: Aaditya Aryal Date: Wed, 27 Mar 2024 09:21:19 +0545 Subject: [PATCH 028/134] copyright --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c7ff901..da7c2ce 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Copyright (c) 2023–2024 Emma Tebibyte # Copyright (c) 2023–2024 DTB # Copyright (c) 2023 Sasha Koshka +# Copyright (c) 2024 Aaditya Aryal # SPDX-License-Identifier: FSFAP # # Copying and distribution of this file, with or without modification, are From a1902df50351218bbad093cbdee9e27aa1054611 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 23:50:16 -0600 Subject: [PATCH 029/134] strcmp.1: Unicode is a proper noun --- docs/strcmp.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/strcmp.1 b/docs/strcmp.1 index c2103dd..48681c6 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -37,7 +37,7 @@ exit with the appropriate sysexits.h(3) error code. .SH UNICODE The program will exit unsuccessfully if the given strings are not identical; -therefore, unicode strings may need to be normalized if the intent is to check +therefore, Unicode strings may need to be normalized if the intent is to check visual similarity and not byte similarity. .SH RATIONALE From f565f0530b041c45d82e27a5045349107a32d0b5 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 23:53:10 -0600 Subject: [PATCH 030/134] dj.1: dd(1p) is not a disk utility --- docs/dj.1 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 3c57155..c1bb81d 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -177,13 +177,12 @@ versions of lowercase options. .SH RATIONALE -The dd(1p) utility specified in POSIX was the basis of this program. - -It includes additional features: typical option formatting, allowing seeks to be -specified in bytes rather than in blocks, allowing arbitrary bytes as padding, -and printing in a format that’s easy to parse for machines. It also neglects -character conversion. This may have been the original intent of dd(1p) but it is -irrelevant to its modern use as a disk utility. +This program was based on the dd(1p) utility as specified in POSIX. While +character conversion may have been the original intent of dd(1p), it is +irrelevant to its modern use. Because of this, it eschews character conversion +and adds typical option formatting, allowing seeks to be specified in bytes +rather than in blocks, allowing arbitrary bytes as padding, and printing in a +format that’s easy to parse for machines. .SH COPYRIGHT From bb43533a374bd95dc844e1d9854777e0ccd99277 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 26 Mar 2024 23:58:00 -0600 Subject: [PATCH 031/134] dj.1: -A and -a: fix descriptions --- docs/dj.1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index c1bb81d..a787544 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -45,11 +45,13 @@ dj .B output offset .R ]) -.SH USAGE +.SH OPTIONS .B -A .RS -Takes no arguments and pads with nuls. +If the output is a stream, nul bytes are printed. In other words, it does what +.B -a +does but with null bytes instead. .RE .B -B @@ -74,8 +76,8 @@ output is a stream, nul characters are printed. .B -a .RS -Takes one argument of one byte in length and pads the input buffer with -that byte in the event that a read doesn’t fill the input buffer, and the +Takes one argument of one byte in length and pads the input buffer with it in +the event of an incomplete read from the input file. .RE .B -b From 49e2022e521e7530bd4201a365f48d586ba037e9 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:08:43 -0600 Subject: [PATCH 032/134] dj.1: -d, -i, -o, fixed descriptions --- docs/dj.1 | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index a787544..41c4f3e 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -95,41 +95,42 @@ continue reading until a partial or empty read. .B -d .RS Prints all debug information, user-specified or otherwise, before program -execution. +execution. Each invocation increments the debug level of the program. .RE .B -i .RS -Takes a path as an argument to open and use in place of standard input. +Takes a file path as an argument to open and use as an input. .RE .B -n .RS -Causes dj to exit on two consecutive empty reads instead of one. +Retries failed reads once more before exiting. .RE .B -o .RS -Does the same as -.B -i -but in place of standard output. Dj does not truncate output -files and instead writes over the bytes in the existing file. +Takes a file path as an argument to open and use as an output. .RE .B -s .RS Takes a numeric argument as the number of bytes to skip into the input -before starting to read. +before starting to read. If the standard input is used, bytes read to this point +are discarded. .RE .B -q .RS Suppresses error messages which print when a read or write is partial or -empty. When -.B -q -is specified twice suppresses diagnostic output entirely. +empty. Each invocation decrements the debug level of the program. .RE +.SH STANDARD INPUT + +The standard input shall be used as an input if one or more of the input files +is “-”. + .SH DIAGNOSTICS On a partial or empty read, dj prints a diagnostic message (unless the @@ -177,6 +178,10 @@ Many lowercase options have capitalized variants and vice-versa which can be confusing. Capitalized options tend to affect output or are more intense versions of lowercase options. +.SH CAVEATS + +Output files are not truncated on ouput and are instead overwritten. + .SH RATIONALE This program was based on the dd(1p) utility as specified in POSIX. While From a2188dc674eb8d8b9801f6060dd31a44f9e378d6 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:09:17 -0600 Subject: [PATCH 033/134] dj.1: fix -H description --- docs/dj.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index 41c4f3e..c38a05d 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -63,7 +63,7 @@ but for the output buffer. .B -H .RS -Prints diagnostics messages in an alternate manner as described in the +Prints diagnostics messages in a human-readable manner as described in the DIAGNOSTICS section below. .RE From 6158a39a4ae58c195763777cd7a39d285248cb90 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:14:02 -0600 Subject: [PATCH 034/134] dj.1: consistency with mm.1 --- docs/dj.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index c38a05d..7e4b40b 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -180,7 +180,7 @@ versions of lowercase options. .SH CAVEATS -Output files are not truncated on ouput and are instead overwritten. +Existing files are not truncated on ouput and are instead overwritten. .SH RATIONALE From 3cb37d830a84710fc5493a953cc1a3b853e21f82 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:14:34 -0600 Subject: [PATCH 035/134] mm.1: wording, consistency with dj.1 --- docs/mm.1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index c8cc5dc..42a3e74 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -26,12 +26,12 @@ Catenate input files and write them to the start of each output file or stream. .B -a .RS -Opens subsequent outputs for appending rather than updating. +Opens outputs for appending rather than updating. .RE .B -e .RS -Set the output to the standard error. +Use the standard error as an output. .RE .B -i @@ -56,6 +56,11 @@ Ensures neither input or output will be buffered. Causes SIGINT signals to be ignored. .RE +.SH STANDARD INPUT + +The standard input shall be used as an input if one or more of the input files +is “-”. + .SH DIAGNOSTICS If an output can no longer be written mm prints a diagnostic message, ceases @@ -65,15 +70,15 @@ continues, eventually exiting unsuccessfully. When an error is encountered, diagnostic message is printed and the program exits with the appropriate sysexits.h(3) status. -.SH BUGS +.SH CAVEATS -Existing files are not truncated, which may lead to unexpected results. +Existing files are not truncated on ouput and are instead overwritten. .SH RATIONALE -The cat(1p) and tee(1p) programs specified in POSIX provide equivalent -functionality. The separation of the two sets of functionality into separate -APIs seemed unncessary. +The cat(1p) and tee(1p) programs specified in POSIX together provide nearly +equivalent functionality. The separation of the two sets of functionality into +separate APIs seemed unncessary. .SH COPYRIGHT From d3bfc7b1f540e1b131deb36e2343fda9281b7686 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:16:15 -0600 Subject: [PATCH 036/134] npc.1: ASCII bytes --- docs/npc.1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/npc.1 b/docs/npc.1 index daad9f1..f3b7d0c 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -21,9 +21,9 @@ Print normally non-printing characters. The program reads from standard input and writes to standard output, replacing non-printing characters with printable equivalents. Control characters print as -a carat (“^”) followed by the character “@” through “_” corresponding to the -character replaced (e.g. control-X becomes “^X”). The delete character (0x7F) -becomes “^?”. Characters with the high bit set (>127) are printed as “M-” +a carat ('^') followed by the character '@' through '_' corresponding to the +character replaced (e.g. control-X becomes '^X'). The delete character (0x7F) +becomes '^?'. Characters with the high bit set (>127) are printed as 'M-' followed by the graphical representation for the same character without the high bit set. @@ -31,12 +31,12 @@ high bit set. .B -e .RS -Prints a currency sign (“$”) before each line ending. +Prints a currency sign ('$') before each line ending. .RE .B -t .RS -Prints tab characters as “^I” rather than a literal horizontal tab. +Prints tab characters as '^I' rather than a literal horizontal tab. .RE .SH DIAGNOSTICS From cdd8e79b01092a307d381d52baa01b6826c8dae0 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:16:51 -0600 Subject: [PATCH 037/134] str.1: strings are not tested against each other --- docs/str.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/str.1 b/docs/str.1 index e671ecd..666f0b1 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -18,7 +18,7 @@ str .SH DESCRIPTION -Test string arguments against each other. +Test string arguments. The tests in this program are equivalent to the functions with the same names in ctype.h(0p) and are the methods by which string arguments are tested. From 603d8ee1d88a84c311ef6af19c7af14d0986eef4 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 27 Mar 2024 00:17:33 -0600 Subject: [PATCH 038/134] str.1: remove extraneous former implementation information --- docs/str.1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/str.1 b/docs/str.1 index 666f0b1..ef86861 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -34,12 +34,6 @@ tests. When invoked incorrectly, a debug message will be printed and the program will exit with the appropriate sysexits.h(3) error code. -.SH DEPRECATED FEATURES - -Originally, there was an isvalue type as an extension to ctype.h(3), but it -was removed in favor of using strcmp(1) to compare strings against the empty -string (''). - .SH BUGS There’s no way of knowing which argument failed the test without re-testing From 70b0c2f9243385cb79d912aaf26372cbe4d88784 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:14:27 -0600 Subject: [PATCH 039/134] dj.1: fixed -d description --- docs/dj.1 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 7e4b40b..631fa7b 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -94,8 +94,9 @@ continue reading until a partial or empty read. .B -d .RS -Prints all debug information, user-specified or otherwise, before program -execution. Each invocation increments the debug level of the program. +Prints invocation information before program execution as described in the +DIAGNOSTICS section below. Each invocation increments the debug level of the +program. .RE .B -i @@ -133,9 +134,9 @@ is “-”. .SH DIAGNOSTICS -On a partial or empty read, dj prints a diagnostic message (unless the +On a partial or empty read, a diagnostic message is printed (unless the .B -q -option is specified) and exits (unless the +option is specified) and the program exits (unless the .B -n option is specified. @@ -159,6 +160,20 @@ option is specified, the following format is used instead: .R {ASCII line feed} .RE +If the +.B -d +option is specified, debug output will be printed at the beginning of execution. +This debug information contains information regarding how the program was +invoked. The following example is the result of running the program with +.B -d +as the only argument: + +.RS +.R argv0=dj +.R in= ibs=1024 skip=0 align=ff count=0 +.R out= obs=1024 seek=0 debug= 3 noerror=0 +.RE + In non-recoverable errors that don’t pertain to the read-write cycle, a diagnostic message is printed and the program exits with the appropriate sysexits.h(3) status. From 4e33f945ae632ff79090fe5be0c5a01583a4d7e0 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:17:48 -0600 Subject: [PATCH 040/134] dj.1: null bytes --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 631fa7b..d309678 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -49,7 +49,7 @@ dj .B -A .RS -If the output is a stream, nul bytes are printed. In other words, it does what +If the output is a stream, null bytes are printed. In other words, it does what .B -a does but with null bytes instead. .RE @@ -71,7 +71,7 @@ DIAGNOSTICS section below. .RS Skips a number of bytes through the output before starting to write from the input. If the input is a stream the bytes are read and discarded. If the -output is a stream, nul characters are printed. +output is a stream, null characters are printed. .RE .B -a From 9ea57a27b7e68d49e01191324de7be724046cd2a Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:21:02 -0600 Subject: [PATCH 041/134] dj.1: stdin by default --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index d309678..0e882dd 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -129,8 +129,8 @@ empty. Each invocation decrements the debug level of the program. .SH STANDARD INPUT -The standard input shall be used as an input if one or more of the input files -is “-”. +The standard input shall be used as an input if no inputs are specified one or +more of the input files is “-”. .SH DIAGNOSTICS From 63c8ff8093564e3a88d1b4021790fb9afef36dd9 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:22:56 -0600 Subject: [PATCH 042/134] intcmp.1: compares integers to each other --- docs/intcmp.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 209b2d8..6087d0e 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -19,7 +19,7 @@ intcmp .SH DESCRIPTION -Compare integers. +Compare integers to each other. .SH USAGE From abc599148da8ab93e7eb41604dcc04bbfa342be1 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:26:41 -0600 Subject: [PATCH 043/134] mm.1: subsequent outputs are opened for appending --- docs/mm.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mm.1 b/docs/mm.1 index 42a3e74..01790fd 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -26,7 +26,7 @@ Catenate input files and write them to the start of each output file or stream. .B -a .RS -Opens outputs for appending rather than updating. +Opens subsequent outputs for appending rather than updating. .RE .B -e From ce5a4dc4bd043febdf02e33c22f309e3a77f0e19 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:29:27 -0600 Subject: [PATCH 044/134] mm.1: removed STANDARD INPUT section --- docs/mm.1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index 01790fd..6a1f664 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -37,13 +37,16 @@ Use the standard error as an output. .B -i .RS Opens a path as an input. Without any inputs specified mm will use the -standard input. +standard input. The standard input shall be used as an input if one or more of +the input files is “-”. .RE .B -o .RS Opens a path as an output. Without any outputs specified mm will use the -standard output. +standard output. The standard output shall be used as an output if one or more +of the output files is “-”. + .RE .B -u @@ -56,11 +59,6 @@ Ensures neither input or output will be buffered. Causes SIGINT signals to be ignored. .RE -.SH STANDARD INPUT - -The standard input shall be used as an input if one or more of the input files -is “-”. - .SH DIAGNOSTICS If an output can no longer be written mm prints a diagnostic message, ceases From 5db09a5ca19aca7b8d2e39b18bb5ac61927ff0fd Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:30:06 -0600 Subject: [PATCH 045/134] mm.1: cat(1p) and tee(1p) provide similar functionality --- docs/mm.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index 6a1f664..5315c8c 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -74,9 +74,9 @@ Existing files are not truncated on ouput and are instead overwritten. .SH RATIONALE -The cat(1p) and tee(1p) programs specified in POSIX together provide nearly -equivalent functionality. The separation of the two sets of functionality into -separate APIs seemed unncessary. +The cat(1p) and tee(1p) programs specified in POSIX together provide similar +functionality. The separation of the two sets of functionality into separate +APIs seemed unncessary. .SH COPYRIGHT From 13ee16173e46c09ba97fd35e6000a3455aaac174 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 29 Mar 2024 16:47:00 -0600 Subject: [PATCH 046/134] fop.1: initial commit --- docs/fop.1 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 docs/fop.1 diff --git a/docs/fop.1 b/docs/fop.1 new file mode 100644 index 0000000..aa71b50 --- /dev/null +++ b/docs/fop.1 @@ -0,0 +1,60 @@ +.\" Copyright (c) 2024 DTB +.\" Copyright (c) 2024 Emma Tebibyte +.\" +.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, +.\" visit . + +.TH fop 1 + +.SH NAME + +fop \(en field operator + +.SH SYNOPSIS + +fop +.RB ( -d ) +.RB [ delimiter ] +.RB index +.RB program... + +.SH DESCRIPTION + +Performs operations on specified fields in input data. + +.SH OPTIONS + +.B -d +.RS +Sets a delimiter by which the input data will be split into fields. The default +is an ASCII record separator (␞). +.RE + +.SH STANDARD INPUT + +Data will be read from the standard input. + +.SH CAVEATS + +Field indices are zero-indexed, which may be unexpected behavior for some users. + +.SH RATIONALE + +With the assumption that tools will output data separated with ASCII field +separators, there is + +The idea for this utility originated in the fact that GNU ls(1) utility contains +a +.B -h +option which enables human-readable units in file size outputs. This +functionality was broken out into hru(1), but there was no easy way to modify +the field in the ouput of ls(1p) without a new tool. + +.SH COPYRIGHT + +Copyright © 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later +. + +.SH SEE ALSO + +sed(1p) From b503d976256e5100809ade0fff6deff1535e5461 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 24 Mar 2024 13:28:42 -0600 Subject: [PATCH 047/134] Makefile: directory specification changes --- Makefile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index dd77985..3a9c844 100644 --- a/Makefile +++ b/Makefile @@ -13,18 +13,18 @@ .PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1) .PRAGMA: command_comment # breaks without this? -DESTDIR=./dist -PREFIX=/usr/local +DESTDIR ?= dist +PREFIX ?= /usr/local -SYSEXITS!=printf '\043include \n' | cpp -M - | sed 's/ /\n/g' \ - | sed -n 's/sysexits\.h//p' || printf 'include/\n' +SYSEXITS != printf '\043include \n' | cpp -M - | sed 's/ /\n/g' \ + | sed -n 's/sysexits\.h//p' || printf 'include\n' -CC?=cc -RUSTC?=rustc -RUSTLIBS=--extern getopt=build/o/libgetopt.rlib \ +CC ?= cc +RUSTC ?= rustc +RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \ --extern sysexits=build/o/libsysexits.rlib \ --extern strerror=build/o/libstrerror.rlib -CFLAGS+=-I$(SYSEXITS) +CFLAGS += -I$(SYSEXITS) .PHONY: all all: dj false fop hru intcmp rpn scrut str strcmp true @@ -36,12 +36,12 @@ build: .PHONY: clean clean: - rm -rf build/ dist/ + rm -rf build dist dist: all - mkdir -p $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/share/man/man1 - cp build/bin/* $(DESTDIR)$(PREFIX)/bin/ - cp docs/*.1 $(DESTDIR)$(PREFIX)/share/man/man1/ + mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1 + cp build/bin/* $(DESTDIR)/$(PREFIX)/bin + cp docs/*.1 $(DESTDIR)/$(PREFIX)/share/man/man1 .PHONY: install install: dist From 61382c34d924ab3b42fb6a666dae43bf441ce30b Mon Sep 17 00:00:00 2001 From: DTB Date: Sun, 31 Mar 2024 22:54:03 -0600 Subject: [PATCH 048/134] mm(1): error out when given positional arguments --- src/mm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mm.c b/src/mm.c index ff62148..dc337b7 100644 --- a/src/mm.c +++ b/src/mm.c @@ -106,6 +106,15 @@ oserr(char *s, char *r){ } \ return retval +/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and + * returns an exit status appropriate for a usage error. */ +int usage(char *s){ + + fprintf(stderr, "Usage: %s (-aenu) (-i [input])... (-o [output])...\n", s); + + return EX_USAGE; +} + int main(int argc, char *argv[]){ int c; struct Files files[2]; /* {read, write} */ @@ -178,12 +187,15 @@ int main(int argc, char *argv[]){ k = 1; break; default: - fprintf(stderr, "Usage: %s (-aenu) (-i [input])..." - " (-o [output])...\n", argv[0]); - retval = EX_USAGE; + retval = usage(argv[0]); terminate; } + if(optind != argc){ + retval = usage(argv[0]); + terminate; + } + files[0].s += files[0].s == 0; files[1].s += files[1].s == 0; From 320a70bc56c3e6527bad325e0756ba010ffe17fa Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 1 Apr 2024 20:37:35 -0600 Subject: [PATCH 049/134] getopt.rs(3): initial commit --- COPYING.LESSER | 165 ++++++++++++++++ Makefile | 4 +- src/getopt-rs/error.rs | 95 --------- src/getopt-rs/errorkind.rs | 61 ------ src/getopt-rs/lib.rs | 72 ------- src/getopt-rs/opt.rs | 89 --------- src/getopt-rs/parser.rs | 382 ------------------------------------- src/getopt-rs/result.rs | 59 ------ src/getopt-rs/tests.rs | 228 ---------------------- src/getopt.rs | 115 +++++++++++ 10 files changed, 282 insertions(+), 988 deletions(-) create mode 100644 COPYING.LESSER delete mode 100644 src/getopt-rs/error.rs delete mode 100644 src/getopt-rs/errorkind.rs delete mode 100644 src/getopt-rs/lib.rs delete mode 100644 src/getopt-rs/opt.rs delete mode 100644 src/getopt-rs/parser.rs delete mode 100644 src/getopt-rs/result.rs delete mode 100644 src/getopt-rs/tests.rs create mode 100644 src/getopt.rs diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/Makefile b/Makefile index 68efd20..7f5c36f 100644 --- a/Makefile +++ b/Makefile @@ -57,9 +57,9 @@ test: build rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ build/o/libstrerror.rlib -build/o/libgetopt.rlib: build src/getopt-rs/lib.rs +build/o/libgetopt.rlib: build src/getopt.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \ - -o $@ src/getopt-rs/lib.rs + -o $@ src/getopt.rs build/o/libstrerror.rlib: build src/strerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ diff --git a/src/getopt-rs/error.rs b/src/getopt-rs/error.rs deleted file mode 100644 index 322af02..0000000 --- a/src/getopt-rs/error.rs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -use std::{ error, fmt }; - -use crate::ErrorKind::{ self, * }; - -/// A basic error type for [`Parser`](struct.Parser.html) -#[derive(Debug, Eq, PartialEq)] -pub struct Error { - culprit: char, - kind: ErrorKind, -} - -impl Error { - /// Creates a new error using a known kind and the character that caused the - /// issue. - pub fn new(kind: ErrorKind, culprit: char) -> Self { - Self { culprit, kind } - } - - /// Returns the [`ErrorKind`](enum.ErrorKind.html) for this error. - pub fn kind(self) -> ErrorKind { - self.kind - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self.kind { - MissingArgument => write!( - f, - "option requires an argument -- {:?}", - self.culprit, - ), - UnknownOption => write!(f, "unknown option -- {:?}", self.culprit), - } - } -} - -impl error::Error for Error { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - None - } -} diff --git a/src/getopt-rs/errorkind.rs b/src/getopt-rs/errorkind.rs deleted file mode 100644 index 5475d8e..0000000 --- a/src/getopt-rs/errorkind.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/// What kinds of errors [`Parser`](struct.Parser.html) can return. -#[derive(Debug, Eq, PartialEq)] -pub enum ErrorKind { - /// An argument was not found for an option that was expecting one. - MissingArgument, - /// An unknown option character was encountered. - UnknownOption, -} diff --git a/src/getopt-rs/lib.rs b/src/getopt-rs/lib.rs deleted file mode 100644 index 62f0e0d..0000000 --- a/src/getopt-rs/lib.rs +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -//! # getopt -//! -//! `getopt` provides a minimal, (essentially) POSIX-compliant option parser. - -pub use crate::{ - error::Error, - errorkind::ErrorKind, - opt::Opt, - parser::Parser, - result::Result -}; - -mod error; -mod errorkind; -mod opt; -mod parser; -mod result; -#[cfg(test)] -mod tests; diff --git a/src/getopt-rs/opt.rs b/src/getopt-rs/opt.rs deleted file mode 100644 index 05b51e6..0000000 --- a/src/getopt-rs/opt.rs +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -use std::fmt; - -/// A single option. -/// -/// For `Opt(x, y)`: -/// - `x` is the character representing the option. -/// - `y` is `Some` string, or `None` if no argument was expected. -/// -/// # Example -/// -/// ``` -/// # fn main() -> Result<(), Box> { -/// use getopt::Opt; -/// -/// // args = ["program", "-abc", "foo"]; -/// # let args: Vec = vec!["program", "-abc", "foo"] -/// # .into_iter() -/// # .map(String::from) -/// # .collect(); -/// let optstring = "ab:c"; -/// let mut opts = getopt::Parser::new(&args, optstring); -/// -/// assert_eq!(Opt('a', None), opts.next().transpose()?.unwrap()); -/// assert_eq!(Opt('b', Some("c".to_string())), opts.next().transpose()?.unwrap()); -/// assert_eq!(None, opts.next().transpose()?); -/// # Ok(()) -/// # } -/// ``` -#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] -pub struct Opt(pub char, pub Option); - -impl fmt::Display for Opt { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Opt({:?}, {:?})", self.0, self.1) - } -} diff --git a/src/getopt-rs/parser.rs b/src/getopt-rs/parser.rs deleted file mode 100644 index 6f06cc3..0000000 --- a/src/getopt-rs/parser.rs +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -use std::collections::HashMap; - -use crate::{ error::Error, errorkind::ErrorKind, opt::Opt, result::Result }; - -/// The core of the `getopt` crate. -/// -/// `Parser` is implemented as an iterator over the options present in the given -/// argument vector. -/// -/// The method [`next`](#method.next) does the heavy lifting. -/// -/// # Examples -/// -/// ## Simplified usage: -/// ``` -/// # fn main() -> Result<(), Box> { -/// use getopt::Opt; -/// -/// // args = ["program", "-abc", "foo"]; -/// # let args: Vec = vec!["program", "-abc", "foo"] -/// # .into_iter() -/// # .map(String::from) -/// # .collect(); -/// let mut opts = getopt::Parser::new(&args, "ab:c"); -/// -/// assert_eq!(Some(Opt('a', None)), opts.next().transpose()?); -/// assert_eq!(1, opts.index()); -/// assert_eq!(Some(Opt('b', Some("c".to_string()))), opts.next().transpose()?); -/// assert_eq!(2, opts.index()); -/// assert_eq!(None, opts.next()); -/// assert_eq!(2, opts.index()); -/// assert_eq!("foo", args[opts.index()]); -/// # Ok(()) -/// # } -/// ``` -/// -/// ## A more idiomatic example: -/// ``` -/// # fn main() -> Result<(), Box> { -/// use getopt::Opt; -/// -/// // args = ["program", "-abc", "-d", "foo", "-e", "bar"]; -/// # let mut args: Vec = vec!["program", "-abc", "-d", "foo", "-e", "bar"] -/// # .into_iter() -/// # .map(String::from) -/// # .collect(); -/// let mut opts = getopt::Parser::new(&args, "ab:cd:e"); -/// -/// let mut a_flag = false; -/// let mut b_flag = String::new(); -/// let mut c_flag = false; -/// let mut d_flag = String::new(); -/// let mut e_flag = false; -/// -/// loop { -/// match opts.next().transpose()? { -/// None => break, -/// Some(opt) => match opt { -/// Opt('a', None) => a_flag = true, -/// Opt('b', Some(arg)) => b_flag = arg.clone(), -/// Opt('c', None) => c_flag = true, -/// Opt('d', Some(arg)) => d_flag = arg.clone(), -/// Opt('e', None) => e_flag = true, -/// _ => unreachable!(), -/// }, -/// } -/// } -/// -/// let new_args = args.split_off(opts.index()); -/// -/// assert_eq!(true, a_flag); -/// assert_eq!("c", b_flag); -/// assert_eq!(false, c_flag); -/// assert_eq!("foo", d_flag); -/// assert_eq!(true, e_flag); -/// -/// assert_eq!(1, new_args.len()); -/// assert_eq!("bar", new_args.first().unwrap()); -/// # Ok(()) -/// # } -/// ``` -#[derive(Debug, Eq, PartialEq)] -pub struct Parser { - opts: HashMap, - args: Vec>, - index: usize, - point: usize, -} - -impl Parser { - /// Create a new `Parser`, which will process the arguments in `args` - /// according to the options specified in `optstring`. - /// - /// For compatibility with - /// [`std::env::args`](https://doc.rust-lang.org/std/env/fn.args.html), - /// valid options are expected to begin at the second element of `args`, and - /// `index` is - /// initialised to `1`. - /// If `args` is structured differently, be sure to call - /// [`set_index`](#method.set_index) before the first invocation of - /// [`next`](#method.next). - /// - /// `optstring` is a string of recognised option characters; if a character - /// is followed by a colon (`:`), that option takes an argument. - /// - /// # Note: - /// Transforming the OS-specific argument strings into a vector of `String`s - /// is the sole responsibility of the calling program, as it involves some - /// level of potential information loss (which this crate does not presume - /// to handle unilaterally) and error handling (which would complicate the - /// interface). - pub fn new(args: &[String], optstring: &str) -> Self { - let optstring: Vec = optstring.chars().collect(); - let mut opts = HashMap::new(); - let mut i = 0; - let len = optstring.len(); - - while i < len { - let j = i + 1; - - if j < len && optstring[j] == ':' { - opts.insert(optstring[i], true); - i += 1; - } else { - opts.insert(optstring[i], false); - } - i += 1; - } - - Self { - opts, - // "explode" the args into a vector of character vectors, to allow - // indexing - args: args.iter().map(|e| e.chars().collect()).collect(), - index: 1, - point: 0, - } - } - - /// Return the current `index` of the parser. - /// - /// `args[index]` will always point to the the next element of `args`; when - /// the parser is - /// finished with an element, it will increment `index`. - /// - /// After the last option has been parsed (and [`next`](#method.next) is - /// returning `None`), - /// `index` will point to the first non-option argument. - pub fn index(&self) -> usize { - self.index - } - - // `point` must be reset to 0 whenever `index` is changed - - /// Modify the current `index` of the parser. - pub fn set_index(&mut self, value: usize) { - self.index = value; - self.point = 0; - } - - /// Increment the current `index` of the parser. - /// - /// This use case is common enough to warrant its own optimised method. - pub fn incr_index(&mut self) { - self.index += 1; - self.point = 0; - } -} - -impl Iterator for Parser { - type Item = Result; - - /// Returns the next option, if any. - /// - /// Returns an [`Error`](struct.Error.html) if an unexpected option is - /// encountered or if an - /// expected argument is not found. - /// - /// Parsing stops at the first non-hyphenated argument; or at the first - /// argument matching "-"; - /// or after the first argument matching "--". - /// - /// When no more options are available, `next` returns `None`. - /// - /// # Examples - /// - /// ## "-" - /// ``` - /// use getopt::Parser; - /// - /// // args = ["program", "-", "-a"]; - /// # let args: Vec = vec!["program", "-", "-a"] - /// # .into_iter() - /// # .map(String::from) - /// # .collect(); - /// let mut opts = Parser::new(&args, "a"); - /// - /// assert_eq!(None, opts.next()); - /// assert_eq!("-", args[opts.index()]); - /// ``` - /// - /// ## "--" - /// ``` - /// use getopt::Parser; - /// - /// // args = ["program", "--", "-a"]; - /// # let args: Vec = vec!["program", "--", "-a"] - /// # .into_iter() - /// # .map(String::from) - /// # .collect(); - /// let mut opts = Parser::new(&args, "a"); - /// - /// assert_eq!(None, opts.next()); - /// assert_eq!("-a", args[opts.index()]); - /// ``` - /// - /// ## Unexpected option: - /// ``` - /// use getopt::Parser; - /// - /// // args = ["program", "-b"]; - /// # let args: Vec = vec!["program", "-b"] - /// # .into_iter() - /// # .map(String::from) - /// # .collect(); - /// let mut opts = Parser::new(&args, "a"); - /// - /// assert_eq!( - /// "unknown option -- 'b'".to_string(), - /// opts.next().unwrap().unwrap_err().to_string() - /// ); - /// ``` - /// - /// ## Missing argument: - /// ``` - /// use getopt::Parser; - /// - /// // args = ["program", "-a"]; - /// # let args: Vec = vec!["program", "-a"] - /// # .into_iter() - /// # .map(String::from) - /// # .collect(); - /// let mut opts = Parser::new(&args, "a:"); - /// - /// assert_eq!( - /// "option requires an argument -- 'a'".to_string(), - /// opts.next().unwrap().unwrap_err().to_string() - /// ); - /// ``` - fn next(&mut self) -> Option> { - if self.point == 0 { - /* - * Rationale excerpts below taken verbatim from "The Open Group Base - * Specifications Issue 7, 2018 edition", IEEE Std 1003.1-2017 - * (Revision of IEEE Std 1003.1-2008). - * Copyright © 2001-2018 IEEE and The Open Group. - */ - - /* - * If, when getopt() is called: - * argv[optind] is a null pointer - * *argv[optind] is not the character '-' - * argv[optind] points to the string "-" - * getopt() shall return -1 without changing optind. - */ - if self.index >= self.args.len() - || self.args[self.index].is_empty() - || self.args[self.index][0] != '-' - || self.args[self.index].len() == 1 - { - return None; - } - - /* - * If: - * argv[optind] points to the string "--" - * getopt() shall return -1 after incrementing index. - */ - if self.args[self.index][1] == '-' && self.args[self.index].len() == 2 { - self.incr_index(); - return None; - } - - // move past the starting '-' - self.point += 1; - } - - let opt = self.args[self.index][self.point]; - self.point += 1; - - match self.opts.get(&opt) { - None => { - if self.point >= self.args[self.index].len() { - self.incr_index(); - } - Some(Err(Error::new(ErrorKind::UnknownOption, opt))) - } - Some(false) => { - if self.point >= self.args[self.index].len() { - self.incr_index(); - } - - Some(Ok(Opt(opt, None))) - } - Some(true) => { - let arg: String = if self.point >= self.args[self.index].len() { - self.incr_index(); - if self.index >= self.args.len() { - return Some(Err(Error::new( - ErrorKind::MissingArgument, - opt, - ))); - } - self.args[self.index].iter().collect() - } else { - self.args[self.index] - .clone() - .split_off(self.point) - .iter() - .collect() - }; - - self.incr_index(); - - Some(Ok(Opt(opt, Some(arg)))) - } - } - } -} diff --git a/src/getopt-rs/result.rs b/src/getopt-rs/result.rs deleted file mode 100644 index 015a402..0000000 --- a/src/getopt-rs/result.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -use std::result; - -use crate::error::Error; - -/// A specialized `Result` type for use with [`Parser`](struct.Parser.html) -pub type Result = result::Result; diff --git a/src/getopt-rs/tests.rs b/src/getopt-rs/tests.rs deleted file mode 100644 index c53d517..0000000 --- a/src/getopt-rs/tests.rs +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2023 Emma Tebibyte - * 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/. - * - * This file incorporates work covered by the following copyright and permission - * notice: - * The Clear BSD License - * - * Copyright © 2017-2023 David Wildasin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions, and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED - * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -use crate::{Opt, Parser}; - -macro_rules! basic_test { - ($name:ident, $expect:expr, $next:expr, [$($arg:expr),+], $optstr:expr) => ( - #[test] - fn $name() -> Result<(), String> { - let expect: Option = $expect; - let args: Vec = vec![$($arg),+] - .into_iter() - .map(String::from) - .collect(); - let next: Option = $next; - let mut opts = Parser::new(&args, $optstr); - - match opts.next().transpose() { - Err(error) => { - return Err(format!("next() returned {:?}", error)) - }, - Ok(actual) => if actual != expect { - return Err( - format!("expected {:?}; got {:?}", expect, actual) - ) - }, - }; - - match next { - None => if opts.index() < args.len() { - return Err(format!( - "expected end of args; got {:?}", args[opts.index()] - )) - }, - Some(n) => if args[opts.index()] != n { - return Err(format!( - "next arg: expected {:?}; got {:?}", - n, - args[opts.index()] - )) - }, - }; - - Ok(()) - } - ) -} - -#[rustfmt::skip] basic_test!( - blank_arg, None, Some(String::new()), ["x", ""], "a" -); -#[rustfmt::skip] basic_test!( - double_dash, None, Some("-a".to_string()), ["x", "--", "-a", "foo"], "a" -); -#[rustfmt::skip] basic_test!(no_opts_1, None, None, ["x"], "a"); -#[rustfmt::skip] basic_test!( - no_opts_2, None, Some("foo".to_string()), ["x", "foo"], "a" -); -#[rustfmt::skip] basic_test!( - no_opts_3, None, Some("foo".to_string()), ["x", "foo", "-a"], "a" -); -#[rustfmt::skip] basic_test!( - single_dash, None, Some("-".to_string()), ["x", "-", "-a", "foo"], "a" -); -#[rustfmt::skip] basic_test!( - single_opt, - Some(Opt('a', None)), - Some("foo".to_string()), - ["x", "-a", "foo"], - "a" -); -#[rustfmt::skip] basic_test!( - single_optarg, - Some(Opt('a', Some("foo".to_string()))), - None, - ["x", "-a", "foo"], - "a:" -); - -macro_rules! error_test { - ($name:ident, $expect:expr, [$($arg:expr),+], $optstr:expr) => ( - #[test] - fn $name() -> Result<(), String> { - let expect: String = $expect.to_string(); - let args: Vec = vec![$($arg),+] - .into_iter() - .map(String::from) - .collect(); - let mut opts = Parser::new(&args, $optstr); - - match opts.next() { - None => { - return Err(format!( - "unexpected successful response: end of options" - )) - }, - Some(Err(actual)) => { - let actual = actual.to_string(); - - if actual != expect { - return Err( - format!("expected {:?}; got {:?}", expect, actual) - ); - } - }, - Some(Ok(opt)) => { - return Err( - format!("unexpected successful response: {:?}", opt) - ) - }, - }; - - Ok(()) - } - ) -} - -#[rustfmt::skip] error_test!( - bad_opt, - "unknown option -- 'b'", - ["x", "-b"], - "a" -); - -#[rustfmt::skip] error_test!( - missing_optarg, - "option requires an argument -- 'a'", - ["x", "-a"], - "a:" -); - -#[test] -fn multiple() -> Result<(), String> { - let args: Vec = vec!["x", "-abc", "-d", "foo", "-e", "bar"] - .into_iter() - .map(String::from) - .collect(); - let optstring = "ab:d:e".to_string(); - let mut opts = Parser::new(&args, &optstring); - - macro_rules! check_result { - ($expect:expr) => { - let expect: Option = $expect; - match opts.next().transpose() { - Err(error) => { - return Err(format!("next() returned {:?}", error)); - }, - Ok(actual) => { - if actual != expect { - return Err( - format!("expected {:?}; got {:?}", expect, actual) - ); - } - } - }; - }; - } - - check_result!(Some(Opt('a', None))); - check_result!(Some(Opt('b', Some("c".to_string())))); - check_result!(Some(Opt('d', Some("foo".to_string())))); - check_result!(Some(Opt('e', None))); - check_result!(None); - - Ok(()) -} - -#[test] -fn continue_after_error() { - let args: Vec = vec!["x", "-z", "-abc"] - .into_iter() - .map(String::from) - .collect(); - let optstring = "ab:d:e".to_string(); - for _opt in Parser::new(&args, &optstring) { - // do nothing, should not panic - } -} diff --git a/src/getopt.rs b/src/getopt.rs new file mode 100644 index 0000000..f7668c6 --- /dev/null +++ b/src/getopt.rs @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2024 Emma Tebibyte + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +use std::ffi::{ c_int, c_char, CString }; + +pub struct Opt { + pub arg: Option, + pub ind: i32, + pub opt: i32, +} + +pub enum OptError { + MissingArg, + UnknownOpt, +} + +// Function signature +pub trait GetOpt { + fn getopt( + argv: Vec, + optstring: &str + ) -> Option>; +} + +impl GetOpt for Vec { + fn getopt( + argv: Vec, + optstring: &str + ) -> Option> { + unsafe { + let args = argv + .iter() + .cloned() + .map(CString::new) + .map(Result::unwrap) + .map(|x| x.as_ptr() as c_char) + .collect::>() + .as_ptr() as *const *mut c_char; + + let len = argv.len() as c_int; + let opts = CString::new(optstring).unwrap().into_raw(); + + let a = match getopt(len, args, opts) { + /* From getopt(3p): + * + * The getopt() function shall return the next option character + * specified on the command line. + * + * A (':') shall be returned if getopt() detects a + * missing argument and the first character of optstring was a + * (':'). + * + * A ('?') shall be returned if getopt() + * encounters an option character not in optstring or detects a + * missing argument and the first character of optstring was not + * a (':'). + * + * Otherwise, getopt() shall return -1 when all command line + * options are parsed. */ + 58 => { // ASCII value for ':' + return Some(Err(OptError::MissingArg)); + }, + 63 => { // ASCII value for '?' + return Some(Err(OptError::UnknownOpt)); + }, + /* From getopt(3p): + * + * If, when getopt() is called: + * + * argv[optind] is a null pointer + * *argv[optind] is not the character - + * argv[optind] points to the string "-" + * + * getopt() shall return -1 without changing optind. If: + * + * argv[optind] points to the string "--" + * + * getopt() shall return -1 after incrementing optind. */ + -1 => return None, + a => a.to_string(), + }; + + Some(Ok(Opt { arg: Some(a), ind: optind, opt: optopt })) + } + } +} + +/* binding to getopt(3p) */ +extern "C" { + static mut _optarg: *mut c_char; + static mut _opterr: c_int; + static mut optind: c_int; + static mut optopt: c_int; + + fn getopt( + ___argc: c_int, + ___argv: *const *mut c_char, + __shortopts: *const c_char, + ) -> c_int; +} From 0164b681c03604f2532d97f52ba0061ef23beaf4 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 1 Apr 2024 20:41:07 -0600 Subject: [PATCH 050/134] Makefile: remove unneeded test --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 7f5c36f..7736a78 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,6 @@ install: dist .PHONY: test test: build tests/posix-compat.sh - $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt .PHONY: rustlibs rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ From 88b0d5544001d326496b335bf626562c68481c1c Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 11 Apr 2024 20:21:01 -0600 Subject: [PATCH 051/134] getopt.rs(3): refactor to remove as much as possible from unsafe --- src/getopt.rs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index f7668c6..b95108c 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -31,31 +31,24 @@ pub enum OptError { // Function signature pub trait GetOpt { - fn getopt( - argv: Vec, - optstring: &str - ) -> Option>; + fn getopt(&self, optstring: &str) -> Option>; } impl GetOpt for Vec { - fn getopt( - argv: Vec, - optstring: &str - ) -> Option> { + fn getopt(&self, optstring: &str) -> Option> { + let argv = self + .iter() + .cloned() + .map(CString::new) + .map(Result::unwrap) + .map(|x| x.as_ptr() as c_char) + .collect::>() + .as_ptr() as *const *mut c_char; + let opts = CString::new(optstring).unwrap().into_raw(); + let len = self.len() as c_int; + unsafe { - let args = argv - .iter() - .cloned() - .map(CString::new) - .map(Result::unwrap) - .map(|x| x.as_ptr() as c_char) - .collect::>() - .as_ptr() as *const *mut c_char; - - let len = argv.len() as c_int; - let opts = CString::new(optstring).unwrap().into_raw(); - - let a = match getopt(len, args, opts) { + let a = match getopt(len, argv, opts) { /* From getopt(3p): * * The getopt() function shall return the next option character From bb2c63bfafc19cd468b7fb9ebbdb3dd4e411d2b4 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 11 Apr 2024 20:33:42 -0600 Subject: [PATCH 052/134] getopt.rs(3): fixed pointer shenanigans --- src/getopt.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index b95108c..81c146d 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -16,7 +16,7 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -use std::ffi::{ c_int, c_char, CString }; +use std::ffi::{ c_int, c_char, CString, CStr }; pub struct Opt { pub arg: Option, @@ -35,20 +35,22 @@ pub trait GetOpt { } impl GetOpt for Vec { - fn getopt(&self, optstring: &str) -> Option> { - let argv = self + fn getopt(&self, optstring: &str) -> Option> { + let c_strings: Vec<_> = self .iter() .cloned() .map(CString::new) .map(Result::unwrap) - .map(|x| x.as_ptr() as c_char) - .collect::>() - .as_ptr() as *const *mut c_char; - let opts = CString::new(optstring).unwrap().into_raw(); - let len = self.len() as c_int; + .collect(); - unsafe { - let a = match getopt(len, argv, opts) { + let argv: Vec<_> = c_strings.iter().map(|x| x.as_ptr()).collect(); + let argv_ptr = argv.as_ptr() as *const *mut c_char; + let optstring_c = CString::new(optstring).unwrap(); + let opts = optstring_c.into_raw(); + let len = self.len() as c_int; + + unsafe { + let a = match getopt(len, argv_ptr, opts) { /* From getopt(3p): * * The getopt() function shall return the next option character @@ -65,11 +67,11 @@ impl GetOpt for Vec { * * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ - 58 => { // ASCII value for ':' + 58 => { /* ASCII value for ':' */ return Some(Err(OptError::MissingArg)); }, - 63 => { // ASCII value for '?' - return Some(Err(OptError::UnknownOpt)); + 63 => { /* ASCII value for '?' */ + return Some(Err(OptError::UnknownOpt)) }, /* From getopt(3p): * @@ -84,18 +86,17 @@ impl GetOpt for Vec { * argv[optind] points to the string "--" * * getopt() shall return -1 after incrementing optind. */ - -1 => return None, - a => a.to_string(), - }; + -1 => return None, + _ => CStr::from_ptr(optarg).to_string_lossy().into_owned(), + }; - Some(Ok(Opt { arg: Some(a), ind: optind, opt: optopt })) - } - } + Some(Ok(Opt { arg: Some(a), ind: optind, opt: optopt })) + } + } } - /* binding to getopt(3p) */ extern "C" { - static mut _optarg: *mut c_char; + static mut optarg: *mut c_char; static mut _opterr: c_int; static mut optind: c_int; static mut optopt: c_int; From ad92fe27d4eb2a6731182844918713ee93acc292 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 11 Apr 2024 23:37:04 -0600 Subject: [PATCH 053/134] fop(1): switch to getopt.rs(3) --- src/fop.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index b829602..a56a0a6 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -26,33 +26,43 @@ extern crate getopt; extern crate strerror; extern crate sysexits; -use getopt::{ Opt, Parser }; +use getopt::GetOpt; use strerror::StrError; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); let mut d = '␞'; - let mut arg_parser = Parser::new(&argv, "d:"); + let usage = format!( + "Usage: {} [-d delimiter] index command [args...]", + argv[0], + ); + let mut index_arg = 0; - while let Some(opt) = arg_parser.next() { + while let Some(opt) = argv.getopt("d:") { match opt { - Ok(Opt('d', Some(arg))) => { + Ok(o) => { + /* unwrap because Err(OptError::MissingArg) will be returned if + * o.arg is None */ + let arg = o.arg.unwrap(); let arg_char = arg.chars().collect::>(); if arg_char.len() > 1 { eprintln!("{}: {}: Not a character.", argv[0], arg); exit(EX_USAGE); } else { d = arg_char[0]; } + index_arg = o.ind as usize; }, - _ => {}, + Err(_) => { + eprintln!("{}", usage); + exit(EX_USAGE); + } }; } - let index_arg = arg_parser.index(); - let command_arg = arg_parser.index() + 1; + let command_arg = index_arg as usize + 1; argv.get(command_arg).unwrap_or_else(|| { - eprintln!("Usage: {} [-d delimiter] index command [args...]", argv[0]); + eprintln!("{}", usage); exit(EX_USAGE); }); From 95927ba8c5125893dbc5a92d2022ed710df7211e Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 11 Apr 2024 23:51:52 -0600 Subject: [PATCH 054/134] getopt.rs(3): formatting --- src/getopt.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index 81c146d..70ee801 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -29,7 +29,7 @@ pub enum OptError { UnknownOpt, } -// Function signature +/* function signature */ pub trait GetOpt { fn getopt(&self, optstring: &str) -> Option>; } @@ -43,10 +43,11 @@ impl GetOpt for Vec { .map(Result::unwrap) .collect(); + /* these operations must be separated out into separate operations so + * the CStrings can live long enough */ let argv: Vec<_> = c_strings.iter().map(|x| x.as_ptr()).collect(); let argv_ptr = argv.as_ptr() as *const *mut c_char; - let optstring_c = CString::new(optstring).unwrap(); - let opts = optstring_c.into_raw(); + let opts = CString::new(optstring).unwrap().into_raw(); let len = self.len() as c_int; unsafe { @@ -67,10 +68,10 @@ impl GetOpt for Vec { * * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ - 58 => { /* ASCII value for ':' */ + 58 => { /* numerical ASCII value for ':' */ return Some(Err(OptError::MissingArg)); }, - 63 => { /* ASCII value for '?' */ + 63 => { /* numerical ASCII value for '?' */ return Some(Err(OptError::UnknownOpt)) }, /* From getopt(3p): From 8c255e61fc4d35ed250b36f4ecf2a8e17edef5d7 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 12 Apr 2024 00:12:37 -0600 Subject: [PATCH 055/134] COPYING.GPL: initial commit --- COPYING.GPL | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 COPYING.GPL diff --git a/COPYING.GPL b/COPYING.GPL new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/COPYING.GPL @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From d1b77d652b18980f45e6a5a19d9a00e5b3b85f2b Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 13 Apr 2024 17:11:04 -0600 Subject: [PATCH 056/134] getopt.rs(3): returns last parsed option --- src/getopt.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index 70ee801..c4f88ab 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -21,12 +21,13 @@ use std::ffi::{ c_int, c_char, CString, CStr }; pub struct Opt { pub arg: Option, pub ind: i32, - pub opt: i32, + /* opt is set to either the current option or the one that cause an error */ + pub opt: String, } pub enum OptError { - MissingArg, - UnknownOpt, + MissingArg(String), + UnknownOpt(String), } /* function signature */ @@ -51,7 +52,7 @@ impl GetOpt for Vec { let len = self.len() as c_int; unsafe { - let a = match getopt(len, argv_ptr, opts) { + match getopt(len, argv_ptr, opts) { /* From getopt(3p): * * The getopt() function shall return the next option character @@ -69,10 +70,10 @@ impl GetOpt for Vec { * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ 58 => { /* numerical ASCII value for ':' */ - return Some(Err(OptError::MissingArg)); + Some(Err(OptError::MissingArg(optopt.to_string()))) }, 63 => { /* numerical ASCII value for '?' */ - return Some(Err(OptError::UnknownOpt)) + Some(Err(OptError::UnknownOpt(optopt.to_string()))) }, /* From getopt(3p): * @@ -88,10 +89,18 @@ impl GetOpt for Vec { * * getopt() shall return -1 after incrementing optind. */ -1 => return None, - _ => CStr::from_ptr(optarg).to_string_lossy().into_owned(), - }; + opt => { + let arg = CStr::from_ptr(optarg) + .to_string_lossy() + .into_owned(); - Some(Ok(Opt { arg: Some(a), ind: optind, opt: optopt })) + Some(Ok(Opt { + arg: Some(arg), + ind: optind, + opt: opt.to_string(), + })) + }, + } } } } From 78eacd660a3af310bae8c23b1693e20e56d49896 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 13 Apr 2024 23:42:11 -0600 Subject: [PATCH 057/134] getopt.rs(3): better Opt return --- src/getopt.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index c4f88ab..b146400 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -21,7 +21,6 @@ use std::ffi::{ c_int, c_char, CString, CStr }; pub struct Opt { pub arg: Option, pub ind: i32, - /* opt is set to either the current option or the one that cause an error */ pub opt: String, } @@ -51,8 +50,8 @@ impl GetOpt for Vec { let opts = CString::new(optstring).unwrap().into_raw(); let len = self.len() as c_int; - unsafe { - match getopt(len, argv_ptr, opts) { + unsafe { // TODO: enable optind modification + match getopt(len, argv_ptr, opts) { /* From getopt(3p): * * The getopt() function shall return the next option character @@ -95,9 +94,9 @@ impl GetOpt for Vec { .into_owned(); Some(Ok(Opt { - arg: Some(arg), - ind: optind, - opt: opt.to_string(), + arg: Some(arg), /* opt argument */ + ind: optind, /* opt index */ + opt: opt.to_string(), /* option itself */ })) }, } From df16707b0e2c74217d7ea4aaaab0f45b6f0cff97 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 18 Apr 2024 08:36:01 -0600 Subject: [PATCH 058/134] intcmp.1: -e permits adjacent integers to be equal to each other --- docs/intcmp.1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 6087d0e..b15f4c1 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -25,11 +25,7 @@ Compare integers to each other. .B -e .RS -Permits given integers to be equal to each other. If combined with -.B -g -or -.B -l -, only adjacent integers in the argument sequence can be equal. +Permits given integers to be equal to each other. .RE .B -g From 3cdade71e2019d754d85b53a680eef27b2fa2939 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 18 Apr 2024 08:38:48 -0600 Subject: [PATCH 059/134] dj.1: -S whether or not the input is a stream is irrelevant --- docs/dj.1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 0e882dd..e70c666 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -70,8 +70,7 @@ DIAGNOSTICS section below. .B -S .RS Skips a number of bytes through the output before starting to write from -the input. If the input is a stream the bytes are read and discarded. If the -output is a stream, null characters are printed. +the input. If the output is a stream, null characters are printed. .RE .B -a From ed284b9949eb9cc5a4fc2796e315d1c430fcce29 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 18 Apr 2024 08:40:29 -0600 Subject: [PATCH 060/134] dj.1: -a: More specific wording --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index e70c666..41e3112 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -75,8 +75,8 @@ the input. If the output is a stream, null characters are printed. .B -a .RS -Takes one argument of one byte in length and pads the input buffer with it in -the event of an incomplete read from the input file. +Accepts a single literal byte with which input buffer is padded in the event +of an incomplete read from the input file. .RE .B -b From b41af1b578a912df0bd4484be2f2a7604e8e9312 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 18 Apr 2024 08:41:55 -0600 Subject: [PATCH 061/134] dj.1: -c: grammar --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 41e3112..9bc2d82 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -87,8 +87,8 @@ default being 1024 bytes or one kibibyte (KiB). .B -c .RS -Specifies an amount of reads to make, and if 0 (the default) dj will -continue reading until a partial or empty read. +Specifies a number of reads to make. If set to zero (the default), reading will +continue until a partial or empty read is encountered. .RE .B -d From 187d9486b762006cbb1efb12a7d8a49ae54ed14a Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 18 Apr 2024 08:44:44 -0600 Subject: [PATCH 062/134] dj.1: debug output clarification --- docs/dj.1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 9bc2d82..175a32c 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -149,9 +149,10 @@ the following format: .R {ASCII record separator} {bytes written} {ASCII file separator} .RE -If the +This format for diagnostic output is designed to be machine-parseable for +convenience. For a more human-readable format, the .B -H -option is specified, the following format is used instead: +option may be specified. In this event, the following format is used instead: .RS .R {records read} '+' {partial records read} '>' {records written} From f6aac60aee89eafcb088337d7f820766a657d5c1 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 12:40:20 -0600 Subject: [PATCH 063/134] Makefile: fixed manpage install location --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 68efd20..e0068dc 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,8 @@ DESTDIR ?= dist PREFIX ?= /usr/local +MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \ + || printf '/share/man\n' SYSEXITS != printf '\043include \n' | cpp -M - | sed 's/ /\n/g' \ | sed -n 's/sysexits\.h//p' || printf 'include\n' @@ -42,7 +44,7 @@ clean: dist: all mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1 cp build/bin/* $(DESTDIR)/$(PREFIX)/bin - cp docs/*.1 $(DESTDIR)/$(PREFIX)/share/man/man1 + cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1 .PHONY: install install: dist From d8b54fdbf5b1e19810c28a341c59d0ec4fec01ec Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 12:43:31 -0600 Subject: [PATCH 064/134] Makefile: fixes erroneous whitespace --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index e0068dc..1952a25 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,6 @@ mm: build/bin/mm build/bin/mm: src/mm.c build $(CC) $(CFLAGS) -o $@ src/mm.c - .PHONY: npc npc: build/bin/npc build/bin/npc: src/npc.c build From 488351da39384f7ef510a19bcfa1af65feccc4f4 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 25 Apr 2024 16:46:05 -0600 Subject: [PATCH 065/134] scrut(1): changed return status 0 to EXIT_SUCCESS --- src/scrut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scrut.c b/src/scrut.c index e2494d3..8d0d393 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -100,5 +100,5 @@ usage: fprintf(stderr, "Usage: %s (-%s) [file...]\n", return 1; }while(*++argv != NULL); - return 0; + return EXIT_SUCCESS; } From adc9dbded5401bb05538d1b2dec8b20b3c2200f3 Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 26 Apr 2024 19:30:33 -0600 Subject: [PATCH 066/134] scrut(1): changed return status 1 to EXIT_FAILURE --- src/scrut.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scrut.c b/src/scrut.c index 8d0d393..025b743 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -17,7 +17,7 @@ */ #include /* fprintf(3), stderr, NULL */ -#include /* EXIT_FAILURE */ +#include /* EXIT_FAILURE, EXIT_SUCCESS */ #include /* memset(3), strchr(3) */ #include /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */ #include /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR, @@ -57,7 +57,7 @@ int main(int argc, char *argv[]){ argv += optind; do{ if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1) - return 1; /* doesn't exist or isn't stattable */ + return EXIT_FAILURE; /* doesn't exist or isn't stattable */ for(i = 0; ops[i] != '\0'; ++i) if(ops[i] == 'e') @@ -97,7 +97,7 @@ usage: fprintf(stderr, "Usage: %s (-%s) [file...]\n", && !S_ISLNK(buf.st_mode)) || (ops[i] == 'S' && !S_ISSOCK(buf.st_mode))) - return 1; + return EXIT_FAILURE; }while(*++argv != NULL); return EXIT_SUCCESS; From 8e38db92c761286d9a4f9e09c111bba94c9a213c Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 26 Apr 2024 19:33:45 -0600 Subject: [PATCH 067/134] scrut(1): update copyright header --- src/scrut.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scrut.c b/src/scrut.c index 025b743..acc05ff 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2023 DTB + * Copyright (c) 2023–2024 DTB + * Copyright (c) 2024 Emma Tebibyte * SPDX-License-Identifier: AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify it under From 919b17140098b01bc2d12e1054a35681b871e549 Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 26 Apr 2024 19:35:33 -0600 Subject: [PATCH 068/134] scrut(1): conditionally include non-POSIX sysexits.h --- src/scrut.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scrut.c b/src/scrut.c index acc05ff..c5b675f 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -20,11 +20,13 @@ #include /* fprintf(3), stderr, NULL */ #include /* EXIT_FAILURE, EXIT_SUCCESS */ #include /* memset(3), strchr(3) */ +#ifndef EX_USAGE +# include +#endif #include /* access(3), getopt(3), F_OK, R_OK, W_OK, X_OK */ #include /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR, * S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK, * S_ISUID, S_ISVTX */ -#include static char args[] = "bcdefghkprsuwxLS"; static char ops[(sizeof args) / (sizeof *args)]; From 432b19818ed625d6673c24e527a8502ffec5b689 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 28 Apr 2024 20:42:44 -0600 Subject: [PATCH 069/134] made dj options no longer alphabetized --- docs/dj.1 | 61 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 175a32c..429b7fc 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -47,11 +47,27 @@ dj .SH OPTIONS -.B -A +.B -i .RS -If the output is a stream, null bytes are printed. In other words, it does what -.B -a -does but with null bytes instead. +Takes a file path as an argument to open and use as an input. +.RE + +.B -b +.RS +Takes a numeric argument as the size in bytes of the input buffer, with the +default being 1024 bytes or one kibibyte (KiB). +.RE + +.B -s +.RS +Takes a numeric argument as the number of bytes to skip into the input +before starting to read. If the standard input is used, bytes read to this point +are discarded. +.RE + +.B -o +.RS +Takes a file path as an argument to open and use as an output. .RE .B -B @@ -61,12 +77,6 @@ Does the same as but for the output buffer. .RE -.B -H -.RS -Prints diagnostics messages in a human-readable manner as described in the -DIAGNOSTICS section below. -.RE - .B -S .RS Skips a number of bytes through the output before starting to write from @@ -79,18 +89,20 @@ Accepts a single literal byte with which input buffer is padded in the event of an incomplete read from the input file. .RE -.B -b -.RS -Takes a numeric argument as the size in bytes of the input buffer, with the -default being 1024 bytes or one kibibyte (KiB). -.RE - .B -c .RS Specifies a number of reads to make. If set to zero (the default), reading will continue until a partial or empty read is encountered. .RE +.B -A +.RS +If the output is a stream, null bytes are printed. This option is equivalent to +specifying +.B -a +with a null byte instead of a character. +.RE + .B -d .RS Prints invocation information before program execution as described in the @@ -98,9 +110,10 @@ DIAGNOSTICS section below. Each invocation increments the debug level of the program. .RE -.B -i +.B -H .RS -Takes a file path as an argument to open and use as an input. +Prints diagnostics messages in a human-readable manner as described in the +DIAGNOSTICS section below. .RE .B -n @@ -108,18 +121,6 @@ Takes a file path as an argument to open and use as an input. Retries failed reads once more before exiting. .RE -.B -o -.RS -Takes a file path as an argument to open and use as an output. -.RE - -.B -s -.RS -Takes a numeric argument as the number of bytes to skip into the input -before starting to read. If the standard input is used, bytes read to this point -are discarded. -.RE - .B -q .RS Suppresses error messages which print when a read or write is partial or From c53f3fa617d1bf628ac2b1874f043d769fdcc87a Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 09:53:54 -0600 Subject: [PATCH 070/134] dj.1: remove mention of KiB --- docs/dj.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index 429b7fc..1ebda2e 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -55,7 +55,7 @@ Takes a file path as an argument to open and use as an input. .B -b .RS Takes a numeric argument as the size in bytes of the input buffer, with the -default being 1024 bytes or one kibibyte (KiB). +default being 1024. .RE .B -s From d87f4b20a32f5b2ce49ce697b843eb749ca2d0bb Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 09:56:44 -0600 Subject: [PATCH 071/134] dj.1: -A: better description --- docs/dj.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 1ebda2e..1473455 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -97,10 +97,10 @@ continue until a partial or empty read is encountered. .B -A .RS -If the output is a stream, null bytes are printed. This option is equivalent to -specifying +Specifying this option pads the input buffer with null bytes in the event of an +incomplete read. Equivalent to specifying .B -a -with a null byte instead of a character. +with a null byte instead of a character. .RE .B -d From 2137b0bf4342c5d63514f8946d15a395c08e29da Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:03:52 -0600 Subject: [PATCH 072/134] dj.1: -i: better description --- docs/dj.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index 1473455..1fd7a63 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -49,7 +49,7 @@ dj .B -i .RS -Takes a file path as an argument to open and use as an input. +Takes a file path as an argument and opens it for use as an input. .RE .B -b From b4173a23276ead1c1965a656c3bc06c58bd61f2c Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:06:15 -0600 Subject: [PATCH 073/134] dj.1: -o: better description --- docs/dj.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index 1fd7a63..49bf733 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -67,7 +67,7 @@ are discarded. .B -o .RS -Takes a file path as an argument to open and use as an output. +Takes a file path as an argument and opens it for use as an output. .RE .B -B From 0660db3d029ab12b58e77bba25e5be3cbfea7f42 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:13:17 -0600 Subject: [PATCH 074/134] dj.1: -c: better description --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 49bf733..e4399c3 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -91,8 +91,8 @@ of an incomplete read from the input file. .B -c .RS -Specifies a number of reads to make. If set to zero (the default), reading will -continue until a partial or empty read is encountered. +Specifies a number of reads to make. The default is zero, in which case the +input is read until a partial or empty read is made. .RE .B -A From 122a10257e472893389fd2678dda3134272d4782 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:13:59 -0600 Subject: [PATCH 075/134] dj.1: fixed option description locations --- docs/dj.1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index e4399c3..2c2e634 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -89,12 +89,6 @@ Accepts a single literal byte with which input buffer is padded in the event of an incomplete read from the input file. .RE -.B -c -.RS -Specifies a number of reads to make. The default is zero, in which case the -input is read until a partial or empty read is made. -.RE - .B -A .RS Specifying this option pads the input buffer with null bytes in the event of an @@ -103,6 +97,12 @@ incomplete read. Equivalent to specifying with a null byte instead of a character. .RE +.B -c +.RS +Specifies a number of reads to make. The default is zero, in which case the +input is read until a partial or empty read is made. +.RE + .B -d .RS Prints invocation information before program execution as described in the From 922ee71283d0738b7c916f58eea45fb563c66aa5 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:14:53 -0600 Subject: [PATCH 076/134] dj.1: fixes standard input section grammar --- docs/dj.1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 2c2e634..7534b6e 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -129,8 +129,8 @@ empty. Each invocation decrements the debug level of the program. .SH STANDARD INPUT -The standard input shall be used as an input if no inputs are specified one or -more of the input files is “-”. +The standard input shall be used as an input if no inputs are specified or if +one or more of the input files is “-”. .SH DIAGNOSTICS From b7f52902b6bde54876b5fd8efafa433e2cf0df9a Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 24 May 2024 10:21:06 -0600 Subject: [PATCH 077/134] dj.1: grammar & formatting --- docs/dj.1 | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 7534b6e..7af1c00 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -138,9 +138,9 @@ On a partial or empty read, a diagnostic message is printed (unless the .B -q option is specified) and the program exits (unless the .B -n -option is specified. +option is specified). -By default statistics are printed for input and output to the standard error in +By default, statistics are printed for input and output to the standard error in the following format: .RS @@ -163,9 +163,9 @@ option may be specified. In this event, the following format is used instead: If the .B -d -option is specified, debug output will be printed at the beginning of execution. -This debug information contains information regarding how the program was -invoked. The following example is the result of running the program with +option is specified, debug output will be printed at the beginning of +execution. This debug information contains information regarding how the program +was invoked. The following example is the result of running the program with .B -d as the only argument: @@ -183,29 +183,31 @@ sysexits.h(3) status. If .B -n -is specified along with a specified count, actual byte output may be lower than -expected (the product of the count multiplied by the input block size). If the +is specified along with the +.B -c +option and a count, actual byte output may be lower than expected (the product +of the count and the input block size). If the .B -a or .B -A -options are used this could make data written nonsensical. - -Many lowercase options have capitalized variants and vice-versa which can be -confusing. Capitalized options tend to affect output or are more intense -versions of lowercase options. +options are used, this could make data written nonsensical. .SH CAVEATS Existing files are not truncated on ouput and are instead overwritten. +Many lowercase options have capitalized variants and vice-versa which can be +confusing. Capitalized options tend to affect output or are more intense +versions of lowercase options. + .SH RATIONALE This program was based on the dd(1p) utility as specified in POSIX. While character conversion may have been the original intent of dd(1p), it is -irrelevant to its modern use. Because of this, it eschews character conversion -and adds typical option formatting, allowing seeks to be specified in bytes -rather than in blocks, allowing arbitrary bytes as padding, and printing in a -format that’s easy to parse for machines. +irrelevant to its modern use. Because of this, this program eschews character +conversion and adds typical option formatting, allowing seeks to be specified +in bytes rather than in blocks, allowing arbitrary bytes as padding, and +printing in a format that’s easy for machines to parse. .SH COPYRIGHT From 70cbc52c932e799b4b9e863d73adbdf95006184c Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 18:47:14 -0600 Subject: [PATCH 078/134] docs: updates to use man(7) macros to fix formatting --- docs/dj.1 | 119 ++++++++++++++++-------------------------------- docs/false.1 | 40 +++++++++-------- docs/fop.1 | 58 ++++++++++++------------ docs/hru.1 | 58 ++++++++++++------------ docs/intcmp.1 | 107 +++++++++++++++++++++---------------------- docs/mm.1 | 51 +++++++-------------- docs/npc.1 | 61 ++++++++++++------------- docs/rpn.1 | 85 +++++++++++++++++++---------------- docs/scrut.1 | 122 ++++++++++++++++++-------------------------------- docs/str.1 | 44 +++++++++--------- docs/strcmp.1 | 66 ++++++++++++++------------- docs/swab.1 | 54 +++++++++------------- docs/true.1 | 36 ++++++++------- 13 files changed, 406 insertions(+), 495 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 7af1c00..df660fa 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -3,15 +3,13 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - -.TH dj 1 - +.\" +.TH DJ 1 .SH NAME - dj \(en disk jockey - +.\" .SH SYNOPSIS - +.\" dj .RB ( -AdHnq ) .RB ( -a @@ -44,102 +42,63 @@ dj .R [ .B output offset .R ]) - +.\" .SH OPTIONS - -.B -i -.RS +.\" +.IP \fB-i\fP Takes a file path as an argument and opens it for use as an input. -.RE - -.B -b -.RS +.IP \fB-b\fP Takes a numeric argument as the size in bytes of the input buffer, with the default being 1024. -.RE - -.B -s -.RS +.IP \fB-s\fP Takes a numeric argument as the number of bytes to skip into the input before starting to read. If the standard input is used, bytes read to this point are discarded. -.RE - -.B -o -.RS +.IP \fB-o\fP Takes a file path as an argument and opens it for use as an output. -.RE - -.B -B -.RS +.IP \fB-B\fP Does the same as .B -b but for the output buffer. -.RE - -.B -S -.RS +.IP \fB-S\fP Skips a number of bytes through the output before starting to write from the input. If the output is a stream, null characters are printed. -.RE - -.B -a -.RS +.IP \fB-a\fP Accepts a single literal byte with which input buffer is padded in the event of an incomplete read from the input file. -.RE - -.B -A -.RS +.IP \fB-A\fP Specifying this option pads the input buffer with null bytes in the event of an incomplete read. Equivalent to specifying .B -a -with a null byte instead of a character. -.RE - -.B -c -.RS +with a null byte instead of a character. +.IP \fB-c\fP Specifies a number of reads to make. The default is zero, in which case the input is read until a partial or empty read is made. -.RE - -.B -d -.RS +.IP \fB-d\fP Prints invocation information before program execution as described in the DIAGNOSTICS section below. Each invocation increments the debug level of the program. -.RE - -.B -H -.RS +.IP \fB-H\fP Prints diagnostics messages in a human-readable manner as described in the DIAGNOSTICS section below. -.RE - -.B -n -.RS +.IP \fB-n\fP Retries failed reads once more before exiting. -.RE - -.B -q -.RS +.IP \fB-q\fP Suppresses error messages which print when a read or write is partial or empty. Each invocation decrements the debug level of the program. -.RE - .SH STANDARD INPUT - +.\" The standard input shall be used as an input if no inputs are specified or if -one or more of the input files is “-”. - +one or more of the input files is \(lq-\(rq. +.\" .SH DIAGNOSTICS - +.\" On a partial or empty read, a diagnostic message is printed (unless the .B -q option is specified) and the program exits (unless the .B -n option is specified). - +.\" By default, statistics are printed for input and output to the standard error in the following format: @@ -175,12 +134,12 @@ as the only argument: .R out= obs=1024 seek=0 debug= 3 noerror=0 .RE -In non-recoverable errors that don’t pertain to the read-write cycle, a +In non-recoverable errors that don\(cqt pertain to the read-write cycle, a diagnostic message is printed and the program exits with the appropriate sysexits.h(3) status. - +.\" .SH BUGS - +.\" If .B -n is specified along with the @@ -191,29 +150,29 @@ of the count and the input block size). If the or .B -A options are used, this could make data written nonsensical. - +.\" .SH CAVEATS - +.\" Existing files are not truncated on ouput and are instead overwritten. Many lowercase options have capitalized variants and vice-versa which can be confusing. Capitalized options tend to affect output or are more intense versions of lowercase options. - +.\" .SH RATIONALE - +.\" This program was based on the dd(1p) utility as specified in POSIX. While character conversion may have been the original intent of dd(1p), it is irrelevant to its modern use. Because of this, this program eschews character conversion and adds typical option formatting, allowing seeks to be specified in bytes rather than in blocks, allowing arbitrary bytes as padding, and -printing in a format that’s easy for machines to parse. - +printing in a format that\(cqs easy for machines to parse. +.\" .SH COPYRIGHT - -Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later +.\" +Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -dd(1p) +.\" +.BR dd (1p) diff --git a/docs/false.1 b/docs/false.1 index b8463ae..5719899 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -3,32 +3,34 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH FALSE 1 - .SH NAME - false \(en do nothing, unsuccessfully - +.\" .SH DESCRIPTION - -Do nothing regardless of operands or standard input. -An exit code of 1 will always be returned. - +.\" +Do nothing regardless of operands or standard input. An exit code of 1 will +always be returned. +.\" .SH RATIONALE - -In POSIX.1-2017, false(1p) exists for the construction of control flow and loops -based on a failure. This implementation functions as described in that standard. - +.\" +In POSIX.1-2017, +.BR false (1p) +exists for the construction of control flow and loops based on a failure. This +implementation functions as described in that standard. +.\" .SH AUTHOR - -Written by Emma Tebibyte . - +.\" +Written by Emma Tebibyte +.MT emma@tebibyte.media +.ME . +.\" .SH COPYRIGHT - +.\" This work is marked with CC0 1.0. To see a copy of this license, visit . - +.\" .SH SEE ALSO - -true(1p) +.\" +.BR true (1p) diff --git a/docs/fop.1 b/docs/fop.1 index aa71b50..75a956d 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -3,58 +3,58 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH fop 1 - .SH NAME - fop \(en field operator - +.\" .SH SYNOPSIS - +.\" fop .RB ( -d ) .RB [ delimiter ] .RB index .RB program... - +.\" .SH DESCRIPTION - +.\" Performs operations on specified fields in input data. - +.\" .SH OPTIONS - -.B -d -.RS +.\" +.IP \fB-d\fP Sets a delimiter by which the input data will be split into fields. The default is an ASCII record separator (␞). -.RE - .SH STANDARD INPUT - +.\" Data will be read from the standard input. - +.\" .SH CAVEATS - +.\" Field indices are zero-indexed, which may be unexpected behavior for some users. - +.\" .SH RATIONALE - +.\" With the assumption that tools will output data separated with ASCII field -separators, there is +separators, there is a need for the ability to modify select fields in this data +easily and quickly. -The idea for this utility originated in the fact that GNU ls(1) utility contains -a +The idea for this utility originated in the fact that the GNU +.BR ls (1) +utility contains a .B -h option which enables human-readable units in file size outputs. This -functionality was broken out into hru(1), but there was no easy way to modify -the field in the ouput of ls(1p) without a new tool. - +functionality was broken out into +.BR hru (1), +but there was no easy way to modify the field in the ouput of +.BR ls (1p) +without creating a new tool. +.\" .SH COPYRIGHT - -Copyright © 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later +.\" +Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -sed(1p) +.\" +.BR sed (1p) diff --git a/docs/hru.1 b/docs/hru.1 index 1ffc00e..f87be16 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -2,58 +2,60 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - -.TH hru 1 - +.\" +.TH HRU 1 .SH NAME - hru \(en human readable units - +.\" .SH SYNOPSIS - +.\" hru - +.\" .SH DESCRIPTION - +.\" Convert counts to higher units. - +.\" The program will read byte counts in the form of whole numbers from the standard -input and write to the standard output the same number converted to a higher +input and write to the standard output the same number converted to a higher unit of data as defined by the International System of Units. - +.\" The program will convert the byte count to the highest unit possible where the value is greater than one. - +.\" .SH DIAGNOSTICS - +.\" If encountering non-integer characters in the standard input, the program will exit with the appropriate error code as defined by sysexits.h(3) and print an error message. - +.\" .SH RATIONALE - -The GNU project’s ls(1) implementation contains a human-readable option (-h) +.\" +The GNU project\(cqs ls(1) implementation contains a human-readable option (-h) that, when specified, makes the tool print size information in a format more immediately readable. This functionality is useful not only in the context of ls(1) so the decision was made to split it into a new tool. The original -functionality in GNU’s ls(1) can be emulated with fop(1) combined with this +functionality in GNU\(cqs ls(1) can be emulated with fop(1) combined with this program. - +.\" .SH STANDARDS - +.\" The standard unit prefixes as specified by the Bureau International des Poids et Mesures (BIPM) in the ninth edition of The International System of Units (SI) are utilized for the ouput of conversions. - +.\" .SH AUTHOR - -Written by Emma Tebibyte . - +.\" +Written by Emma Tebibyte +.MT emma@tebibyte.media +.ME . +.\" .SH COPYRIGHT - -Copyright (c) 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later +.\" +Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -GNU ls(1), The International System of Units (SI) 9th Edition +.\" +GNU +.BR ls (1), +The International System of Units (SI) 9th Edition diff --git a/docs/intcmp.1 b/docs/intcmp.1 index b15f4c1..79902b9 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -3,90 +3,87 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - -.TH intcmp 1 - +.\" +.TH INTCMP 1 .SH NAME - intcmp \(en compare integers - +.\" .SH SYNOPSIS - +.\" intcmp .RB ( -egl ) .RB [ integer ] .RB [ integer... ] - .SH DESCRIPTION - Compare integers to each other. - -.SH USAGE - -.B -e -.RS +.SH OPTIONS +.IP \fB-e\fP Permits given integers to be equal to each other. -.RE - -.B -g -.RS +.IP \fB-g\fP Permits a given integer to be greater than the following integer. -.RE - -.B -l -.RS +.IP \fB-l\fP Permits a given integer to be less than the following integer. -.RE - .SH EXAMPLES - +.\" It may help to think of the -e, -g, and -l options as equivalent to the -infix algebraic “=”, “>”, and “<” operators respectively, with each option -putting its symbol between every given integer. The following example is -equivalent to evaluating “1 < 2 < 3”: +infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq operators respectively, with +each option putting its symbol between every given integer. The following +example is equivalent to evaluating \(lq1 < 2 < 3\(rq: .RS .R intcmp -l 1 2 3 .RE - +.\" .SH DIAGNOSTICS - +.\" The program will exit with a status code of 0 for a valid expression and with a code of 1 for an invalid expression. In the event of an error, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. - +exit with the appropriate +.BR sysexits.h (3) +error code. +.\" .SH BUGS +.\" +-egl, \(lqequal to or less than or greater than\(rq, exits 0 no matter what for +valid program usage and may be abused to function as an integer validator. Use +.BR str (1) +instead. +.\" +.SH CAVEATS +.\" +There are multiple ways to express compound comparisons; \(lqless than or equal +to\(rq can be -le or -el, for example. -There are multiple ways to express compound comparisons; “less than or equal -to” can be -le or -el, for example. - -The inequality comparison is -gl or -lg for “less than or greater than”; this -is elegant but unintuitive. - --egl, “equal to or less than or greater than”, exits 0 no matter what for valid -program usage and may be abused to function as an integer validator. -Use str(1) instead. - +The inequality comparison is -gl or -lg for \(lqless than or greater than\(rq; +this is elegant but unintuitive. +.\" .SH RATIONALE - +.\" The traditional tool for integer comparisons in POSIX and other Unix shells has -been test(1). This tool also handles string comparisons and file scrutiny. -These parts of its functionality have been broken out into multiple utilities. - -This program’s functionality may be performed on a POSIX-compliant system with -test(1p). +been +.BR test (1). +This tool also handles string 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 +with +.BR test (1p). +.\" .SH AUTHOR - -Written by DTB . - +.\" +Written by DTB +.MT trinity@trinity.moe +.ME . +.\" .SH COPYRIGHT - -Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later +.\" +Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -strcmp(1), scrut(1), str(1), test(1p) +.BR scrut (1), +.BR strcmp (1), +.BR str (1), +.BR test (1p) diff --git a/docs/mm.1 b/docs/mm.1 index 5315c8c..72ce9a1 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -2,62 +2,41 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH mm 1 - .SH NAME - mm \(en middleman - .SH SYNOPSIS - +.\" mm .RB ( -aenu ) .RB ( -i .RB [ input ]) .RB ( -o .RB [ output ]) - +.\" .SH DESCRIPTION - +.\" Catenate input files and write them to the start of each output file or stream. - +.\" .SH OPTIONS - -.B -a -.RS +.\" +.IP -a Opens subsequent outputs for appending rather than updating. -.RE - -.B -e -.RS +.IP -e Use the standard error as an output. -.RE - -.B -i -.RS +.IP -i Opens a path as an input. Without any inputs specified mm will use the standard input. The standard input shall be used as an input if one or more of the input files is “-”. -.RE - -.B -o -.RS +.IP -o Opens a path as an output. Without any outputs specified mm will use the standard output. The standard output shall be used as an output if one or more of the output files is “-”. - -.RE - -.B -u -.RS +.IP -u Ensures neither input or output will be buffered. -.RE - -.B -n -.RS +.IP -n Causes SIGINT signals to be ignored. -.RE .SH DIAGNOSTICS @@ -84,5 +63,7 @@ Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .SH SEE ALSO - -cat(1p), dd(1), dj(1), tee(1p) +.BR cat (1p), +.BR dd (1), +.BR dj (1), +.BR tee (1p) diff --git a/docs/npc.1 b/docs/npc.1 index f3b7d0c..a75db5e 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -3,20 +3,18 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - -.TH npc 1 - +.\" +.TH NPC 1 .SH NAME - npc \(en show non-printing characters - +.\" .SH SYNOPSIS - +.\" npc .RB ( -et ) - +.\" .SH DESCRIPTION - +.\" Print normally non-printing characters. The program reads from standard input and writes to standard output, replacing @@ -26,41 +24,43 @@ character replaced (e.g. control-X becomes '^X'). The delete character (0x7F) becomes '^?'. Characters with the high bit set (>127) are printed as 'M-' followed by the graphical representation for the same character without the high bit set. - +.\" .SH USAGE - -.B -e -.RS +.\" +.IP -e Prints a currency sign ('$') before each line ending. -.RE - -.B -t -.RS +.IP -t Prints tab characters as '^I' rather than a literal horizontal tab. -.RE - +.\" .SH DIAGNOSTICS - +.\" In the event of an error, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. - +exit with the appropriate +.BR sysexits.h (3) +error code. +.\" .SH BUGS - +.\" 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 -using a standard tool. A popular extension to cat(1p), the +using a standard tool. A popular extension to +.BR cat (1p), +the .B -v option, is the bandage solution GNU and other software suites use. - +.\" This functionality is a separate tool because its usefulness extends beyond that -of cat(1p). - +of +.BR cat (1p). +.\" .SH AUTHOR -Written by DTB . +Written by DTB +.MT trinity@trinity.moe +.ME . .SH COPYRIGHT @@ -69,7 +69,8 @@ Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later .SH SEE ALSO -cat(1p), cat-v(1) +.BR cat (1p), +.BR cat-v (1) .I UNIX Style, or cat -v Considered Harmful by Rob Pike diff --git a/docs/rpn.1 b/docs/rpn.1 index 0b6b264..53a8a9f 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -3,20 +3,19 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH rpn 1 - .SH NAME - rpn \(en reverse polish notation evaluation - +.\" .SH SYNOPSIS - +.\" rpn -.RB [numbers...]\ [operators...] - +.RB [ numbers... ] +.RB [ operators... ] +.\" .SH DESCRIPTION - +.\" Evaluate reverse polish notation. The program evaluates reverse polish notation expressions either read from the @@ -28,48 +27,58 @@ standard output. Any further specified numbers will be placed at the end of the stack. For information on for reverse polish notation syntax, see rpn(7). - +.\" .SH STANDARD INPUT - -If arguments are passed , they are interpreted as an expression to be evaluated. -Otherwise, it reads whitespace-delimited numbers and operations from the -standard input. - +.\" +If arguments are passed, they are interpreted as an expression to be +evaluated. Otherwise, it reads whitespace-delimited numbers and operations from +the standard input. +.\" .SH DIAGNOSTICS - +.\" In the event of a syntax error, the program will print an In the event of an error, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. - +exit with the appropriate +.BR sysexits.h(3) +error code. +.\" .SH CAVEATS - +.\" Due to precision constraints and the way floats are represented in accordance -with the IEEE Standard for Floating Point Arithmetic (IEEE 754), floating-point -arithmetic has rounding errors. This is somewhat curbed by using the -machine epsilon as provided by the Rust standard library to which to round +with the IEEE Standard for Floating Point Arithmetic (\fIIEEE 754\fP), +floating-point arithmetic has rounding errors. This is somewhat curbed by using +the machine epsilon as provided by the Rust standard library to which to round numbers. Because of this, variation is expected in the number of decimal places the program can handle based on the platform and hardware of any given machine. - +.\" .SH RATIONALE - -An infix notation calculation utility, bc(1p), is included in the POSIX -standard, but does not accept expressions as arguments; in scripts, any -predefined, non-interactive input must be piped into the program. A dc(1) -pre-dates the standardized bc(1p), the latter originally being a preprocessor -for the former, and was included in UNIX v2 onward. While it implements reverse -polish notation, it still suffers from being unable to accept an expression as -an argument. - +.\" +An infix notation calculation utility, +.BR bc (1p), +is included in the POSIX 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) +pre-dates the standardized +.BR bc (1p), +the latter originally being a preprocessor for the former, and was included in +UNIX v2 onward. While it implements reverse polish notation, it still suffers +from being unable to accept an expression as an argument. +.\" .SH AUTHOR - -Written by Emma Tebibyte . - +.\" +Written by Emma Tebibyte +.MT emma@tebibyte.media +.ME . +.\" .SH COPYRIGHT - +.\" Copyright (c) 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -bc(1p), dc(1), rpn(7), IEEE 754 +.BR bc (1p), +.BR dc (1), +.BR rpn(7), +.I IEEE 754 diff --git a/docs/scrut.1 b/docs/scrut.1 index 4c0b75b..e6973ad 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -3,122 +3,86 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH scrut 1 - .SH NAME - scrut \(en scrutinize file properties - .SH SYNOPSIS - +.\" scrut .RB ( -bcdefgkprsuwxLS ) .RB [ file... ] - +.\" .SH DESCRIPTION - +.\" Determine if files comply with requirements. - +.\" .SH OPTIONS - -.B -L -.RS +.\" +.IP -L Requires the given files to exist and be symbolic links. -.RE - -.B -S -.RS +.IP -S Requires the given files to exist and be sockets. -.RE - -.B -b -.RS +.IP -b Requires the given files to exist and be block special files. -.RE - -.B -c -.RS +.IP -c Requires the given files to exist and be character special files. -.RE - -.B -d -.RS +.IP -d Requires the given files to exist and be directories. -.RE - -.B -e -.RS +.IP -e Requires the given files to exist, and is redundant to any other option. -.RE - -.B -e -.RS +.IP -e Requires the given files to exist and be regular files. -.RE - -.B -g -.RS +.IP -g Requires the given files to exist and have their set group ID flags set. -.RE - -.B -k -.RS +.IP -k Requires the given files to exist and have their sticky bit set. -.RE - -.B -p -.RS +.IP -p Requires the given files to exist and be named pipes. -.RE - -.B -r -.RS +.IP -r Requires the given files to exist and be readable. -.RE - -.B -u -.RS +.IP -u Requires the given files to exist and have their set user ID flags set. -.RE - -.B -w -.RS +.IP -w Requires the given files to exist and be writable. -.RE - -.B -x -.RS +.IP -x Requires the given files to exist and be executable. -.RE - -.SH EXIT STATUS - +.\" +.SH DIAGNOSTICS +.\" If the given files comply with the specified requirements, the program will exit successfully. If not, it exits unsuccessfully. When invoked incorrectly, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. - -.SH STANDARDS - -The test(1p) utility contains functionality that was broken out into separate -programs. Thus, the scope of this program is narrower than it. Notably, the +exit with the appropriate +.BR sysexits.h (3) +error code. +.\" +.SH RATIONALE +.\" +The +.BR test (1p) +utility contains functionality that was broken out into separate programs. Thus, +the scope of this program is narrower than it. Notably, the .B -h option is now invalid and therefore shows usage information instead of being an alias to the modern .B -L option. - +.\" .SH AUTHOR - -Written by DTB . - +.\" +Written by DTB +.MT trinity@trinity.moe +.ME . +.\" .SH COPYRIGHT -Copyright © 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .SH SEE ALSO -access(3p), lstat(3p), test(1p) +.BR access (3p), +.BR lstat (3p), +.BR test (1p) diff --git a/docs/str.1 b/docs/str.1 index ef86861..641a75f 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -3,28 +3,27 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH STR 1 - .SH NAME - str \(en test the character types of string arguments - +.\" .SH SYNOPSIS - +.\" str .RB [ type ] .RB [ string... ] - +.\" .SH DESCRIPTION - +.\" Test string arguments. The tests in this program are equivalent to the functions with the same names in -ctype.h(0p) and are the methods by which string arguments are tested. - +.BR ctype.h (0p) +and are the methods by which string arguments are tested. +.\" .SH DIAGNOSTICS - +.\" If all tests pass, the program will exit with an exit code of 0. If any of the tests fail, the program will exit unsuccessfully with an error code of 1. @@ -33,23 +32,26 @@ tests. When invoked incorrectly, a debug message will be printed and the program will exit with the appropriate sysexits.h(3) error code. - -.SH BUGS - +.\" +.SH CAVEATS +.\" There’s no way of knowing which argument failed the test without re-testing arguments individually. If a character in a string isn't valid ASCII str will exit unsuccessfully. - +.\" .SH AUTHOR - -Written by DTB . - +.\" +Written by DTB +.MT trinity@trinity.moe +.ME . +.\" .SH COPYRIGHT - +.\" Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -ctype(3p), strcmp(1), ascii(7) +.BR ctype (3p), +.BR strcmp(1), +.BR ascii(7) diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 48681c6..1cc03dd 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -3,61 +3,63 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH STRCMP 1 - .SH NAME - strcmp \(en compare strings - +.\" .SH SYNOPSIS - +.\" strcmp .RM [ string ] .RB [ strings... ] - +.\" .SH DESCRIPTION - +.\" Check whether string arguments are the same. - +.\" .SH DIAGNOSTICS - +.\" The program will exit successfully if the strings are identical. Otherwise, it exits with the value 1 if an earlier string has a greater byte value than a -later string (e.g. -.R strcmp b a -) -and 255 if an earlier string has a lesser byte value (e.g. -.R strcmp a b -). +later string (e.g. strcmp b a) and 255 if an earlier string has a lesser byte +value (e.g. strcmp a b). When invoked incorrectly, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. - -.SH UNICODE - +exit with the appropriate +.BR sysexits.h (3) +error code. +.\" +.SH CAVEATS +.\" The program will exit unsuccessfully if the given strings are not identical; therefore, Unicode strings may need to be normalized if the intent is to check visual similarity and not byte similarity. - +.\" .SH RATIONALE - +.\" The traditional tool for string comparisons in POSIX and other Unix shells has -been test(1). This tool also handles integer comparisons and file scrutiny. -These parts of its functionality have been broken out into multiple utilities. +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’s functionality may be performed on a POSIX-compliant system with -test(1p). - +.BR test (1p). +.\" .SH AUTHOR - -Written by DTB . - +.\" +Written by DTB +.MT trinity@trinity.moe +.ME . +.\" .SH COPYRIGHT - +.\" Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -strcmp(3), intcmp(1), scrut(1), test(1p) +.BR strcmp (3), +.BR intcmp (1), +.BR scrut (1), +.BR test (1p) diff --git a/docs/swab.1 b/docs/swab.1 index f7e10b0..078dd54 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -3,43 +3,36 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - -.TH swab 1 - +.\" +.TH SWAB 1 .SH NAME - swab \(en swap bytes - +.\" .SH SYNOPSIS - +.\" swab .RB ( -f ) .RB ( -w .R [ .B word size .R ]) - +.\" .SH USAGE - +.\" Swap the latter and former halves of a block of bytes. - +.\" .SH OPTIONS - -.B -f -.RS +.\" +.IP -f Ignore system call interruptions. -.RE - -.B -w -.RS +.IP -w Configures the word size; that is, the size in bytes of the block size on which to operate. By default the word size is 2. The word size must be cleanly divisible by 2, otherwise the block of bytes being processed can't be halved. -.RE - +.\" .SH EXAMPLES - +.\" The following sh(1p) line: .RS @@ -51,27 +44,24 @@ Produces the following output: .RS .R ehll oowlr!d .RE - +.\" .SH DIAGNOSTICS - +.\" In the event of an error, a debug message will be printed and the program will exit with the appropriate sysexits.h(3) error code. - +.\" .SH RATIONALE - -This program was modeled and named after the -.R conv=swab -functionality specified in the dd(1p) utility. It additionally allows the word -size to be configured. +.\" +This program was modeled and named after the conv=swab functionality specified +in the dd(1p) utility. It additionally allows the word size to be configured. This functionality is useful for fixing the endianness of binary files produced on other machines. - +.\" .SH COPYRIGHT - +.\" Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - -dd(1p) +.BR dd (1p) diff --git a/docs/true.1 b/docs/true.1 index 9b02fdd..1025c21 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -3,32 +3,34 @@ .\" .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . - +.\" .TH TRUE 1 - .SH NAME - true \(en do nothing, successfully - +.\" .SH DESCRIPTION - +.\" Do nothing regardless of operands or standard input. An exit code of 0 will always be returned. - +.\" .SH RATIONALE - -In POSIX.1-2017, true(1p) exists for the construction of control flow and loops -based on a success. This implementation functions as described in that standard. - +.\" +In \fIPOSIX.1-2017\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. +.\" .SH AUTHOR - -Written by Emma Tebibyte . - +.\" +Written by Emma Tebibyte +.MT emma@tebibyte.media +.ME . +.\" .SH COPYRIGHT - +.\" This work is marked with CC0 1.0. To see a copy of this license, visit . - +.\" .SH SEE ALSO - -false(1p) +.BR false (1p), +.BR true (1p) From 2dd6c0ded7a65fee58a8fbff5f62891d5484b778 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 19:05:30 -0600 Subject: [PATCH 079/134] fop(1): adds the ability to use any string as a delimiter --- src/fop.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index b829602..d28a7b0 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -32,18 +32,12 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); - let mut d = '␞'; + let mut d = "␞".to_owned(); let mut arg_parser = Parser::new(&argv, "d:"); while let Some(opt) = arg_parser.next() { match opt { - Ok(Opt('d', Some(arg))) => { - let arg_char = arg.chars().collect::>(); - if arg_char.len() > 1 { - eprintln!("{}: {}: Not a character.", argv[0], arg); - exit(EX_USAGE); - } else { d = arg_char[0]; } - }, + Ok(Opt('d', Some(arg))) => d = arg, _ => {}, }; } @@ -63,7 +57,7 @@ fn main() { let mut buf = String::new(); let _ = stdin().read_to_string(&mut buf); - let mut fields = buf.split(d).collect::>(); + let mut fields = buf.split(&d).collect::>(); let opts = argv .iter() From 24b235e7c1737a5e01c5390dcac3052e3c64d760 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 19:15:23 -0600 Subject: [PATCH 080/134] README: updated to make current --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index accfc7e..d7a79f6 100644 --- a/README +++ b/README @@ -20,9 +20,9 @@ See docs/ for more on the specific utilities currently implemented. Building The coreutils require a POSIX-compliant environment to compile, including a C -compiler and preprocessor (cc(1) and cpp(1) by default) with the -idirafter -flag, a Rust compiler (rustc(1) by default), bindgen(1), and a POSIX-compliant -make(1) utility. +compiler and preprocessor (cc(1) and cpp(1) by default), an edition 2023 Rust +compiler (rustc(1) by default), bindgen(1), and a POSIX-compliant make(1) +utility. To build and install: From 642774bccf76b7025005c0d34f1f6b0b2d22b275 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 19:21:56 -0600 Subject: [PATCH 081/134] src: removed erroneous file --- src/test.rs | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/test.rs diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index 4a602b1..0000000 --- a/src/test.rs +++ /dev/null @@ -1,10 +0,0 @@ -extern crate strerror; - -use strerror::raw_message; - -fn main() { - stdout.write_all(b"meow\n").unwrap_or_else(|e| { - eprintln!("{}", raw_message(e)); - std::process::exit(1); - }); -} From d6fb08019eb4a1d80b6160f02678afd67567ebc2 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 2 Jun 2024 23:14:40 -0600 Subject: [PATCH 082/134] CONDUCT: initial commit --- CONDUCT | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING | 2 ++ 2 files changed, 82 insertions(+) create mode 100644 CONDUCT diff --git a/CONDUCT b/CONDUCT new file mode 100644 index 0000000..0585d15 --- /dev/null +++ b/CONDUCT @@ -0,0 +1,80 @@ +Code of Conduct + +This Code of Conduct is derived from the 10 Pāramitās of Theravadin Buddhism. +You can read more about them in Ṭhānissaro Bhikkhu’s Ten Perfections: A Study +Guide [0]. + +1. Generosity (Dāna) + +Give contributions freely and willingly under the terms of the GNU Affero +General Public License, version 3 or later, or a compatible license. + +2. Ethics (Sīla) + +Do not use nonfree code or uncredited code in contributions. Do not take credit +for others’ contributions. Make sure to utilize the copyright header and license +notice on source files to credit yourself and others for their work. + +3. Renunciation (Nekkhamma) + +Stay committed to the principles of simplicity and interoperability embodied by +the project. Keep your personal will and desire out of the project, for it can +only prove harmful to its success. + +4. Wisdom (Pañña) + +Look to established sources for standards, best practices, and important +implementation details when setting new precedence. Follow the existing +precedence where it applies. + +5. Energy (Viriya) + +Focus on the currently-open, currently-assigned, and currently-in-progress +issues, pull requests, and other endeavors in order to keep yourself and others +from being overwhelmed with responsibility, either from your zeal or your +negligence. + +If you notice an issue, open an issue as soon as you can. If you see a neglected +branch, open a pull request or comment on an existing one, if applicable. Be +diligent in your commitment to making this project work. + +6. Patience (Khanti) + +Be patient with maintainers and other contributors. We all have our own lives +going on and may need significant time to get to things. + +7. Truthfulness (Sacca) + +Communicate honestly and openly. Do not embellish facts to get your way. Make +sure to let maintainers know about any issues along the way and keep ample +communication channels open. + +8. Determination (Adhiṭṭhāna) + +Stay focused on long-term objectives and cultivate attainment to that +achievement by utilizing to the fullest extent possible the tools available to +you for managing the workload. + +9. Loving-Kindness (Mettā) + +Treat everyone with respect, even if they treat you poorly. This does not mean +you have to put up with abuse, but make sure to respond with kindness and with +love in your heart. Support and uplift maintainers and other contributors with +your words and actions. + +Do not use angry or hateful language toward contributors, such as demeaning +phrases and slurs. Make sure that if you do not know the pronouns of a +contributor to ask for them and, in the meantime, use gender-neutral they/them +or equivalent pronouns. + +10. Equanimity (Upekkhā) + +Keep a balanced perspective on all suggestions and contributions and make +judgements not from a place of ego and personal preference but on their +usefulness and suitability to the project. Make sure to keep an eye on the +bigger picture as implementing individual features may seem intuitive at first +but scale poorly in practical use. Keep a level head about your own work: it is +not shameful to make a mistake in this vein, and fixing it usually leads to +more insight. + +[0] diff --git a/CONTRIBUTING b/CONTRIBUTING index d7fdc8e..74e821e 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1,3 +1,5 @@ +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 From c32c554e03f8f7fdd62bbf981bbf70e3fe318f71 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 3 Jun 2024 23:07:19 -0600 Subject: [PATCH 083/134] docs: removed unnecessary comments --- docs/dj.1 | 19 +++++++++---------- docs/false.1 | 9 ++++----- docs/fop.1 | 15 +++++++-------- docs/hru.1 | 19 +++++++++---------- docs/intcmp.1 | 17 ++++++++++------- docs/mm.1 | 17 +++++++++-------- docs/npc.1 | 19 +++++++++---------- docs/rpn.1 | 16 ++++++++-------- docs/scrut.1 | 15 +++++++-------- docs/str.1 | 12 ++++++------ docs/strcmp.1 | 14 +++++++------- docs/swab.1 | 14 +++++++------- docs/true.1 | 8 ++++---- 13 files changed, 96 insertions(+), 98 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index df660fa..21f0e1d 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -9,7 +9,7 @@ dj \(en disk jockey .\" .SH SYNOPSIS -.\" + dj .RB ( -AdHnq ) .RB ( -a @@ -44,7 +44,7 @@ dj .R ]) .\" .SH OPTIONS -.\" + .IP \fB-i\fP Takes a file path as an argument and opens it for use as an input. .IP \fB-b\fP @@ -87,18 +87,18 @@ Retries failed reads once more before exiting. Suppresses error messages which print when a read or write is partial or empty. Each invocation decrements the debug level of the program. .SH STANDARD INPUT -.\" + The standard input shall be used as an input if no inputs are specified or if one or more of the input files is \(lq-\(rq. .\" .SH DIAGNOSTICS -.\" + On a partial or empty read, a diagnostic message is printed (unless the .B -q option is specified) and the program exits (unless the .B -n option is specified). -.\" + By default, statistics are printed for input and output to the standard error in the following format: @@ -139,7 +139,7 @@ diagnostic message is printed and the program exits with the appropriate sysexits.h(3) status. .\" .SH BUGS -.\" + If .B -n is specified along with the @@ -152,7 +152,7 @@ or options are used, this could make data written nonsensical. .\" .SH CAVEATS -.\" + Existing files are not truncated on ouput and are instead overwritten. Many lowercase options have capitalized variants and vice-versa which can be @@ -160,7 +160,7 @@ confusing. Capitalized options tend to affect output or are more intense versions of lowercase options. .\" .SH RATIONALE -.\" + This program was based on the dd(1p) utility as specified in POSIX. While character conversion may have been the original intent of dd(1p), it is irrelevant to its modern use. Because of this, this program eschews character @@ -169,10 +169,9 @@ in bytes rather than in blocks, allowing arbitrary bytes as padding, and printing in a format that\(cqs easy for machines to parse. .\" .SH COPYRIGHT -.\" + Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO -.\" .BR dd (1p) diff --git a/docs/false.1 b/docs/false.1 index 5719899..91bd286 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -9,28 +9,27 @@ false \(en do nothing, unsuccessfully .\" .SH DESCRIPTION -.\" + Do nothing regardless of operands or standard input. An exit code of 1 will always be returned. .\" .SH RATIONALE -.\" + In POSIX.1-2017, .BR false (1p) exists for the construction of control flow and loops based on a failure. This implementation functions as described in that standard. .\" .SH AUTHOR -.\" + Written by Emma Tebibyte .MT emma@tebibyte.media .ME . .\" .SH COPYRIGHT -.\" + This work is marked with CC0 1.0. To see a copy of this license, visit . .\" .SH SEE ALSO -.\" .BR true (1p) diff --git a/docs/fop.1 b/docs/fop.1 index 75a956d..29ba7ea 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -9,7 +9,7 @@ fop \(en field operator .\" .SH SYNOPSIS -.\" + fop .RB ( -d ) .RB [ delimiter ] @@ -17,24 +17,24 @@ fop .RB program... .\" .SH DESCRIPTION -.\" + Performs operations on specified fields in input data. .\" .SH OPTIONS -.\" + .IP \fB-d\fP Sets a delimiter by which the input data will be split into fields. The default is an ASCII record separator (␞). .SH STANDARD INPUT -.\" + Data will be read from the standard input. .\" .SH CAVEATS -.\" + Field indices are zero-indexed, which may be unexpected behavior for some users. .\" .SH RATIONALE -.\" + With the assumption that tools will output data separated with ASCII field separators, there is a need for the ability to modify select fields in this data easily and quickly. @@ -51,10 +51,9 @@ but there was no easy way to modify the field in the ouput of without creating a new tool. .\" .SH COPYRIGHT -.\" + Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO -.\" .BR sed (1p) diff --git a/docs/hru.1 b/docs/hru.1 index f87be16..984222a 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -8,28 +8,28 @@ hru \(en human readable units .\" .SH SYNOPSIS -.\" + hru .\" .SH DESCRIPTION -.\" + Convert counts to higher units. -.\" + The program will read byte counts in the form of whole numbers from the standard input and write to the standard output the same number converted to a higher unit of data as defined by the International System of Units. -.\" + The program will convert the byte count to the highest unit possible where the value is greater than one. .\" .SH DIAGNOSTICS -.\" + If encountering non-integer characters in the standard input, the program will exit with the appropriate error code as defined by sysexits.h(3) and print an error message. .\" .SH RATIONALE -.\" + The GNU project\(cqs ls(1) implementation contains a human-readable option (-h) that, when specified, makes the tool print size information in a format more immediately readable. This functionality is useful not only in the context of @@ -38,24 +38,23 @@ functionality in GNU\(cqs ls(1) can be emulated with fop(1) combined with this program. .\" .SH STANDARDS -.\" + The standard unit prefixes as specified by the Bureau International des Poids et Mesures (BIPM) in the ninth edition of The International System of Units (SI) are utilized for the ouput of conversions. .\" .SH AUTHOR -.\" + Written by Emma Tebibyte .MT emma@tebibyte.media .ME . .\" .SH COPYRIGHT -.\" + Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO -.\" GNU .BR ls (1), The International System of Units (SI) 9th Edition diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 79902b9..ed88038 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -9,22 +9,25 @@ intcmp \(en compare integers .\" .SH SYNOPSIS -.\" + intcmp .RB ( -egl ) .RB [ integer ] .RB [ integer... ] .SH DESCRIPTION Compare integers to each other. +.\" .SH OPTIONS + .IP \fB-e\fP Permits given integers to be equal to each other. .IP \fB-g\fP Permits a given integer to be greater than the following integer. .IP \fB-l\fP Permits a given integer to be less than the following integer. -.SH EXAMPLES .\" +.SH EXAMPLES + It may help to think of the -e, -g, and -l options as equivalent to the infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq operators respectively, with each option putting its symbol between every given integer. The following @@ -35,7 +38,7 @@ example is equivalent to evaluating \(lq1 < 2 < 3\(rq: .RE .\" .SH DIAGNOSTICS -.\" + The program will exit with a status code of 0 for a valid expression and with a code of 1 for an invalid expression. @@ -45,14 +48,14 @@ exit with the appropriate error code. .\" .SH BUGS -.\" + -egl, \(lqequal to or less than or greater than\(rq, exits 0 no matter what for valid program usage and may be abused to function as an integer validator. Use .BR str (1) instead. .\" .SH CAVEATS -.\" + There are multiple ways to express compound comparisons; \(lqless than or equal to\(rq can be -le or -el, for example. @@ -60,7 +63,7 @@ The inequality comparison is -gl or -lg for \(lqless than or greater than\(rq; this is elegant but unintuitive. .\" .SH RATIONALE -.\" + The traditional tool for integer comparisons in POSIX and other Unix shells has been .BR test (1). @@ -72,7 +75,7 @@ with .BR test (1p). .\" .SH AUTHOR -.\" + Written by DTB .MT trinity@trinity.moe .ME . diff --git a/docs/mm.1 b/docs/mm.1 index 72ce9a1..c971c00 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -6,8 +6,9 @@ .TH mm 1 .SH NAME mm \(en middleman -.SH SYNOPSIS .\" +.SH SYNOPSIS + mm .RB ( -aenu ) .RB ( -i @@ -16,11 +17,11 @@ mm .RB [ output ]) .\" .SH DESCRIPTION -.\" + Catenate input files and write them to the start of each output file or stream. .\" .SH OPTIONS -.\" + .IP -a Opens subsequent outputs for appending rather than updating. .IP -e @@ -37,7 +38,7 @@ of the output files is “-”. Ensures neither input or output will be buffered. .IP -n Causes SIGINT signals to be ignored. - +.\" .SH DIAGNOSTICS If an output can no longer be written mm prints a diagnostic message, ceases @@ -46,22 +47,22 @@ continues, eventually exiting unsuccessfully. When an error is encountered, diagnostic message is printed and the program exits with the appropriate sysexits.h(3) status. - +.\" .SH CAVEATS Existing files are not truncated on ouput and are instead overwritten. - +.\" .SH RATIONALE The cat(1p) and tee(1p) programs specified in POSIX together provide similar functionality. The separation of the two sets of functionality into separate APIs seemed unncessary. - +.\" .SH COPYRIGHT Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO .BR cat (1p), .BR dd (1), diff --git a/docs/npc.1 b/docs/npc.1 index a75db5e..64f3406 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -9,12 +9,12 @@ npc \(en show non-printing characters .\" .SH SYNOPSIS -.\" + npc .RB ( -et ) .\" .SH DESCRIPTION -.\" + Print normally non-printing characters. The program reads from standard input and writes to standard output, replacing @@ -26,32 +26,32 @@ followed by the graphical representation for the same character without the high bit set. .\" .SH USAGE -.\" + .IP -e Prints a currency sign ('$') before each line ending. .IP -t Prints tab characters as '^I' rather than a literal horizontal tab. .\" .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. .\" .SH BUGS -.\" + 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 using a standard tool. A popular extension to .BR cat (1p), the .B -v option, is the bandage solution GNU and other software suites use. -.\" + This functionality is a separate tool because its usefulness extends beyond that of .BR cat (1p). @@ -61,14 +61,13 @@ of Written by DTB .MT trinity@trinity.moe .ME . - +.\" .SH COPYRIGHT Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - .BR cat (1p), .BR cat-v (1) diff --git a/docs/rpn.1 b/docs/rpn.1 index 53a8a9f..c791613 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -9,13 +9,13 @@ rpn \(en reverse polish notation evaluation .\" .SH SYNOPSIS -.\" + rpn .RB [ numbers... ] .RB [ operators... ] .\" .SH DESCRIPTION -.\" + Evaluate reverse polish notation. The program evaluates reverse polish notation expressions either read from the @@ -29,13 +29,13 @@ stack. For information on for reverse polish notation syntax, see rpn(7). .\" .SH STANDARD INPUT -.\" + If arguments are passed, they are interpreted as an expression to be evaluated. Otherwise, it reads whitespace-delimited numbers and operations from the standard input. .\" .SH DIAGNOSTICS -.\" + In the event of a syntax error, the program will print an In the event of an error, a debug message will be printed and the program will @@ -44,7 +44,7 @@ exit with the appropriate error code. .\" .SH CAVEATS -.\" + Due to precision constraints and the way floats are represented in accordance with the IEEE Standard for Floating Point Arithmetic (\fIIEEE 754\fP), floating-point arithmetic has rounding errors. This is somewhat curbed by using @@ -53,7 +53,7 @@ numbers. Because of this, variation is expected in the number of decimal places the program can handle based on the platform and hardware of any given machine. .\" .SH RATIONALE -.\" + An infix notation calculation utility, .BR bc (1p), is included in the POSIX standard, but does not accept expressions as arguments; @@ -67,13 +67,13 @@ UNIX v2 onward. While it implements reverse polish notation, it still suffers from being unable to accept an expression as an argument. .\" .SH AUTHOR -.\" + Written by Emma Tebibyte .MT emma@tebibyte.media .ME . .\" .SH COPYRIGHT -.\" + Copyright (c) 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later . .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index e6973ad..52d96ed 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -8,17 +8,17 @@ .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS -.\" + scrut .RB ( -bcdefgkprsuwxLS ) .RB [ file... ] .\" .SH DESCRIPTION -.\" + Determine if files comply with requirements. .\" .SH OPTIONS -.\" + .IP -L Requires the given files to exist and be symbolic links. .IP -S @@ -49,7 +49,7 @@ Requires the given files to exist and be writable. Requires the given files to exist and be executable. .\" .SH DIAGNOSTICS -.\" + If the given files comply with the specified requirements, the program will exit successfully. If not, it exits unsuccessfully. @@ -59,7 +59,7 @@ exit with the appropriate error code. .\" .SH RATIONALE -.\" + The .BR test (1p) utility contains functionality that was broken out into separate programs. Thus, @@ -71,7 +71,7 @@ alias to the modern option. .\" .SH AUTHOR -.\" + Written by DTB .MT trinity@trinity.moe .ME . @@ -80,9 +80,8 @@ Written by DTB Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . - +.\" .SH SEE ALSO - .BR access (3p), .BR lstat (3p), .BR test (1p) diff --git a/docs/str.1 b/docs/str.1 index 641a75f..d40eafa 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -9,13 +9,13 @@ str \(en test the character types of string arguments .\" .SH SYNOPSIS -.\" + str .RB [ type ] .RB [ string... ] .\" .SH DESCRIPTION -.\" + Test string arguments. The tests in this program are equivalent to the functions with the same names in @@ -23,7 +23,7 @@ The tests in this program are equivalent to the functions with the same names in and are the methods by which string arguments are tested. .\" .SH DIAGNOSTICS -.\" + If all tests pass, the program will exit with an exit code of 0. If any of the tests fail, the program will exit unsuccessfully with an error code of 1. @@ -34,20 +34,20 @@ When invoked incorrectly, a debug message will be printed and the program will exit with the appropriate sysexits.h(3) error code. .\" .SH CAVEATS -.\" + There’s no way of knowing which argument failed the test without re-testing arguments individually. If a character in a string isn't valid ASCII str will exit unsuccessfully. .\" .SH AUTHOR -.\" + Written by DTB .MT trinity@trinity.moe .ME . .\" .SH COPYRIGHT -.\" + Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 1cc03dd..768be0f 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -9,17 +9,17 @@ strcmp \(en compare strings .\" .SH SYNOPSIS -.\" + strcmp .RM [ string ] .RB [ strings... ] .\" .SH DESCRIPTION -.\" + Check whether string arguments are the same. .\" .SH DIAGNOSTICS -.\" + The program will exit successfully if the strings are identical. Otherwise, it exits with the value 1 if an earlier string has a greater byte value than a later string (e.g. strcmp b a) and 255 if an earlier string has a lesser byte @@ -31,13 +31,13 @@ exit with the appropriate error code. .\" .SH CAVEATS -.\" + The program will exit unsuccessfully if the given strings are not identical; therefore, Unicode strings may need to be normalized if the intent is to check visual similarity and not byte similarity. .\" .SH RATIONALE -.\" + The traditional tool for string comparisons in POSIX and other Unix shells has been .BR test (1). @@ -48,13 +48,13 @@ This program’s functionality may be performed on a POSIX-compliant system with .BR test (1p). .\" .SH AUTHOR -.\" + Written by DTB .MT trinity@trinity.moe .ME . .\" .SH COPYRIGHT -.\" + Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" diff --git a/docs/swab.1 b/docs/swab.1 index 078dd54..b1a0834 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -9,7 +9,7 @@ swab \(en swap bytes .\" .SH SYNOPSIS -.\" + swab .RB ( -f ) .RB ( -w @@ -18,11 +18,11 @@ swab .R ]) .\" .SH USAGE -.\" + Swap the latter and former halves of a block of bytes. .\" .SH OPTIONS -.\" + .IP -f Ignore system call interruptions. .IP -w @@ -32,7 +32,7 @@ cleanly divisible by 2, otherwise the block of bytes being processed can't be halved. .\" .SH EXAMPLES -.\" + The following sh(1p) line: .RS @@ -46,12 +46,12 @@ Produces the following output: .RE .\" .SH DIAGNOSTICS -.\" + In the event of an error, a debug message will be printed and the program will exit with the appropriate sysexits.h(3) error code. .\" .SH RATIONALE -.\" + This program was modeled and named after the conv=swab functionality specified in the dd(1p) utility. It additionally allows the word size to be configured. @@ -59,7 +59,7 @@ This functionality is useful for fixing the endianness of binary files produced on other machines. .\" .SH COPYRIGHT -.\" + Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" diff --git a/docs/true.1 b/docs/true.1 index 1025c21..ac2e222 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -9,25 +9,25 @@ true \(en do nothing, successfully .\" .SH DESCRIPTION -.\" + Do nothing regardless of operands or standard input. An exit code of 0 will always be returned. .\" .SH RATIONALE -.\" + In \fIPOSIX.1-2017\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. .\" .SH AUTHOR -.\" + Written by Emma Tebibyte .MT emma@tebibyte.media .ME . .\" .SH COPYRIGHT -.\" + This work is marked with CC0 1.0. To see a copy of this license, visit . .\" From e7ba74013b9cbaed29334cc540a607e95ad618b3 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 3 Jun 2024 23:21:00 -0600 Subject: [PATCH 084/134] dj.1: fixes man page reference formatting --- docs/dj.1 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 21f0e1d..ea73a75 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -161,12 +161,15 @@ versions of lowercase options. .\" .SH RATIONALE -This program was based on the dd(1p) utility as specified in POSIX. While -character conversion may have been the original intent of dd(1p), it is -irrelevant to its modern use. Because of this, this program eschews character -conversion and adds typical option formatting, allowing seeks to be specified -in bytes rather than in blocks, allowing arbitrary bytes as padding, and -printing in a format that\(cqs easy for machines to parse. +This program was based on the +.BR dd (1p) +utility as specified in POSIX. 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 +character conversion and adds typical option formatting, allowing seeks to be +specified in bytes rather than in blocks, allowing arbitrary bytes as padding, +and printing in a format that\(cqs easy for machines to parse. .\" .SH COPYRIGHT From beff2d98c672cf3696db6aff4b5a25d757cf7cdd Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 3 Jun 2024 23:45:26 -0600 Subject: [PATCH 085/134] mm.1: fixed manpage reference formatting --- docs/mm.1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index c971c00..ef0336a 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -46,7 +46,9 @@ writing to that particular output, and if there are more outputs specified, continues, eventually exiting unsuccessfully. When an error is encountered, diagnostic message is printed and the program -exits with the appropriate sysexits.h(3) status. +exits with the appropriate +.BR sysexits.h (3) +status. .\" .SH CAVEATS @@ -54,9 +56,13 @@ Existing files are not truncated on ouput and are instead overwritten. .\" .SH RATIONALE -The cat(1p) and tee(1p) programs specified in POSIX together provide similar -functionality. The separation of the two sets of functionality into separate -APIs seemed unncessary. +The +.BR cat (1p) +and +.BR tee (1p) +programs specified in POSIX together provide similar functionality. The +separation of the two sets of functionality into separate APIs seemed +unncessary. .\" .SH COPYRIGHT From fec61fee1b2009dd095d79be567a6a478a874519 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 3 Jun 2024 23:47:14 -0600 Subject: [PATCH 086/134] swab.1: fixes formatting --- docs/swab.1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/swab.1 b/docs/swab.1 index b1a0834..90b50b0 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -23,9 +23,9 @@ Swap the latter and former halves of a block of bytes. .\" .SH OPTIONS -.IP -f +.IP \fB-f\fP Ignore system call interruptions. -.IP -w +.IP \fB-w\fP Configures the word size; that is, the size in bytes of the block size on which to operate. By default the word size is 2. The word size must be cleanly divisible by 2, otherwise the block of bytes being processed can't be @@ -33,7 +33,9 @@ halved. .\" .SH EXAMPLES -The following sh(1p) line: +The following +.Br sh (1p) +line: .RS .R printf 'hello world!\n' | swab @@ -48,12 +50,16 @@ Produces the following output: .SH DIAGNOSTICS In the event of an error, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. +exit with the appropriate +.BR sysexits.h (3) +error code. .\" .SH RATIONALE This program was modeled and named after the conv=swab functionality specified -in the dd(1p) utility. It additionally allows the word size to be configured. +in the +.BR dd (1p) +utility. It additionally allows the word size to be configured. This functionality is useful for fixing the endianness of binary files produced on other machines. From 896b251434bc544fc548bff69b63593d2b214018 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 3 Jun 2024 23:52:28 -0600 Subject: [PATCH 087/134] hru.1: fixes formatting --- docs/hru.1 | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/hru.1 b/docs/hru.1 index 984222a..c3a5cdc 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -25,23 +25,30 @@ value is greater than one. .SH DIAGNOSTICS If encountering non-integer characters in the standard input, the program will -exit with the appropriate error code as defined by sysexits.h(3) and print an -error message. +exit with the appropriate error code as defined by +.BR sysexits.h (3) +and print an error message. .\" .SH RATIONALE -The GNU project\(cqs ls(1) implementation contains a human-readable option (-h) -that, when specified, makes the tool print size information in a format more -immediately readable. This functionality is useful not only in the context of -ls(1) so the decision was made to split it into a new tool. The original -functionality in GNU\(cqs ls(1) can be emulated with fop(1) combined with this -program. +The GNU project\(cqs +.BR ls (1) +implementation contains a human-readable option (\fB-h\fP) that, when specified, +makes the tool print size information in a format more immediately readable. +This functionality is useful not only in the context of +.BR ls (1) +so the decision was made to split it into a new tool. The original functionality +in GNU\(cqs +.BR ls (1) +can be emulated with +.BR fop (1) +combined with this program. .\" .SH STANDARDS The standard unit prefixes as specified by the Bureau International des Poids -et Mesures (BIPM) in the ninth edition of The International System of Units -(SI) are utilized for the ouput of conversions. +et Mesures (BIPM) in the ninth edition of The International System of Units (SI) +are utilized for the ouput of conversions. .\" .SH AUTHOR From a5a9c91cb6f18159e39c87143ece06a4ceb8d7df Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 14:28:19 -0600 Subject: [PATCH 088/134] getopt.rs(3): optind support --- src/getopt.rs | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index b146400..79879df 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -18,6 +18,21 @@ use std::ffi::{ c_int, c_char, CString, CStr }; + +/* binding to getopt(3p) */ +extern "C" { + static mut optarg: *mut c_char; + static mut _opterr: c_int; + static mut optind: c_int; + static mut optopt: c_int; + + fn getopt( + ___argc: c_int, + ___argv: *const *mut c_char, + __shortopts: *const c_char, + ) -> c_int; +} + pub struct Opt { pub arg: Option, pub ind: i32, @@ -50,7 +65,7 @@ impl GetOpt for Vec { let opts = CString::new(optstring).unwrap().into_raw(); let len = self.len() as c_int; - unsafe { // TODO: enable optind modification + unsafe { match getopt(len, argv_ptr, opts) { /* From getopt(3p): * @@ -103,16 +118,24 @@ impl GetOpt for Vec { } } } -/* binding to getopt(3p) */ -extern "C" { - static mut optarg: *mut c_char; - static mut _opterr: c_int; - static mut optind: c_int; - static mut optopt: c_int; - fn getopt( - ___argc: c_int, - ___argv: *const *mut c_char, - __shortopts: *const c_char, - ) -> c_int; -} +/* From getopt(3p): + * + * The variable optind is the index of the next element of the argv[] + * vector to be processed. It shall be initialized to 1 by the system, and + * getopt() shall update it when it finishes with each element of argv[]. + * If the application sets optind to zero before calling getopt(), the + * behavior is unspecified. When an element of argv[] contains multiple + * option characters, it is unspecified how getopt() determines which + * options have already been processed. + * + * This API can be utilized using unsafe blocks and dereferencing: + * + * use getopt::OPTIND; + * + * unsafe { while *OPTIND < 5 { + * println!("{}", *OPTIND); // 1..4 + * *OPTIND += 1; + * }} + */ +pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) }; From b7283d54fe42fe7d6ac3899c2e6ea1fea55552f6 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 15:07:11 -0600 Subject: [PATCH 089/134] getopt.rs(3): formatting & organization --- src/getopt.rs | 55 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index 79879df..0324f87 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -18,7 +18,6 @@ use std::ffi::{ c_int, c_char, CString, CStr }; - /* binding to getopt(3p) */ extern "C" { static mut optarg: *mut c_char; @@ -33,6 +32,27 @@ extern "C" { ) -> c_int; } +/* From getopt(3p): + * + * The variable optind is the index of the next element of the argv[] + * vector to be processed. It shall be initialized to 1 by the system, and + * getopt() shall update it when it finishes with each element of argv[]. + * If the application sets optind to zero before calling getopt(), the + * behavior is unspecified. When an element of argv[] contains multiple + * option characters, it is unspecified how getopt() determines which + * options have already been processed. + * + * This API can be utilized using unsafe blocks and dereferencing: + * + * use getopt::OPTIND; + * + * unsafe { while *OPTIND < 5 { + * println!("{}", *OPTIND); // 1..4 + * *OPTIND += 1; + * }} + */ +pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) }; + pub struct Opt { pub arg: Option, pub ind: i32, @@ -83,12 +103,12 @@ impl GetOpt for Vec { * * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ - 58 => { /* numerical ASCII value for ':' */ - Some(Err(OptError::MissingArg(optopt.to_string()))) - }, - 63 => { /* numerical ASCII value for '?' */ - Some(Err(OptError::UnknownOpt(optopt.to_string()))) - }, + 58 => { /* numerical ASCII value for ':' */ + Some(Err(OptError::MissingArg(optopt.to_string()))) + }, + 63 => { /* numerical ASCII value for '?' */ + Some(Err(OptError::UnknownOpt(optopt.to_string()))) + }, /* From getopt(3p): * * If, when getopt() is called: @@ -118,24 +138,3 @@ impl GetOpt for Vec { } } } - -/* From getopt(3p): - * - * The variable optind is the index of the next element of the argv[] - * vector to be processed. It shall be initialized to 1 by the system, and - * getopt() shall update it when it finishes with each element of argv[]. - * If the application sets optind to zero before calling getopt(), the - * behavior is unspecified. When an element of argv[] contains multiple - * option characters, it is unspecified how getopt() determines which - * options have already been processed. - * - * This API can be utilized using unsafe blocks and dereferencing: - * - * use getopt::OPTIND; - * - * unsafe { while *OPTIND < 5 { - * println!("{}", *OPTIND); // 1..4 - * *OPTIND += 1; - * }} - */ -pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) }; From f4cad598c467c07f2a7d3014e70093a85103eed6 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 16:11:33 -0600 Subject: [PATCH 090/134] docs: formatting --- docs/intcmp.1 | 2 +- docs/mm.1 | 18 +++++++++--------- docs/npc.1 | 7 +++---- docs/rpn.1 | 7 ++++--- docs/scrut.1 | 30 +++++++++++++++--------------- docs/str.1 | 11 +++++++---- docs/strcmp.1 | 20 +++++++++++++++----- docs/swab.1 | 6 +++--- 8 files changed, 57 insertions(+), 44 deletions(-) diff --git a/docs/intcmp.1 b/docs/intcmp.1 index ed88038..905d31d 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -32,7 +32,7 @@ It may help to think of the -e, -g, and -l options as equivalent to the infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq operators respectively, with each option putting its symbol between every given integer. The following example is equivalent to evaluating \(lq1 < 2 < 3\(rq: - +\" .RS .R intcmp -l 1 2 3 .RE diff --git a/docs/mm.1 b/docs/mm.1 index ef0336a..58bc26e 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -22,21 +22,21 @@ Catenate input files and write them to the start of each output file or stream. .\" .SH OPTIONS -.IP -a +.IP \fB-a\fP Opens subsequent outputs for appending rather than updating. -.IP -e +.IP \fB-e\fP Use the standard error as an output. -.IP -i +.IP \fB-i\fP Opens a path as an input. Without any inputs specified mm will use the standard input. The standard input shall be used as an input if one or more of -the input files is “-”. -.IP -o +the input files is \(lq-\(rq. +.IP \fB-o\fP Opens a path as an output. Without any outputs specified mm will use the standard output. The standard output shall be used as an output if one or more -of the output files is “-”. -.IP -u +of the output files is \(lq-\(rq. +.IP \fB-u\fP Ensures neither input or output will be buffered. -.IP -n +.IP \fB-n\fP Causes SIGINT signals to be ignored. .\" .SH DIAGNOSTICS @@ -66,7 +66,7 @@ unncessary. .\" .SH COPYRIGHT -Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO diff --git a/docs/npc.1 b/docs/npc.1 index 64f3406..e18e4ff 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -27,9 +27,9 @@ high bit set. .\" .SH USAGE -.IP -e +.IP \fB-e\fP Prints a currency sign ('$') before each line ending. -.IP -t +.IP \fB-t\fP Prints tab characters as '^I' rather than a literal horizontal tab. .\" .SH DIAGNOSTICS @@ -69,7 +69,6 @@ Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later .\" .SH SEE ALSO .BR cat (1p), -.BR cat-v (1) - +.BR cat-v (1), .I UNIX Style, or cat -v Considered Harmful by Rob Pike diff --git a/docs/rpn.1 b/docs/rpn.1 index c791613..8e87802 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -26,7 +26,8 @@ Upon evaluation, the program will print the resulting number on the stack to the standard output. Any further specified numbers will be placed at the end of the stack. -For information on for reverse polish notation syntax, see rpn(7). +For information on for reverse polish notation syntax, see +.BR rpn (7). .\" .SH STANDARD INPUT @@ -40,7 +41,7 @@ In the event of a syntax error, the program will print an In the event of an error, a debug message will be printed and the program will exit with the appropriate -.BR sysexits.h(3) +.BR sysexits.h (3) error code. .\" .SH CAVEATS @@ -80,5 +81,5 @@ Copyright (c) 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later .SH SEE ALSO .BR bc (1p), .BR dc (1), -.BR rpn(7), +.BR rpn (7), .I IEEE 754 diff --git a/docs/scrut.1 b/docs/scrut.1 index 52d96ed..22c77fb 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -10,7 +10,7 @@ scrut \(en scrutinize file properties .SH SYNOPSIS scrut -.RB ( -bcdefgkprsuwxLS ) +.RB ( -LSbcdefgkprsuwx ) .RB [ file... ] .\" .SH DESCRIPTION @@ -19,33 +19,33 @@ Determine if files comply with requirements. .\" .SH OPTIONS -.IP -L +.IP \fB-L\fB Requires the given files to exist and be symbolic links. -.IP -S +.IP \fB-S\fP Requires the given files to exist and be sockets. -.IP -b +.IP \fB-b\fP Requires the given files to exist and be block special files. -.IP -c +.IP \fB-c\fP Requires the given files to exist and be character special files. -.IP -d +.IP \fB-d\fP Requires the given files to exist and be directories. -.IP -e +.IP \fB-e\fP Requires the given files to exist, and is redundant to any other option. -.IP -e +.IP \fB-f\fP Requires the given files to exist and be regular files. -.IP -g +.IP \fB-g\fP Requires the given files to exist and have their set group ID flags set. -.IP -k +.IP \fB-k\fP Requires the given files to exist and have their sticky bit set. -.IP -p +.IP \fB-p\fP Requires the given files to exist and be named pipes. -.IP -r +.IP \fB-r\fP Requires the given files to exist and be readable. -.IP -u +.IP \fB-u\fP Requires the given files to exist and have their set user ID flags set. -.IP -w +.IP \fB-w\fP Requires the given files to exist and be writable. -.IP -x +.IP \fB-x\fP Requires the given files to exist and be executable. .\" .SH DIAGNOSTICS diff --git a/docs/str.1 b/docs/str.1 index d40eafa..87caabb 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -31,14 +31,17 @@ An empty string will cause an unsuccessful exit as none of its contents pass any tests. When invoked incorrectly, a debug message will be printed and the program will -exit with the appropriate sysexits.h(3) error code. +exit with the appropriate +.BR sysexits.h (3) +error code. .\" .SH CAVEATS -There’s no way of knowing which argument failed the test without re-testing +There\(cqs no way of knowing which argument failed the test without re-testing arguments individually. -If a character in a string isn't valid ASCII str will exit unsuccessfully. +If a character in a string isn\(cqt valid ASCII the program will exit +unsuccessfully. .\" .SH AUTHOR @@ -48,7 +51,7 @@ Written by DTB .\" .SH COPYRIGHT -Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 768be0f..84b661d 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -21,9 +21,19 @@ Check whether string arguments are the same. .SH DIAGNOSTICS The program will exit successfully if the strings are identical. Otherwise, it -exits with the value 1 if an earlier string has a greater byte value than a -later string (e.g. strcmp b a) and 255 if an earlier string has a lesser byte -value (e.g. strcmp a b). +will exit with an error code of 1 if a string passed has a lesser byte value +than one of the prior strings: + +.RS +.R strcmp b a +.RE + +and with an error code of 255 if it has a greater byte value than one of the +prior strings: + +.RS +.R strcmp a b +.RE When invoked incorrectly, a debug message will be printed and the program will exit with the appropriate @@ -44,7 +54,7 @@ been This tool also handles integer comparisons and file scrutiny. These parts of its functionality have been broken out into multiple utilities. -This program’s functionality may be performed on a POSIX-compliant system with +This program\(cqs functionality may be performed on a POSIX-compliant system with .BR test (1p). .\" .SH AUTHOR @@ -55,7 +65,7 @@ Written by DTB .\" .SH COPYRIGHT -Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO diff --git a/docs/swab.1 b/docs/swab.1 index 90b50b0..7197a0a 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -17,7 +17,7 @@ swab .B word size .R ]) .\" -.SH USAGE +.SH DESCRIPTION Swap the latter and former halves of a block of bytes. .\" @@ -28,7 +28,7 @@ Ignore system call interruptions. .IP \fB-w\fP Configures the word size; that is, the size in bytes of the block size on which to operate. By default the word size is 2. The word size must be -cleanly divisible by 2, otherwise the block of bytes being processed can't be +cleanly divisible by 2, otherwise the block of bytes being processed can\(cqt be halved. .\" .SH EXAMPLES @@ -66,7 +66,7 @@ on other machines. .\" .SH COPYRIGHT -Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later +Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later . .\" .SH SEE ALSO From 46c4be5c591f189598bbaaa23d8fc73947e4befd Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 16:21:25 -0600 Subject: [PATCH 091/134] CONDUCT: no llm contributions --- CONDUCT | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CONDUCT b/CONDUCT index 0585d15..4a26e37 100644 --- a/CONDUCT +++ b/CONDUCT @@ -11,9 +11,11 @@ General Public License, version 3 or later, or a compatible license. 2. Ethics (Sīla) -Do not use nonfree code or uncredited code in contributions. Do not take credit -for others’ contributions. Make sure to utilize the copyright header and license -notice on source files to credit yourself and others for their work. +Do not use nonfree code or uncredited code in contributions. Do not contribute +code of dubious origins, such as code generated in large part by large language +models [1]. Do not take credit for others’ contributions. Make sure to utilize +the copyright header and license notice on source files to credit yourself and +others for their work. 3. Renunciation (Nekkhamma) @@ -78,3 +80,4 @@ not shameful to make a mistake in this vein, and fixing it usually leads to more insight. [0] +[1] From 35ddc729fdc78334ab3656094ca0c6b81f32ca2d Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 19:15:22 -0600 Subject: [PATCH 092/134] getopt.rs(3): makes optind part of the Opt struct --- src/getopt.rs | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index 0324f87..62696e0 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -32,30 +32,9 @@ extern "C" { ) -> c_int; } -/* From getopt(3p): - * - * The variable optind is the index of the next element of the argv[] - * vector to be processed. It shall be initialized to 1 by the system, and - * getopt() shall update it when it finishes with each element of argv[]. - * If the application sets optind to zero before calling getopt(), the - * behavior is unspecified. When an element of argv[] contains multiple - * option characters, it is unspecified how getopt() determines which - * options have already been processed. - * - * This API can be utilized using unsafe blocks and dereferencing: - * - * use getopt::OPTIND; - * - * unsafe { while *OPTIND < 5 { - * println!("{}", *OPTIND); // 1..4 - * *OPTIND += 1; - * }} - */ -pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) }; - pub struct Opt { pub arg: Option, - pub ind: i32, + pub ind: *mut i32, pub opt: String, } @@ -89,7 +68,7 @@ impl GetOpt for Vec { match getopt(len, argv_ptr, opts) { /* From getopt(3p): * - * The getopt() function shall return the next option character + * The getopt() f unction shall return the next option character * specified on the command line. * * A (':') shall be returned if getopt() detects a @@ -130,7 +109,22 @@ impl GetOpt for Vec { Some(Ok(Opt { arg: Some(arg), /* opt argument */ - ind: optind, /* opt index */ + /* From getopt(3p): + * + * The variable optind is the index of the next element + * of the argv[] vector to be processed. It shall be + * initialized to 1 by the system, and getopt() shall + * update it when it finishes with each element of + * argv[]. If the application sets optind to zero + * before calling getopt(), the behavior is unspecified. + * When an element of argv[] contains multiple option + * characters, it is unspecified how getopt() + * determines which options have already been processed. + * + * This API is unsafe and can be utilized by + * dereferencing the ind field before reading to and + * writing from the optind memory. */ + ind: std::ptr::addr_of_mut!(optind), opt: opt.to_string(), /* option itself */ })) }, From 05cde15105239a1fc960c2563826dc367e11bd0b Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 4 Jun 2024 19:15:55 -0600 Subject: [PATCH 093/134] fop(1): updated to use new optind api --- src/fop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fop.rs b/src/fop.rs index a56a0a6..8ffb447 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -50,7 +50,7 @@ fn main() { eprintln!("{}: {}: Not a character.", argv[0], arg); exit(EX_USAGE); } else { d = arg_char[0]; } - index_arg = o.ind as usize; + unsafe { index_arg = *o.ind as usize; } }, Err(_) => { eprintln!("{}", usage); From e862b7fec6a1fa12222ce298b4df8c9cdbee7d89 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 11:54:55 -0600 Subject: [PATCH 094/134] getopt.rs(3): safe api around optind reading and setting --- src/getopt.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index 62696e0..dca53e0 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -34,10 +34,16 @@ extern "C" { pub struct Opt { pub arg: Option, - pub ind: *mut i32, + ind: *mut i32, pub opt: String, } +impl Opt { + pub fn index(&self) -> usize { unsafe { *self.ind as usize } } + + pub fn set_index(&self, ind: i32) { unsafe { *self.ind = ind; } } +} + pub enum OptError { MissingArg(String), UnknownOpt(String), @@ -82,12 +88,12 @@ impl GetOpt for Vec { * * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ - 58 => { /* numerical ASCII value for ':' */ - Some(Err(OptError::MissingArg(optopt.to_string()))) - }, - 63 => { /* numerical ASCII value for '?' */ - Some(Err(OptError::UnknownOpt(optopt.to_string()))) - }, + 58 => { /* numerical ASCII value for ':' */ + Some(Err(OptError::MissingArg(optopt.to_string()))) + }, + 63 => { /* numerical ASCII value for '?' */ + Some(Err(OptError::UnknownOpt(optopt.to_string()))) + }, /* From getopt(3p): * * If, when getopt() is called: @@ -121,9 +127,8 @@ impl GetOpt for Vec { * characters, it is unspecified how getopt() * determines which options have already been processed. * - * This API is unsafe and can be utilized by - * dereferencing the ind field before reading to and - * writing from the optind memory. */ + * This API is can be utilized with the index() and + * set_index() methods implemented for Opt. */ ind: std::ptr::addr_of_mut!(optind), opt: opt.to_string(), /* option itself */ })) From 02daca87dcd3a098d0c85b5021949a8e731d2947 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 11:55:16 -0600 Subject: [PATCH 095/134] fop(1): updated to latest optind api --- src/fop.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index 8ffb447..e0bba4c 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -44,13 +44,13 @@ fn main() { Ok(o) => { /* unwrap because Err(OptError::MissingArg) will be returned if * o.arg is None */ - let arg = o.arg.unwrap(); + let arg = o.arg.clone().unwrap(); let arg_char = arg.chars().collect::>(); if arg_char.len() > 1 { eprintln!("{}: {}: Not a character.", argv[0], arg); exit(EX_USAGE); } else { d = arg_char[0]; } - unsafe { index_arg = *o.ind as usize; } + index_arg = o.index(); }, Err(_) => { eprintln!("{}", usage); From 3c0725f137a6089b549ae928dbd37c41eb336fbe Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 17:15:42 -0600 Subject: [PATCH 096/134] dj.1: adds DESCRIPTION and removes seek/skip confusion --- docs/dj.1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index ea73a75..d4c5053 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -43,6 +43,17 @@ dj .B output offset .R ]) .\" +.SH DESCRIPTION + +Perform precise read and write operations on files. This utility is useful for +reading and writing binary data to and from disks, hence the name. + +This manual page uses the terms \(lqskip\(rq and \(lqseek\(rq to refer to moving +to a specified byte by index in the input and output of the program +respectively. This language is inherited from the +.BR dd (1p) +utility and is used here to decrease ambiguity. +.\" .SH OPTIONS .IP \fB-i\fP @@ -61,7 +72,7 @@ Does the same as .B -b but for the output buffer. .IP \fB-S\fP -Skips a number of bytes through the output before starting to write from +Seeks a number of bytes through the output before starting to write from the input. If the output is a stream, null characters are printed. .IP \fB-a\fP Accepts a single literal byte with which input buffer is padded in the event @@ -86,6 +97,7 @@ Retries failed reads once more before exiting. .IP \fB-q\fP Suppresses error messages which print when a read or write is partial or empty. Each invocation decrements the debug level of the program. +.\" .SH STANDARD INPUT The standard input shall be used as an input if no inputs are specified or if From 11b1b424a022d8a86abdc74e21720e98cb55d520 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 17:18:21 -0600 Subject: [PATCH 097/134] dj.1: more clarification --- docs/dj.1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/dj.1 b/docs/dj.1 index d4c5053..67d294d 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -53,6 +53,9 @@ to a specified byte by index in the input and output of the program respectively. This language is inherited from the .BR dd (1p) utility and is used here to decrease ambiguity. + +When seeking or skipping to a byte, writing or reading starts at the byte +immediately subsequent to the specified byte. .\" .SH OPTIONS From 3392d64e440b8911a51bfead6c73fb5c4fe3f452 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 17:25:22 -0600 Subject: [PATCH 098/134] fop(1): literal record separator --- src/fop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fop.rs b/src/fop.rs index d28a7b0..1cc8152 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -32,7 +32,7 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); - let mut d = "␞".to_owned(); + let mut d = 0x1E.to_string(); let mut arg_parser = Parser::new(&argv, "d:"); while let Some(opt) = arg_parser.next() { From 516d10e21d37bc94f63e67c0ec930fd374d61e22 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 17:27:13 -0600 Subject: [PATCH 099/134] CONDUCT: wording --- CONDUCT | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONDUCT b/CONDUCT index 4a26e37..4dd97a9 100644 --- a/CONDUCT +++ b/CONDUCT @@ -12,10 +12,10 @@ General Public License, version 3 or later, or a compatible license. 2. Ethics (Sīla) Do not use nonfree code or uncredited code in contributions. Do not contribute -code of dubious origins, such as code generated in large part by large language -models [1]. Do not take credit for others’ contributions. Make sure to utilize -the copyright header and license notice on source files to credit yourself and -others for their work. +code of dubious origins, such as code generated by large language models or +unlicensed snippets found online [1]. Do not take credit for others’ +contributions. Make sure to utilize the copyright header and license notice on +source files to credit yourself and others for their work. 3. Renunciation (Nekkhamma) From ad6f9d565baf1999675fcbfcfa9fd34a5cca1030 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 20:39:37 -0600 Subject: [PATCH 100/134] dj.1: formats sysexits.h(3) reference --- docs/dj.1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/dj.1 b/docs/dj.1 index 67d294d..f5dbe18 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -151,7 +151,8 @@ as the only argument: In non-recoverable errors that don\(cqt pertain to the read-write cycle, a diagnostic message is printed and the program exits with the appropriate -sysexits.h(3) status. +.BR sysexits.h (3) +status. .\" .SH BUGS From 526185c2c3e9900a03a1c591665fbb05f2664bc8 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 22:35:50 -0600 Subject: [PATCH 101/134] swab.1: typo --- docs/swab.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swab.1 b/docs/swab.1 index 7197a0a..b1d27fc 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -34,7 +34,7 @@ halved. .SH EXAMPLES The following -.Br sh (1p) +.BR sh (1p) line: .RS From 8ce7890124307220a2ef9edd7057461c50ee5ad8 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 23:07:15 -0600 Subject: [PATCH 102/134] fop.1: removes Unicode representation of RS; hru.1: removes erroneous line break; mm.1: formatting & grammar; npc.1: dollar sign, not currency sign; rpn.1: syntax error; scrut.1: move description to DESCRIPTION; str.1: comma; swab.1: wording & escape codes; true.1: formatting --- docs/fop.1 | 3 ++- docs/hru.1 | 4 ++-- docs/mm.1 | 17 +++++++---------- docs/npc.1 | 2 +- docs/rpn.1 | 5 ++--- docs/scrut.1 | 7 +++---- docs/str.1 | 2 +- docs/swab.1 | 4 ++-- docs/true.1 | 4 ++-- 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/docs/fop.1 b/docs/fop.1 index 29ba7ea..295d9ff 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -24,7 +24,8 @@ Performs operations on specified fields in input data. .IP \fB-d\fP Sets a delimiter by which the input data will be split into fields. The default -is an ASCII record separator (␞). +is an ASCII record separator. +.\" .SH STANDARD INPUT Data will be read from the standard input. diff --git a/docs/hru.1 b/docs/hru.1 index c3a5cdc..8b898f8 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -34,8 +34,8 @@ and print an error message. The GNU project\(cqs .BR ls (1) implementation contains a human-readable option (\fB-h\fP) that, when specified, -makes the tool print size information in a format more immediately readable. -This functionality is useful not only in the context of +makes the tool print size information in a format more immediately +readable. This functionality is useful not only in the context of .BR ls (1) so the decision was made to split it into a new tool. The original functionality in GNU\(cqs diff --git a/docs/mm.1 b/docs/mm.1 index 58bc26e..812aef7 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -27,13 +27,11 @@ Opens subsequent outputs for appending rather than updating. .IP \fB-e\fP Use the standard error as an output. .IP \fB-i\fP -Opens a path as an input. Without any inputs specified mm will use the -standard input. The standard input shall be used as an input if one or more of -the input files is \(lq-\(rq. +Opens a path as an input. If one or more of the input files is \(lq-\(rq or if +no inputs are specified, the standard input shall be used. .IP \fB-o\fP -Opens a path as an output. Without any outputs specified mm will use the -standard output. The standard output shall be used as an output if one or more -of the output files is \(lq-\(rq. +Opens a path as an output. If one or more of the output files is \(lq-\(rq or if +no outputs are specified, the standard output shall be used. .IP \fB-u\fP Ensures neither input or output will be buffered. .IP \fB-n\fP @@ -41,11 +39,10 @@ Causes SIGINT signals to be ignored. .\" .SH DIAGNOSTICS -If an output can no longer be written mm prints a diagnostic message, ceases -writing to that particular output, and if there are more outputs specified, -continues, eventually exiting unsuccessfully. +If an output cannot be written to, an error occurs. Additional outputs are not +affected and writing to them continues. -When an error is encountered, diagnostic message is printed and the program +When an error is encountered, a diagnostic message is printed and the program exits with the appropriate .BR sysexits.h (3) status. diff --git a/docs/npc.1 b/docs/npc.1 index e18e4ff..27926ee 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -28,7 +28,7 @@ high bit set. .SH USAGE .IP \fB-e\fP -Prints a currency sign ('$') before each line ending. +Prints a dollar sign ('$') before each line ending. .IP \fB-t\fP Prints tab characters as '^I' rather than a literal horizontal tab. .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index 8e87802..8a3b0fe 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -37,12 +37,11 @@ the standard input. .\" .SH DIAGNOSTICS -In the event of a syntax error, the program will print an - 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. +error code; however, in the event of a syntax error, the program will print an +error message and continue accepting input. .\" .SH CAVEATS diff --git a/docs/scrut.1 b/docs/scrut.1 index 22c77fb..2cb687c 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -15,7 +15,9 @@ scrut .\" .SH DESCRIPTION -Determine if files comply with requirements. +Determine if files comply with requirements. If the given files comply with the +specified requirements, the program will exit successfully. Otherwise, it exits +unsuccessfully. .\" .SH OPTIONS @@ -50,9 +52,6 @@ Requires the given files to exist and be executable. .\" .SH DIAGNOSTICS -If the given files comply with the specified requirements, the program will exit -successfully. If not, it exits unsuccessfully. - When invoked incorrectly, a debug message will be printed and the program will exit with the appropriate .BR sysexits.h (3) diff --git a/docs/str.1 b/docs/str.1 index 87caabb..66565b9 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -40,7 +40,7 @@ error code. 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 +If a character in a string isn\(cqt valid ASCII, the program will exit unsuccessfully. .\" .SH AUTHOR diff --git a/docs/swab.1 b/docs/swab.1 index b1d27fc..64aed1a 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -27,7 +27,7 @@ Swap the latter and former halves of a block of bytes. Ignore system call interruptions. .IP \fB-w\fP Configures the word size; that is, the size in bytes of the block size -on which to operate. By default the word size is 2. The word size must be +on which to operate. The default word size is 2. The word size must be cleanly divisible by 2, otherwise the block of bytes being processed can\(cqt be halved. .\" @@ -38,7 +38,7 @@ The following line: .RS -.R printf 'hello world!\n' | swab +.R printf 'hello world!\(rsn' | swab .RE Produces the following output: diff --git a/docs/true.1 b/docs/true.1 index ac2e222..ecf4c8e 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -10,8 +10,8 @@ true \(en do nothing, successfully .\" .SH DESCRIPTION -Do nothing regardless of operands or standard input. -An exit code of 0 will always be returned. +Do nothing regardless of operands or standard input. An exit code of 0 will +always be returned. .\" .SH RATIONALE From 4d27a4976c51126cd15058a415cfab3e62aff555 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 5 Jun 2024 23:17:21 -0600 Subject: [PATCH 103/134] swab.1: -f Ignores the SIGINT signal --- docs/swab.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swab.1 b/docs/swab.1 index 64aed1a..0ca19e8 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -24,7 +24,7 @@ Swap the latter and former halves of a block of bytes. .SH OPTIONS .IP \fB-f\fP -Ignore system call interruptions. +Ignore SIGINT signal. .IP \fB-w\fP Configures the word size; that is, the size in bytes of the block size on which to operate. The default word size is 2. The word size must be From 51421b2128ba93502dec3ccb19b01772ac7c2226 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 6 Jun 2024 00:14:55 -0600 Subject: [PATCH 104/134] dj.1, strcmp.1, swab.1: remove nonexistent roff macros --- docs/dj.1 | 44 ++++++++++++++++---------------------------- docs/strcmp.1 | 4 ++-- docs/swab.1 | 4 ++-- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index f5dbe18..f2570ae 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -18,30 +18,18 @@ dj .RB [ count ]) .RB ( -i -.R [ -.B input file -.R ]) +[\fBinput file\fP]) .RB ( -b -.R [ -.B input block size -.R ]) +[\fBinput block size\fP]) .RB ( -s -.R [ -.B input offset -.R ]) +[\fBinput offset\fP]) .RB ( -o -.R [ -.B output file -.R ]) +[\fBoutput file\fP]) .RB ( -B -.R [ -.B output block size -.R ]) +[\fBoutput block size\fP]) .RB ( -S -.R [ -.B output offset -.R ]) +[\fBoutput offset\fP]) .\" .SH DESCRIPTION @@ -118,10 +106,10 @@ By default, statistics are printed for input and output to the standard error in the following format: .RS -.R {records read} {ASCII unit separator} {partial records read} -.R {ASCII record separator} {records written} {ASCII unit separator} -.R {partial records written} {ASCII group separator} {bytes read} -.R {ASCII record separator} {bytes written} {ASCII file separator} +{records read} {ASCII unit separator} {partial records read} +{ASCII record separator} {records written} {ASCII unit separator} +{partial records written} {ASCII group separator} {bytes read} +{ASCII record separator} {bytes written} {ASCII file separator} .RE This format for diagnostic output is designed to be machine-parseable for @@ -130,9 +118,9 @@ convenience. For a more human-readable format, the option may be specified. In this event, the following format is used instead: .RS -.R {records read} '+' {partial records read} '>' {records written} -.R '+' {partial records written} ';' {bytes read} '>' {bytes written} -.R {ASCII line feed} +{records read} '+' {partial records read} '>' {records written} +'+' {partial records written} ';' {bytes read} '>' {bytes written} +{ASCII line feed} .RE If the @@ -144,9 +132,9 @@ was invoked. The following example is the result of running the program with as the only argument: .RS -.R argv0=dj -.R in= ibs=1024 skip=0 align=ff count=0 -.R out= obs=1024 seek=0 debug= 3 noerror=0 +argv0=dj +in= ibs=1024 skip=0 align=ff count=0 +out= obs=1024 seek=0 debug= 3 noerror=0 .RE In non-recoverable errors that don\(cqt pertain to the read-write cycle, a diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 84b661d..46eccdf 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -25,14 +25,14 @@ will exit with an error code of 1 if a string passed has a lesser byte value than one of the prior strings: .RS -.R strcmp b a +strcmp b a .RE and with an error code of 255 if it has a greater byte value than one of the prior strings: .RS -.R strcmp a b +strcmp a b .RE When invoked incorrectly, a debug message will be printed and the program will diff --git a/docs/swab.1 b/docs/swab.1 index 0ca19e8..526b057 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -38,13 +38,13 @@ The following line: .RS -.R printf 'hello world!\(rsn' | swab +printf 'hello world!\(rsn' | swab .RE Produces the following output: .RS -.R ehll oowlr!d +ehll oowlr!d .RE .\" .SH DIAGNOSTICS From 40da8135f189db009dfb24bbc1c3ccc7e2879ed1 Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 6 Jun 2024 01:03:01 -0600 Subject: [PATCH 105/134] getopt.rs(3): relicense to AGPLv3 --- COPYING.GPL | 674 ------------------------------------------------- COPYING.LESSER | 165 ------------ src/getopt.rs | 10 +- 3 files changed, 5 insertions(+), 844 deletions(-) delete mode 100644 COPYING.GPL delete mode 100644 COPYING.LESSER diff --git a/COPYING.GPL b/COPYING.GPL deleted file mode 100644 index f288702..0000000 --- a/COPYING.GPL +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/COPYING.LESSER b/COPYING.LESSER deleted file mode 100644 index 0a04128..0000000 --- a/COPYING.LESSER +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/src/getopt.rs b/src/getopt.rs index dca53e0..5ce094c 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -1,18 +1,18 @@ /* - * Copyright (c) 2024 Emma Tebibyte - * SPDX-License-Identifier: LGPL-3.0-or-later + * Copyright (c) 2023–2024 Emma Tebibyte + * 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 Lesser General Public License as published by the Free + * 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 Lesser General Public License for more + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * - * You should have received a copy of the GNU Lesser General Public License + * 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/. */ From 314254b32f2cd508724f55a2310ff076e26493ba Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 6 Jun 2024 13:32:54 -0600 Subject: [PATCH 106/134] docs: hotfix --- docs/dj.1 | 2 +- docs/false.1 | 2 +- docs/fop.1 | 2 +- docs/hru.1 | 2 +- docs/intcmp.1 | 2 +- docs/mm.1 | 2 +- docs/npc.1 | 2 +- docs/rpn.1 | 2 +- docs/scrut.1 | 2 +- docs/str.1 | 2 +- docs/strcmp.1 | 2 +- docs/swab.1 | 2 +- docs/true.1 | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index f2570ae..1572991 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 +.TH DJ 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME dj \(en disk jockey .\" diff --git a/docs/false.1 b/docs/false.1 index 91bd286..1dec3ce 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FALSE 1 +.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME false \(en do nothing, unsuccessfully .\" diff --git a/docs/fop.1 b/docs/fop.1 index 295d9ff..fe1a3c5 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH fop 1 +.TH FOP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME fop \(en field operator .\" diff --git a/docs/hru.1 b/docs/hru.1 index 8b898f8..b24671e 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 +.TH HRU 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME hru \(en human readable units .\" diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 905d31d..94e88a4 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH INTCMP 1 +.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME intcmp \(en compare integers .\" diff --git a/docs/mm.1 b/docs/mm.1 index 812aef7..2585cab 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH mm 1 +.TH MM 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME mm \(en middleman .\" diff --git a/docs/npc.1 b/docs/npc.1 index 27926ee..a2c4fd8 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 +.TH NPC 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME npc \(en show non-printing characters .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index 8a3b0fe..507789d 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH rpn 1 +.TH RPN 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME rpn \(en reverse polish notation evaluation .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index 2cb687c..636c5d3 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH scrut 1 +.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS diff --git a/docs/str.1 b/docs/str.1 index 66565b9..c3f7538 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 +.TH STR 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME str \(en test the character types of string arguments .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 46eccdf..facfdeb 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 +.TH STRCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME strcmp \(en compare strings .\" diff --git a/docs/swab.1 b/docs/swab.1 index 526b057..a3af1ad 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 +.TH SWAB 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME swab \(en swap bytes .\" diff --git a/docs/true.1 b/docs/true.1 index ecf4c8e..2e8d5eb 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH TRUE 1 +.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME true \(en do nothing, successfully .\" From 376feb9ae9a884c0f3655902c1027cebdf5b6203 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 22:52:58 -0600 Subject: [PATCH 107/134] npc.1: fixes minor details --- docs/npc.1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/npc.1 b/docs/npc.1 index a2c4fd8..a0e503e 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME npc \(en show non-printing characters .\" @@ -25,10 +25,10 @@ becomes '^?'. Characters with the high bit set (>127) are printed as 'M-' followed by the graphical representation for the same character without the high bit set. .\" -.SH USAGE +.SH OPTIONS .IP \fB-e\fP -Prints a dollar sign ('$') before each line ending. +Prints a dollar sign ('$') before each newline. .IP \fB-t\fP Prints tab characters as '^I' rather than a literal horizontal tab. .\" @@ -52,8 +52,8 @@ the .B -v option, is the bandage solution GNU and other software suites use. -This functionality is a separate tool because its usefulness extends beyond that -of +This functionality is included in a separate tool because its usefulness extends +beyond that of .BR cat (1p). .\" .SH AUTHOR From 15d5761cd7f9919700cbd893f7f1d18d18bc4223 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 22:57:08 -0600 Subject: [PATCH 108/134] mm.1: fixes clunky sentence --- docs/mm.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/mm.1 b/docs/mm.1 index 2585cab..1fe64ba 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME mm \(en middleman .\" @@ -39,8 +39,8 @@ Causes SIGINT signals to be ignored. .\" .SH DIAGNOSTICS -If an output cannot be written to, an error occurs. Additional outputs are not -affected and writing to them continues. +If an output cannot be written to, an error occurs; however, exiting will be +deferred until writing to any other specified outputs completes. When an error is encountered, a diagnostic message is printed and the program exits with the appropriate From ee9d42d0d4b5f04f6380eb9c109adad589b10925 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:02:13 -0600 Subject: [PATCH 109/134] str.1: cleanup --- docs/str.1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/str.1 b/docs/str.1 index c3f7538..d45289a 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -6,7 +6,7 @@ .\" .TH STR 1 2024-06-06 "Bonsai Core Utilites 0.13.8" .SH NAME -str \(en test the character types of string arguments +str \(en test string arguments .\" .SH SYNOPSIS @@ -16,7 +16,7 @@ str .\" .SH DESCRIPTION -Test string arguments. +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) @@ -24,11 +24,8 @@ and are the methods by which string arguments are tested. .\" .SH DIAGNOSTICS -If all tests pass, the program will exit with an exit code of 0. If any of the -tests fail, the program will exit unsuccessfully with an error code of 1. - -An empty string will cause an unsuccessful exit as none of its contents pass any -tests. +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 @@ -37,6 +34,9 @@ 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. From 53d5a1db73542cc9a11a1e9356f0a5f232c225f9 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:09:15 -0600 Subject: [PATCH 110/134] hru.1: italics and removes clunky sentences --- docs/hru.1 | 24 +++++++++++++----------- docs/str.1 | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/hru.1 b/docs/hru.1 index b24671e..acd5876 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME hru \(en human readable units .\" @@ -15,9 +15,9 @@ hru Convert counts to higher units. -The program will read byte counts in the form of whole numbers from the standard -input and write to the standard output the same number converted to a higher -unit of data as defined by the International System of Units. +Byte counts will be read in the form of whole numbers from the standard input +and be written to the standard output the same number converted to a higher unit +of data as defined by the \fIInternational System of Units\fP. The program will convert the byte count to the highest unit possible where the value is greater than one. @@ -35,10 +35,8 @@ The GNU project\(cqs .BR ls (1) implementation contains a human-readable option (\fB-h\fP) that, when specified, makes the tool print size information in a format more immediately -readable. This functionality is useful not only in the context of -.BR ls (1) -so the decision was made to split it into a new tool. The original functionality -in GNU\(cqs +readable. This functionality is useful not only in this context, so the decision +was made to split it into a new tool. The original functionality from GNU\(cqs .BR ls (1) can be emulated with .BR fop (1) @@ -46,8 +44,12 @@ combined with this program. .\" .SH STANDARDS -The standard unit prefixes as specified by the Bureau International des Poids -et Mesures (BIPM) in the ninth edition of The International System of Units (SI) +The standard unit prefixes as specified by the +.I Bureau International des Poids et Mesures +.RI ( BIPM ) +in the ninth edition of +.I The International System of Units +.RI ( SI ) are utilized for the ouput of conversions. .\" .SH AUTHOR @@ -64,4 +66,4 @@ Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later .SH SEE ALSO GNU .BR ls (1), -The International System of Units (SI) 9th Edition +.I The International System of Units (SI) 9th Edition diff --git a/docs/str.1 b/docs/str.1 index d45289a..55dd0bb 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME str \(en test string arguments .\" From 1b299f8ee1f3cbf367327bd3eedbe600f7c32b57 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:16:25 -0600 Subject: [PATCH 111/134] rpn.1: fixes clunkiness --- docs/rpn.1 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/rpn.1 b/docs/rpn.1 index 507789d..01e00b9 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH RPN 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME rpn \(en reverse polish notation evaluation .\" @@ -18,12 +18,12 @@ rpn Evaluate reverse polish notation. -The program evaluates reverse polish notation expressions either read from the +The program evaluates reverse polish notation expressions read either from the standard input or parsed from provided arguments. See the STANDARD INPUT section. -Upon evaluation, the program will print the resulting number on the stack to the -standard output. Any further specified numbers will be placed at the end of the +Upon evaluation, the resulting number on the stack will be printed to the +standard output. Any further numbers specified will be placed at the end of the stack. For information on for reverse polish notation syntax, see @@ -31,8 +31,8 @@ For information on for reverse polish notation syntax, see .\" .SH STANDARD INPUT -If arguments are passed, they are interpreted as an expression to be -evaluated. Otherwise, it reads whitespace-delimited numbers and operations from +If arguments are specified, they are interpreted as an expression to be +evaluated. Otherwise, whitespace-delimited numbers and operations are read from the standard input. .\" .SH DIAGNOSTICS @@ -46,11 +46,13 @@ error message and continue accepting input. .SH CAVEATS Due to precision constraints and the way floats are represented in accordance -with the IEEE Standard for Floating Point Arithmetic (\fIIEEE 754\fP), -floating-point arithmetic has rounding errors. This is somewhat curbed by using -the machine epsilon as provided by the Rust standard library to which to round -numbers. Because of this, variation is expected in the number of decimal places -the program can handle based on the platform and hardware of any given machine. +with the +.I IEEE Standard for Floating Point Arithmetic +(\fIIEEE 754\fP), floating-point arithmetic has rounding errors. This is +somewhat curbed by using the machine epsilon as provided by the Rust standard +library to which numbers are rounded. Because of this, variation is expected in +the number of decimal places the program can handle based on the platform and +hardware of any given machine. .\" .SH RATIONALE @@ -63,8 +65,8 @@ program. A pre-dates the standardized .BR bc (1p), the latter originally being a preprocessor for the former, and was included in -UNIX v2 onward. While it implements reverse polish notation, it still suffers -from being unable to accept an expression as an argument. +Second Edition UNIX and onward. While it implements reverse polish notation, it +still suffers from being unable to accept an expression as an argument. .\" .SH AUTHOR From 266ee20d5c7d7dc93cd925df84936ab182dcc8a4 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:18:45 -0600 Subject: [PATCH 112/134] fop.1: removes unnecessary stdin section and adds AUTHOR --- docs/fop.1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/fop.1 b/docs/fop.1 index fe1a3c5..b5c1b7c 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FOP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME fop \(en field operator .\" @@ -18,7 +18,7 @@ fop .\" .SH DESCRIPTION -Performs operations on specified fields in input data. +Performs operations on specified fields in data read from the standard input. .\" .SH OPTIONS @@ -26,10 +26,6 @@ Performs operations on specified fields in input data. Sets a delimiter by which the input data will be split into fields. The default is an ASCII record separator. .\" -.SH STANDARD INPUT - -Data will be read from the standard input. -.\" .SH CAVEATS Field indices are zero-indexed, which may be unexpected behavior for some users. @@ -51,6 +47,12 @@ but there was no easy way to modify the field in the ouput of .BR ls (1p) without creating a new tool. .\" +.SH AUTHOR + +Written by Emma Tebibyte +.MT emma@tebibyte.media +.ME . +.\" .SH COPYRIGHT Copyright \(co 2024 Emma Tebibyte. License AGPLv3+: GNU AGPL version 3 or later From bf10689606b53588dac03d6d48ded1d8560228fd Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:20:29 -0600 Subject: [PATCH 113/134] swab.1: bold --- docs/swab.1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/swab.1 b/docs/swab.1 index a3af1ad..abaab0b 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME swab \(en swap bytes .\" @@ -56,7 +56,9 @@ error code. .\" .SH RATIONALE -This program was modeled and named after the conv=swab functionality specified +This program was modeled and named after the +.B conv=swab +functionality specified in the .BR dd (1p) utility. It additionally allows the word size to be configured. @@ -64,6 +66,12 @@ utility. It additionally allows the word size to be configured. This functionality is useful for fixing the endianness of binary files produced on other machines. .\" +.SH AUTHOR + +Written by DTB +.MT trinity@trinity.moe +.ME . +.\" .SH COPYRIGHT Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later From 59eee27979666b3eaca0c2721965bf2c82eca342 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:21:44 -0600 Subject: [PATCH 114/134] strcmp.1: or --- docs/strcmp.1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/strcmp.1 b/docs/strcmp.1 index facfdeb..5941762 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME strcmp \(en compare strings .\" @@ -28,7 +28,7 @@ than one of the prior strings: strcmp b a .RE -and with an error code of 255 if it has a greater byte value than one of the +or with an error code of 255 if it has a greater byte value than one of the prior strings: .RS @@ -54,7 +54,8 @@ been 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 with +This program\(cqs functionality may be performed on a POSIX-compliant system +with .BR test (1p). .\" .SH AUTHOR From e38dcc09b12a0fa2c1c1a7e4e645027a29bfbe56 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:27:19 -0600 Subject: [PATCH 115/134] intcmp.1: bold --- docs/intcmp.1 | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 94e88a4..2808362 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -28,19 +28,23 @@ Permits a given integer to be less than the following integer. .\" .SH EXAMPLES -It may help to think of the -e, -g, and -l options as equivalent to the -infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq operators respectively, with -each option putting its symbol between every given integer. The following -example is equivalent to evaluating \(lq1 < 2 < 3\(rq: +It may help to think of the +.BR -e , +.BR -g , +and +.B -l +options as equivalent to the infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq +operators respectively, with each option putting its symbol between every given +integer. The following example is equivalent to evaluating \(lq1 < 2 < 3\(rq: \" .RS -.R intcmp -l 1 2 3 +intcmp -l 1 2 3 .RE .\" .SH DIAGNOSTICS -The program will exit with a status code of 0 for a valid expression and with a -code of 1 for an invalid expression. +The program will exit with a successfully for a valid expression and with an +error code of 1 for an invalid expression. In the event of an error, a debug message will be printed and the program will exit with the appropriate @@ -49,7 +53,8 @@ error code. .\" .SH BUGS --egl, \(lqequal to or less than or greater than\(rq, exits 0 no matter what for +.BR -egl , +\(lqequal to or less than or greater than\(rq, always exits successfully for valid program usage and may be abused to function as an integer validator. Use .BR str (1) instead. @@ -57,9 +62,17 @@ instead. .SH CAVEATS There are multiple ways to express compound comparisons; \(lqless than or equal -to\(rq can be -le or -el, for example. +to\(rq can be +.B -le +or +.BR -el , +for example. -The inequality comparison is -gl or -lg for \(lqless than or greater than\(rq; +The inequality comparison is +.B -gl +.B or +.B -lg +for \(lqless than or greater than\(rq; this is elegant but unintuitive. .\" .SH RATIONALE From 6814111ad1a6d14ac5b514212f5a9e1a9a7c6947 Mon Sep 17 00:00:00 2001 From: emma Date: Mon, 17 Jun 2024 23:36:52 -0600 Subject: [PATCH 116/134] dj.1: fixes many clunky sentences --- docs/dj.1 | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 1572991..6073fc6 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.8" .SH NAME dj \(en disk jockey .\" @@ -34,13 +34,13 @@ dj .SH DESCRIPTION Perform precise read and write operations on files. This utility is useful for -reading and writing binary data to and from disks, hence the name. +reading and writing binary data to and from disks. This manual page uses the terms \(lqskip\(rq and \(lqseek\(rq to refer to moving to a specified byte by index in the input and output of the program respectively. This language is inherited from the .BR dd (1p) -utility and is used here to decrease ambiguity. +utility and used here to decrease ambiguity. When seeking or skipping to a byte, writing or reading starts at the byte immediately subsequent to the specified byte. @@ -50,8 +50,8 @@ immediately subsequent to the specified byte. .IP \fB-i\fP Takes a file path as an argument and opens it for use as an input. .IP \fB-b\fP -Takes a numeric argument as the size in bytes of the input buffer, with the -default being 1024. +Takes a numeric argument as the size in bytes of the input buffer, the default +being 1024. .IP \fB-s\fP Takes a numeric argument as the number of bytes to skip into the input before starting to read. If the standard input is used, bytes read to this point @@ -66,25 +66,25 @@ but for the output buffer. Seeks a number of bytes through the output before starting to write from the input. If the output is a stream, null characters are printed. .IP \fB-a\fP -Accepts a single literal byte with which input buffer is padded in the event +Accepts a single literal byte with which the input buffer is padded in the event of an incomplete read from the input file. .IP \fB-A\fP Specifying this option pads the input buffer with null bytes in the event of an -incomplete read. Equivalent to specifying +incomplete read. This is equivalent to specifying .B -a with a null byte instead of a character. .IP \fB-c\fP -Specifies a number of reads to make. The default is zero, in which case the +Specifies a number of reads to make. The default is 0, in which case the input is read until a partial or empty read is made. .IP \fB-d\fP Prints invocation information before program execution as described in the -DIAGNOSTICS section below. Each invocation increments the debug level of the +DIAGNOSTICS section. Each invocation increments the debug level of the program. .IP \fB-H\fP Prints diagnostics messages in a human-readable manner as described in the -DIAGNOSTICS section below. +DIAGNOSTICS section. .IP \fB-n\fP -Retries failed reads once more before exiting. +Retries failed reads once before exiting. .IP \fB-q\fP Suppresses error messages which print when a read or write is partial or empty. Each invocation decrements the debug level of the program. @@ -94,13 +94,18 @@ empty. Each invocation decrements the debug level of the program. The standard input shall be used as an input if no inputs are specified or if one or more of the input files is \(lq-\(rq. .\" +.SH STANDARD OUTPUT +The standard output shall be used as an output if no inputs are specified or if +one or more of the input files is \(lq-\(rq. +.\" .SH DIAGNOSTICS -On a partial or empty read, a diagnostic message is printed (unless the +On a partial or empty read, unless the .B -q -option is specified) and the program exits (unless the +option is specified, a diagnostic message is printed. Then, the program exits +unless the .B -n -option is specified). +option is specified. By default, statistics are printed for input and output to the standard error in the following format: @@ -125,9 +130,9 @@ option may be specified. In this event, the following format is used instead: If the .B -d -option is specified, debug output will be printed at the beginning of -execution. This debug information contains information regarding how the program -was invoked. The following example is the result of running the program with +option is specified, debug information will be printed at the beginning of +execution. This output contains information regarding how the program was +invoked. The following example is the result of running the program with .B -d as the only argument: @@ -148,12 +153,12 @@ If .B -n is specified along with the .B -c -option and a count, actual byte output may be lower than expected (the product -of the count and the input block size). If the +option and a count, actual byte output is the product of the count and the input +block size and therefore may be lower than expected. If the .B -a or .B -A -options are used, this could make data written nonsensical. +options are specified, this could make written data nonsensical. .\" .SH CAVEATS From d201f9228ce6e6379c845d1a541a133629da4b05 Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 18 Jun 2024 16:32:20 -0600 Subject: [PATCH 117/134] Makefile: updates to use new POSIX 2024 standard features! --- Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1952a25..15b2968 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,7 @@ .POSIX: # if using BSD make(1), remove these pragmas because they break it -.PRAGMA: posix_202x # future POSIX standard support à la pdpmake(1) -.PRAGMA: command_comment # breaks without this? + DESTDIR ?= dist PREFIX ?= /usr/local @@ -32,9 +31,9 @@ CFLAGS += -I$(SYSEXITS) .PHONY: all all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true +# keep build/include until bindgen(1) has stdin support +# https://github.com/rust-lang/rust-bindgen/issues/2703 build: - # keep build/include until bindgen(1) has stdin support - # https://github.com/rust-lang/rust-bindgen/issues/2703 mkdir -p build/bin build/include build/lib build/o build/test .PHONY: clean @@ -67,9 +66,9 @@ build/o/libstrerror.rlib: build src/strerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ src/strerror.rs +# bandage solution until bindgen(1) gets stdin support build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h - # bandage solution until bindgen(1) gets stdin support - printf '#define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \ + printf '\043define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \ > build/include/sysexits.h bindgen --default-macro-constant-type signed --use-core --formatter=none \ build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ - From f553cff09651512b609e2c394f368775fe9c674b Mon Sep 17 00:00:00 2001 From: emma Date: Tue, 18 Jun 2024 16:33:22 -0600 Subject: [PATCH 118/134] Makefile: removes unneeded comment --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 15b2968..0dee534 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,6 @@ .POSIX: -# if using BSD make(1), remove these pragmas because they break it - - DESTDIR ?= dist PREFIX ?= /usr/local From 125b4c89300916bd3325343c71ff601be3916911 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 19 Jun 2024 02:52:58 -0600 Subject: [PATCH 119/134] README: updated for clarity --- README | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README b/README index d7a79f6..68be16c 100644 --- a/README +++ b/README @@ -1,9 +1,11 @@ “Seek not to walk the path of the masters; seek what they sought.” – Matsuo Basho -The Bonsai core utilities are the result of the careful examination of the -current state of POSIX and Unix utilies. The Unix Philosophy, “do one thing and -do it well” is its core but these tools do not cling to the names of the past. +The Bonsai core 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. The era of the original Unix tools has been long and fruitful, but they have their flaws. The new, non-POSIX era of this project started with frustration @@ -38,7 +40,7 @@ To test the utilities: $ make test -To remove all untracked files: +To remove all build and distributable files: $ make clean From e1ac40e7ee285131711117d5373825addfafb522 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 19 Jun 2024 15:03:06 -0600 Subject: [PATCH 120/134] docs: updates version number --- docs/dj.1 | 2 +- docs/false.1 | 2 +- docs/fop.1 | 2 +- docs/hru.1 | 2 +- docs/intcmp.1 | 2 +- docs/mm.1 | 2 +- docs/npc.1 | 2 +- docs/rpn.1 | 2 +- docs/scrut.1 | 2 +- docs/str.1 | 2 +- docs/strcmp.1 | 2 +- docs/swab.1 | 2 +- docs/true.1 | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index 6073fc6..e229d1f 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME dj \(en disk jockey .\" diff --git a/docs/false.1 b/docs/false.1 index 1dec3ce..f86e1d8 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.9" .SH NAME false \(en do nothing, unsuccessfully .\" diff --git a/docs/fop.1 b/docs/fop.1 index b5c1b7c..6c7b991 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME fop \(en field operator .\" diff --git a/docs/hru.1 b/docs/hru.1 index acd5876..60a5afd 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME hru \(en human readable units .\" diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 2808362..b50b3f9 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.9" .SH NAME intcmp \(en compare integers .\" diff --git a/docs/mm.1 b/docs/mm.1 index 1fe64ba..107d5b0 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME mm \(en middleman .\" diff --git a/docs/npc.1 b/docs/npc.1 index a0e503e..7b54e31 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME npc \(en show non-printing characters .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index 01e00b9..10cd709 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME rpn \(en reverse polish notation evaluation .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index 636c5d3..9dac85b 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.9" .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS diff --git a/docs/str.1 b/docs/str.1 index 55dd0bb..cfc859f 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME str \(en test string arguments .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 5941762..0e5d46f 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME strcmp \(en compare strings .\" diff --git a/docs/swab.1 b/docs/swab.1 index abaab0b..97002e7 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.8" +.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.9" .SH NAME swab \(en swap bytes .\" diff --git a/docs/true.1 b/docs/true.1 index 2e8d5eb..b23021d 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.8" +.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.9" .SH NAME true \(en do nothing, successfully .\" From 35f49a699f5d4edb252b873dda1841645ba486a2 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 19 Jun 2024 15:26:46 -0600 Subject: [PATCH 121/134] fop(1): fixes record separator, again --- src/fop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fop.rs b/src/fop.rs index 1cc8152..9bf2396 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -32,7 +32,7 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); - let mut d = 0x1E.to_string(); + let mut d = char::from(0x1E).to_string(); let mut arg_parser = Parser::new(&argv, "d:"); while let Some(opt) = arg_parser.next() { From 72f57ba08be24574ecd458f351c13ecf75d8192d Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 19 Jun 2024 23:29:22 -0600 Subject: [PATCH 122/134] Makefile: adds octal disclaimer --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 0dee534..7756c56 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ # permitted in any medium without royalty provided the copyright notice and this # notice are preserved. This file is offered as-is, without any warranty. +# The octal escape \043 is utilized twice in this file as make(1p) will +# interpret a hash in a rule as an inline comment. + .POSIX: DESTDIR ?= dist From 4b3333d8d31eae5a0d1a3f5c8601c696179150c2 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 21 Jun 2024 03:23:39 -0600 Subject: [PATCH 123/134] fop(1): record separator worky now? --- docs/dj.1 | 2 +- docs/false.1 | 2 +- docs/fop.1 | 2 +- docs/hru.1 | 2 +- docs/intcmp.1 | 2 +- docs/mm.1 | 2 +- docs/npc.1 | 2 +- docs/rpn.1 | 2 +- docs/scrut.1 | 2 +- docs/str.1 | 2 +- docs/strcmp.1 | 2 +- docs/swab.1 | 2 +- docs/true.1 | 2 +- src/fop.rs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/dj.1 b/docs/dj.1 index e229d1f..7d28ac8 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME dj \(en disk jockey .\" diff --git a/docs/false.1 b/docs/false.1 index f86e1d8..5b582dd 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.9" +.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.11" .SH NAME false \(en do nothing, unsuccessfully .\" diff --git a/docs/fop.1 b/docs/fop.1 index 6c7b991..f7afa54 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME fop \(en field operator .\" diff --git a/docs/hru.1 b/docs/hru.1 index 60a5afd..346f200 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME hru \(en human readable units .\" diff --git a/docs/intcmp.1 b/docs/intcmp.1 index b50b3f9..315cda2 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.9" +.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.11" .SH NAME intcmp \(en compare integers .\" diff --git a/docs/mm.1 b/docs/mm.1 index 107d5b0..3ca0722 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME mm \(en middleman .\" diff --git a/docs/npc.1 b/docs/npc.1 index 7b54e31..51cb851 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME npc \(en show non-printing characters .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index 10cd709..7d3b477 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME rpn \(en reverse polish notation evaluation .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index 9dac85b..1e17f7e 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.9" +.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.11" .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS diff --git a/docs/str.1 b/docs/str.1 index cfc859f..6f01125 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME str \(en test string arguments .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 0e5d46f..2ff08f6 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME strcmp \(en compare strings .\" diff --git a/docs/swab.1 b/docs/swab.1 index 97002e7..1c75705 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.9" +.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.11" .SH NAME swab \(en swap bytes .\" diff --git a/docs/true.1 b/docs/true.1 index b23021d..ebf8916 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.9" +.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.11" .SH NAME true \(en do nothing, successfully .\" diff --git a/src/fop.rs b/src/fop.rs index 9bf2396..5244300 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -32,7 +32,7 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); - let mut d = char::from(0x1E).to_string(); + let mut d = '\u{1E}'.to_string(); let mut arg_parser = Parser::new(&argv, "d:"); while let Some(opt) = arg_parser.next() { From 8f990ba515ccdb548b8f4a858e128e204842fcbd Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 22 Jun 2024 22:18:13 -0600 Subject: [PATCH 124/134] getopt.rs(3): adds testing --- Makefile | 6 +- src/getopt.rs | 151 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 111 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 7736a78..734a62c 100644 --- a/Makefile +++ b/Makefile @@ -49,9 +49,13 @@ install: dist cp -r $(DESTDIR)/* / .PHONY: test -test: build +test: build /tmp/getopt tests/posix-compat.sh +/tmp/getopt: src/getopt.rs + $(RUSTC) --test -o /tmp/getopt src/getopt.rs + /tmp/getopt + .PHONY: rustlibs rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ build/o/libstrerror.rlib diff --git a/src/getopt.rs b/src/getopt.rs index 5ce094c..dc88229 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -32,49 +32,71 @@ extern "C" { ) -> c_int; } -pub struct Opt { - pub arg: Option, - ind: *mut i32, - pub opt: String, -} - -impl Opt { - pub fn index(&self) -> usize { unsafe { *self.ind as usize } } - - pub fn set_index(&self, ind: i32) { unsafe { *self.ind = ind; } } -} - +#[derive(Clone, Debug)] pub enum OptError { MissingArg(String), UnknownOpt(String), } +#[derive(Clone, Debug)] +pub struct Opt { + arg: Option, + ind: *mut i32, + opt: Result, +} + +impl Opt { + pub fn arg(&self) -> Option { self.arg.clone() } + + /* sets optarg if default is desired */ + pub fn arg_or(&self, default: impl std::fmt::Display) -> String { + default.to_string() + } + + pub fn opt(&self) -> Result<&str, OptError> { + self.opt.as_ref().map(|o| o.as_str()).map_err(OptError::clone) + } + + /* From getopt(3p): + * + * The variable optind is the index of the next element of the argv[] + * vector to be processed. It shall be initialized to 1 by the system, and + * getopt() shall update it when it finishes with each element of argv[]. + * If the application sets optind to zero before calling getopt(), the + * behavior is unspecified. When an element of argv[] contains multiple + * option characters, it is unspecified how getopt() determines which + * options have already been processed. */ + pub fn ind(&self) -> usize { unsafe { *self.ind as usize } } + + pub fn set_ind(&self, ind: i32) { unsafe { *self.ind = ind; } } +} + /* function signature */ pub trait GetOpt { - fn getopt(&self, optstring: &str) -> Option>; + fn getopt(&self, optstring: &str) -> Option; } impl GetOpt for Vec { - fn getopt(&self, optstring: &str) -> Option> { + fn getopt(&self, optstring: &str) -> Option { let c_strings: Vec<_> = self .iter() .cloned() - .map(CString::new) - .map(Result::unwrap) + .map(|x| CString::new(x).unwrap().into_raw()) .collect(); + let boxed = Box::into_raw(c_strings.into_boxed_slice()); + let argv = boxed as *const *mut i8; + /* these operations must be separated out into separate operations so * the CStrings can live long enough */ - let argv: Vec<_> = c_strings.iter().map(|x| x.as_ptr()).collect(); - let argv_ptr = argv.as_ptr() as *const *mut c_char; let opts = CString::new(optstring).unwrap().into_raw(); let len = self.len() as c_int; unsafe { - match getopt(len, argv_ptr, opts) { + let ret = match getopt(len, argv, opts) { /* From getopt(3p): * - * The getopt() f unction shall return the next option character + * The getopt() function shall return the next option character * specified on the command line. * * A (':') shall be returned if getopt() detects a @@ -89,10 +111,24 @@ impl GetOpt for Vec { * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ 58 => { /* numerical ASCII value for ':' */ - Some(Err(OptError::MissingArg(optopt.to_string()))) + Some(Opt { + /* opt argument */ + arg: None, + /* opt index */ + ind: std::ptr::addr_of_mut!(optind), + /* error containing option */ + opt: Err(OptError::MissingArg(optopt.to_string())), + }) }, 63 => { /* numerical ASCII value for '?' */ - Some(Err(OptError::UnknownOpt(optopt.to_string()))) + Some(Opt { + /* opt argument */ + arg: None, + /* opt index */ + ind: std::ptr::addr_of_mut!(optind), + /* error containing option */ + opt: Err(OptError::UnknownOpt(optopt.to_string())), + }) }, /* From getopt(3p): * @@ -109,31 +145,56 @@ impl GetOpt for Vec { * getopt() shall return -1 after incrementing optind. */ -1 => return None, opt => { - let arg = CStr::from_ptr(optarg) - .to_string_lossy() - .into_owned(); + let arg: Option; - Some(Ok(Opt { - arg: Some(arg), /* opt argument */ - /* From getopt(3p): - * - * The variable optind is the index of the next element - * of the argv[] vector to be processed. It shall be - * initialized to 1 by the system, and getopt() shall - * update it when it finishes with each element of - * argv[]. If the application sets optind to zero - * before calling getopt(), the behavior is unspecified. - * When an element of argv[] contains multiple option - * characters, it is unspecified how getopt() - * determines which options have already been processed. - * - * This API is can be utilized with the index() and - * set_index() methods implemented for Opt. */ - ind: std::ptr::addr_of_mut!(optind), - opt: opt.to_string(), /* option itself */ - })) + if optarg.is_null() { arg = None; } + else { + arg = Some(CStr::from_ptr(optarg) + .to_string_lossy() + .into_owned()); + } + + Some(Opt { + arg, /* opt argument */ + ind: std::ptr::addr_of_mut!(optind), /* opt index */ + /* option itself */ + opt: Ok((opt as u8 as char).to_string()), + }) }, - } + }; + + /* delloc argv */ + let _ = Box::from_raw(boxed); + return ret; } } } + +#[cfg(test)] +mod tests { + use GetOpt; + + #[test] + fn testing() { + let argv: Vec = ["test", "-b", "-f", "arg", "-o", "arg"] + .iter() + .map(|s| s.to_string()) + .collect(); + + while let Some(opt) = argv.getopt(":abf:o:") { + match opt.opt() { + Ok("a") => assert_eq!(opt.ind(), 1), + Ok("b") => assert_eq!(opt.ind(), 2), + Ok("f") | Ok("o") => { + assert_eq!(opt.arg(), Some("arg".into())); + }, + _ => assert!(false), + }; + } + + if let Some(opt) = argv.getopt("abc:") { + opt.clone().set_ind(1); + assert_eq!(opt.ind(), 1); + } + } +} From e1bf49c75af4ff75aaae9761cc5a8196c4d6e198 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 22 Jun 2024 22:30:30 -0600 Subject: [PATCH 125/134] getopt.rs(3): adds comments & documentation --- src/getopt.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/getopt.rs b/src/getopt.rs index dc88229..ee8cafa 100644 --- a/src/getopt.rs +++ b/src/getopt.rs @@ -40,9 +40,9 @@ pub enum OptError { #[derive(Clone, Debug)] pub struct Opt { - arg: Option, - ind: *mut i32, - opt: Result, + arg: Option, /* option argument */ + ind: *mut i32, /* option index */ + opt: Result, /* option option */ } impl Opt { @@ -53,6 +53,7 @@ impl Opt { default.to_string() } + /* makes matching the output of this method more bearable */ pub fn opt(&self) -> Result<&str, OptError> { self.opt.as_ref().map(|o| o.as_str()).map_err(OptError::clone) } @@ -68,6 +69,7 @@ impl Opt { * options have already been processed. */ pub fn ind(&self) -> usize { unsafe { *self.ind as usize } } + /* this is patently terrible and is only happening because I’m stubborn */ pub fn set_ind(&self, ind: i32) { unsafe { *self.ind = ind; } } } @@ -84,11 +86,11 @@ impl GetOpt for Vec { .map(|x| CString::new(x).unwrap().into_raw()) .collect(); + /* god knows what this does */ let boxed = Box::into_raw(c_strings.into_boxed_slice()); let argv = boxed as *const *mut i8; - /* these operations must be separated out into separate operations so - * the CStrings can live long enough */ + /* 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; @@ -110,21 +112,17 @@ impl GetOpt for Vec { * * Otherwise, getopt() shall return -1 when all command line * options are parsed. */ - 58 => { /* numerical ASCII value for ':' */ + 58 => { /* ASCII ':' */ Some(Opt { - /* opt argument */ arg: None, - /* opt index */ ind: std::ptr::addr_of_mut!(optind), /* error containing option */ opt: Err(OptError::MissingArg(optopt.to_string())), }) }, - 63 => { /* numerical ASCII value for '?' */ + 63 => { /* ASCII '?' */ Some(Opt { - /* opt argument */ arg: None, - /* opt index */ ind: std::ptr::addr_of_mut!(optind), /* error containing option */ opt: Err(OptError::UnknownOpt(optopt.to_string())), @@ -155,21 +153,25 @@ impl GetOpt for Vec { } Some(Opt { - arg, /* opt argument */ - ind: std::ptr::addr_of_mut!(optind), /* opt index */ - /* option itself */ + arg, + ind: std::ptr::addr_of_mut!(optind), + /* I didn’t need to cast this before; I rewrote the + * pointer logic and now I do + * + * I don’t know why this is */ opt: Ok((opt as u8 as char).to_string()), }) }, }; - /* delloc argv */ + /* delloc argv (something online said I should do this) */ let _ = Box::from_raw(boxed); return ret; } } } +/* tests (good) */ #[cfg(test)] mod tests { use GetOpt; From 6e4aeb7be7615ea899d7ba234713e50a63cc0a20 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 23 Jun 2024 01:00:48 -0600 Subject: [PATCH 126/134] fop(1): bring getopt(3) usage up-to-date --- src/fop.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index 29f1522..91c8a72 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -33,25 +33,20 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); let mut d = '\u{1E}'.to_string(); + let mut index_arg = 0; + let usage = format!( "Usage: {} [-d delimiter] index command [args...]", argv[0], ); - let mut index_arg = 0; - let mut arg_parser = Parser::new(&argv, "d:"); while let Some(opt) = argv.getopt("d:") { - match opt { - Ok(o) => { + match opt.opt() { + Ok(_) => { /* unwrap because Err(OptError::MissingArg) will be returned if - * o.arg is None */ - let arg = o.arg.clone().unwrap(); - let arg_char = arg.chars().collect::>(); - if arg_char.len() > 1 { - eprintln!("{}: {}: Not a character.", argv[0], arg); - exit(EX_USAGE); - } else { d = arg_char[0]; } - index_arg = o.index(); + * opt.arg() is None */ + d = opt.arg().unwrap(); + index_arg = opt.ind(); }, Err(_) => { eprintln!("{}", usage); From 8b400d8a6251115d449d6930245e0dda0457ef95 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 23 Jun 2024 23:34:23 -0600 Subject: [PATCH 127/134] Makefile, docs: rename --- README | 23 +++++++++++------------ docs/dj.1 | 2 +- docs/false.1 | 2 +- docs/fop.1 | 2 +- docs/hru.1 | 2 +- docs/intcmp.1 | 2 +- docs/mm.1 | 2 +- docs/npc.1 | 2 +- docs/rpn.1 | 2 +- docs/scrut.1 | 2 +- docs/str.1 | 2 +- docs/strcmp.1 | 2 +- docs/swab.1 | 2 +- docs/true.1 | 2 +- 14 files changed, 24 insertions(+), 25 deletions(-) diff --git a/README b/README index 68be16c..fdb05fb 100644 --- a/README +++ b/README @@ -1,28 +1,27 @@ “Seek not to walk the path of the masters; seek what they sought.” – Matsuo Basho -The Bonsai core 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. +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. The era of the original Unix tools has been long and fruitful, but they have -their flaws. The new, non-POSIX era of this project started with frustration -with the way certain tools work and how other projects that extend POSIX don’t -make anything better. +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 -Bonsai core utilities will intentionally discourage use of the shell for -purposes beyond its scope. +harakit utilities will intentionally discourage use of the shell for purposes +beyond its scope. See docs/ for more on the specific utilities currently implemented. Building -The coreutils require a POSIX-compliant environment to compile, including a C -compiler and preprocessor (cc(1) and cpp(1) by default), an edition 2023 Rust +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 compiler (rustc(1) by default), bindgen(1), and a POSIX-compliant make(1) utility. diff --git a/docs/dj.1 b/docs/dj.1 index 7d28ac8..5cf2368 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH DJ 1 2024-06-17 "Harakit 0.13.11" .SH NAME dj \(en disk jockey .\" diff --git a/docs/false.1 b/docs/false.1 index 5b582dd..1d6691b 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FALSE 1 2024-06-06 "Bonsai Core Utilites 0.13.11" +.TH FALSE 1 2024-06-06 "Harakit 0.13.11" .SH NAME false \(en do nothing, unsuccessfully .\" diff --git a/docs/fop.1 b/docs/fop.1 index f7afa54..2d54720 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FOP 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH FOP 1 2024-06-17 "Harakit 0.13.11" .SH NAME fop \(en field operator .\" diff --git a/docs/hru.1 b/docs/hru.1 index 346f200..eb0ce5e 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH HRU 1 2024-06-17 "Harakit 0.13.11" .SH NAME hru \(en human readable units .\" diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 315cda2..19c2c75 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH INTCMP 1 2024-06-06 "Bonsai Core Utilites 0.13.11" +.TH INTCMP 1 2024-06-06 "Harakit 0.13.11" .SH NAME intcmp \(en compare integers .\" diff --git a/docs/mm.1 b/docs/mm.1 index 3ca0722..0f1b97b 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH MM 1 2024-06-17 "Harakit 0.13.11" .SH NAME mm \(en middleman .\" diff --git a/docs/npc.1 b/docs/npc.1 index 51cb851..03890fb 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH NPC 1 2024-06-17 "Harakit 0.13.11" .SH NAME npc \(en show non-printing characters .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index 7d3b477..f937889 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH RPN 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH RPN 1 2024-06-17 "Harakit 0.13.11" .SH NAME rpn \(en reverse polish notation evaluation .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index 1e17f7e..541dcf2 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SCRUT 1 2024-06-06 "Bonsai Core Utilites 0.13.11" +.TH SCRUT 1 2024-06-06 "Harakit 0.13.11" .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS diff --git a/docs/str.1 b/docs/str.1 index 6f01125..c4d68cc 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH STR 1 2024-06-17 "Harakit 0.13.11" .SH NAME str \(en test string arguments .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 2ff08f6..781fc92 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH STRCMP 1 2024-06-17 "Harakit 0.13.11" .SH NAME strcmp \(en compare strings .\" diff --git a/docs/swab.1 b/docs/swab.1 index 1c75705..708a59b 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 2024-06-17 "Bonsai Core Utilites 0.13.11" +.TH SWAB 1 2024-06-17 "Harakit 0.13.11" .SH NAME swab \(en swap bytes .\" diff --git a/docs/true.1 b/docs/true.1 index ebf8916..15a4667 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH TRUE 1 2024-06-06 "Bonsai Core Utilites 0.13.11" +.TH TRUE 1 2024-06-06 "Harakit 0.13.11" .SH NAME true \(en do nothing, successfully .\" From 0fc9a6b533d740214b4364a52bbebe86f81c7dee Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 23 Jun 2024 23:47:29 -0600 Subject: [PATCH 128/134] Makefile, docs: programmatically generate version for docs (i got tired of doing it myself) --- Makefile | 13 ++++++++++--- docs/dj.1 | 2 +- docs/false.1 | 2 +- docs/fop.1 | 2 +- docs/hru.1 | 2 +- docs/intcmp.1 | 2 +- docs/mm.1 | 2 +- docs/npc.1 | 2 +- docs/rpn.1 | 2 +- docs/scrut.1 | 2 +- docs/str.1 | 2 +- docs/strcmp.1 | 2 +- docs/swab.1 | 2 +- docs/true.1 | 2 +- 14 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7756c56..9ecbedb 100644 --- a/Makefile +++ b/Makefile @@ -29,12 +29,12 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \ CFLAGS += -I$(SYSEXITS) .PHONY: all -all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true +all: docs dj false fop hru intcmp mm npc rpn scrut str strcmp swab true # keep build/include until bindgen(1) has stdin support # https://github.com/rust-lang/rust-bindgen/issues/2703 build: - mkdir -p build/bin build/include build/lib build/o build/test + mkdir -p build/bin build/docs build/include build/lib build/o build/test .PHONY: clean clean: @@ -43,7 +43,7 @@ clean: dist: all mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1 cp build/bin/* $(DESTDIR)/$(PREFIX)/bin - cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1 + cp build/docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1 .PHONY: install install: dist @@ -54,6 +54,13 @@ test: build tests/posix-compat.sh $(RUSTC) --test src/getopt-rs/lib.rs -o build/test/getopt +.PHONY: docs +docs: docs/ build + for file in docs/*; do original="$$(sed -n '/^\.TH/p' <"$$file")"; \ + title="$$(printf '%s\n' "$$original" | sed \ + "s/X\.X\.X/$$(git describe --tags --long | cut -d'-' -f1)/g")"; \ + sed "s/$$original/$$title/g" <"$$file" >"build/$$file"; done + .PHONY: rustlibs rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ build/o/libstrerror.rlib diff --git a/docs/dj.1 b/docs/dj.1 index 5cf2368..7031ccf 100644 --- a/docs/dj.1 +++ b/docs/dj.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH DJ 1 2024-06-17 "Harakit 0.13.11" +.TH DJ 1 2024-06-17 "Harakit X.X.X" .SH NAME dj \(en disk jockey .\" diff --git a/docs/false.1 b/docs/false.1 index 1d6691b..b940909 100644 --- a/docs/false.1 +++ b/docs/false.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FALSE 1 2024-06-06 "Harakit 0.13.11" +.TH FALSE 1 2024-06-06 "Harakit X.X.X" .SH NAME false \(en do nothing, unsuccessfully .\" diff --git a/docs/fop.1 b/docs/fop.1 index 2d54720..d777c68 100644 --- a/docs/fop.1 +++ b/docs/fop.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH FOP 1 2024-06-17 "Harakit 0.13.11" +.TH FOP 1 2024-06-17 "Harakit X.X.X" .SH NAME fop \(en field operator .\" diff --git a/docs/hru.1 b/docs/hru.1 index eb0ce5e..6929d51 100644 --- a/docs/hru.1 +++ b/docs/hru.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH HRU 1 2024-06-17 "Harakit 0.13.11" +.TH HRU 1 2024-06-17 "Harakit X.X.X" .SH NAME hru \(en human readable units .\" diff --git a/docs/intcmp.1 b/docs/intcmp.1 index 19c2c75..034a4fd 100644 --- a/docs/intcmp.1 +++ b/docs/intcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH INTCMP 1 2024-06-06 "Harakit 0.13.11" +.TH INTCMP 1 2024-06-06 "Harakit X.X.X" .SH NAME intcmp \(en compare integers .\" diff --git a/docs/mm.1 b/docs/mm.1 index 0f1b97b..2ff9f44 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -3,7 +3,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-06-17 "Harakit 0.13.11" +.TH MM 1 2024-06-17 "Harakit X.X.X" .SH NAME mm \(en middleman .\" diff --git a/docs/npc.1 b/docs/npc.1 index 03890fb..3e7af39 100644 --- a/docs/npc.1 +++ b/docs/npc.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH NPC 1 2024-06-17 "Harakit 0.13.11" +.TH NPC 1 2024-06-17 "Harakit X.X.X" .SH NAME npc \(en show non-printing characters .\" diff --git a/docs/rpn.1 b/docs/rpn.1 index f937889..8c8cd84 100644 --- a/docs/rpn.1 +++ b/docs/rpn.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH RPN 1 2024-06-17 "Harakit 0.13.11" +.TH RPN 1 2024-06-17 "Harakit X.X.X" .SH NAME rpn \(en reverse polish notation evaluation .\" diff --git a/docs/scrut.1 b/docs/scrut.1 index 541dcf2..56383b8 100644 --- a/docs/scrut.1 +++ b/docs/scrut.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SCRUT 1 2024-06-06 "Harakit 0.13.11" +.TH SCRUT 1 2024-06-06 "Harakit X.X.X" .SH NAME scrut \(en scrutinize file properties .SH SYNOPSIS diff --git a/docs/str.1 b/docs/str.1 index c4d68cc..22ffea1 100644 --- a/docs/str.1 +++ b/docs/str.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STR 1 2024-06-17 "Harakit 0.13.11" +.TH STR 1 2024-06-17 "Harakit X.X.X" .SH NAME str \(en test string arguments .\" diff --git a/docs/strcmp.1 b/docs/strcmp.1 index 781fc92..0ad21b2 100644 --- a/docs/strcmp.1 +++ b/docs/strcmp.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH STRCMP 1 2024-06-17 "Harakit 0.13.11" +.TH STRCMP 1 2024-06-17 "Harakit X.X.X" .SH NAME strcmp \(en compare strings .\" diff --git a/docs/swab.1 b/docs/swab.1 index 708a59b..72f0f19 100644 --- a/docs/swab.1 +++ b/docs/swab.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH SWAB 1 2024-06-17 "Harakit 0.13.11" +.TH SWAB 1 2024-06-17 "Harakit X.X.X" .SH NAME swab \(en swap bytes .\" diff --git a/docs/true.1 b/docs/true.1 index 15a4667..97af65b 100644 --- a/docs/true.1 +++ b/docs/true.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH TRUE 1 2024-06-06 "Harakit 0.13.11" +.TH TRUE 1 2024-06-06 "Harakit X.X.X" .SH NAME true \(en do nothing, successfully .\" From 2f87ad948f530f095b5821a9e60f4cd857df6a4e Mon Sep 17 00:00:00 2001 From: emma Date: Thu, 27 Jun 2024 14:04:31 -0600 Subject: [PATCH 129/134] strerror.rs(3), getopt.rs(3): renames --- Makefile | 14 +++++++------- src/{getopt.rs => libgetopt.rs} | 0 src/{strerror.rs => libstrerror.rs} | 0 3 files changed, 7 insertions(+), 7 deletions(-) rename src/{getopt.rs => libgetopt.rs} (100%) rename src/{strerror.rs => libstrerror.rs} (100%) diff --git a/Makefile b/Makefile index 2188b41..8109cd6 100644 --- a/Makefile +++ b/Makefile @@ -51,23 +51,23 @@ install: dist .PHONY: test test: build /tmp/getopt + /tmp/getopt tests/posix-compat.sh -/tmp/getopt: src/getopt.rs - $(RUSTC) --test -o /tmp/getopt src/getopt.rs - /tmp/getopt +/tmp/getopt: src/libgetopt.rs + $(RUSTC) --test -o /tmp/getopt src/libgetopt.rs .PHONY: rustlibs rustlibs: build/o/libsysexits.rlib build/o/libgetopt.rlib \ build/o/libstrerror.rlib -build/o/libgetopt.rlib: build src/getopt.rs +build/o/libgetopt.rlib: build src/libgetopt.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib --crate-name=getopt \ - -o $@ src/getopt.rs + -o $@ src/libgetopt.rs -build/o/libstrerror.rlib: build src/strerror.rs +build/o/libstrerror.rlib: build src/libstrerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ - src/strerror.rs + src/libstrerror.rs # bandage solution until bindgen(1) gets stdin support build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h diff --git a/src/getopt.rs b/src/libgetopt.rs similarity index 100% rename from src/getopt.rs rename to src/libgetopt.rs diff --git a/src/strerror.rs b/src/libstrerror.rs similarity index 100% rename from src/strerror.rs rename to src/libstrerror.rs From d07bb7da416b7bbefaae1d9df7402e27a319fc80 Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 28 Jun 2024 08:33:31 -0600 Subject: [PATCH 130/134] swab(1): untested move to new getopt bindings --- src/swab.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/swab.rs b/src/swab.rs index ca944d9..d997ddf 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -49,20 +49,16 @@ fn main() -> ExitCode { let mut force = false; let mut wordsize: usize = 2; - loop { - match opts.next() { - None => break, - Some(opt) => - match opt { - Ok(Opt('f', None)) => force = true, - Ok(Opt('w', Some(arg))) => { - match arg.parse::() { - Ok(w) if w % 2 == 0 => { wordsize = w; () }, - _ => { return usage(&argv[0]); }, - } - }, - _ => { return usage(&argv[0]); } - } + while let Some(opt) = argv.getopt("fw:") { + match opt.opt() { + Ok("f") => force = true, + Ok("w") => { + match arg.parse::() { + Ok(w) if w % 2 == 0 => { wordsize = w; () }, + _ => { return usage(&argv[0]); }, + } + }, + _ => { return usage(&argv[0]); } } } From 50bbee10a9b7403893dd64ae527fb852a70edfab Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 28 Jun 2024 10:22:20 -0600 Subject: [PATCH 131/134] libgetopt.rs(3): fixes typecasting for ARM devices --- src/libgetopt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libgetopt.rs b/src/libgetopt.rs index ee8cafa..8064c81 100644 --- a/src/libgetopt.rs +++ b/src/libgetopt.rs @@ -88,7 +88,7 @@ impl GetOpt for Vec { /* god knows what this does */ let boxed = Box::into_raw(c_strings.into_boxed_slice()); - let argv = boxed as *const *mut i8; + 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(); From 6bd19c072d1bf1ab0b8d472c14df66c8b115d6b1 Mon Sep 17 00:00:00 2001 From: DTB Date: Fri, 28 Jun 2024 17:43:32 -0600 Subject: [PATCH 132/134] swab(1): fix some silly mistakes --- src/swab.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/swab.rs b/src/swab.rs index d997ddf..810a6cb 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -24,7 +24,7 @@ use std::{ }; extern crate getopt; -use getopt::{ Opt, Parser }; +use getopt::GetOpt; extern crate sysexits; use sysexits::{ EX_OK, EX_OSERR, EX_USAGE }; @@ -45,7 +45,6 @@ fn main() -> ExitCode { let mut input = stdin(); let mut output = stdout().lock(); - let mut opts = Parser::new(&argv, "fw:"); let mut force = false; let mut wordsize: usize = 2; @@ -53,11 +52,13 @@ fn main() -> ExitCode { match opt.opt() { Ok("f") => force = true, Ok("w") => { - match arg.parse::() { + if let Some(arg) = opt.arg() { + match opt.arg().parse::() { Ok(w) if w % 2 == 0 => { wordsize = w; () }, _ => { return usage(&argv[0]); }, } - }, + } + }, _ => { return usage(&argv[0]); } } } From cf5136d247dcb3329f5f4488d10258449423ae1e Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 29 Jun 2024 07:49:47 -0600 Subject: [PATCH 133/134] Makefile, swab(1): fixes swab build --- Makefile | 6 ++---- src/swab.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8109cd6..8a9e936 100644 --- a/Makefile +++ b/Makefile @@ -133,10 +133,8 @@ build/bin/strcmp: src/strcmp.c build .PHONY: swab swab: build/bin/swab -build/bin/swab: src/swab.rs build build/o/libsysexits.rlib - $(RUSTC) $(RUSTFLAGS) --extern getopt=build/o/libgetopt.rlib \ - --extern sysexits=build/o/libsysexits.rlib \ - -o $@ src/swab.rs +build/bin/swab: src/swab.rs build rustlibs + $(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/swab.rs .PHONY: true true: build/bin/true diff --git a/src/swab.rs b/src/swab.rs index 810a6cb..d05b651 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -53,7 +53,7 @@ fn main() -> ExitCode { Ok("f") => force = true, Ok("w") => { if let Some(arg) = opt.arg() { - match opt.arg().parse::() { + match arg.parse::() { Ok(w) if w % 2 == 0 => { wordsize = w; () }, _ => { return usage(&argv[0]); }, } From 40984453e35c452c8ba71b98351a5d692055fc15 Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 29 Jun 2024 08:01:33 -0600 Subject: [PATCH 134/134] Makefile: better leverage targets for sysexits build --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 70f53b4..fb9aa5d 100644 --- a/Makefile +++ b/Makefile @@ -76,13 +76,14 @@ build/o/libstrerror.rlib: build src/libstrerror.rs $(RUSTC) $(RUSTFLAGS) --crate-type=lib -o $@ \ src/libstrerror.rs -# bandage solution until bindgen(1) gets stdin support -build/o/libsysexits.rlib: build $(SYSEXITS)sysexits.h - printf '\043define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h \ - > build/include/sysexits.h +build/o/libsysexits.rlib: build/include/sysexits.h bindgen --default-macro-constant-type signed --use-core --formatter=none \ build/include/sysexits.h | $(RUSTC) $(RUSTFLAGS) --crate-type lib -o $@ - +# bandage solution until bindgen(1) gets stdin support +build/include/sysexits.h: build $(SYSEXITS)sysexits.h + printf '\043define EXIT_FAILURE 1\n' | cat - $(SYSEXITS)sysexits.h > $@ + .PHONY: dj dj: build/bin/dj build/bin/dj: src/dj.c build