author | wenzelm |
Sat, 27 Jul 2013 21:01:35 +0200 | |
changeset 52740 | bceec99254b0 |
parent 52542 | 19d674acb764 |
child 53777 | 06a6216f733e |
permissions | -rw-r--r-- |
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
1 |
/* Title: Pure/Tools/doc.scala |
52427 | 2 |
Author: Makarius |
3 |
||
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
4 |
View Isabelle documentation. |
52427 | 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)) |
|
52740 | 21 |
|
52427 | 22 |
|
23 |
/* contents */ |
|
24 |
||
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
25 |
private def contents_lines(): List[String] = |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
26 |
for { |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
27 |
dir <- dirs() |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
28 |
catalog = dir + Path.basic("Contents") |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
29 |
if catalog.is_file |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
30 |
line <- split_lines(Library.trim_line(File.read(catalog))) |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
31 |
} yield line |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
32 |
|
52427 | 33 |
sealed abstract class Entry |
34 |
case class Section(text: String) extends Entry |
|
35 |
case class Doc(name: String, title: String) extends Entry |
|
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
36 |
case class Text_File(name: String, path: Path) extends Entry |
52427 | 37 |
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
38 |
private val Section_Entry = new Regex("""^(\S.*)\s*$""") |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
39 |
private val Doc_Entry = new Regex("""^\s+(\S+)\s+(.+)\s*$""") |
52427 | 40 |
|
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
41 |
private def release_notes(): List[Entry] = |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
42 |
{ |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
43 |
def text_file(name: String): Option[Text_File] = |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
44 |
{ |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
45 |
val path = Path.variable("ISABELLE_HOME") + Path.explode(name) |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
46 |
if (path.is_file) Some(Text_File(name, path)) |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
47 |
else None |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
48 |
} |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
49 |
val names = |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
50 |
List("ANNOUNCE", "README", "NEWS", "COPYRIGHT", "CONTRIBUTORS", |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
51 |
"contrib/README", "README_REPOSITORY") |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
52 |
Section("Release notes") :: |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
53 |
(for (name <- names; entry <- text_file(name)) yield entry) |
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
54 |
} |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52448
diff
changeset
|
55 |
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
56 |
def contents(): List[Entry] = |
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52448
diff
changeset
|
57 |
(for { |
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
58 |
line <- contents_lines() |
52427 | 59 |
entry <- |
60 |
line match { |
|
61 |
case Section_Entry(text) => Some(Section(text)) |
|
62 |
case Doc_Entry(name, title) => Some(Doc(name, title)) |
|
63 |
case _ => None |
|
64 |
} |
|
52542
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
65 |
} yield entry) ::: release_notes() |
52427 | 66 |
|
67 |
||
68 |
/* view */ |
|
69 |
||
70 |
def view(name: String) |
|
71 |
{ |
|
52740 | 72 |
val doc = name + ".pdf" |
52448
082a1c8c2c89
clarified ISABELLE_DOC_FORMAT -- eliminated slightly odd fall-back;
wenzelm
parents:
52444
diff
changeset
|
73 |
dirs().find(dir => (dir + Path.basic(doc)).is_file) match { |
082a1c8c2c89
clarified ISABELLE_DOC_FORMAT -- eliminated slightly odd fall-back;
wenzelm
parents:
52444
diff
changeset
|
74 |
case Some(dir) => |
52429
921f22c8890e
detach process more reliably -- NB: viewer might be synchronous or asynchronous depending on settings;
wenzelm
parents:
52427
diff
changeset
|
75 |
Isabelle_System.bash_env(dir.file, null, |
921f22c8890e
detach process more reliably -- NB: viewer might be synchronous or asynchronous depending on settings;
wenzelm
parents:
52427
diff
changeset
|
76 |
"\"$ISABELLE_TOOL\" display " + quote(doc) + " >/dev/null 2>/dev/null &") |
52448
082a1c8c2c89
clarified ISABELLE_DOC_FORMAT -- eliminated slightly odd fall-back;
wenzelm
parents:
52444
diff
changeset
|
77 |
case None => error("Missing Isabelle documentation file: " + quote(doc)) |
52427 | 78 |
} |
79 |
} |
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
80 |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
81 |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
82 |
/* command line entry point */ |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
83 |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
84 |
def main(args: Array[String]) |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
85 |
{ |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
86 |
Command_Line.tool { |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
87 |
if (args.isEmpty) Console.println(cat_lines(contents_lines())) |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
88 |
else args.foreach(view) |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
89 |
0 |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
90 |
} |
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
91 |
} |
52427 | 92 |
} |
93 |