2016-07-25 23:42:50 +03:00
|
|
|
#!/bin/bash
|
2016-07-26 09:21:29 +03:00
|
|
|
#
|
|
|
|
# sch2pdf - Generate PDF from schematics, using sch2fig
|
|
|
|
#
|
|
|
|
# Written 2016 by Werner Almesberger
|
|
|
|
# Copyright 2016 by Werner Almesberger
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Known bugs:
|
|
|
|
# - expects first sheet to be index page
|
|
|
|
# - only renders sub-sheets
|
|
|
|
# - has all the limitations of sch2fig (see TODO)
|
|
|
|
#
|
|
|
|
|
2016-07-25 23:42:50 +03:00
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
2016-07-26 08:32:53 +03:00
|
|
|
cat <<EOF 1>&2
|
2016-07-27 00:09:28 +03:00
|
|
|
usage: $0 [-n first_num] [-o output.pdf] [-q] [-t template.fig ]
|
|
|
|
file.lib ... file.sch
|
2016-07-26 08:32:53 +03:00
|
|
|
EOF
|
2016-07-25 23:42:50 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out=out.pdf
|
|
|
|
quiet=false
|
2016-07-26 08:32:53 +03:00
|
|
|
template=
|
2016-07-27 00:09:28 +03:00
|
|
|
num=1
|
2016-07-25 23:42:50 +03:00
|
|
|
while [ "$1" ]; do
|
|
|
|
case "$1" in
|
2016-07-27 00:09:28 +03:00
|
|
|
-n) num=$2
|
|
|
|
shift 2;;
|
2016-07-25 23:42:50 +03:00
|
|
|
-o) out=$2
|
|
|
|
shift 2;;
|
|
|
|
-q) quiet=true
|
|
|
|
shift;;
|
2016-07-26 08:32:53 +03:00
|
|
|
-t) template="-t $2"
|
|
|
|
shift 2;;
|
2016-07-25 23:42:50 +03:00
|
|
|
-*) usage;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$1" ] || usage
|
|
|
|
|
|
|
|
libs=
|
|
|
|
while [ "$2" ]; do
|
|
|
|
libs="$libs $1"
|
|
|
|
shift
|
|
|
|
done
|
2016-07-26 09:16:09 +03:00
|
|
|
|
2016-07-30 05:29:17 +03:00
|
|
|
./sch2fig "-DTITLE=`basename \"$1\" .sch`" -DNUMBER=$num $template $libs "$1" |
|
2016-07-30 04:00:57 +03:00
|
|
|
fig2dev -L pdf >"$out"
|
|
|
|
|
2016-07-26 09:16:09 +03:00
|
|
|
sheet=false
|
|
|
|
while read line; do
|
|
|
|
if ! $sheet; then
|
|
|
|
[ "${line#\$Sheet}" != "$line" ] && sheet=true
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
if [ "${line#\$EndSheet}" != "$line" ]; then
|
|
|
|
sheet=false
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
2016-07-30 05:29:17 +03:00
|
|
|
|
2016-07-26 09:16:09 +03:00
|
|
|
if [ "${line#F0 \"}" != "$line" ]; then
|
|
|
|
name=${line#F0 \"}
|
|
|
|
name=${name%%\"*}
|
|
|
|
fi
|
|
|
|
[ "${line#F1 \"}" = "$line" ] && continue
|
|
|
|
file=${line#F1 \"}
|
|
|
|
file=${file%%\"*}
|
|
|
|
|
2016-07-30 05:29:17 +03:00
|
|
|
num=`expr $num + 1`
|
|
|
|
|
2016-07-26 09:16:09 +03:00
|
|
|
$quiet || echo "$file" 1>&2
|
2016-07-27 00:09:28 +03:00
|
|
|
./sch2fig "-DTITLE=$name" -DNUMBER=$num $template \
|
|
|
|
$libs `dirname "$1"`/$file |
|
2016-07-26 09:16:09 +03:00
|
|
|
fig2dev -L pdf >_tmp.pdf
|
2016-07-30 04:00:57 +03:00
|
|
|
pdfunite "$out" _tmp.pdf _tmp2.pdf
|
|
|
|
mv _tmp2.pdf "$out"
|
2016-07-26 09:16:09 +03:00
|
|
|
done <"$1"
|
|
|
|
exit
|