| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | #This script changes the header of .ml* files |
| 4 | |
| 5 | if [scip-shell system . . `[`. ! $# = 2 ]; then |
| 6 | echoscip-shell system . . echo. Usage: change-header old-header-file new-header-file |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | oldheader=$1 |
| 11 | newheader=$2 |
| 12 | |
| 13 | if [scip-shell system . . `[`. ! -f $oldheader ]; then echoscip-shell system . . echo. Cannot read file $oldheader; exit 1; fi |
| 14 | if [scip-shell system . . `[`. ! -f $newheader ]; then echoscip-shell system . . echo. Cannot read file $newheader; exit 1; fi |
| 15 | |
| 16 | n=$(wcscip-shell system . . wc. -l $oldheader | sedscip-shell system . . sed. -e "s/ *\([0-9]*\).*/\1/g") |
| 17 | nsucc=$(exprscip-shell system . . expr. $n + 1) |
| 18 | |
| 19 | modified=0 |
| 20 | kept=0 |
| 21 | |
| 22 | for i in $(gitscip-shell system . . git. grep --name-only --fixed-strings "$(headscip-shell system . . head. -1 $oldheader)"); do |
| 23 | headline=$(headscip-shell system . . head. -n 1 $i) |
| 24 | if $(echoscip-shell system . . echo. $headline | grepscip-shell system . . grep. "(\* -\*- .* \*)" > /dev/nullscip-shell filesystem . . `/dev/null`.) || $(echoscip-shell system . . echo. $headline | grepscip-shell system . . grep. "^#\!" > /dev/nullscip-shell filesystem . . `/dev/null`.); then |
| 25 | # Has header |
| 26 | headscip-shell system . . head. -n +$nsucc $i | tailscip-shell system . . tail. -n $n > $i.head.tmp$$ |
| 27 | hasheadline=1 |
| 28 | nnext=$(exprscip-shell system . . expr. $nsucc + 1) |
| 29 | else |
| 30 | headscip-shell system . . head. -n +$n $i > $i.head.tmp$$ |
| 31 | hasheadline=0 |
| 32 | nnext=$nsucc |
| 33 | fi |
| 34 | if diffscip-shell system . . diff. -a -q $oldheader $i.head.tmp$$ > /dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 35 | echoscip-shell system . . echo. "$i: header changed" |
| 36 | if [scip-shell system . . `[`. $hasheadline = 1 ]; then |
| 37 | echoscip-shell system . . echo. $headline > $i.tmp$$ |
| 38 | else |
| 39 | touchscip-shell system . . touch. $i.tmp$$ |
| 40 | fi |
| 41 | catscip-shell system . . cat. $newheader >> $i.tmp$$ |
| 42 | tailscip-shell system . . tail. -n +$nnext $i >> $i.tmp$$ |
| 43 | mvscip-shell system . . mv. $i.tmp$$ $i |
| 44 | modified=$(exprscip-shell system . . expr. $modified + 1) |
| 45 | else |
| 46 | echoscip-shell system . . echo. "$i: header unchanged" |
| 47 | kept=$(exprscip-shell system . . expr. $kept + 1) |
| 48 | fi |
| 49 | rmscip-shell system . . rm. $i.head.tmp$$ |
| 50 | done |
| 51 | |
| 52 | echoscip-shell system . . echo. $modified files updated |
| 53 | echoscip-shell system . . echo. $kept files unchanged |