summaryrefslogtreecommitdiff
path: root/support/TeX4ht/source/update-htfonts
blob: 1b24cc5ec4523d0403099b824c2d63ffbb9f4cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
# $Id: update-htfonts 1141 2022-06-01 21:43:42Z karl $
# Public domain. Originally written by Karl Berry, 2022.

# don't bother with real option parsing.
if test $# -ne 3; then
cat <<END_USAGE
Usage: $0 [ diff | update ] HTF-DEVDIR HTF-INSTDIR
END_USAGE
  exit 1
fi

verbose=true
prg=`basename $0`
cp="cp -pv"
mkdir="mkdir -v"
svn=svn

if test x"$1" = xdiff; then
  shift
  do_updates=false
  cp="echo would $cp"
  mkdir="echo would $mkdir"
  svn="echo would $svn"

elif test x"$1" = xupdate; then
  shift
  do_updates=true
else
  echo "$0: first arg must be \`diff' or \`update', not: $1" >&2
  exit 1
fi

devdir=$1
instdir=$2
verbose=true
tmp=/tmp/htdif # prefix

if test ! -d "$devdir"; then
  echo "$0: devdir not a directory: $devdir" >&2
  exit 1
fi
if test ! -d "$instdir"; then
  echo "$0: instdir not a directory: $instdir" >&2
  exit 1
fi


#  Function to copy SRC to DEST, or fail. Just calls $cp.
# 
copy_file () {
  src=$1; dest=$2
  #
  if $cp "$src" "$dest"; then :; else
    echo "$0: copy ($cp) failed: $src -> $dest" >&2
    exit 1
  fi
}

#  Function to compare SRC to DEST. Return zero if equivalent,
# nonzero if different (or DEST does not exist, etc.).
# 
# Remove a timestamp string from both files for comparison:
# YYYY-MM-DD-HH:MM or just YYYY-MM-DD
# 
htf_same () {
  src=$1; dest=$2;
  #
  src_filtered=$tmp.s`basename "$src"`
  dest_filtered=$tmp.d`basename "$dest"`
  #
  sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \
      $src >$src_filtered || exit 1
  sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \
      $dest >$dest_filtered || exit 1
  cmp -s "$src_filtered" "$dest_filtered"
}

#  Iterate through all files in the dev directory.
echo "$prg: comparing $devdir"
echo "$prg:        to $instdir"
>$tmp.0 # accumulate diffs here
#
find "$devdir" -type f -print | sort | while read devf; do
  instf=`echo "$devf" | sed "s,^$devdir/,$instdir/,"`
  #echo "$devf" | grep ec-mlm >/dev/null &&
  #$verbose && echo "considering $devf -> $instf"
  
  if test -r "$instf"; then
    # we have a file in both directories; see if they are the same (enough).
    if htf_same "$devf" "$instf"; then
      : # $verbose && echo "`basename \"$devf\"`: same ($devf == $instf)"
    else
      $verbose && echo "`basename \"$devf\"`: diff ($devf != $instf)"
      # save diff from (older) DEST to newer (SRC).
      diff -u0 "$dest" "$src" >>$tmp.0
      #
      copy_file "$devf" "$instf"
    fi

  else
    # no destination file. see if we have the containing directory.
    destdirf=`dirname "$instf"`
    if test -d "$destdirf"; then
      # have directory, so add file.
      $verbose && echo "newfile ($devf -> $instf)"
      copy_file "$devf" "$instf"
      $svn add "$instf" || exit 1
    else
      # don't even have directory. create it, then copy file.
      $mkdir "$destdirf"
      $verbose && echo "newdir ($devf -> $destdirf)"
      if test ! -d "$destdirf"; then
        echo "$0: could not make dest dir: $destdirf (for $devf->$instf)" >&2
        exit 1
      fi
      $svn add "$destdirf" || exit 1
      copy_file "$devf" "$instf"
      $svn add "$instf" || exit 1
    fi
  fi
done

#  check for extra files in $instdir
(cd "$devdir" && find . -type f -print | sort) >$tmp.devdir || exit 1
(cd "$instdir" && find . -type f -print | sort) >$tmp.instdir || exit 1

echo "$prg: files in devdir and not in instdir (should be empty):"
comm -23 $tmp.devdir $tmp.instdir

echo "$prg: files in instdir and not in devdir (you should remove):"
comm -13 $tmp.devdir $tmp.instdir
# maybe better to leave it for manual removal?

echo "$prg: done."