home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / ZMISC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  22KB  |  742 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 Zmodem routines used by Zsend and Zreceive               */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  43. /*  The original work is (C) Copyright 1986, Wynn Wagner III. The original  */
  44. /*  authors have graciously allowed us to use their code in this work.      */
  45. /*                                                                          */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. /* Include this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. static int Rxtype;                               /* Type of header received                 */
  53.  
  54. static char hex[] = "0123456789abcdef";
  55.  
  56. /* Send a byte as two hex digits */
  57. #define Z_PUTHEX(i,c) {i=(c);SENDBYTE(hex[((i)&0xF0)>>4]);SENDBYTE(hex[(i)&0xF]);}
  58.  
  59. /*--------------------------------------------------------------------------*/
  60. /* Private routines                                                         */
  61. /*--------------------------------------------------------------------------*/
  62. int _Z_GetBinaryHeader (unsigned char *);
  63. int _Z_32GetBinaryHeader (unsigned char *);
  64. int _Z_GetHexHeader (unsigned char *);
  65. int _Z_GetHex (void);
  66. int _Z_TimedRead (void);
  67. long _Z_PullLongFromHeader (unsigned char *);
  68.  
  69. #ifdef MILQ
  70. /*
  71.  * Dst   - Where to put this.  Should use a static buffer, if
  72.  *         a destination is not provided
  73.  *
  74.  * Src   - The filename to be conditioned
  75.  *
  76.  * TblNm - Name of the file to use for the source of path
  77.  *         conditioning entries
  78.  *
  79.  * Mode  -
  80.  */
  81.  
  82. char *ZMdmFlNmCndtn( char *Dst,
  83.                      char *Src,
  84.                      char *Tbl,
  85.                      int   Mode ) {
  86.   char                 *p;
  87.   char                 *q;
  88.  
  89.   for ( p = Src, q = Dst; *p; ) {
  90.     switch ( *p ) {
  91.       case '/':
  92.       case '\\':
  93.         switch ( UsePaths ) {
  94.           case FALSE:
  95.             q = Dst;
  96.             break;
  97.           default:
  98.             *q++ = '/';
  99.             break;
  100.           }                            /* end of switch ( UsePaths ) */
  101.         break;
  102.       case ':':
  103.         q = Dst;
  104.         break;
  105.       default:
  106.         *q++ = (char) tolower (*p);
  107.         break;
  108.       }                                /* end of for ( p = Src ... ) */
  109.     p++;
  110.     }
  111.   *q++ = '\0';
  112.   return Dst;
  113.   }
  114. #endif
  115.  
  116. void z_message (char *s)
  117. {
  118.    if (fullscreen && un_attended)
  119.       {
  120.       if (s)
  121.          {
  122.          sb_move (file_hWnd, 2, 27);
  123.          FlLnModeSet( FILE_LN_2, 0 );
  124.          sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 + GD_STATUS ), s );
  125.          }
  126. #ifndef MILQ
  127.       sb_puts (file_hWnd, "              ");
  128. #endif
  129.       sb_show ();
  130.       }
  131.    else
  132.       {
  133.       gotoxy (locate_x + 20, locate_y);
  134.       if (s)
  135.          {
  136.          (void) cputs (s);
  137.          }
  138.       (void) cputs ("               ");
  139.       }
  140. }
  141.  
  142. void z_log (char *s)
  143. {
  144.    word x, y;
  145.  
  146.    z_message (s);
  147.  
  148.    x = locate_x;
  149.    y = locate_y;
  150.    status_line (s);                              /* also does disk file
  151.                                                   * logging */
  152.    locate_x = x;
  153.    locate_y = y;
  154. }
  155.  
  156. void show_loc (unsigned long l, unsigned int w)
  157. {
  158.    char j[100];
  159.  
  160.    if (fullscreen && un_attended)
  161.       {
  162.  
  163.       (void) sprintf (j, "Ofs=%ld Retries=%d        ", l, w);
  164.       sb_move (file_hWnd, 2, 37);
  165.       sb_puts( GetDlgItem( file_hWnd, FILE_LN_2 + GD_SIZE ), j );
  166.       sb_show ();
  167.       }
  168.    else
  169.       {
  170.       gotoxy (locate_x + 35, locate_y);
  171.       (void) printf ("Ofs=%ld Retries=%d        ", l, w);
  172.       }
  173. }
  174.  
  175. /*--------------------------------------------------------------------------*/
  176. /* Z GET BYTE                                                               */
  177. /* Get a byte from the modem;                                               */
  178. /* return TIMEOUT if no read within timeout tenths,                         */
  179. /* return RCDO if carrier lost                                              */
  180. /*--------------------------------------------------------------------------*/
  181. int Z_GetByte (int tenths)
  182. {
  183.    long timeout;
  184.  
  185.    if (PEEKBYTE () >= 0)
  186.       return (MODEM_IN ());
  187.  
  188.    timeout = timerset (tenths * 10);
  189.  
  190.    do
  191.       {
  192.       if (PEEKBYTE () >= 0)
  193.          return MODEM_IN ();
  194.  
  195.       if (!CARRIER)
  196.          return RCDO;
  197.  
  198.       if (got_ESC ())
  199.          return -1;
  200.  
  201.       time_release ();
  202.       }
  203.    while (!timeup (timeout));
  204.  
  205.    return TIMEOUT;
  206. }
  207.  
  208. /*--------------------------------------------------------------------------*/
  209. /* Z PUT STRING                                                             */
  210. /* Send a string to the modem, processing for \336 (sleep 1 sec)            */
  211. /* and \335 (break signal, ignored)                                         */
  212. /*--------------------------------------------------------------------------*/
  213. void Z_PutString (register unsigned char *s)
  214. {
  215.    register unsigned c;
  216.  
  217.    while (*s)
  218.       {
  219.       switch (c = *s++)
  220.          {
  221.          case (unsigned int) '\336':
  222.             big_pause (2);
  223.          case (unsigned int) '\335':
  224. /* Should send a break on this */
  225.             break;
  226.          default:
  227.             SENDBYTE ((unsigned char) c);
  228.          }                                       /* switch */
  229.  
  230.       }                                          /* while */
  231.  
  232.    Z_UncorkTransmitter ();                       /* Make sure all is well */
  233. }                                                /* Z_PutString */
  234.  
  235. /*--------------------------------------------------------------------------*/
  236. /* Z SEND HEX HEADER                                                        */
  237. /* Send ZMODEM HEX header hdr of type type                                  */
  238. /*--------------------------------------------------------------------------*/
  239. void Z_SendHexHeader (unsigned int type, register unsigned char *hdr)
  240. {
  241.    register int n;
  242.    register int i;
  243.    register word crc;
  244.  
  245.    Z_UncorkTransmitter ();                       /* Get our transmitter going */
  246.  
  247. #ifdef DEBUG
  248.    show_debug_name ("Z_SendHexHeader");
  249. #endif
  250.  
  251.    SENDBYTE (ZPAD);
  252.    SENDBYTE (ZPAD);
  253.    SENDBYTE (ZDLE);
  254.    SENDBYTE (ZHEX);
  255.  
  256.    Z_PUTHEX (i, type);
  257.  
  258.    Crc32t = 0;
  259.    crc = Z_UpdateCRC (type, 0);
  260.  
  261.    for (n = 4; --n >= 0;)
  262.       {
  263.       Z_PUTHEX (i, (*hdr));
  264.       crc = Z_UpdateCRC (((unsigned short) (*hdr++)), crc);
  265.       }
  266.    Z_PUTHEX (i, (crc >> 8));
  267.    Z_PUTHEX (i, crc);
  268.  
  269.    /* Make it printable on remote machine */
  270.    SENDBYTE ('\r');
  271.    SENDBYTE ('\n');
  272.  
  273.    /* Uncork the remote in case a fake XOFF has stopped data flow */
  274.    if (type != ZFIN && type != ZACK)
  275.       SENDBYTE (021);
  276.  
  277.    if (!CARRIER)
  278.       CLEAR_OUTBOUND ();
  279.  
  280. }                                                /* Z_SendHexHeader */
  281.  
  282. /*--------------------------------------------------------------------------*/
  283. /* Z UNCORK TRANSMITTER                                                     */
  284. /* Wait a reasonable amount of time for transmitter buffer to clear.        */
  285. /*   When it does, or when time runs out, turn XON/XOFF off then on.        */
  286. /*   This should release a transmitter stuck by line errors.                */
  287. /*--------------------------------------------------------------------------*/
  288.  
  289. void Z_UncorkTransmitter ()
  290. {
  291.    long t;
  292.  
  293. #ifdef DEBUG
  294.    show_debug_name ("Z_UncorkTransmitter");
  295. #endif
  296.  
  297.    if (!OUT_EMPTY () && CARRIER)
  298.       {
  299.       t = timerset (5 * Rxtimeout);              /* Wait for silence */
  300.       while (!timeup (t) && !OUT_EMPTY () && CARRIER)
  301.          time_release ();                        /* Give up slice while
  302.                                                   * waiting  */
  303.       }
  304.  
  305.    com_kick ();
  306.  
  307. }
  308.  
  309.  
  310. /*--------------------------------------------------------------------------*/
  311. /* Z GET HEADER                                                             */
  312. /* Read a ZMODEM header to hdr, either binary or hex.                       */
  313. /*   On success, set Zmodem to 1 and return type of header.                 */
  314. /*   Otherwise return negative on error                                     */
  315. /*--------------------------------------------------------------------------*/
  316. int Z_GetHeader (byte *hdr)
  317. {
  318.  
  319.    register int c;
  320.    register int n;
  321.    int cancount;
  322.  
  323. #ifdef DEBUG
  324.    show_debug_name ("Z_GetHeader");
  325. #endif
  326.  
  327.    n = cur_baud.rate_value;                      /* Max characters before
  328.                                                   * start of frame */
  329.    cancount = 5;
  330.  
  331. Again:
  332.  
  333.    if (got_ESC ())
  334.       {
  335.       send_can ();
  336.       z_log (MSG_TXT(M_KBD_MSG));
  337.       return ZCAN;
  338.       }
  339.  
  340.    Rxframeind = Rxtype = 0;
  341.  
  342.    switch (c = _Z_TimedRead ())
  343.       {
  344.       case ZPAD:
  345.       case ZPAD | 0200:
  346.          /*-----------------------------------------------*/
  347.          /* This is what we want.                         */
  348.          /*-----------------------------------------------*/
  349.          break;
  350.  
  351.       case RCDO:
  352.       case TIMEOUT:
  353.          goto Done;
  354.  
  355.       case CAN:
  356.  
  357.    GotCan:
  358.  
  359.          if (--cancount <= 0)
  360.             {
  361.             c = ZCAN;
  362.             goto Done;
  363.             }
  364.          switch (c = Z_GetByte (1))
  365.             {
  366.             case TIMEOUT:
  367.                goto Again;
  368.  
  369.             case ZCRCW:
  370.                c = ERROR;
  371.                /* fallthrough... */
  372.  
  373.             case RCDO:
  374.                goto Done;
  375.  
  376.             case CAN:
  377.                if (--cancount <= 0)
  378.                   {
  379.                   c = ZCAN;
  380.                   goto Done;
  381.                   }
  382.                goto Again;
  383.             }
  384.          /* fallthrough... */
  385.  
  386.       default:
  387.  
  388.    Agn2:
  389.  
  390.          if (--n <= 0)
  391.             {
  392.             z_log (MSG_TXT(M_FUBAR_MSG));
  393.             return ERROR;
  394.             }
  395.  
  396.          if (c != CAN)
  397.             cancount = 5;
  398.          goto Again;
  399.  
  400.       }                                          /* switch */
  401.  
  402.    cancount = 5;
  403.  
  404. Splat:
  405.  
  406.    switch (c = _Z_TimedRead ())
  407.       {
  408.       case ZDLE:
  409.          /*-----------------------------------------------*/
  410.          /* This is what we want.                         */
  411.          /*-----------------------------------------------*/
  412.          break;
  413.  
  414.       case ZPAD:
  415.          goto Splat;
  416.  
  417.       case RCDO:
  418.       case TIMEOUT:
  419.          goto Done;
  420.  
  421.       default:
  422.          goto Agn2;
  423.  
  424.       }                                          /* switch */
  425.  
  426.  
  427.    switch (c = _Z_TimedRead ())
  428.       {
  429.  
  430.       case ZBIN:
  431.          Rxframeind = ZBIN;
  432.          Crc32 = 0;
  433.          c = _Z_GetBinaryHeader (hdr);
  434.          break;
  435.  
  436.       case ZBIN32:
  437.          Crc32 = Rxframeind = ZBIN32;
  438.          c = _Z_32GetBinaryHeader (hdr);
  439.          break;
  440.  
  441.       case ZHEX:
  442.          Rxframeind = ZHEX;
  443.          Crc32 = 0;
  444.          c = _Z_GetHexHeader (hdr);
  445.          break;
  446.  
  447.       case CAN:
  448.          goto GotCan;
  449.  
  450.       case RCDO:
  451.       case TIMEOUT:
  452.          goto Done;
  453.  
  454.       default:
  455.          goto Agn2;
  456.  
  457.       }                                          /* switch */
  458.  
  459.    Rxpos = _Z_PullLongFromHeader (hdr);
  460.  
  461. Done:
  462.  
  463.    return c;
  464. }                                                /* Z_GetHeader */
  465.  
  466. /*--------------------------------------------------------------------------*/
  467. /* Z GET BINARY HEADER                                                      */
  468. /* Receive a binary style header (type and position)                        */
  469. /*--------------------------------------------------------------------------*/
  470. int _Z_GetBinaryHeader (register unsigned char *hdr)
  471. {
  472.    register int c;
  473.    register unsigned int crc;
  474.    register int n;
  475.  
  476. #ifdef DEBUG
  477.    show_debug_name ("Z_GetBinaryHeader");
  478. #endif
  479.  
  480.    if ((c = Z_GetZDL ()) & ~0xFF)
  481.       return c;
  482.    Rxtype = c;
  483.    crc = Z_UpdateCRC (c, 0);
  484.  
  485.    for (n = 4; --n >= 0;)
  486.       {
  487.       if ((c = Z_GetZDL ()) & ~0xFF)
  488.          return c;
  489.       crc = Z_UpdateCRC (c, crc);
  490.       *hdr++ = (unsigned char) (c & 0xff);
  491.       }
  492.    if ((c = Z_GetZDL ()) & ~0xFF)
  493.       return c;
  494.  
  495.    crc = Z_UpdateCRC (c, crc);
  496.    if ((c = Z_GetZDL ()) & ~0xFF)
  497.       return c;
  498.  
  499.    crc = Z_UpdateCRC (c, crc);
  500.    if (crc & 0xFFFF)
  501.       {
  502.       z_message (MSG_TXT(M_CRC_MSG));
  503.       return ERROR;
  504.       }
  505.  
  506.    return Rxtype;
  507. }                                                /* _Z_GetBinaryHeader */
  508.  
  509.  
  510. /*--------------------------------------------------------------------------*/
  511. /* Z GET BINARY HEADER with 32 bit CRC                                      */
  512. /* Receive a binary style header (type and position)                        */
  513. /*--------------------------------------------------------------------------*/
  514. int _Z_32GetBinaryHeader (register unsigned char *hdr)
  515. {
  516.    register int c;
  517.    register unsigned long crc;
  518.    register int n;
  519.  
  520. #ifdef DEBUG
  521.    show_debug_name ("Z_32GetBinaryHeader");
  522. #endif
  523.  
  524.    if ((c = Z_GetZDL ()) & ~0xFF)
  525.       return c;
  526.    Rxtype = c;
  527.    crc = 0xFFFFFFFF;
  528.    crc = Z_32UpdateCRC (c, crc);
  529.  
  530.    for (n = 4; --n >= 0;)
  531.       {
  532.       if ((c = Z_GetZDL ()) & ~0xFF)
  533.          return c;
  534.       crc = Z_32UpdateCRC (c, crc);
  535.       *hdr++ = (unsigned char) (c & 0xff);
  536.       }
  537.  
  538.    for (n = 4; --n >= 0;)
  539.       {
  540.       if ((c = Z_GetZDL ()) & ~0xFF)
  541.          return c;
  542.  
  543.       crc = Z_32UpdateCRC (c, crc);
  544.       }
  545.  
  546.    if (crc != 0xDEBB20E3)
  547.       {
  548.       z_message (MSG_TXT(M_CRC_MSG));
  549.       return ERROR;
  550.       }
  551.  
  552.    return Rxtype;
  553. }                                                /* _Z_32GetBinaryHeader */
  554.  
  555. /*--------------------------------------------------------------------------*/
  556. /* Z GET HEX HEADER                                                         */
  557. /* Receive a hex style header (type and position)                           */
  558. /*--------------------------------------------------------------------------*/
  559. int _Z_GetHexHeader (register unsigned char *hdr)
  560. {
  561.    register int c;
  562.    register unsigned int crc;
  563.    register int n;
  564.  
  565. #ifdef DEBUG
  566.    show_debug_name ("Z_GetHexHeader");
  567. #endif
  568.  
  569.    if ((c = _Z_GetHex ()) < 0)
  570.       return c;
  571.    Rxtype = c;
  572.    crc = Z_UpdateCRC (c, 0);
  573.  
  574.    for (n = 4; --n >= 0;)
  575.       {
  576.       if ((c = _Z_GetHex ()) < 0)
  577.          return c;
  578.       crc = Z_UpdateCRC (c, crc);
  579.       *hdr++ = (unsigned char) c;
  580.       }
  581.  
  582.    if ((c = _Z_GetHex ()) < 0)
  583.       return c;
  584.    crc = Z_UpdateCRC (c, crc);
  585.    if ((c = _Z_GetHex ()) < 0)
  586.       return c;
  587.    crc = Z_UpdateCRC (c, crc);
  588.    if (crc & 0xFFFF)
  589.       {
  590.       z_message (MSG_TXT(M_CRC_MSG));
  591.       return ERROR;
  592.       }
  593.    if (Z_GetByte (1) == '\r')
  594.       (void) Z_GetByte (1);                    /* Throw away possible cr/lf */
  595.  
  596.    return Rxtype;
  597. }
  598.  
  599. /*--------------------------------------------------------------------------*/
  600. /* Z GET HEX                                                                */
  601. /* Decode two lower case hex digits into an 8 bit byte value                */
  602. /*--------------------------------------------------------------------------*/
  603. int _Z_GetHex ()
  604. {
  605.    register int c, n;
  606.  
  607. #ifdef DEBUG
  608.    show_debug_name ("Z_GetHex");
  609. #endif
  610.  
  611.    if ((n = _Z_TimedRead ()) < 0)
  612.       return n;
  613.    n -= '0';
  614.    if (n > 9)
  615.       n -= ('a' - ':');
  616.    if (n & ~0xF)
  617.       return ERROR;
  618.  
  619.    if ((c = _Z_TimedRead ()) < 0)
  620.       return c;
  621.    c -= '0';
  622.    if (c > 9)
  623.       c -= ('a' - ':');
  624.    if (c & ~0xF)
  625.       return ERROR;
  626.  
  627.    return ((n << 4) | c);
  628. }
  629.  
  630. /*--------------------------------------------------------------------------*/
  631. /* Z GET ZDL                                                                */
  632. /* Read a byte, checking for ZMODEM escape encoding                         */
  633. /* including CAN*5 which represents a quick abort                           */
  634. /*--------------------------------------------------------------------------*/
  635. int Z_GetZDL ()
  636. {
  637.    register int c;
  638.  
  639.    if ((c = Z_GetByte (Rxtimeout)) != ZDLE)
  640.       return c;
  641.  
  642.    switch (c = Z_GetByte (Rxtimeout))
  643.       {
  644.       case CAN:
  645.          return ((c = Z_GetByte (Rxtimeout)) < 0) ? c :
  646.             ((c == CAN) && ((c = Z_GetByte (Rxtimeout)) < 0)) ? c :
  647.             ((c == CAN) && ((c = Z_GetByte (Rxtimeout)) < 0)) ? c : (GOTCAN);
  648.  
  649.       case ZCRCE:
  650.       case ZCRCG:
  651.       case ZCRCQ:
  652.       case ZCRCW:
  653.          return (c | GOTOR);
  654.  
  655.       case ZRUB0:
  656.          return 0x7F;
  657.  
  658.       case ZRUB1:
  659.          return 0xFF;
  660.  
  661.       default:
  662.          return (c < 0) ? c :
  663.             ((c & 0x60) == 0x40) ? (c ^ 0x40) : ERROR;
  664.  
  665.       }                                          /* switch */
  666. }                                                /* Z_GetZDL */
  667.  
  668. /*--------------------------------------------------------------------------*/
  669. /* Z TIMED READ                                                             */
  670. /* Read a character from the modem line with timeout.                       */
  671. /*  Eat parity, XON and XOFF characters.                                    */
  672. /*--------------------------------------------------------------------------*/
  673. int _Z_TimedRead ()
  674. {
  675.    register int c;
  676.  
  677. #ifdef DEBUG
  678.    show_debug_name ("Z_TimedRead");
  679. #endif
  680.  
  681.    for (;;)
  682.       {
  683.       if ((c = Z_GetByte (Rxtimeout)) < 0)
  684.          return c;
  685.  
  686.       switch (c &= 0x7F)
  687.          {
  688.          case XON:
  689.          case XOFF:
  690.             continue;
  691.  
  692.          default:
  693.             if (!(c & 0x60))
  694.                continue;
  695.  
  696.          case '\r':
  697.          case '\n':
  698.          case ZDLE:
  699.             return c;
  700.          }                                       /* switch */
  701.  
  702.       }                                          /* for */
  703. }                                                /* _Z_TimedRead */
  704.  
  705. /*--------------------------------------------------------------------------*/
  706. /* Z LONG TO HEADER                                                         */
  707. /* Store long integer pos in Txhdr                                          */
  708. /*--------------------------------------------------------------------------*/
  709. void Z_PutLongIntoHeader (long pos)
  710. {
  711. #ifndef GENERIC
  712.    *((long *) Txhdr) = pos;
  713. #else
  714.    Txhdr[ZP0] = pos;
  715.    Txhdr[ZP1] = pos >> 8;
  716.    Txhdr[ZP2] = pos >> 16;
  717.    Txhdr[ZP3] = pos >> 24;
  718. #endif
  719. }                                                /* Z_PutLongIntoHeader */
  720.  
  721. /*--------------------------------------------------------------------------*/
  722. /* Z PULL LONG FROM HEADER                                                  */
  723. /* Recover a long integer from a header                                     */
  724. /*--------------------------------------------------------------------------*/
  725. long _Z_PullLongFromHeader (unsigned char *hdr)
  726. {
  727. #ifndef GENERIC
  728.    return (*((long *) hdr)); /*PLF Fri  05-05-1989  06:42:41 */
  729. #else
  730.  
  731.    long l;
  732.  
  733.    l = hdr[ZP3];
  734.    l = (l << 8) | hdr[ZP2];
  735.    l = (l << 8) | hdr[ZP1];
  736.    l = (l << 8) | hdr[ZP0];
  737.    return l;
  738. #endif
  739. }                                                /* _Z_PullLongFromHeader */
  740.  
  741. /* END OF FILE: zmisc.c */
  742.