Debian Codegraph @

tools/autotangle

raw
1 #!/usr/bin/env rc
2
3 nl='
4 '
5 tf=`tempfile
6
7 for (f in ``($nl){noroots $* |sed 's/^<<\(.*\)>>$/\1/'}) {
8 if (~ $f *' '*) {
9 echo >[1=2] 'Skipping bad root <<'^$^f^'>>'
10 } else {
11 d=`{dirname $f} if (! test -d $d) mkdir -p $d
12 switch (`{basename $f}) {
13 case *.c *.h; o=(-L'#line %L "%F"%N')
14 case *.lua; o=(-L'-- %F:%L%N')
15 case *.sh; o=(-L'# %F:%L%N')
16 case mkfile; o=(-t8)
17 case *; o=()
18 }
19 notangle $o -R$f $* >$tf
20 if (! cmp -s $tf $f) {
21 echo Updating $f
22 rm -f $f
23 cat $tf > $f
24 chmod a-w $f
25 }
26 }
27 }
28 rm $tf