Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove debug.Printf from scanner #573

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,6 @@ func TestUnbalancedParens(t *testing.T) {
x8A4M3e23mRZ9VrbpMngwcrqNAg== )`
_, err := NewRR(sig)
if err == nil {
t.Fatalf("Failed to detect extra opening brace")
t.Fatalf("failed to detect extra opening brace")
}
}
35 changes: 6 additions & 29 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ package dns

import (
"io"
"log"
"os"
"strconv"
"strings"
)

type debugging bool

const debug debugging = false

func (d debugging) Printf(format string, args ...interface{}) {
if d {
log.Printf(format, args...)
}
}

const maxTok = 2048 // Largest token we can return.
const maxUint16 = 1<<16 - 1

Expand Down Expand Up @@ -127,7 +116,7 @@ func NewRR(s string) (RR, error) {
// See NewRR for more documentation.
func ReadRR(q io.Reader, filename string) (RR, error) {
defttl := &ttlState{defaultTtl, false}
r := <-parseZoneHelper(q, ".", defttl, filename, 1)
r := <-parseZoneHelper(q, ".", filename, defttl, 1)
if r == nil {
return nil, nil
}
Expand Down Expand Up @@ -164,16 +153,16 @@ func ReadRR(q io.Reader, filename string) (RR, error) {
// The text "; this is comment" is returned in Token.Comment. Comments inside the
// RR are discarded. Comments on a line by themselves are discarded too.
func ParseZone(r io.Reader, origin, file string) chan *Token {
return parseZoneHelper(r, origin, nil, file, 10000)
return parseZoneHelper(r, origin, file, nil, 10000)
}

func parseZoneHelper(r io.Reader, origin string, defttl *ttlState, file string, chansize int) chan *Token {
func parseZoneHelper(r io.Reader, origin, file string, defttl *ttlState, chansize int) chan *Token {
t := make(chan *Token, chansize)
go parseZone(r, origin, defttl, file, t, 0)
go parseZone(r, origin, file, defttl, t, 0)
return t
}

func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *Token, include int) {
func parseZone(r io.Reader, origin, f string, defttl *ttlState, t chan *Token, include int) {
defer func() {
if include == 0 {
close(t)
Expand Down Expand Up @@ -305,7 +294,7 @@ func parseZone(r io.Reader, origin string, defttl *ttlState, f string, t chan *T
t <- &Token{Error: &ParseError{f, "too deeply nested $INCLUDE", l}}
return
}
parseZone(r1, neworigin, defttl, l.token, t, include+1)
parseZone(r1, neworigin, l.token, defttl, t, include+1)
st = zExpectOwnerDir
case zExpectDirTTLBl:
if l.value != zBlank {
Expand Down Expand Up @@ -497,14 +486,12 @@ func zlexer(s *scan, c chan lex) {
if stri >= maxTok {
l.token = "token length insufficient for parsing"
l.err = true
debug.Printf("[%+v]", l.token)
c <- l
return
}
if comi >= maxTok {
l.token = "comment length insufficient for parsing"
l.err = true
debug.Printf("[%+v]", l.token)
c <- l
return
}
Expand Down Expand Up @@ -547,7 +534,6 @@ func zlexer(s *scan, c chan lex) {
case "$GENERATE":
l.value = zDirGenerate
}
debug.Printf("[7 %+v]", l.token)
c <- l
} else {
l.value = zString
Expand Down Expand Up @@ -589,7 +575,6 @@ func zlexer(s *scan, c chan lex) {
}
}
}
debug.Printf("[6 %+v]", l.token)
c <- l
}
stri = 0
Expand All @@ -598,7 +583,6 @@ func zlexer(s *scan, c chan lex) {
l.value = zBlank
l.token = " "
l.length = 1
debug.Printf("[5 %+v]", l.token)
c <- l
}
owner = false
Expand All @@ -621,7 +605,6 @@ func zlexer(s *scan, c chan lex) {
l.token = string(str[:stri])
l.tokenUpper = strings.ToUpper(l.token)
l.length = stri
debug.Printf("[4 %+v]", l.token)
c <- l
stri = 0
}
Expand Down Expand Up @@ -659,7 +642,6 @@ func zlexer(s *scan, c chan lex) {
l.tokenUpper = l.token
l.length = 1
l.comment = string(com[:comi])
debug.Printf("[3 %+v %+v]", l.token, l.comment)
c <- l
l.comment = ""
comi = 0
Expand All @@ -685,14 +667,12 @@ func zlexer(s *scan, c chan lex) {
rrtype = true
}
}
debug.Printf("[2 %+v]", l.token)
c <- l
}
l.value = zNewline
l.token = "\n"
l.tokenUpper = l.token
l.length = 1
debug.Printf("[1 %+v]", l.token)
c <- l
stri = 0
commt = false
Expand Down Expand Up @@ -738,7 +718,6 @@ func zlexer(s *scan, c chan lex) {
l.tokenUpper = strings.ToUpper(l.token)
l.length = stri

debug.Printf("[%+v]", l.token)
c <- l
stri = 0
}
Expand Down Expand Up @@ -774,7 +753,6 @@ func zlexer(s *scan, c chan lex) {
l.token = "extra closing brace"
l.tokenUpper = l.token
l.err = true
debug.Printf("[%+v]", l.token)
c <- l
return
}
Expand All @@ -800,7 +778,6 @@ func zlexer(s *scan, c chan lex) {
l.tokenUpper = strings.ToUpper(l.token)
l.length = stri
l.value = zString
debug.Printf("[%+v]", l.token)
c <- l
}
if brace != 0 {
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,11 @@ func TestServerStartStopRace(t *testing.T) {
s := &Server{}
s, _, _, err = RunLocalUDPServerWithFinChan(":0")
if err != nil {
t.Fatalf("Could not start server: %s", err)
t.Fatalf("could not start server: %s", err)
}
go func() {
if err := s.Shutdown(); err != nil {
t.Fatalf("Could not stop server: %s", err)
t.Fatalf("could not stop server: %s", err)
}
}()
}
Expand Down