home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / LBR / BOOZ4CPM.ARK / PORTABLE.C < prev    next >
Text File  |  1988-09-05  |  4KB  |  122 lines

  1. /* 
  2. The contents of this file are hereby released to the public domain.
  3.                                    -- Rahul Dhesi 1987/02/08
  4. */
  5.  
  6. typedef char BYTE;      /* MUST be an 8-bit value */
  7.  
  8. #include "func.h"
  9. #include "zoo.h"
  10.  
  11. long to_long ();
  12. int to_int ();
  13. int b_to_zooh();
  14. int b_to_dir();
  15. int splitlong();
  16. int splitint();
  17.  
  18. /**********************
  19. to_long() converts four consecutive bytes, in order of increasing
  20. significance, to a long integer.  It is used to make Zoo independent of the
  21. byte order of the system.  
  22. */
  23. long to_long(data)
  24. BYTE data[];
  25. {
  26.    int i;
  27.    long retval;
  28.    retval = ((unsigned) data[2] & 0xff) | 
  29.       (((unsigned) data[3] & 0xff) << 8);
  30.    retval <<= 16;
  31.    retval |= (((unsigned) data[0] & 0xff) | 
  32.       (((unsigned) data[1] & 0xff) << 8));
  33.    return (retval);
  34. }
  35.  
  36. /**********************
  37. to_int() converts two consecutive bytes, in order of increasing
  38. significance, to an integer, in a machine-independent manner
  39. */
  40. int to_int(data)
  41. BYTE data[];
  42. {
  43.    return (int) (((unsigned) data[0] & 0xff) | 
  44.       ((unsigned) (data[1] & 0xff) << 8));
  45. }
  46.  
  47. /**********************
  48. Function rd_zooh() reads a Zoo archive header in a machine-dependent manner,
  49. from a file handle.
  50. */
  51. int rd_zooh (header, zoo_han)
  52. struct zoo_header *header;
  53. int zoo_han;
  54. {
  55.    int status;
  56.    BYTE bytes[SIZ_ZOOH];
  57.    status = read (zoo_han, (char *) bytes, SIZ_ZOOH);
  58.    b_to_zooh (header, bytes);
  59.    return (status);
  60. }
  61.  
  62. /**********************
  63. Function rd_dir() reads a directory entry in a machine-independent manner
  64. from a handle.
  65. */
  66. int rd_dir(direntry, zoo_han)
  67. struct direntry *direntry;
  68. int zoo_han;
  69. {
  70.    int status;
  71.    BYTE bytes[SIZ_DIR];
  72.    status = read (zoo_han, (char *) bytes, SIZ_DIR);
  73.    b_to_dir (direntry, bytes);
  74.    return (status);
  75. }
  76.  
  77. /***********************
  78. b_to_zooh() converts an array of BYTE to a zoo_header structure.
  79. */
  80. int b_to_zooh (zoo_header, bytes)
  81. struct zoo_header *zoo_header;
  82. BYTE bytes[];
  83. {
  84.    int i;
  85.    for (i = 0; i < SIZ_TEXT; i++)
  86.       zoo_header->text[i] = bytes[TEXT_I + i];
  87.    zoo_header->lo_tag = to_int(&bytes[ZTAG_I]);
  88.    zoo_header->hi_tag = to_int(&bytes[ZTAG_I+2]);
  89.    /* zoo_header->zoo_tag = to_long(&bytes[ZTAG_I]); */
  90.    zoo_header->zoo_start = to_long(&bytes[ZST_I]);
  91.    zoo_header->zoo_minus = to_long(&bytes[ZSTM_I]);
  92.    zoo_header->major_ver = bytes[MAJV_I];
  93.    zoo_header->minor_ver = bytes[MINV_I];
  94. }
  95.  
  96. /* b_to_dir() converts bytes to directory entry structure */
  97. int b_to_dir(direntry, bytes)
  98. struct direntry *direntry;
  99. BYTE bytes[];
  100. {
  101.    int i;
  102.    direntry->lo_tag = to_int(&bytes[DTAG_I]);
  103.    direntry->hi_tag = to_int(&bytes[DTAG_I+2]);
  104.    /* direntry->zoo_tag = to_long(&bytes[DTAG_I]); */
  105.    direntry->type = bytes[DTYP_I];
  106.    direntry->packing_method = bytes[PKM_I];
  107.    direntry->next = to_long(&bytes[NXT_I]);
  108.    direntry->offset = to_long(&bytes[OFS_I]);
  109.    direntry->date = to_int(&bytes[DAT_I]);
  110.    direntry->time = to_int(&bytes[TIM_I]);
  111.    direntry->file_crc = to_int(&bytes[CRC_I]);
  112.    direntry->org_size = to_long(&bytes[ORGS_I]);
  113.    direntry->size_now = to_long(&bytes[SIZNOW_I]);
  114.    direntry->major_ver = bytes[DMAJ_I];
  115.    direntry->minor_ver = bytes[DMIN_I];
  116.    direntry->deleted = bytes[DEL_I];
  117.    direntry->comment = to_long(&bytes[CMT_I]);
  118.    direntry->cmt_size = to_int(&bytes[CMTSIZ_I]);
  119.    for (i = 0; i < FNM_SIZ; i++)
  120.       direntry->fname[i] = bytes[FNAME_I + i];
  121. }
  122.