Debian Codegraph @

debian/local/update-fonts-scale

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 # $Id: update-fonts-scale 189 2005-06-11 00:04:27Z branden $
4
5 # This program generates fonts.scale files for X font directories; see
6 # mkfontdir(1x) for a description of the format of fonts.scale files.
7
8 # Copyright 1999-2002, 2004 Branden Robinson.
9 # Copyright 2006 Steve Langasek.
10 # Licensed under the GNU General Public License, version 2. See the file
11 # /usr/share/common-licenses/GPL or <https://www.gnu.org/copyleft/gpl.txt>.
12
13 PROGNAME=${0##*/}
14
15 # Query the terminal to establish a default number of columns to use for
16 # displaying messages to the user. This is used only as a fallback in the event
17 # the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the
18 # script is running, and this cannot, only being calculated once.)
19 DEFCOLUMNS=$(sttyscip-shell system . . stty. size 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. '{print $2}') || truescip-shell system . . true.
20 if ! exprscip-shell system . . expr. "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
21 DEFCOLUMNS=80
22 fi
23
24 # Display a message, wrapping lines at the terminal width.
25 messagescip-shell shell xfonts-utils 1:7.7+7 message(). () {
26 echoscip-shell system . . echo. "$*" | fmtscip-shell system . . fmt. -t -w ${COLUMNS:-$DEFCOLUMNS}
27 }
28
29 # Display a debugging message.
30 tracescip-shell shell xfonts-utils 1:7.7+7 trace(). () {
31 if [scip-shell system . . `[`. -n "$DEBUG" ]; then
32 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "note: $*" >&2
33 fi
34 }
35
36 # Display a warning message.
37 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). () {
38 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "warning: $*" >&2
39 }
40
41 # Display an error message and exit.
42 diescip-shell shell xfonts-utils 1:7.7+7 die(). () {
43 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "fatal error: $*" >&2
44 exit 1
45 }
46
47 # Display a usage message.
48 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). () {
49 if [scip-shell system . . `[`. -n "$*" ]; then
50 messagescip-shell shell xfonts-utils 1:7.7+7 message(). "usage error: $*"
51 fi
52 catscip-shell system . . cat. <<EOF
53 Usage: $PROGNAME DIRECTORY ...
54 $PROGNAME { -h | --help }
55 This program combines scalable X font information from several packages into a
56 single file that is placed in each specified X font directory DIRECTORY. This
57 utility is primarily useful to Debian package maintainer scripts. See
58 update-fonts-scale(8) for more information.
59 Options:
60 -h, --help display this usage message and exit
61 EOF
62 }
63
64 X11R7_LAYOUT=
65
66 # Validate arguments.
67 case "$1" in
68 -h|--help)
69 usagescip-shell shell xfonts-utils 1:7.7+7 usage().
70 exit 0
71 ;;
72 -7|--x11r7-layout)
73 X11R7_LAYOUT=true
74 shift
75 ;;
76 esac
77
78 case "$1" in
79 -*)
80 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "unrecognized option" >&2
81 exit 2
82 ;;
83 esac
84
85 if [scip-shell system . . `[`. $# -eq 0 ]; then
86 usagescip-shell shell xfonts-utils 1:7.7+7 usage(). "one or more font directories must be specified" >&2
87 exit 2
88 fi
89
90 while [scip-shell system . . `[`. -n "$1" ]; do
91 # Try to be clever about the argument; were we given an absolute path?
92 if exprscip-shell system . . expr. "$1" : "/.*" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
93 # Yes; an absolute path to an X font directory was provided.
94 X11R7DIR=$1
95 ETCDIR=/etc/X11/fonts/${X11R7DIR##*/}
96 ETC7DIR=/etc/X11/fonts/X11R7/${X11R7DIR##*/}
97 if [scip-shell system . . `[`. "$X11R7DIR" = "$ETCDIR" ] || [scip-shell system . . `[`. "$X11R7DIR" = "$ETC7DIR" ]; then
98 # We were given an /etc directory as an argument.
99 diescip-shell shell xfonts-utils 1:7.7+7 die(). "path to X font directory must be used"
100 else
101 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "absolute path $X11R7DIR was provided"
102 fi
103 else
104 # No; a relative path was provided -- assume we were given just the
105 # basename.
106 X11R7DIR=/usr/share/fonts/X11/$1
107 ETCDIR=/etc/X11/fonts/$1
108 ETC7DIR=/etc/X11/fonts/X11R7/$1
109 fi
110
111 shift
112
113 # Confirm that the directories to be operated on exist.
114 VALIDSRC=
115 if [scip-shell system . . `[`. -d "$ETCDIR" ]; then
116 VALIDSRC=yes
117 else
118 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$ETCDIR does not exist or is not a directory"
119 fi
120 if [scip-shell system . . `[`. -d "$ETC7DIR" ]; then
121 VALIDSRC=yes
122 else
123 if [scip-shell system . . `[`. -n "$X11R7_LAYOUT" ]; then
124 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$ETC7DIR does not exist or is not a directory"
125 fi
126 fi
127
128 VALIDDEST=
129 if [scip-shell system . . `[`. -d "$X11R7DIR" ]; then
130 VALIDDEST=yes
131 else
132 warnscip-shell shell xfonts-utils 1:7.7+7 warn(). "$X11R7DIR does not exist or is not a directory"
133 fi
134
135 if [scip-shell system . . `[`. -z "$VALIDSRC" ] || [scip-shell system . . `[`. -z "$VALIDDEST" ]; then
136 continue
137 fi
138
139 # Are there any files to process?
140 if [scip-shell system . . `[`. "$(echoscip-shell system . . echo. "$ETCDIR"/*.scale "$ETC7DIR"/*.scale)" != "$ETCDIR/*.scale $ETC7DIR/*.scale" ]
141 then
142 if [scip-shell system . . `[`. -n "$X11R7DIR" ] && [scip-shell system . . `[`. -d "$X11R7DIR" ]; then
143 for SCALEFILE in "$ETCDIR"/*.scale "$ETC7DIR"/*.scale; do
144 [scip-shell system . . `[`. -e "$SCALEFILE" ] || continue
145 # Only write fonts to the .scale file that actually exist, so
146 # that removed-but-not-purged scalable font packages do not
147 # register nonexistent fonts; this has the desirable side effect
148 # that the count at the top of the file is also omitted.
149 #
150 # XXX: This technique will be tricked into yielding false
151 # negatives if the font filename has whitespace in it.
152 while read FONTFILE FONTNAME; do
153 if [scip-shell system . . `[`. -f "$X11R7DIR/$FONTFILE" ]; then
154 echoscip-shell system . . echo. "$FONTFILE $FONTNAME" \
155 >>"$X11R7DIR/fonts.scale.update-tmp"
156 else
157 trscip-shell shell xfonts-utils 1:7.7+7 trace().acescip-shell shell xfonts-utils 1:7.7+7 trace(). "$SCALEFILE references nonexistent font file" \
158 "$FONTFILE; skipping"
159 fi
160 done <"$SCALEFILE"
161 done
162 if [scip-shell system . . `[`. -e "$X11R7DIR/fonts.scale.update-tmp" ]; then
163 # Write the new scale file to a temporary location in case we
164 # are interrupted. Write the new count to the top of file. Use
165 # cat and pipe to wc so wc doesn't report the filename.
166 catscip-shell system . . cat. "$X11R7DIR/fonts.scale.update-tmp" \
167 | wcscip-shell system . . wc. -l | trscip-shell system . . tr. -d '[:blank:]' \
168 >"$X11R7DIR/fonts.scale.update-new"
169 catscip-shell system . . cat. "$X11R7DIR/fonts.scale.update-tmp" \
170 >>"$X11R7DIR/fonts.scale.update-new"
171 mvscip-shell system . . mv. "$X11R7DIR/fonts.scale.update-new" "$X11R7DIR/fonts.scale"
172 rmscip-shell system . . rm. "$X11R7DIR/fonts.scale.update-tmp"
173 else
174 # No font in the processed *.scale files was in the current
175 # directory, so remove fonts.scale.
176 rmscip-shell system . . rm. -f "$X11R7DIR/fonts.scale"
177 fi
178 fi
179 else
180 if [scip-shell system . . `[`. -n "$X11R7DIR" ] && [scip-shell system . . `[`. -d "$X11R7DIR" ]; then
181 # No files to process; remove any fonts.scale file already in the
182 # font directory.
183 rmscip-shell system . . rm. -f "$X11R7DIR/fonts.scale"
184 # Remove the font directory if it is empty.
185 rmdirscip-shell system . . rmdir. "$X11R7DIR" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true.
186 fi
187 fi
188 done
189
190 exit 0
191
192 # vim:set ai et sts=4 sw=4 tw=80: