Files
taiji/sys/lib/ghostscript/showchar.ps
T
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

94 lines
2.9 KiB
PostScript
Executable File

% Copyright (C) 1993, 1994, 1996 Aladdin Enterprises. All rights reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
% $Id: showchar.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
% showchar.ps
% Show the outline and rasterized forms of a character.
/F where { pop } { /F /Times-Roman def } ifelse
/P where { pop } { /P 16 def } ifelse
/Rx where { pop } { /Rx 100 def } ifelse
/Ry where { pop } { /Ry 100 def } ifelse
/Cs where { pop } { /Cs (M) def } ifelse
/Pr where { pop } { /Pr false def } ifelse
/Delay where { pop } { /Delay 0 def } ifelse
0 setgray
(markpath.ps) runlibfile
(markhint.ps) runlibfile
/mmx [1 0 0 1 0 0] def
/getpath % - getpath <pathproc>
{ [
{ /moveto cvx } { /lineto cvx } { /curveto cvx } { /closepath cvx }
pathforall
] cvx
} def
/bitselectfont % <fontname> <scale> bitselectfont -
{ exch findfont exch scalefont setfont
% Compute the bounding box in device coordinates.
gsave [Rx 72 div 0 0 Ry 72 div 0 0] setmatrix
currentfont /FontMatrix get concat
currentfont /FontBBox get aload pop
transform ceiling cvi /ury exch def ceiling cvi /urx exch def
transform floor cvi /lly exch def floor cvi /llx exch def
/bbx urx llx sub def /bby ury lly sub def
grestore
} def
/bitshow % <string> bitshow -
{ /S exch def gsave
/W bbx 8 add 7 or 1 add def
/H bby 8 add def
/buf W 8 idiv string def
/M [Rx 72 div 0 0 Ry -72 div 4 llx sub H 4 sub] def
M W H <ff 00> makeimagedevice
/dev exch def
gsave dev setdevice
newpath 0 lly idtransform moveto
0 setgray
gsave
/hpath S false charpath getpath def
grestore
S show grestore
20 20 translate
50000 Rx Ry .max P mul div dup scale
0.7 setgray
0 W H true M
{ dup 1 add exch dev exch buf copyscanlines
} imagemask pop
0 setlinewidth
gsave 0.5 1 0.5 setrgbcolor hpath exec mmx markpath grestore
0 0.5 1 setrgbcolor hpath exec stroke
% Show the hints for Type 1 fonts also.
currentfont /FontType get 1 eq
{ gsave 1 0 0 setrgbcolor
0 lly M idtransform translate
currentfont /FontMatrix get
dup Pr markfonthints
currentfont /Encoding get S 0 get get exch Pr markcharhints
grestore
}
if
} def
F P bitselectfont
/S1 1 string def
Cs
{ /C exch def
currentfont /Encoding get C get /.notdef ne
{ save S1 0 C put S1 bitshow
showpage restore
} if
} forall
quit