1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

uucore: move printf::memo module to uucore

Move the `printf::memo` module to `uucore` so that it can be used by
other programs, not just `printf`. For example, the `-f` option to `seq`
requires parsing and formatting numbers according to the same logic as
`printf`.
This commit is contained in:
Jeffrey Finkelstein 2021-11-29 20:17:27 -05:00
parent 2d66c84413
commit d9afdf0527
25 changed files with 27 additions and 17 deletions

1
Cargo.lock generated
View file

@ -3212,6 +3212,7 @@ dependencies = [
"data-encoding-macro",
"dns-lookup",
"dunce",
"itertools 0.8.2",
"lazy_static",
"libc",
"nix 0.23.1",

View file

@ -20,7 +20,7 @@ path = "src/printf.rs"
[dependencies]
clap = { version = "2.33", features = ["wrap_help"] }
itertools = "0.8.0"
uucore = { version=">=0.0.11", package="uucore", path="../../uucore" }
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["memo"] }
uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" }
[[bin]]

View file

@ -1,3 +1 @@
mod cli;
mod memo;
mod tokenize;

View file

@ -4,11 +4,9 @@
use clap::{crate_version, App, Arg};
use uucore::error::{UResult, UUsageError};
use uucore::memo;
use uucore::InvalidEncodingHandling;
mod memo;
mod tokenize;
const VERSION: &str = "version";
const HELP: &str = "help";
static LONGHELP_LEAD: &str = "printf

View file

@ -21,6 +21,7 @@ dns-lookup = { version="1.0.5", optional=true }
dunce = "1.0.0"
wild = "2.0"
# * optional
itertools = { version="0.8", optional=true }
thiserror = { version="1.0", optional=true }
time = { version="<= 0.1.43", optional=true }
# * "problem" dependencies (pinned)
@ -53,6 +54,7 @@ encoding = ["data-encoding", "data-encoding-macro", "z85", "thiserror"]
entries = ["libc"]
fs = ["libc", "nix", "winapi-util"]
fsext = ["libc", "time"]
memo = ["itertools"]
mode = ["libc"]
perms = ["libc", "walkdir"]
process = ["libc"]

View file

@ -6,8 +6,12 @@ pub mod encoding;
pub mod fs;
#[cfg(feature = "fsext")]
pub mod fsext;
#[cfg(feature = "memo")]
pub mod memo;
#[cfg(feature = "ringbuffer")]
pub mod ringbuffer;
#[cfg(feature = "memo")]
mod tokenize;
// * (platform-specific) feature-gated modules
// ** non-windows (i.e. Unix + Fuchsia)

View file

@ -5,15 +5,14 @@
//! 2. feeds remaining arguments into function
//! that prints tokens.
use crate::display::Quotable;
use crate::features::tokenize::sub::Sub;
use crate::features::tokenize::token::{Token, Tokenizer};
use crate::features::tokenize::unescaped_text::UnescapedText;
use crate::show_warning;
use itertools::put_back_n;
use std::iter::Peekable;
use std::slice::Iter;
use uucore::display::Quotable;
use uucore::show_warning;
use crate::tokenize::sub::Sub;
use crate::tokenize::token::{Token, Tokenizer};
use crate::tokenize::unescaped_text::UnescapedText;
pub struct Memo {
tokens: Vec<Box<dyn Token>>,

View file

@ -1,9 +1,9 @@
//! Primitives used by num_format and sub_modules.
//! never dealt with above (e.g. Sub Tokenizer never uses these)
use crate::{display::Quotable, show_error};
use itertools::{put_back_n, PutBackN};
use std::str::Chars;
use uucore::{display::Quotable, show_error};
use super::format_field::FormatField;

View file

@ -32,17 +32,20 @@ pub fn arrnum_int_mult(arr_num: &[u8], basenum: u8, base_ten_int_fact: u8) -> Ve
ret
}
#[allow(dead_code)]
pub struct Remainder<'a> {
pub position: usize,
pub replace: Vec<u8>,
pub arr_num: &'a Vec<u8>,
}
#[allow(dead_code)]
pub struct DivOut<'a> {
pub quotient: u8,
pub remainder: Remainder<'a>,
}
#[allow(dead_code)]
pub fn arrnum_int_div_step(
rem_in: Remainder,
radix_in: u8,
@ -141,6 +144,7 @@ pub fn base_conv_vec(src: &[u8], radix_src: u8, radix_dest: u8) -> Vec<u8> {
result
}
#[allow(dead_code)]
pub fn unsigned_to_arrnum(src: u16) -> Vec<u8> {
let mut result: Vec<u8> = Vec::new();
let mut src_tmp: u16 = src;

View file

@ -9,6 +9,7 @@ use super::base_conv::RadixDef;
use super::float_common::{primitive_to_str_common, FloatAnalysis};
pub struct CninetyNineHexFloatf {
#[allow(dead_code)]
as_num: f64,
}
impl CninetyNineHexFloatf {
@ -91,6 +92,7 @@ fn get_primitive_hex(
}
}
#[allow(dead_code)]
fn to_hex(src: &str, before_decimal: bool) -> String {
let radix_ten = base_conv::RadixTen;
let radix_hex = base_conv::RadixHex;

View file

@ -7,8 +7,8 @@
use std::env;
use std::vec::Vec;
use uucore::display::Quotable;
use uucore::{show_error, show_warning};
use crate::display::Quotable;
use crate::{show_error, show_warning};
use super::format_field::{FieldType, FormatField};
use super::formatter::{Base, FormatPrimitive, Formatter, InitialPrefix};

View file

@ -5,12 +5,12 @@
//! it is created by Sub's implementation of the Tokenizer trait
//! Subs which have numeric field chars make use of the num_format
//! submodule
use crate::show_error;
use itertools::{put_back_n, PutBackN};
use std::iter::Peekable;
use std::process::exit;
use std::slice::Iter;
use std::str::Chars;
use uucore::show_error;
// use std::collections::HashSet;
use super::num_format::format_field::{FieldType, FormatField};

View file

@ -3,7 +3,7 @@
//! and escaped character literals (of allowed escapes),
//! into an unescaped text byte array
// spell-checker:ignore (ToDO) retval hexchars octals printf's bvec vals coreutil addchar eval bytecode
// spell-checker:ignore (ToDO) retval hexchars octals printf's bvec vals coreutil addchar eval bytecode bslice
use itertools::PutBackN;
use std::char::from_u32;

View file

@ -36,6 +36,8 @@ pub use crate::features::encoding;
pub use crate::features::fs;
#[cfg(feature = "fsext")]
pub use crate::features::fsext;
#[cfg(feature = "memo")]
pub use crate::features::memo;
#[cfg(feature = "ringbuffer")]
pub use crate::features::ringbuffer;