Date:2010-08-30 07:53:41 (9 years 18 days ago)
Author:Werner Almesberger
Commit:800577353e88fadb4e52bc1b2e8cfc8d0c83f9ef
Message:Merged the functionality of gitsch2ppm into schhist2web.

- scripts/normalizeschps: don't edit in place and thus become capable of
running in a pipe
- scripts/schps2ppm: considered - to be an option and thus didn't accept
it as input file name
- scripts/schhist2web: open-coded functionality of "gitsch2ppm"
- scripts/gitsch2ppm: removed
Files: scripts/gitsch2ppm (1 diff)
scripts/normalizeschps (2 diffs)
scripts/schhist2web (1 diff)
scripts/schps2ppm (1 diff)

Change Details

scripts/gitsch2ppm
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"
scripts/normalizeschps
1818usage()
1919{
2020    cat <<EOF 1>&2
21usage: $0 [options] file ...
21usage: $0 [options] [in.ps [out.ps]]
2222
2323  -w points Postscript line width (default: $LINEWIDTH)
2424EOF
...... 
3838    esac
3939done
4040
41for n in "$@"; do
42    sed -i '
43      1c%!PS-Adobe-3.0\
44      currentdict /DidNormalize known not { \
45          /setlinewidth { '$LINEWIDTH' 2 copy lt { exch } if pop \
46            setlinewidth } bind def \
47          /rectfill { rectstroke } bind def \
48      /DidNormalize true def \
49      } if \
50      gsave
51      /%%DocumentMedia: A4.*/a-20 -10 translate
52      /%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
53      }
54      /%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
55      }
56      $agrestore' "$n"
57done
41[ -z "$3" ] || usage
42in=${1:--}
43out=${2:-/dev/stdout}
44
45sed '
46  1c%!PS-Adobe-3.0\
47  currentdict /DidNormalize known not { \
48      /setlinewidth { '$LINEWIDTH' 2 copy lt { exch } if pop \
49        setlinewidth } bind def \
50      /rectfill { rectstroke } bind def \
51      /DidNormalize true def \
52  } if \
53  gsave
54  /%%DocumentMedia: A4.*/a-20 -10 translate
55  /%%DocumentMedia: A3.*/{s/A3/A4/;a-20 -10 translate 0.70 dup scale
56  }
57  /%%DocumentMedia: A2.*/{s/A2/A4/;a-18 -12 translate 0.49 dup scale
58  }
59  $agrestore' "$in" >"$out"
5860
5961# /%%Orientation: Landscape/d' "$n"
scripts/schhist2web
190190    echo Name change $schname to $new 1>&2
191191    schname="$new"
192192    fi
193    trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0
193    tmp=`pwd`/_schhist2web
194    trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\" \"$tmp\"" 0
194195    if [ ! -d "$cache/ppm_$n" ]; then
195    rm -rf "$cache/ppm_$n"
196    mkdir "$cache/ppm_$n"
196    rm -rf "$cache/ppm_$n" "$cache/fat_$n"
197    mkdir "$cache/ppm_$n" "$cache/fat_$n"
197198    #
198199    # potential optimization here: remember Postscript files from previous
199200    # run (or their md5sum) and check if they have changed. If not, skip
200201    # the ghostscript run and just put a symlink, replacing the less
201202    # efficient optimization below.
202203    #
203    gitsch2ppm $sanitize -k "$dir" "$schname" $n "$cache/ppm_$n" || exit
204    gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit
204    gitsch2ps $sanitize "$dir" "$schname" $n "$tmp" || exit
205    for m in "$tmp"/*.ps; do
206        ppm="$cache/ppm_$n/`basename "$m" .ps`.ppm"
207        normalizeschps "$m" | schps2ppm - "$ppm" || exit
208        ppm="$cache/fat_$n/`basename "$m" .ps`.ppm"
209        normalizeschps -w 500 "$m" | schps2ppm - "$ppm" || exit
210    done
211    rm -rf "$tmp"
205212    fi
206213    for m in "$cache/ppm_$n/"*; do
207214    [ "$m" = "$cache/ppm_$n/*" ] && break
scripts/schps2ppm
3131    -r) [ -z "$2" ] && usage
3232    RES="$2"
3333    shift 2;;
34    -*)
35    usage;;
36    *)
37    break;;
34    -) break;;
35    -*) usage;;
36    *) break;;
3837    esac
3938done
4039

Archive Download the corresponding diff file



interactive