src/Pure/Thy/present.scala
changeset 67177 af5b89bc065c
parent 67176 13b5c3ff1954
child 67180 dcac4659d482
equal deleted inserted replaced
67176:13b5c3ff1954 67177:af5b89bc065c
   155 
   155 
   156   def build_document(
   156   def build_document(
   157     document_name: String = default_document_name,
   157     document_name: String = default_document_name,
   158     document_format: String = default_document_format,
   158     document_format: String = default_document_format,
   159     document_dir: Option[Path] = None,
   159     document_dir: Option[Path] = None,
   160     clean: Boolean = false,
       
   161     tags: List[String] = Nil)
   160     tags: List[String] = Nil)
   162   {
   161   {
       
   162     val document_target = Path.parent + Path.explode(document_name).ext(document_format)
       
   163 
   163     if (!document_formats.contains(document_format))
   164     if (!document_formats.contains(document_format))
   164       error("Bad document output format: " + quote(document_format))
   165       error("Bad document output format: " + quote(document_format))
   165 
   166 
   166     val dir = document_dir getOrElse default_document_dir(document_name)
   167     val dir = document_dir getOrElse default_document_dir(document_name)
   167     if (!dir.is_dir) error("Bad document output directory " + dir)
   168     if (!dir.is_dir) error("Bad document output directory " + dir)
   182 
   183 
   183     def bash(script: String): Process_Result =
   184     def bash(script: String): Process_Result =
   184     {
   185     {
   185       Output.writeln(script)  // FIXME
   186       Output.writeln(script)  // FIXME
   186       Isabelle_System.bash(script, cwd = dir.file)
   187       Isabelle_System.bash(script, cwd = dir.file)
   187     }
       
   188 
       
   189 
       
   190     /* clean target */
       
   191 
       
   192     val document_target = Path.parent + Path.explode(document_name).ext(document_format)
       
   193 
       
   194     if (clean) {
       
   195       bash("rm -f *.aux *.out *.ind *.idx *.ilg *.bbl *.blg *.log " +
       
   196         File.bash_path(document_target)).check
       
   197     }
   188     }
   198 
   189 
   199 
   190 
   200     /* prepare document */
   191     /* prepare document */
   201 
   192 
   224         "Document preparation failure in directory " + dir)
   215         "Document preparation failure in directory " + dir)
   225     }
   216     }
   226 
   217 
   227     bash("[ -f " + root_bash(document_format) + " ] && cp -f " +
   218     bash("[ -f " + root_bash(document_format) + " ] && cp -f " +
   228       root_bash(document_format) + " " + File.bash_path(document_target)).check
   219       root_bash(document_format) + " " + File.bash_path(document_target)).check
   229 
       
   230     // beware!
       
   231     if (clean) Isabelle_System.rm_tree(dir)
       
   232   }
   220   }
   233 
   221 
   234 
   222 
   235   /* Isabelle tool wrapper */
   223   /* Isabelle tool wrapper */
   236 
   224 
   237   val isabelle_tool =
   225   val isabelle_tool =
   238     Isabelle_Tool("document", "prepare theory session document", args =>
   226     Isabelle_Tool("document", "prepare theory session document", args =>
   239   {
   227   {
   240     var clean = false
       
   241     var document_dir: Option[Path] = None
   228     var document_dir: Option[Path] = None
   242     var document_name = default_document_name
   229     var document_name = default_document_name
   243     var document_format = default_document_format
   230     var document_format = default_document_format
   244     var tags: List[String] = Nil
   231     var tags: List[String] = Nil
   245 
   232 
   246     val getopts = Getopts("""
   233     val getopts = Getopts("""
   247 Usage: isabelle document [OPTIONS]
   234 Usage: isabelle document [OPTIONS]
   248 
   235 
   249   Options are:
   236   Options are:
   250     -c           aggressive cleanup of -d DIR content
       
   251     -d DIR       document output directory (default """ +
   237     -d DIR       document output directory (default """ +
   252       default_document_dir(default_document_name) + """)
   238       default_document_dir(default_document_name) + """)
   253     -n NAME      document name (default """ + quote(default_document_name) + """)
   239     -n NAME      document name (default """ + quote(default_document_name) + """)
   254     -o FORMAT    document format: """ +
   240     -o FORMAT    document format: """ +
   255       commas(document_formats.map(fmt =>
   241       commas(document_formats.map(fmt =>
   257     -t TAGS      markup for tagged regions
   243     -t TAGS      markup for tagged regions
   258 
   244 
   259   Prepare the theory session document in document directory, producing the
   245   Prepare the theory session document in document directory, producing the
   260   specified output format.
   246   specified output format.
   261 """,
   247 """,
   262       "c" -> (_ => clean = true),
       
   263       "d:" -> (arg => document_dir = Some(Path.explode(arg))),
   248       "d:" -> (arg => document_dir = Some(Path.explode(arg))),
   264       "n:" -> (arg => document_name = arg),
   249       "n:" -> (arg => document_name = arg),
   265       "o:" -> (arg => document_format = arg),
   250       "o:" -> (arg => document_format = arg),
   266       "t:" -> (arg => tags = space_explode(',', arg)))
   251       "t:" -> (arg => tags = space_explode(',', arg)))
   267 
   252 
   268     val more_args = getopts(args)
   253     val more_args = getopts(args)
   269     if (more_args.nonEmpty) getopts.usage()
   254     if (more_args.nonEmpty) getopts.usage()
   270 
   255 
   271     build_document(document_dir = document_dir, document_name = document_name,
   256     build_document(document_dir = document_dir, document_name = document_name,
   272       document_format = document_format, clean = clean, tags = tags)
   257       document_format = document_format, tags = tags)
   273   })
   258   })
   274 }
   259 }