1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #8095 from sylvestre/l10n-tsort

l10n: port tsort to translation + add french
This commit is contained in:
Daniel Hofstetter 2025-06-09 14:06:07 +02:00 committed by GitHub
commit ab0841ec01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View file

@ -3,3 +3,6 @@ tsort-about = Topological sort the strings in FILE.
Useful for scheduling and determining execution order.
If FILE is not passed in, stdin is used instead.
tsort-usage = tsort [OPTIONS] FILE
tsort-error-is-dir = read error: Is a directory
tsort-error-odd = input contains an odd number of tokens
tsort-error-loop = input contains a loop:

View file

@ -0,0 +1,8 @@
tsort-about = Tri topologique des chaînes présentes dans FILE.
Les chaînes sont définies comme toute séquence de jetons séparés par des espaces (tabulation, espace ou saut de ligne), ordonnées selon les dépendances dans un graphe orienté acyclique (DAG).
Utile pour la planification et la détermination de l'ordre d'exécution.
Si FILE n'est pas fourni, l'entrée standard (stdin) est utilisée.
tsort-usage = tsort [OPTIONS] FILE
tsort-error-is-dir = erreur de lecture : c'est un répertoire
tsort-error-odd = l'entrée contient un nombre impair de jetons
tsort-error-loop = l'entrée contient une boucle :

View file

@ -20,18 +20,18 @@ mod options {
#[derive(Debug, Error)]
enum TsortError {
/// The input file is actually a directory.
#[error("{0}: read error: Is a directory")]
#[error("{input}: {message}", input = .0, message = get_message("tsort-error-is-dir"))]
IsDir(String),
/// The number of tokens in the input data is odd.
///
/// The list of edges must be even because each edge has two
/// components: a source node and a target node.
#[error("{input}: input contains an odd number of tokens", input = .0.maybe_quote())]
#[error("{input}: {message}", input = .0.maybe_quote(), message = get_message("tsort-error-odd"))]
NumTokensOdd(String),
/// The graph contains a cycle.
#[error("{0}: input contains a loop:")]
#[error("{input}: {message}", input = .0, message = get_message("tsort-error-loop"))]
Loop(String),
/// A particular node in a cycle. (This is mainly used for printing.)
@ -72,6 +72,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
g.run_tsort();
Ok(())
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(uucore::crate_version!())
@ -147,7 +148,7 @@ impl<'input> Graph<'input> {
/// Implementation of algorithm T from TAOCP (Don. Knuth), vol. 1.
fn run_tsort(&mut self) {
// First, we find a node that have no prerequisites (independent nodes)
// First, we find nodes that have no prerequisites (independent nodes).
// If no such node exists, then there is a cycle.
let mut independent_nodes_queue: VecDeque<&'input str> = self
.nodes
@ -177,7 +178,7 @@ impl<'input> Graph<'input> {
let successor_node = self.nodes.get_mut(successor_name).unwrap();
successor_node.predecessor_count -= 1;
if successor_node.predecessor_count == 0 {
// if we find nodes without any other prerequisites, we add them to the queue.
// If we find nodes without any other prerequisites, we add them to the queue.
independent_nodes_queue.push_back(successor_name);
}
}