4// For unexpand the 4 spaces that the typescript compiler outputs into tabs.
5// Not all unexpand commands implement the -t flag (openbsd).
17func xcheckf(err error, format string, args ...any) {
19 log.Fatalf("%s: %s", fmt.Sprintf(format, args...), err)
26 flag.IntVar(&width, "t", 8, "tab width")
29 log.Print("usage: unexpand [-t tabwidth] < input.spaces >output.tabs")
40 r := bufio.NewReader(os.Stdin)
41 w := bufio.NewWriter(os.Stdout)
47 for ; nspace > 0; nspace-- {
48 err := w.WriteByte(' ')
52 write := func(b byte) {
58 b, err := r.ReadByte()
64 if start && b == ' ' {
78 xcheckf(err, "flush output")