1 |
frodo |
149 |
#! /bin/sh |
2 |
frodo |
2 |
|
3 |
frodo |
149 |
make_targets_file() |
4 |
frodo |
2 |
{ |
5 |
frodo |
149 |
# local file line line_nr error targets_file files |
6 |
frodo |
2 |
targets_file="$1" |
7 |
|
|
shift |
8 |
|
|
files="$@" |
9 |
frodo |
250 |
printf "" > "$targets_file" |
10 |
frodo |
2 |
|
11 |
|
|
for file in $files; do |
12 |
|
|
( |
13 |
|
|
line_nr=1 |
14 |
|
|
while read line; do |
15 |
|
|
error=0 |
16 |
frodo |
250 |
while [ $error -eq 0 ] && echo $line | grep '\[' >/dev/null ; do |
17 |
|
|
if echo $line | grep '\[.*\]' >/dev/null; then |
18 |
|
|
printf "%s %s " "$file" "$line_nr" >> "$targets_file" |
19 |
frodo |
2 |
echo $line | sed -e 's,^[^\[]*\[,,' -e 's,\].*$,,' \ |
20 |
|
|
>> "$targets_file" |
21 |
frodo |
149 |
else |
22 |
|
|
echo "In \`$file\' line $line_nr: target brackets inbalance" >&2 |
23 |
|
|
error=1 |
24 |
frodo |
2 |
fi |
25 |
|
|
line=`echo $line | sed -e 's,^[^]]*\],,'` |
26 |
|
|
done |
27 |
frodo |
250 |
if [ $error -eq 0 ] && echo $line | grep '\]' >/dev/null ; then |
28 |
frodo |
2 |
echo "In \`$file\' line $line_nr: target brackets inbalance" >&2 |
29 |
|
|
error=1 |
30 |
|
|
fi |
31 |
frodo |
250 |
line_nr=`echo "$line_nr + 1" | bc` |
32 |
frodo |
2 |
done |
33 |
|
|
) < $file |
34 |
|
|
done |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
make_targets_file "$@" |