Root/scripts/gitsch2ppm

Source at commit b3f201486360ad2ffeb7d1ac24d14972d850f8ca created 10 years 24 days ago.
By Werner Almesberger, Split gitsch2ppm into its constituents.
1#!/bin/sh
2#
3# gitsch2ppm - Generate PPM files for KiCad schematics in git
4#
5# Written 2010 by Werner Almesberger
6# Copyright 2010 Werner Almesberger
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13
14
15usage()
16{
17    cat <<EOF 1>&2
18usage: $0 [options] top-dir top-schem [commit] outdir
19
20  -c use cached Postscript files (from previous run, with -k)
21  -k keep checked-out tree (for immediate reuse with -c)
22  -r XxY image resolution (default: $RES)
23  -S sanitize the KiCad profile
24  -w points Postscript line width (default: $LINEWIDTH)
25EOF
26    exit 1
27}
28
29
30cache=false
31keep=false
32res=
33sanitize=
34width=
35while true; do
36    case "$1" in
37    -c) cache=true
38    shift;;
39    -k) keep=true
40    shift;;
41    -r) [ -z "$2" ] && usage
42    res="-r $2"
43    shift 2;;
44    -S) sanitize=-S
45    shift;;
46    -w) [ -z "$2" ] && usage
47    width="-r $2"
48    shift 2;;
49    -*)
50    usage;;
51    *)
52    break;;
53    esac
54done
55
56tmp=`pwd`/_gitsch2ppm
57eval outdir=\${$#}
58
59# with thanks to http://www.faqs.org/faqs/unix-faq/faq/part2/section-12.html
60argv=
61while [ $# -gt 1 ]; do
62    argv="$argv \"$1\""
63    shift
64done
65eval set x "$argv"
66shift
67
68if ! $cache; then
69    rm -rf "$tmp"
70    rm -rf "$outdir"
71    gitsch2ps $sanitize "$@" "$tmp"
72    for n in "$tmp"/*.ps; do
73    normalizeschps $width "$n"
74    done
75fi
76
77mkdir -p "$outdir"
78for n in "$tmp"/*.ps; do
79    schps2ppm $res "$n" "$outdir/`basename \"${n%.ps}.ppm\"`"
80done
81
82$keep || rm -rf "$tmp"
83

Archive Download this file



interactive