Commit c8384c61 authored by Lee Shallis's avatar Lee Shallis
Browse files

No longer need a bunch of the pront statments that were being used,

reduced complexity of LoadZlibHuffs() too, still have the problem of
overly long loop UIDs
parent a317a3d4
......@@ -331,14 +331,12 @@ int LoadZlibHuffs( ZLIB *zlib )
ZLIB_SYMBOLS *Codes = &(zlib->Symbols[ZLIB_SYMBOLS_ID_CODE]);
ZLIB_SYMBOLS *Loops = &(zlib->Symbols[ZLIB_SYMBOLS_ID_LOOP]);
ZLIB_SYMBOL *codes = Codes->symbols, *Code;
ZLIB_FULL_SYMBOL fullType = {0};
ZLIB_FULL_SYMBOL fullType = {0}, Temp;
STREAM *Stream = zlib->Stream;
FILE *errors = zlib->Buffers->Alloc->errors;
FILE *verbose = zlib->Buffers->Alloc->verbose;
FILE *detailed = zlib->Buffers->Alloc->detailed;
int done = 0, pos = ZLIB_MAX_TYPES, lit = 0, prv = 0,
keep = Codes->foresee,
count = keep + Loops->foresee;
total = keep + Loops->foresee, count = keep, loose = 0;
if ( !quiet_zlib )
{
......@@ -354,163 +352,55 @@ int LoadZlibHuffs( ZLIB *zlib )
);
}
while ( done < count && Stream->err == 0 )
while ( done < total )
{
bool use;
int i = 0, copy = 0, len = prv;
ZLIB_SYMBOL *Type = SeekZlibSymbol( Stream, Types );
if ( !Type )
while ( done < count && Stream->err == 0 )
{
ECHO
(
errors,
fputs( "Couldn't find code!\n", errors );
EchoZlibSymbolsListDetails( errors, zlib, ZLIB_SYMBOLS_ID_TYPE );
ECHO_ERR( errors, EINVAL )
);
return EINVAL;
}
int i = 0;
ZLIB_SYMBOL *Type = SeekZlibSymbol( Stream, Types );
ZlibFullSymbol( &fullType, Type );
memset( &Temp, 0, sizeof(ZLIB_FULL_SYMBOL) );
if ( !quiet_zlib )
{
ECHO
(
detailed,
EchoStreamDetails( detailed, Stream );
fprintf( detailed,"type_" );
EchoZlibSymbolDetails( detailed, Type, Type->src )
);
}
if ( done == keep )
{
lit = ZLIB_LOOP_LIT0;
pos = ZLIB_MAX_TYPES + ZLIB_MAX_CODES;
}
ZlibFullSymbol( &fullType, Type );
Temp.cpy = fullType.cpy;
if ( Type->lit >= 16 )
{
copy = StreamBits( Stream, fullType.get, true );
copy += fullType.cpy;
if ( Type->lit > 16 || !len )
if ( Type->lit < 16 )
Temp.len = loose ? Type->len + 1 : Type->lit;
else
{
len = codes->len;
Temp.cpy += StreamBits( Stream, fullType.get, true );
Temp.len = (Type->lit == 16) ? prv : codes->len;
if ( !len )
if ( !Temp.len )
{
lit += copy;
pos += copy;
done += copy;
copy = 0;
len = -1;
lit += Temp.cpy;
pos += Temp.cpy;
done += Temp.cpy;
Temp.cpy = 0;
}
}
}
else
{
Code = codes + pos;
Code->lit = lit;
if ( done < keep )
{
Code->src = done;
Code->len = Type->lit;
Code->use = !!(Type->lit);
}
else
{
Code->use = true;
Code->src = done - keep;
Code->len = Type->len + 1;
}
if ( !quiet_zlib && detailed && Code->len )
{
fprintf(detailed,"%s_", (done >= keep) ? "loop" : "code" );
EchoZlibSymbolDetails( detailed, Code, Code->src );
}
if ( Code->len > Codes->longest )
Codes->longest = Code->len;
Temp.use = !!(Temp.len);
prv = Temp.len;
//if ( Type->lit || done >= keep )
prv = Code->len;
++lit;
++pos;
++done;
}
if ( Temp.len > Codes->longest )
Codes->longest = Temp.len;
if ( copy )
{
if ( lit < ZLIB_LOOP_LIT0 )
for ( i = 0; i < Temp.cpy; ++i, ++lit, ++pos, ++done )
{
if ( lit + copy > 286 )
{
ECHO
(
errors,
ECHO( errors, EINVAL );
fprintf
(
errors,
"copy of a literal's length would have gone "
"beyond the limit for literal/repeater codes (286), "
"lit = %3u, copy = %3u\n", lit, copy
)
);
return EINVAL;
}
}
else if ( done + copy > count )
{
ECHO
(
errors,
ECHO( errors, EINVAL );
fprintf
(
errors,
"copy of a loop code's length would have gone "
"beyond the expected limit for loop codes (%u)\n",
count - keep
)
);
return EINVAL;
}
Code = codes + pos;
if ( !quiet_zlib )
{
ECHO
(
detailed,
fprintf
(
detailed,
"Copying %d length %u times...\n",
len, copy
)
);
Code->use = Temp.use;
Code->len = Temp.len;
Code->lit = lit;
Code->src = done - loose;
}
}
len += !(done < keep);
use = !!len;
for ( i = 0; i < copy; ++i, ++lit, ++pos, ++done )
{
Code = codes + pos;
Code->lit = lit;
Code->use = use;
Code->len = len;
Code->src = (done < keep) ? lit : done - keep;
}
lit = ZLIB_LOOP_LIT0;
pos = ZLIB_MAX_TYPES + ZLIB_MAX_CODES;
count = total;
loose = keep;
}
Codes->used = ZLIB_MAX_CODES;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment