From f6875f1918fee5bf08d29676d7e6ef7f0ed40121 Mon Sep 17 00:00:00 2001 From: Robert Kroeger Date: Tue, 14 Jan 2025 17:13:50 -0500 Subject: [PATCH] Further refactor exec.go:/exec to prepare for bug fix Refactor exec.go/exect to fix chord reporting bug. Note: it would appear from this change that a tiny change (setting r to not empty in delegateExection) is all that was required to actually fix the bug but wait for a subsequent CL that contains unit tests. --- exec.go | 104 ++++++++++++++++++++++++++++++-------------------------- guide | 1 + 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/exec.go b/exec.go index 977c7f52..75b02589 100644 --- a/exec.go +++ b/exec.go @@ -89,7 +89,7 @@ var globalexectab = []Exectab{ var wsre = regexp.MustCompile("[ \t\n]+") // TODO(rjk): Exectab is sorted. Consider using a binary search -func lookup(r string, exectab []Exectab ) *Exectab { +func lookup(r string, exectab []Exectab) *Exectab { r = wsre.ReplaceAllString(r, " ") r = strings.TrimLeft(r, " ") words := strings.SplitN(r, " ", 2) @@ -183,10 +183,62 @@ func expandRuneOffsetsToWord(t *Text, q0 int, q1 int) (int, int) { return q0, q1 } +// delegateExecution handles the situation where an external command is +// using the event file to control the operation of Edwood via the +// filesystem. +func delegateExecution(t *Text, e *Exectab, aq0, aq1, q0, q1 int, argt *Text) { + var r []rune + + f := 0 + if e != nil { + f |= 1 + } + if q0 != aq0 || q1 != aq1 { + r = make([]rune, aq1-aq0) + t.file.Read(aq0, r) + f |= 2 + } + a, aa := getarg(argt, true, true) + if a != "" { + if len(a) > EVENTSIZE { // too big; too bad + warning(nil, "argument string too long\n") + return + } + f |= 8 + } + c := 'x' + if t.what == Body { + c = 'X' + } + n := aq1 - aq0 + if n <= EVENTSIZE { + t.w.Eventf("%c%d %d %d %d %v\n", c, aq0, aq1, f, n, string(r)) + } else { + t.w.Eventf("%c%d %d %d 0 \n", c, aq0, aq1, f) + } + if q0 != aq0 || q1 != aq1 { + n = q1 - q0 + r = make([]rune, n) + t.file.Read(q0, r) + if n <= EVENTSIZE { + t.w.Eventf("%c%d %d 0 %d %v\n", c, q0, q1, n, string(r)) + } else { + t.w.Eventf("%c%d %d 0 0 \n", c, q0, q1) + } + } + if a != "" { + t.w.Eventf("%c0 0 0 %d %v\n", c, utf8.RuneCountInString(a), a) + if aa != "" { + t.w.Eventf("%c0 0 0 %d %v\n", c, utf8.RuneCountInString(aa), aa) + } else { + t.w.Eventf("%c0 0 0 0 \n", c) + } + } + return +} + // execute must run with an existing lock on t's Window func execute(t *Text, aq0 int, aq1 int, external bool, argt *Text) { - var n, f int - q0, q1 := expandRuneOffsetsToWord(t, aq0, aq1) r := make([]rune, q1-q0) @@ -196,51 +248,7 @@ func execute(t *Text, aq0 int, aq1 int, external bool, argt *Text) { // Send commands to external client if the target window's event file is // in use. if !external && t.w != nil && t.w.nopen[QWevent] > 0 { - f = 0 - if e != nil { - f |= 1 - } - if q0 != aq0 || q1 != aq1 { - r = make([]rune, aq1-aq0) - t.file.Read(aq0, r) - f |= 2 - } - a, aa := getarg(argt, true, true) - if a != "" { - if len(a) > EVENTSIZE { // too big; too bad - warning(nil, "argument string too long\n") - return - } - f |= 8 - } - c := 'x' - if t.what == Body { - c = 'X' - } - n = aq1 - aq0 - if n <= EVENTSIZE { - t.w.Eventf("%c%d %d %d %d %v\n", c, aq0, aq1, f, n, string(r)) - } else { - t.w.Eventf("%c%d %d %d 0 \n", c, aq0, aq1, f) - } - if q0 != aq0 || q1 != aq1 { - n = q1 - q0 - r := make([]rune, n) - t.file.Read(q0, r) - if n <= EVENTSIZE { - t.w.Eventf("%c%d %d 0 %d %v\n", c, q0, q1, n, string(r)) - } else { - t.w.Eventf("%c%d %d 0 0 \n", c, q0, q1) - } - } - if a != "" { - t.w.Eventf("%c0 0 0 %d %v\n", c, utf8.RuneCountInString(a), a) - if aa != "" { - t.w.Eventf("%c0 0 0 %d %v\n", c, utf8.RuneCountInString(aa), aa) - } else { - t.w.Eventf("%c0 0 0 0 \n", c) - } - } + delegateExecution(t, e, aq0, aq1, q0, q1, argt) return } diff --git a/guide b/guide index 0b898d5e..7b1ed549 100644 --- a/guide +++ b/guide @@ -7,6 +7,7 @@ X:edwood/.*\.go: w {go build -tags debug} ./testedwood.sh +./testacme.sh {go test -covermode=count -coverprofile=count.out} go tool cover -html=count.out