3// For unexpand the 4 spaces that the typescript compiler outputs into tabs.
4// Not all unexpand commands implement the -t flag (openbsd).
16func xcheckf(err error, format string, args ...any) {
18 log.Fatalf("%s: %s", fmt.Sprintf(format, args...), err)
25 flag.IntVar(&width, "t", 8, "tab width")
28 log.Print("usage: unexpand [-t tabwidth] < input.spaces >output.tabs")
39 r := bufio.NewReader(os.Stdin)
40 w := bufio.NewWriter(os.Stdout)
46 for ; nspace > 0; nspace-- {
47 err := w.WriteByte(' ')
51 write := func(b byte) {
57 b, err := r.ReadByte()
63 if start && b == ' ' {
77 xcheckf(err, "flush output")