コード例 #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
ファイル: UrlParam.cpp プロジェクト: azybler/scaliendb
void UrlParam::AddParam(const char *s, int length)
{
    int     offset;
    int     i;
    int     unlen; // length of the unencoded string
    char    c;

    unlen = 0;
    offset = buffer.GetLength();

    for (i = 0; i < length; /* i increased in loop */)
    {
        if (s[i] == '%')
        {
            c = DecodeChar(s + i);
            i += 3;
        }
        else 
        {
            c = s[i];
            i += 1;
        }

        unlen += 1;
        buffer.Append(&c, 1);
    }
    buffer.NullTerminate();
    
    params.Append((const char*) &offset, sizeof(int));
    params.Append((const char*) &unlen, sizeof(int));
    numParams++;
    
}
コード例 #3
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
	}
}
コード例 #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
ファイル: couch_js.c プロジェクト: vmx/couchdb_old
JSBool
DecodeString(const char *src, size_t srclen, jschar *dst, size_t *dstlenp) {
    uint32 v;
    size_t offset = 0, j, n, dstlen = *dstlenp, origDstlen = dstlen;

    if (!dst)
        dstlen = origDstlen = (size_t) -1;

    while (srclen) {
        v = (uint8) *src;
        n = 1;
        if (v & 0x80) {
            while (v & (0x80 >> n))
                n++;
            if (n > srclen)
                goto bufferTooSmall;
            if (n == 1 || n > 6)
                goto badCharacter;
            for (j = 1; j < n; j++) {
                if ((src[j] & 0xC0) != 0x80)
                    goto badCharacter;
            }
            v = DecodeChar((const uint8 *) src, n);
            if (v >= 0x10000) {
                v -= 0x10000;
                if (v > 0xFFFFF || dstlen < 2) {
                    *dstlenp = (origDstlen - dstlen);
                    return JS_FALSE;
                }
                if (dstlen < 2)
                    goto bufferTooSmall;
                if (dst) {
                    *dst++ = (jschar)((v >> 10) + 0xD800);
                    v = (jschar)((v & 0x3FF) + 0xDC00);
                }
                dstlen--;
            }
        }
        if (!dstlen)
            goto bufferTooSmall;
        if (dst)
            *dst++ = (jschar) v;
        dstlen--;
        offset += n;
        src += n;
        srclen -= n;
    }
コード例 #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);
}
コード例 #7
0
int td0dsk_t::Decode(UINT8 *buf, int len)  /* Decoding/Uncompressing */
{
    INT16 c,pos;
    int  count;  // was an unsigned long, seems unnecessary
    for (count = 0; count < len; ) {
            if(tdctl.bufcnt == 0) {
                if((c = DecodeChar()) < 0)
                    return(count); // fatal error
                if (c < 256) {
                    *(buf++) = c;
                    text_buf[tdctl.r++] = c;
                    tdctl.r &= (N - 1);
                    count++;
                }
                else {
                    if((pos = DecodePosition()) < 0)
                           return(count); // fatal error
                    tdctl.bufpos = (tdctl.r - pos - 1) & (N - 1);
                    tdctl.bufcnt = c - 255 + THRESHOLD;
                    tdctl.bufndx = 0;
                }
            }
            else { // still chars from last string
                while( tdctl.bufndx < tdctl.bufcnt && count < len ) {
                    c = text_buf[(tdctl.bufpos + tdctl.bufndx) & (N - 1)];
                    *(buf++) = c;
                    tdctl.bufndx++;
                    text_buf[tdctl.r++] = c;
                    tdctl.r &= (N - 1);
                    count++;
                }
                // reset bufcnt after copy string from text_buf[]
                if(tdctl.bufndx >= tdctl.bufcnt)
                    tdctl.bufndx = tdctl.bufcnt = 0;
            }
    }
    return(count); // count == len, success
}
コード例 #8
0
ファイル: u_deep.c プロジェクト: agwatic/PUAE
USHORT Unpack_DEEP(UCHAR *in, UCHAR *out, USHORT origsize){
	USHORT i, j, c;
	UCHAR *outend;

	initbitbuf(in);

	if (dms_init_deep_tabs) Init_DEEP_Tabs();

	outend = out+origsize;
	while (out < outend) {
		c = DecodeChar();
		if (c < 256) {
			*out++ = dms_text[dms_deep_text_loc++ & DBITMASK] = (UCHAR)c;
		} else {
			j = (USHORT) (c - 255 + THRESHOLD);
			i = (USHORT) (dms_deep_text_loc - DecodePosition() - 1);
			while (j--) *out++ = dms_text[dms_deep_text_loc++ & DBITMASK] = dms_text[i++ & DBITMASK];
		}
	}

	dms_deep_text_loc = (USHORT)((dms_deep_text_loc+60) & DBITMASK);

	return 0;
}
コード例 #9
0
ファイル: lzdecode.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
COUNT
cread (void *buf, COUNT size, COUNT count, PLZHCODE_DESC lpCodeDesc)
{
	COUNT r, j, i;
	BYTE *lpStr;

	if ((_lpCurCodeDesc = lpCodeDesc) == 0)
		return (0);

	size *= count;
	if (lpCodeDesc->StreamIndex + size > lpCodeDesc->StreamLength)
	{
		size /= count;
		count = (COUNT)((lpCodeDesc->StreamLength
				- lpCodeDesc->StreamIndex) / size);

		size *= count;
	}

	if (size == 0)
		return (0);

	lpStr = (BYTE*)buf;
	_StreamType = lpCodeDesc->StreamType;

	_Stream = lpCodeDesc->Stream;
	_workbuf = lpCodeDesc->workbuf;
	_workbuflen = lpCodeDesc->workbuflen;

	lpCodeDesc->StreamIndex += size;
	r = lpCodeDesc->buf_index;
	j = lpCodeDesc->bytes_left;
	if (j)
	{
		lpCodeDesc->bytes_left = 0;
		i = lpCodeDesc->restart_index;

		goto ReenterRun;
	}

	do
	{
		COUNT c;

		DecodeChar (&c);

		if (c < 256)
		{
			size--;

			*lpStr++ = lpCodeDesc->text_buf[r++ & (N - 1)] = (BYTE)c;
		}
		else
		{
			COUNT copy_size;

			//i is a COUNT;
				DecodePosition(&i);
			i = r - i - 1;
			j = c - 255 + THRESHOLD;
ReenterRun:
			if (j > size)
			{
				lpCodeDesc->bytes_left = j - size;
				lpCodeDesc->restart_index = i + size;
				j = size;
			}

			size -= j;
			do
			{
				COUNT loc_size;

				i &= (N - 1);
				r &= (N - 1);
				if ((i < r && i + j > r) || (i > r && i + j > r + N))
					copy_size = (r - i) & (N - 1);
				else if ((copy_size = j) > N)
					copy_size = N;

				loc_size = copy_size;
				if (i + loc_size > N)
				{
					COUNT k;

					k = N - i;
					memcpy (lpStr, &lpCodeDesc->text_buf[i], k);
					lpStr += k;
					loc_size -= k;
					i = 0;
				}

				memcpy (lpStr, &lpCodeDesc->text_buf[i], loc_size);
				lpStr += loc_size;
				i += loc_size;

				lpStr -= copy_size;

				loc_size = copy_size;
				if (r + loc_size > N)
				{
					COUNT k;

					k = N - r;
					memcpy (&lpCodeDesc->text_buf[r], lpStr, k);
					lpStr += k;
					loc_size -= k;
					r = 0;
				}

				memcpy (&lpCodeDesc->text_buf[r], lpStr, loc_size);
				lpStr += loc_size;
				r += loc_size;
			} while (j -= copy_size);
		}
	} while (size);

	lpCodeDesc->buf_index = r;
	lpCodeDesc->Stream = _Stream;
	lpCodeDesc->workbuf = _workbuf;
	lpCodeDesc->workbuflen = _workbuflen;

	return (count);
}