moved getopts to Scala;
authorwenzelm
Sun Feb 28 15:00:17 2016 +0100 (2016-02-28)
changeset 6244591902961184c
parent 62444 94f457bea7c1
child 62446 5b749c31eb97
moved getopts to Scala;
lib/Tools/update_cartouches
src/Pure/Tools/update_cartouches.scala
     1.1 --- a/lib/Tools/update_cartouches	Sun Feb 28 14:48:38 2016 +0100
     1.2 +++ b/lib/Tools/update_cartouches	Sun Feb 28 15:00:17 2016 +0100
     1.3 @@ -4,62 +4,6 @@
     1.4  #
     1.5  # DESCRIPTION: update theory syntax to use cartouches
     1.6  
     1.7 -
     1.8 -## diagnostics
     1.9 -
    1.10 -PRG="$(basename "$0")"
    1.11 -
    1.12 -function usage()
    1.13 -{
    1.14 -  echo
    1.15 -  echo "Usage: isabelle $PRG [FILES|DIRS...]"
    1.16 -  echo
    1.17 -  echo "  Options are:"
    1.18 -  echo "    -c           replace comment marker \"--\" by symbol \"\\<comment>\""
    1.19 -  echo "    -t           replace @{text} antiquotations within text tokens"
    1.20 -  echo
    1.21 -  echo "  Recursively find .thy files and update theory syntax to use cartouches"
    1.22 -  echo "  instead of old-style {* verbatim *} or \`alt_string\` tokens."
    1.23 -  echo
    1.24 -  echo "  Old versions of files are preserved by appending \"~~\"."
    1.25 -  echo
    1.26 -  exit 1
    1.27 -}
    1.28 -
    1.29 -
    1.30 -## process command line
    1.31 -
    1.32 -# options
    1.33 -
    1.34 -COMMENT="false"
    1.35 -TEXT="false"
    1.36 +isabelle_admin_build jars || exit $?
    1.37  
    1.38 -while getopts "ct" OPT
    1.39 -do
    1.40 -  case "$OPT" in
    1.41 -    c)
    1.42 -      COMMENT="true"
    1.43 -      ;;
    1.44 -    t)
    1.45 -      TEXT="true"
    1.46 -      ;;
    1.47 -    \?)
    1.48 -      usage
    1.49 -      ;;
    1.50 -  esac
    1.51 -done
    1.52 -
    1.53 -shift $(($OPTIND - 1))
    1.54 -
    1.55 -
    1.56 -# args
    1.57 -
    1.58 -[ "$#" -eq 0 -o "$1" = "-?" ] && usage
    1.59 -
    1.60 -SPECS="$@"; shift "$#"
    1.61 -
    1.62 -
    1.63 -## main
    1.64 -
    1.65 -find $SPECS -name \*.thy -print0 | \
    1.66 -  xargs -0 "$ISABELLE_TOOL" java isabelle.Update_Cartouches "$COMMENT" "$TEXT"
    1.67 +"$ISABELLE_TOOL" java isabelle.Update_Cartouches "$@"
     2.1 --- a/src/Pure/Tools/update_cartouches.scala	Sun Feb 28 14:48:38 2016 +0100
     2.2 +++ b/src/Pure/Tools/update_cartouches.scala	Sun Feb 28 15:00:17 2016 +0100
     2.3 @@ -87,13 +87,31 @@
     2.4    def main(args: Array[String])
     2.5    {
     2.6      Command_Line.tool0 {
     2.7 -      args.toList match {
     2.8 -        case Properties.Value.Boolean(replace_comment) ::
     2.9 -            Properties.Value.Boolean(replace_text) :: files =>
    2.10 -          files.foreach(file =>
    2.11 -            update_cartouches(replace_comment, replace_text, Path.explode(file)))
    2.12 -        case _ => error("Bad arguments:\n" + cat_lines(args))
    2.13 -      }
    2.14 +      var replace_comment = false
    2.15 +      var replace_text = false
    2.16 +
    2.17 +      val getopts = Getopts(() => """
    2.18 +Usage: isabelle update_cartouches [FILES|DIRS...]
    2.19 +
    2.20 +  Options are:
    2.21 +    -c           replace comment marker "--" by symbol "\<comment>"
    2.22 +    -t           replace @{text} antiquotations within text tokens
    2.23 +
    2.24 +  Recursively find .thy files and update theory syntax to use cartouches
    2.25 +  instead of old-style {* verbatim *} or `alt_string` tokens.
    2.26 +
    2.27 +  Old versions of files are preserved by appending "~~".
    2.28 +""",
    2.29 +        "c" -> (_ => replace_comment = true),
    2.30 +        "t" -> (_ => replace_text = true))
    2.31 +
    2.32 +      val specs = getopts(args)
    2.33 +      if (specs.isEmpty) getopts.usage()
    2.34 +
    2.35 +      for {
    2.36 +        spec <- specs
    2.37 +        file <- File.find_files(Path.explode(spec).file, file => file.getName.endsWith(".thy"))
    2.38 +      } update_cartouches(replace_comment, replace_text, Path.explode(File.standard_path(file)))
    2.39      }
    2.40    }
    2.41  }