help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does the exit command do?


From: Geraint Paul Bevan
Subject: Re: What does the exit command do?
Date: Thu, 23 Sep 2004 20:57:29 +0100
User-agent: Mozilla Thunderbird 0.7.1 (X11/20040715)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John W. Eaton wrote:

| But -q just means to be silent at startup (not print the banner).  The
| -H option (though you wrote -h, I assumed you meant -H) seems more
| relevant here, since it is documented to tell octave to not save
| commands to the history list.  I can see how this could easily be
| interpreted to mean "completely disable the command history feature",
| but that is not quite what it means.  We can make it appear to have
| that meaning (assuming the user does not later set saving_history to
| true and execute some commands) if someone will do the work to modify
| the history library to keep track of whether thie history list has
| been modified, or point out how to extract that information from it
| given the current interface.


The patch below records the position of the last history entry when
Octave reads the history file and then only writes the history file if
entries have been added to the history list. I am not at all familiar
with either the history library or the way that Octave handles the
history so I may have overlooked something important but it seems to
work for me, as demonstrated by the following log:


$ ls -l .octave_hist
- -rw-------  1 gbevan gbevan 37083 Sep 23 20:40 .octave_hist
$ date
Thu Sep 23 20:53:37 BST 2004

# Modified CVS octave does not touch the history
$ echo quit | /tmp/octave/bin/octave -qH ; ls -l .octave_hist
- -rw-------  1 gbevan gbevan 37083 Sep 23 20:40 .octave_hist

# Standard 2.1.57 does modify the history
$ echo quit | /usr/bin/octave -qH ; ls -l .octave_hist
- -rw-------  1 gbevan gbevan 37083 Sep 23 20:54 .octave_hist



Similarly, the modification prevents the permissios error when quitting
as www-data

$ su -c 'su www-data'
Password:
sh-3.00$ whoami
www-data
sh-3.00$ echo quit | octave -qH                 # <-- standard 2.1.57
error: Permission denied
sh-3.00$ echo quit | /tmp/octave/bin/octave -qH # <-- modified CVS




Index: liboctave/oct-rl-hist.c
===================================================================
RCS file: /cvs/octave/liboctave/oct-rl-hist.c,v
retrieving revision 1.6
diff -u -r1.6 oct-rl-hist.c
- --- a/liboctave/oct-rl-hist.c 10 Nov 2003 15:50:39 -0000      1.6
+++ b/liboctave/oct-rl-hist.c   23 Sep 2004 19:50:31 -0000
@@ -32,6 +32,8 @@

~ #include <readline/history.h>

+static HIST_ENTRY *octave_saved_entry;
+
~ void
~ octave_add_history (const char *line)
~ {
@@ -89,7 +91,9 @@
~ int
~ octave_read_history (const char *f)
~ {
- -  return read_history (f);
+  int retval = read_history (f);
+  octave_saved_entry = history_get (history_length);
+  return retval;
~ }

~ void
@@ -107,7 +111,12 @@
~ int
~ octave_write_history (const char *f)
~ {
- -  return write_history (f);
+  int retval = 0;
+  if (history_get (history_length) != octave_saved_entry)
+    {
+      retval = write_history (f);
+  }
+  return retval;
~ }

~ int



- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iEYEARECAAYFAkFTKqgACgkQcXV3N50QmNPApACaApJv4X1HE4hTJQUMJcLbfBkR
qZkAnjYI402vFX56WShDdTSfgE0UDhtF
=/40F
-----END PGP SIGNATURE-----



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]