2 * Dynamic web page generation
with Standard ML
3 * Copyright (C
) 2003 Adam Chlipala
5 * This library is free software
; you can redistribute it
and/or
6 * modify it under the terms
of the GNU Lesser General Public
7 * License
as published by the Free Software Foundation
; either
8 * version
2.1 of the License
, or (at your option
) any later version
.
10 * This library is distributed
in the hope that it will be useful
,
11 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the GNU
13 * Lesser General Public License for more details
.
15 * You should have received a copy
of the GNU Lesser General Public
16 * License along
with this library
; if not
, write to the Free Software
17 * Foundation
, Inc
., 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
20 (* User
-specifed runtime configuration
*)
22 structure Config
:> CONFIG
=
24 val defaultFile
= "/etc/mlt.conf"
27 CONFIG
of {inPath
: string, (* Directory for input sources
*)
28 outPath
: string, (* Working directory
*)
29 pubPath
: string, (* Directory
in which to put actual CGI scripts
*)
30 lib
: string, (* Path to runtime library
.cm file
*)
31 compiler
: string, (* Path to compiler library
.cm file
*)
32 sml
: string, (* Path to sml program
*)
33 printFn
: string StringMap
.map
, (* Map from SML
type names to text for functions to print
35 cm
: string list
, (* List of extra SML
/CM files to use
with this project
*)
36 beforeT
: string option
, (* Template to run
before every template execution
*)
37 afterT
: string option
, (* Template to run after every successful template execution
*)
38 exnT
: string option (* Template to run after every template execution
39 * ending
in an uncaught
exception *)}
41 fun inPath (CONFIG
{inPath
, ...}) = inPath
42 fun outPath (CONFIG
{outPath
, ...}) = outPath
43 fun pubPath (CONFIG
{pubPath
, ...}) = pubPath
44 fun lib (CONFIG
{lib
, ...}) = lib
45 fun sml (CONFIG
{sml
, ...}) = sml
46 fun compiler (CONFIG
{compiler
, ...}) = compiler
47 fun beforeT (CONFIG
{beforeT
, ...}) = beforeT
48 fun afterT (CONFIG
{afterT
, ...}) = afterT
49 fun exnT (CONFIG
{exnT
, ...}) = exnT
50 fun cm (CONFIG
{cm
, ...}) = cm
51 fun printFn (CONFIG
{printFn
, ...}) s
= StringMap
.find (printFn
, s
)
54 if size path
>= 1 andalso String.sub (path
, 0) <> #
"/" then
55 OS
.FileSys
.getDir () ^
"/" ^ path
59 fun read
fname (config
as CONFIG fields
) =
61 val inf
= TextIO.openIn fname
63 fun read (fields
as {inPath
, outPath
, pubPath
, lib
, compiler
, cm
, sml
, printFn
, beforeT
, afterT
, exnT
}) =
64 (case TextIO.inputLine inf
of
67 (case String.tokens
Char.isSpace line
of
69 |
["in", inPath
] => read
{inPath
= expandPath inPath
, outPath
= outPath
, pubPath
= pubPath
,
70 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
72 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
73 |
["out", outPath
] => read
{inPath
= inPath
, outPath
= expandPath outPath
, pubPath
= pubPath
,
74 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
76 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
77 |
["pub", pubPath
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= expandPath pubPath
,
78 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
80 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
81 |
["lib", lib
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
82 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
84 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
85 |
["compiler", compiler
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
86 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
88 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
89 |
["sml", sml
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
90 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
92 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
93 |
["before", beforeT
] => read
{inPath
= inPath
, outPath
= expandPath outPath
, pubPath
= pubPath
,
94 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
96 beforeT
= SOME beforeT
, afterT
= afterT
, exnT
= exnT
}
97 |
["after", afterT
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= expandPath pubPath
,
98 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
100 beforeT
= beforeT
, afterT
= SOME afterT
, exnT
= exnT
}
101 |
["exn", exnT
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
102 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
104 beforeT
= beforeT
, afterT
= afterT
, exnT
= SOME exnT
}
107 fun split ([], _
) = (print
"Bad printFn directive\n";
109 |
split ("="::after
, befor
) =
111 val befor
= rev befor
113 |
toS (h
::t
) = foldl (fn (s
, acc
) => acc ^
" " ^ s
) h t
114 val printFn
= StringMap
.insert (printFn
, toS befor
, toS after
)
116 read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
117 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
119 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
121 |
split (h
::after
, befor
) = split (after
, h
::befor
)
125 |
["cm", fname
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
126 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
127 cm
= fname
::cm
, sml
= sml
,
128 beforeT
= beforeT
, afterT
= afterT
, exnT
= exnT
}
129 | _
=> (print
"Unknown config directive\n";
133 before TextIO.closeIn inf
134 end handle Io
=> config
138 val cwd
= OS
.FileSys
.getDir ()
140 val base
= CONFIG
{lib
= "/usr/local/share/mlt/src/lib/sources.cm",
141 compiler
= "/usr/local/share/mlt/src/sources.cm",
142 sml
= "/usr/local/sml/bin",
146 printFn
= StringMap
.empty
,
152 read defaultFile base