commit 628a425f3697d6def8e9d0c963f12ca3986d199a
parent 32724d609c139695156e60d529d8a6ab58d86627
Author: phoebos <ben@bvnf.space>
Date: Mon, 17 Jul 2023 12:47:27 +0100
contrib: add a tsort(1)
Diffstat:
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/contrib/tsort b/contrib/tsort
@@ -0,0 +1,26 @@
+#!/usr/bin/env lua
+-- This is a tsort(1) interface to the library.
+local tsort = require "bliss.tsort"
+local utils = require "bliss.utils"
+
+local t = tsort.new()
+local deps = {}
+
+for line in io.stdin:lines() do
+ local l = utils.split(line, " ")
+ deps[l[1]] = deps[l[1]] or {}
+ table.insert(deps[l[1]], l[2])
+end
+
+for k,v in pairs(deps) do
+ t:add(k, v)
+end
+
+local s, x,y = t:sort()
+if not s then
+ utils.die("Circular dependency detected: " .. x .. " <> " .. y)
+end
+
+for _, v in ipairs(s) do
+ print(v)
+end