-
Notifications
You must be signed in to change notification settings - Fork 0
/
chkRecord.go
82 lines (73 loc) · 1.77 KB
/
chkRecord.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package cmd
import (
"github.com/paulmatencio/s3c/gLog"
"github.com/paulmatencio/s3c/utils"
"github.com/spf13/cobra"
"io"
"path/filepath"
"strconv"
)
// readConvalCmd represents the readConval command
var (
ST33 bool
rl int
chKRecordCmd = &cobra.Command{
Use: "chkRecord",
Short: "Command to check valid record of VB file",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
readVB(cmd,args)
},
}
)
func initVbFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&ifile,"input-file","i","","the VB data file ")
cmd.Flags().StringVarP(&idir,"input-directory","d","","the name of the directory")
cmd.Flags().BoolVarP(&ST33,"st33","s",true,"Input format is ST33")
}
func init() {
RootCmd.AddCommand(chKRecordCmd)
initVbFlags(chKRecordCmd)
}
// Read VB file
func readVB(cmd *cobra.Command, args []string) {
if len(ifile) == 0 {
gLog.Info.Printf("%s",missingInputFile)
return
}
if len(idir) == 0 {
gLog.Info.Printf("%s",missingInputFolder)
return
}
n:= 0
bad:= 0
if vb,err := utils.NewVBRecord(filepath.Join(idir,ifile)); err == nil {
for {
b,err:= vb.Read()
if ST33 {
rl = 0
if len(b) > 5 {
RL := utils.Ebc2asci(b[0:5])
rl, _ = strconv.Atoi(string(RL[0:5]))
if len(b) != rl {
gLog.Error.Printf("Wrong ST33 record - Record lengths differ rdw=%d not equal size of the record : %d", len(b), rl)
bad++
}
}
}
gLog.Trace.Printf("Previous address : X'%x' Current address : X'%x' - Record length: %d %d\n",vb.Previous,vb.Current,len(b),rl)
if err == io.EOF {
vb.File.Close()
gLog.Info.Printf("Total number of records: %d %d",n,bad)
break
} else {
n++
/* e:= []byte("\n")
vb.OutFile.Write(append(b,e[0]))
*/
}
}
} else {
gLog.Error.Printf("%v %v ",err)
}
}