]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-log/main.go
Raise copyright years
[nncp.git] / src / cmd / nncp-log / main.go
index 74062610aa93cb8db189847aa023c86d9617421c..dbe03b8d20bbbba943ea29ec6ddf7031f8bfa65b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -19,13 +19,14 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package main
 
 import (
-       "bufio"
        "flag"
        "fmt"
+       "io"
        "log"
        "os"
 
-       "go.cypherpunks.ru/nncp/v5"
+       "go.cypherpunks.ru/nncp/v8"
+       "go.cypherpunks.ru/recfile"
 )
 
 func usage() {
@@ -43,6 +44,7 @@ func main() {
                version  = flag.Bool("version", false, "Print version information")
                warranty = flag.Bool("warranty", false, "Print warranty information")
        )
+       log.SetFlags(log.Lshortfile)
        flag.Usage = usage
        flag.Parse()
        if *warranty {
@@ -63,15 +65,22 @@ func main() {
        if err != nil {
                log.Fatalln("Can not open log:", err)
        }
-       scanner := bufio.NewScanner(fd)
-       for scanner.Scan() {
-               t := scanner.Text()
+       r := recfile.NewReader(fd)
+       for {
+               le, err := r.NextMap()
+               if err != nil {
+                       if err == io.EOF {
+                               break
+                       }
+                       log.Fatalln("Can not read log:", err)
+               }
                if *debug {
-                       fmt.Println(t)
+                       fmt.Println(le)
                }
-               fmt.Println(ctx.Humanize(t))
-       }
-       if err = scanner.Err(); err != nil {
-               log.Fatalln("Can not read log:", err)
+               s, err := ctx.Humanize(le)
+               if err != nil {
+                       s = fmt.Sprintf("Can not humanize: %s\n%s", err, le)
+               }
+               fmt.Println(s)
        }
 }