3 # This script is used to extract all elements from an "oldlib" (M4)
4 # style library and place them in individual "newlib" style files.
7 contents
=pcblib.contents
16 $0 [-c|--contents contents_file] [-o|--output output_directory] [-p|--png] [-d|--dpi]
18 Extracts all footprints from an m4 library and creates a "newlib" style
21 The following options are supported:
23 -a | --awk awk : Specifies the awk implementation to use. Defaults to "${AWK}".
25 -c | --contents file : Specifies the contents file to be use as an input.
26 Default is "${contents}".
28 -d | --dpi : Specifies that the png output should use a fixed pixels
29 per inch scaling instead of a fixed maximum size. This
30 option is useful when comparing the before and after footprints
31 when making footprint library changes.
33 -h | --help : Outputs this message and exits.
35 -o | --output dir : Specifies the directory that the newlib library will be
36 written to. This directory must exist and be empty.
39 -P | --pcb pcb : Specifies the pcb binary to use for creating png previews. Defaults to
42 -p | --png : Generates png previews for all the footprints.
44 -v | --version : Displays the version of this script and exits.
50 $AWK '/# [\$]Id:.*$/ {sub(/,v/,""); \
51 print $3 " Version "$4", "$5}' $0
55 png_flag
="--xy-max 200"
57 while test $# -gt 0 ; do
100 echo "ERROR: $0: Unknown option $1"
112 if test -d ${outd} ; then
113 echo "Output directory ${outd} already exists"
118 outd_full
="`cd $outd && pwd`"
127 # we have to use this trick because variables like outd are not yet defined
130 brokenurl = "broken.html";
131 broken = outd "/" brokenurl;
134 ind = outd "/index.html";
136 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > ind;
137 print "<HTML><HEAD><TITLE>PCB Footprint Library</TITLE></HEAD>" >> ind;
138 print "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\">" >> ind;
139 print "<H1>PCB Footprint Library</H1>" >> ind;
143 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > broken;
144 print "<HTML><BODY>" >> broken;
145 print "<TABLE BORDER=2>" >> broken;
146 print "<TR><TD><EM>Library</EM></TD>" >> broken;
147 print " <TD><EM>Comment</EM></TD>" >> broken;
148 print " <TD><EM>Footprint Name</EM></TD>" >> broken;
149 print " <TD><EM>Broken Command</EM></TD>" >> broken;
150 print "</TR>" >> broken;
156 # we are starting a new library
160 gsub(/TYPE=~/, "", lib);
163 gsub(/ /, "%20", urldir);
165 libind = outd "/" lib "/index.html";
166 #gsub(/ /, "\\ ", libind);
169 gsub(/ /,"\\ ", dir);
170 print "Processing library: " lib " and creating " libind;
171 system("mkdir -p " dir);
173 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > libind;
174 print "<HTML><HEAD><TITLE>PCB " lib " Footprint Library</TITLE></HEAD>" >> libind;
175 print "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\">" >> libind;
176 print "<H1>PCB " lib " Footprint Library</H1>" >> libind;
178 print "<TABLE BORDER=2>" >> libind;
179 print "<TR>" >> libind;
180 print " <TD><EM>Comment</EM></TD>" >> libind;
181 print " <TD><EM>Footprint Name</EM></TD>" >> libind;
182 print "</TR>" >> libind;
185 print "<LI><A HREF=\"" txtdir "/index.html\">~" lib "</A></LI>" >> ind;
192 split(line, a, "[:]");
199 # pick out the name of the footprint
200 match (comment, /(.*)\[(.*)\]/, fp);
202 comment = a[3] ", " fp[1];
207 # escape the spaces in for URLs and also filenames
208 gsub(/ /, "%20", urlcomp);
209 gsub(/ /, "\\ ", comp);
212 # extract the footprint
213 # path library template value package
215 gsub(/ /, "\\ ", templ);
218 gsub(/ /, "\\ ", pkg);
221 # skip the QFP builder menu
223 if( templ == "menu_qfp" ) {
224 cmd1 = "Skipping QFP builder menu";
227 cmd1 = "sh " cmd_path "/QueryLibrary.sh . pcblib " templ " " comp " " pkg;
228 cmd = cmd1 " > " dir "/" comp ".fp";
233 printf("<TR><TD>~%s</TD>\n", lib) >> broken;
234 printf(" <TD>%s</TD>\n", comp) >> broken;
235 printf(" <TD>%s</TD>\n", comment) >> broken;
236 printf(" <TD>%s</TD>\n", cmd1) >> broken;
237 printf("</TR>\n") >> broken;
239 # no need to go further with this footprint. It is broken.
242 # generate the web index
243 printf(" <TR>\n <TD>%s</TD>\n", comment) >> libind;
244 printf(" <TD><A HREF=\"%s.fp\">%s.fp</A>", txtcomp, txtcomp) >> libind;
246 printf("(<A HREF=\"%s.png\">preview</A>)", txtcomp) >> libind;
248 printf("</TD>\n </TR>\n") >> libind;
251 # Now create a layout with that element and print it.
253 layout = "temp.pcb" ;
254 laytmpl = "footprint.pcb" ;
255 compfile = dir "/" comp ".fp";
256 pngfile = dir "/" comp ".png";
257 compfile2 = compfile;
258 gsub(/\\/, "", compfile2);
260 printf(" ===> %s\n", compfile);
263 while ( (getline < laytmpl) == 1 ) {
264 if( $0 ~ /ELEMENT/ ) {
273 while( (x = getline < compfile2) == 1 ) {
279 while( (getline < laytmpl) == 1 ) {
283 if( $0 ~ /ELEMENT/ ) {
290 cmd = PCB " -x png --outfile temp.png ${png_flag} --only-visible " layout " 2>&1 > /dev/null" ;
293 printf("<TR><TD>~%s</TD>\n", lib) >> broken;
294 printf(" <TD>%s</TD>\n", comp) >> broken;
295 printf(" <TD>%s</TD>\n", comment) >> broken;
296 printf(" <TD>%s</TD>\n", cmd) >> broken;
297 printf("</TR>\n") >> broken;
299 system( "mv temp.png " pngfile " ; rm " layout);
306 print "</UL>" >> ind;
308 print "<P>For a list of footprints with either m4 syntax errors" >> ind;
309 print "or PCB syntax errors see <A HREF=\"" brokenurl "\">the broken log file.</A></P>" >> ind;
310 print "</BODY></HTML>" >> ind;
314 print "</TABLE>" >> broken;
316 print "</BODY></HTML>" >> broken;
322 function finish_libind() {
325 print "</TABLE>" >> libind;
327 print "</BODY></HTML>" >> libind;
332 ' cmd_path
=.
/ do_png
=$do_png outd
="$outd_full" awk=$AWK PCB
="${PCB}" $contents