🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: mod.mac.sources
Article #44

PSPrinter.src

#44
From: macintosh
Date: Tue, 24 Feb 1987 08:10
221 lines
5338 bytes
[PSPrinter.src]

Below, you will find the Rascal source to PSPrinter.  The Desk
Accessory has also been posted (to mod.mac.binaries, I think).

PSPrinter is a desk accessory that sends PostScript files
directly to your AppleTalked LaserWriter.  

Files sent to a LaserWriter via PSPrinter must be of type TEXT,
and they must be complete PostScript files:  PSPrinter does
not send any information to the printer except to lengthen the
default timeout, and to initialize the LaserWriter's coordinate
system ("initmatrix").

Scott Gillespie
Reed College

---

program PSPrinter;

Uses    __ToolTraps __DeskLib
(*$U+*)   uMacPrint ;

Link   __NoSyscall, __ToolLink __SFNames  __MacPrint  __DeskLib  :;

Const
    WhichPrinter    = $947; (* Low-mem address of type of installed printer *)
    lPrDocClose     = $00050000L;
    prCommand       = 1L;
    
    cNumItem = 4;
    cStringlist = 1;    
    cInfLog = 1;  (* info dialog *)    
    cAlrt = 2;
    cMenu = 1;
    cAbout = 3;
    
    
    realIOAbort = -27;
    realMemFull = -108;
    realPrintNotfound = -4101;
    realLostCont = -4100;
    realUserAbort = 128;
    
    errIOAbort = 1;
    errMemFull = 2;
    errPrintNotfound = 3;
    errLostCont = 4;
    errNoLaser = 5;
    errGeneric = 6;

Var
  InfLog: DialogPtr;
  Name: Ptrb;
  Vref,Menu: Integer;
  MenuHand: MenuHandle;

Function Error(i: Integer): Boolean;
Var
  S: Str255;
{
  If !i Then Return(False);
  Error := True;  
  Case i of
    realUserAbort: Return;
    errNoLaser:   i:= errNoLaser;
    realIOAbort:  i:= errIOAbort;
    realMemFull:  i:= errMemFull;
    realPrintNotfound: i:= errPrintNotfound;
    realLostCont: i:= errLostCont;
    Otherwise
      i:=errGeneric;
  End;
  GetIndString(@S,MapResID(cStringList),i);
  ParamText(Name,S,"","");
  If StopAlert(MapResId(cAlrt),Nil) Then;
};

(* ------- Generic Routines for Manipulating DBoxes -------- *)

procedure mygetitem(thelog: DialogPtr; item:integer; hand: ^Handle);
var
   box: Rect;
   kind: integer;
{
  getditem(thelog,item,@kind,hand,box);
};

procedure setnotext(thelog:DialogPtr; item: integer; str:str255);
var
   itemhand: Handle;
{
  mygetitem(thelog,item,@itemhand);
  setitext(itemhand,str);
};

procedure setdnum(thelog: DialogPtr; itemno:Integer; val: Longint);
var
   str: block[30];
{
  numtostring(val,str);
  setnotext(thelog,itemno,str);
};
  
(* --------------- *)

Procedure InfoCount(L: Longint);
{
  SetDNum(InfLog,cNumItem,L);
};

Procedure SetInfoDialog(N: Ptrb);
{
  ParamText(N,"","","");
  InfLog := GetNewDialog(MapResId(cInfLog),Nil,-1L);
  DrawDialog(InfLog);
};
  
Procedure DumpInfoDialog(); DisposDialog(InfLog);

procedure OpenPrinter();
{
   prctlcall(iPrDevCtl, lprReset, 0L, Nil);
     (* The LaserWriter's default coordinate system has 0,0 at lower
        left; if the next call is not made, everything printed will
        be upside down and mirror-imaged *) 
   prctlcall(iPrIOCtl, " initmatrix\n "+2, 12L, prCommand);
   prctlcall(iPrIOCtl, " statusdict /waittimeout 600 put\n "+2, 33L, prCommand);
};

procedure ClosePrinter();
{
   prctlcall(iPrDevCtl, lPrDocClose, Nil, Nil);
};

Proc SendToLaser(); 
Const
    BufSize = 1024;
Var
    Buf: Byte[BufSize];
    f,eof: Integer;
    Amt,Left: Longint;
{
  OpenPrinter();
  
  If !Error(PrError()) Then {
    fopen(@f,Name,0,Vref);
    fLength(f,@Left);
    SetInfoDialog(Name);
    Loop(,,feof(f,@eof),eof) {
      InfoCount(Left);
      amt := BufSize;
      Fread(f,Buf,@amt);
      prctlcall(iPrIOCtl,Buf,amt, prCommand);
      Left -= amt;
      If Error(PrError()) Then Break;
      };
    DumpInfoDialog();
    fclose(f);
    };
    
  ClosePrinter();
};

Proc TalkAbout();
Var
  MyLog: DialogPtr;
  Item: Integer;
{
  MyLog := GetNewDialog(MapResID(cAbout),Nil,-1L);
  ModalDialog(Nil,@Item);
  DisPosdialog(MyLog);
};

Proc _Menu(id,item: Integer);
Var
  Good : Integer;
{
  If ID<>Menu Then return;
  
  Case item of
    3: TalkAbout();
    4: Reqhalt();
    1: {
       PrDrvrOpen();            
       If (-(ptrb(WhichPrinter)^) <> bDevLaser) then {
         If Error(errNoLaser) Then;
         Return;
         };       
       GetFile(@Name,@Vref,@good);
       If Good Then 
         SendToLaser();
       };
  End;
};    

Proc _Init();
{
  Name := "";
  Menu := MapResID(cMenu);
  If IsDARun() Then
    SetDAMenuID(Menu);
  MenuHand := GetMenu(Menu);
  InsertMenu(MenuHand,0);
  DrawMenuBar();
};

Proc _Halt();
{
  DeleteMenu(Menu);
  DisposeMenu(MenuHand);
  DrawMenuBar();
};

Proc _Main();
{
  If IsDARun() Then
    SetDAMenuID(Menu);
};
---
Technical Details
Message-ID: <2335@felix.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!sri-unix!hplabs!felix!macintosh

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!sri-unix!hplabs!felix!macintosh
From: macintosh@felix.UUCP
Newsgroups: mod.mac.sources
Subject: PSPrinter.src
Message-ID: <2335@felix.UUCP>
Date: Tue, 24-Feb-87 03:10:47 EST
Article-I.D.: felix.2335
Posted: Tue Feb 24 03:10:47 1987
Date-Received: Thu, 26-Feb-87 23:47:25 EST
Sender: root@felix.UUCP
Reply-To: macintosh@felix.UUCP (The Moderator)
Organization: FileNet Corp., Costa Mesa, Ca.
Lines: 221
Approved: bytebug@felix.UUCP (Roger L. Long)