From 6bbccb3776da30be99b97753e1edbfe6939dac7c Mon Sep 17 00:00:00 2001 From: DTB Date: Mon, 29 Jul 2024 21:14:45 -0600 Subject: [PATCH] fop(1): fix minor optind bug, add some comments --- src/fop.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index bbca85e..9f547b1 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -33,7 +33,7 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { let argv = args().collect::>(); let mut d = '\u{1E}'.to_string(); /* ASCII record separator */ - let mut optind = 0; + let mut optind = 1; let usage = format!( "Usage: {} [-d delimiter] index command [args...]", @@ -54,6 +54,12 @@ fn main() { }; } + /* parse the specified index as a number we can use */ + let index = argv[optind].parse::().unwrap_or_else(|e| { + eprintln!("{}: {}: {}", argv[0], argv[1], e); + exit(EX_DATAERR); + }); + /* index of the argv[0] for the operator command */ let command_arg = optind as usize + 1; @@ -63,12 +69,7 @@ fn main() { exit(EX_USAGE); }); - /* parse the specified index as a number we can use */ - let index = argv[optind].parse::().unwrap_or_else(|e| { - eprintln!("{}: {}: {}", argv[0], argv[1], e); - exit(EX_DATAERR); - }); - + /* read entire standard input into memory */ let mut buf = String::new(); if let Err(e) = stdin().read_to_string(&mut buf) { eprintln!("{}: {}", argv[0], e.strerror());