home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 592b.lha / XprZmodem_v2.50 / XprZmodem.h < prev    next >
C/C++ Source or Header  |  1991-11-22  |  9KB  |  199 lines

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