Mercurial > octave-nkf
diff src/pager.cc @ 581:bc813f5eb025
[project @ 1994-08-07 01:02:15 by jwe]
author | jwe |
---|---|
date | Sun, 07 Aug 1994 01:02:15 +0000 |
parents | 7ea224e713cd |
children | 7caf80625d0e |
line wrap: on
line diff
--- a/src/pager.cc Sun Aug 07 01:02:15 1994 +0000 +++ b/src/pager.cc Sun Aug 07 01:02:15 1994 +0000 @@ -27,17 +27,32 @@ #include <iostream.h> #include <strstream.h> +#include <fstream.h> #include <stdlib.h> #include "procstream.h" #include "user-prefs.h" +#include "oct-obj.h" +#include "error.h" +#include "defun.h" #include "input.h" #include "pager.h" +#include "utils.h" +#include "help.h" // Where we stash output headed for the screen. static ostrstream *pager_buf = 0; +// Nonzero means we write to the diary file. +static int write_to_diary_file = 0; + +// The name of the current diary file. +static char *diary_file = "diary"; + +// The diary file. +static ofstream diary_stream; + static int line_count (char *s) { @@ -52,13 +67,12 @@ return count; } -/* - * For now, use the variables from readline. It already handles - * SIGWINCH, so these values have a good chance of being correct even - * if the window changes size (they will be wrong if, for example, the - * luser changes the window size while the pager is running, and the - * signal is handled by the pager instead of us. - */ +// For now, use the variables from readline. It already handles +// SIGWINCH, so these values have a good chance of being correct even +// if the window changes size (they will be wrong if, for example, the +// luser changes the window size while the pager is running, and the +// signal is handled by the pager instead of us. + int terminal_columns (void) { @@ -116,6 +130,8 @@ return; } + maybe_write_to_diary_file (message); + int nlines = line_count (message); if (nlines > terminal_rows () - 2) @@ -142,6 +158,76 @@ initialize_pager (); } +static void +open_diary_file (void) +{ + if (diary_stream.is_open ()) + diary_stream.close (); + + diary_stream.open (diary_file, ios::app); + + if (! diary_stream) + error ("diary: can't open diary file `%s'", diary_file); +} + +void +close_diary_file (void) +{ + if (diary_stream) + diary_stream.close (); +} + +void +maybe_write_to_diary_file (const char *s) +{ + if (write_to_diary_file && diary_stream) + diary_stream << s; +} + +DEFUN_TEXT ("diary", Fdiary, Sdiary, -1, 1, + "diary [on|off]\n\ +diary [file]\n\ +\n\ +redirect all input and screen output to a file.") +{ + Octave_object retval; + + DEFINE_ARGV("diary"); + + switch (argc) + { + case 1: + write_to_diary_file = ! write_to_diary_file; + open_diary_file (); + break; + case 2: + { + char *arg = argv[1]; + if (strcmp (arg, "on") == 0) + { + write_to_diary_file = 1; + open_diary_file (); + } + else if (strcmp (arg, "off") == 0) + write_to_diary_file = 0; + else + { + delete [] diary_file; + diary_file = strsave (arg); + open_diary_file (); + } + } + break; + default: + print_usage ("diary"); + break; + } + + DELETE_ARGV; + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***