diff --git a/Cargo.lock b/Cargo.lock index 9bcb00d7c..76f107590 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,12 +62,6 @@ dependencies = [ "parking_lot_core", ] -[[package]] -name = "either" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" - [[package]] name = "errno" version = "0.2.8" @@ -109,7 +103,7 @@ dependencies = [ "num-traits", "once_cell", "pcre2", - "printf-compat", + "printf", "rand", "rand_pcg", "rsconf", @@ -150,15 +144,6 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - [[package]] name = "jobserver" version = "0.1.31" @@ -356,17 +341,6 @@ dependencies = [ "widestring", ] -[[package]] -name = "printf-compat" -version = "0.1.1" -source = "git+https://github.com/fish-shell/printf-compat.git?branch=fish#ff460021ba11e2a2c69e1fe04cb1961d6a75be15" -dependencies = [ - "bitflags 1.3.2", - "itertools", - "libc", - "widestring", -] - [[package]] name = "proc-macro2" version = "1.0.82" diff --git a/Cargo.toml b/Cargo.toml index 61f70668a..c849bc1e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ default-run = "fish" [dependencies] pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", branch = "master", default-features = false, features = ["utf32"] } fast-float = { git = "https://github.com/fish-shell/fast-float-rust", branch="fish" } -printf-compat = { git = "https://github.com/fish-shell/printf-compat.git", branch="fish" } bitflags = "2.4.0" errno = "0.2.8" @@ -35,6 +34,7 @@ lru = "0.10.0" nix = { version = "0.25.0", default-features = false, features = ["inotify", "resource", "fs"] } num-traits = "0.2.15" once_cell = "1.17.0" +printf = { path = "./printf" } rand = { version = "0.8.5", features = ["small_rng"] } widestring = "1.0.2" terminfo = "0.9.0" diff --git a/src/builtins/jobs.rs b/src/builtins/jobs.rs index db4248c0f..7660091af 100644 --- a/src/builtins/jobs.rs +++ b/src/builtins/jobs.rs @@ -18,7 +18,7 @@ wutil::{fish_wcstoi, wgettext_fmt}, }; use libc::c_int; -use printf_compat::sprintf; +use printf::sprintf; use std::num::NonZeroU32; use std::sync::atomic::Ordering; diff --git a/src/builtins/printf.rs b/src/builtins/printf.rs index 7ffd37a29..4c896c7f3 100644 --- a/src/builtins/printf.rs +++ b/src/builtins/printf.rs @@ -57,8 +57,7 @@ wcstoi::{wcstoi_partial, Options as WcstoiOpts}, wstr_offset_in, }; -use printf_compat::args::ToArg; -use printf_compat::printf::sprintf_locale; +use printf::{sprintf_locale, ToArg}; /// Return true if `c` is an octal digit. fn is_octal_digit(c: char) -> bool { @@ -266,10 +265,10 @@ macro_rules! append_output_fmt { if !self.early_exit { sprintf_locale( &mut self.buff, - $fmt, + $fmt.as_char_slice(), &self.locale, - &[$($arg.to_arg()),*] - ) + &mut [$($arg.to_arg()),*] + ).expect("sprintf failed"); } } } diff --git a/src/builtins/string/match.rs b/src/builtins/string/match.rs index e625f9eb3..af0ff4da8 100644 --- a/src/builtins/string/match.rs +++ b/src/builtins/string/match.rs @@ -1,5 +1,5 @@ use pcre2::utf32::{Captures, Regex, RegexBuilder}; -use printf_compat::sprintf; +use printf::sprintf; use std::collections::HashMap; use super::*; diff --git a/src/complete.rs b/src/complete.rs index 8d129384f..2cf9feb0c 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -16,7 +16,7 @@ }; use bitflags::bitflags; use once_cell::sync::Lazy; -use printf_compat::sprintf; +use printf::sprintf; use crate::{ abbrs::with_abbrs, diff --git a/src/job_group.rs b/src/job_group.rs index 5055999c3..a9ad2a798 100644 --- a/src/job_group.rs +++ b/src/job_group.rs @@ -41,8 +41,8 @@ fn to_wstring(&self) -> WString { } } -impl<'a> printf_compat::args::ToArg<'a> for MaybeJobId { - fn to_arg(self) -> printf_compat::args::Arg<'a> { +impl<'a> printf::ToArg<'a> for MaybeJobId { + fn to_arg(self) -> printf::Arg<'a> { self.as_num().to_arg() } } diff --git a/src/key.rs b/src/key.rs index d00036816..cfb580ef1 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; - use libc::VERASE; use crate::{ @@ -376,9 +374,9 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { } } -impl printf_compat::args::ToArg<'static> for Key { - fn to_arg(self) -> printf_compat::args::Arg<'static> { - printf_compat::args::Arg::BoxedStr(Rc::new(WString::from(self).into_boxed_utfstr())) +impl printf::ToArg<'static> for Key { + fn to_arg(self) -> printf::Arg<'static> { + printf::Arg::WString(self.into()) } } diff --git a/src/locale.rs b/src/locale.rs index 6785ed4da..99e0d94f0 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -1,5 +1,5 @@ /// Support for the "current locale." -pub use printf_compat::locale::{Locale, C_LOCALE}; +pub use printf::locale::{Locale, C_LOCALE}; use std::sync::Mutex; /// Lock guarding libc `setlocale()` or `localeconv()` calls to avoid races. diff --git a/src/parse_constants.rs b/src/parse_constants.rs index 79df932eb..3b8d0eb73 100644 --- a/src/parse_constants.rs +++ b/src/parse_constants.rs @@ -235,9 +235,9 @@ pub fn to_wstr(self) -> &'static wstr { } } -impl printf_compat::args::ToArg<'static> for ParseKeyword { - fn to_arg(self) -> printf_compat::args::Arg<'static> { - printf_compat::args::Arg::Str(self.to_wstr()) +impl printf::ToArg<'static> for ParseKeyword { + fn to_arg(self) -> printf::Arg<'static> { + printf::Arg::WStr(self.to_wstr()) } } diff --git a/src/parser.rs b/src/parser.rs index 585d7b782..236816dc6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -32,7 +32,7 @@ use crate::wutil::{perror, wgettext, wgettext_fmt}; use crate::{function, FLOG}; use libc::c_int; -use printf_compat::sprintf; +use printf::sprintf; use std::cell::{Ref, RefCell, RefMut}; use std::ffi::{CStr, OsStr}; use std::os::fd::{AsRawFd, OwnedFd, RawFd}; diff --git a/src/proc.rs b/src/proc.rs index 9f941856c..66a7d97ea 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -31,7 +31,7 @@ _SC_CLK_TCK, }; use once_cell::sync::Lazy; -use printf_compat::sprintf; +use printf::sprintf; use std::cell::{Cell, Ref, RefCell, RefMut}; use std::fs; use std::io::{Read, Write}; diff --git a/src/tokenizer.rs b/src/tokenizer.rs index c6d9521f0..a23bc6d9a 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -191,9 +191,10 @@ fn from(err: TokenizerError) -> Self { } } -impl printf_compat::args::ToArg<'static> for TokenizerError { - fn to_arg(self) -> printf_compat::args::Arg<'static> { - printf_compat::args::Arg::Str(self.into()) +impl printf::ToArg<'static> for TokenizerError { + fn to_arg(self) -> printf::Arg<'static> { + let msg: &'static wstr = self.into(); + printf::Arg::WStr(msg) } } diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 49d8bbe1c..abb73978b 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -21,12 +21,14 @@ use crate::wcstringutil::{join_strings, wcs2string_callback}; use errno::errno; pub use gettext::{wgettext, wgettext_fmt, wgettext_maybe_fmt, wgettext_str}; -pub use printf::sprintf; use std::ffi::{CStr, OsStr}; use std::fs::{self, canonicalize}; use std::io::{self, Write}; use std::os::unix::prelude::*; +extern crate printf as extern_printf; +pub use extern_printf::sprintf; + pub use wcstoi::*; /// Wide character version of opendir(). Note that opendir() is guaranteed to set close-on-exec by diff --git a/src/wutil/printf.rs b/src/wutil/printf.rs index 880943230..859aac619 100644 --- a/src/wutil/printf.rs +++ b/src/wutil/printf.rs @@ -1,5 +1,5 @@ // Re-export sprintf macro. -pub use printf_compat::sprintf; +pub use printf::sprintf; #[cfg(test)] mod tests {