isabelle getenv: option -d;
authorwenzelm
Sun, 07 Jun 2009 19:07:05 +0200
changeset 31497 5333aa739082
parent 31496 c4b74075fc17
child 31498 be0f7f4f9e12
isabelle getenv: option -d;
doc-src/System/Thy/Misc.thy
doc-src/System/Thy/document/Misc.tex
lib/Tools/getenv
--- a/doc-src/System/Thy/Misc.thy	Sat Jun 06 23:43:07 2009 +0200
+++ b/doc-src/System/Thy/Misc.thy	Sun Jun 07 19:07:05 2009 +0200
@@ -85,6 +85,8 @@
   Options are:
     -a           display complete environment
     -b           print values only (doesn't work for -a)
+    -d FILE      dump complete environment to FILE
+                 (null terminated entries)
 
   Get value of VARNAMES from the Isabelle settings.
 \end{ttbox}
@@ -95,6 +97,10 @@
   Normally, output is a list of lines of the form @{text
   name}@{verbatim "="}@{text value}. The @{verbatim "-b"} option
   causes only the values to be printed.
+
+  Option @{verbatim "-d"} produces a dump of the complete environment
+  to the specified file.  Entries are terminated by the ASCII null
+  character, i.e.\ the C string terminator.
 *}
 
 
--- a/doc-src/System/Thy/document/Misc.tex	Sat Jun 06 23:43:07 2009 +0200
+++ b/doc-src/System/Thy/document/Misc.tex	Sun Jun 07 19:07:05 2009 +0200
@@ -110,6 +110,8 @@
   Options are:
     -a           display complete environment
     -b           print values only (doesn't work for -a)
+    -d FILE      dump complete environment to FILE
+                 (null terminated entries)
 
   Get value of VARNAMES from the Isabelle settings.
 \end{ttbox}
@@ -118,7 +120,11 @@
   environment that Isabelle related programs are run in. This usually
   contains much more variables than are actually Isabelle settings.
   Normally, output is a list of lines of the form \isa{name}\verb|=|\isa{value}. The \verb|-b| option
-  causes only the values to be printed.%
+  causes only the values to be printed.
+
+  Option \verb|-d| produces a dump of the complete environment
+  to the specified file.  Entries are terminated by the ASCII null
+  character, i.e.\ the C string terminator.%
 \end{isamarkuptext}%
 \isamarkuptrue%
 %
--- a/lib/Tools/getenv	Sat Jun 06 23:43:07 2009 +0200
+++ b/lib/Tools/getenv	Sun Jun 07 19:07:05 2009 +0200
@@ -17,6 +17,8 @@
   echo "  Options are:"
   echo "    -a           display complete environment"
   echo "    -b           print values only (doesn't work for -a)"
+  echo "    -d FILE      dump complete environment to FILE"
+  echo "                 (null terminated entries)"
   echo
   echo "  Get value of VARNAMES from the Isabelle settings."
   echo
@@ -30,8 +32,9 @@
 
 ALL=""
 BASE=""
+DUMP=""
 
-while getopts "ab" OPT
+while getopts "abd:" OPT
 do
   case "$OPT" in
     a)
@@ -40,6 +43,9 @@
     b)
       BASE=true
       ;;
+    d)
+      DUMP="$OPTARG"
+      ;;
     \?)
       usage
       ;;
@@ -68,3 +74,8 @@
     fi
   done
 fi
+
+if [ -n "$DUMP" ]; then
+  exec perl -w -e 'for $key (keys %ENV) { print $key, "=", $ENV{$key}, "\x00"; }' > "$DUMP"
+fi
+