mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
Changes parameter parsing to clap
- Uses clap to parse parameters - Removes of "allow" directive where they are not necessary - Removes of unused variables
This commit is contained in:
parent
cee59c0343
commit
01fef70143
10 changed files with 29 additions and 48 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1,7 +1,5 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "advapi32-sys"
|
||||
version = "0.2.0"
|
||||
|
|
|
@ -18,18 +18,15 @@ pub fn err_msg(msg: &str) {
|
|||
|
||||
// by default stdout only flushes
|
||||
// to console when a newline is passed.
|
||||
#[allow(unused_must_use)]
|
||||
pub fn flush_char(c: char) {
|
||||
print!("{}", c);
|
||||
stdout().flush();
|
||||
let _ = stdout().flush();
|
||||
}
|
||||
#[allow(unused_must_use)]
|
||||
pub fn flush_str(s: &str) {
|
||||
print!("{}", s);
|
||||
stdout().flush();
|
||||
let _ = stdout().flush();
|
||||
}
|
||||
#[allow(unused_must_use)]
|
||||
pub fn flush_bytes(bslice: &[u8]) {
|
||||
stdout().write(bslice);
|
||||
stdout().flush();
|
||||
let _ = stdout().write(bslice);
|
||||
let _ = stdout().flush();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
// spell-checker:ignore (change!) each's
|
||||
// spell-checker:ignore (ToDO) LONGHELP FORMATSTRING templating parameterizing formatstr
|
||||
|
||||
|
@ -9,7 +8,6 @@ mod tokenize;
|
|||
|
||||
static NAME: &str = "printf";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static SHORT_USAGE: &str = "printf: usage: printf [-v var] format [arguments]";
|
||||
static LONGHELP_LEAD: &str = "printf
|
||||
|
||||
USAGE: printf FORMATSTRING [ARGUMENT]...
|
||||
|
|
|
@ -28,8 +28,7 @@ pub fn arrnum_int_mult(arr_num: &[u8], basenum: u8, base_ten_int_fact: u8) -> Ve
|
|||
}
|
||||
}
|
||||
}
|
||||
#[allow(clippy::map_clone)]
|
||||
let ret: Vec<u8> = ret_rev.iter().rev().map(|x| *x).collect();
|
||||
let ret: Vec<u8> = ret_rev.into_iter().rev().collect();
|
||||
ret
|
||||
}
|
||||
|
||||
|
@ -193,8 +192,7 @@ pub fn arrnum_int_add(arrnum: &[u8], basenum: u8, base_ten_int_term: u8) -> Vec<
|
|||
}
|
||||
}
|
||||
}
|
||||
#[allow(clippy::map_clone)]
|
||||
let ret: Vec<u8> = ret_rev.iter().rev().map(|x| *x).collect();
|
||||
let ret: Vec<u8> = ret_rev.into_iter().rev().collect();
|
||||
ret
|
||||
}
|
||||
|
||||
|
@ -220,8 +218,7 @@ pub fn unsigned_to_arrnum(src: u16) -> Vec<u8> {
|
|||
}
|
||||
|
||||
// temporary needs-improvement-function
|
||||
#[allow(unused_variables)]
|
||||
pub fn base_conv_float(src: &[u8], radix_src: u8, radix_dest: u8) -> f64 {
|
||||
pub fn base_conv_float(src: &[u8], radix_src: u8, _radix_dest: u8) -> f64 {
|
||||
// it would require a lot of addl code
|
||||
// to implement this for arbitrary string input.
|
||||
// until then, the below operates as an outline
|
||||
|
@ -269,7 +266,6 @@ pub fn arrnum_to_str(src: &[u8], radix_def_dest: &dyn RadixDef) -> String {
|
|||
str_out
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn base_conv_str(
|
||||
src: &str,
|
||||
radix_def_src: &dyn RadixDef,
|
||||
|
|
|
@ -43,13 +43,11 @@ impl Formatter for CninetyNineHexFloatf {
|
|||
// c99 hex has unique requirements of all floating point subs in pretty much every part of building a primitive, from prefix and suffix to need for base conversion (in all other cases if you don't have decimal you must have decimal, here it's the other way around)
|
||||
|
||||
// on the todo list is to have a trait for get_primitive that is implemented by each float formatter and can override a default. when that happens we can take the parts of get_primitive_dec specific to dec and spin them out to their own functions that can be overridden.
|
||||
#[allow(unused_variables)]
|
||||
#[allow(unused_assignments)]
|
||||
fn get_primitive_hex(
|
||||
inprefix: &InPrefix,
|
||||
str_in: &str,
|
||||
analysis: &FloatAnalysis,
|
||||
last_dec_place: usize,
|
||||
_str_in: &str,
|
||||
_analysis: &FloatAnalysis,
|
||||
_last_dec_place: usize,
|
||||
capitalized: bool,
|
||||
) -> FormatPrimitive {
|
||||
let prefix = Some(String::from(if inprefix.sign == -1 { "-0x" } else { "0x" }));
|
||||
|
@ -57,13 +55,13 @@ fn get_primitive_hex(
|
|||
// assign the digits before and after the decimal points
|
||||
// to separate slices. If no digits after decimal point,
|
||||
// assign 0
|
||||
let (mut first_segment_raw, second_segment_raw) = match analysis.decimal_pos {
|
||||
Some(pos) => (&str_in[..pos], &str_in[pos + 1..]),
|
||||
None => (str_in, "0"),
|
||||
};
|
||||
if first_segment_raw.is_empty() {
|
||||
first_segment_raw = "0";
|
||||
}
|
||||
//let (mut first_segment_raw, second_segment_raw) = match analysis.decimal_pos {
|
||||
//Some(pos) => (&str_in[..pos], &str_in[pos + 1..]),
|
||||
//None => (str_in, "0"),
|
||||
//};
|
||||
//if first_segment_raw.is_empty() {
|
||||
//first_segment_raw = "0";
|
||||
//}
|
||||
// convert to string, hexifying if input is in dec.
|
||||
// let (first_segment, second_segment) =
|
||||
// match inprefix.radix_in {
|
||||
|
|
|
@ -22,12 +22,11 @@ fn get_len_fprim(fprim: &FormatPrimitive) -> usize {
|
|||
len
|
||||
}
|
||||
|
||||
pub struct Decf {
|
||||
as_num: f64,
|
||||
}
|
||||
pub struct Decf;
|
||||
|
||||
impl Decf {
|
||||
pub fn new() -> Decf {
|
||||
Decf { as_num: 0.0 }
|
||||
Decf
|
||||
}
|
||||
}
|
||||
impl Formatter for Decf {
|
||||
|
|
|
@ -5,12 +5,10 @@ use super::super::format_field::FormatField;
|
|||
use super::super::formatter::{FormatPrimitive, Formatter, InPrefix};
|
||||
use super::float_common::{get_primitive_dec, primitive_to_str_common, FloatAnalysis};
|
||||
|
||||
pub struct Floatf {
|
||||
as_num: f64,
|
||||
}
|
||||
pub struct Floatf;
|
||||
impl Floatf {
|
||||
pub fn new() -> Floatf {
|
||||
Floatf { as_num: 0.0 }
|
||||
Floatf
|
||||
}
|
||||
}
|
||||
impl Formatter for Floatf {
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::i64;
|
|||
use std::u64;
|
||||
|
||||
pub struct Intf {
|
||||
a: u32,
|
||||
_a: u32,
|
||||
}
|
||||
|
||||
// see the Intf::analyze() function below
|
||||
|
@ -24,7 +24,7 @@ struct IntAnalysis {
|
|||
|
||||
impl Intf {
|
||||
pub fn new() -> Intf {
|
||||
Intf { a: 0 }
|
||||
Intf { _a: 0 }
|
||||
}
|
||||
// take a ref to argument string, and basic information
|
||||
// about prefix (offset, radix, sign), and analyze string
|
||||
|
|
|
@ -5,12 +5,11 @@ use super::super::format_field::FormatField;
|
|||
use super::super::formatter::{FormatPrimitive, Formatter, InPrefix};
|
||||
use super::float_common::{get_primitive_dec, primitive_to_str_common, FloatAnalysis};
|
||||
|
||||
pub struct Scif {
|
||||
as_num: f64,
|
||||
}
|
||||
pub struct Scif;
|
||||
|
||||
impl Scif {
|
||||
pub fn new() -> Scif {
|
||||
Scif { as_num: 0.0 }
|
||||
Scif
|
||||
}
|
||||
}
|
||||
impl Formatter for Scif {
|
||||
|
|
|
@ -242,18 +242,16 @@ impl UnescapedText {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
impl token::Tokenizer for UnescapedText {
|
||||
fn from_it(
|
||||
it: &mut PutBackN<Chars>,
|
||||
args: &mut Peekable<Iter<String>>,
|
||||
_: &mut Peekable<Iter<String>>,
|
||||
) -> Option<Box<dyn token::Token>> {
|
||||
UnescapedText::from_it_core(it, false)
|
||||
}
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
impl token::Token for UnescapedText {
|
||||
fn print(&self, pf_args_it: &mut Peekable<Iter<String>>) {
|
||||
fn print(&self, _: &mut Peekable<Iter<String>>) {
|
||||
cli::flush_bytes(&self.0[..]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue