X-Git-Url: http://git.hcoop.net/bpt/mlt.git/blobdiff_plain/c0a3b4882df1afe4a0155654c1102bd0f9729993..b7ef52bfe976f5ca21732c0e56219f9ce4a67e40:/src/config.sml diff --git a/src/config.sml b/src/config.sml index d021359..ad3946f 100644 --- a/src/config.sml +++ b/src/config.sml @@ -1,6 +1,6 @@ (* * Dynamic web page generation with Standard ML - * Copyright (C) 2003 Adam Chlipala + * Copyright (C) 2003-2004 Adam Chlipala * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,7 +21,7 @@ structure Config :> CONFIG = struct - val defaultFile = "/etc/mlt.conf" + open Settings datatype config = CONFIG of {inPath : string, (* Directory for input sources *) @@ -32,7 +32,11 @@ struct sml : string, (* Path to sml program *) printFn : string StringMap.map, (* Map from SML type names to text for functions to print * their values *) - cm : string list (* List of extra SML/CM files to use with this project *)} + cm : string list, (* List of extra SML/CM files to use with this project *) + beforeT : string option, (* Template to run before every template execution *) + afterT : string option, (* Template to run after every successful template execution *) + exnT : string option (* Template to run after every template execution + * ending in an uncaught exception *)} fun inPath (CONFIG {inPath, ...}) = inPath fun outPath (CONFIG {outPath, ...}) = outPath @@ -40,6 +44,9 @@ struct fun lib (CONFIG {lib, ...}) = lib fun sml (CONFIG {sml, ...}) = sml fun compiler (CONFIG {compiler, ...}) = compiler + fun beforeT (CONFIG {beforeT, ...}) = beforeT + fun afterT (CONFIG {afterT, ...}) = afterT + fun exnT (CONFIG {exnT, ...}) = exnT fun cm (CONFIG {cm, ...}) = cm fun printFn (CONFIG {printFn, ...}) s = StringMap.find (printFn, s) @@ -53,30 +60,48 @@ struct let val inf = TextIO.openIn fname - fun read (fields as {inPath, outPath, pubPath, lib, compiler, cm, sml, printFn}) = + fun read (fields as {inPath, outPath, pubPath, lib, compiler, cm, sml, printFn, beforeT, afterT, exnT}) = (case TextIO.inputLine inf of - "" => CONFIG fields - | line => + NONE => CONFIG fields + | SOME line => (case String.tokens Char.isSpace line of [] => read fields | ["in", inPath] => read {inPath = expandPath inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | ["out", outPath] => read {inPath = inPath, outPath = expandPath outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | ["pub", pubPath] => read {inPath = inPath, outPath = outPath, pubPath = expandPath pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | ["lib", lib] => read {inPath = inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | ["compiler", compiler] => read {inPath = inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | ["sml", sml] => read {inPath = inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} + | ["before", beforeT] => read {inPath = inPath, outPath = expandPath outPath, pubPath = pubPath, + lib = lib, compiler = compiler, printFn = printFn, + cm = cm, sml = sml, + beforeT = SOME beforeT, afterT = afterT, exnT = exnT} + | ["after", afterT] => read {inPath = inPath, outPath = outPath, pubPath = expandPath pubPath, + lib = lib, compiler = compiler, printFn = printFn, + cm = cm, sml = sml, + beforeT = beforeT, afterT = SOME afterT, exnT = exnT} + | ["exn", exnT] => read {inPath = inPath, outPath = outPath, pubPath = pubPath, + lib = lib, compiler = compiler, printFn = printFn, + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = SOME exnT} | "print"::rest => let fun split ([], _) = (print "Bad printFn directive\n"; @@ -90,7 +115,8 @@ struct in read {inPath = inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = cm, sml = sml} + cm = cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} end | split (h::after, befor) = split (after, h::befor) in @@ -98,7 +124,8 @@ struct end | ["cm", fname] => read {inPath = inPath, outPath = outPath, pubPath = pubPath, lib = lib, compiler = compiler, printFn = printFn, - cm = fname::cm, sml = sml} + cm = fname::cm, sml = sml, + beforeT = beforeT, afterT = afterT, exnT = exnT} | _ => (print "Unknown config directive\n"; read fields))) in @@ -110,14 +137,17 @@ struct let val cwd = OS.FileSys.getDir () - val base = CONFIG {lib = "/usr/local/share/mlt/src/lib/sources.cm", - compiler = "/usr/local/share/mlt/src/sources.cm", - sml = "/usr/local/sml/bin", - inPath = cwd, - outPath = cwd, - pubPath = cwd, - printFn = StringMap.empty, - cm = []} + val base = CONFIG {lib = mltdir ^ "/src/lib/sources.cm", + compiler = mltdir ^ "/src/sources.cm", + sml = smlbin, + inPath = cwd, + outPath = cwd, + pubPath = cwd, + printFn = StringMap.empty, + cm = [], + beforeT = NONE, + afterT = NONE, + exnT = NONE} in read defaultFile base end