Path: utzoo!attcan!utgpu!watmath!att!dptg!rutgers!cs.utexas.edu!uunet!mcsun!ukc!edcastle!lfcs!ajcd From: ajcd@lfcs.ed.ac.uk (Angus Duggan) Newsgroups: comp.windows.news Subject: Enhanced psview and DVI previewing (Part 2 of 2) Summary: DVILASER/PS previewing under NeWS code Keywords: psview scrollbars DVILASER/PS Message-ID: <467@castle.ed.ac.uk> Date: 21 Sep 89 14:19:13 GMT Sender: root@castle.ed.ac.uk Reply-To: ajcd@lfcs.ed.ac.uk (Angus Duggan) Organization: Laboratory for the Foundations of Computer Science, University of Edinburgh Lines: 1157 #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of archive 2 (of 2)." # Contents: dvips.opt dvips.pro dviview psmung.c # Wrapped by ajcd@cheops on Thu Sep 21 15:04:05 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'dvips.opt' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dvips.opt'\" else echo shar: Extracting \"'dvips.opt'\" \(875 characters\) sed "s/^X//" >'dvips.opt' <<'END_OF_FILE' X% X% This is the version of DVIPS.OPT distributed with X% the Sun Workstation version of DVILASER/PS. X% The Apollo and VAX/VMS versions differ slightly. X% X% Establish local defaults for DVILASER/PS. X% X% Any DVILASER/PS commands can be placed in this file. For X% example, commands to declare the paper width and height X% as well as which PostScript printer is being used. X% X% tfmpath is set up to use the same tfm files as TeX. X% new paths for pixels and tfms AJCD 23/11/88 X% AJS Changed downloaded fonts => memoryavailable has changed Xprinter LaserWriter memoryavailable 1000000 resolution 300 300 Xpixelpath /usr/local/share/tex/fonts/pk/canon /usr/local/share/tex/fonts/pk/arbor /usr/local/share/tex/fonts/pk/dist /usr/local/share/tex/fonts/pk/agfa Xtfmpath /usr/local/share/tex/fonts/tfm Xheight 11.65in Xwidth 8.22in Xreverse off Xxy 1.3in 1.6in Xdownload all prolog X%verbose END_OF_FILE echo shar: NEWLINE appended to \"'dvips.opt'\" if test 876 -ne `wc -c <'dvips.opt'`; then echo shar: \"'dvips.opt'\" unpacked with wrong size! fi # end of 'dvips.opt' fi if test -f 'dvips.pro' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dvips.pro'\" else echo shar: Extracting \"'dvips.pro'\" \(17432 characters\) sed "s/^X//" >'dvips.pro' <<'END_OF_FILE' X% X% Dvips.pro - included prolog for DviLaser-generated PostScript files. X% X% This version hacked for NeWS previewing - AJCD 22/3/89 X% X% Copyright (c) 1986-88, ArborText, Inc. All Rights Reserved. X% X% This PostScript prolog code is part of the proprietary DVILASER/PS X% program package and may not be copied or re-distributed without X% the permission of ArborText, Inc. X% X X/DeFiNeFoNt /definefont load def X X/definefont { X exch {findfont} stopped X {exch DeFiNeFoNt} X {exch pop} X ifelse X} bind def X Xsystemdict /setpacking known % use array packing mode if its available X {/savepackingmode currentpacking def X true setpacking} X if X X/$DviLaser where X {pop} X {/$DviLaser 200 dict def} X ifelse X X% Begin document X/BeginDviLaserDoc { X vmstatus pop pop 0 eq X { $DviLaser begin X InitializeState } X { /DviLaserJob save def X $DviLaser begin X InitializeState X /DviLaserFonts save def } X ifelse X} bind def X X% End document X/EndDviLaserDoc { X vmstatus pop pop 0 eq X { end } X { DviLaserFonts restore X end X DviLaserJob restore } X ifelse X} bind def X X$DviLaser begin X X/tempstr 64 string def X/tempint 0 def X/tempmatrix matrix def X X% X% Debugging routines X% X/DebugMode false def X X/PrintInt { X tempstr cvs print X} bind def X X/PrintLn { X (\n) print flush X} bind def X X/PrintVMStats { X (VM status - ) print X vmstatus X 3 copy X PrintInt (\(total\), ) print X PrintInt (\(used\), ) print X pop X exch sub X PrintInt (\(remaining\), ) print X PrintInt (\(level\)) print X PrintLn X} bind def X X/VMS /PrintVMStats load def X X/VMSDebug { X DebugMode X {PrintVMStats} X {pop} X ifelse X} bind def X X(beginning of common prolog) VMSDebug X X% Make it easy to bind definitions. X/bdef /def load def %{ bind def } bind def X/xdef { exch def } bdef X X% Begin page X/BP { X /Magnification xdef X /DviLaserPage save def X (beginning of page) VMSDebug X} bdef X X% End page X/EP { X DviLaserPage restore X} bdef X X% Exit page (temporarily) to add fonts/characters. X/XP { X % Save current point information so it can be reset later. X /Xpos where {pop Xpos} {0} ifelse X /Ypos where {pop Ypos} {0} ifelse X {currentpoint} stopped {0 0 moveto currentpoint} if X /DviLaserPage where {pop DviLaserPage restore} if X moveto X /Ypos xdef X /Xpos xdef X} bdef X X% Resume page X/RP { X /DviLaserPage save def X} bdef X X% Purge all fonts to reclaim memory space. X/PF { X GlobalMode X LocalMode X} bdef X X% Switch to base save/restore level, saving state information. X/GlobalMode { X /UserSave where {pop UserSave} if % invoke "UserSave" if available X PortraitMode X PaperWidth X PaperHeight X PxlResolution X Resolution X Magnification X Ymax X RasterScaleFactor X % Save current point information so it can be reset later. X /currentpoint cvx stopped {0 0 moveto currentpoint} if X /DviLaserPage where {pop DviLaserPage restore} if X DviLaserFonts restore X RecoverState X} bdef X X% Preserve state at the base level. X/RecoverState { X 10 copy X /Ypos xdef X /Xpos xdef X /RasterScaleFactor xdef X /Ymax xdef X /Magnification xdef X /Resolution xdef X /PxlResolution xdef X /PaperHeight xdef X /PaperWidth xdef X /PortraitMode xdef X DoInitialScaling X PortraitMode not {PaperWidth 0 SetupLandscape} if X Xpos Ypos moveto X} bdef X X% Initialize state variables to default values. X/InitializeState { X /Resolution 3600.0 def X /PxlResolution 300.0 def X /RasterScaleFactor PxlResolution Resolution div def X /PortraitMode true def X GetPageDimensions X 72.0 div Resolution mul /PaperHeight xdef X 72.0 div Resolution mul /PaperWidth xdef X /Ymax PaperHeight def X /Magnification 1000.0 def X /Xpos 0.0 def X /Ypos 0.0 def X /InitialMatrix {{PSCanvas ps_scale matrix currentmatrix} win send} def X} bdef X X% X% Procedure to figure out the current page dimensions. There unfortunately X% is no direct way to obtain this information. This approach works for X% letter, note, and legal page sizes. X% X% GetPageDimensions X% X/GetPageDimensions { X /PSPageW win send 72.0 mul /PSPageH win send 72.0 mul X} bdef X X% Switch from base save/restore level, restoring state information. X/LocalMode { X /Ypos xdef X /Xpos xdef X /RasterScaleFactor xdef X /Ymax xdef X /Magnification xdef X /Resolution xdef X /PxlResolution xdef X /PaperHeight xdef X /PaperWidth xdef X /PortraitMode xdef X DoInitialScaling X PortraitMode not {PaperWidth 0 SetupLandscape} if X Xpos Ypos moveto X /UserRestore where {pop UserRestore} if % invoke "UserRestore" if available X /DviLaserFonts save def X /DviLaserPage save def X} bdef X X% Abbreviations X/S /show load def X/SV /save load def X/RST /restore load def X X/Yadjust {Ymax exch sub} bdef X X% (x,y) position absolute, just set Xpos & Ypos, don't move. X/SXY { X Yadjust X /Ypos xdef /Xpos xdef X} bdef X X% (x,y) position absolute X/XY { X Yadjust X 2 copy /Ypos xdef /Xpos xdef X moveto X} bdef X X% (x,0) position absolute X/X { X currentpoint exch pop X 2 copy /Ypos xdef /Xpos xdef X moveto X} bdef X X% (0,y) position absolute X/Y { X currentpoint pop exch Yadjust X 2 copy /Ypos xdef /Xpos xdef X moveto X} bdef X X% (x,y) position relative X/xy { X neg rmoveto X currentpoint /Ypos xdef /Xpos xdef X} bdef X X% (x,0) position relative X/x { X 0.0 rmoveto X currentpoint /Ypos xdef /Xpos xdef X} bdef X X% (0,y) position relative X/y { X 0.0 exch neg rmoveto X currentpoint /Ypos xdef /Xpos xdef X } bdef X X% Print a rule X/R { X /ht xdef X /wd xdef X gsave X 0 setgray X currentpoint X newpath X moveto X 0.0 ht rlineto X wd 0.0 rlineto X 0.0 ht neg rlineto X wd neg 0.0 rlineto X closepath fill X grestore X wd 0.0 rmoveto X currentpoint /Ypos xdef /Xpos xdef X} bdef X X% X% RES X% X/RES { X /Resolution xdef X /PxlResolution xdef X /RasterScaleFactor PxlResolution Resolution div def X DoInitialScaling X} bdef X X% X% Do initial scaling. X% X/DoInitialScaling { X InitialMatrix setmatrix X 72.0 Resolution div dup scale X} bdef X X% X% PM X% X/PM { X XP X /PaperWidth xdef X /PaperHeight xdef X /Ymax PaperHeight def X /PortraitMode true def X DoInitialScaling X RP X} bdef X X% X% LM X% X/LM { X XP X /PaperWidth xdef X /PaperHeight xdef X /Ymax PaperWidth def X /PortraitMode false def X DoInitialScaling X PaperWidth 0 SetupLandscape X RP X} bdef X X% Change magnification setting X/MAG { X XP X /Magnification xdef X RP X} bdef X X% X% Switch to landscape mode X% X/SetupLandscape { X translate X 90.0 rotate X} bdef X X% X% SPB - begin "\special" mode X% X% This is the PostScript procedure used to transfer from the internal X% environment used for the DVI translation code emitted by DVIPS to X% a standard PostScript environment. X% X% Parameters: 0 - Local X% 1 - Global X% 2 - Inline X% X/SPB { X /spc_mode xdef X spc_mode 0 eq spc_mode 2 eq or X {XP} X {spc_mode 1 eq {GlobalMode} if} X ifelse X Resolution 72.0 div dup scale % Restore default scaling... X Magnification 1000.0 div dup scale % Adjust for any magnification... X /Xpos Xpos 72.0 Resolution div mul 1000.0 Magnification div mul def X /Ypos Ypos 72.0 Resolution div mul 1000.0 Magnification div mul def X} bdef X X% X% SPE - end "\special" mode X% X% This is the PostScript procedure used to reenter the internal X% environment used for the DVI translation code emitted by DVIPS from X% the standard PostScript environment provided for processing user-supplied X% PostScript code. X% X% Parameters: 0 - Local X% 1 - Global X% 2 - Inline X% X/SPE { X /spc_mode xdef X 1000.0 Magnification div dup scale % Un-adjust for any magnification... X 72.0 Resolution div dup scale % Restore default internal scaling... X spc_mode 0 eq spc_mode 2 eq or X {RP} X {spc_mode 1 eq {LocalMode} if} X ifelse X} bdef X X% X% PP X% X/PP { X /#copies xdef X showpage X /#copies 1 def X} bdef X X% X% CLRP X% X/CLRP { X% erasepage X} bdef X X% X% /font-name DMF X% X/DMF { X /psz xdef X /nam xdef X nam findfont psz scalefont setfont X} bdef X X% X% /abcd (xxx) str-concat ==> /abcdxxx X% X/str-concatstr 64 string def X X/str-concat { X /xxx xdef X /nam xdef X /namstr nam str-concatstr cvs def X /newnam namstr length xxx length add string def X newnam 0 namstr putinterval X newnam namstr length xxx putinterval X newnam cvn X} bdef X X% X% /abcdef 2 str-strip ==> /cdef X% X/str-strip { X /num xdef X /nam xdef X /namstr nam tempstr cvs def X /newlen namstr length num sub def X namstr num newlen getinterval X cvn X} bdef X X% X% copydict ==> new-dict on stack X% X/copydict { X dup length 1 add dict /newdict xdef X {1 index /FID ne X {newdict 3 1 roll put} X {pop pop} X ifelse X } forall X newdict X} bdef X X% X% DefineCMEncoding X% X/DefineCMEncoding { X /EncodeType xdef X X /CMEncoding 256 array def X /Times-Roman findfont /Encoding get aload pop CMEncoding astore pop X X EncodeType 11 eq {Do-CM-rm-encoding} if X EncodeType 12 eq {Do-CM-it-encoding} if X EncodeType 13 eq {Do-CM-tt-encoding} if X} bdef X X% X% Do special mappings for the various CM-font types. Characters that X% get "covered up" are repositioned in the range (128,128+32). X% X/Do-standard-CM-encodings { X CMEncoding X dup 0 /.notdef put X dup 1 /.notdef put X dup 2 /.notdef put X dup 3 /.notdef put X dup 4 /.notdef put X dup 5 /.notdef put X dup 6 /.notdef put X dup 7 /.notdef put X X dup 8 /.notdef put X dup 9 /.notdef put X dup 10 /.notdef put X dup 11 /.notdef put X dup 12 /fi put X dup 13 /fl put X dup 14 /.notdef put X dup 15 /.notdef put X X dup 16 /dotlessi put X dup 17 /.notdef put X dup 18 /grave put X dup 19 /acute put X dup 20 /caron put X dup 21 /breve put X dup 22 /macron put X dup 23 /ring put X X dup 24 /cedilla put X dup 25 /germandbls put X dup 26 /ae put X dup 27 /oe put X dup 28 /oslash put X dup 29 /AE put X dup 30 /OE put X dup 31 /Oslash put X dup 127 /dieresis put X X dup 128 /space put X dup 129 /quotedbl put X dup 130 /sterling put X dup 131 /dollar put X dup 132 /less put X dup 133 /greater put X dup 134 /backslash put X dup 135 /asciicircum put X dup 136 /underscore put X dup 137 /braceleft put X dup 138 /bar put X dup 139 /braceright put X dup 140 /asciitilde put X pop X} bdef X X/Do-CM-rm-encoding { X Do-standard-CM-encodings X CMEncoding X dup 32 /.notdef put X dup 34 /quotedblright put X dup 60 /exclamdown put X dup 62 /questiondown put X dup 92 /quotedblleft put X dup 94 /circumflex put X dup 95 /dotaccent put X dup 123 /endash put X dup 124 /emdash put X dup 125 /hungarumlaut put X dup 126 /tilde put X pop X} bdef X X/Do-CM-it-encoding { X Do-standard-CM-encodings X CMEncoding X dup 32 /.notdef put X dup 34 /quotedblright put X dup 36 /sterling put X dup 60 /exclamdown put X dup 62 /questiondown put X dup 92 /quotedblleft put X dup 94 /circumflex put X dup 95 /dotaccent put X dup 123 /endash put X dup 124 /emdash put X dup 125 /hungarumlaut put X dup 126 /tilde put X pop X} bdef X X/Do-CM-tt-encoding { X Do-standard-CM-encodings X CMEncoding X dup 12 /.notdef put X dup 13 /quotesingle put X dup 14 /exclamdown put X dup 15 /questiondown put X pop X} bdef X X% X% DefineCMFont X% X% type 10: "as-is" PostScript font X% type 11: CM-mapped PostScript font - roman X% type 12: CM-mapped PostScript font - text italic X% type 13: CM-mapped PostScript font - typewriter type X% X/int-dict-name {int (-dict) str-concat} bdef X/int-dict {int (-dict) str-concat cvx load} bdef X X/DF { X true % signal that the font is already loaded X DefineCMFont X} bdef X X/DNF { X false % signal that the font is not already loaded X DefineCMFont X} bdef X X/DefineCMFont { X /loaded xdef X /typ xdef X /psz xdef X /ext xdef X /int xdef X X typ 10 ne X { % font_type = 11, 12, 13 X loaded not X { /fnam ext 3 str-strip def X fnam findfont copydict /newdict xdef X typ DefineCMEncoding X newdict /Encoding CMEncoding put X ext newdict definefont pop X } if X% int-dict-name ext findfont psz scalefont def X% currentdict int [int-dict /setfont cvx] cvx put X currentdict int [ext findfont psz scalefont /setfont cvx] cvx put X } X { % font_type = 10 X% /fnam ext def X% int-dict-name fnam findfont psz scalefont def X% currentdict int [int-dict /setfont cvx] cvx put X currentdict int [ext findfont psz scalefont /setfont cvx] cvx put X } X ifelse X} bdef X X% X% X% [llx lly urx ury] DefinePXLFont X% X X/PXLF { X true % signal that the font is already loaded X DefinePXLFont X} bdef X X/PXLNF { X false % signal that the font is not already loaded X DefinePXLFont X} bdef X X/PXLBuildCharDict 17 dict def X X/CMEncodingArray 256 array def X0 1 255 {CMEncodingArray exch dup tempstr cvs cvn put} for X X/RasterConvert {RasterScaleFactor div} bdef X X/TransformBBox { X aload pop X X /BB-ury xdef X /BB-urx xdef X /BB-lly xdef X /BB-llx xdef X X [BB-llx RasterConvert BB-lly RasterConvert X BB-urx RasterConvert BB-ury RasterConvert] X} bdef X X/DefinePXLFont { X /newfont xdef X /bb xdef X /num xdef X /psz xdef X /dsz xdef X /pxlmag xdef X /ext xdef X /int xdef X X /fnam ext (-) str-concat pxlmag tempstr cvs str-concat def X X newfont not { X int-dict-name 13 dict def X X int-dict begin X /FontType 3 def X /FontMatrix [1 dsz div 0 0 1 dsz div 0 0] def X /FontBBox bb TransformBBox def X /Encoding CMEncodingArray def X /BuildChar X { X PXLBuildCharDict begin X /char xdef X /fontdict xdef X X fontdict /CharDict get /Char-Info get char get aload pop X X /rasters xdef X /cols xdef X /rows xdef X /wx xdef X /ury xdef X /urx xdef X /lly xdef X /llx xdef X X rows 0 lt X { /rows rows neg def X /runlength 1 def } X { /runlength 0 def } X ifelse X X wx 0 X llx RasterConvert lly RasterConvert X urx RasterConvert ury RasterConvert setcachedevice X rows 0 ne X { X gsave X llx .5 add lly .5 add translate X cols rows scale % work around NeWS bugs X true rasters imagemaskcanvas X grestore X } if X end X } def X /CharDict 1 dict def X CharDict /Char-Info num array put X end X fnam int-dict definefont pop X } if X X% int-dict-name fnam findfont psz scalefont def X% currentdict int [int-dict /setfont cvx] cvx put X currentdict int [fnam findfont psz scalefont /setfont cvx] cvx put X} bdef X X% X% PXLC X% X/PXLC { X X /rasters xdef X /runlength xdef X /cols xdef X /rows xdef X /ury xdef X /urx xdef X /lly xdef X /llx xdef X /wx xdef X /code xdef X /int xdef X X % See if the long or short format is required X% true cols CKSZ rows CKSZ ury CKSZ urx CKSZ lly CKSZ llx CKSZ X TackRunLengthToRows X int-dict /CharDict get /Char-Info get code X [llx lly urx ury wx rows cols % rasters => build canvas for NeWS X cols rows 1 [RasterScaleFactor 0 0 RasterScaleFactor neg 0 0] X GenerateRasters buildimage X ] put X} bdef X X/CKSZ {abs 127 le and} bdef X/TackRunLengthToRows {runlength 0 ne {/rows rows neg def} if} bdef X X% X% PLOTC X% X/PLOTC { X /rasters xdef X /runlength xdef X /cols xdef X /rows xdef X /ury xdef X /urx xdef X /lly xdef X /llx xdef X /psz xdef X /dsz xdef X /wx xdef X X % "Plot" a character's raster pattern. X rows 0 ne X { X gsave X currentpoint translate X psz dsz div dup scale X% cols rows scale % work around NeWS bugs X% llx ury moveto % NeWS ignores imagemask matrix X cols rows true X RasterScaleFactor 0 0 RasterScaleFactor neg llx .5 add neg ury .5 add X tempmatrix astore X GenerateRasters imagemask X grestore X } if X wx x X} bdef X X% Routine to generate rasters for "imagemask". X/GenerateRasters { X rasters X runlength 1 eq {RunLengthToRasters} if X} bdef X X% Routine to convert from runlength encoding back to rasters. X/RunLengthToRasters { X % ...not done yet... X} bdef X X% X% These procedures handle bitmap processing. X% X% BMbeg X% X/BMbeg { X /BMmagnification xdef X /BMresolution xdef X /BMrows xdef X /BMcols xdef X X /BMcurrentrow 0 def X gsave X 0.0 setgray X Resolution BMresolution div dup scale X currentpoint translate X BMmagnification 1000.0 div dup scale X 0.0 BMrows moveto X BMrows dup scale X currentpoint translate X /BMCheckpoint save def X } bdef X X/BMend { X BMCheckpoint restore X grestore X } bdef X X% X% BMswath X% X/BMswath { X /rows xdef X /rasters xdef X X BMcols rows true X [BMrows 0 0 BMrows neg 0 BMcurrentrow neg] X rasters X imagemask X X /BMcurrentrow BMcurrentrow rows add def X BMcurrentrow % save this on the stack around a restore... X BMCheckpoint restore X /BMcurrentrow xdef X /BMCheckpoint save def X } bdef X X(end of common prolog) VMSDebug X Xend X Xsystemdict /setpacking known X {savepackingmode setpacking} X if X X% X% End of included prolog section. X% END_OF_FILE echo shar: NEWLINE appended to \"'dvips.pro'\" if test 17433 -ne `wc -c <'dvips.pro'`; then echo shar: \"'dvips.pro'\" unpacked with wrong size! fi # end of 'dvips.pro' fi if test -f 'dviview' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dviview'\" else echo shar: Extracting \"'dviview'\" \(201 characters\) sed "s/^X//" >'dviview' <<'END_OF_FILE' Xif [ "$#" != "1" ] Xthen X echo "usage: $0 file.dvi" X exit 1 Xfi Xdvips -nodialog -OPT $NEWSHOME/lib/dvips.opt -FNT $NEWSHOME/lib/dvips.fnt -PRO $NEWSHOME/lib/dvips.pro -dvi $1 -ps - | psmung | psview -a4 END_OF_FILE echo shar: NEWLINE appended to \"'dviview'\" if test 202 -ne `wc -c <'dviview'`; then echo shar: \"'dviview'\" unpacked with wrong size! fi chmod +x 'dviview' # end of 'dviview' fi if test -f 'psmung.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'psmung.c'\" else echo shar: Extracting \"'psmung.c'\" \(4474 characters\) sed "s/^X//" >'psmung.c' <<'END_OF_FILE' X/* psmung.c X * X * This program takes the output of ArborText's dvips and mungs it for NeWS X * previewing. This consists of putting all of the font definitions into X * the end of the prologue. X * Fonts definitions are started by lines of the form X * X * XP /F25 /cmr10 .... RP X * X * Character definitions are started by lines of the form X * X * XP /F25 100 .... X * .... RP X */ X X#include X#include X X/* Reading and Writing files is done a line at a time by the functions X * X * char * GetLine(FILE *stream, char *line) X * PutLine(FILE *stream, char *line) X */ X X Xchar line[BUFSIZ]; X X#define GetLine(stream,line) fgets(line,BUFSIZ,stream) X#define PutLine(stream,line) fputs(line,stream) X X X/* search states */ X#define SCANNING 0 X#define SKIPPING 1 X#define COPYING 2 X X X#define GetNumber(num,ptr) while (isdigit(*ptr)) num = num * 10 + *ptr++ - '0' X#define SkipSpace(ptr) while (isspace(*ptr)) ptr++ X X Xstruct FontInfo { X struct FontInfo *next; X int number; X char named; X char bits[256]; X} *Fontlist; X X#define GetNamed(fptr) ((*fptr).named) X#define SetNamed(fptr) (*fptr).named = 1 X X/*#define GetLetter(fptr,letter) ((*fptr).bits[letter>>3] & (1<<(letter&3))) X#define SetLetter(fptr,letter) (*fptr).bits[letter>>3] |= (1<<(letter&3))*/ X#define GetLetter(fptr,letter) ((*fptr).bits[letter]) X#define SetLetter(fptr,letter) (*fptr).bits[letter] = 1 X X X/* find font array if available, create and clear otherwise */ Xstruct FontInfo *FindFont(font) X int font; X{ X struct FontInfo *fptr = Fontlist; X X while (fptr) { /* linear search for font number */ X if ((*fptr).number == font) X return fptr; X fptr = (*fptr).next; X } X /* number not found: create new entry and link in */ X fptr = (struct FontInfo *)calloc((unsigned)1, X (unsigned)sizeof(struct FontInfo)); X (*fptr).next = Fontlist; X (*fptr).number = font; X Fontlist = fptr; X return fptr; X} X X X/* test if 'RP' found and chop before it */ Xint FoundRP(str) X char *str; X{ X while (*str) { X if (*str++ == 'R') X if (*str == 'P') { X *str = '\0'; X *--str = '\n'; X return 1; X } X } X return 0; X} X X X/* Here we go, here we go, here we go... */ Xmain(argc,argv) X int argc; X char *argv[]; X{ X int state; X FILE *pages; X char *tmpname="/tmp/ps.XXXXXX"; X X Fontlist = NULL; /* initialise font list */ X X /* (re)open stdin file */ X /* (re)open stdout file */ X X pages = fopen(mktemp(tmpname),"w+"); /* open pages file */ X X while (GetLine(stdin,line) && strncmp(line,"%%EndProlog",11)) X PutLine(stdout,line); /* pass header straight through */ X X PutLine(pages,line); /* save first non-header line */ X X PutLine(stdout,"XP\n"); X X state = SCANNING; X while (GetLine(stdin,line)) { X switch (state) { X case SCANNING: /* scan for XP lines */ X if (!strncmp(line,"XP /F",5)) { /* XP_/F found */ X char *cptr = &line[5]; X int fontnum = 0; X struct FontInfo *fontptr; X X GetNumber(fontnum,cptr); /* parse font number */ X SkipSpace(cptr); /* skip white space */ X fontptr = FindFont(fontnum); /* find font record */ X X if (*cptr == '/') { /* font definition found */ X if (GetNamed(fontptr)) { /* check if font definition already done */ X if (!FoundRP(line)) X state = SKIPPING; X } X else { X SetNamed(fontptr); X if (!FoundRP(line)) X state = COPYING; X PutLine(stdout,&line[3]); /* put line without XP & RP */ X } X } X else if (isdigit(*cptr)) { /* character definition found */ X int letter = 0; X GetNumber(letter,cptr); /* parse char number */ X if (!GetNamed(fontptr)) X fprintf(stderr,"Warning: font %d not defined (char %d)\n", X fontnum,letter); X if (GetLetter(fontptr,letter)) { /* check if letter already done */ X if (!FoundRP(line)) X state = SKIPPING; X } X else { X SetLetter(fontptr,letter); X if (!FoundRP(line)) X state = COPYING; X PutLine(stdout,&line[3]); /* put line without XP & RP */ X } X } X else fprintf(stderr,"Ignoring line:\n %s",line); X } else PutLine(pages,line); X break; X case SKIPPING: /* skipping to RP */ X if (FoundRP(line)) X state = SCANNING; X break; X case COPYING: /* copying to RP */ X if (FoundRP(line)) /* FoundRP chops line */ X state = SCANNING; X PutLine(stdout,line); X break; X } X } X X PutLine(stdout,"RP\n"); X X rewind(pages); /* goto start of pages file */ X while (GetLine(pages,line)) X PutLine(stdout,line); /* copy pages to output */ X X fclose(pages); /* close pages file */ X /* delete pages file */ X} END_OF_FILE echo shar: NEWLINE appended to \"'psmung.c'\" if test 4475 -ne `wc -c <'psmung.c'`; then echo shar: \"'psmung.c'\" unpacked with wrong size! fi # end of 'psmung.c' fi echo shar: End of archive 2 \(of 2\). cp /dev/null ark2isdone MISSING="" for I in 1 2 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked both archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 Angus Duggan, Department of Computer Science, | University of Edinburgh, JCMB, | USENET: ajcd@lfcs.ed.ac.uk The King's Buildings, Mayfield Road, | JANET: ajcd@uk.ac.ed.lfcs Edinburgh, EH9 3JZ, Scotland. | OR: ajcd%lfcs.ed.ac.uk@nsfnet-relay.ac.uk