X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/d5772aa364d60b3a005443b07db58672d64b0432..991d8e6619bc9ff2182a39cfbeead53bee768a99:/src/plugins/apt.sml diff --git a/src/plugins/apt.sml b/src/plugins/apt.sml index d2517e9..e97ec82 100644 --- a/src/plugins/apt.sml +++ b/src/plugins/apt.sml @@ -22,6 +22,31 @@ structure Apt :> APT = struct fun validName s = CharVector.all (fn ch => Char.isAlphaNum ch orelse ch = #"_" orelse ch = #"-" orelse ch = #".") s andalso (size s > 0 andalso String.sub (s, 0) <> #"-") + +(* Copyed from the portal, doesn't exactly go out this in the most + direct way, or does it? *) + +fun exists name = + validName name andalso let + val proc = Unix.execute ("/usr/bin/apt-cache", ["show", name]) + val inf = Unix.textInstreamOf proc + + val _ = TextIO.inputLine inf (* in every let* lies an imperative program in disguise *) + + fun loop _ = + case TextIO.inputLine inf of + NONE => false + | SOME line => + if size line >= 9 andalso String.substring (line, 0, 9) = "Section: " then + true + else if size line >= 13 andalso String.substring (line, 0, 13) = "Description: " then + false + else + loop () + in + loop () + before ignore (Unix.reap proc) + end fun installed name = validName name