Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

static bool GetHeader ( void   )  [static]

Fetch ARC64 header.

Returns:
true if header is ok.

Definition at line 269 of file unarc.c.

References BitBuf, crc, crc2, ctrl, fp, GetBit(), GetByte(), GetThree(), GetWord(), hc, hcount, hl, hv, ssort(), State, and Status.

Referenced by ReadARC().

{
  unsigned int  w, i;
  const char LegalTypes[] = "SPUR";
  unsigned long mask;

  if (feof(fp) || ferror(fp))
    return false;
  else
    Status = 0;

  BitBuf        = 2;              /* Clear Bit buffer */
  crc           = 0;              /* checksum */
  crc2          = 0;              /* Used in checksum calculation */
  State         = 0;              /* LZW state */
  ctrl          = 254;            /* Run-Length control character */

  entry.version = GetByte();
  entry.mode    = GetByte();
  entry.check   = GetWord();
  entry.size    = GetThree();
  entry.blocks  = GetWord();
  entry.type    = GetByte();
  entry.fnlen   = GetByte();

  /* Check for invalid header, If invalid, then we've input past the end */
  /* Possibly due to XMODEM padding or whatever */

  if (entry.fnlen > 16)
    return 0;

  for (w=0; w < entry.fnlen; w++)
    entry.name[w] = GetByte();

  entry.name[entry.fnlen] = 0;

  if (entry.version > 1) {
    entry.rl  = GetByte();
    entry.date= GetWord();
  }

  if (Status == EOF)
    return false;

  if (entry.version == 0 || entry.version > 2)
    return false;

  if (entry.version == 1) { /* If ARC64 version 1.xx */
    if (entry.mode > 2)     /* Only store, pack, squeeze */
      return false;
  }
  if (entry.mode == 1)      /* If packed get control char */
    ctrl = GetByte();       /* V2 always uses 0xfe V1 varies */

  if (entry.mode > 5)
    return false;

  if ((entry.mode == 2) || (entry.mode == 4)) { /* if squeezed or squashed */
    hcount = 255;                                 /* Will be first code */

    for (w=0; w<256; w++) {                       /* Fetch Huffman codes */
      hv[w] = w;

      hl[w]=0;
      mask = 1;
      for (i=1; i<6; i++) {
      if (GetBit())
        hl[w] |= mask;
      mask <<= 1;
      }

      if (hl[w] > 24)
      return false;                             /* Code too big */

      hc[w] = 0;
      if (hl[w]) {
      i = 0;
      mask = 1;
      while (i<hl[w]) {
        if (GetBit())
          hc[w] |= mask;
        i++;
        mask <<= 1;
      }
      }
      else
      hcount--;
    }
    ssort ();
  }

  return !!strchr (LegalTypes, entry.type);
}


Generated by  Doxygen 1.6.0   Back to index