optimizations #161

Open
emma wants to merge 44 commits from optimizations into main
Showing only changes of commit 150fa22f35 - Show all commits

View File

@ -72,7 +72,7 @@ fn main() -> ExitCode {
/* parse the specified index as a number we can use */
let index = argv[optind].parse::<usize>().unwrap_or_else(|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 */
@ -80,14 +80,14 @@ fn main() -> ExitCode {
/* argv[0] of the operator command */
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 */
let mut buf = String::new();
if let Err(e) = stdin().read_to_string(&mut buf) {
err(&argv[0], e);
exit(EX_IOERR as i32);
exit(EX_IOERR.into());
};
/* split the buffer by the delimiter (by default, '\u{1E}') */
@ -108,13 +108,13 @@ fn main() -> ExitCode {
.spawn()
.unwrap_or_else( |e| {
err(&argv[0], e);
exit(EX_UNAVAILABLE as i32);
exit(EX_UNAVAILABLE.into());
});
/* get field we want to pipe into spawned program */
let field = fields.get(index).unwrap_or_else(|| {
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 */
@ -125,7 +125,7 @@ fn main() -> ExitCode {
let output = spawned.wait_with_output().unwrap_or_else(|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 */
@ -142,7 +142,7 @@ fn main() -> ExitCode {
/* convert the output of the program to UTF-8 */
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
eprintln!("{}: {}", argv[0], e);
exit(EX_IOERR as i32);
exit(EX_IOERR.into());
});
/* store the new field in the old fields vector */
@ -153,7 +153,7 @@ fn main() -> ExitCode {
fields.join(&d.to_string()).as_bytes()
).unwrap_or_else(|e| {
err(&argv[0], e);
exit(EX_IOERR as i32);
exit(EX_IOERR.into());
});
ExitCode::SUCCESS