Hey Guys,

I made an improvement in ed: creating macros!

E.g. if you want to print the lines 30 to 55 often.
Create the macro "oa":
oa 30,50n

Now you can execute the macro only with typing:
oa

Let me know, if we can implement the improvement in
the next version. It has only 17 lines off code.

In the attachment you can find the diff file 
depends on the ed version 1.18.


Greetings
Harry


--- main_loop.bak       2022-10-01 08:40:34.740558153 +0200
+++ main_loop.c 2022-10-02 08:34:00.129357959 +0200
@@ -488,11 +488,20 @@
 static int exec_command( const char ** const ibufpp, const int prev_status,
                          const bool isglobal )
   {
+  /* HG */
+  char *s;
+  static char obufp['z' - 'a' +1][30];
+  /* HG. */
   const char * fnp;                            /* filename */
-  int pflags = 0;                              /* print suffixes */
+  int pflags;
+  int addr_cnt;
   int addr, c, n;
-  const int addr_cnt = extract_addresses( ibufpp );
 
+/* HG */
+start:
+/* HG. */
+  addr_cnt = extract_addresses( ibufpp );
+  pflags = 0;                          /* print suffixes */
   if( addr_cnt < 0 ) return ERR;
   *ibufpp = skip_blanks( *ibufpp );
   c = *(*ibufpp)++;
@@ -598,6 +607,20 @@
               if( !move_lines( first_addr, second_addr, addr, isglobal ) )
                 return ERR;
               break;
+    case 'o': c= *(*ibufpp)++;
+              if( c < 'a' || c > 'z') return ERR;
+              s= obufp[c - 'a'];
+              if(  **ibufpp == '\n' ){
+                printf("%s",s);
+                *ibufpp= s;
+                goto start;
+              }
+              for( n=0;; n++ ){
+                if( n>= (int) sizeof obufp[0] ) return ERR;
+                s[n]= *(*ibufpp)++;
+                if(s[n] == '\0') break;
+              }
+              break;
     case 'P':
     case 'q':
     case 'Q': if( unexpected_address( addr_cnt ) ||

Reply via email to