src/Pure/Tools/update_header.scala
author wenzelm
Sun, 16 Aug 2015 23:14:27 +0200
changeset 60953 87f0f707a5f8
parent 59083 88b0b1f28adc
child 61463 8e46cea6a45a
permissions -rw-r--r--
clarified initial ML name space (amending 7aad4be8a48e);

/*  Title:      Pure/Tools/update_header.scala
    Author:     Makarius

Replace theory header command.
*/

package isabelle


object Update_Header
{
  def update_header(section: String, path: Path)
  {
    val text0 = File.read(path)
    val text1 =
      (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator)
        yield { if (tok.source == "header") section else tok.source }).mkString

    if (text0 != text1) {
      Output.writeln("changing " + path)
      File.write_backup2(path, text1)
    }
  }


  /* command line entry point */

  def main(args: Array[String])
  {
    Command_Line.tool0 {
      args.toList match {
        case section :: files =>
          if (!Set("chapter", "section", "subsection", "subsubsection").contains(section))
            error("Bad heading command: " + quote(section))
          files.foreach(file => update_header(section, Path.explode(file)))
        case _ => error("Bad arguments:\n" + cat_lines(args))
      }
    }
  }
}