mm(1): added -t for disabling truncation; mm.1: updated docs
This commit is contained in:
parent
1b3b03cae0
commit
e972ff468a
16
docs/mm.1
16
docs/mm.1
@ -10,7 +10,7 @@ mm \(en middleman
|
||||
.SH SYNOPSIS
|
||||
|
||||
mm
|
||||
.RB [ -aenu ]
|
||||
.RB [ -aetu ]
|
||||
.RB [ -i\ input ]
|
||||
.RB [ -o\ output ]
|
||||
.\"
|
||||
@ -21,19 +21,19 @@ Catenate input files and write them to the start of each output file or stream.
|
||||
.SH OPTIONS
|
||||
|
||||
.IP \fB-a\fP
|
||||
Opens subsequent outputs for appending rather than updating.
|
||||
Opens outputs for appending rather than updating.
|
||||
.IP \fB-e\fP
|
||||
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
|
||||
Opens a path as an input. If one or more of the input files is \(lq-\(rq or if
|
||||
no inputs are specified, the standard input shall be used.
|
||||
.IP \fB-o\fP\ \fIoutput\fP
|
||||
Opens a path as an output. If one or more of the output files is \(lq-\(rq or if
|
||||
no outputs are specified, the standard output shall be used.
|
||||
.IP \fB-u\fP
|
||||
Ensures neither input or output will be buffered.
|
||||
.IP \fB-n\fP
|
||||
Causes SIGINT signals to be ignored.
|
||||
.\"
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
@ -45,10 +45,6 @@ exits with the appropriate
|
||||
.BR sysexits.h (3)
|
||||
status.
|
||||
.\"
|
||||
.SH CAVEATS
|
||||
|
||||
Existing files are not truncated on ouput and are instead overwritten.
|
||||
.\"
|
||||
.SH RATIONALE
|
||||
|
||||
The
|
||||
|
14
src/mm.rs
14
src/mm.rs
@ -34,19 +34,21 @@ use sysexits::{ EX_IOERR, EX_USAGE };
|
||||
|
||||
fn main() -> ExitCode {
|
||||
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 e = false; /* use stderr as an output */
|
||||
let mut t = true;
|
||||
let mut u = false; /* unbuffer i/o */
|
||||
let mut ins = Vec::new(); /* initial inputs 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() {
|
||||
Ok("a") => a = true,
|
||||
Ok("e") => e = true,
|
||||
Ok("u") => u = true,
|
||||
Ok("e") => e = true,
|
||||
Ok("u") => u = true,
|
||||
Ok("t") => t = false,
|
||||
Ok("i") => { /* add input */
|
||||
let input = opt.arg().unwrap();
|
||||
ins.push(input);
|
||||
@ -75,7 +77,7 @@ fn main() -> ExitCode {
|
||||
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,
|
||||
Err(e) => {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
@ -91,7 +93,7 @@ fn main() -> ExitCode {
|
||||
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,
|
||||
Err(e) => {
|
||||
eprintln!("{}: {}", argv[0], e.strerror());
|
||||
|
Loading…
Reference in New Issue
Block a user