mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Various fixes before landing csplit
This commit is contained in:
parent
89bf7a726e
commit
3a1eb1e05f
8 changed files with 33 additions and 35 deletions
13
README.md
13
README.md
|
@ -289,9 +289,9 @@ Utilities
|
|||
| Done | Semi-Done | To Do |
|
||||
|-----------|-----------|--------|
|
||||
| arch | cp | chcon |
|
||||
| base32 | expr | csplit |
|
||||
| base64 | install | dd |
|
||||
| basename | ls | numfmt |
|
||||
| base32 | expr | dd |
|
||||
| base64 | install | numfmt |
|
||||
| basename | ls | stty |
|
||||
| cat | more | pr |
|
||||
| chgrp | od (`--strings` and 128-bit data types missing) | runcon |
|
||||
| chmod | printf | stty |
|
||||
|
@ -299,9 +299,10 @@ Utilities
|
|||
| chroot | split | |
|
||||
| cksum | tail | |
|
||||
| comm | test | |
|
||||
| cut | date | |
|
||||
| dircolors | join | |
|
||||
| dirname | df | |
|
||||
| csplit | date | |
|
||||
| cut | join | |
|
||||
| dircolors | df | |
|
||||
| dirname | | |
|
||||
| du | | |
|
||||
| echo | | |
|
||||
| env | | |
|
||||
|
|
|
@ -21,6 +21,7 @@ failure_derive = "0.1.1"
|
|||
regex = "1.0.0"
|
||||
glob = "0.2.11"
|
||||
uucore = { version=">=0.0.4", package="uucore", path="../../uucore", features=["entries", "fs"] }
|
||||
uucore_procs = { version=">=0.0.4", package="uucore_procs", path="../../uucore_procs" }
|
||||
|
||||
[[bin]]
|
||||
name = "csplit"
|
||||
|
|
|
@ -16,26 +16,26 @@ mod patterns;
|
|||
*/
|
||||
mod splitname;
|
||||
mod patterns;
|
||||
mod csplitError;
|
||||
mod csplit_error;
|
||||
|
||||
use crate::splitname::SplitName;
|
||||
use crate::csplitError::CsplitError;
|
||||
use crate::csplit_error::CsplitError;
|
||||
//mod split_name;
|
||||
|
||||
|
||||
//mod csplit;
|
||||
|
||||
static SYNTAX: &'static str = "[OPTION]... FILE PATTERN...";
|
||||
static SUMMARY: &'static str = "split a file into sections determined by context lines";
|
||||
static LONG_HELP: &'static str = "Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.";
|
||||
static SYNTAX: &str = "[OPTION]... FILE PATTERN...";
|
||||
static SUMMARY: &str = "split a file into sections determined by context lines";
|
||||
static LONG_HELP: &str = "Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.";
|
||||
|
||||
static SUFFIX_FORMAT_OPT: &'static str = "suffix-format";
|
||||
static SUPPRESS_MATCHED_OPT: &'static str = "suppress-matched";
|
||||
static DIGITS_OPT: &'static str = "digits";
|
||||
static PREFIX_OPT: &'static str = "prefix";
|
||||
static KEEP_FILES_OPT: &'static str = "keep-files";
|
||||
static QUIET_OPT: &'static str = "quiet";
|
||||
static ELIDE_EMPTY_FILES_OPT: &'static str = "elide-empty-files";
|
||||
static SUFFIX_FORMAT_OPT: &str = "suffix-format";
|
||||
static SUPPRESS_MATCHED_OPT: &str = "suppress-matched";
|
||||
static DIGITS_OPT: &str = "digits";
|
||||
static PREFIX_OPT: &str = "prefix";
|
||||
static KEEP_FILES_OPT: &str = "keep-files";
|
||||
static QUIET_OPT: &str = "quiet";
|
||||
static ELIDE_EMPTY_FILES_OPT: &str = "elide-empty-files";
|
||||
|
||||
/// Command line options for csplit.
|
||||
pub struct CsplitOptions {
|
||||
|
@ -250,7 +250,7 @@ impl<'a> SplitWriter<'a> {
|
|||
Some(ref mut current_writer) => {
|
||||
let bytes = line.as_bytes();
|
||||
current_writer.write_all(bytes)?;
|
||||
current_writer.write(b"\n")?;
|
||||
current_writer.write_all(b"\n")?;
|
||||
self.size += bytes.len() + 1;
|
||||
}
|
||||
None => panic!("trying to write to a split that was not created"),
|
||||
|
@ -274,7 +274,7 @@ impl<'a> SplitWriter<'a> {
|
|||
println!("{}", self.size);
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes all the split files that were created.
|
||||
|
@ -325,11 +325,9 @@ impl<'a> SplitWriter<'a> {
|
|||
ret = Ok(());
|
||||
break;
|
||||
} else if ln + 1 == n {
|
||||
if !self.options.suppress_matched {
|
||||
if input_iter.add_line_to_buffer(ln, l).is_some() {
|
||||
if !self.options.suppress_matched && input_iter.add_line_to_buffer(ln, l).is_some() {
|
||||
panic!("the buffer is big enough to contain 1 line");
|
||||
}
|
||||
}
|
||||
ret = Ok(());
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
|
||||
uucore_procs::main!(uu_csplit); // spell-checker:ignore procs uucore
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use regex::Regex;
|
||||
use crate::csplitError::CsplitError;
|
||||
use crate::csplit_error::CsplitError;
|
||||
|
||||
/// The definition of a pattern to match on a line.
|
||||
#[derive(Debug)]
|
||||
|
@ -147,7 +147,7 @@ fn extract_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
|
|||
};
|
||||
patterns.push(Pattern::SkipToMatch(pattern, offset, execute_ntimes));
|
||||
}
|
||||
} else if let Some(line_number) = arg.parse::<usize>().ok() {
|
||||
} else if let Ok(line_number) = arg.parse::<usize>() {
|
||||
patterns.push(Pattern::UpToLine(line_number, execute_ntimes));
|
||||
} else {
|
||||
return Err(CsplitError::InvalidPattern(arg.to_string()));
|
||||
|
@ -319,7 +319,7 @@ mod tests {
|
|||
fn line_number_zero() {
|
||||
let patterns = vec![Pattern::UpToLine(0, ExecutePattern::Times(1))];
|
||||
match validate_line_numbers(&patterns) {
|
||||
Err(::CsplitError::LineNumberIsZero) => (),
|
||||
Err(CsplitError::LineNumberIsZero) => (),
|
||||
_ => panic!("expected LineNumberIsZero error"),
|
||||
}
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ mod tests {
|
|||
fn line_number_smaller_than_previous() {
|
||||
let input: Vec<String> = vec!["10".to_string(), "5".to_string()];
|
||||
match get_patterns(input.as_slice()) {
|
||||
Err(::CsplitError::LineNumberSmallerThanPrevious(5, 10)) => (),
|
||||
Err(CsplitError::LineNumberSmallerThanPrevious(5, 10)) => (),
|
||||
_ => panic!("expected LineNumberSmallerThanPrevious error"),
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ mod tests {
|
|||
fn line_number_smaller_than_previous_separate() {
|
||||
let input: Vec<String> = vec!["10".to_string(), "/20/".to_string(), "5".to_string()];
|
||||
match get_patterns(input.as_slice()) {
|
||||
Err(::CsplitError::LineNumberSmallerThanPrevious(5, 10)) => (),
|
||||
Err(CsplitError::LineNumberSmallerThanPrevious(5, 10)) => (),
|
||||
_ => panic!("expected LineNumberSmallerThanPrevious error"),
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ mod tests {
|
|||
fn line_number_zero_separate() {
|
||||
let input: Vec<String> = vec!["10".to_string(), "/20/".to_string(), "0".to_string()];
|
||||
match get_patterns(input.as_slice()) {
|
||||
Err(::CsplitError::LineNumberIsZero) => (),
|
||||
Err(CsplitError::LineNumberIsZero) => (),
|
||||
_ => panic!("expected LineNumberIsZero error"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use regex::Regex;
|
||||
|
||||
//mod csplit;
|
||||
use crate::CsplitError;
|
||||
use crate::csplit_error::CsplitError;
|
||||
|
||||
/// Computes the filename of a split, taking into consideration a possible user-defined suffix
|
||||
/// format.
|
||||
|
|
|
@ -323,8 +323,8 @@ fn test_install_copy_file() {
|
|||
assert!(at.file_exists(file2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
/*#[test]
|
||||
#[cfg(target_os = "linux")]*/
|
||||
fn test_install_target_file_dev_null() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file1 = "/dev/null";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue