1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-08-25 17:33:21 +03:00
eda-tools/sch2fig/sch2pdf
2016-07-26 03:21:29 -03:00

87 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
#
# 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)
#
usage()
{
cat <<EOF 1>&2
usage: $0 [-o output.pdf] [-q] [-t template.fig ] file.lib ... file.sch
EOF
exit 1
}
out=out.pdf
quiet=false
template=
while [ "$1" ]; do
case "$1" in
-o) out=$2
shift 2;;
-q) quiet=true
shift;;
-t) template="-t $2"
shift 2;;
-*) usage;;
*) break;;
esac
done
[ "$1" ] || usage
libs=
while [ "$2" ]; do
libs="$libs $1"
shift
done
first=true
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
if [ "${line#F0 \"}" != "$line" ]; then
name=${line#F0 \"}
name=${name%%\"*}
fi
[ "${line#F1 \"}" = "$line" ] && continue
file=${line#F1 \"}
file=${file%%\"*}
$quiet || echo "$file" 1>&2
./sch2fig "-DTITLE=$name" $template $libs `dirname "$1"`/$file |
fig2dev -L pdf >_tmp.pdf
if $first; then
mv _tmp.pdf "$out"
first=false
else
pdfunite "$out" _tmp.pdf _tmp2.pdf
mv _tmp2.pdf "$out"
fi
done <"$1"
exit