home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / PAPTool / PAPFile.h < prev    next >
Encoding:
Text File  |  1992-11-29  |  5.3 KB  |  241 lines  |  [TEXT/MPS ]

  1. //    ©1992 Conrad Carlen & Manuel Veloso. All rights reserved.
  2. #ifndef _PAPFILE_
  3. #define _PAPFILE_
  4.  
  5. #ifndef __EXCEPTIONS__
  6. #include <Exceptions.h>
  7. #endif
  8.  
  9. #ifndef __FOLDERS__
  10. #include <Folders.h>
  11. #endif
  12.  
  13. #ifndef __APPLETALK__
  14. #include <Appletalk.h>
  15. #endif
  16.  
  17. #ifndef __EVENTS__
  18. #include <Events.h>
  19. #endif
  20.  
  21. const short kPAPBlock = 512;
  22. const short kFlowQuantum = 8;
  23. const short kPAPBufferSize = kPAPBlock * kFlowQuantum;
  24.  
  25. struct buffer
  26. {
  27.     char    *buf;
  28.     short    count;
  29.     short    size;
  30. };
  31.  
  32. struct statusRec
  33. {
  34.     long    stuff;
  35.     Str255    status;
  36. };
  37.  
  38. extern "C"
  39. {
  40.     pascal short PAPOpen(short *refNum, EntityName *PrinterName, const short FlowQuantum, statusRec *StatusBuff, short *CompState, const Ptr coderesource) = { 0x205F, 0x4E90 };
  41.     pascal short PAPRead(const short refNum, const char *ReadBuf, short *DataSize, short *eof, short *CompState, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0004 };
  42.     pascal short PAPWrite(const short refNum, const char *WriteBuf, const short DataSize, const short eof, short *CompState, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0008 };
  43.     pascal short PAPStatus(const EntityName *PrinterName, statusRec *StatusBuff, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x000c };
  44.     pascal short PAPClose(const short refNum, const Ptr coderesource) = { 0x205F, 0x4ea8, 0x0010 };
  45.     pascal short PAPUnload(Ptr coderesource) = { 0x205F, 0x4ea8, 0x0014 };
  46. }
  47.  
  48. //    CPapCode
  49. //--------------------------------------------------------------------------
  50.  
  51. class CPapCode
  52. {
  53. public:
  54.     CPapCode();
  55.     ~CPapCode();
  56.     OSErr IPapCode();
  57. protected:
  58.     const    Ptr GetPapPtr() const;
  59.  
  60. private:
  61.     Ptr            fPapPtr;                    // pointer to pdef 10
  62.     Handle        fPapHandle;                    // handle to pdef 10
  63.  
  64.     OSErr FindLaserwriter(FSSpec &theFile);
  65.     OSErr MyFindFolder(short &vRefNum, long &parID, OSType type);
  66.     OSErr GetPDEF();
  67.  
  68. };
  69.  
  70. //    CPapFile
  71. //--------------------------------------------------------------------------
  72.  
  73. class CPapFile : public CPapCode
  74. {
  75. public:
  76.     CPapFile();
  77.     ~CPapFile();
  78.     OSErr    IPapFile(short readBufSize = kPAPBufferSize, short writeBufSize = kPAPBufferSize);
  79.     OSErr     Open(EntityName &thePrinter);    // open a pap file.
  80.                                             // EntityName must be packed with NBPSetEntity
  81.     OSErr    Read();                            // read from a pap file
  82.     OSErr     Write();                        // write to a pap file
  83.     OSErr     Close();                        // close a pap file
  84.  
  85.     char    *GetReadBufferAddress();                // use as argument
  86.     char    *GetWriteBufferAddress();            // use as argument
  87.  
  88.     short    GetReadCount() const;
  89.     short    GetWriteCount() const;
  90.     short    GetReadSize() const;
  91.     short    GetWriteSize() const;
  92.     short    GetOpenStatus() const;
  93.     short    GetReadStatus() const;
  94.     short    GetWriteStatus() const;
  95.     OSErr    GetLastErr() const;
  96.     OSErr    GetLastReadErr() const;
  97.     OSErr    GetLastWriteErr() const;
  98.     OSErr    GetReadEOF() const;
  99.     OSErr    GetWriteEOF() const;
  100.     
  101.     StringPtr GetPrinterName();
  102.     StringPtr GetPrinterType();
  103.     StringPtr GetPrinterZone();
  104.     const    StringPtr GetPrinterStatus();
  105.  
  106.     void    SetReadCount(short howMany);
  107.     void    SetWriteCount(short howMany);
  108.  
  109. protected:
  110.     const    short GetRefNum() const;
  111.     
  112. private:
  113.     short        fRefNum;                    // connection id
  114.     short        fOpenStatus;                    // state of open request
  115.     short        fReadStatus;                // pending read status
  116.     short        fWriteStatus;                // pending write status
  117.     short        fReadEOF;                    // is eof?
  118.     short        fWriteEOF;                    // is eof?
  119.     OSErr        fCurrentError;                // the last error code
  120.     OSErr        fLastReadError;                // the last read error
  121.     OSErr        fLastWriteError;            // the last write error
  122.     buffer        fReadBuffer, fWriteBuffer;    // buffers for reading & writing
  123.     statusRec    fStatus;                    // current status
  124.     EntityName    fThePrinter;                // the printer we’re talking to, unpacked
  125.     AddrBlock    fTheAddress;                // where the printer actually is
  126.  
  127.     OSErr Status();                            // gets the printer status
  128. };
  129.  
  130. inline char *CPapFile::GetReadBufferAddress()
  131. {
  132.     return fReadBuffer.buf;
  133. }
  134.  
  135. inline char *CPapFile::GetWriteBufferAddress()
  136. {
  137.     return fWriteBuffer.buf;
  138. }
  139.  
  140. inline short CPapFile::GetReadCount() const
  141. {
  142.     return fReadBuffer.count;
  143. }
  144.  
  145. inline short CPapFile::GetWriteCount() const
  146. {
  147.     return fWriteBuffer.count;
  148. }
  149.  
  150. inline short CPapFile::GetReadSize() const
  151. {
  152.     return fReadBuffer.size;
  153. }
  154.  
  155. inline short CPapFile::GetWriteSize() const
  156. {
  157.     return fWriteBuffer.size;
  158. }
  159.  
  160. inline short CPapFile::GetOpenStatus() const
  161. {
  162.     return fOpenStatus;
  163. }
  164.  
  165. inline short CPapFile::GetReadStatus() const
  166. {
  167.     return fReadStatus;
  168. }
  169.  
  170. inline short CPapFile::GetWriteStatus() const
  171. {
  172.     return fWriteStatus;
  173. }
  174.  
  175. inline OSErr CPapFile::GetLastErr() const
  176. {
  177.     return fCurrentError;
  178. }
  179.  
  180. inline OSErr CPapFile::GetLastReadErr() const
  181. {
  182.     return fLastReadError;
  183. }
  184.  
  185. inline OSErr CPapFile::GetLastWriteErr() const
  186. {
  187.     return fLastWriteError;
  188. }
  189.  
  190. inline short CPapFile::GetReadEOF() const
  191. {
  192.     return fReadEOF;
  193. }
  194.  
  195. inline short CPapFile::GetWriteEOF() const
  196. {
  197.     return fWriteEOF;
  198. }
  199.  
  200. inline StringPtr CPapFile::GetPrinterName()
  201. {
  202.     return fThePrinter.objStr;
  203. }
  204.  
  205. inline StringPtr CPapFile::GetPrinterType()
  206. {
  207.     return fThePrinter.typeStr;
  208. }
  209.  
  210. inline StringPtr CPapFile::GetPrinterZone()
  211. {
  212.     return fThePrinter.zoneStr;
  213. }
  214.  
  215. inline const StringPtr CPapFile::GetPrinterStatus()
  216. {
  217.     fCurrentError = Status();
  218.     return fStatus.status;
  219. }
  220.  
  221. inline void CPapFile::SetReadCount(short howMany)
  222. {
  223.     fReadBuffer.count = howMany;
  224. }
  225.  
  226. inline void CPapFile::SetWriteCount(short howMany)
  227. {
  228.     fWriteBuffer.count = howMany;
  229. }
  230.  
  231. inline const Ptr CPapCode::GetPapPtr() const
  232. {
  233.     return fPapPtr;
  234. }
  235.  
  236. inline const short CPapFile::GetRefNum() const
  237. {
  238.     return fRefNum;
  239. }
  240. #endif
  241.