Skip to content

Commit

Permalink
Further refactor exec.go:/exec to prepare for bug fix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjkroege committed Jan 14, 2025
1 parent 846e008 commit f6875f1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
104 changes: 56 additions & 48 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, ubuntu-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, macos-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, windows-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, ubuntu-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, windows-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, macos-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.19.x, windows-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

redundant return statement (S1023)

Check failure on line 237 in exec.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, windows-latest)

redundant return statement (S1023)
}

// 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)
Expand All @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions guide
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6875f1

Please sign in to comment.