示例#1
0
/* ===========================================================================
 * Initialize the "longest match" routines for a new file
 */
void lm_init (int pack_level, /* 1: best speed, 9: best compression */
              ush *flags)     /* general purpose bit flag */
{
    register unsigned j;

    if (pack_level < 1 || pack_level > 9) gzip_error ("bad pack level");

    /* Initialize the hash table. */
    memzero((char*)head, HASH_SIZE*sizeof(*head));
    /* prev will be initialized on the fly */

    /* rsync params */
    rsync_chunk_end = 0xFFFFFFFFUL;
    rsync_sum = 0;

    /* Set the default configuration parameters:
     */
    max_lazy_match   = configuration_table[pack_level].max_lazy;
    good_match       = configuration_table[pack_level].good_length;
#ifndef FULL_SEARCH
    nice_match       = configuration_table[pack_level].nice_length;
#endif
    max_chain_length = configuration_table[pack_level].max_chain;
    if (pack_level == 1) {
       *flags |= FAST;
    } else if (pack_level == 9) {
       *flags |= SLOW;
    }
    /* ??? reduce max_chain_length for binary files */

    strstart = 0;
    block_start = 0L;

    lookahead = read_buf((char*)window,
			 sizeof(int) <= 2 ? (unsigned)WSIZE : 2*WSIZE);

    if (lookahead == 0 || lookahead == (unsigned)EOF) {
       eofile = 1, lookahead = 0;
       return;
    }
    eofile = 0;
    /* Make sure that we always have enough lookahead. This is important
     * if input comes from a device such as a tty.
     */
    while (lookahead < MIN_LOOKAHEAD && !eofile) fill_window();

    ins_h = 0;
    for (j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(ins_h, window[j]);
    /* If lookahead < MIN_MATCH, ins_h is garbage, but this is
     * not important since only literal bytes will be emitted.
     */
}
示例#2
0
文件: gzip.cpp 项目: leeter/VGMSource
			void gzip_header::process(char c)
			{
				uint8_t value = static_cast<uint8_t>(c);
				switch (state_) {
				case s_id1:
					if (value != gzip::magic::id1)
						boost::throw_exception(gzip_error(gzip::bad_header));
					state_ = s_id2;
					break;
				case s_id2:
					if (value != gzip::magic::id2)
						boost::throw_exception(gzip_error(gzip::bad_header));
					state_ = s_cm;
					break;
				case s_cm:
					if (value != gzip::method::deflate)
						boost::throw_exception(gzip_error(gzip::bad_method));
					state_ = s_flg;
					break;
				case s_flg:
					flags_ = value;
					state_ = s_mtime;
					break;
				case s_mtime:
					mtime_ += value << (offset_ * 8);
					if (offset_ == 3) {
						state_ = s_xfl;
						offset_ = 0;
					}
					else {
						++offset_;
					}
					break;
				case s_xfl:
					state_ = s_os;
					break;
				case s_os:
					os_ = value;
					if (flags_ & gzip::flags::extra) {
						state_ = s_xlen;
					}
					else if (flags_ & gzip::flags::name) {
						state_ = s_name;
					}
					else if (flags_ & gzip::flags::comment) {
						state_ = s_comment;
					}
					else if (flags_ & gzip::flags::header_crc) {
						state_ = s_hcrc;
					}
					else {
						state_ = s_done;
					}
					break;
				case s_xlen:
					xlen_ += value << (offset_ * 8);
					if (offset_ == 1) {
						state_ = s_extra;
						offset_ = 0;
					}
					else {
						++offset_;
					}
					break;
				case s_extra:
					if (--xlen_ == 0) {
						if (flags_ & gzip::flags::name) {
							state_ = s_name;
						}
						else if (flags_ & gzip::flags::comment) {
							state_ = s_comment;
						}
						else if (flags_ & gzip::flags::header_crc) {
							state_ = s_hcrc;
						}
						else {
							state_ = s_done;
						}
					}
					break;
				case s_name:
					if (c != 0) {
						file_name_ += c;
					}
					else if (flags_ & gzip::flags::comment) {
						state_ = s_comment;
					}
					else if (flags_ & gzip::flags::header_crc) {
						state_ = s_hcrc;
					}
					else {
						state_ = s_done;
					}
					break;
				case s_comment:
					if (c != 0) {
						comment_ += c;
					}
					else if (flags_ & gzip::flags::header_crc) {
						state_ = s_hcrc;
					}
					else {
						state_ = s_done;
					}
					break;
				case s_hcrc:
					if (offset_ == 1) {
						state_ = s_done;
						offset_ = 0;
					}
					else {
						++offset_;
					}
					break;
				default:
					BOOST_ASSERT(0);
				}
			}