-
Notifications
You must be signed in to change notification settings - Fork 0
/
guj2dev.go
55 lines (49 loc) · 833 Bytes
/
guj2dev.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
package main
import (
"bufio"
"flag"
"fmt"
"os"
)
func cvt(in, out *os.File) {
guj2dev := 0xa80 - 0x900
i := bufio.NewReader(in)
o := bufio.NewWriter(out)
for {
r, _, err := i.ReadRune()
if err != nil {
o.Flush()
return
}
if rune(0x0a80) <= r && r <= rune(0xAFF) {
r = rune(int(r) - guj2dev)
}
_,err = o.WriteRune(r)
}
}
func errExit(msg string) {
fmt.Fprintf(os.Stderr, "%s", msg)
os.Exit(1)
}
func usage() {
errExit("Usage: guj2dev input output\n")
}
func main() {
flag.Parse()
if flag.NArg() < 2 {
usage()
}
input := flag.Arg(0)
output := flag.Arg(1)
in, err := os.Open(input)
if err != nil {
errExit(input + ": " + err.Error())
}
defer in.Close()
out, err := os.Create(flag.Arg(1))
if err != nil {
errExit(output + ": " + err.Error())
}
defer out.Close()
cvt(in, out)
}