Compare commits
2 Commits
09193a14d5
...
d2ae35eac9
Author | SHA1 | Date | |
---|---|---|---|
d2ae35eac9 | |||
0f121cbac7 |
15
src/fop.rs
15
src/fop.rs
@ -71,7 +71,7 @@ fn main() {
|
|||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Err(e) = stdin().read_to_string(&mut buf) {
|
if let Err(e) = stdin().read_to_string(&mut buf) {
|
||||||
eprintln!("{}: {}", argv[0], e.strerror);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ fn main() {
|
|||||||
let mut fields = buf.split(&d).collect::<Vec<&str>>();
|
let mut fields = buf.split(&d).collect::<Vec<&str>>();
|
||||||
|
|
||||||
/* collect arguments for the operator command */
|
/* collect arguments for the operator command */
|
||||||
let opts = argv
|
let command_args = argv
|
||||||
.iter()
|
.iter()
|
||||||
.clone()
|
.clone()
|
||||||
.skip(command_arg + 1) /* skip the command name */
|
.skip(command_arg + 1) /* skip the command name */
|
||||||
@ -87,7 +87,7 @@ fn main() {
|
|||||||
|
|
||||||
/* spawn the command to operate on the field */
|
/* spawn the command to operate on the field */
|
||||||
let mut spawned = Command::new(operator)
|
let mut spawned = Command::new(operator)
|
||||||
.args(opts) /* spawn with the specified arguments */
|
.args(command_args) /* spawn with the specified arguments */
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped()) /* piped stdout to handle output ourselves */
|
.stdout(Stdio::piped()) /* piped stdout to handle output ourselves */
|
||||||
.spawn()
|
.spawn()
|
||||||
@ -120,8 +120,13 @@ fn main() {
|
|||||||
/* get the output with which the original field will be replaced */
|
/* get the output with which the original field will be replaced */
|
||||||
let mut replace = output.stdout.clone();
|
let mut replace = output.stdout.clone();
|
||||||
|
|
||||||
/* as long as it’s not a newline, set the replacement to the output */
|
/* pop trailing newline out if the input did not contain it */
|
||||||
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
if fields[index].chars().last() != Some('\n') /* no newline */
|
||||||
|
&& replace.pop() != Some(b'\n') { /* pop last char of replacement */
|
||||||
|
/* restore replacement to original command output if popped char was not
|
||||||
|
* a newline */
|
||||||
|
replace = output.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
/* convert the output of the program to UTF-8 */
|
/* convert the output of the program to UTF-8 */
|
||||||
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
||||||
|
Loading…
Reference in New Issue
Block a user