------- Original Message -------
On Monday, October 16th, 2023 at 04:21, Rob Landley <[email protected]> wrote:


> On 10/14/23 17:15, Oliver Webb via Toybox wrote:
> 
> > I have added the 'v' command (Which is essentially the opposite of the 
> > g[lobal] command).
> > Fixed a memory leak in the g[lobal] command (Freeing data while aborting)
> > Along with some code formatting (Replacing *(cmd+1) with cmd[1])
> 
> 
> I removed the hunk adding a SUBSTRING() macro which you never called and which
> doesn't seem that much of an improvement over the call to xmprintf() anyway...
> 
> By the way, I've mostly been cleaning up the:
> 
> .git/rebase-apply/patch:56: trailing whitespace. }
> warning: 1 line adds whitespace errors.
> 
> in all your patches, but I didn't bother this time.

My bad, Removed the trailing whitespace in this patch

> > I have been trying to get a implementation of the s[ubsitute] command to 
> > work in vi.c.
> > The best I have been able to implement barely works. I know sed.c has one 
> > that does what
> > I am trying to do but I haven't been able to implement the algorithm that 
> > sed.c is using.
> 
> 
> I was hoping to get stuff to share code, but I can worry about that in the
> eventual cleanup pass.

If you are planning on code-sharing the regex line substitution stuff.
Then this will probably be my last patch to vi.c for a while 
(Unless there is something wrong with it that can be fixed reasonably).

I have removed some of the overhead to minimize throughput, Replacing 
"run_vi_cmd("j")" 
with "cur_down(1, 1, 0)" The page clearing function calls with setting 
vi_mov_flag, etc. 

> Rob

- Oliver Webb <[email protected]>
From 0b3b674f5385493af5011c6193b4a2c46a8dd6f6 Mon Sep 17 00:00:00 2001
From: Oliver Webb <[email protected]>
Date: Mon, 16 Oct 2023 22:02:43 -0500
Subject: [PATCH] Replaced some calles to run_vi_cmd to more direct calls,
 Fixed memory leak in line range code, Removed Trailing whitespace

---
 toys/pending/vi.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/toys/pending/vi.c b/toys/pending/vi.c
index 8c3a5796..6f55466e 100644
--- a/toys/pending/vi.c
+++ b/toys/pending/vi.c
@@ -1324,7 +1324,7 @@ static int run_vi_cmd(char *cmd)
   return 0;
 }
 
-// Page breaks while doing things like ":2,3d" unless we can call this
+
 static void draw_page();
 
 static int get_endline(void)
@@ -1370,43 +1370,39 @@ static int run_ex_cmd(char *cmd)
 
     else if (cmd[1] == 'd') {
       run_vi_cmd("dd");
-      run_vi_cmd("k");
+      cur_up(1, 1, 0);
     } else if (cmd[1] == 'g' || cmd[1] == 'v') {
       char *rgx = xmalloc(strlen(cmd));
-      int el = get_endline(), ln = 0, vorg = ((cmd[1] == 'v') ? REG_NOMATCH : 0);
+      int el = get_endline(), ln = 0, vorg = (cmd[1] == 'v' ? REG_NOMATCH : 0);
       regex_t rgxc;
 
       if (!sscanf(cmd+2, "/%[^/]/%[^\ng]", rgx, cmd+1) ||
           regcomp(&rgxc, rgx, 0)) goto gcleanup;
 
       cmd[0] = ':';
-      
+
       for (; ln < el; ln++) {
         run_vi_cmd("yy");
         if (regexec(&rgxc, TT.yank.data, 0, 0, 0) == vorg) run_ex_cmd(cmd);
-        run_vi_cmd("j");
+        cur_down(1, 1, 0);
       }
 
       // Reset Frame
-      ctrl_f(); draw_page(); ctrl_b();
+      TT.vi_mov_flag |= 0x30000000;
 gcleanup:
       regfree(&rgxc); free(rgx);
-    } 
+    }
 
     // Line Ranges
     else if (cmd[1] >= '0' && cmd[1] <= '9') {
       if (strstr(cmd, ",")) {
-        char *tcmd = xmalloc(strlen(cmd));
-
-        sscanf(cmd, ":%d,%d%[^\n]", &startline, &endline, tcmd+2);
-        cmd = tcmd;
+        sscanf(cmd, ":%d,%d%[^\n]", &startline, &endline, cmd+2);
         ofst = 1;
       } else run_vi_cmd(xmprintf("%dG", atoi(cmd+1)));
     } else if (cmd[1] == '$') run_vi_cmd("G");
     else if (cmd[1] == '%') {
-      startline = 1;
       endline = get_endline();
-      ofst = 1;
+      ofst = startline = 1;
     } else show_error("unknown command '%s'",cmd+1);
 
     if (ofst) {
@@ -1414,17 +1410,15 @@ gcleanup:
 
       draw_page();
       cline = TT.cur_row+1;
-      *(cmd+ofst) = ':';
+      cmd[ofst] = ':';
       run_vi_cmd(xmprintf("%dG", startline));
       for (; startline <= endline; startline++) {
         run_ex_cmd(cmd+ofst);
-        run_vi_cmd("j");
+        cur_down(1, 1, 0);
       }
       run_vi_cmd(xmprintf("%dG", cline));
       // Screen Reset
-      ctrl_f();
-      draw_page();
-      ctrl_b();
+      TT.vi_mov_flag |= 0x30000000;
     }
   }
   return 0;
-- 
2.34.1

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to