All pastes #283359 Raw Edit

Mine

public cpp v1 · immutable
#283359 ·published 2006-12-18 08:22 UTC
rendered paste body
	// We need to decompress the LZSS compression	// This is my own code, so excuse the ugliness	int windowSize = 4096;	char *dict = new char[4096];	// Fill dictionary with spaces	memset(dict,'\0x20',4096);		int offset;	char O;	char L;	char FLAGS;	char byte;	short N;	// 0. Set dictionary offset to D-18	offset = 4078;		// 1. If at the end of file, exit.	while(filesize)	{		// 2. Read N (2 bytes == word) from input.		// The absolute value of N is how many bytes of data to read (if N=0, exit)		DAT1Stream.read((char *)&N,sizeof(N));		filesize--;		// Flip endianness		N = (N>>8) | (N<<8);		// 2.1. If N < 0, read the absolute value 		// of N bytes from input and write to output (do not put into dictionary). Go to 1.		if (N < 0)		{			char *output = new char[N*-1];			DAT1Stream.read((char *)output,N*-1);			filesize -= N*-1;			fout.write((char *)output,N*-1);			continue;		}		// 2.2. If N > 0, clear dictionary, repeat below until N bytes have been read from input,		// and then go to 1.		if (N > 0)		{			// Clear dictionary (with spaces, not null)			memset(dict,'\0x20',4096);			while (N)			{				// 2.2.1. Read FLAGS (1 byte) from input. Repeat below 8 times.				DAT1Stream.read((char *)&FLAGS,sizeof(FLAGS));				filesize -= sizeof(FLAGS);				// Repeat 8 times				for (int i=0;i<8;i++,filesize--,N--)				{					// 2.2.1.1. If FLAGS *is not* a modulus of 2 (& 1 != 0), 					//read 1 byte from input, write to output, then go to 2.2.1.3.					if ((FLAGS & 1) != 0)					{						DAT1Stream.read((char *)&byte, sizeof(byte));						filesize--;						cout << byte;						// 2.2.1.3. Divide FLAGS by 2, rounding down (>> 1).						FLAGS = (FLAGS/2);						FLAGS = (FLAGS>>1);					} else { // 2.2.1.2. If FLAGS *is* a modulus of 2 (& 1 == 0)						// 2.2.1.2.1. Read O (1 byte) and L (1 byte) from input.						DAT1Stream.read((char *)&O,sizeof(O));						DAT1Stream.read((char *)&L,sizeof(L));						filesize -= 2;						// 2.2.1.2.2. Take away the High-nibble (first 4 bits) from L and prepend it to O;						O = (O>>4) | (L<<4);						return;					}				}			}				}	}