forked from bonsai/harakit
getopt.rs(3): formatting & organization
This commit is contained in:
parent
a5a9c91cb6
commit
b7283d54fe
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
use std::ffi::{ c_int, c_char, CString, CStr };
|
use std::ffi::{ c_int, c_char, CString, CStr };
|
||||||
|
|
||||||
|
|
||||||
/* binding to getopt(3p) */
|
/* binding to getopt(3p) */
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static mut optarg: *mut c_char;
|
static mut optarg: *mut c_char;
|
||||||
@ -33,6 +32,27 @@ extern "C" {
|
|||||||
) -> c_int;
|
) -> 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 struct Opt {
|
||||||
pub arg: Option<String>,
|
pub arg: Option<String>,
|
||||||
pub ind: i32,
|
pub ind: i32,
|
||||||
@ -83,12 +103,12 @@ impl GetOpt for Vec<String> {
|
|||||||
*
|
*
|
||||||
* Otherwise, getopt() shall return -1 when all command line
|
* Otherwise, getopt() shall return -1 when all command line
|
||||||
* options are parsed. */
|
* options are parsed. */
|
||||||
58 => { /* numerical ASCII value for ':' */
|
58 => { /* numerical ASCII value for ':' */
|
||||||
Some(Err(OptError::MissingArg(optopt.to_string())))
|
Some(Err(OptError::MissingArg(optopt.to_string())))
|
||||||
},
|
},
|
||||||
63 => { /* numerical ASCII value for '?' */
|
63 => { /* numerical ASCII value for '?' */
|
||||||
Some(Err(OptError::UnknownOpt(optopt.to_string())))
|
Some(Err(OptError::UnknownOpt(optopt.to_string())))
|
||||||
},
|
},
|
||||||
/* From getopt(3p):
|
/* From getopt(3p):
|
||||||
*
|
*
|
||||||
* If, when getopt() is called:
|
* 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) };
|
|
||||||
|
Loading…
Reference in New Issue
Block a user