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
*)}
37 fun inPath (CONFIG
{inPath
, ...}) = inPath
38 fun outPath (CONFIG
{outPath
, ...}) = outPath
39 fun pubPath (CONFIG
{pubPath
, ...}) = pubPath
40 fun lib (CONFIG
{lib
, ...}) = lib
41 fun sml (CONFIG
{sml
, ...}) = sml
42 fun compiler (CONFIG
{compiler
, ...}) = compiler
43 fun cm (CONFIG
{cm
, ...}) = cm
44 fun printFn (CONFIG
{printFn
, ...}) s
= StringMap
.find (printFn
, s
)
47 if size path
>= 1 andalso String.sub (path
, 0) <> #
"/" then
48 OS
.FileSys
.getDir () ^
"/" ^ path
52 fun read
fname (config
as CONFIG fields
) =
54 val inf
= TextIO.openIn fname
56 fun read (fields
as {inPath
, outPath
, pubPath
, lib
, compiler
, cm
, sml
, printFn
}) =
57 (case TextIO.inputLine inf
of
60 (case String.tokens
Char.isSpace line
of
62 |
["in", inPath
] => read
{inPath
= expandPath inPath
, outPath
= outPath
, pubPath
= pubPath
,
63 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
65 |
["out", outPath
] => read
{inPath
= inPath
, outPath
= expandPath outPath
, pubPath
= pubPath
,
66 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
68 |
["pub", pubPath
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= expandPath pubPath
,
69 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
71 |
["lib", lib
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
72 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
74 |
["compiler", compiler
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
75 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
77 |
["sml", sml
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
78 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
82 fun split ([], _
) = (print
"Bad printFn directive\n";
84 |
split ("="::after
, befor
) =
88 |
toS (h
::t
) = foldl (fn (s
, acc
) => acc ^
" " ^ s
) h t
89 val printFn
= StringMap
.insert (printFn
, toS befor
, toS after
)
91 read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
92 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
95 |
split (h
::after
, befor
) = split (after
, h
::befor
)
99 |
["cm", fname
] => read
{inPath
= inPath
, outPath
= outPath
, pubPath
= pubPath
,
100 lib
= lib
, compiler
= compiler
, printFn
= printFn
,
101 cm
= fname
::cm
, sml
= sml
}
102 | _
=> (print
"Unknown config directive\n";
106 before TextIO.closeIn inf
107 end handle Io
=> config
111 val cwd
= OS
.FileSys
.getDir ()
113 val base
= CONFIG
{lib
= "/usr/local/share/mlt/src/lib/sources.cm",
114 compiler
= "/usr/local/share/mlt/src/sources.cm",
115 sml
= "/usr/local/sml/bin",
119 printFn
= StringMap
.empty
,
122 read defaultFile base