From f14b185dfe1fed4fdc951b91f3338359538c4832 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sun, 26 Mar 2023 18:31:10 +0200 Subject: Add option to specify [START,END) lines --- main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index e4d2027..55e7989 100644 --- a/main.go +++ b/main.go @@ -90,11 +90,11 @@ func main() { log.Printf("INFO: generating work\n") nextLine, readAll := workGenerator(ctx, opts, fp, questionCh) if !readAll { - warn := fmt.Sprintf("only read up until line %d", nextLine) - if opts.NextLine != 0 { - warn += fmt.Sprintf(" (line %d relative to start)", nextLine-opts.NextLine) + notice := fmt.Sprintf("only read up until line %d", nextLine) + if opts.StartLineInclusive != 0 { + notice += fmt.Sprintf(" (line %d relative to start)", nextLine-opts.StartLineInclusive) } - log.Printf("NOTICE: %s\n", warn) + log.Printf("NOTICE: %s\n", notice) } } @@ -218,18 +218,18 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest scanner.Buffer(buf, opts.MaxFileBuffer*1024*1024) nextLine := int64(0) - if opts.NextLine > nextLine { + if opts.StartLineInclusive > nextLine { for scanner.Scan() { + nextLine++ select { case <-ctx.Done(): return nextLine, false default: } - if nextLine+1 == opts.NextLine { + if nextLine == opts.StartLineInclusive { break } - nextLine++ } } @@ -238,8 +238,12 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest startTime := time.Now().Unix() latestTime := startTime - latestCount := opts.NextLine + latestCount := opts.StartLineInclusive for scanner.Scan() { + if opts.EndLineExclusive > 0 && nextLine == opts.EndLineExclusive { + break + } + select { case <-ctx.Done(): return nextLine, false @@ -247,7 +251,7 @@ func workGenerator(ctx context.Context, opts options.Options, fp *os.File, quest now := time.Now().Unix() log.Printf("INFO: currently %.1f sites/s, %.1f sites/s since start, at line %d\n", float64(nextLine-latestCount)/float64(now-latestTime), - float64(nextLine-opts.NextLine)/float64(now-startTime), + float64(nextLine-opts.StartLineInclusive)/float64(now-startTime), nextLine, ) -- cgit v1.2.3