Package: ed
Version: 0.7-1
Severity: wishlist
Tags: patch

Hi,

Plan9's ed has a browse, which can be used to browse the file `page by
page'.  The document about it is:

(.)b[+-][pagesize][pln]
Browse.  Print a `page', normally 20 lines.  The optional (default) or
specifies whether the next or previous page is to be printed.  The
optional pagesize is the number of lines in a page.  The optional or
causes printing in the specified format, initially Pagesize and format
are remembered between commands.  Dot is left at the last line
displayed.

Obviously, it is a very convenient feature.  (GNU ed claims that
``Prints the addressed lines.  If invoked from a terminal, ed
pauses at the end of each page until a newline is entered.  The
current address is set to the last line printed.''  But I don't know
how to use it, unfortunately.)

As an initial try, I modified the source file `main_loop.c', based on
GNU ed version 0.9, and basically implement it.  The patch is attached
below:


--- ed-0.9/main_loop.c  2008-01-24 02:11:32.000000000 +0800
+++ ed-0.9-hzwang-0.1/main_loop.c       2008-03-21 02:37:13.000000000 +0800
@@ -390,6 +390,11 @@
   int status = 0;
   int addr, c, n;
 
+  static int pagesize = 20;
+  char direction = '+';
+  static int bflags = 0;
+  char ch;
+
   const int addr_cnt = extract_addr_range(); if( addr_cnt < 0 ) return ERR;
   ibufp = skip_blanks( ibufp );
   c = *ibufp++;
@@ -488,6 +493,51 @@
                return ERR;
              gflags = 0;
              break;
+    case 'b': ch = *ibufp++;
+                 if (ch == '-' || ch == '+')
+                       {
+                         direction = ch;
+                         ch = *ibufp++;
+                       }
+                 if (isdigit (ch))
+                       pagesize = 0;
+                 while (isdigit (ch))
+                       {
+                         pagesize = atoi (&ch) + pagesize * 10;
+                         ch = *ibufp++;
+                       }
+                 if (ch == 'l')
+                       bflags = GLS;
+                 else if (ch == 'n')
+                       bflags = GNP;
+                 else if (ch == 'p')
+            bflags = GPR;
+                 else if (ch == '\n')
+            ;
+          else
+                       {
+                         set_error_msg ("Invalid command suffix");
+                         return ERR;
+                       }
+                 if (second_addr < 0 || second_addr > last_addr ())
+                       {
+                         invalid_address ();
+                         return ERR;
+                       }
+                 if (direction == '+')
+                       {
+                         first_addr = second_addr;
+                         second_addr = second_addr + pagesize > last_addr ()
+                               ? last_addr () : second_addr + pagesize;
+                       }
+                 else
+                       {
+                         first_addr = second_addr - pagesize > 0
+                               ? second_addr - pagesize : 1;
+                       }
+                 if (!display_lines (first_addr, second_addr, bflags))
+                       return ERR;
+                 break;
     case 'm': if( !check_addr_range( -1, -1, addr_cnt ) ||
                  !get_third_addr( &addr ) ) return ERR;
              if( addr >= first_addr && addr < second_addr )



Thanks.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages ed depends on:
ii  libc6                         2.7-9      GNU C Library: Shared libraries

ed recommends no packages.

-- no debconf information



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to