Skip to content

Commit

Permalink
Fix issue #23.
Browse files Browse the repository at this point in the history
Parse written events correctly.  These don't fit the specification
of events in "man acme", but do match the C code.
  • Loading branch information
paul-lalonde committed Apr 2, 2018
1 parent cd69e43 commit 7006db5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 69 deletions.
3 changes: 1 addition & 2 deletions look.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,10 @@ func expandfile(t *Text, q0 int, q1 int, e *Expand) (success bool) {
}

func access(name string) bool {
f, err := os.Open(name)
_, err := os.Stat(name)
if err != nil {
return false
}
f.Close()
return true
}

Expand Down
10 changes: 8 additions & 2 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,12 @@ func (t *Text) DirName(name string) string {
}
b := make([]rune, t.w.tag.file.b.Nc())
t.w.tag.file.b.Read(0, b)
spl := strings.SplitN(string(b), " ", 1)[0]
return filepath.Clean(filepath.Dir(spl) + string(filepath.Separator) + name)
spl := strings.SplitN(string(b), " ", 2)[0]
if !strings.HasSuffix(spl, string(filepath.Separator)) {
spl = filepath.Dir(spl)
}
spl = filepath.Clean(spl + string(filepath.Separator) + name)
fmt.Println("Full path is", spl)
return spl

}
76 changes: 11 additions & 65 deletions xfid.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ forloop:
func xfideventwrite(x *Xfid, w *Window) {
var (
fc plan9.Fcall
m, n int
err error
t *Text
q0, q1 int
Expand All @@ -777,79 +776,25 @@ func xfideventwrite(x *Xfid, w *Window) {
text, which may itself contain newlines.
%c%c%d %d %d %d %s\n
*/
events := string(x.fcall.Data)
n = 0
for events != "" {
lines := strings.Split(string(x.fcall.Data), "\n")
for _, events := range lines {
if events == "" { continue }
w.owner = int(events[0])
n++
c := events[1]
n++
events = events[2:]

for events[0] == ' ' {
events = events[1:]
n++
}
e := strings.SplitN(events, " ", 2)
n += len(e[0]) + 1
num, err = strconv.ParseInt(e[0], 10, 32)
words := strings.Split(wsre.ReplaceAllString(events[2:], " "), " ")
num, err = strconv.ParseInt(words[0], 10, 32)
if err != nil {
err = Ebadevent
break
}
q0 = int(num)
events = e[1]

for events[0] == ' ' {
events = events[1:]
n++
}
e = strings.SplitN(events, " ", 2)
n += len(e[0]) + 1
num, err = strconv.ParseInt(e[0], 10, 32)
num, err = strconv.ParseInt(words[1], 10, 32)
if err != nil {
err = Ebadevent
break
}
q1 = int(num)
events = e[1]

for events[0] == ' ' {
events = events[1:]
n++
}
n += len(e[0]) + 1
e = strings.SplitN(events, " ", 2)
num, err = strconv.ParseInt(e[0], 10, 32)
if err != nil {
err = Ebadevent
break
}
//flag := int(num)
events = e[1]

for events[0] == ' ' {
events = events[1:]
n++
}
n += len(e[0]) + 1
e = strings.SplitN(events, " ", 2)
num, err = strconv.ParseInt(e[0], 10, 32)
if err != nil {
err = Ebadevent
break
}
m = int(num)
events = e[1]

for events[0] == ' ' {
events = events[1:]
n++
}

if m != len(x.fcall.Data)-n {
panic("mis-shaped event")
}
if 'a' <= c && c <= 'z' {
t = &w.tag
} else {
Expand All @@ -867,11 +812,11 @@ func xfideventwrite(x *Xfid, w *Window) {

row.lk.Lock() // just like mousethread
switch c {
case 'x':
case 'x': fallthrough
case 'X':
execute(t, q0, q1, true, nil)
break
case 'l':
case 'l': fallthrough
case 'L':
look3(t, q0, q1, true)
break
Expand All @@ -883,9 +828,10 @@ func xfideventwrite(x *Xfid, w *Window) {
}

if err != nil {
n = 0
fc.Count = 0
} else {
fc.Count = uint32(len(x.fcall.Data))
}
fc.Count = uint32(n)
respond(x, &fc, err)
return
}
Expand Down

0 comments on commit 7006db5

Please sign in to comment.