diff --git a/awk/Cargo.toml b/awk/Cargo.toml index 4b4eeba1..7a204133 100644 --- a/awk/Cargo.toml +++ b/awk/Cargo.toml @@ -7,7 +7,6 @@ edition.workspace = true rust-version.workspace = true [dependencies] -plib = { path = "../plib" } gettext-rs.workspace = true clap.workspace = true libc.workspace = true @@ -17,6 +16,9 @@ lazy_static = "1.4" lexical = { version = "6.1", features = ["format"] } rand = {version = "0.8", default-features = false, features = ["small_rng"] } +[dev-dependencies] +plib = { path = "../plib" } + [lints] workspace = true diff --git a/awk/src/main.rs b/awk/src/main.rs index ef181334..5118ffdf 100644 --- a/awk/src/main.rs +++ b/awk/src/main.rs @@ -11,8 +11,7 @@ use crate::compiler::compile_program; use crate::interpreter::interpret; use clap::Parser; use compiler::SourceFile; -use gettextrs::{bind_textdomain_codeset, gettext, textdomain}; -use plib::PROJECT_NAME; +use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use std::error::Error; use std::fmt::Display; use std::io::Read; @@ -56,8 +55,9 @@ fn exit_if_error(r: Result) -> T { } fn main() -> Result<(), Box> { - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + setlocale(LocaleCategory::LcAll, ""); + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; let args = Args::parse(); diff --git a/awk/tests/integration.rs b/awk/tests/integration.rs index 0c4f5bf3..831356c8 100644 --- a/awk/tests/integration.rs +++ b/awk/tests/integration.rs @@ -1,4 +1,4 @@ -use plib::{run_test, run_test_with_checker, TestPlan}; +use plib::testing::{run_test, run_test_with_checker, TestPlan}; fn test_awk(args: Vec, expected_output: &str) { run_test(TestPlan { diff --git a/calc/Cargo.toml b/calc/Cargo.toml index a204a80e..a568378d 100644 --- a/calc/Cargo.toml +++ b/calc/Cargo.toml @@ -7,7 +7,6 @@ edition.workspace = true rust-version.workspace = true [dependencies] -plib = { path = "../plib" } gettext-rs.workspace = true regex.workspace = true clap.workspace = true @@ -17,6 +16,9 @@ lazy_static = "1.4" bigdecimal = "0.4" rustyline = { version = "14.0", default-features = false } +[dev-dependencies] +plib = { path = "../plib" } + [lints] workspace = true diff --git a/calc/bc.rs b/calc/bc.rs index ef0fe5c0..46dc73ca 100644 --- a/calc/bc.rs +++ b/calc/bc.rs @@ -16,7 +16,6 @@ use bc_util::{ use clap::Parser; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use plib::PROJECT_NAME; use rustyline::{error::ReadlineError, DefaultEditor, Result}; mod bc_util; @@ -45,10 +44,11 @@ fn print_output_or_error(result: ExecutionResult) { fn main() -> Result<()> { setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; let args = Args::parse(); + let mut interpreter = Interpreter::default(); if args.define_math_functions { diff --git a/calc/expr.rs b/calc/expr.rs index e99efd9e..618d7739 100644 --- a/calc/expr.rs +++ b/calc/expr.rs @@ -8,7 +8,6 @@ // use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use plib::PROJECT_NAME; use regex::Regex; #[derive(Clone, Debug, PartialEq)] @@ -370,10 +369,9 @@ fn eval_expression(tokens: &[Token]) -> Result { } fn main() -> Result<(), Box> { - // initialize translations setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; // tokenize and evaluate the expression let arg_tokens = tokenize(); diff --git a/calc/tests/bc/mod.rs b/calc/tests/bc/mod.rs index b2a166e6..b9bf58af 100644 --- a/calc/tests/bc/mod.rs +++ b/calc/tests/bc/mod.rs @@ -7,7 +7,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test, TestPlan}; +use plib::testing::{run_test, TestPlan}; fn test_bc(program: &str, expected_output: &str) { run_test(TestPlan { diff --git a/calc/tests/expr/mod.rs b/calc/tests/expr/mod.rs index ee7eaee5..8cb428c2 100644 --- a/calc/tests/expr/mod.rs +++ b/calc/tests/expr/mod.rs @@ -7,7 +7,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test, TestPlan}; +use plib::testing::{run_test, TestPlan}; fn expr_test(args: &[&str], expected_output: &str) { let str_args: Vec = args.iter().map(|s| String::from(*s)).collect(); diff --git a/dev/Cargo.toml b/dev/Cargo.toml index 7ac48cb0..faebcd67 100644 --- a/dev/Cargo.toml +++ b/dev/Cargo.toml @@ -8,13 +8,15 @@ edition.workspace = true rust-version.workspace = true [dependencies] -plib = { path = "../plib" } clap.workspace = true gettext-rs.workspace = true object = { version = "0.35", features = ["read", "build", "elf"]} chrono.workspace = true ar = "0.9" +[dev-dependencies] +plib = { path = "../plib" } + [lints] workspace = true diff --git a/dev/nm.rs b/dev/nm.rs index ebae7ad8..2cb23893 100644 --- a/dev/nm.rs +++ b/dev/nm.rs @@ -18,7 +18,6 @@ use object::{ use clap::{Parser, ValueEnum}; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; -use plib::PROJECT_NAME; use std::collections::HashMap; use std::fs; @@ -143,12 +142,11 @@ fn show_object_file(args: &Args) -> Result<(), Box> { } fn main() -> Result<(), Box> { - // parse command line arguments - let args = Args::parse(); - setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; + + let args = Args::parse(); show_object_file(&args)?; diff --git a/dev/strings.rs b/dev/strings.rs index 7666cb32..f46164f9 100644 --- a/dev/strings.rs +++ b/dev/strings.rs @@ -12,7 +12,6 @@ use std::ffi::OsString; use clap::{Parser, ValueEnum}; use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory}; use object::{Object, ObjectSection}; -use plib::PROJECT_NAME; #[derive(Clone, Copy, ValueEnum)] enum OffsetFormat { @@ -188,10 +187,11 @@ where fn main() -> StringsResult { setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; let args = Args::parse(); + match CharacterSet::from_env() { CharacterSet::Utf8 => { for file in args.input_files { diff --git a/dev/strip.rs b/dev/strip.rs index e6eaa471..f3b210c7 100644 --- a/dev/strip.rs +++ b/dev/strip.rs @@ -7,11 +7,6 @@ // SPDX-License-Identifier: MIT // -use std::{ - ffi::{OsStr, OsString}, - io::Read, -}; - use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; use object::{ @@ -19,7 +14,10 @@ use object::{ build::elf::{Builder, Section, SectionData}, elf, }; -use plib::PROJECT_NAME; +use std::{ + ffi::{OsStr, OsString}, + io::Read, +}; #[derive(Parser)] #[command(version, about = gettext("strip - remove unnecessary information from strippable files"))] @@ -145,10 +143,11 @@ fn strip_file(file: &OsStr) { fn main() -> Result<(), Box> { setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; let args = Args::parse(); + for file in args.input_files { strip_file(&file); } diff --git a/dev/tests/dev-tests.rs b/dev/tests/dev-tests.rs index 89485119..835d3f30 100644 --- a/dev/tests/dev-tests.rs +++ b/dev/tests/dev-tests.rs @@ -1,5 +1,5 @@ use object::{Object, ObjectSection, ObjectSymbol}; -use plib::{run_test, run_test_with_checker, TestPlan}; +use plib::testing::{run_test, run_test_with_checker, TestPlan}; use std::fs; fn ar_compare_test( diff --git a/i18n/gencat.rs b/i18n/gencat.rs index 65fd0c10..5021ce90 100644 --- a/i18n/gencat.rs +++ b/i18n/gencat.rs @@ -1,7 +1,7 @@ use byteorder::{BigEndian, ByteOrder, LittleEndian, NativeEndian, WriteBytesExt}; use clap::Parser; use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory}; -use plib::PROJECT_NAME; +use plib::io::input_stream; use std::{ cell::RefCell, collections::BTreeMap, @@ -295,7 +295,7 @@ impl MessageCatalog { input_path: &PathBuf, catfile_catalog: Option, ) -> Result> { - let mut file = plib::io::input_stream(input_path, true)?; + let mut file = input_stream(input_path, true)?; let mut input = String::new(); file.read_to_string(&mut input)?; @@ -774,11 +774,11 @@ impl MessageCatalog { } fn main() -> Result<(), Box> { - let args = Args::parse(); - setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; + + let args = Args::parse(); let mut exit_code = 0; diff --git a/i18n/iconv.rs b/i18n/iconv.rs index 5636ed28..4ddae8d8 100644 --- a/i18n/iconv.rs +++ b/i18n/iconv.rs @@ -15,7 +15,7 @@ use iconv_lib::{ utf_32::{self, UTF32Variant}, utf_8, }; -use plib::PROJECT_NAME; +use plib::io::input_stream; use std::{ collections::HashMap, env, @@ -480,11 +480,11 @@ fn charmap_conversion( } fn main() -> Result<(), Box> { - let args = Args::parse(); - setlocale(LocaleCategory::LcAll, ""); - textdomain(PROJECT_NAME)?; - bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?; + textdomain(env!("PROJECT_NAME"))?; + bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?; + + let args = Args::parse(); if args.list_codesets { list_encodings(); @@ -517,7 +517,7 @@ fn main() -> Result<(), Box> { let inputs: Vec> = match args.files { Some(files) => files .into_iter() - .map(|file| plib::io::input_stream(&file, true)) + .map(|file| input_stream(&file, true)) .collect::, _>>()?, None => vec![Box::new(io::stdin().lock())], }; diff --git a/i18n/tests/gencat/mod.rs b/i18n/tests/gencat/mod.rs index a1f57b7c..5c4fbf0a 100644 --- a/i18n/tests/gencat/mod.rs +++ b/i18n/tests/gencat/mod.rs @@ -7,7 +7,7 @@ // SPDX-License-Identifier: MIT // -use plib::{run_test_u8, TestPlanU8}; +use plib::testing::{run_test_u8, TestPlanU8}; use std::env; use std::path::PathBuf; use std::{fs::File, io::Read}; diff --git a/i18n/tests/iconv/mod.rs b/i18n/tests/iconv/mod.rs index 2c3342dc..47b63ca7 100644 --- a/i18n/tests/iconv/mod.rs +++ b/i18n/tests/iconv/mod.rs @@ -8,7 +8,7 @@ // #![allow(non_snake_case)] -use plib::{run_test_u8, TestPlanU8}; +use plib::testing::{run_test_u8, TestPlanU8}; use std::env; use std::path::PathBuf; use std::{fs::File, io::Read}; diff --git a/plib/src/io.rs b/plib/src/io.rs index 969d4336..253763f4 100644 --- a/plib/src/io.rs +++ b/plib/src/io.rs @@ -11,8 +11,8 @@ use std::fs; use std::io::{self, Read}; use std::path::PathBuf; +/// open file, or stdin pub fn input_stream(pathname: &PathBuf, dashed_stdin: bool) -> io::Result> { - // open file, or stdin let path_str = pathname.as_os_str(); let file: Box = if (dashed_stdin && path_str == "-") || (!dashed_stdin && path_str.is_empty()) {