Compare commits
No commits in common. "d2ae35eac9eca030d9b96252706da8494b7f5b18" and "09193a14d5dcdc324387081667c02aa4854bee0b" have entirely different histories.
d2ae35eac9
...
09193a14d5
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 command_args = argv
|
let opts = 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(command_args) /* spawn with the specified arguments */
|
.args(opts) /* 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,13 +120,8 @@ 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();
|
||||||
|
|
||||||
/* pop trailing newline out if the input did not contain it */
|
/* as long as it’s not a newline, set the replacement to the output */
|
||||||
if fields[index].chars().last() != Some('\n') /* no newline */
|
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
||||||
&& 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