IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit d7d95ff2da07c37cd95d5466d7cd2b775c771ec8 created 13 years 7 months ago. By Werner Almesberger, Allow schhist2web and friends to run from a directory outside the working tree. | |
---|---|
1 | #!/bin/sh |
2 | # |
3 | # schhist2web - Web-browseable graphical revision history of schematics |
4 | # |
5 | # Written 2010 by Werner Almesberger |
6 | # Copyright 2010 Werner Almesberger |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify |
9 | # it under the terms of the GNU General Public License as published by |
10 | # the Free Software Foundation; either version 2 of the License, or |
11 | # (at your option) any later version. |
12 | # |
13 | |
14 | |
15 | OUTDIR=_out |
16 | THUMB_OPTS="-w 3 -d 60 -c 0.5,0.5,0.5 -n 1,1,0" |
17 | BG_COLOR="f0f0ff" |
18 | FNAME_COLOR="#b0f0ff" |
19 | SEP_COLOR="#000000" |
20 | |
21 | |
22 | shrink() |
23 | { |
24 | pnmscale -width 120 "$@" || exit |
25 | } |
26 | |
27 | |
28 | pngdiff() |
29 | { |
30 | # pngdiff preproc outfile arg ... |
31 | pp="$1" |
32 | of="$2" |
33 | shift 2 |
34 | if ! PATH=$PATH:`dirname $0`/ppmdiff ppmdiff "$@" "$out/_tmp"; then |
35 | rm -f "$out/_tmp" |
36 | return 1 |
37 | fi |
38 | $pp "$out/_tmp" | pnmtopng >"$of" |
39 | rm "$out/_tmp" |
40 | } |
41 | |
42 | |
43 | usage() |
44 | { |
45 | cat <<EOF 2>&1 |
46 | usage: $0 [-c cache-dir] [-n] [top-dir] [top-schem] [out-dir] |
47 | |
48 | top-dir top-level directory of the git archive (default: locate it) |
49 | top-schem root sheet of the schematics (default: locate it in top-dir) |
50 | out-dir output directory (default: $OUTDIR) |
51 | -n don't use previous cache content (rebuild the cache) |
52 | -c cache-dir cache directory (default: same as out-dir) |
53 | EOF |
54 | exit 1 |
55 | } |
56 | |
57 | |
58 | no_cache=false |
59 | while true; do |
60 | case "$1" in |
61 | -n) no_cache=true |
62 | shift;; |
63 | -c) [ -z "$1" ] && usage |
64 | cache="$1" |
65 | shift 2;; |
66 | -*) usage;; |
67 | *) break;; |
68 | esac |
69 | done |
70 | |
71 | if [ ! -z "$1" -a -d "$1/.git" ]; then |
72 | dir="$1" |
73 | shift |
74 | else |
75 | dir=. |
76 | while [ ! -d $dir/.git ]; do |
77 | if [ $dir -ef $dir/.. ]; then |
78 | echo "no .git/ directory found in hierarchy" 1>&2 |
79 | exit 1 |
80 | fi |
81 | dir=$dir/.. |
82 | done |
83 | echo "found top-dir: $dir" 1>&2 |
84 | fi |
85 | |
86 | if [ ! -z "$1" -a -f "$dir/$1" -a \ |
87 | -f "$dir"/`dirname "$1"`/`basename "$1" .sch`.pro ]; then |
88 | sch="$1" |
89 | shift |
90 | else |
91 | for n in "$dir"/*.sch; do |
92 | [ -f `dirname "$n"`/`basename "$n" .sch`.pro ] || continue |
93 | if [ ! -z "$sch" ]; then |
94 | echo "multiple choices for top-level .sch file" 1>&2 |
95 | exit 1 |
96 | fi |
97 | sch="$n" |
98 | done |
99 | if [ -z "$sch" -o "$sch" = "$dir/*.sch" ]; then |
100 | echo "no candidate for top-level .sch file found" 1>&2 |
101 | exit 1 |
102 | fi |
103 | echo "found root sheet: $sch" 1>&2 |
104 | fi |
105 | |
106 | if [ ! -z "$1" ] && [ ! -e "$1" ] || [ -d "$1" -a ! -d "$1"/.git ]; then |
107 | out="$1" |
108 | shift |
109 | else |
110 | out=$OUTDIR |
111 | fi |
112 | [ -z "$cache" ] && cache="$out" |
113 | |
114 | [ -z "$1" ] || usage |
115 | |
116 | PATH=`dirname "$0"`:"$PATH" |
117 | first=`gitenealogy "$dir" "$sch" | sed '$s/ .*//p;d'` |
118 | schname=`gitenealogy "$dir" "$sch" | sed '$s/^.* //p;d'` |
119 | |
120 | rm -rf "$out/diff_*" "$out/thumb_*" "$out/names" |
121 | $no_cache && rm -rf "$cache" |
122 | mkdir -p "$out/names" |
123 | mkdir -p "$cache" |
124 | |
125 | head= |
126 | for n in $first `cd "$dir" && git rev-list --reverse $first..HEAD`; do |
127 | ( cd "$dir" && git show --pretty=format:'' --name-only $n; ) | |
128 | egrep -q '\.sch$|\.pro$|\.lib$' || continue |
129 | echo Processing $n |
130 | new=`gitenealogy "$dir" "$sch" | sed "/^$n /s///p;d"` |
131 | if [ ! -z "$new" ]; then |
132 | echo Name change $schname to $new 1>&2 |
133 | schname="$new" |
134 | fi |
135 | trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0 |
136 | if [ ! -d "$cache/ppm_$n" ]; then |
137 | rm -rf "$cache/ppm_$n" |
138 | mkdir "$cache/ppm_$n" |
139 | gitsch2ppm -k "$dir" "$schname" $n "$cache/ppm_$n" || exit |
140 | gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit |
141 | fi |
142 | for m in "$cache/ppm_$n/"*; do |
143 | [ "$m" = "$cache/ppm_$n/*" ] && break |
144 | touch "$out/names/"`basename "$m" .ppm` |
145 | done |
146 | trap 0 |
147 | head=$n |
148 | done |
149 | |
150 | if [ -z "$head" ]; then |
151 | echo "no usable head found" 2>&1 |
152 | exit 1 |
153 | fi |
154 | |
155 | ppmmake '#e0e0e0' 5 20 | pnmtopng >"$out"/unchanged.png |
156 | |
157 | index="$out/index.html" |
158 | { |
159 | cat <<EOF |
160 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
161 | <HTML> |
162 | EOF |
163 | if [ ! -z "$SCHHIST_TITLE" ]; then |
164 | echo "<TITLE>$SCHHIST_TITLE</TITLE>" |
165 | fi |
166 | echo "<BODY>" |
167 | if [ ! -z "$SCHHIST_TITLE" ]; then |
168 | echo "<H1>" |
169 | [ -z "$SCHHIST_HOME_URL" ] || echo "<A href=\"$SCHHIST_HOME_URL\">" |
170 | echo "$SCHHIST_TITLE" |
171 | [ -z "$SCHHIST_HOME_URL" ] || echo "</A>" |
172 | echo "</H1>" |
173 | fi |
174 | cat <<EOF |
175 | <TABLE bgcolor="$BG_COLOR" callpadding=1> |
176 | <TR bgcolor="$FNAME_COLOR"> |
177 | EOF |
178 | for m in `ls -1 "$out/names"`; do |
179 | echo "<TD><B>$m</B>" |
180 | done |
181 | } >"$index" |
182 | |
183 | next="$head" |
184 | for n in `cd "$dir" && git rev-list $first..HEAD~1` $first; do |
185 | [ -d "$cache/ppm_$n" ] || continue |
186 | empty=true |
187 | s="<TR><TR>" |
188 | mkdir -p "$out/diff_$next" "$out/thumb_$next" |
189 | for m in `ls -1 "$out/names"`; do |
190 | a="$cache/ppm_$n/$m.ppm" |
191 | fat_a="$cache/fat_$n/$m.ppm" |
192 | b="$cache/ppm_$next/$m.ppm" |
193 | fat_b="$cache/fat_$next/$m.ppm" |
194 | diff="$out/diff_$next/$m.png" |
195 | thumb="$out/thumb_$next/$m.png" |
196 | |
197 | if [ -f "$a" -a -f "$b" ]; then |
198 | s="$s<TD align=\"center\" valign=\"middle\">" |
199 | if ! pngdiff cat "$diff" "$a" "$b"; then |
200 | s="$s<IMG src=\"unchanged.png\"" |
201 | continue |
202 | fi |
203 | pngdiff shrink "$thumb" -f $THUMB_OPTS "$fat_a" "$fat_b" \ |
204 | "$a" "$b" || exit |
205 | elif [ -f "$a" ]; then |
206 | s="$s<TD>" |
207 | pngdiff cat "$diff" -f -c 1,0,0 "$a" "$a" || exit |
208 | pngdiff shrink "$thumb" -f -c 1,0,0 $THUMB_OPTS "$fat_a" "$fat_a" \ |
209 | || exit |
210 | elif [ -f "$b" ]; then |
211 | s="$s<TD>" |
212 | pngdiff cat "$diff" -f -c 0,1,0 "$b" "$b" || exit |
213 | pngdiff shrink "$thumb" -f -c 0,1,0 $THUMB_OPTS "$fat_b" "$fat_b" \ |
214 | || exit |
215 | else |
216 | s="$s<TD>" |
217 | continue |
218 | fi |
219 | echo "$s" >>"$index" |
220 | s= |
221 | empty=false |
222 | echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index" |
223 | done |
224 | if ! $empty; then |
225 | ( |
226 | cat <<EOF |
227 | $s<TD valign="middle"> |
228 | <TABLE bgcolor="$SEP_COLOR" cellspacing=0 width="100%"><TR><TD></TABLE> |
229 | EOF |
230 | mkdir -p "$out/diff_$next" "$out/thumb_$next" |
231 | echo "<PRE>" |
232 | ( cd "$dir" && git log --pretty=short $next~1..$next; ) | |
233 | if [ -z "$SCHHIST_COMMIT_TEMPLATE" ]; then |
234 | cat |
235 | else |
236 | url=`echo "$SCHHIST_COMMIT_TEMPLATE" | sed "s/{}/$next/g"` |
237 | sed "s|^commit |<A href=\"$url\">commit</a> |" |
238 | fi | |
239 | sed '/^<.*>commit</n;s/&/&/g;s/</\</g;s/>/\>/g' |
240 | echo "</PRE>" |
241 | ) >>"$index" |
242 | fi |
243 | next=$n |
244 | done |
245 | |
246 | cat <<EOF >>"$index" |
247 | </TABLE> |
248 | <HR> |
249 | `date -u '+%F %X'` UTC |
250 | </BODY> |
251 | </HTML> |
252 | EOF |
253 |