lee@uhccux.uhcc.Hawaii.Edu (Greg Lee ) (10/22/88)
Posting-number: Volume 5, Issue 2 Submitted-by: "Greg Lee " <lee@uhccux.uhcc.Hawaii.Edu> Archive-name: lwf/Part2 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 2 (of 3)." # Contents: X.h lwf.c # Wrapped by lee@uhccux on Wed Oct 19 17:12:33 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'X.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'X.h'\" else echo shar: Extracting \"'X.h'\" \(18246 characters\) sed "s/^X//" >'X.h' <<'END_OF_FILE' X/* X * $Header: X.h,v 1.65 87/09/07 14:57:14 toddb Exp $ X */ X X/* Definitions for the X window system likely to be used by applications */ X X#ifndef X_H X#define X_H X X/*********************************************************** XCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts. X X All Rights Reserved X XPermission to use, copy, modify, and distribute this software and its Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Digital or MIT not be Xused in advertising or publicity pertaining to distribution of the Xsoftware without specific, written prior permission. X XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS XSOFTWARE. X X******************************************************************/ X#define X_PROTOCOL 11 /* current protocol version */ X#define X_PROTOCOL_REVISION 0 /* current minor version */ X X/* Resources */ X Xtypedef unsigned long XID; X Xtypedef XID Window; Xtypedef XID Drawable; Xtypedef XID Font; Xtypedef XID Pixmap; Xtypedef XID Cursor; Xtypedef XID Colormap; Xtypedef XID GContext; Xtypedef XID KeySym; X Xtypedef unsigned long Mask; X Xtypedef unsigned long Atom; X Xtypedef unsigned long VisualID; X Xtypedef unsigned long Time; X Xtypedef unsigned char KeyCode; X X/***************************************************************** X * RESERVED RESOURCE AND CONSTANT DEFINITIONS X *****************************************************************/ X X#define None 0L /* universal null resource or null atom */ X X#define ParentRelative 1L /* background pixmap in CreateWindow X and ChangeWindowAttributes */ X X#define CopyFromParent 0L /* border pixmap in CreateWindow X and ChangeWindowAttributes X special VisualID and special window X class passed to CreateWindow */ X X#define PointerWindow 0L /* destination window in SendEvent */ X#define InputFocus 1L /* destination window in SendEvent */ X X#define PointerRoot 1L /* focus window in SetInputFocus */ X X#define AnyPropertyType 0L /* special Atom, passed to GetProperty */ X X#define AnyKey 0L /* special Key Code, passed to GrabKey */ X X#define AnyButton 0L /* special Button Code, passed to GrabButton */ X X#define AllTemporary 0L /* special Resource ID passed to KillClient */ X X#define CurrentTime 0L /* special Time */ X X#define NoSymbol 0L /* special KeySym */ X X/***************************************************************** X * EVENT DEFINITIONS X *****************************************************************/ X X/* Input Event Masks. Used as event-mask window attribute and as arguments X to Grab requests. Not to be confused with event names. */ X X#define NoEventMask 0L X#define KeyPressMask (1L<<0) X#define KeyReleaseMask (1L<<1) X#define ButtonPressMask (1L<<2) X#define ButtonReleaseMask (1L<<3) X#define EnterWindowMask (1L<<4) X#define LeaveWindowMask (1L<<5) X#define PointerMotionMask (1L<<6) X#define PointerMotionHintMask (1L<<7) X#define Button1MotionMask (1L<<8) X#define Button2MotionMask (1L<<9) X#define Button3MotionMask (1L<<10) X#define Button4MotionMask (1L<<11) X#define Button5MotionMask (1L<<12) X#define ButtonMotionMask (1L<<13) X#define KeymapStateMask (1L<<14) X#define ExposureMask (1L<<15) X#define VisibilityChangeMask (1L<<16) X#define StructureNotifyMask (1L<<17) X#define ResizeRedirectMask (1L<<18) X#define SubstructureNotifyMask (1L<<19) X#define SubstructureRedirectMask (1L<<20) X#define FocusChangeMask (1L<<21) X#define PropertyChangeMask (1L<<22) X#define ColormapChangeMask (1L<<23) X#define OwnerGrabButtonMask (1L<<24) X X/* Event names. Used in "type" field in XEvent structures. Not to be Xconfused with event masks above. They start from 2 because 0 and 1 Xare reserved in the protocol for errors and replies. */ X X#define KeyPress 2 X#define KeyRelease 3 X#define ButtonPress 4 X#define ButtonRelease 5 X#define MotionNotify 6 X#define EnterNotify 7 X#define LeaveNotify 8 X#define FocusIn 9 X#define FocusOut 10 X#define KeymapNotify 11 X#define Expose 12 X#define GraphicsExpose 13 X#define NoExpose 14 X#define VisibilityNotify 15 X#define CreateNotify 16 X#define DestroyNotify 17 X#define UnmapNotify 18 X#define MapNotify 19 X#define MapRequest 20 X#define ReparentNotify 21 X#define ConfigureNotify 22 X#define ConfigureRequest 23 X#define GravityNotify 24 X#define ResizeRequest 25 X#define CirculateNotify 26 X#define CirculateRequest 27 X#define PropertyNotify 28 X#define SelectionClear 29 X#define SelectionRequest 30 X#define SelectionNotify 31 X#define ColormapNotify 32 X#define ClientMessage 33 X#define MappingNotify 34 X#define LASTEvent 35 /* must be bigger than any event # */ X X X/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer, X state in various key-, mouse-, and button-related events. */ X X#define ShiftMask (1<<0) X#define LockMask (1<<1) X#define ControlMask (1<<2) X#define Mod1Mask (1<<3) X#define Mod2Mask (1<<4) X#define Mod3Mask (1<<5) X#define Mod4Mask (1<<6) X#define Mod5Mask (1<<7) X X/* modifier names. Used to build a SetModifierMapping request or X to read a GetModifierMapping request. These correspond to the X masks defined above. */ X#define ShiftMapIndex 0 X#define LockMapIndex 1 X#define ControlMapIndex 2 X#define Mod1MapIndex 3 X#define Mod2MapIndex 4 X#define Mod3MapIndex 5 X#define Mod4MapIndex 6 X#define Mod5MapIndex 7 X X X/* button masks. Used in same manner as Key masks above. Not to be confused X with button names below. */ X X#define Button1Mask (1<<8) X#define Button2Mask (1<<9) X#define Button3Mask (1<<10) X#define Button4Mask (1<<11) X#define Button5Mask (1<<12) X X#define AnyModifier (1<<15) /* used in GrabButton, GrabKey */ X X X/* button names. Used as arguments to GrabButton and as detail in ButtonPress X and ButtonRelease events. Not to be confused with button masks above. X Note that 0 is already defined above as "AnyButton". */ X X#define Button1 1 X#define Button2 2 X#define Button3 3 X#define Button4 4 X#define Button5 5 X X/* Notify modes */ X X#define NotifyNormal 0 X#define NotifyGrab 1 X#define NotifyUngrab 2 X#define NotifyWhileGrabbed 3 X X#define NotifyHint 1 /* for MotionNotify events */ X X/* Notify detail */ X X#define NotifyAncestor 0 X#define NotifyVirtual 1 X#define NotifyInferior 2 X#define NotifyNonlinear 3 X#define NotifyNonlinearVirtual 4 X#define NotifyPointer 5 X#define NotifyPointerRoot 6 X#define NotifyDetailNone 7 X X/* Visibility notify */ X X#define VisibilityUnobscured 0 X#define VisibilityPartiallyObscured 1 X#define VisibilityFullyObscured 2 X X/* Circulation request */ X X#define PlaceOnTop 0 X#define PlaceOnBottom 1 X X/* protocol families */ X X#define FamilyInternet 0 X#define FamilyDECnet 1 X#define FamilyChaos 2 X X/* Property notification */ X X#define PropertyNewValue 0 X#define PropertyDelete 1 X X/* Color Map notification */ X X#define ColormapUninstalled 0 X#define ColormapInstalled 1 X X/* GrabPointer, GrabButton, GrabKeyboard, GrabKey Modes */ X X#define GrabModeSync 0 X#define GrabModeAsync 1 X X/* GrabPointer, GrabKeyboard reply status */ X X#define GrabSuccess 0 X#define AlreadyGrabbed 1 X#define GrabInvalidTime 2 X#define GrabNotViewable 3 X#define GrabFrozen 4 X X/* AllowEvents modes */ X X#define AsyncPointer 0 X#define SyncPointer 1 X#define ReplayPointer 2 X#define AsyncKeyboard 3 X#define SyncKeyboard 4 X#define ReplayKeyboard 5 X#define AsyncBoth 6 X#define SyncBoth 7 X X/* Used in SetInputFocus, GetInputFocus */ X X#define RevertToNone (int)None X#define RevertToPointerRoot (int)PointerRoot X#define RevertToParent 2 X X/***************************************************************** X * ERROR CODES X *****************************************************************/ X X#define Success 0 /* everything's okay */ X#define BadRequest 1 /* bad request code */ X#define BadValue 2 /* int parameter out of range */ X#define BadWindow 3 /* parameter not a Window */ X#define BadPixmap 4 /* parameter not a Pixmap */ X#define BadAtom 5 /* parameter not an Atom */ X#define BadCursor 6 /* parameter not a Cursor */ X#define BadFont 7 /* parameter not a Font */ X#define BadMatch 8 /* parameter mismatch */ X#define BadDrawable 9 /* parameter not a Pixmap or Window */ X#define BadAccess 10 /* depending on context: X - key/button already grabbed X - attempt to free an illegal X cmap entry X - attempt to store into a read-only X color map entry. X - attempt to modify the access control X list from other than the local host. X */ X#define BadAlloc 11 /* insufficient resources */ X#define BadColor 12 /* no such colormap */ X#define BadGC 13 /* parameter not a GC */ X#define BadIDChoice 14 /* choice not in range or already used */ X#define BadName 15 /* font or color name doesn't exist */ X#define BadLength 16 /* Request length incorrect */ X#define BadImplementation 17 /* server is defective */ X X#define FirstExtensionError 128 X#define LastExtensionError 255 X X/***************************************************************** X * WINDOW DEFINITIONS X *****************************************************************/ X X/* Window classes used by CreateWindow */ X/* Note that CopyFromParent is already defined as 0 above */ X X#define InputOutput 1 X#define InputOnly 2 X X/* Window attributes for CreateWindow and ChangeWindowAttributes */ X X#define CWBackPixmap (1L<<0) X#define CWBackPixel (1L<<1) X#define CWBorderPixmap (1L<<2) X#define CWBorderPixel (1L<<3) X#define CWBitGravity (1L<<4) X#define CWWinGravity (1L<<5) X#define CWBackingStore (1L<<6) X#define CWBackingPlanes (1L<<7) X#define CWBackingPixel (1L<<8) X#define CWOverrideRedirect (1L<<9) X#define CWSaveUnder (1L<<10) X#define CWEventMask (1L<<11) X#define CWDontPropagate (1L<<12) X#define CWColormap (1L<<13) X#define CWCursor (1L<<14) X X/* ConfigureWindow structure */ X X#define CWX (1<<0) X#define CWY (1<<1) X#define CWWidth (1<<2) X#define CWHeight (1<<3) X#define CWBorderWidth (1<<4) X#define CWSibling (1<<5) X#define CWStackMode (1<<6) X X X/* Bit Gravity */ X X#define ForgetGravity 0 X#define NorthWestGravity 1 X#define NorthGravity 2 X#define NorthEastGravity 3 X#define WestGravity 4 X#define CenterGravity 5 X#define EastGravity 6 X#define SouthWestGravity 7 X#define SouthGravity 8 X#define SouthEastGravity 9 X#define StaticGravity 10 X X/* Window gravity + bit gravity above */ X X#define UnmapGravity 0 X X/* Used in CreateWindow for backing-store hint */ X X#define NotUseful 0 X#define WhenMapped 1 X#define Always 2 X X/* Used in GetWindowAttributes reply */ X X#define IsUnmapped 0 X#define IsUnviewable 1 X#define IsViewable 2 X X/* Used in ChangeSaveSet */ X X#define SetModeInsert 0 X#define SetModeDelete 1 X X/* Used in ChangeCloseDownMode */ X X#define DestroyAll 0 X#define RetainPermanent 1 X#define RetainTemporary 2 X X/* Window stacking method (in configureWindow) */ X X#define Above 0 X#define Below 1 X#define TopIf 2 X#define BottomIf 3 X#define Opposite 4 X X/* Circulation direction */ X X#define RaiseLowest 0 X#define LowerHighest 1 X X/* Property modes */ X X#define PropModeReplace 0 X#define PropModePrepend 1 X#define PropModeAppend 2 X X/***************************************************************** X * GRAPHICS DEFINITIONS X *****************************************************************/ X X/* graphics functions, as in GC.alu */ X X#define GXclear 0x0 /* 0 */ X#define GXand 0x1 /* src AND dst */ X#define GXandReverse 0x2 /* src AND NOT dst */ X#define GXcopy 0x3 /* src */ X#define GXandInverted 0x4 /* NOT src AND dst */ X#define GXnoop 0x5 /* dst */ X#define GXxor 0x6 /* src XOR dst */ X#define GXor 0x7 /* src OR dst */ X#define GXnor 0x8 /* NOT src AND NOT dst */ X#define GXequiv 0x9 /* NOT src XOR dst */ X#define GXinvert 0xa /* NOT dst */ X#define GXorReverse 0xb /* src OR NOT dst */ X#define GXcopyInverted 0xc /* NOT src */ X#define GXorInverted 0xd /* NOT src OR dst */ X#define GXnand 0xe /* NOT src OR NOT dst */ X#define GXset 0xf /* 1 */ X X/* LineStyle */ X X#define LineSolid 0 X#define LineOnOffDash 1 X#define LineDoubleDash 2 X X/* capStyle */ X X#define CapNotLast 0 X#define CapButt 1 X#define CapRound 2 X#define CapProjecting 3 X X/* joinStyle */ X X#define JoinMiter 0 X#define JoinRound 1 X#define JoinBevel 2 X X/* fillStyle */ X X#define FillSolid 0 X#define FillTiled 1 X#define FillStippled 2 X#define FillOpaqueStippled 3 X X/* fillRule */ X X#define EvenOddRule 0 X#define WindingRule 1 X X/* subwindow mode */ X X#define ClipByChildren 0 X#define IncludeInferiors 1 X X/* SetClipRectangles ordering */ X X#define Unsorted 0 X#define YSorted 1 X#define YXSorted 2 X#define YXBanded 3 X X/* CoordinateMode for drawing routines */ X X#define CoordModeOrigin 0 /* relative to the origin */ X#define CoordModePrevious 1 /* relative to previous point */ X X/* Polygon shapes */ X X#define Complex 0 /* paths may intersect */ X#define Nonconvex 1 /* no paths intersect, but not convex */ X#define Convex 2 /* wholly convex */ X X/* Arc modes for PolyFillArc */ X X#define ArcChord 0 /* join endpoints of arc */ X#define ArcPieSlice 1 /* join endpoints to center of arc */ X X/* GC components: masks used in CreateGC, CopyGC, ChangeGC, OR'ed into X GC.stateChanges */ X X#define GCFunction (1L<<0) X#define GCPlaneMask (1L<<1) X#define GCForeground (1L<<2) X#define GCBackground (1L<<3) X#define GCLineWidth (1L<<4) X#define GCLineStyle (1L<<5) X#define GCCapStyle (1L<<6) X#define GCJoinStyle (1L<<7) X#define GCFillStyle (1L<<8) X#define GCFillRule (1L<<9) X#define GCTile (1L<<10) X#define GCStipple (1L<<11) X#define GCTileStipXOrigin (1L<<12) X#define GCTileStipYOrigin (1L<<13) X#define GCFont (1L<<14) X#define GCSubwindowMode (1L<<15) X#define GCGraphicsExposures (1L<<16) X#define GCClipXOrigin (1L<<17) X#define GCClipYOrigin (1L<<18) X#define GCClipMask (1L<<19) X#define GCDashOffset (1L<<20) X#define GCDashList (1L<<21) X#define GCArcMode (1L<<22) X X#define GCLastBit 22 X/***************************************************************** X * FONTS X *****************************************************************/ X X/* used in QueryFont -- draw direction */ X X#define FontLeftToRight 0 X#define FontRightToLeft 1 X X#define FontChange 255 X X/***************************************************************** X * IMAGING X *****************************************************************/ X X/* ImageFormat -- PutImage, GetImage */ X X#define XYBitmap 0 /* depth 1, XYFormat */ X#define XYPixmap 1 /* depth == drawable depth */ X#define ZPixmap 2 /* depth == drawable depth */ X X/***************************************************************** X * COLOR MAP STUFF X *****************************************************************/ X X/* For CreateColormap */ X X#define AllocNone 0 /* create map with no entries */ X#define AllocAll 1 /* allocate entire map writeable */ X X X/* Flags used in StoreNamedColor, StoreColors */ X X#define DoRed (1<<0) X#define DoGreen (1<<1) X#define DoBlue (1<<2) X X/***************************************************************** X * CURSOR STUFF X *****************************************************************/ X X/* QueryBestSize Class */ X X#define CursorShape 0 /* largest size that can be displayed */ X#define TileShape 1 /* size tiled fastest */ X#define StippleShape 2 /* size stippled fastest */ X X/***************************************************************** X * KEYBOARD/POINTER STUFF X *****************************************************************/ X X#define AutoRepeatModeOff 0 X#define AutoRepeatModeOn 1 X#define AutoRepeatModeDefault 2 X X#define LedModeOff 0 X#define LedModeOn 1 X X/* masks for ChangeKeyboardControl */ X X#define KBKeyClickPercent (1L<<0) X#define KBBellPercent (1L<<1) X#define KBBellPitch (1L<<2) X#define KBBellDuration (1L<<3) X#define KBLed (1L<<4) X#define KBLedMode (1L<<5) X#define KBKey (1L<<6) X#define KBAutoRepeatMode (1L<<7) X X#define MappingSuccess 0 X#define MappingBusy 1 X#define MappingFailed 2 X X#define MappingModifier 0 X#define MappingKeyboard 1 X#define MappingPointer 2 X X/***************************************************************** X * SCREEN SAVER STUFF X *****************************************************************/ X X#define DontPreferBlanking 0 X#define PreferBlanking 1 X#define DefaultBlanking 2 X X#define DisableScreenSaver 0 X#define DisableScreenInterval 0 X X#define DontAllowExposures 0 X#define AllowExposures 1 X#define DefaultExposures 2 X X/* for ForceScreenSaver */ X X#define ScreenSaverReset 0 X#define ScreenSaverActive 1 X X/***************************************************************** X * HOSTS AND CONNECTIONS X *****************************************************************/ X X/* for ChangeHosts */ X X#define HostInsert 0 X#define HostDelete 1 X X/* for ChangeAccessControl */ X X#define EnableAccess 1 X#define DisableAccess 0 X X/* Display classes used in opening the connection X * Note that the statically allocated ones are even numbered and the X * dynamically changeable ones are odd numbered */ X X#define StaticGray 0 X#define GrayScale 1 X#define StaticColor 2 X#define PseudoColor 3 X#define TrueColor 4 X#define DirectColor 5 X X X/* Byte order used in imageByteOrder and bitmapBitOrder */ X X#define LSBFirst 0 X#define MSBFirst 1 X X#endif /* X_H */ END_OF_FILE if test 18246 -ne `wc -c <'X.h'`; then echo shar: \"'X.h'\" unpacked with wrong size! fi # end of 'X.h' fi if test -f 'lwf.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'lwf.c'\" else echo shar: Extracting \"'lwf.c'\" \(29448 characters\) sed "s/^X//" >'lwf.c' <<'END_OF_FILE' X X/* vi: set tabstop=4 : */ X X/* X * lwf - Convert ASCII text to PostScript X * X * Usage: X * lwf [-d] [-i#] [-l] [-m] [-olist] [-p[str]] [-P filename] [-s#] [-t#] X * [-v] [file ...] X * X * Options: X * -d Debug mode X * -i# Indent each line # inches (so much for metric) X * -l Landscape instead of Portrait X * -m Use 3 hole punch margins X * -olist Only print pages in the specified range X * -p[str] Use pr to print, passing optional string X * -P filename Copy prologue from filename instead of default X * -r Toggle page reversal flag (see Makefile) X * -s# Use point size # X * -t# Spaces between tab stops is # characters X * -v Verbose X * -S Standalone mode (print header page, use EOF's) X * X * If no files are specified, stdin is used. X * Form feeds handled X * Backspacing with underlining (or overprinting) works X * The output conforms to Adobe 2.0 X * X * Problems: X * - assumes fixed-width (non-proportional) font in some places X * - can't back up (using backspaces) over tabs X * - assumes 8.5 x 11.0 paper X * X * BJB - Jun/87 X * ======================================================================== X * X * Permission is given to freely copy and distribute this software provided: X * X * 1) You do not sell it, X * 2) You do not use it for commercial advantage, and X * 3) This notice accompanies the distribution X * X * Copyright (c) 1988 X * Barry Brachman X * Dept. of Computer Science X * Univ. of British Columbia X * Vancouver, B.C. V6T 1W5 X * X * .. {ihnp4!alberta, uw-beaver, uunet}!ubc-vision!ubc-csgrads!brachman X * brachman@grads.cs.ubc.cdn X * brachman%ubc.csnet@csnet-relay.arpa X * brachman@ubc.csnet X * ======================================================================== X */ X X#include <sys/file.h> X#include <ctype.h> X#include <pwd.h> X#include <stdio.h> X X#define min(a, b) ((a) < (b) ? (a) : (b)) X X#define PROCPROL X/* X * Configurable... X * BUFOUT should be fairly large X */ X#define BUFIN 1024 /* maximum length of an input line */ X#define BUFOUT (BUFIN * 5) X#define MAXPAGES 10000 /* maximum number of pages per job */ X#define DEFAULT_TAB_SIZE 8 X#define DEFAULT_POINT_SIZE 10 X#ifndef PROLOGUE X#define PROLOGUE "/usr/local/lib/lwf.prologue" X#endif X#ifdef KANJI X#ifndef KPLACE X#define KPLACE "/usr/local/lib/k14.snf" X#endif X#endif X#ifndef REVERSE X#define REVERSE 0 X#endif X#ifndef PR X#define PR "/bin/pr" X#endif X X#ifdef SYSV X#define rindex strrchr X#endif X X/* X * As mentioned in the man page, /bin/pr doesn't handle formfeeds correctly X * when doing multicolumn formatting X * Instead of starting a new column or page it passes a formfeed through, X * causing pr and lwf to get out-of-synch with regard to the current X * location on the page X * If your pr behaves this way (4.[23] does, SYSV doesn't), define PRBUG so X * that fgetline() will filter out these bogus formfeeds while preserving X * the column structuring X */ X#ifndef SYSV X#define PRBUG 1 X#endif X X/* X * PostScript command strings defined in the prologue file X */ X#define BACKSPACE "B" X#define ENDPAGE "EP" X#define LINETO "L" X#define MOVETO "M" X#define NEWPATH "NP" X#define SHOW "S" X#define STARTPAGE "SP" X#define STARTHPAGE "SHP" X#define STARTLPAGE "SLP" X#define STROKE "ST" X#define TAB "T" X#ifdef KANJI X#define SHOWK "K" X#endif X X/* X * Conformance requires that no PostScript line exceed 256 characters X */ X#define MAX_OUTPUT_LINE_LENGTH 256 X X#define TEXTFONT "Courier" X#define HEADERFONT "Times-Roman" X#define HEADERPS 18 /* header page point size */ X X#define PORTRAIT_START_Y 768 /* first row (Y coord) on each page */ X#define LANDSCAPE_START_Y 576 X#define START_X 25 /* position of start of each line */ X#define START_Y_HEADER 700 /* first row (Y coord) of header */ X#define THREE_HOLE_X 1.0 /* portrait x offset (inches) 3 hole */ X#define THREE_HOLE_Y 0.5 /* landscape y offset (inches) 3 hole */ X X#define MAX_X 612 X#define MAX_Y 792 X X#define SEP_CHAR '\001' /* pr column separator character */ X X#define PS_EOF 04 X X#define NPSIZES 9 Xstruct psize { X int size; /* point size */ X double charsperinch; /* approx. char width, for Courier */ X int portrait_page_length; /* page length in lines */ X int portrait_cols; /* maximum # of chars per line */ X int landscape_page_length; X int landscape_cols; X} psize[NPSIZES] = { X 7, 17.0, 108, 135, 80, 181, X 8, 15.0, 94, 118, 70, 159, X 9, 14.0, 84, 105, 62, 141, X 10, 12.0, 75, 94, 56, 127, X 11, 11.0, 68, 86, 51, 115, X 12, 10.0, 62, 79, 46, 106, X 14, 8.8, 54, 67, 40, 90, X 16, 7.5, 47, 59, 35, 79, X 18, 7.0, 42, 52, 31, 70 X}; X X X#define USAGE \ X"[-d] [-i#] [-l] [-m] [-olist] [-p[str]] [-r] [-s#] [-t#] [-v] [-S] [file ...]" X Xlong page_map[MAXPAGES]; /* offset of first byte of each page */ Xint page_count; X Xint lines_per_page; Xint columns; Xint point_size; Xint start_x, start_y; Xint ncopies; X Xchar bufin[BUFIN]; /* input buffer */ Xchar bufout[BUFOUT]; /* used for page reversal and output buffering */ X Xchar *currentdate, *username; Xchar hostname[32]; X Xint row; Xchar *range; Xint tabstop; Xchar *propts; X Xint dflag, lflag, mflag, pflag, rflag, vflag, Sflag; X X#ifdef KANJI Xint kflag, kfontopen; Xextern char *kimage(); Xextern int openkfont(); Xextern void closekfont(); X#endif X Xchar *strcpy(); Xchar *fgetline(); Xchar *sprintf(); X Xchar *prologue; Xchar *progname; X Xchar *version = "lwf V2.0 brachman@ubc.csnet 21-Feb-88"; X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X register int i, j, first_file; X char *pc; X struct psize *p, *get_psize(); X double offset, atof(); X char *rindex(); X FILE *infile, *popen(); X double ceil(); X X if ((pc = rindex(argv[0], '/')) != (char *) NULL) X progname = pc + 1; X else X progname = argv[0]; X range = ":"; X propts = ""; X tabstop = DEFAULT_TAB_SIZE; X page_count = 0; X ncopies = 1; X offset = 0.0; X prologue = PROLOGUE; X p = get_psize(DEFAULT_POINT_SIZE); X rflag = REVERSE; X X for (i = 1; i < argc && argv[i][0] == '-'; i++) { X switch (argv[i][1]) { X case 'c': X ncopies = atof(&argv[i][2]); X if (ncopies <= 0) { X fatal("number of copies must be > 0"); X /*NOTREACHED*/ X } X break; X case 'd': X dflag = 1; X break; X case 'i': X offset = atof(&argv[i][2]); X if (offset < 0.0 || offset >= 8.5) { X fatal("bad indent"); X /*NOTREACHED*/ X } X break; X case 'l': X lflag = 1; X break; X case 'm': X mflag = 1; X break; X case 'o': X range = &argv[i][2]; X if (checkrange(range)) { X fatal("bad range specification"); X /*NOTREACHED*/ X } X break; X case 'p': X pflag = 1; X propts = &argv[i][2]; X break; X case 'P': X if (++i == argc) { X fatal("missing filename after -P"); X /*NOTREACHED*/ X } X prologue = argv[i]; X break; X case 'r': X rflag = !rflag; X break; X case 's': X j = atoi(&argv[i][2]); X if ((p = get_psize(j)) == (struct psize *) NULL) { X fatal("bad point size"); X /*NOTREACHED*/ X } X break; X case 't': X tabstop = atoi(&argv[i][2]); X if (tabstop < 1) { X fatal("bad tabstop"); X /*NOTREACHED*/ X } X break; X case 'v': X vflag = 1; X break; X case 'S': X Sflag = 1; X break; X default: X (void) fprintf(stderr, "Usage: %s %s\n", progname, USAGE); X exit(1); X } X } X X /* X * Check that all files are readable X * This is so that no output at all is produced if any file is not X * readable in case the output is being piped to a printer X */ X for (j = i; j < argc; j++) { X if (access(argv[j], R_OK) == -1) { X fatal("cannot access %s", argv[j]); X /*NOTREACHED*/ X } X } X X point_size = p->size; X X if (lflag) { X start_y = LANDSCAPE_START_Y; X start_x = START_X + (int) (offset * 72.27); X lines_per_page = p->landscape_page_length; X columns = p->landscape_cols - (int) ceil(offset * p->charsperinch); X if (mflag) { X int nlines; X X nlines = (int) ceil((THREE_HOLE_Y * 72.27) / point_size); X start_y -= (nlines * point_size); X lines_per_page -= nlines; X columns -= (int) ceil(THREE_HOLE_Y * p->charsperinch); X } X } X else { X start_y = PORTRAIT_START_Y; X lines_per_page = p->portrait_page_length; X start_x = START_X; X if (mflag) X offset += THREE_HOLE_X; X start_x += (int) (offset * 72.27); X columns = p->portrait_cols - (int) ceil(offset * p->charsperinch); X } X if (vflag) { X (void) fprintf(stderr, "%s\n\n", version); X (void) fprintf(stderr, "Lines/page = %d\n", lines_per_page); X (void) fprintf(stderr, "Columns = %d\n", columns); X (void) fprintf(stderr, "X-offset = %5.2f inches\n", offset); X } X X setup(); X preamble(); X X first_file = i; X X if (!rflag && Sflag) X header(argc - first_file, argv + first_file); X X if (i == argc) { /* no files on command line */ X infile = stdin; X if (pflag) { X build_prcmd(bufin, ""); X if ((infile = popen(bufin, "r")) == (FILE *) NULL) { X fatal("popen failed"); X /*NOTREACHED*/ X } X } X if (vflag) X (void) fprintf(stderr, "printing stdin\n"); X print(infile); X if (pflag) X (void) pclose(infile); X } X X /* X * If page reversal is performed, process the file arguments right to left, X * oth. left to right X * If the correct flag is used for the printer the first file argument X * will be on top in the printer's output tray when the paper is removed X */ X if (rflag) X j = argc - 1; X else X j = i; X while (i < argc) { X infile = stdin; X if (pflag) { X build_prcmd(bufin, argv[j]); X if ((infile = popen(bufin, "r")) == (FILE *) NULL) { X fatal("popen failed"); X /*NOTREACHED*/ X } X } X else { X if (freopen(argv[j], "r", stdin) == (FILE *) NULL) { X fatal("can't open %s", argv[j]); X /*NOTREACHED*/ X } X } X if (vflag) X (void) fprintf(stderr, "printing %s\n", argv[j]); X print(infile); X if (pflag) X (void) pclose(infile); X if (rflag) X j--; X else X j++; X i++; X } X X if (rflag && Sflag) X header(argc - first_file, argv + first_file); X X (void) printf("%%%%Trailer\n"); X (void) printf("%%%%Pages: %d\n", page_count); X if (Sflag) X (void) putc(PS_EOF, stdout); X X if (fflush(stdout) == EOF) { X fatal("write error on stdout"); X /*NOTREACHED*/ X } X#ifdef KANJI X if (kfontopen) closekfont(); X#endif X exit(0); X} X X/* X * Return a pointer to the point size structure for the X * specified point size X */ Xstruct psize * Xget_psize(size) Xint size; X{ X register int i; X X for (i = 0; i < NPSIZES; i++) X if (psize[i].size == size) X break; X if (i == NPSIZES) X return((struct psize *) NULL); X return(&psize[i]); X} X X/* X * Initial lines sent to the LaserWriter X * This stuff is sent to stdout since we don't want it to be reversed X * Generates the PostScript header and includes the prologue file X * There is limited checking for I/O errors here X * When the standard prologue is being used we probably should verify X * that it is the correct version (via %%BeginProcSet) X */ Xpreamble() X{ X#ifndef PROCPROL X FILE *fp; X X if ((fp = fopen(prologue, "r")) == (FILE *) NULL) { X fatal("can't open prologue file `%s'", prologue); X /*NOTREACHED*/ X } X#endif X if (Sflag) X (void) putc(PS_EOF, stdout); X X (void) printf("%%!PS-Adobe-2.0\n"); X (void) printf("%%%%Creator: %s on %s\n", progname, hostname); X (void) printf("%%%%CreationDate: %s\n", currentdate); X (void) printf("%%%%For: %s\n", username); X (void) printf("%%%%DocumentFonts: %s", TEXTFONT); X if (Sflag) X (void) printf(" %s\n", HEADERFONT); X else X (void) printf("\n"); X (void) printf("%%%%Pages: (atend)\n"); X#ifndef PROCPROL X while (fgets(bufin, sizeof(bufin), fp) != (char *) NULL) X fputs(bufin, stdout); X (void) fclose(fp); X#else X doprologue(); X#endif X X if (ferror(stdout) || fflush(stdout) == EOF) { X fatal("write error on stdout"); X /*NOTREACHED*/ X } X} X#ifdef PROCPROL X Xdoprologue() X{ X printf("%%%%EndComments\n"); X printf("%% PostScript Prologue for lwf V2.0 ASCII to PostScript filter\n"); X printf("%% Barry Brachman\n"); X printf("%% Dept. of Computer Science\n"); X printf("%% University of British Columbia\n"); X printf("/B {NW 0 rmoveto}bind def\n"); X printf("/EP {SV restore /#copies exch def showpage}bind def\n"); X printf("/L /lineto load def\n"); X printf("/M /moveto load def\n"); X printf("/NP /newpath load def\n"); X printf("/S /show load def\n"); X printf("/SHP {SP 2 setlinewidth}bind def\n"); X printf("/SLP {SP 612 0 translate 90 rotate}bind def\n"); X printf("/SP {/SV save def findfont exch scalefont setfont ( )\n"); X printf(" stringwidth pop dup /W exch def neg /NW exch def}bind def\n"); X printf("/ST /stroke load def\n"); X printf("/T {W mul 0 rmoveto}bind def\n"); X printf("/K {/kimage exch def gsave currentpoint translate W W scale\n"); X printf(" 14 14 true [14 0 0 -14 0 14] kimage imagemask\n"); X printf(" grestore W 0 rmoveto}bind def\n"); X printf("%%%%EndProlog\n"); X} X#endif X X/* X * Generate a command, in the specified buffer, to print the given file X * according to the options in effect X */ Xbuild_prcmd(buf, file) Xchar *buf, *file; X{ X X#ifdef SYSV X (void) sprintf(buf, "%s -e%d -w%d -l%d -s%c %s %s", X PR, tabstop, columns, lines_per_page, SEP_CHAR, propts, file); X#else X (void) sprintf(buf, "%s -w%d -l%d -s%c %s %s", X PR, columns, lines_per_page, SEP_CHAR, propts, file); X#endif X if (vflag) X (void) fprintf(stderr, "pr cmd: %s\n", buf); X} X X/* X * Print a file X * X * The input stream may be stdin, a file, or a pipe X * If page reversal is being performed, the output goes to a temporary file and X * then reverse() is called to do the page reversal to stdout X */ Xprint(infile) XFILE *infile; X{ X register int eof, pagenum, r; X register char *p; X FILE *outfile; X char *mktemp(); X X if (rflag) { X static char bigbuf[BUFOUT]; X X page_map[0] = 0L; X (void) sprintf(bufin, "/tmp/%sXXXXXX", progname); X if (vflag) X (void) fprintf(stderr, "temp will be: %s ... ", bufin); X p = mktemp(bufin); X if (vflag) X (void) fprintf(stderr, "%s\n", p); X if ((outfile = fopen(p, "w+")) == (FILE *) NULL) { X (void) fprintf(stderr, "%s: can't create %s\n", progname, p); X cleanup(); X /*NOTREACHED*/ X } X setbuffer(outfile, bigbuf, sizeof(bigbuf)); X if (!dflag) X (void) unlink(p); X else X (void) fprintf(stderr, "will not unlink %s\n", p); X } X else X outfile = stdout; X X pagenum = 1; X eof = 0; X while (!eof) { X row = start_y; X if ((r = inrange(pagenum, range)) == -1) { X cleanup(); X /*NOTREACHED*/ X } X else if (r == 1) X eof = printpage(infile, outfile); X else if (r == 0) X eof = flushpage(infile); X else { X fatal("bad inrange result"); X /*NOTREACHED*/ X } X pagenum++; X } X if (row != start_y) X endpage(outfile); X if (vflag) X (void) fprintf(stderr, "\n"); X if (fflush(outfile) == EOF) { X fatal("write error while flushing output"); X /*NOTREACHED*/ X } X if (rflag) { X reverse(outfile); X (void) fclose(outfile); X } X} X X/* X * Process the next page X * Return 1 on EOF, 0 oth. X */ Xprintpage(infile, outfile) XFILE *infile, *outfile; X{ X register int lineno; X X if (ungetc(getc(infile), infile) == EOF) X return(1); X X startpage(page_count + 1, outfile); X for (lineno = 0; lineno < lines_per_page; lineno++) { X if (fgetline(bufin, sizeof(bufin), infile) == (char *) NULL) X return(1); X if (bufin[0] == '\f') X break; X if (bufin[0] != '\0') { X (void) fprintf(outfile, "%d %d %s\n", start_x, row, MOVETO); X proc(bufin, outfile); X } X row -= point_size; X } X endpage(outfile); X return(0); X} X X/* X * The next page will not be printed; just consume the input and discard X * Don't change xrow since we don't want an endpage() X */ Xflushpage(infile) XFILE *infile; X{ X register int lineno, xrow; X X xrow = row; X for (lineno = 0; lineno < lines_per_page; lineno++) { X if (fgetline(bufin, sizeof(bufin), infile) == (char *) NULL) X return(1); X if (bufin[0] == '\f') X break; X xrow -= point_size; X } X return(0); X} X X/* X * Start a new page X */ Xstartpage(n, outfile) Xint n; XFILE *outfile; X{ X X (void) fprintf(outfile, "%%%%Page: ? %d\n", n); X (void) fprintf(outfile, "%d /%s %s\n", X point_size, TEXTFONT, lflag ? STARTLPAGE : STARTPAGE); X} X X/* X * A page has been written to the temp file X * Record the start of the next page X * Terminate the page and indicate the start of the next X */ Xendpage(outfile) XFILE *outfile; X{ X long ftell(); X X if (page_count == MAXPAGES) { X fatal("pagelimit (%d) reached", MAXPAGES); X /*NOTREACHED*/ X } X (void) fprintf(outfile, "%d %s\n", ncopies, ENDPAGE); X if (rflag) { X if (fflush(outfile) == EOF) { X fatal("write error while flushing page"); X /*NOTREACHED*/ X } X page_map[++page_count] = ftell(outfile); X } X else X page_count++; X if (vflag) X (void) fprintf(stderr, "x"); X} X X/* X * Print the pages to stdout in reverse order X * Assumes that the number of characters per page can be contained in an int X */ Xreverse(outfile) XFILE *outfile; X{ X register int i; X int bytecount, nbytes; X long lseek(); X X if (vflag) X (void) fprintf(stderr, "\nreversing %d page%s\n", page_count, X page_count > 1 ? "s" : ""); X if (dflag) { X for (i = 0; i <= page_count; i++) X (void) fprintf(stderr, "[%ld]\n", page_map[i]); X } X for (i = page_count - 1; i >= 0; i--) { X if (fseek(outfile, page_map[i], 0) == -1L) { X fatal("seek error"); X /*NOTREACHED*/ X } X nbytes = (int) (page_map[i + 1] - page_map[i]); X while (nbytes > 0) { X bytecount = min(nbytes, sizeof(bufout)); X if (fread(bufout, 1, bytecount, outfile) != bytecount) { X fatal("read error while reversing pages"); X /*NOTREACHED*/ X } X if (fwrite(bufout, 1, bytecount, stdout) != bytecount) { X fatal("write error while reversing pages"); X /*NOTREACHED*/ X } X nbytes -= bytecount; X } X } X} X X/* X * Process a line of input, escaping characters when necessary and handling X * tabs X * X * The output is improved somewhat by coalescing consecutive tabs and X * backspaces and eliminating tabs at the end of a line X * X * Overprinting (presumably most often used in underlining) can be far from X * optimal; in particular the way nroff underlines by sequences like X * "_\ba_\bb_\bc" creates a large volume of PostScript. This isn't too X * serious since a lot of nroff underlining is unlikely. X * X * Since a newline is generated for each call there will be more X * newlines in the output than is necessary X */ Xproc(in, outfile) Xchar *in; XFILE *outfile; X{ X register int i; X register char *last, *p, *q; X int currentp, instr, tabc, tabto; X char *savep; X static int colskip, ncols; X static int seen_sep = 0; X X currentp = 0; X instr = 0; X tabto = 0; X last = bufout + MAX_OUTPUT_LINE_LENGTH - 20; /* subtract slop factor */ X X q = bufout; X *q = '\0'; X for (p = in; *p != '\0'; p++) { X switch (*p) { X case SEP_CHAR: X /* X * This assumes that the input buffer contains the entire line X * oth. the column count will be off X * Also, the input stream must be formatted into a constant number X * of columns oth. it would be necessary to scan each line to X * count SEP_CHARs (which is not hard but could be slow) X */ X if (!seen_sep) { /* discern number of columns */ X seen_sep = 1; X ncols = 2; /* there are at least two columns... */ X savep = p++; X while (*p != '\0') { X if (*p++ == SEP_CHAR) X ncols++; X } X p = savep; X colskip = columns / ncols; X if (vflag) X (void) fprintf(stderr, "Using %d columns\n", ncols); X } X if (instr) { X (void) sprintf(q, ")%s ", SHOW); X q += strlen(q); X instr = 0; X } X tabto += (colskip - currentp); X currentp = 0; X break; X case '\t': X /* X * Count the number of tabs that immediately follow the one we're X * looking at X */ X tabc = 0; X while (*(p + 1) == '\t') { X p++; X tabc++; X } X if (currentp > 0) { /* not beginning of line */ X i = tabstop - (currentp % tabstop) + tabc * tabstop; X if (instr) { X (void) sprintf(q, ")%s ", SHOW); X q += strlen(q); X instr = 0; X } X } X else X i = (tabc + 1) * tabstop; X tabto += i; X currentp += i; X break; X case '\b': X *q = '\0'; X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X /* backspacing over tabs doesn't work... */ X if (tabto != 0) { X fatal("attempt to backspace over a tab"); X /*NOTREACHED*/ X } X p++; X for (i = 1; *p == '\b'; p++) X i++; X if (currentp - i < 0) { X fatal("too many backspaces"); X /*NOTREACHED*/ X } X if (!instr) { X fatal("bad backspacing"); X /*NOTREACHED*/ X } X if (i == 1) /* frequent case gets special attention */ X (void) sprintf(bufout, "%s (", BACKSPACE); X else X (void) sprintf(bufout, "-%d %s (", i, TAB); X currentp -= i; X q = bufout + strlen(bufout); X p--; X break; X case '\f': X tabto = 0; /* optimizes */ X *q = '\0'; X if (instr) X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X else X (void) fprintf(outfile, "%s\n", bufout); X endpage(outfile); X startpage(page_count + 1, outfile); X row = start_y; X (void) fprintf(outfile, "%d %d %s\n", start_x, row, MOVETO); X q = bufout; X currentp = 0; X instr = 0; X break; X case '\r': X tabto = 0; /* optimizes */ X if (instr) { X *q = '\0'; X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X instr = 0; X q = bufout; X } X (void) fprintf(outfile, "%d %d %s\n", start_x, row, MOVETO); X currentp = 0; X break; X case '(': X#ifdef KANJI X if (kflag && *(p+1) == 'J') { X kflag = 0; X p++; X break; X } X#endif X case '\\': X case ')': X if (!instr) { X if (tabto) { X (void) sprintf(q, "%d %s ", tabto, TAB); X q += strlen(q); X tabto = 0; X } X *q++ = '('; X instr = 1; X } X *q++ = '\\'; X *q++ = *p; X currentp++; X break; X#ifdef KANJI X case '\033': X if (*(p+1) == '$' && (*(p+2) == 'B' || *(p+2) == 'J')) { X if (!kfontopen) kfontopen = openkfont(KPLACE); X if (!kfontopen) fatal("No kanji font"); X kflag = 1; X p++; p++; X *q = '\0'; X if (instr) X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X else X (void) fprintf(outfile, "%s\n", bufout); X q = bufout; X instr = 0; X } X else if (*(p+1) == '(' && (*(p+2) == 'B' || *(p+2) == 'J')) { X kflag = 0; X p++; p++; X } X break; X case '$': X if (!kflag && *(p+1) == '@') { X if (!kfontopen) kfontopen = openkfont(KPLACE); X if (!kfontopen) fatal("No kanji font"); X kflag = 1; X p++;; X *q = '\0'; X if (instr) X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X else X (void) fprintf(outfile, "%s\n", bufout); X q = bufout; X instr = 0; X break; X } X#endif X default: X /* X * According to the PostScript Language Manual, PostScript files X * can contain only "the printable subset of the ASCII character X * set (plus the newline marker)". X */ X if (!isascii(*p) || !isprint(*p)) { X fatal("bad character in input"); X /*NOTREACHED*/ X } X#ifdef KANJI X if (!instr && !kflag) { X#else X if (!instr) { X#endif X if (tabto) { X (void) sprintf(q, "%d %s ", tabto, TAB); X q += strlen(q); X tabto = 0; X } X *q++ = '('; X instr = 1; X } X#ifdef KANJI X if (kflag) { X if (*(p+1)) { X (void) fprintf(outfile, "{<%s>} %s\n", X kimage(*p, *(p+1)), SHOWK ); X p++; X currentp++; X } X } X else { X *q++ = *p; X currentp++; X } X#else X *q++ = *p; X currentp++; X#endif X break; X } X if (q >= last) { X *q = '\0'; X if (instr) X (void) fprintf(outfile, "%s)%s\n", bufout, SHOW); X else X (void) fprintf(outfile, "%s\n", bufout); X q = bufout; X instr = 0; X } X } X if (instr) { X (void) sprintf(q, ")%s", SHOW); X q += strlen(q); X } X else X *q = '\0'; X if (q >= last) { X fatal("bufout overflow"); X /*NOTREACHED*/ X } X if (bufout[0] != '\0') X (void) fprintf(outfile, "%s\n", bufout); X} X X/* X * Find out who the user is, etc. X * Possible system dependencies here... X */ Xsetup() X{ X int len; X char *p; X long t, time(); X int gethostname(); X char *ctime(), *getlogin(), *malloc(); X struct passwd *pw, *getpwuid(); X X if ((p = getlogin()) == (char *) NULL) { X if ((pw = getpwuid(getuid())) == (struct passwd *) NULL) X p = "Whoknows"; X else X p = pw->pw_name; X endpwent(); X } X username = (char *) malloc((unsigned) (strlen(p) + 1)); X (void) strcpy(username, p); X X#ifdef HOSTNAME X (void) strncpy(hostname, HOSTNAME, sizeof(hostname)); X hostname[sizeof(hostname) - 1] = '\0'; X#else X (void) gethostname(hostname, sizeof(hostname)); X#endif X X t = time((long *) 0); X p = ctime(&t); X len = strlen(p); X *(p + len - 1) = '\0'; /* zap the newline character */ X currentdate = (char *) malloc((unsigned) len); X (void) strcpy(currentdate, p); X} X X/* X * Print a header page X * Assumes setup() has already been called to fill in the user, host, etc. X * Uses HEADERFONT in HEADERPS point X */ Xheader(nfiles, files) Xint nfiles; Xchar **files; X{ X register int i; X register char *p; X X if (vflag) { X (void) fprintf(stderr, "printing header\n"); X (void) fprintf(stderr, "%d file%s are:\n", nfiles, X nfiles > 1 ? "s" : ""); X if (nfiles == 0) X (void) fprintf(stderr, "\tstdin\n"); X for (i = 0; i < nfiles; i++) X (void) fprintf(stderr, "\t%s\n", files[i]); X } X X (void) fprintf(stdout, "%%%%Page: ? %d\n", ++page_count); X (void) fprintf(stdout, "%d /%s %s\n", HEADERPS, HEADERFONT, STARTHPAGE); X X /* X * The header sheet looks like: X * X * ---------------------------- X * ---------------------------- X * X * User: X * Host: X * Date: X * Files: X * X * ---------------------------- X * ---------------------------- X */ X row = START_Y_HEADER; X (void) printf("%s %d %d %s\n", NEWPATH, START_X, row, MOVETO); X (void) printf("%d %d %s\n", START_X + 400, row, LINETO); X row -= 6; X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) printf("%d %d %s\n", START_X + 400, row, LINETO); X row -= 24; X (void) printf("%s\n", STROKE); X X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) sprintf(bufin, "User: %s", username); X proc(bufin, stdout); X row -= 24; X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) sprintf(bufin, "Host: %s", hostname); X proc(bufin, stdout); X row -= 24; X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) sprintf(bufin, "Date: %s", currentdate); X proc(bufin, stdout); X row -= 24; X X if (nfiles == 0) { X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) sprintf(bufin, "File: <stdin>"); X proc(bufin, stdout); X } X else { X register int len, max, sum; X X /* X * If the list of files is "too long" we'll only print as many as X * possible X * Arbitrary chop off point is 50 characters X * (assume bufin is bigger than this) X */ X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) sprintf(bufin, "File%s: ", nfiles > 1 ? "s" : ""); X p = bufin + (sum = strlen(bufin)); X max = 50; X for (i = 0; i < nfiles - 1; i++) { X sum += (len = strlen(files[i]) + 1); X if (sum >= max) X break; X (void) sprintf(p, "%s,", files[i]); X p += len; X } X sum += (len = strlen(files[i]) + 1); X if (sum < max) X (void) sprintf(p, "%s", files[i]); X else X (void) strcpy(p, "..."); X proc(bufin, stdout); X } X X row -= 12; X (void) printf("%s %d %d %s\n", NEWPATH, START_X, row, MOVETO); X (void) printf("%d %d %s\n", START_X + 400, row, LINETO); X row -= 6; X (void) printf("%d %d %s\n", START_X, row, MOVETO); X (void) printf("%d %d %s\n", START_X + 400, row, LINETO); X (void) printf("%s\n", STROKE); X (void) printf("1 %s\n", ENDPAGE); X if (fflush(stdout) == EOF) { X fatal("write error on stdout"); X /*NOTREACHED*/ X } X} X X/* X * Special version of fgets X * Read until a formfeed, newline, or overflow X * If a formfeed is the first character, return it immediately X * If a formfeed is found after the first character, replace it by a newline X * and push the formfeed back onto the input stream X * A special case is a formfeed followed by a newline in which case the X * newline is ignored X * The input buffer will be null-terminated and will *not* end with a newline X * The buffer size n includes the null X */ Xchar * Xfgetline(s, n, iop) Xchar *s; Xint n; Xregister FILE *iop; X{ X register int ch; X register char *cs; X X if (n < 2) { X fatal("fgetline called with bad buffer size!?"); X /*NOTREACHED*/ X } X X cs = s; X n--; /* the null */ X X /* X * Check out the special cases X */ X if ((ch = getc(iop)) == EOF) X return((char *) NULL); X if (ch == '\f') { X#ifdef PRBUG X if (pflag) { X /* X * Filter out the formfeeds X */ X do { X if (ch == '\f') X continue; X if (ch == '\n') X break; X *cs++ = ch; X n--; X } while (n > 0 && (ch = getc(iop)) != EOF); X if (ch == EOF) { X if (ungetc(ch, iop) == EOF && !feof(iop)) { X /* Shouldn't happen since a getc() was just done */ X fatal("fgetline - ungetc failed"); X /*NOTREACHED*/ X } X } X else if (ch != '\n') { X fatal("fgetline - input line too long"); X /*NOTREACHED*/ X } X *cs = '\0'; X return(s); X } X#endif X if ((ch = getc(iop)) != '\n') { X /* X * If EOF was just read it will be noticed next time through X */ X if (ungetc(ch, iop) == EOF && !feof(iop)) { X /* Shouldn't happen since a getc() was just done */ X fatal("fgetline - ungetc failed"); X /*NOTREACHED*/ X } X } X *cs++ = '\f'; X *cs = '\0'; X return(s); X } X X /* X * Check for "weird" input characters is made in proc() X */ X while (n-- > 0) { X if (ch == '\f' || ch == '\n') X break; X *cs++ = ch; X if ((ch = getc(iop)) == EOF) X break; X } X X if (ch == EOF && cs == s) /* Nothing was read */ X return((char *) NULL); X if (ch == '\f') { X if (ungetc(ch, iop) == EOF) X (void) fprintf(stderr, "fgetline - can't ungetc??\n"); X } X else if (ch != '\n' && ch != EOF) { X fatal("fgetline - input line too long"); X /*NOTREACHED*/ X } X *cs = '\0'; X return(s); X} X X/*VARARGS*/ Xfatal(s, a, b, c, d, e, f, g, h, i, j) Xchar *s; X{ X X (void) fprintf(stderr, "%s: ", progname); X (void) fprintf(stderr, s, a, b, c, d, e, f, g, h, i, j); X (void) fprintf(stderr, "\n"); X cleanup(); X /*NOTREACHED*/ X} X X/* X * Clean up and exit after an error X */ Xcleanup() X{ X#ifdef KANJI X if (kfontopen) closekfont(); X#endif X exit(1); X} X END_OF_FILE if test 29448 -ne `wc -c <'lwf.c'`; then echo shar: \"'lwf.c'\" unpacked with wrong size! fi # end of 'lwf.c' fi echo shar: End of archive 2 \(of 3\). cp /dev/null ark2isdone MISSING="" for I in 1 2 3 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 3 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 -- -- Greg, lee@uhccux.uhcc.hawaii.edu