Files
taiji/sys/lib/postscript/troff
Russ Cox 535bf48a25 all: remove trailing spaces in text files
To avoid acme making spurious edits in future changes,
edited all text files to remove end-of-line spaces and tabs,
remove trailing blank lines, and add missing final newlines,
using this Go program.

package main

import (
	"bytes"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"regexp"
	"unicode/utf8"
)

var blank = []byte("\n\n")

func main() {
	log.SetPrefix("fixspace: ")
	log.SetFlags(0)

	re := regexp.MustCompile(`(?m)[ \t]+$`)
	filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
		if err != nil {
			log.Print(err)
			return nil
		}
		if info.IsDir() {
			return nil
		}
		old, err := os.ReadFile(path)
		if err != nil {
			return err
		}
		if !utf8.Valid(old) || bytes.ContainsAny(old, "\x00\r") {
			return nil
		}

		// Remove trailing spaces at ends of lines.
		new := re.ReplaceAll(old, nil)

		// Remove trailing blank lines.
		for len(new) > 0 && bytes.HasSuffix(new, blank) {
			new = new[:len(new)-1]
		}
		if len(new) == 1 && new[0] == '\n' {
			new = nil
		}

		// Add newline at end of line if needed.
		if len(new) > 0 && new[len(new)-1] != '\n' {
			new = append(new, '\n')
		}

		if !bytes.Equal(old, new) {
			if err := os.WriteFile(path, new, 0666); err != nil {
				log.Print(err)
				return nil
			}
			fmt.Printf("%s\n", path)
		}
		return nil
	})
}
2025-03-09 08:26:49 -04:00
..
2025-03-01 11:40:04 -05:00
2025-03-09 08:26:49 -04:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00
2025-03-01 11:40:04 -05:00