IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit 56a95040ca2fe2a265bd27fce365515f7656383e created 13 years 6 months ago. By Werner Almesberger, Generate commit entry and show diffs also for the first commit. Plus cleanup. | |
---|---|
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 | |
15 | RES=1280x850 |
16 | LINEWIDTH=120 |
17 | |
18 | |
19 | ps2ppm() |
20 | { |
21 | X=`echo $RES | sed 's/x.*//'` |
22 | Y=`echo $RES | sed 's/.*x//'` |
23 | IRES=${Y}x$X |
24 | res=`expr 72 \* $X / 800` |
25 | |
26 | ( cat <<EOF |
27 | %!PS-Adobe-3.0 |
28 | /setlinewidth { $LINEWIDTH 2 copy lt { exch } if pop setlinewidth } bind def |
29 | /rectfill { rectstroke } bind def |
30 | EOF |
31 | sed 1d <"$1"; ) | |
32 | gs -sDEVICE=ppmraw -sOutputFile=- -g$IRES -r$res \ |
33 | -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q - | |
34 | pnmflip -r270 | |
35 | cat >"${1%.ps}.ppm" |
36 | } |
37 | |
38 | |
39 | usage() |
40 | { |
41 | cat <<EOF 1>&2 |
42 | usage: $0 [options] top-dir top-schem [commit] outdir |
43 | |
44 | -c use cached Postscript files (from previous run, with -k) |
45 | -k keep checked-out tree (for immediate reuse with -c) |
46 | -r XxY image resolution (default: $RES) |
47 | -S sanitize the KiCad profile |
48 | -w points Postscript line width (default: $LINEWIDTH) |
49 | EOF |
50 | exit 1 |
51 | } |
52 | |
53 | |
54 | cache=false |
55 | keep=false |
56 | sanitize=true |
57 | while true; do |
58 | case "$1" in |
59 | -c) cache=true |
60 | shift;; |
61 | -k) keep=true |
62 | shift;; |
63 | -r) [ -z "$2" ] && usage |
64 | RES="$2" |
65 | shift 2;; |
66 | -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile` |
67 | [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize" |
68 | shift;; |
69 | -w) [ -z "$2" ] && usage |
70 | LINEWIDTH="$2" |
71 | shift 2;; |
72 | -*) |
73 | usage;; |
74 | *) |
75 | break;; |
76 | esac |
77 | done |
78 | |
79 | [ ! -z "$3" -a -z "$5" ] || usage |
80 | dir="$1" |
81 | schem="$2" |
82 | sdir=`dirname "$schem"` |
83 | if [ -z "$4" ]; then |
84 | commit=HEAD |
85 | outdir="$3" |
86 | else |
87 | commit="$3" |
88 | outdir="$4" |
89 | fi |
90 | |
91 | [ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir |
92 | |
93 | [ "$commit" != HEAD -o -f "$dir/$schem" ] || usage |
94 | [ -d "$dir/.git" ] || usage |
95 | |
96 | tmp="$dir/../_gitsch2ppm" |
97 | sch="$tmp/$sdir" |
98 | |
99 | if ! $cache; then |
100 | rm -rf "$tmp" |
101 | rm -rf "$outdir" |
102 | |
103 | git clone -s -n "$dir/.git" "$tmp" || exit |
104 | ( cd "$tmp" && git checkout -q "$commit"; ) || exit |
105 | |
106 | if [ ! -f "$tmp/$schem" ]; then |
107 | echo "$schem not found (checked out into $tmp)" 1>&2 |
108 | exit 1 |
109 | fi |
110 | |
111 | ( |
112 | cd "$sch" || exit |
113 | rm -f *.ps *.ppm |
114 | $sanitize "$tmp/${schem%.sch}.pro" || |
115 | exit |
116 | eeschema --plot "$tmp/$schem" |
117 | ) || exit |
118 | fi |
119 | |
120 | for n in "$sch"/*.ps; do |
121 | ps2ppm "$n" |
122 | done |
123 | |
124 | mkdir -p "$outdir" |
125 | |
126 | mv "$sch"/*.ppm "$outdir" |
127 | |
128 | $keep || rm -rf "$tmp" |
129 |