From 9d24b7378294c625954d4ac1dce520525beecdf8 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Sat, 22 Mar 2025 14:26:04 +0200 Subject: [PATCH 01/16] Remove GNU --binary option There are specialized commands that can handle this (tr, dos2unit). Adding such support to every command runs against the Unix philosphy. Furthermore, Rust, for good reasons, does not support opening files in binary or text mode, so such support (which is complex and platform dependent) would have to be emulated. --- src/uu/sed/src/sed.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uu/sed/src/sed.rs b/src/uu/sed/src/sed.rs index 48fa4590..23e76371 100644 --- a/src/uu/sed/src/sed.rs +++ b/src/uu/sed/src/sed.rs @@ -118,7 +118,6 @@ pub fn uu_app() -> Command { .short('a') .help("Create or truncate all output files before processing.") .action(clap::ArgAction::SetTrue), - arg!(-b --binary "Treat files as binary: do not process CR+LFs."), arg!(--debug "Annotate program execution."), Arg::new("regexp-extended") .short('E') From d540eef0805b312640355094a7f3109fd8dfff59 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Sat, 22 Mar 2025 15:22:41 +0200 Subject: [PATCH 02/16] Create processing context out of CLI options --- LICENSE | 2 +- src/uu/sed/src/command.rs | 28 ++++++++- src/uu/sed/src/sed.rs | 129 +++++++++++++++++++++++++++++++++++++- 3 files changed, 154 insertions(+), 5 deletions(-) diff --git a/LICENSE b/LICENSE index 6bd7307b..c66459ce 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 uutils +Copyright (c) 2025 Diomidis Spinellis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/uu/sed/src/command.rs b/src/uu/sed/src/command.rs index c395c8fb..4e85fa50 100644 --- a/src/uu/sed/src/command.rs +++ b/src/uu/sed/src/command.rs @@ -1,7 +1,10 @@ // Definitions for the compiled code data structures // -// This file is part of the uutils sed package. +// SPDX-License-Identifier: MIT +// Copyright (c) 2025 Diomidis Spinellis // +// This file is part of the uutils sed package. +// It is licensed under the MIT License. // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -13,6 +16,29 @@ use std::collections::HashMap; use std::fs::File; use std::path::PathBuf; // For file descriptors and equivalent +// Compilation and processing context +#[derive(Debug)] +pub struct Context { + // Input file/string and position + pub input: String, + pub line: usize, + + // Command-line flags with corresponding names + pub all_output_files: bool, + pub debug: bool, + pub regexp_extended: bool, + pub follow_symlinks: bool, + pub in_place: bool, + pub in_place_suffix: Option, + pub length: usize, + pub quiet: bool, + pub posix: bool, + pub separate: bool, + pub sandbox: bool, + pub unbuffered: bool, + pub null_data: bool, +} + // The specification of a script: through a string or a file #[derive(Debug, PartialEq)] pub enum ScriptValue { diff --git a/src/uu/sed/src/sed.rs b/src/uu/sed/src/sed.rs index 23e76371..d6f81d32 100644 --- a/src/uu/sed/src/sed.rs +++ b/src/uu/sed/src/sed.rs @@ -1,5 +1,10 @@ -// This file is part of the uutils sed package. +// Program entry point and CLI processing +// +// SPDX-License-Identifier: MIT +// Copyright (c) 2025 Diomidis Spinellis // +// This file is part of the uutils sed package. +// It is licensed under the MIT License. // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. @@ -7,7 +12,7 @@ pub mod command; pub mod compiler; pub mod processor; -use crate::command::ScriptValue; +use crate::command::{Context, ScriptValue}; use crate::compiler::compile; use crate::processor::process; use clap::{arg, Arg, ArgMatches, Command}; @@ -96,6 +101,8 @@ fn get_scripts_files(matches: &ArgMatches) -> UResult<(Vec, Vec UResult<()> { let matches = uu_app().try_get_matches_from(args)?; let (scripts, files) = get_scripts_files(&matches)?; + let _context = build_context(&matches); + let executable = compile(scripts)?; process(executable, files)?; Ok(()) @@ -123,7 +130,8 @@ pub fn uu_app() -> Command { .short('E') .long("regexp-extended") .short_alias('r') - .help("Use extended regular expressions."), + .help("Use extended regular expressions.") + .action(clap::ArgAction::SetTrue), arg!(-e --expression