1 (* HCoop
Domtool (http
://hcoop
.sourceforge
.net
/)
2 * Copyright (c
) 2006-2007, Adam Chlipala
4 * This program is free software
; you can redistribute it
and/or
5 * modify it under the terms
of the GNU General Public License
6 * as published by the Free Software Foundation
; either version
2
7 * of the License
, or (at your option
) any later version
.
9 * This program is distributed
in the hope that it will be useful
,
10 * but WITHOUT ANY WARRANTY
; without even the implied warranty
of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
. See the
12 * GNU General Public License for more details
.
14 * You should have received a copy
of the GNU General Public License
15 * along
with this program
; if not
, write to the Free Software
16 * Foundation
, Inc
., 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301, USA
.
19 (* Domain
-related primitive actions
*)
21 structure Domain
:> DOMAIN
= struct
25 structure SM
= DataStructures
.StringMap
26 structure SS
= DataStructures
.StringSet
28 val ssl_context
= ref (NONE
: OpenSSL
.context option
)
29 fun set_context ctx
= ssl_context
:= SOME ctx
31 val nodes
= map #
1 Config
.nodeIps
32 val nodeMap
= foldl (fn ((node
, ip
), mp
) => SM
.insert (mp
, node
, ip
))
33 SM
.empty Config
.nodeIps
34 fun nodeIp node
= valOf (SM
.find (nodeMap
, node
))
39 val your_doms
= ref SS
.empty
40 fun your_domains () = !your_doms
42 val your_usrs
= ref SS
.empty
43 fun your_users () = !your_usrs
45 val your_grps
= ref SS
.empty
46 fun your_groups () = !your_grps
48 val your_pths
= ref SS
.empty
49 fun your_paths () = !your_pths
51 val world_readable
= SS
.addList (SS
.empty
, Config
.worldReadable
)
52 val readable_pths
= ref SS
.empty
53 fun readable_paths () = !readable_pths
59 val your_paths
= Acl
.class
{user
= getUser (),
62 your_doms
:= Acl
.class
{user
= getUser (),
64 your_usrs
:= Acl
.class
{user
= getUser (),
66 your_grps
:= Acl
.class
{user
= getUser (),
68 your_pths
:= your_paths
;
69 readable_pths
:= SS
.union (your_paths
, world_readable
)
73 case map
Int.fromString (String.fields (fn ch
=> ch
= #
".") s
) of
74 [SOME n1
, SOME n2
, SOME n3
, SOME n4
] =>
75 n1
>= 0 andalso n1
< 256 andalso n2
>= 0 andalso n2
< 256 andalso n3
>= 0 andalso n3
< 256 andalso n4
>= 0 andalso n4
< 256
78 fun isIdent ch
= Char.isLower ch
orelse Char.isDigit ch
81 size s
> 0 andalso size s
< 20
82 andalso CharVector
.all (fn ch
=> isIdent ch
orelse ch
= #
"-") s
85 size s
> 0 andalso size s
< 100
86 andalso List.all
validHost (String.fields (fn ch
=> ch
= #
".") s
)
88 fun validNode s
= List.exists (fn s
' => s
= s
') nodes
90 fun yourDomain s
= SS
.member (your_domains (), s
)
91 fun yourUser s
= SS
.member (your_users (), s
)
92 fun yourGroup s
= SS
.member (your_groups (), s
)
93 fun checkPath paths path
=
94 List.all (fn s
=> s
<> "..") (String.fields (fn ch
=> ch
= #
"/") path
)
95 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
orelse ch
= #
"." orelse ch
= #
"/"
96 orelse ch
= #
"-" orelse ch
= #
"_") path
97 andalso SS
.exists (fn s
' => path
= s
' orelse String.isPrefix (s
' ^
"/") path
) (paths ())
98 val yourPath
= checkPath your_paths
99 val readablePath
= checkPath readable_paths
101 fun yourDomainHost s
=
104 val (pref
, suf
) = Substring
.splitl (fn ch
=> ch
<> #
".") (Substring
.full s
)
106 Substring
.size suf
> 0
107 andalso validHost (Substring
.string pref
)
108 andalso yourDomain (Substring
.string
109 (Substring
.slice (suf
, 1, NONE
)))
112 val yourDomain
= yourDomainHost
114 fun validUser s
= size s
> 0 andalso size s
< 20
115 andalso CharVector
.all
Char.isAlphaNum s
117 fun validEmailUser s
=
118 size s
> 0 andalso size s
< 50
119 andalso CharVector
.all (fn ch
=> Char.isAlphaNum ch
125 val validGroup
= validUser
127 val _
= Env
.type_one
"no_spaces"
129 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso not (Char.isSpace ch
)
130 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
131 val _
= Env
.type_one
"no_newlines"
133 (CharVector
.all (fn ch
=> Char.isPrint ch
andalso ch
<> #
"\n" andalso ch
<> #
"\r"
134 andalso ch
<> #
"\"" andalso ch
<> #
"'"))
136 val _
= Env
.type_one
"ip"
140 val _
= Env
.type_one
"host"
144 val _
= Env
.type_one
"domain"
148 val _
= Env
.type_one
"your_domain"
152 val _
= Env
.type_one
"your_domain_host"
156 val _
= Env
.type_one
"user"
160 val _
= Env
.type_one
"group"
164 val _
= Env
.type_one
"your_user"
168 val _
= Env
.type_one
"your_group"
172 val _
= Env
.type_one
"your_path"
176 val _
= Env
.type_one
"readable_path"
180 val _
= Env
.type_one
"node"
184 val _
= Env
.registerFunction ("dns_node_to_node",
188 val _
= Env
.registerFunction ("mail_node_to_node",
193 val dl
= ErrorMsg
.dummyLoc
195 val nsD
= (EString Config
.defaultNs
, dl
)
196 val serialD
= (EVar
"serialAuto", dl
)
197 val refD
= (EInt Config
.defaultRefresh
, dl
)
198 val retD
= (EInt Config
.defaultRetry
, dl
)
199 val expD
= (EInt Config
.defaultExpiry
, dl
)
200 val minD
= (EInt Config
.defaultMinimum
, dl
)
202 val soaD
= multiApp ((EVar
"soa", dl
),
204 [nsD
, serialD
, refD
, retD
, expD
, minD
])
206 val masterD
= (EApp ((EVar
"internalMaster", dl
),
207 (EString Config
.masterNode
, dl
)),
210 val slavesD
= (EList (map (fn s
=> (EString s
, dl
)) Config
.slaveNodes
), dl
)
212 val _
= Defaults
.registerDefault ("Aliases",
213 (TList (TBase
"your_domain", dl
), dl
),
214 (fn () => (EList
[], dl
)))
216 val _
= Defaults
.registerDefault ("Mailbox",
218 (fn () => (EString (getUser ()), dl
)))
220 val _
= Defaults
.registerDefault ("DNS",
221 (TBase
"dnsKind", dl
),
222 (fn () => multiApp ((EVar
"useDns", dl
),
224 [soaD
, masterD
, slavesD
])))
226 val _
= Defaults
.registerDefault ("TTL",
228 (fn () => (EInt Config
.Bind
.defaultTTL
, dl
)))
230 type soa
= {ns
: string,
237 val serial
= fn (EVar
"serialAuto", _
) => SOME NONE
238 |
(EApp ((EVar
"serialConst", _
), n
), _
) => Option
.map
SOME (Env
.int n
)
241 val soa
= fn (EApp ((EApp ((EApp ((EApp ((EApp ((EApp
242 ((EVar
"soa", _
), ns
), _
),
248 (case (Env
.string ns
, serial sl
, Env
.int rf
,
249 Env
.int ret
, Env
.int exp
, Env
.int min
) of
250 (SOME ns
, SOME sl
, SOME rf
,
251 SOME ret
, SOME exp
, SOME min
) =>
262 ExternalMaster
of string
263 | InternalMaster
of string
267 val _
= Env
.registerFunction ("ip_of_node",
268 fn [(EString node
, _
)] => SOME (EString (nodeIp node
), dl
)
271 val master
= fn (EApp ((EVar
"externalMaster", _
), e
), _
) => Option
.map
ExternalMaster (ip e
)
272 |
(EApp ((EVar
"internalMaster", _
), e
), _
) => Option
.map
InternalMaster (Env
.string e
)
276 UseDns
of {soa
: soa
,
278 slaves
: string list
}
281 val dnsKind
= fn (EApp ((EApp ((EApp
282 ((EVar
"useDns", _
), sa
), _
),
285 (case (soa sa
, master mstr
, Env
.list Env
.string slaves
) of
286 (SOME sa
, SOME mstr
, SOME slaves
) =>
287 SOME (UseDns
{soa
= sa
,
291 |
(EVar
"noDns", _
) => SOME NoDns
294 val befores
= ref (fn (_
: string) => ())
295 val afters
= ref (fn (_
: string) => ())
297 fun registerBefore f
=
301 befores
:= (fn x
=> (old x
; f x
))
304 fun registerAfter f
=
308 afters
:= (fn x
=> (old x
; f x
))
311 val globals
= ref (fn () => ())
312 val locals
= ref (fn () => ())
314 fun registerResetGlobal f
=
318 globals
:= (fn x
=> (old x
; f x
))
321 fun registerResetLocal f
=
325 locals
:= (fn x
=> (old x
; f x
))
328 fun resetGlobal () = (!globals ();
329 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ Config
.resultRoot ^
"/*")))
330 fun resetLocal () = !locals ()
333 val currentPath
= ref (fn (_
: string) => "")
334 val currentPathAli
= ref (fn (_
: string, _
: string) => "")
338 fun currentDomain () = !current
340 val currentsAli
= ref ([] : string list
)
342 fun currentAliasDomains () = !currentsAli
343 fun currentDomains () = currentDomain () :: currentAliasDomains ()
345 fun domainFile
{node
, name
} = ((*print ("Opening " ^
!currentPath node ^ name ^
"\n");*)
346 TextIO.openOut (!currentPath node ^ name
))
348 type files
= {write
: string -> unit
,
349 writeDom
: unit
-> unit
,
350 close
: unit
-> unit
}
352 fun domainsFile
{node
, name
} =
354 val doms
= currentDomains ()
355 val files
= map (fn dom
=> (dom
, TextIO.openOut (!currentPathAli (dom
, node
) ^ name
))) doms
357 {write
= fn s
=> app (fn (_
, outf
) => TextIO.output (outf
, s
)) files
,
358 writeDom
= fn () => app (fn (dom
, outf
) => TextIO.output (outf
, dom
)) files
,
359 close
= fn () => app (fn (_
, outf
) => TextIO.closeOut outf
) files
}
364 val toks
= String.fields (fn ch
=> ch
= #
".") domain
366 val elems
= foldr (fn (piece
, elems
) =>
368 val elems
= piece
:: elems
372 val path
= String.concatWith
"/"
373 (Config
.resultRoot
:: node
:: rev elems
)
374 val tmpPath
= String.concatWith
"/"
375 (Config
.tmpDir
:: node
:: rev elems
)
377 (if Posix
.FileSys
.ST
.isDir
378 (Posix
.FileSys
.stat path
) then
381 (OS
.FileSys
.remove path
;
382 OS
.FileSys
.mkDir path
))
383 handle OS
.SysErr _
=> OS
.FileSys
.mkDir path
;
385 (if Posix
.FileSys
.ST
.isDir
386 (Posix
.FileSys
.stat tmpPath
) then
389 (OS
.FileSys
.remove tmpPath
;
390 OS
.FileSys
.mkDir tmpPath
))
391 handle OS
.SysErr _
=> OS
.FileSys
.mkDir tmpPath
398 fn (root
, site
) => String.concatWith
"/" (root
:: site
:: rev ("" :: elems
))
401 datatype file_action
' =
402 Add
' of {src
: string, dst
: string}
404 | Modify
' of {src
: string, dst
: string}
406 fun findDiffs (site
, dom
, acts
) =
409 val realPath
= gp (Config
.resultRoot
, site
)
410 val tmpPath
= gp (Config
.tmpDir
, site
)
412 (*val _
= print ("getDiffs(" ^ site ^
", " ^ dom ^
")... " ^ realPath ^
"; " ^ tmpPath ^
"\n")*)
414 val dir
= Posix
.FileSys
.opendir realPath
417 case Posix
.FileSys
.readdir dir
of
418 NONE
=> (Posix
.FileSys
.closedir dir
;
422 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
424 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
427 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat
real) then
429 else if Posix
.FileSys
.access (tmp
, []) then
430 if Slave
.shell
[Config
.diff
, " ", real, " ", tmp
] then
433 loopReal ((site
, dom
, realPath
, Modify
' {src
= tmp
, dst
= real}) :: acts
)
435 loopReal ((site
, dom
, realPath
, Delete
' real) :: acts
)
438 val acts
= loopReal acts
440 val dir
= Posix
.FileSys
.opendir tmpPath
443 case Posix
.FileSys
.readdir dir
of
444 NONE
=> (Posix
.FileSys
.closedir dir
;
448 val real = OS
.Path
.joinDirFile
{dir
= realPath
,
450 val tmp
= OS
.Path
.joinDirFile
{dir
= tmpPath
,
453 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat tmp
) then
455 else if Posix
.FileSys
.access (real, []) then
458 loopTmp ((site
, dom
, realPath
, Add
' {src
= tmp
, dst
= real}) :: acts
)
461 val acts
= loopTmp acts
466 fun findAllDiffs () =
468 val dir
= Posix
.FileSys
.opendir Config
.tmpDir
469 val len
= length (String.fields (fn ch
=> ch
= #
"/") Config
.tmpDir
) + 1
471 fun exploreSites diffs
=
472 case Posix
.FileSys
.readdir dir
of
476 fun explore (dname
, diffs
) =
478 val dir
= Posix
.FileSys
.opendir dname
481 case Posix
.FileSys
.readdir dir
of
485 val fname
= OS
.Path
.joinDirFile
{dir
= dname
,
488 loop (if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fname
) then
490 val dom
= String.fields (fn ch
=> ch
= #
"/") fname
491 val dom
= List.drop (dom
, len
)
492 val dom
= String.concatWith
"." (rev dom
)
494 val dname
' = OS
.Path
.joinDirFile
{dir
= dname
,
498 findDiffs (site
, dom
, diffs
))
505 before Posix
.FileSys
.closedir dir
508 exploreSites (explore (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
509 file
= site
}, diffs
))
513 before Posix
.FileSys
.closedir dir
516 val masterNode
: string option ref
= ref NONE
517 fun dnsMaster () = !masterNode
519 val _
= Env
.containerV_one
"domain"
520 ("domain", Env
.string)
523 val kind
= Env
.env
dnsKind (evs
, "DNS")
524 val ttl
= Env
.env Env
.int (evs
, "TTL")
525 val aliases
= Env
.env (Env
.list Env
.string) (evs
, "Aliases")
527 val path
= getPath dom
529 val () = (current
:= dom
;
530 currentsAli
:= Slave
.remove (Slave
.removeDups aliases
, dom
);
531 currentPath
:= (fn site
=> path (Config
.tmpDir
, site
));
532 currentPathAli
:= (fn (dom
, site
) => getPath
dom (Config
.tmpDir
, site
)))
534 fun saveSoa (kind
, soa
: soa
) node
=
536 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "soa"}
540 write (Int.toString ttl
);
546 | SOME n
=> write (Int.toString n
);
548 write (Int.toString (#ref soa
));
550 write (Int.toString (#ret soa
));
552 write (Int.toString (#exp soa
));
554 write (Int.toString (#min soa
));
559 fun saveNamed (kind
, soa
: soa
, masterIp
, slaveIps
) node
=
560 if dom
= "localhost" then
563 val {write
, writeDom
, close
} = domainsFile
{node
= node
, name
= "named.conf"}
567 write
"\" {\n\ttype ";
569 write
";\n\tfile \"";
570 write Config
.Bind
.zonePath_real
;
575 "master" => (write
"\tallow-transfer {\n";
576 app (fn ip
=> (write
"\t\t";
578 write
";\n")) slaveIps
;
580 | _
=> (write
"\tmasters { ";
588 NoDns
=> masterNode
:= NONE
593 InternalMaster node
=> nodeIp node
594 | ExternalMaster ip
=> ip
596 val slaveIps
= map
nodeIp (#slaves dns
)
598 app (saveSoa ("slave", #soa dns
)) (#slaves dns
);
599 app (saveNamed ("slave", #soa dns
, masterIp
, slaveIps
)) (#slaves dns
);
601 InternalMaster node
=>
602 (masterNode
:= SOME node
;
603 saveSoa ("master", #soa dns
) node
;
604 saveNamed ("master", #soa dns
, masterIp
, slaveIps
) node
)
605 | _
=> masterNode
:= NONE
609 fn () => !afters (!current
))
611 val () = Env
.registerPre (fn () => (ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
612 fn cl
=> "Temp file cleanup failed: " ^ cl
));
613 OS
.FileSys
.mkDir Config
.tmpDir
;
614 app (fn node
=> OS
.FileSys
.mkDir
615 (OS
.Path
.joinDirFile
{dir
= Config
.tmpDir
,
618 app (fn node
=> OS
.FileSys
.mkDir
619 (OS
.Path
.joinDirFile
{dir
= Config
.resultRoot
,
621 handle OS
.SysErr _
=> ())
624 fun handleSite (site
, files
) =
628 print ("New configuration for node " ^ site ^
"\n");
629 if site
= Config
.defaultNode
then
630 Slave
.handleChanges files
632 val bio
= OpenSSL
.connect (valOf (!ssl_context
),
635 ^
Int.toString Config
.slavePort
)
637 app (fn file
=> Msg
.send (bio
, MsgFile file
)) files
;
638 Msg
.send (bio
, MsgDoFiles
);
640 NONE
=> print
"Slave closed connection unexpectedly\n"
643 MsgOk
=> print ("Slave " ^ site ^
" finished\n")
644 | MsgError s
=> print ("Slave " ^ site
645 ^
" returned error: " ^
647 | _
=> print ("Slave " ^ site
648 ^
" returned unexpected command\n");
653 val () = Env
.registerPost (fn () =>
655 val diffs
= findAllDiffs ()
657 val diffs
= map (fn (site
, dom
, dir
, Add
' {src
, dst
}) =>
658 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
659 fn cl
=> "Copy failed: " ^ cl
);
665 |
(site
, dom
, dir
, Delete
' dst
) =>
666 (OS
.FileSys
.remove dst
667 handle OS
.SysErr _
=>
668 ErrorMsg
.error
NONE ("Delete failed for " ^ dst
);
670 {action
= Slave
.Delete
true,
674 |
(site
, dom
, dir
, Modify
' {src
, dst
}) =>
675 (Slave
.shellF ([Config
.cp
, " ", src
, " ", dst
],
676 fn cl
=> "Copy failed: " ^ cl
);
678 {action
= Slave
.Modify
,
683 if !ErrorMsg
.anyErrors
then
686 val changed
= foldl (fn ((site
, file
), changed
) =>
688 val ls
= case SM
.find (changed
, site
) of
692 SM
.insert (changed
, site
, file
:: ls
)
695 SM
.appi handleSite changed
697 ignore (Slave
.shellF ([Config
.rm
, " -rf ", Config
.tmpDir
, ""],
698 fn cl
=> "Temp file cleanup failed: " ^ cl
))
701 fun hasPriv priv
= Acl
.query
{user
= getUser (), class
= "priv", value
= "all"}
702 orelse Acl
.query
{user
= getUser (), class
= "priv", value
= priv
}
704 val _
= Env
.type_one
"dns_node"
707 List.exists (fn x
=> x
= node
) Config
.dnsNodes_all
708 orelse (hasPriv
"dns"
709 andalso List.exists (fn x
=> x
= node
) Config
.dnsNodes_admin
))
711 val _
= Env
.type_one
"mail_node"
714 List.exists (fn x
=> x
= node
) Config
.mailNodes_all
715 orelse (hasPriv
"mail"
716 andalso List.exists (fn x
=> x
= node
) Config
.mailNodes_admin
))
718 fun rmdom
' delete resultRoot doms
=
720 fun doNode (node
, _
) =
722 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
725 fun doDom (dom
, actions
) =
727 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
728 val dname
= OS
.Path
.concat (dname
, domPath
)
730 fun visitDom (dom
, dname
, actions
) =
732 val dir
= Posix
.FileSys
.opendir dname
735 case Posix
.FileSys
.readdir dir
of
739 val fnameFull
= OS
.Path
.joinDirFile
{dir
= dname
,
742 if Posix
.FileSys
.ST
.isDir (Posix
.FileSys
.stat fnameFull
) then
743 loop (visitDom (fname ^
"." ^ dom
,
747 loop ({action
= Slave
.Delete delete
,
750 file
= fnameFull
} :: actions
)
754 before Posix
.FileSys
.closedir dir
756 handle OS
.SysErr (s
, _
) =>
757 (print ("Warning: System error deleting domain " ^ dom ^
" on " ^ node ^
": " ^ s ^
"\n");
760 visitDom (dom
, dname
, actions
)
763 val actions
= foldl doDom
[] doms
765 handleSite (node
, actions
)
767 handle IO
.Io _
=> print ("Warning: IO error deleting domains on " ^ node ^
".\n")
769 fun cleanupNode (node
, _
) =
773 val domPath
= String.concatWith
"/" (rev (String.fields (fn ch
=> ch
= #
".") dom
))
774 val dname
= OS
.Path
.joinDirFile
{dir
= resultRoot
,
776 val dname
= OS
.Path
.concat (dname
, domPath
)
779 ignore (OS
.Process
.system (Config
.rm ^
" -rf " ^ dname
))
787 app doNode Config
.nodeIps
;
788 app cleanupNode Config
.nodeIps
791 val rmdom
= rmdom
' true Config
.resultRoot
792 val rmdom
' = rmdom
' false
794 fun homedirOf uname
=
795 Posix
.SysDB
.Passwd
.home (Posix
.SysDB
.getpwnam uname
)
797 fun homedir () = homedirOf (getUser ())
799 type subject
= {node
: string, domain
: string}
801 val describers
: (subject
-> string) list ref
= ref
[]
803 fun registerDescriber f
= describers
:= f
:: !describers
805 fun describeOne arg
= String.concat (map (fn f
=> f arg
) (rev (!describers
)))
807 val line
= "--------------------------------------------------------------\n"
808 val dline
= "==============================================================\n"
811 String.concat (List.mapPartial
813 case describeOne
{node
= node
, domain
= dom
} of
816 SOME (String.concat
[dline
, "Node ", node
, "\n", dline
, "\n", s
]))
819 datatype description
=
820 Filename
of { filename
: string, heading
: string, showEmpty
: bool }
821 | Extension
of { extension
: string, heading
: string -> string }
823 fun considerAll ds
{node
, domain
} =
825 val ds
= map (fn d
=> (d
, ref
[])) ds
827 val path
= Config
.resultRoot
828 val jdf
= OS
.Path
.joinDirFile
829 val path
= jdf
{dir
= path
, file
= node
}
830 val path
= foldr (fn (more
, path
) => jdf
{dir
= path
, file
= more
})
831 path (String.tokens (fn ch
=> ch
= #
".") domain
)
833 if Posix
.FileSys
.access (path
, []) then
835 val dir
= Posix
.FileSys
.opendir path
838 case Posix
.FileSys
.readdir dir
of
841 (app (fn (d
, entries
) =>
843 fun readFile showEmpty entries
' =
845 val fname
= OS
.Path
.joinDirFile
{dir
= path
,
848 val inf
= TextIO.openIn fname
850 fun loop (seenOne
, entries
') =
851 case TextIO.inputLine inf
of
852 NONE
=> if seenOne
orelse showEmpty
then
856 | SOME line
=> loop (true, line
:: entries
')
858 loop (false, entries
')
859 before TextIO.closeIn inf
863 Filename
{filename
, heading
, showEmpty
} =>
864 if fname
= filename
then
865 entries
:= readFile
showEmpty ("\n" :: line
:: ":\n" :: heading
:: line
:: !entries
)
868 | Extension
{extension
, heading
} =>
870 val {base
, ext
} = OS
.Path
.splitBaseExt fname
875 if extension
' = extension
then
876 entries
:= readFile
true ("\n" :: line
:: ":\n" :: heading base
:: line
:: !entries
)
884 Posix
.FileSys
.closedir dir
;
885 String.concat (List.concat (map (fn (_
, entries
) => rev (!entries
)) ds
))
891 val () = registerDescriber (considerAll
[Filename
{filename
= "soa",