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,
|
||||||
@ -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