getopt.rs(3): formatting & organization

This commit is contained in:
Emma Tebibyte 2024-06-04 15:07:11 -06:00
parent a5a9c91cb6
commit b7283d54fe
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -18,7 +18,6 @@
use std::ffi::{ c_int, c_char, CString, CStr };
/* binding to getopt(3p) */
extern "C" {
static mut optarg: *mut c_char;
@ -33,6 +32,27 @@ extern "C" {
) -> c_int;
}
/* From getopt(3p):
*
* The variable optind is the index of the next element of the argv[]
* vector to be processed. It shall be initialized to 1 by the system, and
* getopt() shall update it when it finishes with each element of argv[].
* If the application sets optind to zero before calling getopt(), the
* behavior is unspecified. When an element of argv[] contains multiple
* option characters, it is unspecified how getopt() determines which
* options have already been processed.
*
* This API can be utilized using unsafe blocks and dereferencing:
*
* use getopt::OPTIND;
*
* unsafe { while *OPTIND < 5 {
* println!("{}", *OPTIND); // 1..4
* *OPTIND += 1;
* }}
*/
pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) };
pub struct Opt {
pub arg: Option<String>,
pub ind: i32,
@ -83,12 +103,12 @@ impl GetOpt for Vec<String> {
*
* Otherwise, getopt() shall return -1 when all command line
* options are parsed. */
58 => { /* numerical ASCII value for ':' */
Some(Err(OptError::MissingArg(optopt.to_string())))
},
63 => { /* numerical ASCII value for '?' */
Some(Err(OptError::UnknownOpt(optopt.to_string())))
},
58 => { /* numerical ASCII value for ':' */
Some(Err(OptError::MissingArg(optopt.to_string())))
},
63 => { /* numerical ASCII value for '?' */
Some(Err(OptError::UnknownOpt(optopt.to_string())))
},
/* From getopt(3p):
*
* If, when getopt() is called:
@ -118,24 +138,3 @@ impl GetOpt for Vec<String> {
}
}
}
/* From getopt(3p):
*
* The variable optind is the index of the next element of the argv[]
* vector to be processed. It shall be initialized to 1 by the system, and
* getopt() shall update it when it finishes with each element of argv[].
* If the application sets optind to zero before calling getopt(), the
* behavior is unspecified. When an element of argv[] contains multiple
* option characters, it is unspecified how getopt() determines which
* options have already been processed.
*
* This API can be utilized using unsafe blocks and dereferencing:
*
* use getopt::OPTIND;
*
* unsafe { while *OPTIND < 5 {
* println!("{}", *OPTIND); // 1..4
* *OPTIND += 1;
* }}
*/
pub static mut OPTIND: *mut i32 = unsafe { std::ptr::addr_of_mut!(optind) };