52427
|
1 |
/* Title: Pure/System/doc.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
View Isabelle documentation (see also "isabelle doc").
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
import scala.util.matching.Regex
|
|
11 |
|
|
12 |
|
|
13 |
object Doc
|
|
14 |
{
|
|
15 |
/* dirs */
|
|
16 |
|
|
17 |
def dirs(): List[Path] =
|
|
18 |
Path.split(Isabelle_System.getenv("ISABELLE_DOCS")).map(dir =>
|
|
19 |
if (dir.is_dir) dir
|
|
20 |
else error("Bad documentation directory: " + dir))
|
|
21 |
|
|
22 |
|
|
23 |
/* contents */
|
|
24 |
|
|
25 |
sealed abstract class Entry
|
|
26 |
case class Section(text: String) extends Entry
|
|
27 |
case class Doc(name: String, title: String) extends Entry
|
|
28 |
|
|
29 |
def contents(): List[Entry] =
|
|
30 |
{
|
|
31 |
val Section_Entry = new Regex("""^(\S.*)\s*$""")
|
|
32 |
val Doc_Entry = new Regex("""^\s+(\S+)\s+(.+)\s*$""")
|
|
33 |
|
|
34 |
for {
|
|
35 |
dir <- dirs()
|
|
36 |
catalog = dir + Path.basic("Contents")
|
|
37 |
if catalog.is_file
|
|
38 |
line <- split_lines(File.read(catalog))
|
|
39 |
entry <-
|
|
40 |
line match {
|
|
41 |
case Section_Entry(text) => Some(Section(text))
|
|
42 |
case Doc_Entry(name, title) => Some(Doc(name, title))
|
|
43 |
case _ => None
|
|
44 |
}
|
|
45 |
} yield entry
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
/* view */
|
|
50 |
|
|
51 |
def view(name: String)
|
|
52 |
{
|
|
53 |
val formats = List(Isabelle_System.getenv_strict("ISABELLE_DOC_FORMAT"), "dvi")
|
|
54 |
val docs =
|
|
55 |
for {
|
|
56 |
dir <- dirs()
|
|
57 |
fmt <- formats
|
|
58 |
doc = name + "." + fmt
|
|
59 |
if (dir + Path.basic(doc)).is_file
|
|
60 |
} yield (dir, doc)
|
|
61 |
docs match {
|
|
62 |
case (dir, doc) :: _ =>
|
|
63 |
Isabelle_System.bash_env(dir.file, null, "\"$ISABELLE_TOOL\" display " + quote(doc) + " &")
|
|
64 |
case Nil => error("Missing Isabelle documentation: " + quote(name))
|
|
65 |
}
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|