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 36e73c4abb520aa65722ef5e1483bcb8b75bf9f4 created 13 years 6 months ago. By Werner Almesberger, Moved tools/ out of atrf, in preparation of merge with atusd. | |
---|---|
1 | #!/usr/bin/perl |
2 | # |
3 | # sanitize-profile - Remove items from a KiCad profile 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 | @LIBS = ("/usr/share/kicad/library", "/usr/local/share/kicad/library"); |
16 | |
17 | |
18 | sub rewrite |
19 | { |
20 | local ($s) = @_; |
21 | |
22 | return $s if $section ne "eeschema/libraries"; |
23 | return $s unless /^LibName(\d+)=(.*)\s*$/; |
24 | my $lib = $2; |
25 | if ($1 == $in_lib) { |
26 | $in_lib++; |
27 | } else { |
28 | print STDERR "LibName$1 when expecting $next_lib. Renumbering."; |
29 | $in_lib = $1+1; |
30 | } |
31 | $out_lib++; |
32 | my $var = "LibName$out_lib"; |
33 | if ($lib =~ /\//) { |
34 | return "$var=$lib\n" if -r "$lib.lib"; |
35 | } |
36 | for (".", $libdir, @LIBS) { |
37 | return "$var=$lib\n" if -r "$_/$lib.lib"; |
38 | } |
39 | print STDERR "cannot find $lib\n"; |
40 | $out_lib--; |
41 | return undef; |
42 | } |
43 | |
44 | |
45 | sub usage |
46 | { |
47 | print STDERR "usage: $0 file.pro [outfile]\n"; |
48 | exit(1); |
49 | } |
50 | |
51 | |
52 | ($file, $out) = @ARGV; |
53 | &usage if $#ARGV > 1; |
54 | |
55 | ($dir = $file) =~ s|.*/||; |
56 | $dir = "." if $dir eq ""; |
57 | |
58 | open(FILE, $file) || die "$file: $!"; |
59 | while (<FILE>) { |
60 | if (/^\[(\S+)\]/) { |
61 | $section = $1; |
62 | if ($section eq "eeschema/libraries") { |
63 | $in_lib = 1; |
64 | $out_lib = 0; |
65 | } |
66 | } |
67 | if ($section eq "eeschema") { |
68 | $libdir = $2 if /^LibDir=(.*)\s*$/; |
69 | } |
70 | $s = &rewrite($_); |
71 | push(@f, $s) if defined $s; |
72 | } |
73 | close FILE; |
74 | |
75 | if (!defined $out) { |
76 | rename($file, "$file.bak"); |
77 | $out= $file; |
78 | } |
79 | |
80 | open(FILE, ">$out") || die "$out: $!"; |
81 | print FILE join("", @f) || die "$out: $!"; |
82 | close FILE || die "$out: $!"; |
83 |