home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 300.lha / xprzmodem.library_v2.0 / xprzmodem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1980-12-01  |  8.0 KB  |  172 lines

  1. /*  xprzmodem.h: Definitions for xprzmodem.library;
  2.     Version 2.0, 28 October 1989, by Rick Huebner.
  3.     Released to the Public Domain; do as you like with this code.  */
  4.  
  5. /* #define DEBUGLOG 1 */
  6.  
  7. /* Return codes */
  8. #define OK        0
  9. #define ERROR   (-1)
  10. #define TIMEOUT (-2)
  11. #define RCDO    (-3)
  12.  
  13. /* Relevant control characters */
  14. #define CR     ('M'&0x1F)        /* ^M */
  15. #define DLE    ('P'&0x1F)        /* ^P */
  16. #define XON    ('Q'&0x1F)        /* ^Q */
  17. #define XOFF   ('S'&0x1F)        /* ^S */
  18. #define CAN    ('X'&0x1F)        /* ^X */
  19. #define CPMEOF ('Z'&0x1F)        /* ^Z */
  20.  
  21. /* Misc. program constants */
  22. #define LZMANAG          0       /* Default ZMODEM file management mode */
  23. #define LZTRANS          0       /* Default ZMODEM file transport mode */
  24. #define PATHLEN        256       /* What's the max legal path size? */
  25. #define CONFIGLEN       32       /* Max length of transfer options string */
  26. #define KSIZE         1024       /* Max allowable packet size */
  27. #define MINBLOCK        64       /* Min allowable packet size */
  28. #define MAXGOODNEEDED 8192       /* Max # good bytes required to bump packet size */
  29.  
  30. /* Provision for future 7-bit ZMODEM; for now, there's no difference */
  31. #define sendline xsendline
  32.  
  33.  
  34. /* Replacement for global variables normally used, in order to make code
  35.    fully reentrant; each invocation allocs their own Vars, and passes the
  36.    struct pointer down through the entire program so they're always available.
  37.    Pointer to this struct is usually able to be a register variable, so access
  38.    is no worse than any stack variable (all register-relative).  Kinda
  39.    kludgey, but the original ZModem code design depended on lots of globals,
  40.    and I didn't want to redesign the whole damn thing.  Besides, it's more
  41.    efficient than constantly pushing & popping args all over the place. */
  42.  
  43. struct Vars {
  44.   struct XPR_IO io;              /* Copy of XProtocol IO struct passed in by term prog. */
  45.   struct XPR_UPDATE xpru;        /* Scratchpad xpr_update() control struct */
  46.   UBYTE Zconv;                   /* ZMODEM file conversion request */
  47.   UBYTE Zmanag;                  /* ZMODEM file management request */
  48.   UBYTE Ztrans;                  /* ZMODEM file transport request */
  49.   UBYTE Lastsent;                /* Last text char written by putsec() */
  50.   UBYTE Lastzsent;               /* Last char sent by zsendline() */
  51.   UBYTE Fileflush;               /* Flush file I/O buffer before closing? */
  52.   UBYTE Msgbuf[128];             /* Scratchpad buffer for printing messages */
  53.   UBYTE Filename[PATHLEN];       /* Name of the file being up/downloaded */
  54.   UBYTE Zsdatabuf[KSIZE*2+2];    /* Modem output buffer for file data xmit */
  55.   UBYTE Modembuf[256];           /* Input buffer for data from modem */
  56.   UBYTE *Modemchar;              /* Next char to get from Modembuf */
  57.   UBYTE *Filebuf;                /* File I/O buffer address */
  58.   UBYTE *Filebufptr;             /* Current position within Filebuf */
  59.   char Rxbinary;                 /* Force binary mode download? */
  60.   char Rxascii;                  /* Force text mode download? */
  61.   char Thisbinary;               /* Receive this file in binary mode? */
  62.   char Lzconv;                   /* Suggested binary/text mode for uploads */
  63.   char Eofseen;                  /* Text-mode EOF marker (^Z) received on download? */
  64.   short Filcnt;                  /* Number of files opened for transmission */
  65.   short Errcnt;                  /* Number of files unreadable */
  66.   short Noroom;                  /* Flags 'insufficient disk space' errors */
  67.   short Rxbuflen;                /* Largest frame they're willing to xfer */
  68.   short Tframlen;                /* Largest frame we're willing to xfer */
  69.   short Rxtimeout;               /* Tenths of seconds to wait for something */
  70.   short Tryzhdrtype;             /* Header type to send corresponding to Last rx close */
  71.   short Modemcount;              /* Number of bytes available in Modembuf */
  72.   long Oldstatus;                /* Original terminal program's modem settings */
  73.   long Baud;                     /* BPS setting of modem */
  74.   long Strtpos;                  /* Starting byte position of transfer */
  75.   long Starttime;                /* Time transfer started */
  76.   long Fsize;                    /* Size of file being transferred */
  77.   long Rxbytes;                  /* Number of bytes received so far */
  78.   long Filebufpos;               /* File offset of data in Filebuf */
  79.   long Filebufmax;               /* Size of Filebuf */
  80.   long Filebuflen;               /* Number of bytes currently stored in Filebuf */
  81.   long Filebufcnt;               /* Number of bytes remaining/written in Filebuf */
  82.   void *File;                    /* Handle of file being transferred */
  83.   UBYTE Pktbuf[KSIZE];           /* File data packet buffer */
  84.   UBYTE Rxhdr[4];                /* Received header */
  85.   UBYTE Txhdr[4];                /* Transmitted header */
  86.   UBYTE Attn[ZATTNLEN+1];        /* Attention string rx sends to tx on err */
  87.   short Rxframeind;              /* ZBIN or ZHEX; type of frame received */
  88.   short Rxtype;                  /* Type of header received */
  89.   short Rxcount;                 /* Count of data bytes received */
  90.   short Znulls;                  /* Number of nulls to send at beginning of ZDATA hdr */
  91.   long Rxpos;                    /* Received file position */
  92.   long Txpos;                    /* Transmitted file position */
  93. };
  94.  
  95. /* Option settings and other variables needed outside of XProtocolSend/Receive;
  96.    separated from rest of Vars so that huge Vars struct doesn't have to be
  97.    allocated except during transfers.  Pointer to this struct kept in xpr_data. */
  98. struct SetupVars {
  99.   UBYTE *matchptr, *bufpos;
  100.   short buflen;
  101.   UBYTE option_t[2], option_o[2], option_b[8], option_f[8], option_s[4];
  102.   UBYTE option_r[4], option_a[4], option_d[4], option_k[4], option_p[256];
  103. };
  104.  
  105.  
  106. /* Function prototypes */
  107.  
  108. long  __saveds XProtocolSend(struct XPR_IO *io);
  109. short getzrxinit(struct Vars *v);
  110. void sendbatch(struct Vars *v);
  111. short sendone(struct Vars *v);
  112. short sendname(struct Vars *v);
  113. short zsendfile(struct Vars *v,short blen);
  114. short zsendfdata(struct Vars *v);
  115. short getinsync(struct Vars *v);
  116. void saybibi(struct Vars *v);
  117.  
  118. long __saveds XProtocolReceive(struct XPR_IO *io);
  119. short rcvbatch(struct Vars *v);
  120. short tryz(struct Vars *v);
  121. short rzfiles(struct Vars *v);
  122. short rzfile(struct Vars *v);
  123. short procheader(struct Vars *v);
  124. short putsec(struct Vars *v);
  125. void ackbibi(struct Vars *v);
  126.  
  127. long __saveds XProtocolSetup(struct XPR_IO *io);
  128. long __saveds XProtocolCleanup(struct XPR_IO *io);
  129. long __saveds XProtocolHostMon(struct XPR_IO *io,UBYTE *serbuff,long actual,long maxsize);
  130. long __saveds XProtocolUserMon(struct XPR_IO *io,UBYTE *serbuff,long actual,long maxsize);
  131. struct Vars *setup(struct XPR_IO *io);
  132. UBYTE *find_option(UBYTE *buf,UBYTE option);
  133. void set_textmode(struct Vars *v);
  134. void canit(struct Vars *v);
  135. void zmputs(struct Vars *v,UBYTE *s);
  136. void xsendline(struct Vars *v,UBYTE c);
  137. short readock(struct Vars *v,short tenths);
  138. char char_avail(struct Vars *v);
  139. void update_rate(struct Vars *v);
  140. void *bfopen(struct Vars *v,UBYTE *mode);
  141. void bfclose(struct Vars *v);
  142. void bfseek(struct Vars *v,long pos);
  143. long bfread(struct Vars *v,UBYTE *buf,long length);
  144. long bfwrite(struct Vars *v,UBYTE *buf,long length);
  145. void ioerr(struct XPR_IO *io,char *msg);
  146. void upderr(struct Vars *v,char *msg);
  147. void updmsg(struct Vars *v,char *msg);
  148. long getfree(void);
  149. char exist(struct Vars *v);
  150. #ifdef DEBUG
  151. void dlog(struct Vars *v,UBYTE *s);
  152. #endif
  153.  
  154. void zsbhdr(struct Vars *v,USHORT type);
  155. void zshhdr(struct Vars *v,USHORT type);
  156. void zsdata(struct Vars *v,short length,USHORT frameend);
  157. short zrdata(struct Vars *v,UBYTE *buf,short length);
  158. short zgethdr(struct Vars *v);
  159. short zrbhdr(struct Vars *v);
  160. short zrhhdr(struct Vars *v);
  161. void zputhex(struct Vars *v,UBYTE c);
  162. void zsendline(struct Vars *v,UBYTE c);
  163. short zgethex(struct Vars *v);
  164. short zdlread(struct Vars *v);
  165. short noxrd7(struct Vars *v);
  166. void stohdr(struct Vars *v,long pos);
  167. long rclhdr(struct Vars *v);
  168.  
  169. extern ULONG UnixTimeOffset;
  170. ULONG GetSysTime(struct timeval *tv);
  171. void TimeOut(long ticks);
  172.