octave-maintainers
[Top][All Lists]
Advanced

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

Re: MSVC compilation patch: less from GnuWin32


From: John W. Eaton
Subject: Re: MSVC compilation patch: less from GnuWin32
Date: Tue, 7 Nov 2006 15:51:45 -0500

On  7-Nov-2006, Michael Goffioul wrote:

| John W. Eaton a écrit :
| > On  7-Nov-2006, address@hidden wrote:
| >
| > | It's not a bug, it's a feature :-)
| > | 
| > | Looking at Less code, it appears that the -X flag disable the terminal
| > | initialization. This code is responsible for calculating the size of the
| > | Windows console, storing the current console buffer, and so on.
| > | When this flag is set, Less does not know about the console size and
| > | does not restore the console state on exit. So it really looks like the
| > | -X flag does not have the same meaning as in the UNIX version.
| >
| > OK.  Is there a way to determine that the gnuwin32 version of less is
| > being used?  What does less --version return?
| >   
| 
| Unfortunately, I think this will be rather difficult to do. less 
| --version gives:
| 
| less 394
| Copyright (C) 1984-2005 Mark Nudelman
| 
| less comes with NO WARRANTY, to the extent permitted by law.
| For information about the terms of redistribution,
| see the file named README in the less distribution.
| Homepage: http://www.greenwoodsoftware.com/less
| 
| I don't see an easy solution for this (except letting the user set LESS
| variable himself and documenting the potential problem).

OK, I don't see a convenient way to determine what the default options
should be, but I think the following changes make it easier for
someone who is packaging Octave to set them.  With the changes below,
the internal VPAGER variable is just set to the program name, and the
new variable VPAGER_FLAGS is set to the options.  The new function
PAGER_FLAGS is used in the system-wide startup file to set default
flags for less if PAGER is less and LESS is not defined in the
environment.

jwe

Index: src/ChangeLog

2006-11-07  John W. Eaton  <address@hidden>

        * pager.cc (default_pager): Don't append options here.
        (pager_command): New function.
        (do_sync): Use it.
        (VPAGER_FLAGS): New variable.
        (FPAGER_FLAGS): New function.

scripts/ChangeLog

2006-11-07  John W. Eaton  <address@hidden>

        * startup/main-rcfile: Conditionally set PAGER_FLAGS.


Index: src/pager.cc
===================================================================
RCS file: /cvs/octave/src/pager.cc,v
retrieving revision 1.101
diff -u -u -r1.101 pager.cc
--- src/pager.cc        19 May 2006 05:32:17 -0000      1.101
+++ src/pager.cc        7 Nov 2006 20:45:01 -0000
@@ -64,19 +64,7 @@
 
 #ifdef OCTAVE_DEFAULT_PAGER
   if (pager_binary.empty ())
-    {
-      pager_binary = std::string (OCTAVE_DEFAULT_PAGER);
-
-      if (pager_binary == "less")
-       {
-         pager_binary.append (" -e");
-
-         std::string lessflags = octave_env::getenv ("LESS");
-         if (lessflags.empty ())
-           pager_binary.append
-             (" -X -P'-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$'");
-       }
-    }
+    pager_binary = OCTAVE_DEFAULT_PAGER;
 #endif
 
   return pager_binary;
@@ -85,6 +73,9 @@
 // The shell command to run as the pager.
 static std::string VPAGER = default_pager ();
 
+// The options to pass to the pager.
+static std::string VPAGER_FLAGS;
+
 // TRUE means that if output is going to the pager, it is sent as soon
 // as it is available.  Otherwise, it is buffered and only sent to the
 // pager when it is time to print another prompt.
@@ -137,6 +128,17 @@
   return retval;
 }
 
+static std::string
+pager_command (void)
+{
+  std::string cmd = VPAGER;
+
+  if (! (cmd.empty () || VPAGER_FLAGS.empty ()))
+    cmd += " " + VPAGER_FLAGS;
+
+  return cmd;
+}
+
 static void
 do_sync (const char *msg, int len, bool bypass_pager)
 {
@@ -151,7 +153,7 @@
        {
          if (! external_pager)
            {
-             std::string pgr = VPAGER;
+             std::string pgr = pager_command ();
 
              if (! pgr.empty ())
                {
@@ -576,12 +578,24 @@
 normally @code{\"less\"}, @code{\"more\"}, or\n\
 @code{\"pg\"}, depending on what programs are installed on your system.\n\
 @xref{Installation}.\n\
address@hidden, page_output_immediately}\n\
address@hidden, page_screen_output, page_output_immediately, PAGER_FLAGS}\n\
 @end deftypefn")
 {
   return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER);
 }
 
+DEFUN (PAGER_FLAGS, args, nargout,
+  "-*- texinfo -*-\n\
address@hidden {Built-in Function} address@hidden =} PAGER_FLAGS ()\n\
address@hidden {Built-in Function} address@hidden =} PAGER_FLAGS 
(@var{new_val})\n\
+Query or set the internal variable that specifies the options to pass\n\
+to the pager.\n\
address@hidden
address@hidden deftypefn")
+{
+  return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (PAGER_FLAGS);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
Index: scripts/startup/main-rcfile
===================================================================
RCS file: /cvs/octave/scripts/startup/main-rcfile,v
retrieving revision 1.3
diff -u -u -r1.3 main-rcfile
--- scripts/startup/main-rcfile 8 May 2006 20:23:04 -0000       1.3
+++ scripts/startup/main-rcfile 7 Nov 2006 20:44:56 -0000
@@ -9,3 +9,7 @@
 read_readline_init_file (sprintf ("%s%s%s",
                                  octave_config_info ("startupfiledir"),
                                  filesep, "inputrc"));
+
+if (strcmp (PAGER (), "less") && isempty (getenv ("LESS")))
+  PAGER_FLAGS ('-e -X -P"-- less ?pB(%pB\\%):--. (f)orward, (b)ack, (q)uit$"');
+endif

reply via email to

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