gendocdb.pl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/perl
  2. sub usage
  3. {
  4. print STDERR "usage: $0 [-c] [-i] map.in file.sch ...\n";
  5. exit(1);
  6. }
  7. while ($ARGV[0] =~ /^-/) {
  8. if ($ARGV[0] eq "-c") {
  9. $cache = 1;
  10. } elsif ($ARGV[0] eq "-i") {
  11. $ignore_errors = 1;
  12. } else {
  13. &usage;
  14. }
  15. shift @ARGV;
  16. }
  17. open(MAP, $ARGV[0]) || die "$ARGV[0]: $!";
  18. while (<MAP>) {
  19. chop;
  20. if (/^\s*$/) {
  21. undef $key;
  22. next;
  23. }
  24. next if /^\s*#/;
  25. if (!defined $key) {
  26. $key = $_;
  27. $key =~ s/([.{}()+[\]])/\\\1/g;
  28. $key =~ s/\*/.*/g;
  29. $key =~ s/\?/./g;
  30. next;
  31. }
  32. die "bad document line" unless /^("[^"]*"|\S+)\s+/;
  33. $xtag = "$1";
  34. $url = "$'";
  35. #print STDERR "$url \n\n";
  36. if ($url =~ "^\`") {
  37. $url = substr($url, 1);
  38. #print STDERR "# $url \n";
  39. $url = `$url`;
  40. #print STDERR "# $url \n";
  41. }
  42. push(@keys, $key);
  43. push(@tags, $xtag);
  44. push(@s, $url);
  45. next unless $cache;
  46. next if $xtag eq "FP" || $xtag eq "PKG";
  47. system("eeshow-viewer", "-c", $url) && push(@failed, $url);
  48. }
  49. close MAP;
  50. shift @ARGV;
  51. sub ith
  52. {
  53. local ($i) = @_;
  54. $tag = $tags[$i];
  55. if ($tag eq "DS") {
  56. print "Data sheet\n";
  57. } elsif ($tag eq "TRM") {
  58. print "TRM\n";
  59. } elsif ($tag =~ /^"([^"]*)"$/) {
  60. print "$1\n";
  61. } elsif ($tag eq "FP" || $tag eq "PKG") {
  62. if ($tag eq "FP") {
  63. print "Footprint\n";
  64. } else {
  65. print "Package\n";
  66. }
  67. if ($s[$i] =~ /^(\d+)\s*$/) {
  68. print "$s[$i - 1]#$1\n\n";
  69. return;
  70. }
  71. } else {
  72. die "unknown tag \"$tag\"";
  73. }
  74. print "$s[$i]\n\n";
  75. }
  76. while (<>) {
  77. if (/^\$Comp/) {
  78. undef @f;
  79. undef $unit;
  80. next;
  81. }
  82. if (/^U\s+(\d+)/) {
  83. $unit = $1;
  84. }
  85. if (/^F\s+(\d+)\s+"([^"]*)"/) {
  86. $f[$1] = $2;
  87. next;
  88. }
  89. if (/^\$EndComp/) {
  90. #print STDERR "|$f[0]_$f[1]| $unit\n";
  91. for ($i = 0; $i <= $#keys; $i++) {
  92. #print STDERR " |$keys[$i]|\n";
  93. next unless "$f[0]_$f[1]" =~ /^$keys[$i]$/;
  94. $sfx = 'A';
  95. for ($u = $unit; $u > 1; $u--) {
  96. $sfx++;
  97. }
  98. # @@@ hack: we should check in the library if the part
  99. # has multiple units, and generate the component
  100. # reference accordingly.
  101. if ($unit < 2) {
  102. print "$f[0]\n";
  103. &ith($i);
  104. }
  105. print "$f[0]$sfx\n";
  106. &ith($i);
  107. }
  108. }
  109. }
  110. exit unless $#failed > -1;
  111. printf STDERR "The following download%s failed:\n", $#failed ? "s" : "";
  112. for (@failed) {
  113. print STDERR "$_\n";
  114. }
  115. exit if $ignore_errors;
  116. exit(1);