# makeps - make Postscript-files of the archetypes listed in text file whose # filename is passed in 'input' # Variables passed in: # archdir - root of crossfire-src, with a trailing slash # libdir - where archetypes etc. is found BEGIN { # Set colour to 1 if you want colour postscript. colour = 0; if (colour) { xpm2ps = "xpmtoppm | pnmdepth 255 | pnmtops -noturn" ppm2ps = "pnmdepth 255 | pnmtops -noturn" } else { xpm2ps = "xpmtoppm | pnmdepth 255 | ppmtopgm | pnmtops -noturn" ppm2ps = "pnmdepth 255 | ppmtopgm | pnmtops -noturn" } bmaps = libdir "/bmaps"; bmappaths = libdir "/bmaps.paths"; while ((getline < bmappaths) == 1) if ($1 != "#") bmappath[$1] = $2; close(bmappaths) while ((getline < bmaps) == 1) if (("\\" $1) in bmappath) bmap[$2] = bmappath["\\" $1]; close(bmaps); # An array listing which archetypes files need fixing, the value # is the file where it is used. There must be at least one character # between the ~~spec~~'s. oldFS=FS; FS="~~"; oldOFS=OFS; OFS=""; while ((getline < input) == 1) { if (NF > 1) { work_todo = 1; for (i = 2; i < NF; i += 2) if ($i != "") makeps[$i] = 1; } } close(input); FS=oldFS; OFS=oldOFS; if (!work_todo) exit; # An array to reduce the size of the bitmap exponentially. # A 4x8 bitmap will be reduced to 60% of its full size. size_mul[1] = 1; for (i = 2; i <= 12; i++) # Max input is 12x12, a *large* bitmap ;-) size_mul[i] = size_mul[i-1] * 0.9; } $1 == "Object" { if (interesting) { faces[x,y] = face; if (!More && makeps[obj] == 1) makeps[obj] = assemble(); } # Get ready for next archetype if (!More) { xmin = xmax = ymin = ymax = 0; obj = substr($0,8); interesting = obj in makeps; } x = y = 0; More = 0; } $1 == "face" { face = $2 } $1 == "x" { x = $2; if (x > xmax) xmax = x; else if (x < xmin) xmin = x; } $1 == "y" { y = $2; if (y > ymax) ymax = y; else if (y < ymin) ymin = y; } $1 == "More" { More = 1; } $1 == "msg" { do { getline } while ($1 != "endmsg"); } END { # Remember to check the last archetype also... if (interesting) { faces[x,y] = face; if (makeps[obj] == 1) makeps[obj] = assemble(); } system("rm -f work.pbm tmp.pbm"); # clean up a little # We've created a number of Postscript-files - now we need to # patch the filenames and sizes into the TeX-files. FS="~~"; OFS=""; while ((getline < input) == 1) { if (NF > 1) { for (i = 2; i <= NF; i += 2) if ($i in makeps) $i = makeps[$i]; } print; } close(input); } function assemble( w, h, ppm, buff, i, j, bmap_file, ps_file) { bmap_file = archdir bmap[faces[0,0]] ".xpm"; ps_file = faces[0,0] ".ps"; gsub(/[_ ]/, "-", ps_file); w = xmax - xmin + 1; h = ymax - ymin + 1; if ((getline buff < ps_file) != -1) close (ps_file); else { if (w == 1 && h == 1) { # xpmtoppm doesn't understand unresolvable symbolic names # and the colour "none". system(sprintf("sed -e 's/[Nn]one/white/g' -e 's/s [^\t]*\t/\t/' %s | " xpm2ps " > %s", bmap_file, ps_file)); } else { ppm = sprintf("%dx%d.ppm", w, h); if ((getline buff < ppm) != -1) { # print "Got premature EOF on " ppm >> "/dev/stderr"; close(ppm); } else { buf=sprintf("pnmscale -xsc %d -ysc %d < empty.pbm | pgmtoppm white > %s", w, h, ppm); # print "Running " buf >> "/dev/stderr"; system(buf); } system("cp " ppm " work.ppm"); ppm = "work.ppm"; for (i = xmin; i <= xmax; i++) for (j = ymin; j <= ymax; j++) { print "Processing " bmap[faces[i,j]] >> "/dev/stderr"; command = sprintf("sed 's/[Nn]one/white/g' < %s | xpmtoppm > tmp.ppm; pnmpaste tmp.ppm %d %d %s > tmp2.ppm; mv tmp2.ppm %s", archdir bmap[faces[i,j]] ".xpm", (i - xmin) * 24, (j - ymin) * 24, ppm, ppm); # print "Running " command >> "/dev/stderr"; system(command); } command=sprintf("cat %s | " ppm2ps " > %s", ppm, ps_file); # print "Running " command >> "/dev/stderr"; system(command); } } mul = size_mul[int(sqrt(w * h))] * size; # ps = sprintf("\\psfig{figure=" ps_file ",width=%0.2fcm,height=%0.2fcm,rwidth=%0.2fcm}", # w * mul, h * mul, w * mul - 0.15); ps = sprintf("\\psfig{figure=" ps_file ",width=%0.2fcm,height=%0.2fcm}", w * mul, h * mul); if (h == 1) return ps; else return sprintf("\\raisebox{-%0.2fcm}{%s}", (h-1) * mul, ps); }