summaryrefslogtreecommitdiff
path: root/regress/usr.bin/tsort/normalize-cycles
diff options
context:
space:
mode:
Diffstat (limited to 'regress/usr.bin/tsort/normalize-cycles')
-rw-r--r--regress/usr.bin/tsort/normalize-cycles37
1 files changed, 37 insertions, 0 deletions
diff --git a/regress/usr.bin/tsort/normalize-cycles b/regress/usr.bin/tsort/normalize-cycles
new file mode 100644
index 00000000000..1188ba785ac
--- /dev/null
+++ b/regress/usr.bin/tsort/normalize-cycles
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+# Written by Marc Espie, 2001.
+# Public domain
+
+@cycle = ();
+
+sub show_cycle()
+{
+ return if @cycle == 0;
+ $min = 'zzzzz';
+ for ($i = 0; $i < @cycle; $i++) {
+ if ($cycle[$i] lt $min) {
+ $minindex = $i;
+ $min = $cycle[$i];
+ }
+ }
+ @ordered=();
+ for ($i = $minindex; $i <@cycle; $i++) {
+ push(@ordered, $cycle[$i]);
+ }
+ for ($i = 0; $i < $minindex; $i++) {
+ push(@ordered, $cycle[$i]);
+ }
+ print join(',', @ordered), "\n";
+}
+
+while (<>) {
+ chomp;
+ if ($_ eq 'tsort: cycle in data') {
+ show_cycle();
+ @cycle = ();
+ } else {
+ m/^tsort:\s+/ and push(@cycle, $');
+ }
+}
+show_cycle();