Beispiel #1
0
void decompress(File *in, File *out)
{
    uint32_t fileSize, length = 0;
	uint16_t encoderNodeCount;
	uint16_t ch, *xList, *zList;
	Encoder_Node *root, *p;

	decoder_readHead(&fileSize, &encoderNodeCount, &xList, &zList, in);
	root = decoder_rebuildEncoder(xList, zList, 0, 0, encoderNodeCount);

	ch = Fgetc(in);
	p = root;
	while (!Feof(in)) {
		int8_t bit;

		while (((bit=FgetBit(ch)) != (int8_t)-1) && length < fileSize) {
			if (bit == (int8_t)0)
				p = p->left;
			else
				p = p->right;

			if (p->left == NULL && p->right == NULL) {
				Fputc(p->ch, out);
				p = root;
				++length;
			}
		}

		ch = Fgetc(in);
	}

	free(xList);
	free(zList);
	encoder_freeEncoder(root);
}
Beispiel #2
0
int Fcopy(FILE * const fdst, FILE * const fsrc)
{	byte *buf;
	size_t len, i;
	int err;

	DBG_ENTER("Fcopy", Suppl_supplio)

	assert(fsrc);
	assert(fdst);

	chkHeap
	if(Fmaxbuf(&buf, &len))
		DBG_RETURN_I( 3)				/* out of memory */

	chkHeap
	while((err = Fcopybuf(fdst, fsrc, buf, len, &i)) == 0);

	chkHeap
	free(buf);
		/*	err == 0 --> impossible
			err == 1 --> read error, this is OK, if read had hit EOF
		*/
	chkHeap
	DBG_RETURN_BI(err < 2? Feof(fsrc) == 0: err)
}
/*
;///////////////////////////////////////////////////////////////////////////////
;> Name:            FSFileEof
; Type:             Function
; Description:      C wrapper for FileEOF
; Inputs:
;                   a = File Handle.
; Outputs:
;                   a = Number of bytes from the end or $7fffff if number of bytes
;                        from the end of file greater than $7fffff.
;                   a = -1 if function failed.
;
; Notes:
;                   see FILECreate for further information.
;<
;///////////////////////////////////////////////////////////////////////////////
*/
INT _reentrant FSFileEof(INT Handle)
{
    LONG retval;
    retval = Feof(Handle);
    if (retval > (LONG)0x7fffff)
    {
        retval = (LONG)0x7fffff;
    }
    return (INT)retval;
}
Beispiel #4
0
void compress(File *in, File *out)
{
	uint8_t ch;
	Queue_Node *buf[256];
	Queue *queueHead;
	Encoder_Node *en, *root;
	Encoder_Table **table;
	Queue_Node *qn;
	uint16_t nodeCount;

	memset(buf, 0, sizeof(buf));

	queueHead = queue_new();
	ch = Fgetc(in);
	while (!Feof(in)) {
		if (buf[ch] == NULL) {
			en = encoder_newNode(ch, 0, NULL, NULL);
			qn = queue_newNode(1, en, NULL, NULL);
			queue_append(queueHead, qn);
			buf[ch] = qn;
		} else
			buf[ch]->count++;

		ch = Fgetc(in);
	}

	Frewind(in);
	root = encoder_newEncoder(queueHead);
	table = encoder_newEncoderTable(buf);
	nodeCount = encoder_getEncoderNodeCount(table);
	encoder_writeHeader(root, out, in->size, nodeCount);
	encoder_writeData(table, in, out);

	encoder_freeEncoder(root);
	encoder_freeEncoderTable(table);
	queue_freeQueue(queueHead);
}