board/mass_prop.sh

59 lines
999 B
Bash
Raw Normal View History

2021-11-02 17:02:42 +01:00
#!/bin/sh
if test ! $# -eq 2
then
echo "Need two arguments: a board file name and a tab file name" >&2
exit 1
fi
board="$1"
tab="$2"
if test ! -f "$board"
then
echo "Board file $board not found" >&2
exit 1
fi
if test ! -f "$tab"
then
echo "Tab file $tab not found" >&2
exit 1
fi
btmp=.tmp.$board
awk -F "[ \t]*[;][ \t]*" -v "outfn=$btmp" '
BEGIN { sq = "'\''" }
# quote s with single quotes and remove any single quote from it
# (pcb-rnd action syntax does not have escaping)
function squote(s)
{
gsub("[" sq "]", ".", s)
return sq s sq
}
# ignore comments
/^[ \t]*#/ { next }
# generate an unselect-query-propset sequence for each line
(NF > 1) {
print "Unselect(all)"
print "query(select, " squote($1) ")"
for(n = 2; n <= NF; n++) {
if (split($n, A, "=") == 2)
print "propset(selection, " squote(A[1]) "," squote(A[2]) ")"
}
}
END {
print "Unselect(all)"
print "Save(LayoutAs, " squote(outfn) ")"
}
' < "$tab" | pcb-rnd --gui batch "$board" && mv "$btmp" "$board"