moved getopts to Scala;
authorwenzelm
Sun, 28 Feb 2016 15:00:17 +0100
changeset 62445 91902961184c
parent 62444 94f457bea7c1
child 62446 5b749c31eb97
moved getopts to Scala;
lib/Tools/update_cartouches
src/Pure/Tools/update_cartouches.scala
--- a/lib/Tools/update_cartouches	Sun Feb 28 14:48:38 2016 +0100
+++ b/lib/Tools/update_cartouches	Sun Feb 28 15:00:17 2016 +0100
@@ -4,62 +4,6 @@
 #
 # DESCRIPTION: update theory syntax to use cartouches
 
-
-## diagnostics
-
-PRG="$(basename "$0")"
-
-function usage()
-{
-  echo
-  echo "Usage: isabelle $PRG [FILES|DIRS...]"
-  echo
-  echo "  Options are:"
-  echo "    -c           replace comment marker \"--\" by symbol \"\\<comment>\""
-  echo "    -t           replace @{text} antiquotations within text tokens"
-  echo
-  echo "  Recursively find .thy files and update theory syntax to use cartouches"
-  echo "  instead of old-style {* verbatim *} or \`alt_string\` tokens."
-  echo
-  echo "  Old versions of files are preserved by appending \"~~\"."
-  echo
-  exit 1
-}
-
-
-## process command line
-
-# options
-
-COMMENT="false"
-TEXT="false"
+isabelle_admin_build jars || exit $?
 
-while getopts "ct" OPT
-do
-  case "$OPT" in
-    c)
-      COMMENT="true"
-      ;;
-    t)
-      TEXT="true"
-      ;;
-    \?)
-      usage
-      ;;
-  esac
-done
-
-shift $(($OPTIND - 1))
-
-
-# args
-
-[ "$#" -eq 0 -o "$1" = "-?" ] && usage
-
-SPECS="$@"; shift "$#"
-
-
-## main
-
-find $SPECS -name \*.thy -print0 | \
-  xargs -0 "$ISABELLE_TOOL" java isabelle.Update_Cartouches "$COMMENT" "$TEXT"
+"$ISABELLE_TOOL" java isabelle.Update_Cartouches "$@"
--- a/src/Pure/Tools/update_cartouches.scala	Sun Feb 28 14:48:38 2016 +0100
+++ b/src/Pure/Tools/update_cartouches.scala	Sun Feb 28 15:00:17 2016 +0100
@@ -87,13 +87,31 @@
   def main(args: Array[String])
   {
     Command_Line.tool0 {
-      args.toList match {
-        case Properties.Value.Boolean(replace_comment) ::
-            Properties.Value.Boolean(replace_text) :: files =>
-          files.foreach(file =>
-            update_cartouches(replace_comment, replace_text, Path.explode(file)))
-        case _ => error("Bad arguments:\n" + cat_lines(args))
-      }
+      var replace_comment = false
+      var replace_text = false
+
+      val getopts = Getopts(() => """
+Usage: isabelle update_cartouches [FILES|DIRS...]
+
+  Options are:
+    -c           replace comment marker "--" by symbol "\<comment>"
+    -t           replace @{text} antiquotations within text tokens
+
+  Recursively find .thy files and update theory syntax to use cartouches
+  instead of old-style {* verbatim *} or `alt_string` tokens.
+
+  Old versions of files are preserved by appending "~~".
+""",
+        "c" -> (_ => replace_comment = true),
+        "t" -> (_ => replace_text = true))
+
+      val specs = getopts(args)
+      if (specs.isEmpty) getopts.usage()
+
+      for {
+        spec <- specs
+        file <- File.find_files(Path.explode(spec).file, file => file.getName.endsWith(".thy"))
+      } update_cartouches(replace_comment, replace_text, Path.explode(File.standard_path(file)))
     }
   }
 }