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
3 changes: 3 additions & 0 deletions src/uu/tsort/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
8 changes: 8 additions & 0 deletions src/uu/tsort/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -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 :
11 changes: 6 additions & 5 deletions src/uu/tsort/src/tsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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!())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading