optimizations #161
16
src/fop.rs
16
src/fop.rs
@ -72,7 +72,7 @@ fn main() -> ExitCode {
|
|||||||
/* parse the specified index as a number we can use */
|
/* parse the specified index as a number we can use */
|
||||||
let index = argv[optind].parse::<usize>().unwrap_or_else(|e| {
|
let index = argv[optind].parse::<usize>().unwrap_or_else(|e| {
|
||||||
eprintln!("{}: {}: {}", argv[0], argv[1], e);
|
eprintln!("{}: {}: {}", argv[0], argv[1], e);
|
||||||
exit(EX_DATAERR as i32);
|
exit(EX_DATAERR.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* index of the argv[0] for the operator command */
|
/* index of the argv[0] for the operator command */
|
||||||
@ -80,14 +80,14 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
/* argv[0] of the operator command */
|
/* argv[0] of the operator command */
|
||||||
let operator = argv.get(command_arg).unwrap_or_else(|| {
|
let operator = argv.get(command_arg).unwrap_or_else(|| {
|
||||||
exit(usage(&argv[0]) as i32);
|
exit(usage(&argv[0]).into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* read entire standard input into memory */
|
/* read entire standard input into memory */
|
||||||
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) {
|
||||||
err(&argv[0], e);
|
err(&argv[0], e);
|
||||||
exit(EX_IOERR as i32);
|
exit(EX_IOERR.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
/* split the buffer by the delimiter (by default, '\u{1E}') */
|
/* split the buffer by the delimiter (by default, '\u{1E}') */
|
||||||
@ -108,13 +108,13 @@ fn main() -> ExitCode {
|
|||||||
.spawn()
|
.spawn()
|
||||||
.unwrap_or_else( |e| {
|
.unwrap_or_else( |e| {
|
||||||
err(&argv[0], e);
|
err(&argv[0], e);
|
||||||
exit(EX_UNAVAILABLE as i32);
|
exit(EX_UNAVAILABLE.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get field we want to pipe into spawned program */
|
/* get field we want to pipe into spawned program */
|
||||||
let field = fields.get(index).unwrap_or_else(|| {
|
let field = fields.get(index).unwrap_or_else(|| {
|
||||||
eprintln!("{}: {}: no such index in input", argv[0], index);
|
eprintln!("{}: {}: no such index in input", argv[0], index);
|
||||||
exit(EX_DATAERR as i32);
|
exit(EX_DATAERR.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get the stdin of the newly spawned program and feed it the field val */
|
/* get the stdin of the newly spawned program and feed it the field val */
|
||||||
@ -125,7 +125,7 @@ fn main() -> ExitCode {
|
|||||||
|
|
||||||
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
let output = spawned.wait_with_output().unwrap_or_else(|e| {
|
||||||
err(&argv[0], e);
|
err(&argv[0], e);
|
||||||
exit(EX_IOERR as i32);
|
exit(EX_IOERR.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* get the output with which the original field will be replaced */
|
/* get the output with which the original field will be replaced */
|
||||||
@ -142,7 +142,7 @@ fn main() -> ExitCode {
|
|||||||
/* 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| {
|
||||||
eprintln!("{}: {}", argv[0], e);
|
eprintln!("{}: {}", argv[0], e);
|
||||||
exit(EX_IOERR as i32);
|
exit(EX_IOERR.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* store the new field in the old fields vector */
|
/* store the new field in the old fields vector */
|
||||||
@ -153,7 +153,7 @@ fn main() -> ExitCode {
|
|||||||
fields.join(&d.to_string()).as_bytes()
|
fields.join(&d.to_string()).as_bytes()
|
||||||
).unwrap_or_else(|e| {
|
).unwrap_or_else(|e| {
|
||||||
err(&argv[0], e);
|
err(&argv[0], e);
|
||||||
exit(EX_IOERR as i32);
|
exit(EX_IOERR.into());
|
||||||
});
|
});
|
||||||
|
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
|
Loading…
Reference in New Issue
Block a user