mm(1): added -t for disabling truncation; mm.1: updated docs

This commit is contained in:
Emma Tebibyte 2024-07-13 23:56:30 -06:00
parent 1b3b03cae0
commit e972ff468a
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270
2 changed files with 14 additions and 16 deletions

View File

@ -10,7 +10,7 @@ mm \(en middleman
.SH SYNOPSIS .SH SYNOPSIS
mm mm
.RB [ -aenu ] .RB [ -aetu ]
.RB [ -i\ input ] .RB [ -i\ input ]
.RB [ -o\ output ] .RB [ -o\ output ]
.\" .\"
@ -21,19 +21,19 @@ 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 subsequent outputs for appending rather than updating. Opens outputs for appending rather than updating.
.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
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. no inputs are specified, the standard input shall be used.
.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 if
no outputs are specified, the standard output shall be used. no outputs are specified, the standard output shall be used.
.IP \fB-u\fP
Ensures neither input or output will be buffered.
.IP \fB-n\fP
Causes SIGINT signals to be ignored.
.\" .\"
.SH DIAGNOSTICS .SH DIAGNOSTICS
@ -45,10 +45,6 @@ exits with the appropriate
.BR sysexits.h (3) .BR sysexits.h (3)
status. status.
.\" .\"
.SH CAVEATS
Existing files are not truncated on ouput and are instead overwritten.
.\"
.SH RATIONALE .SH RATIONALE
The The

View File

@ -34,19 +34,21 @@ use sysexits::{ EX_IOERR, EX_USAGE };
fn main() -> ExitCode { fn main() -> ExitCode {
let argv = args().collect::<Vec<_>>(); let argv = args().collect::<Vec<_>>();
let usage = format!("Usage: {} [-aeu] [-i input] [-o output]", argv[0]); let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]);
let mut a = false; /* append rather than update */ let mut a = false; /* append rather than update */
let mut e = false; /* use stderr as an output */ let mut e = false; /* use stderr as an output */
let mut t = true;
let mut u = false; /* unbuffer i/o */ let mut u = false; /* unbuffer i/o */
let mut ins = Vec::new(); /* initial inputs vector */ let mut ins = Vec::new(); /* initial inputs vector */
let mut outs = Vec::new(); /* initial outputs vector */ let mut outs = Vec::new(); /* initial outputs vector */
while let Some(opt) = argv.getopt("aei:o:u") { while let Some(opt) = argv.getopt("aei:o:tu") {
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("u") => u = true,
Ok("t") => t = false,
Ok("i") => { /* add input */ Ok("i") => { /* add input */
let input = opt.arg().unwrap(); let input = opt.arg().unwrap();
ins.push(input); ins.push(input);
@ -75,7 +77,7 @@ fn main() -> ExitCode {
return unsafe { File::from_raw_fd(stdin().as_raw_fd()) }; /* fd0 = stdin */ return unsafe { File::from_raw_fd(stdin().as_raw_fd()) }; /* fd0 = stdin */
} }
match File::options().append(a).open(file) { match File::options().open(file) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
eprintln!("{}: {}", argv[0], e.strerror()); eprintln!("{}: {}", argv[0], e.strerror());
@ -91,7 +93,7 @@ fn main() -> ExitCode {
return unsafe { File::from_raw_fd(stdout().as_raw_fd()) }; /* fd1 = stdout */ return unsafe { File::from_raw_fd(stdout().as_raw_fd()) }; /* fd1 = stdout */
} }
match File::options().append(a).open(file) { match File::options().truncate(t).append(a).open(file) {
Ok(f) => return f, Ok(f) => return f,
Err(e) => { Err(e) => {
eprintln!("{}: {}", argv[0], e.strerror()); eprintln!("{}: {}", argv[0], e.strerror());