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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "0.0.1"
authors = ["uutils developers"]
license = "MIT"
description = "sed ~ implemented as universal (cross-platform) utils, written in Rust"
default-run = "sedapp"
default-run = "sed"

homepage = "https://github.com/uutils/sed"
repository = "https://github.com/uutils/sed"
Expand Down Expand Up @@ -96,8 +96,8 @@ phf_codegen = { workspace = true }
path = "src/lib.rs"

[[bin]]
name = "sedapp"
path = "src/bin/sedapp.rs"
name = "sed"
path = "src/bin/sed.rs"

[[bin]]
name = "uudoc"
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ cargo build --release
cargo run --release
```

To call the binary `sed`, create a symlink like:

```bash
ln -s target/release/sedapp sed
```
The binary is named `sed` in `target/release/sed`.

## Extensions and incompatibilities
### Supported GNU extensions
Expand Down
39 changes: 39 additions & 0 deletions src/bin/sed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file is part of the uutils sed package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use std::ffi::OsString;
use std::process;

fn main() {
// Detect multicall vs single-call BEFORE any uucore calls
// This must happen first to set the utility name detection mode correctly
let raw_args: Vec<OsString> = std::env::args_os().collect();
if raw_args.len() > 1 && raw_args[1] == "sed" {
// Multicall binary mode: tell uucore to use args[1] for util_name()
uucore::set_utility_is_second_arg();
}

uucore::panic::mute_sigpipe_panic();

let mut args = raw_args;

// Strip .exe extension from binary name on Windows for consistent error messages
#[cfg(windows)]
if let Some(binary_name) = args.get_mut(0) {
let binary_str = binary_name.to_string_lossy();
if let Some(stripped) = binary_str.strip_suffix(".exe") {
*binary_name = OsString::from(stripped);
}
}

// Handle both single-call and multi-call binary compatibility
// If first argument after binary name is "sed", skip it (multi-call compatibility)
if args.len() > 1 && args[1] == "sed" {
args.remove(1);
}

let code = sed::sed::uumain(args.into_iter());
process::exit(code);
}
222 changes: 0 additions & 222 deletions src/bin/sedapp.rs

This file was deleted.

7 changes: 6 additions & 1 deletion src/sed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

#[allow(clippy::cognitive_complexity)]
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
#[cfg(windows)]
let util_name = "sed";
#[cfg(not(windows))]
let util_name = uucore::util_name();

Command::new(util_name)
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
Expand Down
6 changes: 5 additions & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
// file that was distributed with this source code.
use std::env;

pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_sedapp");
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_sed");

// Use the ctor attribute to run this function before any tests
#[ctor::ctor]
fn init() {
unsafe {
// Necessary for uutests to be able to find the binary
std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
// For single-call binaries, tell uutests not to auto-add the utility name
std::env::remove_var("UUTESTS_UTIL_NAME");
std::env::set_var("UUTESTS_UTIL_NAME", "");
std::env::set_var("UUTILS_MULTICALL", "0");
}
}

Expand Down
Loading