Root/
| 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 | |
| 15 | sub 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 | |
| 28 | open(FILE, $file) || die "$file: $!"; |
| 29 | while (<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 | } |
| 52 | close FILE; |
| 53 | |
| 54 | if (!defined $out) { |
| 55 | rename($file, "$file.bak"); |
| 56 | $out= $file; |
| 57 | } |
| 58 | |
| 59 | open(FILE, ">$out") || die "$out: $!"; |
| 60 | print FILE join("", @f) || die "$out: $!"; |
| 61 | close FILE || die "$out: $!"; |
| 62 |
Branches:
master
