1 Commits

Author SHA1 Message Date
a3bbad467e getopt.rs(3): fixes formatting issues 2024-11-27 12:28:32 -07:00
2 changed files with 21 additions and 25 deletions

View File

@@ -79,8 +79,8 @@ pub trait GetOpt {
} }
impl GetOpt for Vec<String> { impl GetOpt for Vec<String> {
fn getopt(&self, optstring: &str) -> Option<Opt> { fn getopt(&self, optstring: &str) -> Option<Opt> {
let c_strings: Vec<_> = self let c_strings: Vec<_> = self
.iter() .iter()
.cloned() .cloned()
.map(|x| CString::new(x).unwrap().into_raw()) .map(|x| CString::new(x).unwrap().into_raw())
@@ -91,11 +91,11 @@ impl GetOpt for Vec<String> {
let argv = boxed as *const *mut c_char; let argv = boxed as *const *mut c_char;
/* operations are separated out so that everything lives long enough */ /* operations are separated out so that everything lives long enough */
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 {
let ret = match getopt(len, argv, opts) { let ret = match getopt(len, argv, 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
@@ -141,8 +141,8 @@ impl GetOpt for Vec<String> {
* argv[optind] points to the string "--" * argv[optind] points to the string "--"
* *
* getopt() shall return -1 after incrementing optind. */ * getopt() shall return -1 after incrementing optind. */
-1 => return None, -1 => return None,
opt => { opt => {
let arg: Option<String>; let arg: Option<String>;
if optarg.is_null() { arg = None; } if optarg.is_null() { arg = None; }
@@ -162,13 +162,13 @@ impl GetOpt for Vec<String> {
opt: Ok((opt as u8 as char).to_string()), opt: Ok((opt as u8 as char).to_string()),
}) })
}, },
}; };
/* delloc argv (something online said I should do this) */ /* delloc argv (something online said I should do this) */
let _ = Box::from_raw(boxed); let _ = Box::from_raw(boxed);
return ret; return ret;
} }
} }
} }
/* tests (good) */ /* tests (good) */

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# Copyright (c) 2024 DTB <trinity@trinity.moe> # Copyright (c) 2024 DTB <trinity@trinity.moe>
# Copyright (c) 20242025 Emma Tebibyte <emma@tebibyte.media> # Copyright (c) 2024 Emma Tebibyte <emma@tebibyte.media>
# SPDX-License-Identifier: FSFAP # SPDX-License-Identifier: FSFAP
# #
# Copying and distribution of this file, with or without modification, are # Copying and distribution of this file, with or without modification, are
@@ -26,7 +26,7 @@ npc_args:
.PHONY: npc_ascii .PHONY: npc_ascii
# Test 0x00 to 0x7f in input; in other words, the full 7b ASCII range. # Test 0x00 to 0x7f in input; in other words, the full 7b ASCII range.
npc_ascii: npc_ascii_controls npc_ascii_uppers # npc_ascii_symbols \ npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \
# npc_ascii_lowers # npc_ascii_lowers
.PHONY: npc_ascii_controls .PHONY: npc_ascii_controls
@@ -63,18 +63,14 @@ npc_ascii_controls:
| tail -n 1 \ | tail -n 1 \
| xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_" | xargs -I out test "^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_"
# This test is broken on Linux and will need closer inspection along with GNU .PHONY: npc_ascii_symbols
# xargs(1). # ASCII 0x1f to 0x3f (^_ and symbols)
# .PHONY: npc_ascii_symbols npc_ascii_symbols:
# # ASCII 0x1f to 0x3f (^_ and symbols) # shell quoting olympics
# npc_ascii_symbols: awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }' \
# # shell quoting olympics | $(BIN)/npc \
# c="$(awk 'BEGIN{ for (i = 31; i < 64; ++i) printf("%c", i); print }')" | sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \
# | xargs -I out test "^_ !\"#$$%&'()*+,-./0123456789:;<=>?" = out
# printf '%s\n' "$c" | $(BIN)/npc \
# | sed -e s"/\'/\\\'/g" -e 's/"/\\"/g' \
# | tr -d '\n' \
# | xargs -I out test "^_ !\"#$$%&\'()*+,-./0123456789:;<=>?" = out
.PHONY: npc_ascii_uppers .PHONY: npc_ascii_uppers
# ASCII 0x40 to 0x5f (uppercases) # ASCII 0x40 to 0x5f (uppercases)