Root/schhist/sanitize-schem

1#!/usr/bin/perl
2#
3# sanitize-schem - Remove items from KiCad schematics that may cause an upset
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
15sub usage
16{
17    print STDERR "usage: $0 file.sch [outfile]\n";
18    exit(1);
19}
20
21
22($file, $out) = @ARGV;
23&usage if $#ARGV > 1;
24
25($dir = $file) =~ s|[^/]*$||;
26$dir = "." if $dir eq "";
27
28open(FILE, $file) || die "$file: $!";
29while (<FILE>) {
30    if (/^\$Sheet/) {
31    $s = $_;
32    $discard = 1;
33    next;
34    }
35    if (/^\$EndSheet/) {
36    push(@f, $s.$_) unless $discard;
37    undef $s;
38    next;
39    }
40    if (!defined $s) {
41    push(@f, $_);
42    next;
43    }
44    $s .= $_;
45    next unless /^F1 "([^"]*)"/;
46    if (-r "$1" || -r "$dir/$1") {
47    $discard = 0;
48    next;
49    }
50    print STDERR "removing $1\n";
51}
52close FILE;
53
54if (!defined $out) {
55    rename($file, "$file.bak");
56    $out= $file;
57}
58
59open(FILE, ">$out") || die "$out: $!";
60print FILE join("", @f) || die "$out: $!";
61close FILE || die "$out: $!";
62

Archive Download this file

Branches:
master



interactive