コード例 #1
0
unsigned unpack_lzh(u8 *src, unsigned size, u8 *buf)
{
  packed_ptr = src; packed_end = src+size;
  int i, j, k, c;
  unsigned count = 0;
  StartHuff();

//  while (count < textsize)  // textsize - sizeof unpacked data
  while (packed_ptr < packed_end)
  {
    c = DecodeChar();
    if (c < 256)
    {
      *buf++ = c;
      text_buf[r++] = c;
      r &= (N - 1);
      count++;
    } else {
      i = (r - DecodePosition() - 1) & (N - 1);
      j = c - 255 + THRESHOLD;
      for (k = 0; k < j; k++)
      {
        c = text_buf[(i + k) & (N - 1)];
        *buf++ = c;
        text_buf[r++] = c;
        r &= (N - 1);
        count++;
      }
    }
  }
  return count;
}
コード例 #2
0
ファイル: decode.c プロジェクト: LambdaCalculus379/SLS-1.02
void melt2 ()
{
	register short    i, j, k, r, c;

/* Huffman-dependent part */
	if(read_header() == EOF)
		return;
	StartHuff(N_CHAR2);
	init(Table2);
/* end of Huffman-dependent part */

	InitIO();
	for (i = 0; i < N2 - F2; i++)
		text_buf[i] = ' ';
	r = N2 - F2;
	for (in_count = 0;; ) {
		c = DecodeChar();

		if (c == ENDOF)
			break;
		if (c < 256) {
#ifdef DEBUG
			if (debug)
				fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
			else
#endif /* DEBUG */
				putchar (c);
			text_buf[r++] = c;
			r &= N2 - 1;
			in_count++;
		} else {
			i = (r - DecodePosition() - 1) & (N2 - 1);
			j = c - 256 + THRESHOLD;
#ifdef DEBUG
			if (debug)
				fputc('"', stderr);
#endif
			for (k = 0; k < j; k++) {
				c = text_buf[(i + k) & (N2 - 1)];
#ifdef DEBUG
				if (debug)
					fprintf(stderr, "%s", pr_char((uc_t)c));
				else
#endif
					putchar (c);
				text_buf[r++] = c;
				r &= (N2 - 1);
				in_count++;
			}
#ifdef DEBUG
			if (debug)
				fprintf(stderr, "\"\n");
#endif
		}
		INDICATOR
	}
}
コード例 #3
0
DECODE_REF
copen (PVOID InStream, STREAM_TYPE SType, STREAM_MODE SMode)
{
	MEM_HANDLE h;
	DWORD StreamLength;

	_StreamType = SType;
	_Stream = InStream;
	if (SMode == STREAM_WRITE) /* writing */
	{
		OutChar (0); /* skip future StreamLength */
		OutChar (0);
		OutChar (0);
		OutChar (0);

		StreamLength = 0;
	}
	else /* reading */
	{
		BYTE lobyte, hibyte;
		UWORD loword, hiword;

		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		loword = MAKE_WORD (lobyte, hibyte);
		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		hiword = MAKE_WORD (lobyte, hibyte);

		StreamLength = MAKE_DWORD (loword, hiword);
	}

	h = 0;
	if (StreamLength == 0xFFFFFFFF
			|| (h = AllocCodeDesc ()) == 0
			|| (_lpCurCodeDesc = LockCodeDesc (h)) == 0)
	{
		_lpCurCodeDesc = 0;
		FreeCodeDesc (h);
	}
	else
	{
		_lpCurCodeDesc->fh = h;
		_lpCurCodeDesc->Stream = _Stream;
		_lpCurCodeDesc->StreamType = _StreamType;
		_lpCurCodeDesc->StreamMode = SMode;
		_lpCurCodeDesc->StreamLength = StreamLength;
		_lpCurCodeDesc->buf_index = N - F;
		memset ((PBYTE)&_lpCurCodeDesc->text_buf[0], ' ', N - F);

		StartHuff ();
	}

	return ((DECODE_REF)_lpCurCodeDesc);
}
コード例 #4
0
ファイル: decode.c プロジェクト: LambdaCalculus379/SLS-1.02
void melt1 ()
{
	register short    i, j, k, r, c;

	StartHuff(N_CHAR1);
	init(Table1);
	InitIO();
	for (i = 0; i < N1 - F1; i++)
		text_buf[i] = ' ';
	r = N1 - F1;
	for (in_count = 0;; ) {
		c =  DecodeChar();

		if (c == ENDOF)
			break;

		if (c < 256) {
#ifdef DEBUG
			if (debug)
				fprintf(stderr, "'%s'\n", pr_char((uc_t)c));
			else
#endif /* DEBUG */
				putchar (c);
			text_buf[r++] = c;
			r &= (N1 - 1);
			in_count++;
		} else {
			i = (r - DecodePOld() - 1) & (N1 - 1);
			j = c - 256 + THRESHOLD;
#ifdef DEBUG
			if (debug)
				fputc('"', stderr);
#endif
			for (k = 0; k < j; k++) {
				c = text_buf[(i + k) & (N1 - 1)];
#ifdef DEBUG
				if (debug)
					fprintf(stderr, "%s", pr_char((uc_t)c));
				else
#endif
					putchar (c);
				text_buf[r++] = c;
				r &= (N1 - 1);
				in_count++;
			}
#ifdef DEBUG
			if (debug)
				fprintf(stderr, "\"\n");
#endif
		}
		INDICATOR
	}
}
コード例 #5
0
void td0dsk_t::init_Decode()
{
    int i;
    getbuf = 0;
    getlen = 0;
    tdctl.ibufcnt= tdctl.ibufndx = 0; // input buffer is empty
    tdctl.bufcnt = 0;
    StartHuff();
    for (i = 0; i < N - F; i++)
        text_buf[i] = ' ';
    tdctl.r = N - F;
}
コード例 #6
0
ファイル: lzhuf.c プロジェクト: Grumbel/rfactortools
int unlzh(unsigned char *in, int insz, unsigned char *out, int outsz) {
    int  i, j, k, r, c;
    unsigned long int  count;

    infile   = in;
    infilel  = in + insz;
    outfile  = out;
    outfilel = out + outsz;

    /*textsize = (xgetc(infile));
    textsize |= (xgetc(infile) << 8);
    textsize |= (xgetc(infile) << 16);
    textsize |= (xgetc(infile) << 24);
    if (textsize == 0)
        return(-1);*/
    textsize = outsz;

    StartHuff();
    for (i = 0; i < N - F; i++)
        text_buf[i] = 0x20;
    r = N - F;
    for (count = 0; count < textsize; ) {
        c = DecodeChar();
        if (c < 256) {
            if (xputc(c, outfile) == -1) {
                return(-1);
            }
            text_buf[r++] = (unsigned char)c;
            r &= (N - 1);
            count++;
        } else {
            i = (r - DecodePosition() - 1) & (N - 1);
            j = c - 255 + THRESHOLD;
            for (k = 0; k < j; k++) {
                c = text_buf[(i + k) & (N - 1)];
                if (xputc(c, outfile) == -1) {
                    return(-1);
                }
                text_buf[r++] = (unsigned char)c;
                r &= (N - 1);
                count++;
            }
        }
    }
    return(outfile - out);
}