Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/generated/cat_args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uu/cat/
// Source: uutils/coreutils@8613dffab src/uu/cat/
// Regenerate: cargo run -p bashkit-coreutils-port -- <UUTILS_DIR> cat <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down
52 changes: 16 additions & 36 deletions crates/bashkit/src/builtins/generated/extendedbigdecimal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/extendedbigdecimal.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/extendedbigdecimal.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down Expand Up @@ -147,14 +147,10 @@ impl Add for ExtendedBigDecimal {
fn add(self, other: Self) -> Self {
match (self, other) {
(Self::BigDecimal(m), Self::BigDecimal(n)) => Self::BigDecimal(m.add(n)),
(Self::BigDecimal(_), Self::MinusInfinity)
| (Self::MinusInfinity, Self::BigDecimal(_))
| (Self::MinusInfinity, Self::MinusInfinity)
| (Self::MinusInfinity, Self::MinusZero) => Self::MinusInfinity,
(Self::BigDecimal(_), Self::Infinity)
| (Self::Infinity, Self::BigDecimal(_))
| (Self::Infinity, Self::Infinity)
| (Self::Infinity, Self::MinusZero) => Self::Infinity,
(Self::BigDecimal(_) | Self::MinusInfinity, Self::MinusInfinity)
| (Self::MinusInfinity, Self::BigDecimal(_) | Self::MinusZero) => Self::MinusInfinity,
(Self::BigDecimal(_) | Self::Infinity, Self::Infinity)
| (Self::Infinity, Self::BigDecimal(_) | Self::MinusZero) => Self::Infinity,
(Self::BigDecimal(m), Self::MinusZero) => Self::BigDecimal(m),
(Self::Infinity, Self::MinusInfinity)
| (Self::MinusInfinity, Self::Infinity)
Expand All @@ -169,22 +165,12 @@ impl PartialEq for ExtendedBigDecimal {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::BigDecimal(m), Self::BigDecimal(n)) => m.eq(n),
(Self::BigDecimal(_), Self::MinusInfinity)
| (Self::BigDecimal(_), Self::Infinity)
| (Self::BigDecimal(_), Self::MinusZero)
| (Self::Infinity, Self::BigDecimal(_))
| (Self::Infinity, Self::MinusZero)
| (Self::Infinity, Self::MinusInfinity)
| (Self::MinusInfinity, Self::BigDecimal(_))
| (Self::MinusInfinity, Self::Infinity)
| (Self::MinusInfinity, Self::MinusZero)
| (Self::MinusZero, Self::BigDecimal(_))
| (Self::MinusZero, Self::Infinity)
| (Self::MinusZero, Self::MinusInfinity)
| (Self::Nan, _)
| (Self::MinusNan, _)
| (_, Self::Nan)
| (_, Self::MinusNan) => false,
(Self::BigDecimal(_) | Self::Infinity | Self::MinusZero, Self::MinusInfinity)
| (Self::BigDecimal(_) | Self::MinusInfinity | Self::MinusZero, Self::Infinity)
| (Self::BigDecimal(_) | Self::Infinity | Self::MinusInfinity, Self::MinusZero)
| (Self::Infinity | Self::MinusInfinity | Self::MinusZero, Self::BigDecimal(_))
| (Self::Nan | Self::MinusNan, _)
| (_, Self::Nan | Self::MinusNan) => false,
(Self::Infinity, Self::Infinity)
| (Self::MinusInfinity, Self::MinusInfinity)
| (Self::MinusZero, Self::MinusZero) => true,
Expand All @@ -195,22 +181,16 @@ impl PartialOrd for ExtendedBigDecimal {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) {
(Self::BigDecimal(m), Self::BigDecimal(n)) => m.partial_cmp(n),
(Self::BigDecimal(_), Self::MinusInfinity)
| (Self::Infinity, Self::BigDecimal(_))
| (Self::Infinity, Self::MinusZero)
| (Self::Infinity, Self::MinusInfinity)
| (Self::MinusZero, Self::MinusInfinity) => Some(Ordering::Greater),
(Self::BigDecimal(_), Self::Infinity)
| (Self::MinusInfinity, Self::BigDecimal(_))
| (Self::MinusInfinity, Self::Infinity)
| (Self::MinusInfinity, Self::MinusZero)
| (Self::MinusZero, Self::Infinity) => Some(Ordering::Less),
(Self::BigDecimal(_) | Self::Infinity | Self::MinusZero, Self::MinusInfinity)
| (Self::Infinity, Self::BigDecimal(_) | Self::MinusZero) => Some(Ordering::Greater),
(Self::BigDecimal(_) | Self::MinusInfinity | Self::MinusZero, Self::Infinity)
| (Self::MinusInfinity, Self::BigDecimal(_) | Self::MinusZero) => Some(Ordering::Less),
(Self::BigDecimal(m), Self::MinusZero) => m.partial_cmp(&BigDecimal::zero()),
(Self::Infinity, Self::Infinity)
| (Self::MinusZero, Self::MinusZero)
| (Self::MinusInfinity, Self::MinusInfinity) => Some(Ordering::Equal),
(Self::MinusZero, Self::BigDecimal(n)) => BigDecimal::zero().partial_cmp(n),
(Self::Nan, _) | (Self::MinusNan, _) | (_, Self::Nan) | (_, Self::MinusNan) => None,
(Self::Nan | Self::MinusNan, _) | (_, Self::Nan | Self::MinusNan) => None,
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/bashkit/src/builtins/generated/format/argument.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/format/argument.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/format/argument.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'a> FormatArguments<'a> {
let Ok(s) = os_str_as_bytes(os) else {
return Err(ExtendedParserError::NotNumeric);
};
let (Some((b'"', bytes)) | Some((b'\'', bytes))) = s.split_first() else {
let Some((b'"' | b'\'', bytes)) = s.split_first() else {
debug_assert!(false);
return Err(ExtendedParserError::NotNumeric);
};
Expand Down Expand Up @@ -170,26 +170,27 @@ fn extract_value<T: Default>(
match p {
Ok(v) => v,
Err(e) => {
set_exit_code(1);
let input = locale_aware_escape_name(OsStr::new(input), QuotingStyle::C_NO_QUOTES);
let input = locale_aware_escape_name(OsStr::new(input), QuotingStyle::Escape);
match e {
ExtendedParserError::Overflow(v) | ExtendedParserError::Underflow(v) => {
set_exit_code(1);
show_error!("{}: Numerical result out of range", input.quote());
v
}
ExtendedParserError::NotNumeric => {
set_exit_code(1);
show_error!("{}: expected a numeric value", input.quote());
Default::default()
}
ExtendedParserError::PartialMatch(v, rest) => {
if quote_start {
set_exit_code(0);
if ::std::option::Option::<::std::ffi::OsString>::None.is_none() {
show_warning!(
"{rest}: character(s) following character constant have been ignored"
);
}
} else {
set_exit_code(1);
show_error!("{}: value not completely converted", input.quote());
}
v
Expand Down
22 changes: 18 additions & 4 deletions crates/bashkit/src/builtins/generated/format/escape.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/format/escape.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/format/escape.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand All @@ -25,6 +25,19 @@ pub enum OctalParsing {
ThreeDigits = 3,
}
#[derive(Clone, Copy)]
pub enum EscapeSet {
/// Interpret `\"`, `\u` and `\U` on top of the shared sequences.
WithUnicodeAndQuote,
/// Only the shared sequences. `\"`, `\u` and `\U` are not escape sequences
/// and are emitted with their backslash, like any other unknown escape.
WithoutUnicodeAndQuote,
}
impl EscapeSet {
fn has_unicode_and_quote(self) -> bool {
matches!(self, Self::WithUnicodeAndQuote)
}
}
#[derive(Clone, Copy)]
enum Base {
Oct(OctalParsing),
Hex,
Expand Down Expand Up @@ -99,6 +112,7 @@ pub enum EscapeError {
pub fn parse_escape_code(
rest: &mut &[u8],
zero_octal_parsing: OctalParsing,
escape_set: EscapeSet,
) -> Result<EscapedChar, FormatError> {
if let [c, new_rest @ ..] = rest {
if let b'1'..=b'7' = c
Expand All @@ -109,7 +123,7 @@ pub fn parse_escape_code(
*rest = new_rest;
match c {
b'\\' => Ok(EscapedChar::Byte(b'\\')),
b'"' => Ok(EscapedChar::Byte(b'"')),
b'"' if escape_set.has_unicode_and_quote() => Ok(EscapedChar::Byte(b'"')),
b'a' => Ok(EscapedChar::Byte(b'\x07')),
b'b' => Ok(EscapedChar::Byte(b'\x08')),
b'c' => Ok(EscapedChar::End),
Expand All @@ -129,14 +143,14 @@ pub fn parse_escape_code(
b'0' => Ok(EscapedChar::Byte(
parse_code(rest, Base::Oct(zero_octal_parsing)).unwrap_or(b'\0'),
)),
b'u' => match parse_unicode(rest, 4) {
b'u' if escape_set.has_unicode_and_quote() => match parse_unicode(rest, 4) {
Ok(c) => Ok(EscapedChar::Char(c)),
Err(EscapeError::MissingHexadecimalNumber) => Err(FormatError::MissingHex(None)),
Err(EscapeError::InvalidCharacters(chars)) => {
Err(FormatError::InvalidCharacter('u', chars, None))
}
},
b'U' => match parse_unicode(rest, 8) {
b'U' if escape_set.has_unicode_and_quote() => match parse_unicode(rest, 8) {
Ok(c) => Ok(EscapedChar::Char(c)),
Err(EscapeError::MissingHexadecimalNumber) => Err(FormatError::MissingHex(None)),
Err(EscapeError::InvalidCharacters(chars)) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/bashkit/src/builtins/generated/format/human.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/format/human.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/format/human.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down
16 changes: 11 additions & 5 deletions crates/bashkit/src/builtins/generated/format/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/format/mod.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/format/mod.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down Expand Up @@ -36,6 +36,7 @@ mod escape;
pub mod human;
pub mod num_format;
mod spec;
pub use self::escape::EscapeSet;
pub use self::escape::EscapedChar;
pub use self::escape::OctalParsing;
use self::escape::parse_escape_code;
Expand Down Expand Up @@ -238,9 +239,13 @@ pub fn parse_spec_and_escape(
let start = fmt.len() - current.len();
current = rest;
Some(
parse_escape_code(&mut current, OctalParsing::default())
.map(FormatItem::Char)
.map_err(|e| e.spanned(start..fmt.len() - current.len())),
parse_escape_code(
&mut current,
OctalParsing::default(),
EscapeSet::WithUnicodeAndQuote,
)
.map(FormatItem::Char)
.map_err(|e| e.spanned(start..fmt.len() - current.len())),
)
}
[c, rest @ ..] => {
Expand Down Expand Up @@ -278,14 +283,15 @@ pub fn parse_spec_only(
pub fn parse_escape_only(
fmt: &[u8],
zero_octal_parsing: OctalParsing,
escape_set: EscapeSet,
) -> impl Iterator<Item = EscapedChar> + '_ {
let mut current = fmt;
std::iter::from_fn(move || match current {
[] => None,
[b'\\', rest @ ..] => {
current = rest;
Some(
parse_escape_code(&mut current, zero_octal_parsing)
parse_escape_code(&mut current, zero_octal_parsing, escape_set)
.unwrap_or(EscapedChar::Backslash(b'x')),
)
}
Expand Down
62 changes: 51 additions & 11 deletions crates/bashkit/src/builtins/generated/format/num_format.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@6579cc2 src/uucore/src/lib/features/format/num_format.rs
// Source: uutils/coreutils@8613dffab src/uucore/src/lib/features/format/num_format.rs
// Regenerate: cargo run -p bashkit-coreutils-port -- port-module <UUTILS_DIR> format <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.
Expand Down Expand Up @@ -319,6 +319,14 @@ fn zero_pad_to(s: &str, width: usize) -> String {
padded
}
}
fn zero_with_fraction_digits(precision: usize) -> String {
if precision == 0 {
return String::from("0");
}
let mut s = String::from("0.");
s.extend(std::iter::repeat_n('0', precision));
s
}
fn get_sign_indicator(sign: PositiveSign, negative: bool) -> String {
if negative {
String::from("-")
Expand All @@ -344,6 +352,22 @@ fn format_float_non_finite(e: &ExtendedBigDecimal, case: Case) -> String {
}
s
}
const MAX_FMT_PRECISION: usize = u16::MAX as usize;
fn integer_digits(bd: &BigDecimal) -> Option<String> {
let (bi, scale) = bd.as_bigint_and_scale();
if scale > 0 {
return None;
}
if bi.is_zero() {
return Some(String::from("0"));
}
let zeros = usize::try_from(scale.unsigned_abs())
.ok()
.filter(|zeros| *zeros <= super::MAX_FORMAT_WIDTH)?;
let mut s = bi.to_str_radix(10);
s.extend(std::iter::repeat_n('0', zeros));
Some(s)
}
fn format_float_decimal(
bd: &BigDecimal,
precision: Option<usize>,
Expand All @@ -352,12 +376,25 @@ fn format_float_decimal(
debug_assert!(!bd.is_negative());
let precision = precision.unwrap_or(6);
if precision == 0 {
let (bi, scale) = bd.as_bigint_and_scale();
if scale == 0 && force_decimal != ForceDecimal::Yes {
return bi.to_str_radix(10);
} else if force_decimal == ForceDecimal::Yes {
return format!("{bd:.0}.");
}
let s = integer_digits(bd).unwrap_or_else(|| format!("{bd:.0}"));
return if force_decimal == ForceDecimal::Yes {
format!("{s}.")
} else {
s
};
}
let digits = usize::try_from(bd.fractional_digit_count().max(0)).unwrap_or(usize::MAX);
let written = digits.min(MAX_FMT_PRECISION);
if precision > written {
let mut s = if written > 0 {
format!("{bd:.written$}")
} else if let Some(s) = integer_digits(bd) {
s + "."
} else {
return format!("{bd:.0}");
};
s.extend(std::iter::repeat_n('0', precision - written));
return s;
}
format!("{bd:.precision$}")
}
Expand Down Expand Up @@ -389,7 +426,7 @@ fn format_float_scientific(
return if force_decimal == ForceDecimal::Yes && precision == 0 {
format!("0.{exp_char}+00")
} else {
format!("{:.precision$}{exp_char}+00", 0.0)
format!("{}{exp_char}+00", zero_with_fraction_digits(precision))
};
}
let (digits, exponent) = bd_to_string_exp_with_prec(bd, precision + 1);
Expand All @@ -414,7 +451,7 @@ fn format_float_shortest(
if BigDecimal::zero().eq(bd) {
return match (force_decimal, precision) {
(ForceDecimal::Yes, 1) => "0.".into(),
(ForceDecimal::Yes, _) => format!("{:.*}", precision - 1, 0.0),
(ForceDecimal::Yes, _) => zero_with_fraction_digits(precision - 1),
(ForceDecimal::No, _) => "0".into(),
};
}
Expand Down Expand Up @@ -470,9 +507,12 @@ fn format_float_hexadecimal(
};
if BigDecimal::zero().eq(bd) {
return if force_decimal == ForceDecimal::Yes && precision.unwrap_or(0) == 0 {
format!("0x0.{exp_char}+0")
format!("{prefix}0.{exp_char}+0")
} else {
format!("0x{:.*}{exp_char}+0", precision.unwrap_or(0), 0.0)
format!(
"{prefix}{}{exp_char}+0",
zero_with_fraction_digits(precision.unwrap_or(0))
)
};
}
let (frac10, p) = bd.as_bigint_and_exponent();
Expand Down
Loading
Loading