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
26 changes: 26 additions & 0 deletions src/uu/csplit/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
csplit-about = Split a file into sections determined by context lines
csplit-usage = csplit [OPTION]... FILE PATTERN...
csplit-after-help = Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ..., and output byte counts of each piece to standard output.

# Help messages
csplit-help-suffix-format = use sprintf FORMAT instead of %02d
csplit-help-prefix = use PREFIX instead of 'xx'
csplit-help-keep-files = do not remove output files on errors
csplit-help-suppress-matched = suppress the lines matching PATTERN
csplit-help-digits = use specified number of digits instead of 2
csplit-help-quiet = do not print counts of output file sizes
csplit-help-elide-empty-files = remove empty output files

# Error messages
csplit-error-line-out-of-range = { $pattern }: line number out of range
csplit-error-line-out-of-range-on-repetition = { $pattern }: line number out of range on repetition { $repetition }
csplit-error-match-not-found = { $pattern }: match not found
csplit-error-match-not-found-on-repetition = { $pattern }: match not found on repetition { $repetition }
csplit-error-line-number-is-zero = 0: line number must be greater than zero
csplit-error-line-number-smaller-than-previous = line number '{ $current }' is smaller than preceding line number, { $previous }
csplit-error-invalid-pattern = { $pattern }: invalid pattern
csplit-error-invalid-number = invalid number: { $number }
csplit-error-suffix-format-incorrect = incorrect conversion specification in suffix
csplit-error-suffix-format-too-many-percents = too many % conversion specifications in suffix
csplit-error-not-regular-file = { $file } is not a regular file
csplit-warning-line-number-same-as-previous = line number '{ $line_number }' is the same as preceding line number
csplit-stream-not-utf8 = stream did not contain valid UTF-8
csplit-read-error = read error
csplit-write-split-not-created = trying to write to a split that was not created
29 changes: 29 additions & 0 deletions src/uu/csplit/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
csplit-about = Diviser un fichier en sections déterminées par des lignes de contexte
csplit-usage = csplit [OPTION]... FICHIER MOTIF...
csplit-after-help = Sortir les morceaux de FICHIER séparés par MOTIF(S) dans les fichiers 'xx00', 'xx01', ..., et sortir le nombre d'octets de chaque morceau sur la sortie standard.

# Messages d'aide
csplit-help-suffix-format = utiliser le FORMAT sprintf au lieu de %02d
csplit-help-prefix = utiliser PRÉFIXE au lieu de 'xx'
csplit-help-keep-files = ne pas supprimer les fichiers de sortie en cas d'erreurs
csplit-help-suppress-matched = supprimer les lignes correspondant au MOTIF
csplit-help-digits = utiliser le nombre spécifié de chiffres au lieu de 2
csplit-help-quiet = ne pas afficher le nombre d'octets des fichiers de sortie
csplit-help-elide-empty-files = supprimer les fichiers de sortie vides

