Debian Codegraph @

texmf-dist/source/generic/tex4ht/update-htfonts

raw
1 #!/bin/sh
2 # $Id: update-htfonts 1343 2023-06-18 14:48:55Z karl $
3 # Update TeX4ht font files (.htf). See ./Makefile for invocations.
4 # Public domain. Originally written by Karl Berry, 2022.
5
6 # don't bother with real option parsing.
7 if test $# -ne 3; then
8 cat <<END_USAGE
9 Usage: $0 [ diff | update ] HTF-DEVDIR HTF-INSTDIR
10 END_USAGE
11 exit 1
12 fi
13
14 verbose=true
15 prg=`basename $0`
16 cp="cp -pv"
17 mkdir="mkdir -v"
18 svn=svn
19
20 if test x"$1" = xdiff; then
21 shift
22 do_updates=false
23 cp="echo would $cp"
24 mkdir="echo would $mkdir"
25 svn="echo would $svn"
26 elif test x"$1" = xupdate; then
27 shift
28 do_updates=true
29 else
30 echo "$0: first arg must be \`diff' or \`update', not: $1" >&2
31 exit 1
32 fi
33
34 devdir=$1
35 instdir=$2
36 tmpdir=/tmp/htdif.d # prefix
37 rm -rf $tmpdir; mkdir $tmpdir
38
39 if test ! -d "$devdir"; then
40 echo "$0: devdir not a directory: $devdir" >&2
41 exit 1
42 fi
43 if test ! -d "$instdir"; then
44 echo "$0: instdir not a directory: $instdir" >&2
45 exit 1
46 fi
47
48
49 # Function to copy SRC to DEST, or fail. Just calls $cp.
50 #
51 copy_file () {
52 src=$1; dest=$2
53 #
54 if $cp "$src" "$dest"; then :; else
55 echo "$0: copy ($cp) failed: $src -> $dest" >&2
56 exit 1
57 fi
58 }
59
60 # Function to compare SRC to DEST. Return zero if equivalent,
61 # nonzero if different (or DEST does not exist, etc.).
62 #
63 # Remove a timestamp string from both files for comparison:
64 # YYYY-MM-DD-HH:MM or just YYYY-MM-DD
65 #
66 htf_same () {
67 src=$1; dest=$2;
68 #
69 src_filtered=$tmpdir/s`basename "$src"`
70 dest_filtered=$tmpdir/d`basename "$dest"`
71 #
72 sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \
73 $src >$src_filtered || exit 1
74 sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \
75 $dest >$dest_filtered || exit 1
76 cmp -s "$src_filtered" "$dest_filtered"
77 }
78
79 # Iterate through all files in the dev directory.
80 echo "$prg: comparing $devdir"
81 echo "$prg: to $instdir"
82 >$tmpdir/0 # accumulate diffs here
83 #
84 find "$devdir" -type f -print | sort | while read devf; do
85 instf=`echo "$devf" | sed "s,^$devdir/,$instdir/,"`
86 #echo "$devf" | grep ec-mlm >/dev/null &&
87 #$verbose && echo "considering $devf -> $instf"
88
89 if test -r "$instf"; then
90 # we have a file in both directories; see if they are the same (enough).
91 if htf_same "$devf" "$instf"; then
92 : # $verbose && echo "`basename \"$devf\"`: same ($devf == $instf)"
93 else
94 $verbose && echo "`basename \"$devf\"`: diff ($devf != $instf)"
95 # save diff from (older) DEST to newer (SRC).
96 diff -u0 "$dest" "$src" >>$tmpdir/0
97 #
98 copy_file "$devf" "$instf"
99 fi
100
101 else
102 # no destination file. see if we have the containing directory.
103 destdirf=`dirname "$instf"`
104 if test -d "$destdirf"; then
105 # have directory, so add file.
106 $verbose && echo "newfile ($devf -> $instf)"
107 copy_file "$devf" "$instf"
108 $svn add "$instf" || exit 1
109 else
110 # don't even have directory. create it, then copy file.
111 $mkdir "$destdirf"
112 $verbose && echo "newdir ($devf -> $destdirf)"
113 if test ! -d "$destdirf"; then
114 echo "$0: could not make dest dir: $destdirf (for $devf->$instf)" >&2
115 exit 1
116 fi
117 $svn add "$destdirf" || exit 1
118 copy_file "$devf" "$instf"
119 $svn add "$instf" || exit 1
120 fi
121 fi
122 done
123
124 # check for extra files in $instdir
125 (cd "$devdir" && find . -type f -print | sort) >$tmpdir/devdir || exit 1
126 (cd "$instdir" && find . -type f -print | sort) >$tmpdir/instdir || exit 1
127
128 echo "$prg: files in devdir and not in instdir (should be empty):"
129 comm -23 $tmpdir/devdir $tmpdir/instdir
130
131 echo "$prg: files in instdir and not in devdir (you should remove):"
132 comm -13 $tmpdir/devdir $tmpdir/instdir
133 # maybe better to leave it for manual removal?
134
135 # also copy source files.
136 t4srcdir=`echo "$instdir" \
137 | sed 's,/texmf-dist/.*,/texmf-dist/source/generic/tex4ht,'`
138 echo "$prg: copying source files to $t4srcdir."
139 cp -p ChangeLog Makefile tex4ht-fonts*.tex update-htfonts "$t4srcdir"
140
141 echo
142 (set -x;
143 $svn status "$instdir"
144 $svn status "$t4srcdir"
145 )
146
147 echo "$prg: done."