Skip to content

Commit

Permalink
pathnames: Use compile-time macro env!
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0 committed Oct 25, 2024
1 parent 3ad6191 commit a252197
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
4 changes: 3 additions & 1 deletion pathnames/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
plib = { path = "../plib" }
clap.workspace = true
gettext-rs.workspace = true
libc.workspace = true

[dev-dependencies]
plib = { path = "../plib" }

[lints]
workspace = true

Expand Down
13 changes: 6 additions & 7 deletions pathnames/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// SPDX-License-Identifier: MIT
//

use std::path::Path;

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::path::Path;

#[derive(Parser)]
#[command(
Expand Down Expand Up @@ -52,12 +52,11 @@ fn show_basename(args: &Args) {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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_basename(&args);

Expand Down
15 changes: 7 additions & 8 deletions pathnames/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// SPDX-License-Identifier: MIT
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::ffi::OsString;
use std::path::PathBuf;

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};

#[derive(Parser)]
#[command(
version,
Expand Down Expand Up @@ -40,12 +40,11 @@ fn show_dirname(args: &Args) {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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_dirname(&args);

Expand Down
15 changes: 7 additions & 8 deletions pathnames/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// SPDX-License-Identifier: MIT
//

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::ffi::CString;
use std::path::{Component, Path};

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};

const _POSIX_PATH_MAX: usize = 255;
const _POSIX_NAME_MAX: usize = 14;

Expand Down Expand Up @@ -142,12 +142,11 @@ fn check_path(args: &Args, pathname: &str) -> Result<(), &'static str> {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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();

let mut exit_code = 0;

Expand Down
12 changes: 6 additions & 6 deletions pathnames/realpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// SPDX-License-Identifier: MIT
//

use std::path::{Component, Path, PathBuf};

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
use plib::PROJECT_NAME;
use std::path::{Component, Path, PathBuf};

/// realpath -- return resolved canonical path
#[derive(Parser)]
Expand Down Expand Up @@ -63,11 +63,11 @@ fn normalize<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
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;

Expand Down
2 changes: 1 addition & 1 deletion pathnames/tests/basename/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// SPDX-License-Identifier: MIT
//

use plib::{run_test, TestPlan};
use plib::testing::{run_test, TestPlan};

#[test]
fn basename_basic() {
Expand Down
2 changes: 1 addition & 1 deletion pathnames/tests/dirname/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// SPDX-License-Identifier: MIT
//

use plib::{run_test, TestPlan};
use plib::testing::{run_test, TestPlan};

#[test]
fn dirname_basic() {
Expand Down
2 changes: 1 addition & 1 deletion pathnames/tests/realpath/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// SPDX-License-Identifier: MIT
//

use plib::{run_test, TestPlan};
use plib::testing::{run_test, TestPlan};

fn realpath_test(args: &[&str], stdout: &str, stderr: &str, expected_code: i32) {
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();
Expand Down

0 comments on commit a252197

Please sign in to comment.