Commit 08f41cbd authored by Jacob Vosmaer's avatar Jacob Vosmaer

Think it works now

parent de97637a
......@@ -29,7 +29,6 @@ func main() {
}
func stripTrailingWhitespace(id int, name string) {
log.Printf("event ID: %d, name: %q", id, name)
w, err := acme.Open(id, nil)
if err != nil {
log.Print(err)
......@@ -39,21 +38,20 @@ func stripTrailingWhitespace(id int, name string) {
oldContent, err := ioutil.ReadFile(name)
if err != nil {
//log.Print(err)
log.Print(err)
return
}
newContent := make([]byte, 0, len(oldContent))
scanner := bufio.NewScanner(bytes.NewReader(oldContent))
lastChanged := 0
line := 0
line := 1
for scanner.Scan() {
newLineContent := bytes.TrimRight(scanner.Bytes(), " ")
if !bytes.Equal(newLineContent, scanner.Bytes()) {
lastChanged = line
}
newContent = append(newContent, newLineContent...)
newContent = append(newContent, '\n')
newContent = append(newContent, append(newLineContent, '\n')...)
line++
}
if scanner.Err() != nil {
......@@ -65,28 +63,13 @@ func stripTrailingWhitespace(id int, name string) {
return
}
w.Write("ctl", []byte("addr=dot"))
q0, q1, err := w.ReadAddr()
if err != nil {
log.Print(err)
return
}
log.Printf("q0,q1 %d,%d", q0, q1)
for _, cmd := range []string{"mark", "nomark"} { //, "addr=dot"} {
for _, cmd := range []string{"mark", "nomark"} {
if _, err := w.Write("ctl", []byte(cmd)); err != nil {
log.Printf("write ctl: %v", err)
return
}
}
q0, q1, err = w.ReadAddr()
if err != nil {
log.Print(err)
return
}
log.Printf("q0,q1 %d,%d", q0, q1)
if err := w.Addr(","); err != nil {
log.Print(err)
return
......@@ -97,19 +80,15 @@ func stripTrailingWhitespace(id int, name string) {
return
}
log.Print(lastChanged)
if err := w.Addr("%d,0", lastChanged); err != nil {
if err := w.Addr("%d/$/", lastChanged-1); err != nil {
log.Print(err)
return
}
if _, err := w.Write("ctl", []byte("dot=addr")); err != nil {
log.Print(err)
return
}
if _, err := w.Write("ctl", []byte("show")); err != nil {
log.Print(err)
return
for _, cmd := range []string{"dot=addr", "show"} {
if _, err := w.Write("ctl", []byte(cmd)); err != nil {
log.Printf("write ctl: %v", err)
return
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment