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

static unsigned decodeBytes ( unsigned  len  )  [static]

Decode a block or compare the second copy to the first copy

Parameters:
len expected length of the block
Returns:
the length of the decoded block

Definition at line 330 of file decode.c.

References block, chk, dec_err, decbuf, declen, decodeBlock(), LongBlock, Mismatch, NoFirst, NoSecond, ShortBlock, and verbose.

Referenced by dec().

{
  /* first copy of the block */
  char* firstbuf;
  /* length of the first copy of the block */
  unsigned firstlen;

  if (chk) {
    firstbuf = decbuf;
    firstlen = declen;
  }
  else {
    firstbuf = 0;
    firstlen = 0;
    free (decbuf);
  }

  decbuf = 0; declen = 0;

  for (;; block++) {
    /* decode a header block */
    switch (decodeBlock ()) {
    default:
      continue;
    case 0:
      free (firstbuf);
      return 0;
    case 0x81: /* first copy */
      if (verbose)
      fprintf (stderr, "decoded %u bytes (1st copy)\n", declen);
      if (chk) {
      if (!dec_err || (*dec_err) (NoSecond, block, 0))
        return 0;
      }
      free (firstbuf); firstbuf = 0; firstlen = 0;
      chk = 1;
      break;
    case 1: /* second copy */
      if (verbose)
      fprintf (stderr, "decoded %u bytes (2nd copy)\n", declen);
      if (!chk) {
      if (!dec_err || (*dec_err) (NoFirst, block, 0))
        return 0;
      }
      else {
      chk = 0;
      if (declen > firstlen) {
        if (!dec_err || (*dec_err) (LongBlock, block, declen - firstlen)) {
          free (firstbuf);
          return 0;
        }
      }
      else if (declen < firstlen) {
        if (!dec_err || (*dec_err) (ShortBlock, block, firstlen - declen)) {
          free (firstbuf);
          return 0;
        }
      }
      else {
        for (declen = 0; declen < firstlen; declen++) {
          if (decbuf[declen] != firstbuf[declen]) {
            if (!dec_err || (*dec_err) (Mismatch, block, declen)) {
            free (firstbuf);
            return 0;
            }
          }
        }
      }

      free (firstbuf); firstbuf = 0; firstlen = 0;
      free (decbuf); decbuf = 0; declen = 0;
      continue;
      }
    }

    if (declen > len) {
      if (!dec_err || (*dec_err) (LongBlock, block, declen - len))
      return 0;
      continue;
    }
    else if (declen < len) {
      if (!dec_err || (*dec_err) (ShortBlock, block, len - declen))
      return 0;
      continue;
    }

    return declen;
  }
}


Generated by  Doxygen 1.6.0   Back to index