-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddCrToHtml.go
72 lines (61 loc) · 1.37 KB
/
AddCrToHtml.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
package main
import (
"fmt"
"os"
"strings"
)
func main () {
numArgs := len(os.Args)
if numArgs < 2 {
fmt.Printf("insufficient arguments\n usage is: \"InsCr file\"\n")
os.Exit(1)
}
infilNam := os.Args[1]
infil, err := os.Open(infilNam)
if err != nil {
fmt.Printf("error opening input file! %v\n", err)
os.Exit(1)
}
defer infil.Close()
idx := strings.Index(infilNam, ".")
// fmt.Printf("outfil: %s %d\n", string(infilNam[:idx]), idx)
outfilNam := infilNam[:idx] + "_cr.html"
fmt.Printf("outfil name: %s\n", outfilNam)
outfil, err := os.Create(outfilNam)
if err != nil {
fmt.Printf("error opening input file! %v\n", err)
os.Exit(1)
}
defer outfil.Close()
fileinfo, err := infil.Stat()
if err != nil {
fmt.Printf("error getting input file stat! %v\n", err)
os.Exit(1)
}
fmt.Printf("file size: %d\n", fileinfo.Size())
inByte := make([]byte, fileinfo.Size())
_, err = infil.Read(inByte)
if err != nil {
fmt.Printf("error reading input file! %v\n", err)
os.Exit(1)
}
fmt.Printf("input: %s\n", string(inByte[:15]))
outByte := make([]byte, fileinfo.Size() + 1024)
i2 := 0
for i:=0; i< len(inByte); i++ {
outByte[i2] = inByte[i]
i2++
if inByte[i] == '}' {
outByte[i2] = '\n'
i2++
}
if inByte[i] == '>' {
if inByte[i-1] != ' ' {
outByte[i2] = '\n'
i2++
}
}
}
outfil.Write(outByte[:i2])
fmt.Println("success!")
}