bug-ed
[Top][All Lists]
Advanced

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

[PATCH] ed - multiple files on command line


From: Paul Jackson
Subject: [PATCH] ed - multiple files on command line
Date: Thu, 9 Nov 2006 20:23:52 -0800

Here is a patch (not very well tested) implementing this proposal.
==================================================================

Provide the ability to edit multiple command line specified files.

Supports editing multiple files named on the command line.  To switch
from the (N)th file to the (N+1)th file, issue the command: e %.  The
'%' is replaced with the name of the next file from the command line.

I previously implemented and supported this feature on Unix systems
shipped by Convergent Technologies, including the Unix PC (circa 1985)
and on Irix systems shipped by SGI.

The code in this implementation is a complete rewrite, and quite a
bit simpler, than the implementation that I used at Convergent and SGI.

From: Paul Jackson <address@hidden>

---
 doc/ed.1       |    8 ++++++++
 doc/ed.info    |    4 +++-
 doc/ed.texinfo |    4 +++-
 ed.h           |    1 +
 main.c         |    3 ++-
 main_loop.c    |   34 ++++++++++++++++++++++++++++++++++
 6 files changed, 51 insertions(+), 3 deletions(-)

--- ed-0.3-rc3.orig/main.c      2006-11-04 04:04:10.000000000 -0800
+++ ed-0.3-rc3/main.c   2006-11-09 20:08:02.000000000 -0800
@@ -73,7 +73,7 @@ void show_error( const char *msg, const 
 void show_help( void )
   {
   printf( "%s - The GNU line editor.\n", Program_name );
-  printf( "\nUsage: %s [options] [file]\n", invocation_name );
+  printf( "\nUsage: %s [options] [file] ...\n", invocation_name );
   printf( "Options:\n" );
   printf( "  -h, --help                 display this help and exit\n" );
   printf( "  -V, --version              output version information and exit\n" 
);
@@ -172,6 +172,7 @@ int main( const int argc, const char *ar
       if( read_file( arg, 0, scripted ) < 0 && is_regular_file( 0 ) )
         return 2;
       else if( arg[0] != '!' ) set_def_filename( arg );
+      setnxtfile( argc - argind - 2, argv + argind + 2 );
       }
     else
       {
--- ed-0.3-rc3.orig/main_loop.c 2006-11-04 03:59:28.000000000 -0800
+++ ed-0.3-rc3/main_loop.c      2006-11-09 20:10:47.000000000 -0800
@@ -174,6 +174,39 @@ const char *get_filename( const char res
   return ( is_valid_filename( file, restricted ) ? file : 0 );
   }
 
+/*
+ * ed file1 file2 ...
+ *
+ * Supports editing multiple files named on the command line.
+ * To switch from the (N)th file to the (N+1)th file,
+ * issue the command: e %.  The '%' is replaced with the name
+ * of the next file from the command line.
+ */
+
+int fncnt = 0;        /* number of cmdline filenames (except first name) */
+const char **fnvec;   /* array of cmdline filenames (except first name) */
+int nexti = 0;        /* index of next filename to edit in fnvec[] */
+
+/* initialize list of files */
+void setnxtfile( const int argc, const char **argv )
+{
+  fncnt = argc;
+  fnvec = argv;
+}
+
+/* return next file, or just "%" */
+const char *getnxtfile( void )
+{
+  const char *fnp;
+
+  if (nexti < fncnt)
+    fnp = fnvec[nexti++];
+  else
+    fnp = "%";
+  set_def_filename( fnp );
+  return fnp;
+}
+
 
 void invalid_address( void ) { set_error_msg( "Invalid address" ); }
 
@@ -429,6 +462,7 @@ int exec_command( const char isglobal, c
              if( fnp[0] && fnp[0] != '!' ) set_def_filename( fnp );
              if( traditional && !fnp[0] && !def_filename[0] )
                { set_error_msg( "No current filename" ); return ERR; }
+             if (!strcmp( fnp, "%" )) fnp = getnxtfile();
              if( read_file( fnp[0] ? fnp : def_filename, 0, scripted ) < 0 )
                return ERR;
              disable_undo(); set_modified( 0 );
--- ed-0.3-rc3.orig/ed.h        2006-11-04 03:57:24.000000000 -0800
+++ ed-0.3-rc3/ed.h     2006-11-09 20:08:33.000000000 -0800
@@ -115,6 +115,7 @@ void set_error_msg( const char *msg );
 void set_prompt( const char *s );
 void set_verbose( void );
 void unmark_line_node( const line_t *lp );
+void setnxtfile( const int, const char ** );
 
 /* defined in re.c */
 char build_active_list( const char **ibufpp, const int first_addr,
--- ed-0.3-rc3.orig/doc/ed.1    2006-10-05 12:35:42.000000000 -0700
+++ ed-0.3-rc3/doc/ed.1 2006-11-09 19:54:32.000000000 -0800
@@ -552,6 +552,14 @@ and sets the default filename.
 If
 .I file
 is not specified, then the  default filename is used.
+If
+.I file
+is replaced by
+.BR % ,
+and if additional
+.I file
+arguments were specified on the command line, the next filename
+specified on the command line is used.
 Any lines in the buffer are deleted before
 the new file is read.
 The current address is set to the last line read.
--- ed-0.3-rc3.orig/doc/ed.info 2006-11-04 08:27:58.000000000 -0800
+++ ed-0.3-rc3/doc/ed.info      2006-11-09 19:59:54.000000000 -0800
@@ -621,7 +621,9 @@ specified (in parenthesis).
 
 `e FILE'
      Edits FILE, and sets the default filename. If FILE is not
-     specified, then the default filename is used. Any lines in the
+     specified, then the default filename is used. If file is replaced by %,
+     and if additional file arguments were specified on the command line, the
+     next filename specified on the command line is used. Any lines in the
      buffer are deleted before the new file is read. The current
      address is set to the last line read.
 
--- ed-0.3-rc3.orig/doc/ed.texinfo      2006-11-04 08:27:41.000000000 -0800
+++ ed-0.3-rc3/doc/ed.texinfo   2006-11-09 20:01:00.000000000 -0800
@@ -688,7 +688,9 @@ range.
 
 @item e @var{file}
 Edits @var{file}, and sets the default filename. If @var{file} is not
-specified, then the default filename is used. Any lines in the buffer
+specified, then the default filename is used. If file is replaced by %,
+and if additional file arguments were specified on the command line, the
+next filename specified on the command line is used. Any lines in the buffer
 are deleted before the new file is read. The current address is set to
 the last line read.
 
The following not very well tested patch, against ed-0.3-rc3,
implements this proposed feature:



-- 
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <address@hidden> 1.925.600.0401




reply via email to

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