6 # This script is used to extract all elements from an "oldlib" (M4)
7 # style library and place them in individual "newlib" style files.
10 contents
=pcblib.contents
19 $0 [-c|--contents contents_file] [-o|--output output_directory] [-p|--png] [-d|--dpi]
21 Extracts all footprints from an m4 library and creates a "newlib" style
24 The following options are supported:
26 -a | --awk awk : Specifies the awk implementation to use. Defaults to "${AWK}".
28 -c | --contents file : Specifies the contents file to be use as an input.
29 Default is "${contents}".
31 -d | --dpi : Specifies that the png output should use a fixed pixels
32 per inch scaling instead of a fixed maximum size. This
33 option is useful when comparing the before and after footprints
34 when making footprint library changes.
36 -h | --help : Outputs this message and exits.
38 -o | --output dir : Specifies the directory that the newlib library will be
39 written to. This directory must exist and be empty.
42 -P | --pcb pcb : Specifies the pcb binary to use for creating png previews. Defaults to
45 -p | --png : Generates png previews for all the footprints.
47 -v | --version : Displays the version of this script and exits.
53 $AWK '/# [\$]Id:.*$/ {sub(/,v/,""); \
54 print $3 " Version "$4", "$5}' $0
58 png_flag
="--xy-max 200"
60 while test $# -gt 0 ; do
103 echo "ERROR: $0: Unknown option $1"
115 if test -d ${outd} ; then
116 echo "Output directory ${outd} already exists"
121 outd_full
="`cd $outd && pwd`"
130 # we have to use this trick because variables like outd are not yet defined
133 brokenurl = "broken.html";
134 broken = outd "/" brokenurl;
137 ind = outd "/index.html";
139 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > ind;
140 print "<HTML><HEAD><TITLE>PCB Footprint Library</TITLE></HEAD>" >> ind;
141 print "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\">" >> ind;
142 print "<H1>PCB Footprint Library</H1>" >> ind;
146 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > broken;
147 print "<HTML><BODY>" >> broken;
148 print "<TABLE BORDER=2>" >> broken;
149 print "<TR><TD><EM>Library</EM></TD>" >> broken;
150 print " <TD><EM>Comment</EM></TD>" >> broken;
151 print " <TD><EM>Footprint Name</EM></TD>" >> broken;
152 print " <TD><EM>Broken Command</EM></TD>" >> broken;
153 print "</TR>" >> broken;
159 # we are starting a new library
163 gsub(/TYPE=~/, "", lib);
166 gsub(/ /, "%20", urldir);
168 libind = outd "/" lib "/index.html";
169 #gsub(/ /, "\\ ", libind);
172 gsub(/ /,"\\ ", dir);
173 print "Processing library: " lib " and creating " libind;
174 system("mkdir -p " dir);
176 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">" > libind;
177 print "<HTML><HEAD><TITLE>PCB " lib " Footprint Library</TITLE></HEAD>" >> libind;
178 print "<BODY bgcolor=\"#FFFFFF\" text=\"#000000\">" >> libind;
179 print "<H1>PCB " lib " Footprint Library</H1>" >> libind;
181 print "<TABLE BORDER=2>" >> libind;
182 print "<TR>" >> libind;
183 print " <TD><EM>Comment</EM></TD>" >> libind;
184 print " <TD><EM>Footprint Name</EM></TD>" >> libind;
185 print "</TR>" >> libind;
188 print "<LI><A HREF=\"" txtdir "/index.html\">~" lib "</A></LI>" >> ind;
195 split(line, a, "[:]");
197 # pick out the name of the footprint
202 # escape the spaces in for URLs and also filenames
203 gsub(/ /, "%20", urlcomp);
204 gsub(/ /, "\\ ", comp);
208 # extract the footprint
209 # path library template value package
211 gsub(/ /, "\\ ", templ);
214 gsub(/ /, "\\ ", pkg);
217 # skip the QFP builder menu
219 if( templ == "menu_qfp" ) {
220 cmd1 = "Skipping QFP builder menu";
223 cmd1 = "sh " cmd_path "/QueryLibrary.sh . pcblib " templ " " comp " " pkg;
224 cmd = cmd1 " > " dir "/" comp ".fp";
229 printf("<TR><TD>~%s</TD>\n", lib) >> broken;
230 printf(" <TD>%s</TD>\n", comp) >> broken;
231 printf(" <TD>%s</TD>\n", comment) >> broken;
232 printf(" <TD>%s</TD>\n", cmd1) >> broken;
233 printf("</TR>\n") >> broken;
235 # no need to go further with this footprint. It is broken.
238 # generate the web index
239 printf(" <TR>\n <TD>%s</TD>\n", comment) >> libind;
240 printf(" <TD><A HREF=\"%s.fp\">%s.fp</A>", txtcomp, txtcomp) >> libind;
242 printf("(<A HREF=\"%s.png\">preview</A>)", txtcomp) >> libind;
244 printf("</TD>\n </TR>\n") >> libind;
247 # Now create a layout with that element and print it.
249 layout = "temp.pcb" ;
250 laytmpl = "footprint.pcb" ;
251 compfile = dir "/" comp ".fp";
252 pngfile = dir "/" comp ".png";
253 compfile2 = compfile;
254 gsub(/\\/, "", compfile2);
256 printf(" ===> %s\n", compfile);
259 while ( (getline < laytmpl) == 1 ) {
260 if( $0 ~ /ELEMENT/ ) {
269 while( (x = getline < compfile2) == 1 ) {
275 while( (getline < laytmpl) == 1 ) {
279 if( $0 ~ /ELEMENT/ ) {
286 cmd = PCB " -x png --outfile temp.png ${png_flag} --only-visible " layout " 2>&1 > /dev/null" ;
289 printf("<TR><TD>~%s</TD>\n", lib) >> broken;
290 printf(" <TD>%s</TD>\n", comp) >> broken;
291 printf(" <TD>%s</TD>\n", comment) >> broken;
292 printf(" <TD>%s</TD>\n", cmd) >> broken;
293 printf("</TR>\n") >> broken;
295 system( "mv temp.png " pngfile " ; rm " layout);
302 print "</UL>" >> ind;
304 print "<P>For a list of footprints with either m4 syntax errors" >> ind;
305 print "or PCB syntax errors see <A HREF=\"" brokenurl "\">the broken log file.</A></P>" >> ind;
306 print "</BODY></HTML>" >> ind;
310 print "</TABLE>" >> broken;
312 print "</BODY></HTML>" >> broken;
318 function finish_libind() {
321 print "</TABLE>" >> libind;
323 print "</BODY></HTML>" >> libind;
328 ' cmd_path
=.
/ do_png
=$do_png outd
="$outd_full" awk=$AWK PCB
="${PCB}" $contents