Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
90de81b5bd
|
|||
|
1bd190ae99
|
|||
|
791f44aa1e
|
|||
|
feac3bf4f8
|
|||
|
544b544d84
|
|||
|
1750329c51
|
|||
|
be6bd5386d
|
|||
|
3b44ddeedd
|
|||
|
8d8df711d9
|
|||
|
ac0f9e4019
|
|||
|
247e469f82
|
|||
|
8eece4cf84
|
12
CONDUCT
12
CONDUCT
@@ -36,9 +36,9 @@ issues, pull requests, and other endeavors in order to keep yourself and others
|
|||||||
from being overwhelmed with responsibility, either from your zeal or your
|
from being overwhelmed with responsibility, either from your zeal or your
|
||||||
negligence.
|
negligence.
|
||||||
|
|
||||||
If you notice an issue, open an issue as soon as you can. If you see a neglected
|
If you notice an issue, open an issue as soon as you can. If you see a
|
||||||
branch, open a pull request or comment on an existing one, if applicable. Be
|
neglected branch, open a pull request or comment on an existing one, if
|
||||||
diligent in your commitment to making this project work.
|
applicable. Be diligent in your commitment to making this project work.
|
||||||
|
|
||||||
6. Patience (Khanti)
|
6. Patience (Khanti)
|
||||||
|
|
||||||
@@ -81,3 +81,9 @@ more insight.
|
|||||||
|
|
||||||
[0] <https://www.dhammatalks.org/books/#/books/TenPerfections/Section0001.html>
|
[0] <https://www.dhammatalks.org/books/#/books/TenPerfections/Section0001.html>
|
||||||
[1] <https://www.fsf.org/news/publication-of-the-fsf-funded-white-papers-on-questions-around-copilot>
|
[1] <https://www.fsf.org/news/publication-of-the-fsf-funded-white-papers-on-questions-around-copilot>
|
||||||
|
|
||||||
|
--
|
||||||
|
Copyright © 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
|
||||||
|
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
||||||
|
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
|
|||||||
265
CONTRIBUTING
265
CONTRIBUTING
@@ -99,17 +99,247 @@ notice:
|
|||||||
Style
|
Style
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Make sure lines never exceed 80 columns in width when using four-character
|
“Everyone knows that debugging is twice as hard as writing a program in the
|
||||||
indentation steps. This helps contributors with smaller screens, those using
|
first place. So if you’re as clever as you can be when you write it, how
|
||||||
side-by-side editor windows or panes, and those who have no text wrapping in
|
will you ever debug it?”
|
||||||
their editor or terminal.
|
– Brian Kernighan, The Elements of Programming Style
|
||||||
|
|
||||||
For usage text and help messages, do not implement a -h option. Instead, print
|
The following guidelines are conducive to clear and readable code that is
|
||||||
usage information when any erroneous option is specified. Follow the NetBSD
|
consistent with the style of the rest of the Bonsai Computer System.
|
||||||
style guide for the usage text’s output format [0].
|
|
||||||
|
Use:
|
||||||
|
|
||||||
|
0. A single line for control flow statements short enough to be easily
|
||||||
|
understood at a glance:
|
||||||
|
|
||||||
|
if !(argc < 0) { usage(program_name); }
|
||||||
|
|
||||||
|
This applies to C switch statements and cases and Rust match statements, as
|
||||||
|
well:
|
||||||
|
|
||||||
|
switch (value) { /* aligning stuff to make it easier to read is fine */
|
||||||
|
case possibility: variable = foo; break;
|
||||||
|
default: variable = NULL; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
1. Switch cases in C and match arms in Rust should start another level of
|
||||||
|
indentation:
|
||||||
|
|
||||||
|
switch (value) {
|
||||||
|
case possibility:
|
||||||
|
statement;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
statement;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(n) => variable = n,
|
||||||
|
Err(e) => error = e,
|
||||||
|
}
|
||||||
|
|
||||||
|
2. Braces in control flow where their inclusion is left optional in C:
|
||||||
|
|
||||||
|
if (condition) { statement; }
|
||||||
|
|
||||||
|
3. Empty lines between different kinds of statements:
|
||||||
|
|
||||||
|
int t;
|
||||||
|
|
||||||
|
assert(io->bufuse > 0);
|
||||||
|
assert(io->bufuse <= io->bs);
|
||||||
|
|
||||||
|
if ((t = write(io->fd, io->buf, io->bufuse)) < 0) {
|
||||||
|
io->error = errno;
|
||||||
|
t = 0;
|
||||||
|
} else if (t > 0) {
|
||||||
|
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
|
||||||
|
}
|
||||||
|
|
||||||
|
io->bytes += t;
|
||||||
|
io->prec += (t > 0 && io->bufuse > 0);
|
||||||
|
io->rec += (t > 0 && io->bufuse == 0);
|
||||||
|
|
||||||
|
return io;
|
||||||
|
|
||||||
|
4. Compiler options that yield the most useful warnings, such as -Wpedantic in
|
||||||
|
a lot of C compilers. Fix the warnings, too [0].
|
||||||
|
|
||||||
|
5. One more level of indentation and one argument per line when a function
|
||||||
|
call or statement header is too long to fit on one line:
|
||||||
|
let usage = format!(
|
||||||
|
"Usage: {} [-d delimiter] index command [args...]",
|
||||||
|
argv[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
6. One more level of indentation than the keyword that initiated a multi-line
|
||||||
|
block.
|
||||||
|
|
||||||
|
if (condition) {
|
||||||
|
statement;
|
||||||
|
statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
7. The return value of all non-void functions, or explicitly ignore them (like
|
||||||
|
casting to void in C) [0]:
|
||||||
|
|
||||||
|
if ((a = malloc(sizeof char)) == NULL) { /* handle this error */
|
||||||
|
(void)fprintf(stderr, "oh noes!"); /* explicitly ignore this one */
|
||||||
|
return EX_OSERR; /* ...because the program is exiting anyway */
|
||||||
|
}
|
||||||
|
|
||||||
|
8. The smallest possible scope for data [0].
|
||||||
|
|
||||||
|
9. Comments noting all the symbols and macros used from a C header file, next
|
||||||
|
to its include macro:
|
||||||
|
|
||||||
|
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
||||||
|
(space-aligned) * optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
||||||
|
|
||||||
|
10. Spaces in control flow statements, after the keyword and before the
|
||||||
|
opening brace:
|
||||||
|
|
||||||
|
for (i = 2; i < argc; ++i) {
|
||||||
|
|
||||||
|
|
||||||
|
11. In Rust, a trailing comma on all arguments or fields that are on their own
|
||||||
|
lines:
|
||||||
|
|
||||||
|
return Err(EvaluationError {
|
||||||
|
message: format!("{}: Invalid token", i),
|
||||||
|
code: EX_DATAERR,
|
||||||
|
})
|
||||||
|
|
||||||
|
12. In Rust, place extern statements after use statements that include standard
|
||||||
|
library crates. Group like statements:
|
||||||
|
|
||||||
|
use std::fs::Path;
|
||||||
|
|
||||||
|
extern crate strerror;
|
||||||
|
extern crate sysexits;
|
||||||
|
|
||||||
|
use strerror::StrError;
|
||||||
|
use sysexits::{ EX_OSERR, EX_USAGE };
|
||||||
|
|
||||||
|
13. If text is on the same line as a brace, spaces after an opening brace and
|
||||||
|
before a closing one:
|
||||||
|
|
||||||
|
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
||||||
|
|
||||||
|
14. Alphabetic sorting, where applicable:
|
||||||
|
|
||||||
|
use std::io::{ BufWriter, Read, Write, stderr, stdin, stdout }
|
||||||
|
|
||||||
|
15. In Rust, use the to_owned() method on string types (str, OsStr, CStr, etc.)
|
||||||
|
and the to_string() method on other types.
|
||||||
|
|
||||||
|
|
||||||
|
Avoid:
|
||||||
|
|
||||||
|
16. Unbounded loops [0].
|
||||||
|
|
||||||
|
17. Function pointers [0].
|
||||||
|
|
||||||
|
18. Heap memory allocation [0].
|
||||||
|
|
||||||
|
19. Using too much nested logic (within reason).
|
||||||
|
|
||||||
|
20. Too many levels of dereferences [0]:
|
||||||
|
|
||||||
|
/* do not do this */
|
||||||
|
for (size_t i = 0; i < sizeof a / sizeof *a; ++i) {
|
||||||
|
if (a[i].id == MATCH) { a[i].val = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do this */
|
||||||
|
for (struct MadeUp *s = &a[0]; *s != NULL; s = &s[1]) {
|
||||||
|
if (s->id == MATCH) { s->val = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
21. Using C preprocessor macros; the fewer, the better [0].
|
||||||
|
|
||||||
|
22. The exit(3p) and std::process::exit() functions; returning from the main
|
||||||
|
function skips a system call.
|
||||||
|
|
||||||
|
|
||||||
|
Do not use:
|
||||||
|
|
||||||
|
23. More than the length of one printed page for a function [0].
|
||||||
|
|
||||||
|
24. Recursion, as it’s complex and can unexpectedly overflow the stack [0].
|
||||||
|
|
||||||
|
25. Any functionality not in the POSIX C specification and language features not
|
||||||
|
in C99.
|
||||||
|
|
||||||
|
26. Do-while loops, as they’re unique to C and confusing for casual programmers.
|
||||||
|
|
||||||
|
27. Labels and goto statements; use sensible flow control [0].
|
||||||
|
|
||||||
|
28. Pointer arithmetic, as it tends to be confusing and unnecessary; use
|
||||||
|
index-reference patterns like &p[1] instead of p + 1. &p[n] is the address at
|
||||||
|
p + sizeof p * n, not p + n, like pointer arithmetic suggests.
|
||||||
|
|
||||||
|
29. C struct bitfields in unions, to access certain bits of bigger data types,
|
||||||
|
as it’s poorly defined in the C standards; use bit arithmetic.
|
||||||
|
|
||||||
|
30. C trigraphs.
|
||||||
|
|
||||||
|
31. Inclusions in C header files, to prevent multiple file inclusions.
|
||||||
|
|
||||||
|
32. C preprocessor variables to prevent multiple inclusions of the same file,
|
||||||
|
such as:
|
||||||
|
|
||||||
|
#ifdef _FILE
|
||||||
|
#define _FILE
|
||||||
|
/* file body */
|
||||||
|
#endif /* ifdef _FILE */
|
||||||
|
|
||||||
|
Instead, take the time to ensure other files aren’t including any files twice.
|
||||||
|
|
||||||
|
33. The gets(3p) function from <stdio.h>, as it’s impossible to prevent buffer
|
||||||
|
overflows when it's used; use fgets(3p) from <stdio.h>.
|
||||||
|
|
||||||
|
34. The scanf(3p) function from <stdio.h> [1].
|
||||||
|
|
||||||
|
35. Any functionality not described in the latest POSIX make(1) specification.
|
||||||
|
|
||||||
|
36. Macros which panic on failure in Rust (such as the print!() and println!()
|
||||||
|
macros). Use a function and handle any errors. However, do use the eprintln!()
|
||||||
|
macro for error messages. Handling an error for writing an error message is
|
||||||
|
redundant.
|
||||||
|
|
||||||
|
37. A -h option for help text. Instead, print usage information when any
|
||||||
|
erroneous option is specified. See the Usage Text section below.
|
||||||
|
|
||||||
|
38. Lines which exceed 80 columns in width when using four-column indentation
|
||||||
|
steps. This helps contributors with smaller screens, those using side-by-side
|
||||||
|
editor windows or panes, and those who have no text wrapping in their editor or
|
||||||
|
terminal.
|
||||||
|
|
||||||
|
|
||||||
|
Usage Text
|
||||||
|
==========
|
||||||
|
|
||||||
|
This section is adapted from the NetBSD style guide [2].
|
||||||
|
|
||||||
|
When programs are invoked incorrectly and in the synopsis of manual pages, uasge
|
||||||
|
text should be provided to the user. The following is the format used by this
|
||||||
|
project for this purpose:
|
||||||
|
|
||||||
|
All optional arguments are to be placed in square brackets (U+005B, U+005D).
|
||||||
|
Mutually exclusive arguments can be separated by a vertical line (U+007C).
|
||||||
|
Groups of arguments should be specified in alphabetical order in most cases. The
|
||||||
|
order of arguments and an example of these rules follows:
|
||||||
|
|
||||||
|
0. Options with no option arguments.
|
||||||
|
1. Options with option arguments. Arguments should be specified inside the same
|
||||||
|
square brackets as the options.
|
||||||
|
3. Non-option arguments.
|
||||||
|
|
||||||
|
"usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
|
||||||
|
"usage: f [-a | -b] [-c [-de] [-n number]]\n"
|
||||||
|
|
||||||
If committing a new utility, please include tests and documentation (see
|
|
||||||
tests/ and docs/) for the new tool.
|
|
||||||
|
|
||||||
Committing
|
Committing
|
||||||
==========
|
==========
|
||||||
@@ -117,6 +347,10 @@ Committing
|
|||||||
When contributing to Bonsai, please sign your commit with a PGP key and create
|
When contributing to Bonsai, please sign your commit with a PGP key and create
|
||||||
the commit with an identity which can be easily contacted.
|
the commit with an identity which can be easily contacted.
|
||||||
|
|
||||||
|
If committing a new utility, please include tests and documentation (see
|
||||||
|
tests/ and docs/) for the new tool.
|
||||||
|
|
||||||
|
|
||||||
Format commit messages following these guidelines:
|
Format commit messages following these guidelines:
|
||||||
|
|
||||||
$ git commit -m 'tool(1): add feature x'
|
$ git commit -m 'tool(1): add feature x'
|
||||||
@@ -147,9 +381,16 @@ Commit messages should be written in the present tense.
|
|||||||
References
|
References
|
||||||
==========
|
==========
|
||||||
|
|
||||||
[0] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
[0] <https://web.eecs.umich.edu/~imarkov/10rules.pdf>
|
||||||
|
[1] <http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html>
|
||||||
|
[2] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
This work © 2023–2024 by Emma Tebibyte is licensed under CC BY-SA 4.0. To view a
|
|
||||||
copy of this license, visit <http://creativecommons.org/licenses/by-sa/4.0/>
|
Copyright © 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
Copyright © 2024 DTB <trinity@trinity.moe>
|
||||||
|
Copyright © Wikipedia contributors
|
||||||
|
|
||||||
|
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
||||||
|
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
|
|||||||
428
COPYING.DOC
Normal file
428
COPYING.DOC
Normal file
@@ -0,0 +1,428 @@
|
|||||||
|
Attribution-ShareAlike 4.0 International
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
||||||
|
does not provide legal services or legal advice. Distribution of
|
||||||
|
Creative Commons public licenses does not create a lawyer-client or
|
||||||
|
other relationship. Creative Commons makes its licenses and related
|
||||||
|
information available on an "as-is" basis. Creative Commons gives no
|
||||||
|
warranties regarding its licenses, any material licensed under their
|
||||||
|
terms and conditions, or any related information. Creative Commons
|
||||||
|
disclaims all liability for damages resulting from their use to the
|
||||||
|
fullest extent possible.
|
||||||
|
|
||||||
|
Using Creative Commons Public Licenses
|
||||||
|
|
||||||
|
Creative Commons public licenses provide a standard set of terms and
|
||||||
|
conditions that creators and other rights holders may use to share
|
||||||
|
original works of authorship and other material subject to copyright
|
||||||
|
and certain other rights specified in the public license below. The
|
||||||
|
following considerations are for informational purposes only, are not
|
||||||
|
exhaustive, and do not form part of our licenses.
|
||||||
|
|
||||||
|
Considerations for licensors: Our public licenses are
|
||||||
|
intended for use by those authorized to give the public
|
||||||
|
permission to use material in ways otherwise restricted by
|
||||||
|
copyright and certain other rights. Our licenses are
|
||||||
|
irrevocable. Licensors should read and understand the terms
|
||||||
|
and conditions of the license they choose before applying it.
|
||||||
|
Licensors should also secure all rights necessary before
|
||||||
|
applying our licenses so that the public can reuse the
|
||||||
|
material as expected. Licensors should clearly mark any
|
||||||
|
material not subject to the license. This includes other CC-
|
||||||
|
licensed material, or material used under an exception or
|
||||||
|
limitation to copyright. More considerations for licensors:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensors
|
||||||
|
|
||||||
|
Considerations for the public: By using one of our public
|
||||||
|
licenses, a licensor grants the public permission to use the
|
||||||
|
licensed material under specified terms and conditions. If
|
||||||
|
the licensor's permission is not necessary for any reason--for
|
||||||
|
example, because of any applicable exception or limitation to
|
||||||
|
copyright--then that use is not regulated by the license. Our
|
||||||
|
licenses grant only permissions under copyright and certain
|
||||||
|
other rights that a licensor has authority to grant. Use of
|
||||||
|
the licensed material may still be restricted for other
|
||||||
|
reasons, including because others have copyright or other
|
||||||
|
rights in the material. A licensor may make special requests,
|
||||||
|
such as asking that all changes be marked or described.
|
||||||
|
Although not required by our licenses, you are encouraged to
|
||||||
|
respect those requests where reasonable. More considerations
|
||||||
|
for the public:
|
||||||
|
wiki.creativecommons.org/Considerations_for_licensees
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons Attribution-ShareAlike 4.0 International Public
|
||||||
|
License
|
||||||
|
|
||||||
|
By exercising the Licensed Rights (defined below), You accept and agree
|
||||||
|
to be bound by the terms and conditions of this Creative Commons
|
||||||
|
Attribution-ShareAlike 4.0 International Public License ("Public
|
||||||
|
License"). To the extent this Public License may be interpreted as a
|
||||||
|
contract, You are granted the Licensed Rights in consideration of Your
|
||||||
|
acceptance of these terms and conditions, and the Licensor grants You
|
||||||
|
such rights in consideration of benefits the Licensor receives from
|
||||||
|
making the Licensed Material available under these terms and
|
||||||
|
conditions.
|
||||||
|
|
||||||
|
|
||||||
|
Section 1 -- Definitions.
|
||||||
|
|
||||||
|
a. Adapted Material means material subject to Copyright and Similar
|
||||||
|
Rights that is derived from or based upon the Licensed Material
|
||||||
|
and in which the Licensed Material is translated, altered,
|
||||||
|
arranged, transformed, or otherwise modified in a manner requiring
|
||||||
|
permission under the Copyright and Similar Rights held by the
|
||||||
|
Licensor. For purposes of this Public License, where the Licensed
|
||||||
|
Material is a musical work, performance, or sound recording,
|
||||||
|
Adapted Material is always produced where the Licensed Material is
|
||||||
|
synched in timed relation with a moving image.
|
||||||
|
|
||||||
|
b. Adapter's License means the license You apply to Your Copyright
|
||||||
|
and Similar Rights in Your contributions to Adapted Material in
|
||||||
|
accordance with the terms and conditions of this Public License.
|
||||||
|
|
||||||
|
c. BY-SA Compatible License means a license listed at
|
||||||
|
creativecommons.org/compatiblelicenses, approved by Creative
|
||||||
|
Commons as essentially the equivalent of this Public License.
|
||||||
|
|
||||||
|
d. Copyright and Similar Rights means copyright and/or similar rights
|
||||||
|
closely related to copyright including, without limitation,
|
||||||
|
performance, broadcast, sound recording, and Sui Generis Database
|
||||||
|
Rights, without regard to how the rights are labeled or
|
||||||
|
categorized. For purposes of this Public License, the rights
|
||||||
|
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
||||||
|
Rights.
|
||||||
|
|
||||||
|
e. Effective Technological Measures means those measures that, in the
|
||||||
|
absence of proper authority, may not be circumvented under laws
|
||||||
|
fulfilling obligations under Article 11 of the WIPO Copyright
|
||||||
|
Treaty adopted on December 20, 1996, and/or similar international
|
||||||
|
agreements.
|
||||||
|
|
||||||
|
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
||||||
|
any other exception or limitation to Copyright and Similar Rights
|
||||||
|
that applies to Your use of the Licensed Material.
|
||||||
|
|
||||||
|
g. License Elements means the license attributes listed in the name
|
||||||
|
of a Creative Commons Public License. The License Elements of this
|
||||||
|
Public License are Attribution and ShareAlike.
|
||||||
|
|
||||||
|
h. Licensed Material means the artistic or literary work, database,
|
||||||
|
or other material to which the Licensor applied this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
i. Licensed Rights means the rights granted to You subject to the
|
||||||
|
terms and conditions of this Public License, which are limited to
|
||||||
|
all Copyright and Similar Rights that apply to Your use of the
|
||||||
|
Licensed Material and that the Licensor has authority to license.
|
||||||
|
|
||||||
|
j. Licensor means the individual(s) or entity(ies) granting rights
|
||||||
|
under this Public License.
|
||||||
|
|
||||||
|
k. Share means to provide material to the public by any means or
|
||||||
|
process that requires permission under the Licensed Rights, such
|
||||||
|
as reproduction, public display, public performance, distribution,
|
||||||
|
dissemination, communication, or importation, and to make material
|
||||||
|
available to the public including in ways that members of the
|
||||||
|
public may access the material from a place and at a time
|
||||||
|
individually chosen by them.
|
||||||
|
|
||||||
|
l. Sui Generis Database Rights means rights other than copyright
|
||||||
|
resulting from Directive 96/9/EC of the European Parliament and of
|
||||||
|
the Council of 11 March 1996 on the legal protection of databases,
|
||||||
|
as amended and/or succeeded, as well as other essentially
|
||||||
|
equivalent rights anywhere in the world.
|
||||||
|
|
||||||
|
m. You means the individual or entity exercising the Licensed Rights
|
||||||
|
under this Public License. Your has a corresponding meaning.
|
||||||
|
|
||||||
|
|
||||||
|
Section 2 -- Scope.
|
||||||
|
|
||||||
|
a. License grant.
|
||||||
|
|
||||||
|
1. Subject to the terms and conditions of this Public License,
|
||||||
|
the Licensor hereby grants You a worldwide, royalty-free,
|
||||||
|
non-sublicensable, non-exclusive, irrevocable license to
|
||||||
|
exercise the Licensed Rights in the Licensed Material to:
|
||||||
|
|
||||||
|
a. reproduce and Share the Licensed Material, in whole or
|
||||||
|
in part; and
|
||||||
|
|
||||||
|
b. produce, reproduce, and Share Adapted Material.
|
||||||
|
|
||||||
|
2. Exceptions and Limitations. For the avoidance of doubt, where
|
||||||
|
Exceptions and Limitations apply to Your use, this Public
|
||||||
|
License does not apply, and You do not need to comply with
|
||||||
|
its terms and conditions.
|
||||||
|
|
||||||
|
3. Term. The term of this Public License is specified in Section
|
||||||
|
6(a).
|
||||||
|
|
||||||
|
4. Media and formats; technical modifications allowed. The
|
||||||
|
Licensor authorizes You to exercise the Licensed Rights in
|
||||||
|
all media and formats whether now known or hereafter created,
|
||||||
|
and to make technical modifications necessary to do so. The
|
||||||
|
Licensor waives and/or agrees not to assert any right or
|
||||||
|
authority to forbid You from making technical modifications
|
||||||
|
necessary to exercise the Licensed Rights, including
|
||||||
|
technical modifications necessary to circumvent Effective
|
||||||
|
Technological Measures. For purposes of this Public License,
|
||||||
|
simply making modifications authorized by this Section 2(a)
|
||||||
|
(4) never produces Adapted Material.
|
||||||
|
|
||||||
|
5. Downstream recipients.
|
||||||
|
|
||||||
|
a. Offer from the Licensor -- Licensed Material. Every
|
||||||
|
recipient of the Licensed Material automatically
|
||||||
|
receives an offer from the Licensor to exercise the
|
||||||
|
Licensed Rights under the terms and conditions of this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
b. Additional offer from the Licensor -- Adapted Material.
|
||||||
|
Every recipient of Adapted Material from You
|
||||||
|
automatically receives an offer from the Licensor to
|
||||||
|
exercise the Licensed Rights in the Adapted Material
|
||||||
|
under the conditions of the Adapter's License You apply.
|
||||||
|
|
||||||
|
c. No downstream restrictions. You may not offer or impose
|
||||||
|
any additional or different terms or conditions on, or
|
||||||
|
apply any Effective Technological Measures to, the
|
||||||
|
Licensed Material if doing so restricts exercise of the
|
||||||
|
Licensed Rights by any recipient of the Licensed
|
||||||
|
Material.
|
||||||
|
|
||||||
|
6. No endorsement. Nothing in this Public License constitutes or
|
||||||
|
may be construed as permission to assert or imply that You
|
||||||
|
are, or that Your use of the Licensed Material is, connected
|
||||||
|
with, or sponsored, endorsed, or granted official status by,
|
||||||
|
the Licensor or others designated to receive attribution as
|
||||||
|
provided in Section 3(a)(1)(A)(i).
|
||||||
|
|
||||||
|
b. Other rights.
|
||||||
|
|
||||||
|
1. Moral rights, such as the right of integrity, are not
|
||||||
|
licensed under this Public License, nor are publicity,
|
||||||
|
privacy, and/or other similar personality rights; however, to
|
||||||
|
the extent possible, the Licensor waives and/or agrees not to
|
||||||
|
assert any such rights held by the Licensor to the limited
|
||||||
|
extent necessary to allow You to exercise the Licensed
|
||||||
|
Rights, but not otherwise.
|
||||||
|
|
||||||
|
2. Patent and trademark rights are not licensed under this
|
||||||
|
Public License.
|
||||||
|
|
||||||
|
3. To the extent possible, the Licensor waives any right to
|
||||||
|
collect royalties from You for the exercise of the Licensed
|
||||||
|
Rights, whether directly or through a collecting society
|
||||||
|
under any voluntary or waivable statutory or compulsory
|
||||||
|
licensing scheme. In all other cases the Licensor expressly
|
||||||
|
reserves any right to collect such royalties.
|
||||||
|
|
||||||
|
|
||||||
|
Section 3 -- License Conditions.
|
||||||
|
|
||||||
|
Your exercise of the Licensed Rights is expressly made subject to the
|
||||||
|
following conditions.
|
||||||
|
|
||||||
|
a. Attribution.
|
||||||
|
|
||||||
|
1. If You Share the Licensed Material (including in modified
|
||||||
|
form), You must:
|
||||||
|
|
||||||
|
a. retain the following if it is supplied by the Licensor
|
||||||
|
with the Licensed Material:
|
||||||
|
|
||||||
|
i. identification of the creator(s) of the Licensed
|
||||||
|
Material and any others designated to receive
|
||||||
|
attribution, in any reasonable manner requested by
|
||||||
|
the Licensor (including by pseudonym if
|
||||||
|
designated);
|
||||||
|
|
||||||
|
ii. a copyright notice;
|
||||||
|
|
||||||
|
iii. a notice that refers to this Public License;
|
||||||
|
|
||||||
|
iv. a notice that refers to the disclaimer of
|
||||||
|
warranties;
|
||||||
|
|
||||||
|
v. a URI or hyperlink to the Licensed Material to the
|
||||||
|
extent reasonably practicable;
|
||||||
|
|
||||||
|
b. indicate if You modified the Licensed Material and
|
||||||
|
retain an indication of any previous modifications; and
|
||||||
|
|
||||||
|
c. indicate the Licensed Material is licensed under this
|
||||||
|
Public License, and include the text of, or the URI or
|
||||||
|
hyperlink to, this Public License.
|
||||||
|
|
||||||
|
2. You may satisfy the conditions in Section 3(a)(1) in any
|
||||||
|
reasonable manner based on the medium, means, and context in
|
||||||
|
which You Share the Licensed Material. For example, it may be
|
||||||
|
reasonable to satisfy the conditions by providing a URI or
|
||||||
|
hyperlink to a resource that includes the required
|
||||||
|
information.
|
||||||
|
|
||||||
|
3. If requested by the Licensor, You must remove any of the
|
||||||
|
information required by Section 3(a)(1)(A) to the extent
|
||||||
|
reasonably practicable.
|
||||||
|
|
||||||
|
b. ShareAlike.
|
||||||
|
|
||||||
|
In addition to the conditions in Section 3(a), if You Share
|
||||||
|
Adapted Material You produce, the following conditions also apply.
|
||||||
|
|
||||||
|
1. The Adapter's License You apply must be a Creative Commons
|
||||||
|
license with the same License Elements, this version or
|
||||||
|
later, or a BY-SA Compatible License.
|
||||||
|
|
||||||
|
2. You must include the text of, or the URI or hyperlink to, the
|
||||||
|
Adapter's License You apply. You may satisfy this condition
|
||||||
|
in any reasonable manner based on the medium, means, and
|
||||||
|
context in which You Share Adapted Material.
|
||||||
|
|
||||||
|
3. You may not offer or impose any additional or different terms
|
||||||
|
or conditions on, or apply any Effective Technological
|
||||||
|
Measures to, Adapted Material that restrict exercise of the
|
||||||
|
rights granted under the Adapter's License You apply.
|
||||||
|
|
||||||
|
|
||||||
|
Section 4 -- Sui Generis Database Rights.
|
||||||
|
|
||||||
|
Where the Licensed Rights include Sui Generis Database Rights that
|
||||||
|
apply to Your use of the Licensed Material:
|
||||||
|
|
||||||
|
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
||||||
|
to extract, reuse, reproduce, and Share all or a substantial
|
||||||
|
portion of the contents of the database;
|
||||||
|
|
||||||
|
b. if You include all or a substantial portion of the database
|
||||||
|
contents in a database in which You have Sui Generis Database
|
||||||
|
Rights, then the database in which You have Sui Generis Database
|
||||||
|
Rights (but not its individual contents) is Adapted Material,
|
||||||
|
including for purposes of Section 3(b); and
|
||||||
|
|
||||||
|
c. You must comply with the conditions in Section 3(a) if You Share
|
||||||
|
all or a substantial portion of the contents of the database.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 4 supplements and does not
|
||||||
|
replace Your obligations under this Public License where the Licensed
|
||||||
|
Rights include other Copyright and Similar Rights.
|
||||||
|
|
||||||
|
|
||||||
|
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
||||||
|
|
||||||
|
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
||||||
|
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
||||||
|
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
||||||
|
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
||||||
|
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
||||||
|
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
||||||
|
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
||||||
|
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
||||||
|
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
||||||
|
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
||||||
|
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
||||||
|
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
||||||
|
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
||||||
|
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
||||||
|
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
||||||
|
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
||||||
|
|
||||||
|
c. The disclaimer of warranties and limitation of liability provided
|
||||||
|
above shall be interpreted in a manner that, to the extent
|
||||||
|
possible, most closely approximates an absolute disclaimer and
|
||||||
|
waiver of all liability.
|
||||||
|
|
||||||
|
|
||||||
|
Section 6 -- Term and Termination.
|
||||||
|
|
||||||
|
a. This Public License applies for the term of the Copyright and
|
||||||
|
Similar Rights licensed here. However, if You fail to comply with
|
||||||
|
this Public License, then Your rights under this Public License
|
||||||
|
terminate automatically.
|
||||||
|
|
||||||
|
b. Where Your right to use the Licensed Material has terminated under
|
||||||
|
Section 6(a), it reinstates:
|
||||||
|
|
||||||
|
1. automatically as of the date the violation is cured, provided
|
||||||
|
it is cured within 30 days of Your discovery of the
|
||||||
|
violation; or
|
||||||
|
|
||||||
|
2. upon express reinstatement by the Licensor.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Section 6(b) does not affect any
|
||||||
|
right the Licensor may have to seek remedies for Your violations
|
||||||
|
of this Public License.
|
||||||
|
|
||||||
|
c. For the avoidance of doubt, the Licensor may also offer the
|
||||||
|
Licensed Material under separate terms or conditions or stop
|
||||||
|
distributing the Licensed Material at any time; however, doing so
|
||||||
|
will not terminate this Public License.
|
||||||
|
|
||||||
|
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 7 -- Other Terms and Conditions.
|
||||||
|
|
||||||
|
a. The Licensor shall not be bound by any additional or different
|
||||||
|
terms or conditions communicated by You unless expressly agreed.
|
||||||
|
|
||||||
|
b. Any arrangements, understandings, or agreements regarding the
|
||||||
|
Licensed Material not stated herein are separate from and
|
||||||
|
independent of the terms and conditions of this Public License.
|
||||||
|
|
||||||
|
|
||||||
|
Section 8 -- Interpretation.
|
||||||
|
|
||||||
|
a. For the avoidance of doubt, this Public License does not, and
|
||||||
|
shall not be interpreted to, reduce, limit, restrict, or impose
|
||||||
|
conditions on any use of the Licensed Material that could lawfully
|
||||||
|
be made without permission under this Public License.
|
||||||
|
|
||||||
|
b. To the extent possible, if any provision of this Public License is
|
||||||
|
deemed unenforceable, it shall be automatically reformed to the
|
||||||
|
minimum extent necessary to make it enforceable. If the provision
|
||||||
|
cannot be reformed, it shall be severed from this Public License
|
||||||
|
without affecting the enforceability of the remaining terms and
|
||||||
|
conditions.
|
||||||
|
|
||||||
|
c. No term or condition of this Public License will be waived and no
|
||||||
|
failure to comply consented to unless expressly agreed to by the
|
||||||
|
Licensor.
|
||||||
|
|
||||||
|
d. Nothing in this Public License constitutes or may be interpreted
|
||||||
|
as a limitation upon, or waiver of, any privileges and immunities
|
||||||
|
that apply to the Licensor or You, including from the legal
|
||||||
|
processes of any jurisdiction or authority.
|
||||||
|
|
||||||
|
|
||||||
|
=======================================================================
|
||||||
|
|
||||||
|
Creative Commons is not a party to its public
|
||||||
|
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
||||||
|
its public licenses to material it publishes and in those instances
|
||||||
|
will be considered the “Licensor.” The text of the Creative Commons
|
||||||
|
public licenses is dedicated to the public domain under the CC0 Public
|
||||||
|
Domain Dedication. Except for the limited purpose of indicating that
|
||||||
|
material is shared under a Creative Commons public license or as
|
||||||
|
otherwise permitted by the Creative Commons policies published at
|
||||||
|
creativecommons.org/policies, Creative Commons does not authorize the
|
||||||
|
use of the trademark "Creative Commons" or any other trademark or logo
|
||||||
|
of Creative Commons without its prior written consent including,
|
||||||
|
without limitation, in connection with any unauthorized modifications
|
||||||
|
to any of its public licenses or any other arrangements,
|
||||||
|
understandings, or agreements concerning use of licensed material. For
|
||||||
|
the avoidance of doubt, this paragraph does not form part of the
|
||||||
|
public licenses.
|
||||||
|
|
||||||
|
Creative Commons may be contacted at creativecommons.org.
|
||||||
|
|
||||||
8
Makefile
8
Makefile
@@ -5,8 +5,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# 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
|
# The octal escape \043 is utilized twice in this file as make(1p) will
|
||||||
# interpret a hash in a rule as an inline comment.
|
# interpret a hash in a rule as an inline comment.
|
||||||
@@ -62,7 +62,7 @@ dist: all docs
|
|||||||
install: dist
|
install: dist
|
||||||
cp -r $(DESTDIR)/* /
|
cp -r $(DESTDIR)/* /
|
||||||
|
|
||||||
TESTFILES != for file in tests/*.mk; do printf '%s ' "$$file"; done
|
TESTFILES != ls tests/*.mk
|
||||||
|
|
||||||
TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \
|
TESTS != printf '%s\n' "$(TESTFILES)" | xargs -n1 basename \
|
||||||
| sed 's/\.mk/_tests/g'
|
| sed 's/\.mk/_tests/g'
|
||||||
@@ -120,7 +120,7 @@ build/bin/false: src/false.c build
|
|||||||
.PHONY: fileis
|
.PHONY: fileis
|
||||||
fileis: build/bin/fileis
|
fileis: build/bin/fileis
|
||||||
build/bin/fileis: src/fileis.rs build rustlibs
|
build/bin/fileis: src/fileis.rs build rustlibs
|
||||||
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/fileis.rs
|
$(RUSTC) $(RUSTFLAGS) -o $@ src/fileis.rs
|
||||||
|
|
||||||
.PHONY: fop
|
.PHONY: fop
|
||||||
fop: build/bin/fop
|
fop: build/bin/fop
|
||||||
|
|||||||
9
README
9
README
@@ -14,11 +14,12 @@ utilities do, but to invent new utilities to perform the same tasks in more
|
|||||||
intuitive ways. GNU and BSD extensions are convenient but often unhealthy,
|
intuitive ways. GNU and BSD extensions are convenient but often unhealthy,
|
||||||
forgetting the purposes of the tools they extend, or building into existing
|
forgetting the purposes of the tools they extend, or building into existing
|
||||||
utilities features that would be more useful as their own tools to be used
|
utilities features that would be more useful as their own tools to be used
|
||||||
anywhere. Other utility sets aim to provide a number of fully-featured
|
anywhere. Other utility sets aim to provide a number of fully-featured programs
|
||||||
programs to be used individually, Harakit utilities are meant to be easily
|
to be used individually, Harakit utilities are meant to be easily composable
|
||||||
composable and work together in pipelines.
|
and work together in pipelines.
|
||||||
|
|
||||||
See docs/ for more on the specific utilities currently implemented.
|
See docs/ for more on the specific utilities currently implemented and see
|
||||||
|
CONTRIBUTING for guidelines for contributions.
|
||||||
|
|
||||||
|
|
||||||
Building
|
Building
|
||||||
|
|||||||
254
STYLE
254
STYLE
@@ -1,254 +0,0 @@
|
|||||||
“Everyone knows that debugging is twice as hard as writing a program in the
|
|
||||||
first place. So if you’re as clever as you can be when you write it, how
|
|
||||||
will you ever debug it?”
|
|
||||||
– Brian Kernighan, The Elements of Programming Style
|
|
||||||
|
|
||||||
|
|
||||||
The following guidelines are conducive to clear and readable code that is
|
|
||||||
consistent with the style of the rest of the Bonsai Computer System.
|
|
||||||
|
|
||||||
|
|
||||||
Use
|
|
||||||
===
|
|
||||||
|
|
||||||
0. A single line for control flow statements short enough to be easily
|
|
||||||
understood at a glance:
|
|
||||||
|
|
||||||
if !(argc < 0) { usage(program_name); }
|
|
||||||
|
|
||||||
This applies to C switch statements and cases and Rust match statements, as
|
|
||||||
well:
|
|
||||||
|
|
||||||
switch (value) { /* aligning stuff to make it easier to read is fine */
|
|
||||||
case possibility: variable = foo; break;
|
|
||||||
default: variable = NULL; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
1. Switch cases in C and match arms in Rust should start another level of
|
|
||||||
indentation:
|
|
||||||
|
|
||||||
switch (value) {
|
|
||||||
case possibility:
|
|
||||||
statement;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
statement;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(n) => variable = n,
|
|
||||||
Err(e) => error = e,
|
|
||||||
}
|
|
||||||
|
|
||||||
2. Braces in control flow where their inclusion is left optional in C:
|
|
||||||
|
|
||||||
if (condition) { statement; }
|
|
||||||
|
|
||||||
3. Empty lines between different kinds of statements:
|
|
||||||
|
|
||||||
int t;
|
|
||||||
|
|
||||||
assert(io->bufuse > 0);
|
|
||||||
assert(io->bufuse <= io->bs);
|
|
||||||
|
|
||||||
if ((t = write(io->fd, io->buf, io->bufuse)) < 0) {
|
|
||||||
io->error = errno;
|
|
||||||
t = 0;
|
|
||||||
} else if (t > 0) {
|
|
||||||
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
|
|
||||||
}
|
|
||||||
|
|
||||||
io->bytes += t;
|
|
||||||
io->prec += (t > 0 && io->bufuse > 0);
|
|
||||||
io->rec += (t > 0 && io->bufuse == 0);
|
|
||||||
|
|
||||||
return io;
|
|
||||||
|
|
||||||
4. Compiler options that yield the most useful warnings, such as -Wpedantic in
|
|
||||||
a lot of C compilers. Fix the warnings, too [0].
|
|
||||||
|
|
||||||
5. One more level of indentation and one argument per line when a function
|
|
||||||
call or statement header is too long to fit on one line:
|
|
||||||
|
|
||||||
let usage = format!(
|
|
||||||
"Usage: {} [-d delimiter] index command [args...]",
|
|
||||||
argv[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
6. One more level of indentation than the keyword that initiated a multi-line
|
|
||||||
block.
|
|
||||||
|
|
||||||
if (condition) {
|
|
||||||
statement;
|
|
||||||
statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
7. The return value of all non-void functions, or explicitly ignore them (like
|
|
||||||
casting to void in C) [0]:
|
|
||||||
|
|
||||||
if ((a = malloc(sizeof char)) == NULL) { /* handle this error */
|
|
||||||
(void)fprintf(stderr, "oh noes!"); /* explicitly ignore this one */
|
|
||||||
return EX_OSERR; /* ...because the program is exiting anyway */
|
|
||||||
}
|
|
||||||
|
|
||||||
8. The smallest possible scope for data [0].
|
|
||||||
|
|
||||||
9. Comments noting all the symbols and macros used from a C header file, next
|
|
||||||
to its include macro:
|
|
||||||
|
|
||||||
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
|
||||||
(space-aligned) * optarg, optind, STDIN_FILENO, STDOUT_FILENO */
|
|
||||||
|
|
||||||
10. Spaces in control flow statements, after the keyword and before the
|
|
||||||
opening brace:
|
|
||||||
|
|
||||||
for (i = 2; i < argc; ++i) {
|
|
||||||
|
|
||||||
|
|
||||||
11. In Rust, a trailing comma on all arguments or fields that are on their own
|
|
||||||
lines:
|
|
||||||
|
|
||||||
return Err(EvaluationError {
|
|
||||||
message: format!("{}: Invalid token", i),
|
|
||||||
code: EX_DATAERR,
|
|
||||||
})
|
|
||||||
|
|
||||||
12. In Rust, place extern statements after use statements that include standard
|
|
||||||
library crates. Group like statements:
|
|
||||||
|
|
||||||
use std::fs::Path;
|
|
||||||
|
|
||||||
extern crate strerror;
|
|
||||||
extern crate sysexits;
|
|
||||||
|
|
||||||
use strerror::StrError;
|
|
||||||
use sysexits::{ EX_OSERR, EX_USAGE };
|
|
||||||
|
|
||||||
13. If text is on the same line as a brace, spaces after an opening brace and
|
|
||||||
before a closing one:
|
|
||||||
|
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
|
||||||
|
|
||||||
14. Alphabetic sorting, where applicable:
|
|
||||||
|
|
||||||
use std::io::{ BufWriter, Read, Write, stderr, stdin, stdout }
|
|
||||||
|
|
||||||
15. In Rust, use the to_owned() method on string types (str, OsStr, CStr, etc.)
|
|
||||||
and the to_string() method on other types.
|
|
||||||
|
|
||||||
|
|
||||||
Avoid
|
|
||||||
=====
|
|
||||||
|
|
||||||
16. Unbounded loops [0].
|
|
||||||
|
|
||||||
17. Function pointers [0].
|
|
||||||
|
|
||||||
18. Heap memory allocation [0].
|
|
||||||
|
|
||||||
19. Using too much nested logic (within reason).
|
|
||||||
|
|
||||||
20. Too many levels of dereferences [0]:
|
|
||||||
|
|
||||||
/* do not do this */
|
|
||||||
for (size_t i = 0; i < sizeof a / sizeof *a; ++i) {
|
|
||||||
if (a[i].id == MATCH) { a[i].val = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do this */
|
|
||||||
for (struct MadeUp *s = &a[0]; *s != NULL; s = &s[1]) {
|
|
||||||
if (s->id == MATCH) { s->val = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
21. Using C preprocessor macros; the fewer, the better [0].
|
|
||||||
|
|
||||||
22. The exit(3p) and std::process::exit() functions; returning from the main
|
|
||||||
function skips a system call.
|
|
||||||
|
|
||||||
|
|
||||||
Do Not Use
|
|
||||||
==========
|
|
||||||
|
|
||||||
23. More than the length of one printed page for a function [0].
|
|
||||||
|
|
||||||
24. Recursion, as it’s complex and can unexpectedly overflow the stack [0].
|
|
||||||
|
|
||||||
25. Any functionality not in the POSIX C specification and language features not
|
|
||||||
in C99.
|
|
||||||
|
|
||||||
26. Do-while loops, as they’re unique to C and confusing for casual programmers.
|
|
||||||
|
|
||||||
27. Labels and goto statements; use sensible flow control [0].
|
|
||||||
|
|
||||||
28. Pointer arithmetic, as it tends to be confusing and unnecessary; use
|
|
||||||
index-reference patterns like &p[1] instead of p + 1. &p[n] is the address at
|
|
||||||
p + sizeof p * n, not p + n, like pointer arithmetic suggests.
|
|
||||||
|
|
||||||
29. C struct bitfields in unions, to access certain bits of bigger data types,
|
|
||||||
as it’s poorly defined in the C standards; use bit arithmetic.
|
|
||||||
|
|
||||||
30. C trigraphs.
|
|
||||||
|
|
||||||
31. Inclusions in C header files, to prevent multiple file inclusions.
|
|
||||||
|
|
||||||
32. C preprocessor variables to prevent multiple inclusions of the same file,
|
|
||||||
such as:
|
|
||||||
|
|
||||||
#ifdef _FILE
|
|
||||||
#define _FILE
|
|
||||||
/* file body */
|
|
||||||
#endif /* ifdef _FILE */
|
|
||||||
|
|
||||||
Instead, take the time to ensure other files aren’t including any files twice.
|
|
||||||
|
|
||||||
33. The gets(3p) function from <stdio.h>, as it’s impossible to prevent buffer
|
|
||||||
overflows when it's used; use fgets(3p) from <stdio.h>.
|
|
||||||
|
|
||||||
34. The scanf(3p) function from <stdio.h> [1].
|
|
||||||
|
|
||||||
35. Any functionality not described in the latest POSIX make(1) specification.
|
|
||||||
|
|
||||||
36. Macros which panic on failure in Rust (such as the print!() and println!()
|
|
||||||
macros). Use a function and handle any errors. However, do use the eprintln!()
|
|
||||||
macro for error messages. Handling an error for writing an error message is
|
|
||||||
redundant.
|
|
||||||
|
|
||||||
|
|
||||||
Usage Text
|
|
||||||
==========
|
|
||||||
|
|
||||||
This section is adapted from the NetBSD style guide [2].
|
|
||||||
|
|
||||||
When programs are invoked incorrectly and in the synopsis of manual pages, uasge
|
|
||||||
text should be provided to the user. The following is the format used by this
|
|
||||||
project for this purpose:
|
|
||||||
|
|
||||||
All optional arguments are to be placed in square brackets (U+005B, U+005D).
|
|
||||||
Mutually exclusive arguments can be separated by a vertical line (U+007C).
|
|
||||||
Groups of arguments should be specified in alphabetical order in most cases. The
|
|
||||||
order of arguments and an example of these rules follows:
|
|
||||||
|
|
||||||
0. Options with no option arguments.
|
|
||||||
1. Options with option arguments. Arguments should be specified inside the same
|
|
||||||
square brackets as the options.
|
|
||||||
3. Non-option arguments.
|
|
||||||
|
|
||||||
"usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n"
|
|
||||||
"usage: f [-a | -b] [-c [-de] [-n number]]\n"
|
|
||||||
|
|
||||||
|
|
||||||
References
|
|
||||||
==========
|
|
||||||
|
|
||||||
[0] <https://web.eecs.umich.edu/~imarkov/10rules.pdf>
|
|
||||||
[1] <http://sekrit.de/webdocs/c/beginners-guide-away-from-scanf.html>
|
|
||||||
[2] <http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/share/misc/style>
|
|
||||||
|
|
||||||
--
|
|
||||||
Copyright © 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
Copyright © 2024 DTB <trinity@trinity.moe>
|
|
||||||
Copyright © Wikipedia contributors
|
|
||||||
|
|
||||||
This work is licensed under CC BY-SA 4.0. To view a copy of this license, visit
|
|
||||||
<http://creativecommons.org/licenses/by-sa/4.0/>.
|
|
||||||
79
docs/dj.1
79
docs/dj.1
@@ -1,10 +1,10 @@
|
|||||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
.\" Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
.\" Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
.\"
|
.\"
|
||||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
.\"
|
.\"
|
||||||
.TH DJ 1 2024-07-14 "Harakit X.X.X"
|
.TH DJ 1 2025-10-26 "Harakit X.X.X"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dj \(en disk jockey
|
dj \(en disk jockey
|
||||||
.\"
|
.\"
|
||||||
@@ -28,45 +28,44 @@ dj
|
|||||||
Perform precise read and write operations on files. This utility is useful for
|
Perform precise read and write operations on files. This utility is useful for
|
||||||
reading and writing binary data to and from disks.
|
reading and writing binary data to and from disks.
|
||||||
|
|
||||||
This manual page uses the terms \(lqskip\(rq and \(lqseek\(rq to refer to moving
|
This manual page uses the terms \(lqskip\(rq and \(lqseek\(rq to refer to
|
||||||
to a specified byte by index in the input and output of the program
|
moving to a specified byte by index in the input and output of the program
|
||||||
respectively. This language is inherited from the
|
respectively. This language is inherited from the
|
||||||
.BR dd (1p)
|
.BR dd (1p)
|
||||||
utility and used here to decrease ambiguity.
|
specification in \*(Px and used here to decrease ambiguity.
|
||||||
|
|
||||||
The offset used when skipping or seeking refers to how many bytes are skipped
|
The offset used when skipping or seeking refers to how many bytes are skipped
|
||||||
or sought. Running
|
or sought. Running
|
||||||
.BR dj (1)
|
.BR dj (1)
|
||||||
with a skip offset of 1 skips one byte into the input and reads from the second
|
with a skip offset of 1 reads from the second byte onwards. A programmer may
|
||||||
byte onwards. A programmer may think of a file as a zero-indexed array of
|
think of a file as a zero-indexed array of bytes; in this analogy, the offset
|
||||||
bytes; in this analogy, the offset given is the index of the byte at which to
|
given is the index of the byte at which to start reading or writing.
|
||||||
start reading or writing.
|
|
||||||
.\"
|
.\"
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
|
||||||
.IP \fB-i\fP\ \fIfile\fP
|
.IP \fB-i\fP\ \fIfile\fP
|
||||||
Takes a file path as an argument and opens it for use as an input.
|
Takes a file path as an argument and opens it for use as an input.
|
||||||
.IP \fB-b\fP\ \fIblock_size\fP
|
.IP \fB-b\fP\ \fIblock_size\fP
|
||||||
Takes a numeric argument as the size in bytes of the input buffer, the default
|
Takes a numeric argument as the size in bytes of the input buffer. If this
|
||||||
being 1024.
|
option is not specified, the size is 1024 bytes.
|
||||||
.IP \fB-s\fP
|
.IP \fB-s\fP \fIoffset\fP
|
||||||
Takes a numeric argument as the index of the byte at which reading will
|
Takes a numeric argument as the index of the byte at which reading will
|
||||||
commence; \(lqskips\(rq that number of bytes. If the standard input is used,
|
commence; the program \(lqskips\(rq that number of \fIbytes\fP. If the standard
|
||||||
bytes read to this point are discarded.
|
input is used, bytes read to this point are discarded.
|
||||||
.IP \fB-o\fP
|
.IP \fB-o\fP \fIfile\fP
|
||||||
Takes a file path as an argument and opens it for use as an output.
|
Takes a file path as an argument and opens it for use as an output.
|
||||||
.IP \fB-B\fP\ \fIblock_size\fP
|
.IP \fB-B\fP\ \fIblock_size\fP
|
||||||
Takes a numeric argument as the size in bytes of the output buffer, the default
|
Takes a numeric argument as the size in bytes of the output buffer. The default
|
||||||
being 1024. Note that this option only affects the size of output writes and not
|
size is 1024. Note that this option only affects the size of output writes and
|
||||||
the amount of output data itself. See the CAVEATS section.
|
not the amount of output data itself. See the CAVEATS section.
|
||||||
.IP \fB-S\fP
|
.IP \fB-S\fP \fIoffset\fP
|
||||||
Takes a numeric argument as the index of the byte at which writing will
|
Takes a numeric argument as the index of the byte at which writing will
|
||||||
commence; \(lqseeks\(rq that number of bytes. If the standard output is used,
|
commence; the program \(lqseeks\(rq that number of bytes. If the standard
|
||||||
null characters are printed.
|
output is used, null characters are first printed this many times.
|
||||||
.IP \fB-a\fP
|
.IP \fB-a\fP
|
||||||
Accepts a single literal byte with which the input buffer is padded in the event
|
Accepts a single literal byte with which the input buffer is padded in the
|
||||||
of an incomplete read from the input file. If the option argument is empty, the
|
event of an incomplete read from the input file. If the option argument is
|
||||||
null byte is used.
|
empty, the null byte is used.
|
||||||
.IP \fB-c\fP
|
.IP \fB-c\fP
|
||||||
Specifies a number of blocks to read. The default is 0, in which case the input
|
Specifies a number of blocks to read. The default is 0, in which case the input
|
||||||
is read until a partial or empty read is made.
|
is read until a partial or empty read is made.
|
||||||
@@ -78,12 +77,12 @@ Retries failed reads once before exiting.
|
|||||||
.\"
|
.\"
|
||||||
.SH STANDARD INPUT
|
.SH STANDARD INPUT
|
||||||
|
|
||||||
The standard input shall be used as an input if no inputs are specified or if
|
The standard input shall be used as an input if none are specified or if the
|
||||||
input file is \(lq-\(rq.
|
input file is \(lq-\(rq.
|
||||||
.\"
|
.\"
|
||||||
.SH STANDARD OUTPUT
|
.SH STANDARD OUTPUT
|
||||||
The standard output shall be used as an output if no inputs are specified or if
|
The standard output shall be used as an output if none are specified or if the
|
||||||
the output file is \(lq-\(rq.
|
output file is \(lq-\(rq.
|
||||||
.\"
|
.\"
|
||||||
.SH EXAMPLES
|
.SH EXAMPLES
|
||||||
|
|
||||||
@@ -135,13 +134,12 @@ invocation.
|
|||||||
.\"
|
.\"
|
||||||
.SH DIAGNOSTICS
|
.SH DIAGNOSTICS
|
||||||
|
|
||||||
On a partial or empty read, a diagnostic message is printed. Then, the program
|
On a partial or empty read, a diagnostic message is printed. Then, unless the
|
||||||
exits unless the
|
|
||||||
.B -n
|
.B -n
|
||||||
option is specified.
|
option is specified, the program exits.
|
||||||
|
|
||||||
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
|
||||||
the following format:
|
in the following format:
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
{records read} {ASCII unit separator} {partial records read}
|
{records read} {ASCII unit separator} {partial records read}
|
||||||
@@ -172,8 +170,8 @@ If
|
|||||||
.B -n
|
.B -n
|
||||||
is specified along with the
|
is specified along with the
|
||||||
.B -c
|
.B -c
|
||||||
option and a count, actual byte output is the product of the count and the input
|
option and a count, actual byte output is the product of the count and the
|
||||||
block size and therefore may be lower than expected. If the
|
input block size and therefore may be lower than expected. If the
|
||||||
.B -a
|
.B -a
|
||||||
option is specified, this could make written data nonsensical.
|
option is specified, this could make written data nonsensical.
|
||||||
.\"
|
.\"
|
||||||
@@ -202,12 +200,15 @@ The skipped or sought bytes while processing irregular files, such as streams,
|
|||||||
are reported in the diagnostic output, because they were actually read or
|
are reported in the diagnostic output, because they were actually read or
|
||||||
written. This is as opposed to bytes skipped while processing regular files,
|
written. This is as opposed to bytes skipped while processing regular files,
|
||||||
which are not reported.
|
which are not reported.
|
||||||
|
|
||||||
|
Much of this program shares its functionality with
|
||||||
|
.BR mm (1).
|
||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
This program was based on the
|
This program was based on the
|
||||||
.BR dd (1p)
|
.BR dd (1p)
|
||||||
utility as specified in POSIX. While character conversion may have been the
|
utility as specified in \*(Px. While character conversion may have been the
|
||||||
original intent of
|
original intent of
|
||||||
.BR dd (1p),
|
.BR dd (1p),
|
||||||
it is irrelevant to its modern use. Because of this, this program eschews
|
it is irrelevant to its modern use. Because of this, this program eschews
|
||||||
@@ -215,12 +216,18 @@ character conversion and adds typical option formatting, allowing seeks to be
|
|||||||
specified in bytes rather than in blocks, allowing arbitrary bytes as padding,
|
specified in bytes rather than in blocks, allowing arbitrary bytes as padding,
|
||||||
and printing in a format that\(cqs easy for machines to parse.
|
and printing in a format that\(cqs easy for machines to parse.
|
||||||
.\"
|
.\"
|
||||||
|
.SH AUTHOR
|
||||||
|
|
||||||
|
Written by DTB
|
||||||
|
.MT trinity@trinity.moe
|
||||||
|
.ME .
|
||||||
|
.\"
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
|
|
||||||
Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
Copyright \(co 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||||
<https://gnu.org/licenses/agpl.html>.
|
<https://gnu.org/licenses/agpl.html>.
|
||||||
.\"
|
.\"
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
.BR mm (1)
|
||||||
.BR dd (1p)
|
.BR dd (1p)
|
||||||
.BR lseek (3p)
|
.BR lseek (3p)
|
||||||
.BR mm (1)
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ always be returned.
|
|||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
In POSIX.1-2017,
|
In \*(Px.1-2024,
|
||||||
.BR false (1p)
|
.BR false (1p)
|
||||||
exists for the construction of control flow and loops based on a failure. This
|
exists for the construction of control flow and loops based on a failure. This
|
||||||
implementation functions as described in that standard.
|
implementation functions as described in that standard.
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ error code.
|
|||||||
|
|
||||||
The
|
The
|
||||||
.BR test (1p)
|
.BR test (1p)
|
||||||
utility contains functionality that was broken out into separate programs. Thus,
|
utility contains functionality that was broken out into separate programs. \
|
||||||
the scope of this program is narrower than it. Notably, the
|
Thus, the scope of this program is narrower than it. Notably, the
|
||||||
.B -h
|
.B -h
|
||||||
option is now invalid and therefore shows usage information instead of being an
|
option is now invalid and therefore shows usage information instead of being an
|
||||||
alias to the modern
|
alias to the modern
|
||||||
|
|||||||
@@ -28,13 +28,14 @@ is an ASCII record separator.
|
|||||||
.\"
|
.\"
|
||||||
.SH CAVEATS
|
.SH CAVEATS
|
||||||
|
|
||||||
Field indices are zero-indexed, which may be unexpected behavior for some users.
|
Field indices are zero-indexed, which may be unexpected behavior for some
|
||||||
|
users.
|
||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
With the assumption that tools will output data separated with ASCII field
|
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
|
separators, there is a need for the ability to modify select fields in this
|
||||||
easily and quickly.
|
data easily and quickly.
|
||||||
|
|
||||||
The idea for this utility originated in the fact that the GNU
|
The idea for this utility originated in the fact that the GNU
|
||||||
.BR ls (1)
|
.BR ls (1)
|
||||||
|
|||||||
13
docs/hru.1
13
docs/hru.1
@@ -16,8 +16,8 @@ hru
|
|||||||
Convert counts to higher units.
|
Convert counts to higher units.
|
||||||
|
|
||||||
Byte counts will be read in the form of whole numbers from the standard input
|
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
|
and be written to the standard output the same number converted to a higher
|
||||||
of data as defined by the \fIInternational System of Units\fP.
|
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
|
The program will convert the byte count to the highest unit possible where the
|
||||||
value is greater than one.
|
value is greater than one.
|
||||||
@@ -33,10 +33,11 @@ and print an error message.
|
|||||||
|
|
||||||
The GNU project\(cqs
|
The GNU project\(cqs
|
||||||
.BR ls (1)
|
.BR ls (1)
|
||||||
implementation contains a human-readable option (\fB-h\fP) that, when specified,
|
implementation contains a human-readable option (\fB-h\fP) that, when
|
||||||
makes the tool print size information in a format more immediately
|
specified, makes the tool print size information in a format more immediately
|
||||||
readable. This functionality is useful not only in this context, so the decision
|
readable. This functionality is useful not only in this context, so the
|
||||||
was made to split it into a new tool. The original functionality from GNU\(cqs
|
decision was made to split it into a new tool. The original functionality from
|
||||||
|
GNU\(cqs
|
||||||
.BR ls (1)
|
.BR ls (1)
|
||||||
can be emulated with
|
can be emulated with
|
||||||
.BR fop (1)
|
.BR fop (1)
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ It may help to think of the
|
|||||||
.BR -g ,
|
.BR -g ,
|
||||||
and
|
and
|
||||||
.B -l
|
.B -l
|
||||||
options as equivalent to the infix algebraic \(lq=\(rq, \(lq>\(rq, and \(lq<\(rq
|
options as equivalent to the infix algebraic \(lq=\(rq, \(lq>\(rq, and
|
||||||
operators respectively, with each option putting its symbol between every given
|
\(lq<\(rq operators respectively, with each option putting its symbol between
|
||||||
integer. The following example is equivalent to evaluating \(lq1 < 2 < 3\(rq:
|
every given integer. The following example is equivalent to evaluating
|
||||||
|
\(lq1 < 2 < 3\(rq:
|
||||||
\"
|
\"
|
||||||
.RS
|
.RS
|
||||||
intcmp -l 1 2 3
|
intcmp -l 1 2 3
|
||||||
@@ -75,7 +76,7 @@ this is elegant but unintuitive.
|
|||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
The traditional tool for integer comparisons in POSIX and other Unix shells has
|
The traditional tool for integer comparisons in \*(Px and other Unix shells has
|
||||||
been
|
been
|
||||||
.BR test (1).
|
.BR test (1).
|
||||||
This tool also handles string comparisons and file scrutiny. These parts of its
|
This tool also handles string comparisons and file scrutiny. These parts of its
|
||||||
|
|||||||
44
docs/mm.1
44
docs/mm.1
@@ -1,16 +1,17 @@
|
|||||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
|
.\" Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
.\"
|
.\"
|
||||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||||
.\"
|
.\"
|
||||||
.TH MM 1 2024-07-14 "Harakit X.X.X"
|
.TH MM 1 2025-11-01 "Harakit X.X.X"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
mm \(en middleman
|
mm \(en middleman
|
||||||
.\"
|
.\"
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
|
||||||
mm
|
mm
|
||||||
.RB [ -aetu ]
|
.RB [ -aet ]
|
||||||
.RB [ -i\ input ]
|
.RB [ -i\ input ]
|
||||||
.RB [ -o\ output ]
|
.RB [ -o\ output ]
|
||||||
.\"
|
.\"
|
||||||
@@ -21,21 +22,21 @@ Catenate input files and write them to the start of each output file or stream.
|
|||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
|
||||||
.IP \fB-a\fP
|
.IP \fB-a\fP
|
||||||
Opens outputs for appending rather than updating.
|
Opens outputs for appending rather than updating. Implies the
|
||||||
|
.B -t
|
||||||
|
option.
|
||||||
.IP \fB-e\fP
|
.IP \fB-e\fP
|
||||||
Use the standard error as an output.
|
Use the standard error as an output.
|
||||||
.IP \fB-t\fP
|
.IP \fB-t\fP
|
||||||
Causes outputs to be overwritten instead of being truncated.
|
Causes outputs to be overwritten instead of being truncated.
|
||||||
.IP \fB-u\fP
|
|
||||||
Ensures neither input or output will be buffered.
|
|
||||||
.IP \fB-i\fP\ \fIinput\fP
|
.IP \fB-i\fP\ \fIinput\fP
|
||||||
Opens a path as an input. If one or more of the input files is \(lq-\(rq or if
|
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. If specified as the
|
no inputs are specified, the standard input shall be used. If specified as the
|
||||||
last option and if there are trailing arguments to the program, they shall be
|
last option and if there are trailing arguments to the program, they shall be
|
||||||
appended to the list of files to use as inputs.
|
appended to the list of files to use as inputs.
|
||||||
.IP \fB-o\fP\ \fIoutput\fP
|
.IP \fB-o\fP\ \fIoutput\fP
|
||||||
Opens a path as an output. If one or more of the output files is \(lq-\(rq or if
|
Opens a path as an output. If one or more of the output files is \(lq-\(rq or
|
||||||
no outputs are specified and the
|
if no outputs are specified and the
|
||||||
.B -e
|
.B -e
|
||||||
option is not specified, the standard output shall be used. If specified as the
|
option is not specified, the standard output shall be used. If specified as the
|
||||||
last option and if there are trailing arguments to the program, they shall be
|
last option and if there are trailing arguments to the program, they shall be
|
||||||
@@ -43,9 +44,6 @@ appended to the list of files to use as outputs.
|
|||||||
.\"
|
.\"
|
||||||
.SH DIAGNOSTICS
|
.SH DIAGNOSTICS
|
||||||
|
|
||||||
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
|
When an error is encountered, a diagnostic message is printed and the program
|
||||||
exits with the appropriate
|
exits with the appropriate
|
||||||
.BR sysexits.h (3)
|
.BR sysexits.h (3)
|
||||||
@@ -57,13 +55,35 @@ The
|
|||||||
.BR cat (1p)
|
.BR cat (1p)
|
||||||
and
|
and
|
||||||
.BR tee (1p)
|
.BR tee (1p)
|
||||||
programs specified in POSIX together provide similar functionality. The
|
programs specified in \*(Px together provide similar functionality. The
|
||||||
separation of the two sets of functionality into separate APIs seemed
|
separation of the two sets of functionality into separate APIs seemed
|
||||||
unncessary.
|
unncessary.
|
||||||
.\"
|
.\"
|
||||||
|
.SH HISTORY
|
||||||
|
|
||||||
|
The \fB-t\fP option was originally the reverse functionality, as the default
|
||||||
|
behavior was to overwrite outputs. This was deemed counterintuitive and the
|
||||||
|
default behavior was changed.
|
||||||
|
|
||||||
|
This utility originally had a \fB-u\fP option for compatibility with cat(1p),
|
||||||
|
but this option is almost always default behavior in practice; therefore, it
|
||||||
|
was dropped both for simplicity and to expand the
|
||||||
|
.BR dj (1)
|
||||||
|
utility\(cqs niche.
|
||||||
|
.\"
|
||||||
|
.SH AUTHOR
|
||||||
|
|
||||||
|
Written by DTB
|
||||||
|
.MT trinity@trinity.moe
|
||||||
|
.ME , \
|
||||||
|
ported to Rust by Emma Tebibyte
|
||||||
|
.MT emma@tebibyte.media
|
||||||
|
.ME .
|
||||||
|
.\"
|
||||||
.SH COPYRIGHT
|
.SH COPYRIGHT
|
||||||
|
|
||||||
Copyright \(co 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
Copyright © 2024 DTB, 2024\(en2025 Emma Tebibyte. \
|
||||||
|
License AGPLv3+: GNU AGPL version 3 or later
|
||||||
<https://gnu.org/licenses/agpl.html>.
|
<https://gnu.org/licenses/agpl.html>.
|
||||||
.\"
|
.\"
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ The program operates in single-byte chunks regardless of intended encoding.
|
|||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
POSIX currently lacks a way to display non-printing characters in the terminal
|
\*(Px currently lacks a way to display non-printing characters in the terminal
|
||||||
using a standard tool. A popular extension to
|
using a standard tool. A popular extension to
|
||||||
.BR cat (1p),
|
.BR cat (1p),
|
||||||
the
|
the
|
||||||
.B -v
|
.B -v
|
||||||
option, is the bandage solution GNU and other software suites use.
|
option, is the bandage solution GNU and other software suites use.
|
||||||
|
|
||||||
This functionality is included in a separate tool because its usefulness extends
|
This functionality is included in a separate tool because its usefulness
|
||||||
beyond that of
|
extends beyond that of
|
||||||
.BR cat (1p).
|
.BR cat (1p).
|
||||||
.\"
|
.\"
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
|
|||||||
14
docs/peek.1
14
docs/peek.1
@@ -47,9 +47,9 @@ installed.
|
|||||||
.\"
|
.\"
|
||||||
.SH CAVEATS
|
.SH CAVEATS
|
||||||
|
|
||||||
This program does nothing to prevent others from seeing the key presses input to
|
This program does nothing to prevent others from seeing the key presses input
|
||||||
a keyboard. It also does not protect against the sound of typing being analyzed
|
to a keyboard. It also does not protect against the sound of typing being
|
||||||
to determine what was input without needing to see screen or keyboard.
|
analyzed to determine what was input without needing to see screen or keyboard.
|
||||||
|
|
||||||
Accepting secrets in shell scripts is probably not advisable.
|
Accepting secrets in shell scripts is probably not advisable.
|
||||||
|
|
||||||
@@ -80,10 +80,10 @@ $ peek | head -n 1 | xargs printf '%s' | htpasswd -nBi _ | cut -d : -f 2
|
|||||||
|
|
||||||
This is an
|
This is an
|
||||||
.BR sh (1p)
|
.BR sh (1p)
|
||||||
command line that allows a user to write blindly into a text file but displaying
|
command line that allows a user to write blindly into a text file but
|
||||||
only written lines. Some writers have the habit of prematurely revising their
|
displaying only written lines. Some writers have the habit of prematurely
|
||||||
work and use tools with functionality similar to this to prevent it.
|
revising their work and use tools with functionality similar to this to prevent
|
||||||
It uses
|
it. It uses
|
||||||
.BR mm (1)
|
.BR mm (1)
|
||||||
to pipe the output of the program to both the standard error and the regular
|
to pipe the output of the program to both the standard error and the regular
|
||||||
file writing.txt:
|
file writing.txt:
|
||||||
|
|||||||
14
docs/rpn.1
14
docs/rpn.1
@@ -50,17 +50,17 @@ with the
|
|||||||
.I IEEE Standard for Floating Point Arithmetic
|
.I IEEE Standard for Floating Point Arithmetic
|
||||||
(\fIIEEE 754\fP), floating-point arithmetic has rounding errors. This is
|
(\fIIEEE 754\fP), floating-point arithmetic has rounding errors. This is
|
||||||
somewhat curbed by using the machine epsilon as provided by the Rust standard
|
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
|
library, to which numbers are rounded. Because of this, variation is expected
|
||||||
the number of decimal places the program can handle based on the platform and
|
in the number of decimal places the program can handle based on the platform
|
||||||
hardware of any given machine.
|
and hardware of any given machine.
|
||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
An infix notation calculation utility,
|
An infix notation calculation utility,
|
||||||
.BR bc (1p),
|
.BR bc (1p),
|
||||||
is included in the POSIX standard, but does not accept expressions as arguments;
|
is included in the \*(Px standard, but does not accept expressions as
|
||||||
in scripts, any predefined, non-interactive input must be piped into the
|
arguments; in scripts, any predefined, non-interactive input must be piped into
|
||||||
program. A
|
the program. A
|
||||||
.BR dc (1)
|
.BR dc (1)
|
||||||
pre-dates the standardized
|
pre-dates the standardized
|
||||||
.BR bc (1p),
|
.BR bc (1p),
|
||||||
@@ -76,7 +76,7 @@ Written by Emma Tebibyte
|
|||||||
.\"
|
.\"
|
||||||
.SH COPYRIGHT
|
.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
|
||||||
<https://gnu.org/licenses/agpl.html>.
|
<https://gnu.org/licenses/agpl.html>.
|
||||||
.\"
|
.\"
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
|||||||
11
docs/str.1
11
docs/str.1
@@ -17,14 +17,15 @@ str
|
|||||||
|
|
||||||
Test the character types of string arguments.
|
Test the character types of string arguments.
|
||||||
|
|
||||||
The tests in this program are equivalent to the functions with the same names in
|
The tests in this program are equivalent to the functions with the same names
|
||||||
|
in
|
||||||
.BR ctype.h (0p)
|
.BR ctype.h (0p)
|
||||||
and are the methods by which string arguments are tested.
|
and are the methods by which string arguments are tested.
|
||||||
.\"
|
.\"
|
||||||
.SH DIAGNOSTICS
|
.SH DIAGNOSTICS
|
||||||
|
|
||||||
If all tests pass, the program will exit successfully. If any of the tests fail,
|
If all tests pass, the program will exit successfully. If any of the tests
|
||||||
the program will exit unsuccessfully with an error code of 1.
|
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
|
When invoked incorrectly, a debug message will be printed and the program will
|
||||||
exit with the appropriate
|
exit with the appropriate
|
||||||
@@ -33,8 +34,8 @@ error code.
|
|||||||
.\"
|
.\"
|
||||||
.SH CAVEATS
|
.SH CAVEATS
|
||||||
|
|
||||||
None of an empty string\(cqs contents pass any of the tests, so the program will
|
None of an empty string\(cqs contents pass any of the tests, so the program
|
||||||
exit unsuccessfully if one is specified.
|
will exit unsuccessfully if one is specified.
|
||||||
|
|
||||||
There\(cqs 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.
|
arguments individually.
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ visual similarity and not byte similarity.
|
|||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
The traditional tool for string comparisons in POSIX and other Unix shells has
|
The traditional tool for string comparisons in \*(Px and other Unix shells has
|
||||||
been
|
been
|
||||||
.BR test (1).
|
.BR test (1).
|
||||||
This tool also handles integer comparisons and file scrutiny. These parts of its
|
This tool also handles integer comparisons and file scrutiny. These parts of
|
||||||
functionality have been broken out into multiple utilities.
|
its functionality have been broken out into multiple utilities.
|
||||||
|
|
||||||
This program\(cqs functionality may be performed on a POSIX-compliant system
|
This program\(cqs functionality may be performed on a \*(Px-compliant system
|
||||||
with
|
with
|
||||||
.BR test (1p).
|
.BR test (1p).
|
||||||
.\"
|
.\"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ always be returned.
|
|||||||
.\"
|
.\"
|
||||||
.SH RATIONALE
|
.SH RATIONALE
|
||||||
|
|
||||||
In \fIPOSIX.1-2017\fP,
|
In \fI\*(Px.1-2024\fP,
|
||||||
.BR true (1p)
|
.BR true (1p)
|
||||||
exists for the construction of control flow and loops based on a success. This
|
exists for the construction of control flow and loops based on a success. This
|
||||||
implementation functions as described in that standard.
|
implementation functions as described in that standard.
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
OSLIB = build/o/libopenbsd.rlib
|
OSLIB = build/o/libopenbsd.rlib
|
||||||
RUSTFLAGS += --extern openbsd=$(OSLIB)
|
RUSTFLAGS += --extern openbsd=$(OSLIB)
|
||||||
|
|||||||
20
src/dj.c
20
src/dj.c
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
@@ -28,7 +28,8 @@
|
|||||||
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
#include <unistd.h> /* close(2), getopt(3), lseek(2), read(2), write(2),
|
||||||
* pledge(2), unveil(2), optarg, optind, STDIN_FILENO,
|
* pledge(2), unveil(2), optarg, optind, STDIN_FILENO,
|
||||||
* STDOUT_FILENO */
|
* STDOUT_FILENO */
|
||||||
#include <sys/stat.h> /* S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR */
|
#include <sys/stat.h> /* S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH,
|
||||||
|
* S_IWUSR */
|
||||||
|
|
||||||
char *program_name = "dj";
|
char *program_name = "dj";
|
||||||
|
|
||||||
@@ -284,7 +285,8 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* easy seeking */
|
/* easy seeking */
|
||||||
if (!fdisstd(io[i].fd) && lseek(io[i].fd, io[i].seek, SEEK_SET) != -1) {
|
if (!fdisstd(io[i].fd) && lseek(io[i].fd, io[i].seek, SEEK_SET) != -1)
|
||||||
|
{
|
||||||
io[i].seek = 0;
|
io[i].seek = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
18
src/fop.rs
18
src/fop.rs
@@ -2,15 +2,15 @@
|
|||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
@@ -141,8 +141,8 @@ fn main() -> ExitCode {
|
|||||||
/* pop trailing newline out if the input did not contain it */
|
/* pop trailing newline out if the input did not contain it */
|
||||||
if fields[index].chars().last() != Some('\n') /* no newline */
|
if fields[index].chars().last() != Some('\n') /* no newline */
|
||||||
&& replace.pop() != Some(b'\n') { /* pop last char of replacement */
|
&& replace.pop() != Some(b'\n') { /* pop last char of replacement */
|
||||||
/* restore replacement to original command output if popped char was not
|
/* restore replacement to original command output if popped char was
|
||||||
* a newline */
|
* not a newline */
|
||||||
replace = output.stdout;
|
replace = output.stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/hru.rs
14
src/hru.rs
@@ -2,15 +2,15 @@
|
|||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
@@ -107,8 +107,8 @@ impl GetOpt for Vec<String> {
|
|||||||
*
|
*
|
||||||
* A <question-mark> ('?') shall be returned if getopt()
|
* A <question-mark> ('?') shall be returned if getopt()
|
||||||
* encounters an option character not in optstring or detects a
|
* encounters an option character not in optstring or detects a
|
||||||
* missing argument and the first character of optstring was not
|
* missing argument and the first character of optstring was
|
||||||
* a <colon> (':').
|
* not a <colon> (':').
|
||||||
*
|
*
|
||||||
* Otherwise, getopt() shall return -1 when all command line
|
* Otherwise, getopt() shall return -1 when all command line
|
||||||
* options are parsed. */
|
* options are parsed. */
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
*
|
*
|
||||||
* Copying and distribution of this file, with or without modification, are
|
* Copying and distribution of this file, with or without modification, are
|
||||||
* permitted in any medium without royalty provided the copyright notice and
|
* permitted in any medium without royalty provided the copyright notice and
|
||||||
* this notice are preserved. This file is offered as-is, without any warranty.
|
* this notice are preserved. This file is offered as-is, without any
|
||||||
|
* warranty.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::ffi::{ c_int, c_char, CStr };
|
use std::ffi::{ c_int, c_char, CStr };
|
||||||
|
|||||||
63
src/mm.rs
63
src/mm.rs
@@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
@@ -20,8 +20,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{ Error, BufWriter, Read, Write, stderr, stdin, stdout },
|
io::{ Error, Read, Write, stderr, stdin, stdout },
|
||||||
os::fd::{ AsRawFd, FromRawFd },
|
|
||||||
process::{ ExitCode, exit},
|
process::{ ExitCode, exit},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ fn err(argv0: &String, e: Error, code: Option<u8>) -> ExitCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn usage(argv0: &String) -> ExitCode {
|
fn usage(argv0: &String) -> ExitCode {
|
||||||
eprintln!("Usage: {} [-aetu] [-i input] [-o output]", argv0);
|
eprintln!("Usage: {} [-aet] [-i input] [-o output]", argv0);
|
||||||
ExitCode::from(EX_USAGE)
|
ExitCode::from(EX_USAGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +69,8 @@ fn main() -> ExitCode {
|
|||||||
let mut a = false; /* append to the file */
|
let mut a = false; /* append to the file */
|
||||||
let mut e = false; /* use stderr as an output */
|
let mut e = false; /* use stderr as an output */
|
||||||
let mut t = true; /* do not truncate the file before writing */
|
let mut t = true; /* do not truncate the file before writing */
|
||||||
let mut u = false; /* unbuffer i/o */
|
let mut ins = Vec::new(); /* initial inputs */
|
||||||
let mut ins = Vec::new(); /* initial input file path vector */
|
let mut outs = Vec::new(); /* initial outputs */
|
||||||
let mut outs = Vec::new(); /* initial output file path vector */
|
|
||||||
let mut mode: Option<ArgMode> = None; /* mode set by last-used option */
|
let mut mode: Option<ArgMode> = None; /* mode set by last-used option */
|
||||||
let mut optind = 0;
|
let mut optind = 0;
|
||||||
|
|
||||||
@@ -80,7 +78,6 @@ fn main() -> ExitCode {
|
|||||||
match opt.opt() {
|
match opt.opt() {
|
||||||
Ok("a") => a = true,
|
Ok("a") => a = true,
|
||||||
Ok("e") => e = true,
|
Ok("e") => e = true,
|
||||||
Ok("u") => u = true,
|
|
||||||
Ok("t") => t = false,
|
Ok("t") => t = false,
|
||||||
Ok("i") => { /* add inputs */
|
Ok("i") => { /* add inputs */
|
||||||
let input = opt.arg().unwrap();
|
let input = opt.arg().unwrap();
|
||||||
@@ -135,7 +132,7 @@ fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ins.is_empty() && outs.is_empty() && argv.len() > optind {
|
if ins.is_empty() && outs.is_empty() && (argv.len() - 1) > optind {
|
||||||
return usage(&argv[0]);
|
return usage(&argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,29 +147,28 @@ fn main() -> ExitCode {
|
|||||||
/* if a file is “-”, it is stdin */
|
/* if a file is “-”, it is stdin */
|
||||||
if *file == "-" {
|
if *file == "-" {
|
||||||
/* portable way to access stdin as a file */
|
/* portable way to access stdin as a file */
|
||||||
return unsafe { File::from_raw_fd(stdin().as_raw_fd()) };
|
return Box::new(stdin().lock()) as Box<dyn Read>;
|
||||||
}
|
}
|
||||||
|
|
||||||
match File::open(file) {
|
match File::open(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => Box::new(f) as Box<dyn Read>,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR.into());
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<Box<dyn Read>>>();
|
||||||
|
|
||||||
/* map all path strings to files */
|
/* map all path strings to files */
|
||||||
let mut outputs = outs.iter().map(|file| {
|
let mut outputs = outs.iter().map(|file| {
|
||||||
/* of a file is “-”, it is stdout */
|
/* of a file is “-”, it is stdout */
|
||||||
if *file == "-" {
|
if *file == "-" {
|
||||||
/* portable way to access stdout as a file */
|
return Box::new(stdout().lock()) as Box<dyn Write>;
|
||||||
return unsafe { File::from_raw_fd(stdout().as_raw_fd()) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = File::options()
|
let options = File::options()
|
||||||
/* don’t truncate if -t is specified, append if -a is specified */
|
/* don’t truncate if -t is specified, append if -a is specified */
|
||||||
.truncate(t)
|
.truncate(!a && t)
|
||||||
.append(a)
|
.append(a)
|
||||||
/* enable the ability to create and write to files */
|
/* enable the ability to create and write to files */
|
||||||
.create(true)
|
.create(true)
|
||||||
@@ -181,30 +177,20 @@ fn main() -> ExitCode {
|
|||||||
.open(file);
|
.open(file);
|
||||||
|
|
||||||
match options {
|
match options {
|
||||||
Ok(f) => return f,
|
Ok(f) => return Box::new(f) as Box<dyn Write>,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
let _ = err(&(argv[0].clone() + ": " + file), e, None);
|
||||||
exit(EX_IOERR.into());
|
exit(EX_IOERR.into());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<Box<dyn Write>>>();
|
||||||
|
|
||||||
/* if -e is specified, use stderr */
|
/* if -e is specified, use stderr */
|
||||||
if e {
|
if e {
|
||||||
/* portable way to access stderr as a file */
|
/* portable way to access stderr as a file */
|
||||||
outputs.push(unsafe { File::from_raw_fd(stderr().as_raw_fd()) });
|
outputs.push(Box::new(stderr().lock()) as Box<dyn Write>);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut outputs = outputs.iter().map(|o| {
|
|
||||||
if u {
|
|
||||||
/* unbuffered writing through a buffer of capacity 0 */
|
|
||||||
BufWriter::with_capacity(0, o)
|
|
||||||
} else {
|
|
||||||
/* theoretically buffered writing */
|
|
||||||
BufWriter::new(o)
|
|
||||||
}
|
|
||||||
}).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for file in inputs {
|
for file in inputs {
|
||||||
for byte in file.bytes().map(|b| {
|
for byte in file.bytes().map(|b| {
|
||||||
b.unwrap_or_else(|e| {
|
b.unwrap_or_else(|e| {
|
||||||
@@ -216,13 +202,6 @@ fn main() -> ExitCode {
|
|||||||
if let Err(e) = out.write(&[byte]) {
|
if let Err(e) = out.write(&[byte]) {
|
||||||
return err(&argv[0], e, Some(EX_IOERR));
|
return err(&argv[0], e, Some(EX_IOERR));
|
||||||
}
|
}
|
||||||
|
|
||||||
if u {
|
|
||||||
/* immediately flush the output for -u */
|
|
||||||
if let Err(e) = out.flush() {
|
|
||||||
return err(&argv[0], e, Some(EX_IOERR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/npc.c
14
src/npc.c
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
14
src/peek.c
14
src/peek.c
@@ -2,15 +2,15 @@
|
|||||||
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
28
src/rpn.rs
28
src/rpn.rs
@@ -2,21 +2,21 @@
|
|||||||
* Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
*
|
*
|
||||||
* This file incorporates work covered by the following copyright and permission
|
* This file incorporates work covered by the following copyright and
|
||||||
* notice:
|
* permission notice:
|
||||||
*
|
*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
@@ -35,11 +35,11 @@
|
|||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
|||||||
116
src/scrut.c
116
src/scrut.c
@@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
|
||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
||||||
* later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see https://www.gnu.org/licenses/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <assert.h> /* assert(3) */
|
|
||||||
#include <stdio.h> /* fprintf(3), stderr, NULL */
|
|
||||||
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
|
|
||||||
#include <string.h> /* memset(3), strchr(3) */
|
|
||||||
#include <sysexits.h> /* EX_OSERR, EX_USAGE */
|
|
||||||
#include <unistd.h> /* access(3), getopt(3), pledge(2), unveil(2), F_OK, R_OK,
|
|
||||||
* W_OK, X_OK */
|
|
||||||
#include <sys/stat.h> /* lstat(3), stat struct, S_ISBLK, S_ISCHR, S_ISDIR,
|
|
||||||
* S_ISFIFO, S_ISGID, S_ISREG, S_ISLNK, S_ISSOCK,
|
|
||||||
* S_ISUID, S_ISVTX */
|
|
||||||
|
|
||||||
char *program_name = "scrut";
|
|
||||||
#define OPTS "bcdefgkprsuwxLS"
|
|
||||||
/* this is an array so main:sel's size can be known at compile time */
|
|
||||||
static char opts[] = OPTS;
|
|
||||||
|
|
||||||
static int
|
|
||||||
usage(char *argv0) {
|
|
||||||
(void)fprintf(stderr, "Usage: %s [-" OPTS "] file...\n", argv0);
|
|
||||||
|
|
||||||
return EX_USAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
char sel[(sizeof opts) / (sizeof *opts)];
|
|
||||||
|
|
||||||
program_name = argv[0] == NULL ? program_name : argv[0];
|
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
if (pledge("rpath stdio unveil", "") == -1) {
|
|
||||||
perror(program_name);
|
|
||||||
return EX_OSERR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc < 2) { return usage(program_name); }
|
|
||||||
|
|
||||||
{ /* option parsing */
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
memset(sel, '\0', sizeof sel);
|
|
||||||
for (int c; (c = getopt(argc, argv, opts)) != -1;) {
|
|
||||||
if ((p = strchr(opts, c)) == NULL) { return usage(argv[0]); }
|
|
||||||
else {
|
|
||||||
assert(p - opts < sizeof sel / sizeof *sel); /* bounds check */
|
|
||||||
sel[p - opts] = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* straighten out selections; permute out nulls */
|
|
||||||
p = sel;
|
|
||||||
for (size_t i = 0; i < (sizeof sel) / (sizeof *sel); ++i) {
|
|
||||||
if (sel[i] != '\0') {
|
|
||||||
*p = sel[i];
|
|
||||||
if (&sel[i] != p++) { sel[i] = '\0'; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind == argc) { return usage(argv[0]); }
|
|
||||||
|
|
||||||
for (argv += optind ; *argv != NULL; argv = &argv[1]) {
|
|
||||||
struct stat buf;
|
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
if (unveil(*argv, "rw") == -1) {
|
|
||||||
perror(program_name);
|
|
||||||
return EX_OSERR;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(access(*argv, F_OK) != 0 || lstat(*argv, &buf) == -1) {
|
|
||||||
return EXIT_FAILURE; /* doesn't exist or isn't stattable */
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; sel[i] != '\0'; ++i) {
|
|
||||||
if (
|
|
||||||
(sel[i] == 'b' && !S_ISBLK(buf.st_mode))
|
|
||||||
|| (sel[i] == 'c' && !S_ISCHR(buf.st_mode))
|
|
||||||
|| (sel[i] == 'd' && !S_ISDIR(buf.st_mode))
|
|
||||||
|| (sel[i] == 'e' && 0)
|
|
||||||
|| (sel[i] == 'f' && !S_ISREG(buf.st_mode))
|
|
||||||
|| (sel[i] == 'g' && !(buf.st_mode & S_ISGID))
|
|
||||||
|| (sel[i] == 'k' && !(buf.st_mode & S_ISVTX))
|
|
||||||
|| (sel[i] == 'p' && !S_ISFIFO(buf.st_mode))
|
|
||||||
|| (sel[i] == 'r' && access(*argv, R_OK) != 0)
|
|
||||||
|| (sel[i] == 'u' && !(buf.st_mode & S_ISUID))
|
|
||||||
|| (sel[i] == 'w' && access(*argv, W_OK) != 0)
|
|
||||||
|| (sel[i] == 'x' && access(*argv, X_OK) != 0)
|
|
||||||
|| (sel[i] == 'L' && !S_ISLNK(buf.st_mode))
|
|
||||||
|| (sel[i] == 'S' && !S_ISSOCK(buf.st_mode))
|
|
||||||
) { return EXIT_FAILURE; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
14
src/str.c
14
src/str.c
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2023 Marceline Cramer <mars@tebibyte.media>
|
* Copyright (c) 2023 Marceline Cramer <mars@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
15
src/strcmp.c
15
src/strcmp.c
@@ -3,19 +3,20 @@
|
|||||||
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h> /* fprintf(3), perror(3), stderr */
|
#include <stdio.h> /* fprintf(3), perror(3), stderr */
|
||||||
#include <sysexits.h> /* EX_OK, EX_OSERR, EX_USAGE */
|
#include <sysexits.h> /* EX_OK, EX_OSERR, EX_USAGE */
|
||||||
|
|
||||||
|
|||||||
14
src/swab.rs
14
src/swab.rs
@@ -3,15 +3,15 @@
|
|||||||
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* the terms of the GNU Affero General Public License as published by the Free
|
* under the terms of the GNU Affero General Public License as published by the
|
||||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
* later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
* 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
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
||||||
* details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero 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/.
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: false_tests
|
.PHONY: false_tests
|
||||||
false_tests: false_test false_help
|
false_tests: false_test false_help
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: fop_tests
|
.PHONY: fop_tests
|
||||||
fop_tests: fop_functionality fop_delimiter fop_help fop_fail
|
fop_tests: fop_functionality fop_delimiter fop_help fop_fail
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: hru_tests
|
.PHONY: hru_tests
|
||||||
hru_tests: hru_help hru_functionality hru_negative hru_regressions
|
hru_tests: hru_help hru_functionality hru_negative hru_regressions
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: intcmp_tests
|
.PHONY: intcmp_tests
|
||||||
intcmp_tests: intcmp_help intcmp_none intcmp_e intcmp_g intcmp_l intcmp_combined
|
intcmp_tests: intcmp_help intcmp_none intcmp_e intcmp_g intcmp_l intcmp_combined
|
||||||
|
|||||||
23
tests/mm.mk
23
tests/mm.mk
@@ -1,9 +1,11 @@
|
|||||||
# Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
|
# Copyright (c) 2024–2025 Emma Tebibyte <emma@tebibyte.media>
|
||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
|
MM_FILE!=mktemp /tmp/mm.XXXXXX
|
||||||
|
|
||||||
.PHONY: mm_tests
|
.PHONY: mm_tests
|
||||||
mm_tests: mm_args mm_help mm_stderr mm_remaining mm_remaining_options
|
mm_tests: mm_args mm_help mm_stderr mm_remaining mm_remaining_options
|
||||||
@@ -38,3 +40,18 @@ mm_remaining: $(BIN)/mm
|
|||||||
mm_remaining_options:
|
mm_remaining_options:
|
||||||
! $(BIN)/mm -i README COPYING -o - 2>&1 | cut -d: -f2 \
|
! $(BIN)/mm -i README COPYING -o - 2>&1 | cut -d: -f2 \
|
||||||
| xargs test " -o" =
|
| xargs test " -o" =
|
||||||
|
|
||||||
|
.PHONY: mm_append
|
||||||
|
mm_append:
|
||||||
|
$(BIN)/mm -i /dev/null -o $(MM_FILE)
|
||||||
|
printf 'test\nstring\nmulti-line\n' | $(BIN)/mm -o $(MM_FILE)
|
||||||
|
printf 'new line\n' | $(BIN)/mm -a -o $(MM_FILE)
|
||||||
|
$(BIN)/mm -i $(MM_FILE) | wc -l | xargs test 4 -eq
|
||||||
|
|
||||||
|
.PHONY: mm_no_truncate
|
||||||
|
mm_no_truncate:
|
||||||
|
$(BIN)/mm -i /dev/null -o $(MM_FILE)
|
||||||
|
printf 'test\nstring\nmulti-line\n' | $(BIN)/mm -o $(MM_FILE)
|
||||||
|
printf 'new line\n' | $(BIN)/mm -t -o $(MM_FILE)
|
||||||
|
$(BIN)/mm -i $(MM_FILE) | wc -l | xargs test 3 -eq
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
# Testing peek is hard as it requires visual confirmation that text isn't being
|
# Testing peek is hard as it requires visual confirmation that text isn't being
|
||||||
# echoed. These tests don't go that far but are a start, and have already
|
# echoed. These tests don't go that far but are a start, and have already
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: rpn_tests
|
.PHONY: rpn_tests
|
||||||
rpn_tests: rpn_help rpn_add rpn_sub rpn_mul rpn_div rpn_mod rpn_flr rpn_stdin
|
rpn_tests: rpn_help rpn_add rpn_sub rpn_mul rpn_div rpn_mod rpn_flr rpn_stdin
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
NAME = strcmp
|
NAME = strcmp
|
||||||
TARGET = $(NAME)_tests
|
TARGET = $(NAME)_tests
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PRAGMA: command_comment
|
.PRAGMA: command_comment
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
# SPDX-License-Identifier: FSFAP
|
# SPDX-License-Identifier: FSFAP
|
||||||
#
|
#
|
||||||
# Copying and distribution of this file, with or without modification, are
|
# Copying and distribution of this file, with or without modification, are
|
||||||
# permitted in any medium without royalty provided the copyright notice and this
|
# permitted in any medium without royalty provided the copyright notice and
|
||||||
# notice are preserved. This file is offered as-is, without any warranty.
|
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||||
|
|
||||||
.PHONY: true_tests
|
.PHONY: true_tests
|
||||||
true_tests: true_test
|
true_tests: true_test
|
||||||
|
|||||||
Reference in New Issue
Block a user