changeset 42:c0851ec35936

don't display Octave banner if not interactive run
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 25 May 2009 11:19:50 +0200
parents de24e11a4c35
children 31df83060183
files ChangeLog package/pytave.py pytave.cc
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 25 10:57:41 2009 +0200
+++ b/ChangeLog	Mon May 25 11:19:50 2009 +0200
@@ -1,3 +1,10 @@
+2009-05-25  Jaroslav Hajek  <highegg@gmail.com>
+
+	* pytave.cc (init): Add parameter; only display Octave banner if
+	requested.
+	* package/pytave.cc: Determine whether the interpreter is
+	interactive.
+
 2009-05-25  Jaroslav Hajek  <highegg@gmail.com>
 
 	* octave_to_python.cc (is_1xn_or_0x0): New inline func.
--- a/package/pytave.py	Mon May 25 10:57:41 2009 +0200
+++ b/package/pytave.py	Mon May 25 11:19:50 2009 +0200
@@ -21,8 +21,12 @@
 """Python to Octave bridge"""
 
 import _pytave
+import sys
 
-_pytave.init()
+arg0 = sys.argv[0]
+interactive = sys.stdin.isatty() and (arg0 == '' or arg0 == '-')
+
+_pytave.init(interactive)
 (OctaveError, ValueConvertError, ObjectConvertError, ParseError, \
  VarNameError) = _pytave.get_exceptions();
 
--- a/pytave.cc	Mon May 25 10:57:41 2009 +0200
+++ b/pytave.cc	Mon May 25 11:19:50 2009 +0200
@@ -48,7 +48,7 @@
 
 namespace pytave { /* {{{ */ 
 
-   void init() {
+   void init(bool silent = true) {
 
       if (!octave_error_exception::init()
           || !value_convert_exception::init()
@@ -64,8 +64,16 @@
       const char* argv[] = {"octave",
                             "--no-line-editing",
                             "--no-history",
+                            "--silent",
                             NULL};
-      octave_main(3, const_cast<char**>(argv), 1);
+      int argc = 4;
+
+      if (silent) {
+         argv[3] = 0;
+         argc = 3;
+      }
+
+      octave_main(argc, const_cast<char**>(argv), 1);
 
       // Initialize Python Numeric Array