home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-06-20 | 28.7 KB | 1,178 lines |
- 18-Jun-88 14:41:49-MDT,30525;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:41:03 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22579; Sat, 18 Jun 88 14:40:58 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24751; Sat, 18 Jun 88 14:40:53 MDT
- Date: Sat, 18 Jun 88 14:40:53 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182040.AA24751@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: SerialPrint.c.shar
-
- #! /bin/sh
- #
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- #
- # 3 README
- # 20 SerialPrint.c
- # 6 SerialPrint.rsrc
- #
- echo 'Extracting README'
- if test -f README; then echo 'shar: will not overwrite README'; else
- cat << '________This_Is_The_END________' > README
- This is the source for a desk accessory I wrote to get letter-quality
- printing from my Mac without buying a LaserWriter. I wrote it to be
- as general as possible. I wanted to have:
-
- User-selectable strings for initializing the printer, etc.
- Variable left margins and page length.
- Support of either sheet feed or continuous feed.
- A bunch of communications port options.
- Compatible with 64k ROMs (God knows why).
- Expands tabs, or not, as required.
- Prints text only files with carriage return at end of each line.
- Most important: work on as many different printer types as possible.
-
- I have posted the binhex'd DA to comp.binaries.mac. These are the sources.
- The DA worked with my Tandy DMP-110 and with my Silver-Reed Penman Deluxe
- with the I/F40 Serial Interface. I tried a bunch of baud rates, and
- both CTS and ^S^Q flow control. I regret that I didn't support ^S^Q
- flow control for 64k ROMs, but you never can tell whether the RAM serial
- driver is going to be present...
-
- It seemed to work with all the printer settings I threw at it, so I posted
- the binhex, and here are the sources. The comments are kinda skimpy, but
- I believe I have used enough meaningful variable names to compensate.
- Even if you see no need for the desk accessory since your boss just got
- a LaserWriter or whatever, you might be able to glean some programming
- tips from this code. How to send junk out the serial port, how to push
- radio buttons, how to manipulate STR# resources in memory, how to
- highlite the "OK" button when using ModalDialog() instead of Alert().
-
- You might even see some huge bugs, and then be able to flame me in
- next week's comp.sys.mac (or whatever they want to call it next week).
- If you want, you can flame me for not writing a Chooser-compatible
- printer driver instead of this. (Make my day.)
-
- The system I used was LSC and RMaker. Code may differ for other systems.
- --
- *********************************************************************
- *Earle R. Horton, H.B. 8000, Dartmouth College, Hanover, NH 03755 *
- *********************************************************************
- ________This_Is_The_END________
- if test `wc -l < README` -ne 39; then
- echo 'shar: README was damaged during transit'
- echo ' (should have been 39 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting SerialPrint.c'
- if test -f SerialPrint.c; then echo 'shar: will not overwrite SerialPrint.c'; else
- cat << '________This_Is_The_END________' > SerialPrint.c
- /*
- * SerialPrint.c. A generic serial printer driver in desk accessory
- * form for the Macintosh.
- * Earle R. Horton. August 17, 1987
- * LightspeedC source.
- * To use, build a project with this file and MacTraps in it.
- * Set the project type to Desk Accessory. Build the desk accessory.
- * Run RMaker to put the owned resources in the suitcase file.
- * Do not attempt to "Run" from within LightspeedC. The use of owned
- * resources presents problems here.
- */
- #include <DeviceMgr.h>
- #include <WindowMgr.h> /* includes QuickDraw.h, MacTypes.h */
- #include <EventMgr.h>
- #include <MenuMgr.h>
- #include <FileMgr.h>
- #include <DialogMgr.h>
- #include <SerialDvr.h>
- #include <StdFilePkg.h>
- #include <ControlMgr.h>
-
- # define nil 0L
-
- /* global variables and macros to use them */
- typedef struct{
- int dummy[9];
- } pconfig,*Pcfg,**Pfg;
- Pfg settings = nil;
- /* Be a real Mac cowboy, access data by the handle. */
- #define pport ((*settings)->dummy[0])
- #define pbaud ((*settings)->dummy[1])
- #define sheetfeed ((*settings)->dummy[2])
- #define tabstops ((*settings)->dummy[3])
- #define width ((*settings)->dummy[4])
- #define margin ((*settings)->dummy[5])
- #define pagelength ((*settings)->dummy[6])
- #define XonXoff ((*settings)->dummy[7])
- #define SDClose ((*settings)->dummy[8])
- /* Yeeeeee-Hah !! I won't even lock it! */
- typedef struct bauds{
- int rate;
- char label[10];
- }BAUDS;
- BAUDS mybauds[] = { /* Baud rate constant table. */
- { baud300, "\p300"}, /* Should use a string list. */
- { baud600, "\p600"}, /* But these are numbers, so I */
- { baud1200, "\p1200"}, /* Think it's OK. */
- { baud1800, "\p1800"},
- { baud2400, "\p2400"},
- { baud3600, "\p3600"},
- { baud4800, "\p4800"},
- { baud7200, "\p7200"},
- { baud9600, "\p9600"},
- { baud19200, "\p19200"}
- };
- typedef struct { /* Structure description of STR# */
- int numstrings; /* resource. */
- unsigned char thestrings[];
- }stringlist,**StrList;
- StrList mystrings = nil;
- Point where = {80,80};
- SFTypeList mytypelist = {'TEXT'};
- ParamBlockRec iopb;
- ParamBlockRec filepb;
- char _iobuf[522];
- int ResID;
- static int phone = FALSE;
- static int printer = FALSE;
- static MenuHandle MHandl;
- static CHANGE1 = FALSE;
- static CHANGE2 = FALSE;
- static int rom,machine;
-
- /* Useful constants */
- #define OWNED_BASE -16384
- #define BAUDLABEL 8 /* Item numbers of configuration box. */
- #define BAUDBUTTON 9
- #define DONEITEM 1
- #define STOPITEM 2
- #define MODEM 5
- #define PRINTER 6
-
- /* Menu item numbers */
- #define ABOUTITEM 1
- #define SETITEM 2
- #define PAGEITEM 3
- #define FLOWITEM 4
- #define PRINTITEM 5
- #define SAVEITEM 6
- #define QUITITEM 7
- /* Printer setup editText Item numbers */
-
- #define TABSITEM 5
- #define WIDTHITEM 6
- #define MARGINITEM 7
- #define LINESITEM 8
-
- #define EOLITEM 11
- #define INITITEM 12
- #define TOPITEM 13
- #define EOPITEM 14
- #define EOFITEM 15
- #define SHEETITEM 19
- #define CONTINUOUSITEM 20
- #define NUMSTRINGS 5
- #define RESPAD 24
-
- #define SERRESET 8 /* csCodes for PBControl */
- #define SERSHAKE 10
-
- #define FLOWBOX (ResID + 4) /* Should have done all like this */
- /* forgot... */
- #define XONCR ((char)17)
- #define XOFFCR ((char)19)
-
-
- main(p, d, n)
- cntrlParam *p; /* ==> parameter block */
- DCtlPtr d; /* ==> device control entry */
- int n; /* entry point selector */
-
- {
-
- /* check to make sure our data area was allocated */
-
- if (d->dCtlStorage == 0)
- {
- if (n == 0) /* open */
- CloseDriver(d->dCtlRefNum);
- }
- else switch (n) /* dispatch */
- {
- case 0: /* open */
- ResID = (~d->dCtlRefNum)<<5 | OWNED_BASE;
- d->dCtlMenu = ResID;
- MHandl = GetMenu(ResID);
- if(MHandl == nil){
- CloseDriver(d->dCtlRefNum);
- return(0);
- }
- InsertMenu(MHandl,0);
- DrawMenuBar();
- if ((settings = (Pfg)(GetResource('Stng',ResID))) == nil ||
- (mystrings = (StrList)(GetResource('STR#',ResID))) == nil){
- CloseDriver(d->dCtlRefNum);
- return(0);
- }
- LoadResource(settings);
- HNoPurge(settings);
- LoadResource(mystrings);
- HNoPurge(mystrings);
- HLock(mystrings);
- Environs(&rom,&machine);
- if(rom < 117){ /* If < 512KE, no XOn/XOff */
- SDClose = FALSE;
- XonXoff = FALSE;
- }
- break;
-
- case 2: /* control */
- switch (p->csCode){
- case accMenu:
- switch (p->csParam[1]){
- case ABOUTITEM:
- DoAbout();
- break;
- case SETITEM:
- if(!prsetup())
- CloseDriver(d->dCtlRefNum);
- break;
- case PAGEITEM:
- if(!pagesetup())
- CloseDriver(d->dCtlRefNum);
- break;
- case FLOWITEM:
- moresettings();
- break;
- case PRINTITEM:
- ffprint();
- break;
- case SAVEITEM:
- if(CHANGE1){
- ChangedResource(settings);
- }
- if(CHANGE2){
- ChangedResource(mystrings);
- }
- if(CHANGE1 || CHANGE2)
- UpdateResFile(HomeResFile(settings));
- break;
- case QUITITEM:
- CloseDriver(d->dCtlRefNum);
- break;
- }
- break;
- }
- break;
- case 4: /* close */
- quit();
- break;
- }
-
- /* done */
-
- return(0);
- }
- quit()
- {
- if(MHandl != nil){
- DeleteMenu(ResID);
- ReleaseResource(MHandl);
- DrawMenuBar();
- MHandl = nil;
- }
- if(SDClose){
- if(printer)RAMSDClose(sPortA);
- if(phone)RAMSDClose(sPortB);
- }
- if (settings != nil) { /* We don't want to leave our junk laying */
- HPurge(settings); /* around... */
- ReleaseResource(settings);
- settings = nil;
- }
- if (mystrings != nil) {
- ReleaseResource(mystrings);
- mystrings = nil;
- }
- }
- pushradiobutton(thedialog,itemhit,first,last) /* push a radio Button */
- DialogPtr thedialog; /* set itemhit, unset */
- int itemhit,first,last; /* all others in range */
- {
- int itemtype,i;
- Handle itemhandle; /* Does check boxes, too. */
- Rect itemrect;
- ControlHandle itemcntlhand;
- if(first ==0) return;
- for(i=first-1;last-i++;){
- GetDItem(thedialog,i,&itemtype,&itemhandle,&itemrect);
- itemcntlhand = (ControlHandle)itemhandle;
- if(i == itemhit) SetCtlValue(itemcntlhand,1);
- else SetCtlValue(itemcntlhand,0);
- }
- }
- pagesetup() /* Derive left margin, tab stops, page length */
- { /* and number columns. */
- DialogPtr pagedialog;
- WindowPtr tempport;
- int itemhit,i,numtype,donetype;
- Handle numitem,doneitem;
- Rect numbox,donebox;
- Str255 numtext;
- long temp;
- if((pagedialog = GetNewDialog(ResID+1, 0L,(WindowPtr) -1)) == nil)
- return FALSE;
- GetDItem(pagedialog,DONEITEM,&donetype,&doneitem,&donebox);
- for(i = TABSITEM - 1;LINESITEM - i++;){
- GetDItem(pagedialog,i,&numtype,&numitem,&numbox);
- NumToString((long)((*settings)->dummy[i-2]),numtext);
- SetIText(numitem,numtext);
- }
- GetPort(&tempport);
- SetPort(pagedialog);
- PenSize(3,3);
- InsetRect(&donebox,-4,-4);
- FrameRoundRect(&donebox,16,16);
- itemhit = 0;
- while(itemhit != DONEITEM){
- ModalDialog(0L,&itemhit);
- switch(itemhit){
- default:
- break;
- }
- }
- for(i = TABSITEM - 1;LINESITEM - i++;){
- GetDItem(pagedialog,i,&numtype,&numitem,&numbox);
- GetIText(numitem,numtext);
- StringToNum(numtext,&temp);
- (*settings)->dummy[i-2] = (int)temp;
- }
- DisposDialog(pagedialog);
- SetPort(tempport);
- CHANGE1 = TRUE;
- return(TRUE);
- }
- #define XONXOFF 2
- #define CTS 3
- #define SDCLOSE 4
- moresettings() /* If 64k ROM or XL, show dialog, do nothing. */
- {
- DialogPtr flowdialog;
- WindowPtr tempport;
- int itemhit,donetype;
- Handle doneitem;
- Rect donebox;
- if((flowdialog = GetNewDialog(FLOWBOX,0L,(WindowPtr) -1)) == nil)
- return FALSE;
- GetDItem(flowdialog,DONEITEM,&donetype,&doneitem,&donebox);
- GetPort(&tempport);
- SetPort(flowdialog);
- PenSize(3,3);
- InsetRect(&donebox,-4,-4);
- FrameRoundRect(&donebox,16,16);
- if (SDClose)
- pushradiobutton(flowdialog, SDCLOSE,SDCLOSE,SDCLOSE);
- else
- pushradiobutton(flowdialog,0,SDCLOSE,SDCLOSE);
- if (XonXoff)
- pushradiobutton(flowdialog,XONXOFF,XONXOFF,CTS);
- else
- pushradiobutton(flowdialog,CTS,XONXOFF,CTS);
- itemhit = 0;
- while(itemhit != DONEITEM){
- ModalDialog(0L,&itemhit);
- if( rom >= 117){ /* If ROM version < 117, forget this. */
- switch(itemhit){
- case XONXOFF:
- XonXoff = TRUE;
- pushradiobutton(flowdialog, itemhit,XONXOFF,CTS);
- break;
- case CTS:
- XonXoff = FALSE;
- pushradiobutton(flowdialog, itemhit,XONXOFF,CTS);
- break;
- case SDCLOSE:
- SDClose = !SDClose;
- if (SDClose)
- pushradiobutton(flowdialog,
- SDCLOSE,SDCLOSE,SDCLOSE);
- else
- pushradiobutton(flowdialog,0,SDCLOSE,SDCLOSE);
- break;
- }
- }
- }
- CHANGE1 = TRUE;
- DisposDialog(flowdialog);
- SetPort(tempport);
- return TRUE;
- }
-
- /* This one enquires for and sets the printer variables.
- * Radio buttons (cute) are used.
- */
- prsetup()
- {
- DialogPtr printdialog;
- WindowPtr tempport;
- int itemhit,i,baudtype,edittype,donetype;
- Handle bauditem,doneitem,edititem;
- Rect baudbox,donebox,editbox;
- Str255 thestring;
- unsigned char *strptr;
- long length;
- if (pbaud<0 || pbaud>9) pbaud = 0;
- if((printdialog = GetNewDialog(ResID, 0L,(WindowPtr) -1)) == nil)
- return FALSE;
- GetDItem(printdialog,BAUDLABEL,&baudtype,&bauditem,&baudbox);
- GetDItem(printdialog,DONEITEM,&donetype,&doneitem,&donebox);
- SetIText(bauditem,mybauds[pbaud].label);
- /* This gets the editText items in the dialog box to contain
- * the strings from one of our string lists.
- */
- strptr = &((*mystrings)->thestrings[0]);
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- SetIText(edititem,strptr);
- strptr += (*strptr) + 1;
- }
- GetPort(&tempport);
- SetPort(printdialog);
- PenSize(3,3);
- InsetRect(&donebox,-4,-4);
- FrameRoundRect(&donebox,16,16);
- pushradiobutton(printdialog, pport+5,5,6);
- pushradiobutton(printdialog,SHEETITEM + sheetfeed,SHEETITEM,
- CONTINUOUSITEM);
- itemhit = 0;
- while(itemhit != DONEITEM){
- ModalDialog(0L,&itemhit);
- switch(itemhit){
- case MODEM: /* port change. */
- case PRINTER:
- pport = itemhit - MODEM;
- pushradiobutton(printdialog,itemhit,
- MODEM,PRINTER);
- break;
- case BAUDBUTTON: /* next baud rate change */
- /* Ten radio buttons would be just too much. */
- if(++pbaud == 10) pbaud = 0;
- SetIText(bauditem,mybauds[pbaud].label);
- break;
- case SHEETITEM: /* feed options */
- case CONTINUOUSITEM:
- sheetfeed = itemhit - SHEETITEM;
- pushradiobutton(printdialog,
- itemhit,SHEETITEM,CONTINUOUSITEM);
- break;
- }
- }
- /* The user has set the baud rate and the port, and also possibly
- * edited the printer control strings. Since we used ModalDialog()
- * with no filterproc we don't know whether any of the strings have
- * been changed. Therefore we just rebuild the whole string list.
- * First, determine the length.
- */
- length = (long) (sizeof(int)+RESPAD);
- /* Try doing this with RESPAD = 0! */
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- GetIText(edititem,thestring);
- length += (long) thestring[0];
- }
- /* Size might have changed, so we unlock the handle and attempt to
- * resize it. Should work, unless no RAM left. */
- HUnlock(mystrings);
- SetHandleSize(mystrings,length);
- if (GetHandleSize(mystrings)!=length){ /* Abort on error. */
- DisposDialog(printdialog);
- SetPort(tempport);
- return(FALSE);
- }
- HNoPurge(mystrings);
- HLock(mystrings);
- /* Rebuild the STR# from the item list. */
- strptr = &((*mystrings)->thestrings[0]);
- for(i = EOLITEM-1;EOFITEM - i++;){
- GetDItem(printdialog,i,&edittype,&edititem,&editbox);
- GetIText(edititem,strptr);
- strptr += (*strptr) + 1;
- }
- DisposDialog(printdialog);
- SetPort(tempport);
- CHANGE2 = CHANGE1 = TRUE;
- return(TRUE);
- }
- waitnextpage() /* For sheet feeders. */
- {
- DialogPtr sheetdialog;
- WindowPtr tempport;
- int itemhit,donetype;
- Handle doneitem;
- Rect donebox;
- if((sheetdialog = GetNewDialog(ResID+3, 0L,(WindowPtr) -1)) == nil)
- return FALSE;
- GetDItem(sheetdialog,DONEITEM,&donetype,&doneitem,&donebox);
- GetPort(&tempport);
- SetPort(sheetdialog);
- PenSize(3,3);
- InsetRect(&donebox,-4,-4);
- FrameRoundRect(&donebox,16,16);
- ModalDialog(0L,&itemhit);
- DisposDialog(sheetdialog);
- SetPort(tempport);
- if(itemhit == STOPITEM) return FALSE;
- return TRUE;
- }
-
- char outbuf[200]; /* Or whatever size you think appropriate. */
- char inbuf[200];
- ffprint()
- {
- register int nline,nchars,i,tab;
- register ParmBlkPtr pb;
- char c;
- int serconfig,drivernum,length,filefinished;
- EventRecord myevent;
- long count1;
- unsigned char *eolstr,*initstr,*topstr,*eopstr,*eofstr;
-
- pb = &iopb;
- /* Get strings from string list. (Pascal strings) */
- eolstr = eofstr = &((*mystrings)->thestrings[0]);
- initstr = (eofstr += (*eofstr) + 1);
- topstr = (eofstr += (*eofstr) + 1);
- eopstr = (eofstr += (*eofstr) + 1);
- eofstr += (*eofstr) + 1;
-
- tab = tabstops - 1;
- switch (pport){ /* get the correct port */
- case 0: /* modem port */
- if(!phone) {
- prinit("\p.AOut");
- phone = TRUE;
- if(rom >= 117)RAMSDOpen(sPortA);
- }
- drivernum = AoutRefNum;
- break;
- case 1: /* printer port */
- if(!printer) {
- prinit("\p.BOut");
- printer = TRUE;
- if(rom >= 117)RAMSDOpen(sPortB);
- }
- drivernum = BoutRefNum;
- break;
- }
- /* set up the io parameter block for writing to the serial driver. */
- /* a control call resets the baud rate */
- pb->ioParam.ioRefNum = drivernum;
- pb->ioParam.ioCompletion = nil;
- ((cntrlParam *)pb)->csCode = SERRESET;
- serconfig = data8 + noParity + stop20;
- serconfig += mybauds[pbaud].rate;
- ((cntrlParam*)pb)->csParam[0] = serconfig;
- PBControl(pb,FALSE);
- #define shake ((SerShk*)&((cntrlParam*)pb)->csParam[0])
- if(rom >= 117){ /* If ROM version < 117, forget this. */
- shake->errs = FALSE;
- shake->evts = FALSE;
- shake->fDTR = FALSE;
- shake->fInX = FALSE;
- if(XonXoff){
- shake->fXOn = TRUE;
- shake->fCTS = FALSE;
- shake->xOn = XONCR;
- shake->xOff = XOFFCR;
- }
- else {
- shake->fXOn = FALSE;
- shake->fCTS = TRUE;
- }
- ((cntrlParam *)pb)->csCode = SERSHAKE;
- PBControl(pb,FALSE);
- }
- #undef shake
- pb->ioParam.ioPosMode = 0;
- pb->ioParam.ioPosOffset = 0;
-
- for(nchars=0;margin-nchars;nchars++){ /* pad the sucker on the */
- outbuf[nchars] = ' '; /* left with margin spaces */
- }
-
- while(ffopen()){
- printstring(initstr);
- filefinished = FALSE;
- nline = 0;
- while (!filefinished){
- if(nline == 0){ /* top of a page */
- printstring(topstr);
- nline++;
- }
- else if (nline == pagelength + 2){ /* bottom */
- printstring(eopstr);
- nline = 0;
- if(sheetfeed == 0) {
- if (waitnextpage() == FALSE) {
- PBClose(&filepb,FALSE);
- return;
- }
- }
- }
- else { /* body */
- if(!getline(inbuf,width,&length))
- filefinished = TRUE;
- nchars = 0;
- i = 0;
- while( i <= width && nchars <= length){
- switch(c = inbuf[nchars++]){
- case 9: /* a tab */
- if (tab){
- do{
- outbuf[margin + i++] = ' ';
- }while((i % tab)!=0);
- }
- else
- outbuf[margin + i++]= c;
- break;
- default:
- outbuf[margin + i++]= c;
- break;
- }
- }
- count1 = (long) (i + margin - 1);
- nline++; /* count lines */
- /* check after every line for user abort */
- /* Admitted, less effective at high baud rates. */
- if (GetNextEvent(everyEvent, &myevent)) {
- switch (myevent.what) {
- case keyDown:
- c = LoWord(myevent.message & charCodeMask);
- if (myevent.modifiers & cmdKey) {
- if( c == '.'){
- PBClose(&filepb,FALSE);
- return;
- } /* quit now */
- }
- break;
- default:
- break;
- }
- }
- /* write out the expanded line */
- /* to the proper device driver. */
- if(!filefinished){
- pb->ioParam.ioBuffer = outbuf;
- pb->ioParam.ioReqCount = count1;
- PBWrite(pb,FALSE);
- printstring(eolstr);
- }
- }
- }
- PBClose(&filepb,FALSE);
- printstring(eofstr);
- }
- }
- char stringbuf[256];
- /*
- * Used for interpreting the printer control codes. Not very efficient,
- * since they are interpreted every time sent.
- */
- printstring(string)
- unsigned char string[];
- {
- register unsigned int i;
- long count;
- count = 0L;
- i = string[0];
- for(i=0;string[0]-i++;){
- switch (string[i]){
- case '^':
- stringbuf[count] = 31 & string[++i];
- break;
- default:
- stringbuf[count] = string[i];
- break;
- }
- count++;
- }
- iopb.ioParam.ioBuffer = stringbuf;
- iopb.ioParam.ioReqCount = count;
- PBWrite(&iopb,FALSE);
- }
- prinit(name) /* Open a driver by name. */
- /* ROM serial driver? RAM serial driver? Who cares? */
- /* Seriously, if ROM is 128k or newer, we do the RAM */
- /* serial driver open later. */
- char *name;
- {
- iopb.ioParam.ioNamePtr = (StringPtr)name;
- iopb.ioParam.ioCompletion = nil;
- iopb.ioParam.ioPermssn = 0;
- PBOpen(&iopb,FALSE);
- }
- ffopen ()
- {
- static SFReply frommac;
- register ParmBlkPtr pb;
-
- pb = &filepb;
-
- SFGetFile (where, 0L, 0L, 1, mytypelist, 0L, &frommac);
- if (frommac.good) {
- pb->ioParam.ioNamePtr = frommac.fName;
- pb->ioParam.ioCompletion = nil;
- pb->ioParam.ioVersNum = 0;
- pb->ioParam.ioMisc = _iobuf;
- pb->ioParam.ioVRefNum = frommac.vRefNum;
- pb->ioParam.ioPermssn = fsRdPerm;
- pb->ioParam.ioPosMode = 3456;
- PBOpen(pb,FALSE);
- if(pb->ioParam.ioResult){
- return (FALSE);
- }
- else return (TRUE);
- }
- else return (FALSE);
- }
- /*
- * Read a line from a file, and store the bytes in the supplied buffer. The
- * "nbuf" is the length of the buffer. Return FALSE if no bytes read.
- * filepb.ioParam.ioPosMode determines that we stop at the newline
- * character, which is <cr>. Should possibly stop on error, but I
- * think error implies no bytes read (?).
- */
- getline(buf,nbuf,nbytes)
- register char buf[];
- int nbuf;
- int *nbytes;
- {
- register int i;
- register ParmBlkPtr pb;
-
- pb = &filepb;
-
- pb->ioParam.ioPosMode = 3456;
- /* This means reads stop at '\r', see IM for details. */
- pb->ioParam.ioBuffer = buf;
- pb->ioParam.ioReqCount = (long)nbuf;
- PBRead(pb,FALSE);
- if ((i = (int)pb->ioParam.ioActCount) == 0){
- *nbytes = 0;
- return (FALSE);
- }
- if(buf[i-1] == '\r') i--; /* strip CR */
- *nbytes = i;
- return (TRUE);
- }
- /*
- * DoAbout:
- *
- * Dialog box handler for extended about box. Put up a dialog
- * box with help information. Cycle through a string list
- * (STR# ID HLIST) to change the contents of a statText item.
- * Help information is updated by changing the contents of the
- * STR#, making things easier to localize.
- */
- #define HDLOG ResID+2
- #define HLIST ResID+1
- #define HITEM 5
- #define MORE 1
- #define BACK 2
- #define ENOUGH 3
- #define int16 short
- DoAbout()
- {
- int16 res,i,helptype,nlimit;
- DialogPtr helpdialog;
- WindowPtr tempport;
- Str255 helpstring;
- Handle helpitem,moreitem;
- Rect helpbox,morebox;
- int16 **stringlist;
- int16 moretype;
- /* Prepare to use dialog box. */
- helpdialog = GetNewDialog(HDLOG,(long)0,(WindowPtr) -1);
- GetDItem(helpdialog,HITEM,&helptype,&helpitem,&helpbox);
- GetDItem(helpdialog,MORE,&moretype,&moreitem,&morebox);
- GetPort(&tempport);
- SetPort(helpdialog);
- PenSize(3,3);
- InsetRect(&morebox,-4,-4);
- FrameRoundRect(&morebox,16,16);
- /* How many strings? */
- stringlist = (int16 **)GetResource('STR#',HLIST);
- if(stringlist == nil) return FALSE;
- LoadResource(stringlist);
- nlimit = (int16) **stringlist;
- i = 0;
- res = 1;
- while(res != ENOUGH){ /* Done when quit button selected. */
- if (res == BACK) i--; /* Cycle back. */
- else i++; /* Cycle forwards. */
- if (i<1) i=nlimit; /* Choose < 1, use last string. */
- GetIndString(helpstring,HLIST,i); /* Get the string. */
- if(helpstring[0] == '\0'){ /* Out of range, last string. */
- i=1; /* Cycle back to first one. */
- GetIndString(helpstring,HLIST,i); /* Get it. */
- }
- SetIText(helpitem,helpstring); /* Use it. */
- ModalDialog(0L,&res); /* ModalDialog handles events. */
- }
- DisposDialog(helpdialog); /* Done, clean up. */
- SetPort(tempport);
- ReleaseResource(stringlist);
- return TRUE;
- }
-
- ________This_Is_The_END________
- if test `wc -l < SerialPrint.c` -ne 758; then
- echo 'shar: SerialPrint.c was damaged during transit'
- echo ' (should have been 758 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting SerialPrint.rsrc'
- if test -f SerialPrint.rsrc; then echo 'shar: will not overwrite SerialPrint.rsrc'; else
- cat << '________This_Is_The_END________' > SerialPrint.rsrc
- *Resource definition file for Device Dependent Printing Desk Accessory
-
- !LSC:SerialPrint:Serial
- DFILDMOV
-
- Type DITL
- Printer Dialog Template,-16000
- 20
-
- * 1
- BtnItem Enabled
- 224 143 240 213
- Done
-
- * 2
- StatText Enabled
- 149 7 165 120
- Bottom of page
-
- * 3
- StatText Disabled
- 6 91 23 219
- Printer Port Setup
-
- * 4
- StatText Disabled
- 30 6 46 51
- Port:
-
- * 5
- RadioItem Enabled
- 30 57 46 157
- Modem Port
-
- * 6
- RadioItem Enabled
- 30 165 46 265
- Printer Port
-
- * 7
- StatText Disabled
- 57 6 73 81
- Baud Rate:
-
- * 8
- StatText Enabled
- 57 98 73 143
- runtime
-
- * 9
- BtnItem Enabled
- 58 153 74 218
- moreI
-
- * 10
- StatText Disabled
- 83 5 99 122
- Line Terminator
-
- * 11
- EditText Enabled
- 83 128 99 320
- runtime
-
- * 12
- EditText Enabled
- 105 128 121 320
- runtime
-
- * 13
- EditText Enabled
- 127 128 143 320
- runtime
-
- * 14
- EditText Enabled
- 149 128 165 320
- runtime
-
- * 15
- EditText Enabled
- 171 128 187 320
- runtime
-
- * 16
- StatText Disabled
- 105 6 121 123
- Initialize
-
- * 17
- StatText Disabled
- 127 7 143 124
- Top of page
-
- * 18
- StatText Enabled
- 171 8 187 121
- End of file
-
- * 19
- RadioItem Enabled
- 197 8 213 121
- Sheet feed
-
- * 20
- RadioItem Enabled
- 197 165 213 265
- Continuous
-
- Type DLOG
- Printer Config Box,-16000
- Serial Port Configuration
- 40 80 296 424
- Visible NoGoAway
- 1 ;; procID
- 0 ;; refCon
- -16000
-
- Type DLOG
- Page Setup Box,-15999
- Page Setup
- 48 51 165 449
- Visible NoGoAway
- 1 ;; procID
- 0 ;; refCon
- -15999
-
- Type DLOG
- Next Page Box,-15997
- Next Page
- 48 51 100 300
- Visible NoGoAway
- 1 ;; procID
- 0 ;; refCon
- -15997
-
- Type DITL
- Next Page Template,-15997
- 3
-
- * 1
- BtnItem Enabled
- 30 60 46 140
- Done
-
- * 2
- BtnItem Enabled
- 30 160 46 240
- Stop
-
- * 3
- StatText
- 8 8 24 292
- SerialPrint: Insert Next Sheet
-
-
- Type DITL
- Page Setup Template,-15999
- 10
-
- * 1
- BtnItem
- 96 165 112 235
- Done
-
- * 2
- StatText
- 64 201 82 316
- Lines per page
-
- * 3
- StatText
- 7 166 24 243
- Page Setup
-
- * 4
- StatText
- 34 5 50 50
- Tabs
-
- * 5
- EditText
- 34 135 52 167
- runtime
-
- * 6
- EditText
- 32 328 49 369
- runtime
-
- * 7
- EditText
- 64 136 80 177
- runtime
-
- * 8
- EditText
- 66 331 82 376
- runtime
-
- * 9
- StatText
- 64 5 80 122
- Left Margin
-
- * 10
- StatText
- 34 202 50 277
- Width
-
- Type Stng = GNRL
- Printer Settings,-16000
- .H ;; Printer port, 1200 baud,no sheet feed, tabstops 8, width = 90,
- 0001 0002 0000 0008 005A 0008 0037 0000 0000 ;;left margin 8, 55 lines/page
-
- Type MENU ;; Set procID of this menu to 0 with ResEdit
- SerialPrint menu,-16000 ;; for operation without la bombe
- SerialPrint
- About SerialPrintI
- Printer SettingsI
- Page SetupI
- Flow ControlI
- PrintI
- Save Settings
- Quit
-
- Type STR# ;; String list for EOL, EOP, BOP strings
- Printer control strings,-16000
- 5
- ^M ;; End of line
- ^[^W ;; Initialize printer
- ^M^M^M^M^M ;; beginning of page
- ^L ;; end of page
- ^L ;; end of document
-
- Type STR# ;; About this DA help strings
- Help Strings,-15999
- 12
- SerialPrint, Edit of August 17, 1987\0DEarle R. Horton\0DPortions Copyright THINK Technologies\0DCompiled with the Lightspeed
- C compiler and RMaker.
- SerialPrint is an adaptable printing program meant to be used in draft mode with printers for which no Macintosh printer driv
- er is available.
- It prints text-only files which have a carriage return at the end of every line.\0DThis revision does not wrap long lines at
- word boundaries.
- The Printer SettingsI menu allows you to change the port, baud rate, and five printer control strings. Your printer manual s
- hould have the appropriate settings to use.
- Non-printing characters are set using control character notation. For example, carriage return is "^M", line feed is "^J".\0
- DSome printers require ^M at the end of a line, some require ^M^J.
- To set the top margin, put the appropriate number of your printer's linefeed character combinations in the box marked "Top of
- page".
- If your printer does not recognize the formfeed character (^L), just put some newlines in the box marked "Bottom of page".
- The Page SetupI menu allows setting of tabstops, left margin, #columns in page, and page length. Page length is the number o
- f printed rows on the page, and does not include top and bottom margins.
- The flow control menu has no effect with 64k ROM or Mac XL systems, where CTS flow control only is used.\0DFor newer systems,
- this menu allows selection of either XOn/XOff or CTS.
- The flow control menu also allows you to specify whether the printer driver used is closed when you quit SerialPrint.\0D(Not
- done with 64k ROMs.)
- The most difficult part of using SerialPrint may be obtaining the proper printer cable. Obtain pinout diagrams of your Macin
- tosh and printer; take them to a responsible electronics technician.
- Settings are not saved unless the menu item is chosen. This edit of SerialPrint saves its settings in the system file.
-
- Type DLOG
- Extended AboutI Box,-15998
- About SerialPrint
- 60 86 242 412
- Visible NoGoAway
- 1 ;; procID
- 0 ;; refCon
- -15998 ;; itemsID
-
- Type DITL
- Extended AboutI Box Template,-15998
- 5
-
- BtnItem
- 152 44 171 109
- More
-
- BtnItem
- 152 129 171 190
- Less
-
- BtnItem
- 152 210 171 285
- Enough
-
- StatText Disabled
- 18 111 25 229
- SerialPrint
-
- StatText
- 46 8 142 310
- String list <OWNER> + 2.
-
- * This resource owned by: DRVR 12: local id 4
- Type DLOG
- more settings,-15996
- New Dialog
- 59 134 209 336
- Visible GoAway
- 1 ;; procID
- 0 ;; refCon
- -15996
-
- * This resource owned by: DRVR 12: local id 4
- Type DITL
- flow control template,-15996
- 4
-
- BtnItem
- 109 67 129 127
- done
-
- RadioItem
- 10 19 30 193
- XOn/XOff Flow control
-
- RadioItem
- 40 19 60 193
- CTS Flow Control
-
- ChkItem
- 70 19 90 193
- Close Driver on Quit
-
- ________This_Is_The_END________
- if test `wc -l < SerialPrint.rsrc` -ne 325; then
- echo 'shar: SerialPrint.rsrc was damaged during transit'
- echo ' (should have been 325 bytes)'
- fi
- fi ; : end of overwriting check
- exit 0
-