home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1992-11-29 | 5.3 KB | 241 lines | [ TEXT/MPS ]
// ©1992 Conrad Carlen & Manuel Veloso. All rights reserved. #ifndef _PAPFILE_ #define _PAPFILE_ #ifndef __EXCEPTIONS__ #include <Exceptions.h> #endif #ifndef __FOLDERS__ #include <Folders.h> #endif #ifndef __APPLETALK__ #include <Appletalk.h> #endif #ifndef __EVENTS__ #include <Events.h> #endif const short kPAPBlock = 512; const short kFlowQuantum = 8; const short kPAPBufferSize = kPAPBlock * kFlowQuantum; struct buffer { char *buf; short count; short size; }; struct statusRec { long stuff; Str255 status; }; extern "C" { pascal short PAPOpen(short *refNum, EntityName *PrinterName, const short FlowQuantum, statusRec *StatusBuff, short *CompState, const Ptr coderesource) = { 0x205F, 0x4E90 }; pascal short PAPRead(const short refNum, const char *ReadBuf, short *DataSize, short *eof, short *CompState, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0004 }; pascal short PAPWrite(const short refNum, const char *WriteBuf, const short DataSize, const short eof, short *CompState, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0008 }; pascal short PAPStatus(const EntityName *PrinterName, statusRec *StatusBuff, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x000c }; pascal short PAPClose(const short refNum, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0010 }; pascal short PAPUnload(Ptr coderesource) = { 0x205F, 0x4ea8, 0x0014 }; } // CPapCode //-------------------------------------------------------------------------- class CPapCode { public: CPapCode(); ~CPapCode(); OSErr IPapCode(); protected: const Ptr GetPapPtr() const; private: Ptr fPapPtr; // pointer to pdef 10 Handle fPapHandle; // handle to pdef 10 OSErr FindLaserwriter(FSSpec &theFile); OSErr MyFindFolder(short &vRefNum, long &parID, OSType type); OSErr GetPDEF(); }; // CPapFile //-------------------------------------------------------------------------- class CPapFile : public CPapCode { public: CPapFile(); ~CPapFile(); OSErr IPapFile(short readBufSize = kPAPBufferSize, short writeBufSize = kPAPBufferSize); OSErr Open(EntityName &thePrinter); // open a pap file. // EntityName must be packed with NBPSetEntity OSErr Read(); // read from a pap file OSErr Write(); // write to a pap file OSErr Close(); // close a pap file char *GetReadBufferAddress(); // use as argument char *GetWriteBufferAddress(); // use as argument short GetReadCount() const; short GetWriteCount() const; short GetReadSize() const; short GetWriteSize() const; short GetOpenStatus() const; short GetReadStatus() const; short GetWriteStatus() const; OSErr GetLastErr() const; OSErr GetLastReadErr() const; OSErr GetLastWriteErr() const; OSErr GetReadEOF() const; OSErr GetWriteEOF() const; StringPtr GetPrinterName(); StringPtr GetPrinterType(); StringPtr GetPrinterZone(); const StringPtr GetPrinterStatus(); void SetReadCount(short howMany); void SetWriteCount(short howMany); protected: const short GetRefNum() const; private: short fRefNum; // connection id short fOpenStatus; // state of open request short fReadStatus; // pending read status short fWriteStatus; // pending write status short fReadEOF; // is eof? short fWriteEOF; // is eof? OSErr fCurrentError; // the last error code OSErr fLastReadError; // the last read error OSErr fLastWriteError; // the last write error buffer fReadBuffer, fWriteBuffer; // buffers for reading & writing statusRec fStatus; // current status EntityName fThePrinter; // the printer we’re talking to, unpacked AddrBlock fTheAddress; // where the printer actually is OSErr Status(); // gets the printer status }; inline char *CPapFile::GetReadBufferAddress() { return fReadBuffer.buf; } inline char *CPapFile::GetWriteBufferAddress() { return fWriteBuffer.buf; } inline short CPapFile::GetReadCount() const { return fReadBuffer.count; } inline short CPapFile::GetWriteCount() const { return fWriteBuffer.count; } inline short CPapFile::GetReadSize() const { return fReadBuffer.size; } inline short CPapFile::GetWriteSize() const { return fWriteBuffer.size; } inline short CPapFile::GetOpenStatus() const { return fOpenStatus; } inline short CPapFile::GetReadStatus() const { return fReadStatus; } inline short CPapFile::GetWriteStatus() const { return fWriteStatus; } inline OSErr CPapFile::GetLastErr() const { return fCurrentError; } inline OSErr CPapFile::GetLastReadErr() const { return fLastReadError; } inline OSErr CPapFile::GetLastWriteErr() const { return fLastWriteError; } inline short CPapFile::GetReadEOF() const { return fReadEOF; } inline short CPapFile::GetWriteEOF() const { return fWriteEOF; } inline StringPtr CPapFile::GetPrinterName() { return fThePrinter.objStr; } inline StringPtr CPapFile::GetPrinterType() { return fThePrinter.typeStr; } inline StringPtr CPapFile::GetPrinterZone() { return fThePrinter.zoneStr; } inline const StringPtr CPapFile::GetPrinterStatus() { fCurrentError = Status(); return fStatus.status; } inline void CPapFile::SetReadCount(short howMany) { fReadBuffer.count = howMany; } inline void CPapFile::SetWriteCount(short howMany) { fWriteBuffer.count = howMany; } inline const Ptr CPapCode::GetPapPtr() const { return fPapPtr; } inline const short CPapFile::GetRefNum() const { return fRefNum; } #endif