getopt.rs(3): better Opt return

This commit is contained in:
Emma Tebibyte 2024-04-13 23:42:11 -06:00
parent d1b77d652b
commit 78eacd660a
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -21,7 +21,6 @@ use std::ffi::{ c_int, c_char, CString, CStr };
pub struct Opt { pub struct Opt {
pub arg: Option<String>, pub arg: Option<String>,
pub ind: i32, pub ind: i32,
/* opt is set to either the current option or the one that cause an error */
pub opt: String, pub opt: String,
} }
@ -51,8 +50,8 @@ impl GetOpt for Vec<String> {
let opts = CString::new(optstring).unwrap().into_raw(); let opts = CString::new(optstring).unwrap().into_raw();
let len = self.len() as c_int; let len = self.len() as c_int;
unsafe { unsafe { // TODO: enable optind modification
match getopt(len, argv_ptr, opts) { match getopt(len, argv_ptr, opts) {
/* From getopt(3p): /* From getopt(3p):
* *
* The getopt() function shall return the next option character * The getopt() function shall return the next option character
@ -95,9 +94,9 @@ impl GetOpt for Vec<String> {
.into_owned(); .into_owned();
Some(Ok(Opt { Some(Ok(Opt {
arg: Some(arg), arg: Some(arg), /* opt argument */
ind: optind, ind: optind, /* opt index */
opt: opt.to_string(), opt: opt.to_string(), /* option itself */
})) }))
}, },
} }