18 |
structure SS = Substring |
structure SS = Substring |
19 |
|
|
20 |
(* search path for the dnorm executable *) |
(* search path for the dnorm executable *) |
21 |
val path = [ |
val paths = [ |
22 |
"@DIDEROT_ROOT@/bin/dnorm", "@prefix@/bin/dnorm" |
"@DIDEROT_ROOT@/bin", "@prefix@/bin" |
23 |
] |
] |
24 |
|
|
25 |
fun findExe () = ( |
(* FIXME: with SML/NJ 110.73, we'll be able to use PathUtil.findExe *) |
26 |
case List.find (fn p => OS.FileSys.access(p, [OS.FileSys.A_EXEC])) path |
fun findExe () = let |
27 |
|
fun isExe p = OS.FileSys.access(p, [OS.FileSys.A_EXEC]) |
28 |
|
in |
29 |
|
case PathUtil.existsFile isExe paths "dnorm" |
30 |
of SOME cmd => cmd |
of SOME cmd => cmd |
31 |
| NONE => raise Fail "unable to find dnorm executable" |
| NONE => raise Fail "unable to find dnorm executable" |
32 |
(* end case *)) |
(* end case *) |
33 |
|
end |
34 |
|
|
35 |
fun run srcFile = let |
fun run srcFile = if OS.FileSys.access(srcFile, [OS.FileSys.A_READ]) |
36 |
|
then let |
37 |
val proc = Unix.execute (findExe(), ["-h", "-i", srcFile]) |
val proc = Unix.execute (findExe(), ["-h", "-i", srcFile]) |
38 |
val inS = Unix.textInstreamOf proc |
val inS = Unix.textInstreamOf proc |
39 |
fun stripWS ss = SS.string (SS.dropl Char.isSpace (SS.dropr Char.isSpace ss)) |
fun stripWS ss = SS.string (SS.dropl Char.isSpace (SS.dropr Char.isSpace ss)) |
60 |
then info |
then info |
61 |
else raise Fail "error running dnorm" |
else raise Fail "error running dnorm" |
62 |
end |
end |
63 |
|
else raise Fail(concat["image file \"", srcFile, "\" not found"]) |
64 |
end |
end |