# Messages d'erreur
csplit-error-line-out-of-range = { $pattern } : numéro de ligne hors limites
csplit-error-line-out-of-range-on-repetition = { $pattern } : numéro de ligne hors limites à la répétition { $repetition }
csplit-error-match-not-found = { $pattern } : correspondance non trouvée
csplit-error-match-not-found-on-repetition = { $pattern } : correspondance non trouvée à la répétition { $repetition }
csplit-error-line-number-is-zero = 0 : le numéro de ligne doit être supérieur à zéro
csplit-error-line-number-smaller-than-previous = le numéro de ligne '{ $current }' est plus petit que le numéro de ligne précédent, { $previous }
csplit-error-invalid-pattern = { $pattern } : motif invalide
csplit-error-invalid-number = nombre invalide : { $number }
csplit-error-suffix-format-incorrect = spécification de conversion incorrecte dans le suffixe
csplit-error-suffix-format-too-many-percents = trop de spécifications de conversion % dans le suffixe
csplit-error-not-regular-file = { $file } n'est pas un fichier régulier
csplit-warning-line-number-same-as-previous = le numéro de ligne '{ $line_number }' est identique au numéro de ligne précédent
csplit-stream-not-utf8 = le flux ne contenait pas d'UTF-8 valide
csplit-read-error = erreur de lecture
csplit-write-split-not-created = tentative d'écriture dans une division qui n'a pas été créée
23 changes: 13 additions & 10 deletions src/uu/csplit/src/csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@
fn next(&mut self) -> Option<Self::Item> {
fn ret(v: Vec<u8>) -> io::Result<String> {
String::from_utf8(v).map_err(|_| {
io::Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
io::Error::new(
ErrorKind::InvalidData,
get_message("csplit-stream-not-utf8"),

Check warning on line 90 in src/uu/csplit/src/csplit.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/csplit/src/csplit.rs#L88-L90

Added lines #L88 - L90 were not covered by tests
)
})
}

Expand Down Expand Up @@ -115,7 +118,7 @@
T: BufRead,
{
let enumerated_input_lines = LinesWithNewlines::new(input)
.map(|line| line.map_err_context(|| "read error".to_string()))
.map(|line| line.map_err_context(|| get_message("csplit-read-error")))
.enumerate();
let mut input_iter = InputSplitter::new(enumerated_input_lines);
let mut split_writer = SplitWriter::new(options);
Expand Down Expand Up @@ -283,7 +286,7 @@
current_writer.write_all(bytes)?;
self.size += bytes.len();
}
None => panic!("trying to write to a split that was not created"),
None => panic!("{}", get_message("csplit-write-split-not-created")),

Check warning on line 289 in src/uu/csplit/src/csplit.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/csplit/src/csplit.rs#L289

Added line #L289 was not covered by tests
}
}
Ok(())
Expand Down Expand Up @@ -638,49 +641,49 @@
.short('b')
.long(options::SUFFIX_FORMAT)
.value_name("FORMAT")
.help("use sprintf FORMAT instead of %02d"),
.help(get_message("csplit-help-suffix-format")),
)
.arg(
Arg::new(options::PREFIX)
.short('f')
.long(options::PREFIX)
.value_name("PREFIX")
.help("use PREFIX instead of 'xx'"),
.help(get_message("csplit-help-prefix")),
)
.arg(
Arg::new(options::KEEP_FILES)
.short('k')
.long(options::KEEP_FILES)
.help("do not remove output files on errors")
.help(get_message("csplit-help-keep-files"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::SUPPRESS_MATCHED)
.long(options::SUPPRESS_MATCHED)
.help("suppress the lines matching PATTERN")
.help(get_message("csplit-help-suppress-matched"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::DIGITS)
.short('n')
.long(options::DIGITS)
.value_name("DIGITS")
.help("use specified number of digits instead of 2"),
.help(get_message("csplit-help-digits")),
)
.arg(
Arg::new(options::QUIET)
.short('q')
.long(options::QUIET)
.visible_short_alias('s')
.visible_alias("silent")
.help("do not print counts of output file sizes")
.help(get_message("csplit-help-quiet"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::ELIDE_EMPTY_FILES)
.short('z')
.long(options::ELIDE_EMPTY_FILES)
.help("remove empty output files")
.help(get_message("csplit-help-elide-empty-files"))
.action(ArgAction::SetTrue),
)
.arg(
Expand Down
26 changes: 14 additions & 12 deletions src/uu/csplit/src/csplit_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use std::collections::HashMap;
use std::io;
use thiserror::Error;

use uucore::display::Quotable;
use uucore::error::UError;
use uucore::locale::{get_message, get_message_with_args};

/// Errors thrown by the csplit command
#[derive(Debug, Error)]
pub enum CsplitError {
#[error("IO error: {}", _0)]
IoError(#[from] io::Error),
#[error("{}: line number out of range", ._0.quote())]
#[error("{}", get_message_with_args("csplit-error-line-out-of-range", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
LineOutOfRange(String),
#[error("{}: line number out of range on repetition {}", ._0.quote(), _1)]
#[error("{}", get_message_with_args("csplit-error-line-out-of-range-on-repetition", HashMap::from([("pattern".to_string(), _0.quote().to_string()), ("repetition".to_string(), _1.to_string())])))]
LineOutOfRangeOnRepetition(String, usize),
#[error("{}: match not found", ._0.quote())]
#[error("{}", get_message_with_args("csplit-error-match-not-found", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
MatchNotFound(String),
#[error("{}: match not found on repetition {}", ._0.quote(), _1)]
#[error("{}", get_message_with_args("csplit-error-match-not-found-on-repetition", HashMap::from([("pattern".to_string(), _0.quote().to_string()), ("repetition".to_string(), _1.to_string())])))]
MatchNotFoundOnRepetition(String, usize),
#[error("0: line number must be greater than zero")]
#[error("{}", get_message("csplit-error-line-number-is-zero"))]
LineNumberIsZero,
#[error("line number '{}' is smaller than preceding line number, {}", _0, _1)]
#[error("{}", get_message_with_args("csplit-error-line-number-smaller-than-previous", HashMap::from([("current".to_string(), _0.to_string()), ("previous".to_string(), _1.to_string())])))]
LineNumberSmallerThanPrevious(usize, usize),
#[error("{}: invalid pattern", ._0.quote())]
#[error("{}", get_message_with_args("csplit-error-invalid-pattern", HashMap::from([("pattern".to_string(), _0.quote().to_string())])))]
InvalidPattern(String),
#[error("invalid number: {}", ._0.quote())]
#[error("{}", get_message_with_args("csplit-error-invalid-number", HashMap::from([("number".to_string(), _0.quote().to_string())])))]
InvalidNumber(String),
#[error("incorrect conversion specification in suffix")]
#[error("{}", get_message("csplit-error-suffix-format-incorrect"))]
SuffixFormatIncorrect,
#[error("too many % conversion specifications in suffix")]
#[error("{}", get_message("csplit-error-suffix-format-too-many-percents"))]
SuffixFormatTooManyPercents,
#[error("{} is not a regular file", ._0.quote())]
#[error("{}", get_message_with_args("csplit-error-not-regular-file", HashMap::from([("file".to_string(), _0.quote().to_string())])))]
NotRegularFile(String),
#[error("{}", _0)]
UError(Box<dyn UError>),
Expand Down
10 changes: 9 additions & 1 deletion src/uu/csplit/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use crate::csplit_error::CsplitError;
use regex::Regex;
use std::collections::HashMap;
use uucore::locale::get_message_with_args;
use uucore::show_warning;

/// The definition of a pattern to match on a line.
Expand Down Expand Up @@ -168,7 +170,13 @@
(_, 0) => Err(CsplitError::LineNumberIsZero),
// two consecutive numbers should not be equal
(n, m) if n == m => {
show_warning!("line number '{n}' is the same as preceding line number");
show_warning!(
"{}",
get_message_with_args(
"csplit-warning-line-number-same-as-previous",
HashMap::from([("line_number".to_string(), n.to_string())])

Check warning on line 177 in src/uu/csplit/src/patterns.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/csplit/src/patterns.rs#L173-L177

Added lines #L173 - L177 were not covered by tests
)
);
Ok(n)
}
// a number cannot be greater than the one that follows
Expand Down
Loading