Initial revision
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2036 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
Debugging within the FreeType sources:
|
||||
======================================
|
||||
|
||||
I. Configuration macros
|
||||
-----------------------
|
||||
|
||||
There are several ways to enable debugging features in a FreeType 2
|
||||
builds. This is controlled through the definition of special macros
|
||||
located in the file "ftoptions.h". The macros are:
|
||||
|
||||
|
||||
FT_DEBUG_LEVEL_ERROR
|
||||
|
||||
#define this macro if you want to compile the FT_ERROR macro calls
|
||||
used to print error messages during program execution. This will
|
||||
not stop the program, but is very useful to spot invalid fonts
|
||||
during development and code wordarounds for them.
|
||||
|
||||
FT_DEBUG_LEVEL_TRACE
|
||||
|
||||
#define this macro if you want to compile both the FT_ERROR macro
|
||||
and the FT_TRACE one. This also includes the variants FT_TRACE0,
|
||||
FT_TRACE1, FT_TRACE2, ..., FT_TRACE6.
|
||||
|
||||
The trace macros are used to send debugging messages when an
|
||||
appropriate "debug level" is configured at runtime through the
|
||||
FT2_DEBUG environment variable (more on this later).
|
||||
|
||||
FT_DEBUG_MEMORY
|
||||
|
||||
If this macro is #defined, the FreeType engines is linked with a
|
||||
small but effective debugging memory manager that tracks all
|
||||
allocations and frees that are performed within the font engine.
|
||||
|
||||
When the FT2_DEBUG_MEMORY environment variable is defined at
|
||||
runtime, a call to FT_Done_FreeType will dump memory statistics,
|
||||
including the list of leaked memory blocks with the source locations
|
||||
where these were allocated. It's always a very good idea to define
|
||||
this in development builds. This works with _any_ program linked to
|
||||
FreeType, but requires a big deal of memory (the debugging memory
|
||||
manager never frees the blocks to the heap in order to detect double
|
||||
frees).
|
||||
|
||||
When FT2_DEBUG_MEMORY isn't defined at runtime, the debugging memory
|
||||
manager is ignored, and performance is un-affected.
|
||||
|
||||
|
||||
II. Debugging macros
|
||||
--------------------
|
||||
|
||||
Several macros can be used within the FreeType sources to help debugging
|
||||
its code:
|
||||
|
||||
1. FT_ERROR(( ... ))
|
||||
|
||||
This macro is used to send debug messages that indicate relatively
|
||||
serious errors (like broken font files), but will not stop the
|
||||
execution of the running program. Its code is compiled only when
|
||||
either FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined in
|
||||
"ftoption.h".
|
||||
|
||||
Note that you must use with a printf-like signature, but with double
|
||||
parentheses, like in:
|
||||
|
||||
FT_ERROR(( "your %s is not %s\n", "foo", "bar" ));
|
||||
|
||||
|
||||
2. FT_ASSERT( condition )
|
||||
|
||||
This macro is used to check strong assertions at runtime. If its
|
||||
condition isn't TRUE, the program will abort with a panic message.
|
||||
Its code is compiled when either FT_DEBUG_LEVEL_ERROR or
|
||||
FT_DEBUG_LEVEL_TRACE are defined. You don't need double-parentheses
|
||||
here. For example:
|
||||
|
||||
FT_ASSERT( ptr != NULL );
|
||||
|
||||
|
||||
3. FT_TRACE( level, (message...) )
|
||||
|
||||
The FT_TRACE macro is used to send general-purpose debugging
|
||||
messages during program execution. This macro uses an *implicit*
|
||||
macro named FT_COMPONENT used to name the current FreeType component
|
||||
being run.
|
||||
|
||||
The developer should always define FT_COMPONENT as appropriate, for
|
||||
example as in:
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_io
|
||||
|
||||
The value of the FT_COMPONENT macro is an enumeration named
|
||||
trace_XXXX where XXXX is one of the component names defined in the
|
||||
internal file <freetype/internal/fttrace.h>.
|
||||
|
||||
Each such component is assigned a "debug level", ranging from 0 to 6
|
||||
when a program linked with FreeType starts, through the use of the
|
||||
FT2_DEBUG environment variable, described later.
|
||||
|
||||
When FT_TRACE is called, its level is compared to the one of the
|
||||
corresponding component. Messages with trace levels *higher* than
|
||||
the corresponding component level are filtered and never printed.
|
||||
|
||||
This means that trace messages with level 0 are always printed,
|
||||
those with level 2 are only printed when the component level is *at
|
||||
least* 2.
|
||||
|
||||
The second parameter to FT_TRACE must contain parentheses and
|
||||
correspond to a print-like call, as in:
|
||||
|
||||
FT_TRACE( 2, ( "your %s is not %s\n", "foo", "bar" ) )
|
||||
|
||||
The shortcut macros FT_TRACE0, FT_TRACE1, FT_TRACE2_, ... FT_TRACE6
|
||||
can be used with constant level indices, and are much cleaner to
|
||||
use, as in
|
||||
|
||||
FT_TRACE2(( "your %s is not %s\n", "foo", "bar" ));
|
||||
|
||||
|
||||
III. Environment variables
|
||||
--------------------------
|
||||
|
||||
The following environment variables control debugging output and
|
||||
behaviour of FreeType at runtime:
|
||||
|
||||
|
||||
FT2_DEBUG
|
||||
|
||||
This variable is only used when FreeType is built with
|
||||
FT_DEBUG_LEVEL_TRACE defined. It contains a list of component level
|
||||
definitions, following this format:
|
||||
|
||||
component1:level1 component2:level2 component3:level3 ...
|
||||
|
||||
where "componentX" is the name of a tracing component, as defined in
|
||||
"fttrace.h", but without the "trace_" prefix, and "levelX" is the
|
||||
corresponding level to use at runtime.
|
||||
|
||||
"any" is a special component name that will be interpreted as
|
||||
"any/all components". For example, the following definitions
|
||||
|
||||
set FT2_DEBUG=any:2 memory:5 io:4 (on Windows)
|
||||
export FT2_DEBUG="any:2 memory:5 io:4" (on Linux)
|
||||
|
||||
both stipulate that all components should have level 2, except for
|
||||
the memory and io components which will be set to trace levels 5 and
|
||||
4 respectively.
|
||||
|
||||
FT2_DEBUG_MEMORY
|
||||
|
||||
This environment variable, when defined, tells FreeType to use a
|
||||
debugging memory manager that will track leaked memory blocks as
|
||||
well as other common errors like double frees. It is also capable
|
||||
of reporting _where_ the leaked blocks were allocated, which
|
||||
considerably saves time when debugging new additions to the library.
|
||||
|
||||
This code is only compiled when FreeType is built with the
|
||||
FT_DEBUG_MEMORY macro #defined in "ftoption.h" though, it will be
|
||||
ignored in other builds.
|
||||
|
||||
|
||||
End of file
|
||||
@@ -0,0 +1,7 @@
|
||||
Libtool's version for FreeType 2.1.3 is `9.2.3'.
|
||||
|
||||
On most platforms, the soname will be `6.3.2' (e.g. `libfreetype.so.6.3.2').
|
||||
|
||||
Libtool's version for FreeType 2.1.2 is `9.1.3'.
|
||||
|
||||
On most platforms, the soname will be `6.3.1' (e.g. `libfreetype.so.6.3.1').
|
||||
@@ -0,0 +1,105 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* ftpfr.c */
|
||||
/* */
|
||||
/* FreeType API for accessing PFR-specific data */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_INTERNAL_PFR_H
|
||||
#include FT_INTERNAL_OBJECTS_H
|
||||
|
||||
|
||||
/* check the format */
|
||||
static FT_Error
|
||||
ft_pfr_check( FT_Face face,
|
||||
FT_PFR_Service *aservice )
|
||||
{
|
||||
FT_Error error = FT_Err_Bad_Argument;
|
||||
|
||||
if ( face && face->driver )
|
||||
{
|
||||
FT_Module module = (FT_Module) face->driver;
|
||||
const char* name = module->clazz->module_name;
|
||||
|
||||
if ( name[0] == 'p' &&
|
||||
name[1] == 'f' &&
|
||||
name[2] == 'r' &&
|
||||
name[4] == 0 )
|
||||
{
|
||||
*aservice = (FT_PFR_Service) module->clazz->module_interface;
|
||||
error = 0;
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_Get_PFR_Metrics( FT_Face face,
|
||||
FT_UInt *aoutline_resolution,
|
||||
FT_UInt *ametrics_resolution,
|
||||
FT_Fixed *ametrics_x_scale,
|
||||
FT_Fixed *ametrics_y_scale )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_PFR_Service service;
|
||||
|
||||
error = ft_pfr_check( face, &service );
|
||||
if ( !error )
|
||||
{
|
||||
error = service->get_metrics( face,
|
||||
aoutline_resolution,
|
||||
ametrics_resolution,
|
||||
ametrics_x_scale,
|
||||
ametrics_y_scale );
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_Get_PFR_Kerning( FT_Face face,
|
||||
FT_UInt left,
|
||||
FT_UInt right,
|
||||
FT_Vector *avector )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_PFR_Service service;
|
||||
|
||||
error = ft_pfr_check( face, &service );
|
||||
if ( !error )
|
||||
{
|
||||
error = service->get_kerning( face, left, right, avector );
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_Get_PFR_Advance( FT_Face face,
|
||||
FT_UInt gindex,
|
||||
FT_Pos *aadvance )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_PFR_Service service;
|
||||
|
||||
error = ft_pfr_check( face, &service );
|
||||
if ( !error )
|
||||
{
|
||||
error = service->get_advance( face, gindex, aadvance );
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/* END */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,326 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* cffcmap.c */
|
||||
/* */
|
||||
/* CFF character mapping table (cmap) support (body). */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#include "cffcmap.h"
|
||||
#include "cffload.h"
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
FT_CALLBACK_DEF( FT_Error )
|
||||
cff_cmap_encoding_init( CFF_CMapStd cmap )
|
||||
{
|
||||
TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
|
||||
CFF_Font cff = (CFF_Font)face->extra.data;
|
||||
CFF_Encoding encoding = &cff->encoding;
|
||||
|
||||
|
||||
cmap->count = encoding->count;
|
||||
cmap->gids = encoding->codes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( void )
|
||||
cff_cmap_encoding_done( CFF_CMapStd cmap )
|
||||
{
|
||||
cmap->count = 0;
|
||||
cmap->gids = NULL;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( FT_UInt )
|
||||
cff_cmap_encoding_char_index( CFF_CMapStd cmap,
|
||||
FT_UInt32 char_code )
|
||||
{
|
||||
FT_UInt result = 0;
|
||||
|
||||
|
||||
if ( char_code < cmap->count )
|
||||
result = cmap->gids[char_code];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( FT_UInt )
|
||||
cff_cmap_encoding_char_next( CFF_CMapStd cmap,
|
||||
FT_UInt32 *pchar_code )
|
||||
{
|
||||
FT_UInt result = 0;
|
||||
FT_UInt32 char_code = *pchar_code;
|
||||
|
||||
|
||||
*pchar_code = 0;
|
||||
|
||||
if ( char_code < cmap->count )
|
||||
{
|
||||
FT_UInt code = (FT_UInt)(char_code + 1);
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if ( code >= cmap->count )
|
||||
break;
|
||||
|
||||
result = cmap->gids[code];
|
||||
if ( result != 0 )
|
||||
{
|
||||
*pchar_code = code;
|
||||
break;
|
||||
}
|
||||
|
||||
code++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
||||
cff_cmap_encoding_class_rec =
|
||||
{
|
||||
sizeof ( CFF_CMapStdRec ),
|
||||
|
||||
(FT_CMap_InitFunc) cff_cmap_encoding_init,
|
||||
(FT_CMap_DoneFunc) cff_cmap_encoding_done,
|
||||
(FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
|
||||
(FT_CMap_CharNextFunc) cff_cmap_encoding_char_next
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
FT_CALLBACK_DEF( FT_Int )
|
||||
cff_cmap_uni_pair_compare( const void* pair1,
|
||||
const void* pair2 )
|
||||
{
|
||||
FT_UInt32 u1 = ((CFF_CMapUniPair)pair1)->unicode;
|
||||
FT_UInt32 u2 = ((CFF_CMapUniPair)pair2)->unicode;
|
||||
|
||||
|
||||
if ( u1 < u2 )
|
||||
return -1;
|
||||
|
||||
if ( u1 > u2 )
|
||||
return +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( FT_Error )
|
||||
cff_cmap_unicode_init( CFF_CMapUnicode cmap )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_UInt count;
|
||||
TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
|
||||
FT_Memory memory = FT_FACE_MEMORY( face );
|
||||
CFF_Font cff = (CFF_Font)face->extra.data;
|
||||
CFF_Charset charset = &cff->charset;
|
||||
PSNames_Service psnames = (PSNames_Service)cff->psnames;
|
||||
|
||||
|
||||
cmap->num_pairs = 0;
|
||||
cmap->pairs = NULL;
|
||||
|
||||
count = (FT_UInt)face->root.num_glyphs;
|
||||
|
||||
if ( !FT_NEW_ARRAY( cmap->pairs, count ) )
|
||||
{
|
||||
FT_UInt n, new_count;
|
||||
CFF_CMapUniPair pair;
|
||||
FT_UInt32 uni_code;
|
||||
|
||||
|
||||
pair = cmap->pairs;
|
||||
for ( n = 0; n < count; n++ )
|
||||
{
|
||||
FT_UInt sid = charset->sids[n];
|
||||
const char* gname;
|
||||
|
||||
|
||||
gname = cff_index_get_sid_string( &cff->string_index, sid, psnames );
|
||||
|
||||
/* build unsorted pair table by matching glyph names */
|
||||
if ( gname )
|
||||
{
|
||||
uni_code = psnames->unicode_value( gname );
|
||||
|
||||
if ( uni_code != 0 )
|
||||
{
|
||||
pair->unicode = uni_code;
|
||||
pair->gindex = n;
|
||||
pair++;
|
||||
}
|
||||
|
||||
FT_FREE( gname );
|
||||
}
|
||||
}
|
||||
|
||||
new_count = (FT_UInt)( pair - cmap->pairs );
|
||||
if ( new_count == 0 )
|
||||
{
|
||||
/* there are no unicode characters in here! */
|
||||
FT_FREE( cmap->pairs );
|
||||
error = FT_Err_Invalid_Argument;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* re-allocate if the new array is much smaller than the original */
|
||||
/* one */
|
||||
if ( new_count != count && new_count < count / 2 )
|
||||
{
|
||||
(void)FT_RENEW_ARRAY( cmap->pairs, count, new_count );
|
||||
error = 0;
|
||||
}
|
||||
|
||||
/* sort the pairs table to allow efficient binary searches */
|
||||
ft_qsort( cmap->pairs,
|
||||
new_count,
|
||||
sizeof ( CFF_CMapUniPairRec ),
|
||||
cff_cmap_uni_pair_compare );
|
||||
|
||||
cmap->num_pairs = new_count;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( void )
|
||||
cff_cmap_unicode_done( CFF_CMapUnicode cmap )
|
||||
{
|
||||
FT_Face face = FT_CMAP_FACE( cmap );
|
||||
FT_Memory memory = FT_FACE_MEMORY( face );
|
||||
|
||||
|
||||
FT_FREE( cmap->pairs );
|
||||
cmap->num_pairs = 0;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( FT_UInt )
|
||||
cff_cmap_unicode_char_index( CFF_CMapUnicode cmap,
|
||||
FT_UInt32 char_code )
|
||||
{
|
||||
FT_UInt min = 0;
|
||||
FT_UInt max = cmap->num_pairs;
|
||||
FT_UInt mid;
|
||||
CFF_CMapUniPair pair;
|
||||
|
||||
|
||||
while ( min < max )
|
||||
{
|
||||
mid = min + ( max - min ) / 2;
|
||||
pair = cmap->pairs + mid;
|
||||
|
||||
if ( pair->unicode == char_code )
|
||||
return pair->gindex;
|
||||
|
||||
if ( pair->unicode < char_code )
|
||||
min = mid + 1;
|
||||
else
|
||||
max = mid;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_DEF( FT_UInt )
|
||||
cff_cmap_unicode_char_next( CFF_CMapUnicode cmap,
|
||||
FT_UInt32 *pchar_code )
|
||||
{
|
||||
FT_UInt result = 0;
|
||||
FT_UInt32 char_code = *pchar_code + 1;
|
||||
|
||||
|
||||
Restart:
|
||||
{
|
||||
FT_UInt min = 0;
|
||||
FT_UInt max = cmap->num_pairs;
|
||||
FT_UInt mid;
|
||||
CFF_CMapUniPair pair;
|
||||
|
||||
|
||||
while ( min < max )
|
||||
{
|
||||
mid = min + ( ( max - min ) >> 1 );
|
||||
pair = cmap->pairs + mid;
|
||||
|
||||
if ( pair->unicode == char_code )
|
||||
{
|
||||
result = pair->gindex;
|
||||
if ( result != 0 )
|
||||
goto Exit;
|
||||
|
||||
char_code++;
|
||||
goto Restart;
|
||||
}
|
||||
|
||||
if ( pair->unicode < char_code )
|
||||
min = mid+1;
|
||||
else
|
||||
max = mid;
|
||||
}
|
||||
|
||||
/* we didn't find it, but we have a pair just above it */
|
||||
char_code = 0;
|
||||
|
||||
if ( min < cmap->num_pairs )
|
||||
{
|
||||
pair = cmap->pairs + min;
|
||||
result = pair->gindex;
|
||||
if ( result != 0 )
|
||||
char_code = pair->unicode;
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
*pchar_code = char_code;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
||||
cff_cmap_unicode_class_rec =
|
||||
{
|
||||
sizeof ( CFF_CMapUnicodeRec ),
|
||||
|
||||
(FT_CMap_InitFunc) cff_cmap_unicode_init,
|
||||
(FT_CMap_DoneFunc) cff_cmap_unicode_done,
|
||||
(FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
|
||||
(FT_CMap_CharNextFunc) cff_cmap_unicode_char_next
|
||||
};
|
||||
|
||||
|
||||
/* END */
|
||||
@@ -0,0 +1,88 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* cffcmap.h */
|
||||
/* */
|
||||
/* CFF character mapping table (cmap) support (specification). */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __CFFCMAP_H__
|
||||
#define __CFFCMAP_H__
|
||||
|
||||
#include "cffobjs.h"
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* standard (and expert) encoding cmaps */
|
||||
typedef struct CFF_CMapStdRec_* CFF_CMapStd;
|
||||
|
||||
typedef struct CFF_CMapStdRec_
|
||||
{
|
||||
FT_CMapRec cmap;
|
||||
FT_UInt count;
|
||||
FT_UShort* gids; /* up to 256 elements */
|
||||
|
||||
} CFF_CMapStdRec;
|
||||
|
||||
|
||||
FT_CALLBACK_TABLE const FT_CMap_ClassRec
|
||||
cff_cmap_encoding_class_rec;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* unicode (synthetic) cmaps */
|
||||
typedef struct CFF_CMapUnicodeRec_* CFF_CMapUnicode;
|
||||
|
||||
typedef struct CFF_CMapUniPairRec_
|
||||
{
|
||||
FT_UInt32 unicode;
|
||||
FT_UInt gindex;
|
||||
|
||||
} CFF_CMapUniPairRec, *CFF_CMapUniPair;
|
||||
|
||||
|
||||
typedef struct CFF_CMapUnicodeRec_
|
||||
{
|
||||
FT_CMapRec cmap;
|
||||
FT_UInt num_pairs;
|
||||
CFF_CMapUniPair pairs;
|
||||
|
||||
} CFF_CMapUnicodeRec;
|
||||
|
||||
|
||||
FT_CALLBACK_TABLE const FT_CMap_ClassRec
|
||||
cff_cmap_unicode_class_rec;
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* __CFFCMAP_H__ */
|
||||
|
||||
|
||||
/* END */
|
||||
@@ -0,0 +1,8 @@
|
||||
# FreeType 2 src/gzip Jamfile (c) 2001 David Turner
|
||||
#
|
||||
|
||||
SubDir FT2_TOP $(FT2_SRC_DIR) gzip ;
|
||||
|
||||
Library $(FT2_LIB) : ftgzip.c ;
|
||||
|
||||
# end of src/pcf Jamfile
|
||||
@@ -0,0 +1,48 @@
|
||||
/* adler32.c -- compute the Adler-32 checksum of a data stream
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: adler32.c,v 1.1 2002/11/20 19:19:09 bonefish Exp $ */
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#define BASE 65521L /* largest prime smaller than 65536 */
|
||||
#define NMAX 5552
|
||||
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
|
||||
|
||||
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
|
||||
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||
|
||||
/* ========================================================================= */
|
||||
ZEXTERNDEF uLong ZEXPORT adler32(adler, buf, len)
|
||||
uLong adler;
|
||||
const Bytef *buf;
|
||||
uInt len;
|
||||
{
|
||||
unsigned long s1 = adler & 0xffff;
|
||||
unsigned long s2 = (adler >> 16) & 0xffff;
|
||||
int k;
|
||||
|
||||
if (buf == Z_NULL) return 1L;
|
||||
|
||||
while (len > 0) {
|
||||
k = len < NMAX ? len : NMAX;
|
||||
len -= k;
|
||||
while (k >= 16) {
|
||||
DO16(buf);
|
||||
buf += 16;
|
||||
k -= 16;
|
||||
}
|
||||
if (k != 0) do {
|
||||
s1 += *buf++;
|
||||
s2 += s1;
|
||||
} while (--k);
|
||||
s1 %= BASE;
|
||||
s2 %= BASE;
|
||||
}
|
||||
return (s2 << 16) | s1;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# FreeType 2 GZip support compilation rules for VMS
|
||||
#
|
||||
|
||||
|
||||
# Copyright 2002 by
|
||||
# David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
#
|
||||
# This file is part of the FreeType project, and may only be used, modified,
|
||||
# and distributed under the terms of the FreeType project license,
|
||||
# LICENSE.TXT. By continuing to use, modify, or distribute this file you
|
||||
# indicate that you have read the license and understand and accept it
|
||||
# fully.
|
||||
|
||||
|
||||
CFLAGS=$(COMP_FLAGS)$(DEBUG)/include=([--.include],[--.src.gzip])
|
||||
|
||||
OBJS=ftgzip.obj
|
||||
|
||||
all : $(OBJS)
|
||||
library [--.lib]freetype.olb $(OBJS)
|
||||
|
||||
# EOF
|
||||
@@ -0,0 +1,561 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* ftgzip.c */
|
||||
/* */
|
||||
/* FreeType support for .gz compressed fileds */
|
||||
/* */
|
||||
/* this optional component relies on zlib. It should mainly be used to */
|
||||
/* parse compressed PCF fonts, as found with many X11 server */
|
||||
/* distributions. */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_INTERNAL_MEMORY_H
|
||||
#include FT_INTERNAL_STREAM_H
|
||||
#include FT_INTERNAL_DEBUG_H
|
||||
#include <string.h>
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_USE_ZLIB
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_SYSTEM_ZLIB
|
||||
|
||||
# include "zlib.h"
|
||||
|
||||
#else /* !SYSTEM_ZLIB */
|
||||
|
||||
/* in this case, we include our own modified sources of the ZLib */
|
||||
/* within the "ftgzip" component. The modifications were necessary */
|
||||
/* to #include all files without conflicts, as well as preventing */
|
||||
/* the definition of "extern" functions that may cause linking */
|
||||
/* conflicts when a program is linked with both FreeType and the */
|
||||
/* original ZLib */
|
||||
|
||||
# define NO_DUMMY_DECL
|
||||
# define BUILDFIXED /* save code size */
|
||||
# define MY_ZCALLOC
|
||||
|
||||
# include "zlib.h"
|
||||
|
||||
# undef SLOW
|
||||
# define SLOW 1 /* we can't use asm-optimized sources here !! */
|
||||
|
||||
# include "zutil.c"
|
||||
# include "inftrees.c"
|
||||
# include "infcodes.c"
|
||||
# include "infutil.c"
|
||||
# include "infblock.c"
|
||||
# include "inflate.c"
|
||||
# include "adler32.c"
|
||||
|
||||
#endif /* !SYSTEM_ZLIB */
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***** *****/
|
||||
/***** Z L I B M E M O R Y M A N A G E M E N T *****/
|
||||
/***** *****/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
/* it's better to use FreeType memory routines instead of raw 'malloc/free' */
|
||||
|
||||
|
||||
static voidpf
|
||||
ft_gzip_alloc( FT_Memory memory,
|
||||
uInt items,
|
||||
uInt size )
|
||||
{
|
||||
FT_ULong sz = (FT_ULong)size * items;
|
||||
FT_Pointer p;
|
||||
|
||||
FT_MEM_ALLOC( p, sz );
|
||||
|
||||
return (voidpf) p;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ft_gzip_free( FT_Memory memory,
|
||||
voidpf address )
|
||||
{
|
||||
FT_MEM_FREE( address );
|
||||
}
|
||||
|
||||
|
||||
#ifndef FT_CONFIG_OPTION_SYSTEM_ZLIB
|
||||
|
||||
local voidpf
|
||||
zcalloc (opaque, items, size)
|
||||
voidpf opaque;
|
||||
unsigned items;
|
||||
unsigned size;
|
||||
{
|
||||
return ft_gzip_alloc( opaque, items, size );
|
||||
}
|
||||
|
||||
local void
|
||||
zcfree( voidpf opaque,
|
||||
voidpf ptr )
|
||||
{
|
||||
ft_gzip_free( opaque, ptr );
|
||||
}
|
||||
|
||||
#endif /* !SYSTEM_ZLIB */
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***** *****/
|
||||
/***** Z L I B F I L E D E S C R I P T O R *****/
|
||||
/***** *****/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
#define FT_GZIP_BUFFER_SIZE 4096
|
||||
|
||||
typedef struct FT_GZipFileRec_
|
||||
{
|
||||
FT_Stream source; /* parent/source stream */
|
||||
FT_Stream stream; /* embedding stream */
|
||||
FT_Memory memory; /* memory allocator */
|
||||
z_stream zstream; /* zlib input stream */
|
||||
|
||||
FT_ULong start; /* starting position, after .gz header */
|
||||
FT_Byte input[ FT_GZIP_BUFFER_SIZE ]; /* input read buffer */
|
||||
|
||||
FT_Byte buffer[ FT_GZIP_BUFFER_SIZE ]; /* output buffer */
|
||||
FT_ULong pos; /* position in output */
|
||||
FT_Byte* cursor;
|
||||
FT_Byte* limit;
|
||||
|
||||
} FT_GZipFileRec, *FT_GZipFile;
|
||||
|
||||
|
||||
/* gzip flag byte */
|
||||
#define FT_GZIP_ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
|
||||
#define FT_GZIP_HEAD_CRC 0x02 /* bit 1 set: header CRC present */
|
||||
#define FT_GZIP_EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
|
||||
#define FT_GZIP_ORIG_NAME 0x08 /* bit 3 set: original file name present */
|
||||
#define FT_GZIP_COMMENT 0x10 /* bit 4 set: file comment present */
|
||||
#define FT_GZIP_RESERVED 0xE0 /* bits 5..7: reserved */
|
||||
|
||||
|
||||
/* check and skip .gz header - we don't support "transparent" compression */
|
||||
static FT_Error
|
||||
ft_gzip_check_header( FT_Stream stream )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Byte head[4];
|
||||
|
||||
if ( FT_STREAM_SEEK( 0 ) ||
|
||||
FT_STREAM_READ( head, 4 ) )
|
||||
goto Exit;
|
||||
|
||||
/* head[0] && head[1] are the magic numbers */
|
||||
/* head[2] is the method, and head[3] the flags */
|
||||
if ( head[0] != 0x1f ||
|
||||
head[1] != 0x8b ||
|
||||
head[2] != Z_DEFLATED ||
|
||||
(head[3] & FT_GZIP_RESERVED) )
|
||||
{
|
||||
error = FT_Err_Invalid_File_Format;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* skip time, xflags and os code */
|
||||
(void)FT_STREAM_SKIP( 6 );
|
||||
|
||||
/* skip the extra field */
|
||||
if ( head[3] && FT_GZIP_EXTRA_FIELD )
|
||||
{
|
||||
FT_UInt len;
|
||||
|
||||
if ( FT_READ_USHORT_LE( len ) ||
|
||||
FT_STREAM_SKIP( len ) )
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* skip original file name */
|
||||
if ( head[3] && FT_GZIP_ORIG_NAME )
|
||||
for (;;)
|
||||
{
|
||||
FT_UInt c;
|
||||
|
||||
if ( FT_READ_BYTE( c) )
|
||||
goto Exit;
|
||||
|
||||
if ( c == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip .gz comment */
|
||||
if ( head[3] & FT_GZIP_COMMENT )
|
||||
for (;;)
|
||||
{
|
||||
FT_UInt c;
|
||||
|
||||
if ( FT_READ_BYTE( c) )
|
||||
goto Exit;
|
||||
|
||||
if ( c == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip CRC */
|
||||
if ( head[3] & FT_GZIP_HEAD_CRC )
|
||||
if ( FT_STREAM_SKIP( 2 ) )
|
||||
goto Exit;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static FT_Error
|
||||
ft_gzip_file_init( FT_GZipFile zip,
|
||||
FT_Stream stream,
|
||||
FT_Stream source )
|
||||
{
|
||||
z_stream* zstream = &zip->zstream;
|
||||
FT_Error error = 0;
|
||||
|
||||
zip->stream = stream;
|
||||
zip->source = source;
|
||||
zip->memory = stream->memory;
|
||||
|
||||
zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
|
||||
zip->cursor = zip->limit;
|
||||
zip->pos = 0;
|
||||
|
||||
/* check and skip .gz header */
|
||||
{
|
||||
stream = source;
|
||||
|
||||
error = ft_gzip_check_header( stream );
|
||||
if (error)
|
||||
goto Exit;
|
||||
|
||||
zip->start = FT_STREAM_POS();
|
||||
}
|
||||
|
||||
/* initialize zlib - there is no zlib header in the compressed stream */
|
||||
zstream->zalloc = (alloc_func) ft_gzip_alloc;
|
||||
zstream->zfree = (free_func) ft_gzip_free;
|
||||
zstream->opaque = stream->memory;
|
||||
|
||||
zstream->avail_in = 0;
|
||||
zstream->next_in = zip->buffer;
|
||||
|
||||
if ( inflateInit2( zstream, -MAX_WBITS ) != Z_OK ||
|
||||
zstream->next_in == NULL )
|
||||
{
|
||||
error = FT_Err_Invalid_File_Format;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
ft_gzip_file_done( FT_GZipFile zip )
|
||||
{
|
||||
z_stream* zstream = &zip->zstream;
|
||||
|
||||
/* clear the rest */
|
||||
zstream->zalloc = NULL;
|
||||
zstream->zfree = NULL;
|
||||
zstream->opaque = NULL;
|
||||
zstream->next_in = NULL;
|
||||
zstream->next_out = NULL;
|
||||
zstream->avail_in = 0;
|
||||
zstream->avail_out = 0;
|
||||
|
||||
zip->memory = NULL;
|
||||
zip->source = NULL;
|
||||
zip->stream = NULL;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
ft_gzip_file_reset( FT_GZipFile zip )
|
||||
{
|
||||
FT_Stream stream = zip->source;
|
||||
FT_Error error;
|
||||
|
||||
if ( !FT_STREAM_SEEK( zip->start ) )
|
||||
{
|
||||
z_stream* zstream = &zip->zstream;
|
||||
|
||||
inflateReset( zstream );
|
||||
|
||||
zstream->avail_in = 0;
|
||||
zstream->next_in = zip->input;
|
||||
zstream->avail_out = 0;
|
||||
zstream->next_out = zip->buffer;
|
||||
|
||||
zip->limit = zip->buffer + FT_GZIP_BUFFER_SIZE;
|
||||
zip->cursor = zip->limit;
|
||||
zip->pos = 0;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
ft_gzip_file_fill_input( FT_GZipFile zip )
|
||||
{
|
||||
z_stream* zstream = &zip->zstream;
|
||||
FT_Stream stream = zip->source;
|
||||
FT_ULong size;
|
||||
|
||||
if ( stream->read )
|
||||
{
|
||||
size = stream->read( stream, stream->pos, zip->input, FT_GZIP_BUFFER_SIZE );
|
||||
if ( size == 0 )
|
||||
return FT_Err_Invalid_Stream_Operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = stream->size - stream->pos;
|
||||
if ( size > FT_GZIP_BUFFER_SIZE )
|
||||
size = FT_GZIP_BUFFER_SIZE;
|
||||
|
||||
if ( size == 0 )
|
||||
return FT_Err_Invalid_Stream_Operation;
|
||||
|
||||
FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
|
||||
}
|
||||
stream->pos += size;
|
||||
|
||||
zstream->next_in = zip->input;
|
||||
zstream->avail_in = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static FT_Error
|
||||
ft_gzip_file_fill_output( FT_GZipFile zip )
|
||||
{
|
||||
z_stream* zstream = &zip->zstream;
|
||||
FT_Error error = 0;
|
||||
|
||||
zip->cursor = zip->buffer;
|
||||
zstream->next_out = zip->cursor;
|
||||
zstream->avail_out = FT_GZIP_BUFFER_SIZE;
|
||||
|
||||
while ( zstream->avail_out > 0 )
|
||||
{
|
||||
int err;
|
||||
|
||||
if ( zstream->avail_in == 0 )
|
||||
{
|
||||
error = ft_gzip_file_fill_input( zip );
|
||||
if ( error )
|
||||
break;
|
||||
}
|
||||
|
||||
err = inflate( zstream, Z_NO_FLUSH );
|
||||
|
||||
if ( err == Z_STREAM_END )
|
||||
{
|
||||
zip->limit = zstream->next_out;
|
||||
break;
|
||||
}
|
||||
else if ( err != Z_OK )
|
||||
{
|
||||
error = FT_Err_Invalid_Stream_Operation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* fill output buffer, 'count' must be <= FT_GZIP_BUFFER_SIZE */
|
||||
static FT_Error
|
||||
ft_gzip_file_skip_output( FT_GZipFile zip,
|
||||
FT_ULong count )
|
||||
{
|
||||
FT_Error error = 0;
|
||||
FT_ULong delta;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
delta = (FT_ULong)( zip->limit - zip->cursor );
|
||||
if ( delta >= count )
|
||||
delta = count;
|
||||
|
||||
zip->cursor += delta;
|
||||
zip->pos += delta;
|
||||
|
||||
count -= delta;
|
||||
if ( count == 0 )
|
||||
break;
|
||||
|
||||
error = ft_gzip_file_fill_output( zip );
|
||||
if ( error )
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_ULong
|
||||
ft_gzip_file_io( FT_GZipFile zip,
|
||||
FT_ULong pos,
|
||||
FT_Byte* buffer,
|
||||
FT_ULong count )
|
||||
{
|
||||
FT_ULong result = 0;
|
||||
FT_Error error;
|
||||
|
||||
/* reset inflate stream if we're seeking backwards */
|
||||
/* yes, that's not too efficient, but it saves memory :-) */
|
||||
if ( pos < zip->pos )
|
||||
{
|
||||
error = ft_gzip_file_reset( zip );
|
||||
if ( error ) goto Exit;
|
||||
}
|
||||
|
||||
/* skip unwanted bytes */
|
||||
if ( pos > zip->pos )
|
||||
{
|
||||
error = ft_gzip_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) );
|
||||
if (error)
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if ( count == 0 )
|
||||
goto Exit;
|
||||
|
||||
/* now read the data */
|
||||
for (;;)
|
||||
{
|
||||
FT_ULong delta;
|
||||
|
||||
delta = (FT_ULong)( zip->limit - zip->cursor );
|
||||
if ( delta >= count )
|
||||
delta = count;
|
||||
|
||||
FT_MEM_COPY( buffer, zip->cursor, delta );
|
||||
buffer += delta;
|
||||
result += delta;
|
||||
zip->cursor += delta;
|
||||
zip->pos += delta;
|
||||
|
||||
count -= delta;
|
||||
if ( count == 0 )
|
||||
break;
|
||||
|
||||
error = ft_gzip_file_fill_output( zip );
|
||||
if (error)
|
||||
break;
|
||||
}
|
||||
|
||||
Exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***** *****/
|
||||
/***** G Z E M B E D D I N G S T R E A M *****/
|
||||
/***** *****/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
static void
|
||||
ft_gzip_stream_close( FT_Stream stream )
|
||||
{
|
||||
FT_GZipFile zip = stream->descriptor.pointer;
|
||||
FT_Memory memory = stream->memory;
|
||||
|
||||
if ( zip )
|
||||
{
|
||||
/* finalize gzip file descriptor */
|
||||
ft_gzip_file_done( zip );
|
||||
|
||||
FT_FREE( zip );
|
||||
|
||||
stream->descriptor.pointer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static FT_ULong
|
||||
ft_gzip_stream_io( FT_Stream stream,
|
||||
FT_ULong pos,
|
||||
FT_Byte* buffer,
|
||||
FT_ULong count )
|
||||
{
|
||||
FT_GZipFile zip = stream->descriptor.pointer;
|
||||
|
||||
return ft_gzip_file_io( zip, pos, buffer, count );
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_Stream_OpenGzip( FT_Stream stream,
|
||||
FT_Stream source )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Memory memory = source->memory;
|
||||
FT_GZipFile zip;
|
||||
|
||||
FT_ZERO( stream );
|
||||
stream->memory = memory;
|
||||
|
||||
if ( !FT_NEW( zip ) )
|
||||
{
|
||||
error = ft_gzip_file_init( zip, stream, source );
|
||||
if ( error )
|
||||
{
|
||||
FT_FREE( zip );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
stream->descriptor.pointer = zip;
|
||||
}
|
||||
|
||||
stream->size = 0x7FFFFFFF; /* don't know the real size !! */
|
||||
stream->pos = 0;
|
||||
stream->base = 0;
|
||||
stream->read = ft_gzip_stream_io;
|
||||
stream->close = ft_gzip_stream_close;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#else /* !FT_CONFIG_OPTION_USE_ZLIB */
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_Stream_OpenGzip( FT_Stream stream,
|
||||
FT_Stream source )
|
||||
{
|
||||
FT_UNUSED( stream );
|
||||
FT_UNUSED( source );
|
||||
|
||||
return FT_Err_Unimplemented_Feature;
|
||||
}
|
||||
|
||||
#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
|
||||
@@ -0,0 +1,383 @@
|
||||
/* infblock.c -- interpret and process block types to last block
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
#include "inftrees.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
/* Table for deflate from PKZIP's appnote.txt. */
|
||||
local const uInt border[] = { /* Order of the bit length code lengths */
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
/*
|
||||
Notes beyond the 1.93a appnote.txt:
|
||||
|
||||
1. Distance pointers never point before the beginning of the output
|
||||
stream.
|
||||
2. Distance pointers can point back across blocks, up to 32k away.
|
||||
3. There is an implied maximum of 7 bits for the bit length table and
|
||||
15 bits for the actual data.
|
||||
4. If only one code exists, then it is encoded using one bit. (Zero
|
||||
would be more efficient, but perhaps a little confusing.) If two
|
||||
codes exist, they are coded using one bit each (0 and 1).
|
||||
5. There is no way of sending zero distance codes--a dummy must be
|
||||
sent if there are none. (History: a pre 2.0 version of PKZIP would
|
||||
store blocks with no distance codes, but this was discovered to be
|
||||
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
|
||||
zero distance codes, which is sent as one code of zero bits in
|
||||
length.
|
||||
6. There are up to 286 literal/length codes. Code 256 represents the
|
||||
end-of-block. Note however that the static length tree defines
|
||||
288 codes just to fill out the Huffman codes. Codes 286 and 287
|
||||
cannot be used though, since there is no length base or extra bits
|
||||
defined for them. Similarily, there are up to 30 distance codes.
|
||||
However, static trees define 32 codes (all 5 bits) to fill out the
|
||||
Huffman codes, but the last two had better not show up in the data.
|
||||
7. Unzip can check dynamic Huffman blocks for complete code sets.
|
||||
The exception is that a single code would not be complete (see #4).
|
||||
8. The five bits following the block type is really the number of
|
||||
literal codes sent minus 257.
|
||||
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
|
||||
(1+6+6). Therefore, to output three times the length, you output
|
||||
three codes (1+1+1), whereas to output four times the same length,
|
||||
you only need two codes (1+3). Hmm.
|
||||
10. In the tree reconstruction algorithm, Code = Code + Increment
|
||||
only if BitLength(i) is not zero. (Pretty obvious.)
|
||||
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
|
||||
12. Note: length code 284 can represent 227-258, but length code 285
|
||||
really is 258. The last length deserves its own, short code
|
||||
since it gets used a lot in very redundant files. The length
|
||||
258 is special since 258 - 3 (the min match length) is 255.
|
||||
13. The literal/length and distance code bit lengths are read as a
|
||||
single stream of lengths. It is possible (and advantageous) for
|
||||
a repeat code (16, 17, or 18) to go across the boundary between
|
||||
the two sets of lengths.
|
||||
*/
|
||||
|
||||
|
||||
local void inflate_blocks_reset(s, z, c)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
uLongf *c;
|
||||
{
|
||||
if (c != Z_NULL)
|
||||
*c = s->check;
|
||||
if (s->mode == BTREE || s->mode == DTREE)
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
if (s->mode == CODES)
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
s->mode = TYPE;
|
||||
s->bitk = 0;
|
||||
s->bitb = 0;
|
||||
s->read = s->write = s->window;
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
|
||||
Tracev((stderr, "inflate: blocks reset\n"));
|
||||
}
|
||||
|
||||
|
||||
local inflate_blocks_statef *inflate_blocks_new(z, c, w)
|
||||
z_streamp z;
|
||||
check_func c;
|
||||
uInt w;
|
||||
{
|
||||
inflate_blocks_statef *s;
|
||||
|
||||
if ((s = (inflate_blocks_statef *)ZALLOC
|
||||
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
|
||||
return s;
|
||||
if ((s->hufts =
|
||||
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
return Z_NULL;
|
||||
}
|
||||
s->end = s->window + w;
|
||||
s->checkfn = c;
|
||||
s->mode = TYPE;
|
||||
Tracev((stderr, "inflate: blocks allocated\n"));
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
local int inflate_blocks(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt t; /* temporary storage */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input based on current state */
|
||||
while (1) switch (s->mode)
|
||||
{
|
||||
case TYPE:
|
||||
NEEDBITS(3)
|
||||
t = (uInt)b & 7;
|
||||
s->last = t & 1;
|
||||
switch (t >> 1)
|
||||
{
|
||||
case 0: /* stored */
|
||||
Tracev((stderr, "inflate: stored block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
t = k & 7; /* go to byte boundary */
|
||||
DUMPBITS(t)
|
||||
s->mode = LENS; /* get length of stored block */
|
||||
break;
|
||||
case 1: /* fixed */
|
||||
Tracev((stderr, "inflate: fixed codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
|
||||
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
|
||||
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
|
||||
if (s->sub.decode.codes == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
}
|
||||
DUMPBITS(3)
|
||||
s->mode = CODES;
|
||||
break;
|
||||
case 2: /* dynamic */
|
||||
Tracev((stderr, "inflate: dynamic codes block%s\n",
|
||||
s->last ? " (last)" : ""));
|
||||
DUMPBITS(3)
|
||||
s->mode = TABLE;
|
||||
break;
|
||||
case 3: /* illegal */
|
||||
DUMPBITS(3)
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid block type";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
break;
|
||||
case LENS:
|
||||
NEEDBITS(32)
|
||||
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
|
||||
{
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid stored block lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.left = (uInt)b & 0xffff;
|
||||
b = k = 0; /* dump bits */
|
||||
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
|
||||
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
|
||||
break;
|
||||
case STORED:
|
||||
if (n == 0)
|
||||
LEAVE
|
||||
NEEDOUT
|
||||
t = s->sub.left;
|
||||
if (t > n) t = n;
|
||||
if (t > m) t = m;
|
||||
zmemcpy(q, p, t);
|
||||
p += t; n -= t;
|
||||
q += t; m -= t;
|
||||
if ((s->sub.left -= t) != 0)
|
||||
break;
|
||||
Tracev((stderr, "inflate: stored end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
s->mode = s->last ? DRY : TYPE;
|
||||
break;
|
||||
case TABLE:
|
||||
NEEDBITS(14)
|
||||
s->sub.trees.table = t = (uInt)b & 0x3fff;
|
||||
#ifndef PKZIP_BUG_WORKAROUND
|
||||
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
|
||||
{
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"too many length or distance symbols";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#endif
|
||||
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
||||
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
DUMPBITS(14)
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: table sizes ok\n"));
|
||||
s->mode = BTREE;
|
||||
case BTREE:
|
||||
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
|
||||
{
|
||||
NEEDBITS(3)
|
||||
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
|
||||
DUMPBITS(3)
|
||||
}
|
||||
while (s->sub.trees.index < 19)
|
||||
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
|
||||
s->sub.trees.bb = 7;
|
||||
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
|
||||
&s->sub.trees.tb, s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
r = t;
|
||||
if (r == Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
}
|
||||
LEAVE
|
||||
}
|
||||
s->sub.trees.index = 0;
|
||||
Tracev((stderr, "inflate: bits tree ok\n"));
|
||||
s->mode = DTREE;
|
||||
case DTREE:
|
||||
while (t = s->sub.trees.table,
|
||||
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
|
||||
{
|
||||
inflate_huft *h;
|
||||
uInt i, j, c;
|
||||
|
||||
t = s->sub.trees.bb;
|
||||
NEEDBITS(t)
|
||||
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
|
||||
t = h->bits;
|
||||
c = h->base;
|
||||
if (c < 16)
|
||||
{
|
||||
DUMPBITS(t)
|
||||
s->sub.trees.blens[s->sub.trees.index++] = c;
|
||||
}
|
||||
else /* c == 16..18 */
|
||||
{
|
||||
i = c == 18 ? 7 : c - 14;
|
||||
j = c == 18 ? 11 : 3;
|
||||
NEEDBITS(t + i)
|
||||
DUMPBITS(t)
|
||||
j += (uInt)b & inflate_mask[i];
|
||||
DUMPBITS(i)
|
||||
i = s->sub.trees.index;
|
||||
t = s->sub.trees.table;
|
||||
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
|
||||
(c == 16 && i < 1))
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
z->msg = (char*)"invalid bit length repeat";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
|
||||
do {
|
||||
s->sub.trees.blens[i++] = c;
|
||||
} while (--j);
|
||||
s->sub.trees.index = i;
|
||||
}
|
||||
}
|
||||
s->sub.trees.tb = Z_NULL;
|
||||
{
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl, *td;
|
||||
inflate_codes_statef *c;
|
||||
|
||||
bl = 9; /* must be <= 9 for lookahead assumptions */
|
||||
bd = 6; /* must be <= 9 for lookahead assumptions */
|
||||
t = s->sub.trees.table;
|
||||
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
|
||||
s->sub.trees.blens, &bl, &bd, &tl, &td,
|
||||
s->hufts, z);
|
||||
if (t != Z_OK)
|
||||
{
|
||||
if (t == (uInt)Z_DATA_ERROR)
|
||||
{
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = BAD;
|
||||
}
|
||||
r = t;
|
||||
LEAVE
|
||||
}
|
||||
Tracev((stderr, "inflate: trees ok\n"));
|
||||
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
|
||||
{
|
||||
r = Z_MEM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
s->sub.decode.codes = c;
|
||||
}
|
||||
ZFREE(z, s->sub.trees.blens);
|
||||
s->mode = CODES;
|
||||
case CODES:
|
||||
UPDATE
|
||||
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
|
||||
return inflate_flush(s, z, r);
|
||||
r = Z_OK;
|
||||
inflate_codes_free(s->sub.decode.codes, z);
|
||||
LOAD
|
||||
Tracev((stderr, "inflate: codes end, %lu total out\n",
|
||||
z->total_out + (q >= s->read ? q - s->read :
|
||||
(s->end - s->read) + (q - s->window))));
|
||||
if (!s->last)
|
||||
{
|
||||
s->mode = TYPE;
|
||||
break;
|
||||
}
|
||||
s->mode = DRY;
|
||||
case DRY:
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
LEAVE
|
||||
s->mode = DONE;
|
||||
case DONE:
|
||||
r = Z_STREAM_END;
|
||||
LEAVE
|
||||
case BAD:
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
local int inflate_blocks_free(s, z)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
{
|
||||
inflate_blocks_reset(s, z, Z_NULL);
|
||||
ZFREE(z, s->window);
|
||||
ZFREE(z, s->hufts);
|
||||
ZFREE(z, s);
|
||||
Tracev((stderr, "inflate: blocks freed\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* infblock.h -- header to use infblock.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
#ifndef _INFBLOCK_H
|
||||
#define _INFBLOCK_H
|
||||
|
||||
struct inflate_blocks_state;
|
||||
typedef struct inflate_blocks_state FAR inflate_blocks_statef;
|
||||
|
||||
local inflate_blocks_statef * inflate_blocks_new OF((
|
||||
z_streamp z,
|
||||
check_func c, /* check function */
|
||||
uInt w)); /* window size */
|
||||
|
||||
local int inflate_blocks OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int)); /* initial return code */
|
||||
|
||||
local void inflate_blocks_reset OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
uLongf *)); /* check value on output */
|
||||
|
||||
local int inflate_blocks_free OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp));
|
||||
|
||||
#endif /* _INFBLOCK_H */
|
||||
@@ -0,0 +1,250 @@
|
||||
/* infcodes.c -- process literals and length/distance pairs
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
#include "infblock.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
START, /* x: set up for LEN */
|
||||
LEN, /* i: get length/literal/eob next */
|
||||
LENEXT, /* i: getting length extra (have base) */
|
||||
DIST, /* i: get distance next */
|
||||
DISTEXT, /* i: getting distance extra */
|
||||
COPY, /* o: copying bytes in window, waiting for space */
|
||||
LIT, /* o: got literal, waiting for output space */
|
||||
WASH, /* o: got eob, possibly still output waiting */
|
||||
END, /* x: got eob and all data flushed */
|
||||
BADCODE} /* x: got error */
|
||||
inflate_codes_mode;
|
||||
|
||||
/* inflate codes private state */
|
||||
struct inflate_codes_state {
|
||||
|
||||
/* mode */
|
||||
inflate_codes_mode mode; /* current inflate_codes mode */
|
||||
|
||||
/* mode dependent information */
|
||||
uInt len;
|
||||
union {
|
||||
struct {
|
||||
inflate_huft *tree; /* pointer into tree */
|
||||
uInt need; /* bits needed */
|
||||
} code; /* if LEN or DIST, where in tree */
|
||||
uInt lit; /* if LIT, literal */
|
||||
struct {
|
||||
uInt get; /* bits to get for extra */
|
||||
uInt dist; /* distance back to copy from */
|
||||
} copy; /* if EXT or COPY, where and how much */
|
||||
} sub; /* submode */
|
||||
|
||||
/* mode independent information */
|
||||
Byte lbits; /* ltree bits decoded per branch */
|
||||
Byte dbits; /* dtree bits decoder per branch */
|
||||
inflate_huft *ltree; /* literal/length/eob tree */
|
||||
inflate_huft *dtree; /* distance tree */
|
||||
|
||||
};
|
||||
|
||||
|
||||
local inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
|
||||
uInt bl, bd;
|
||||
inflate_huft *tl;
|
||||
inflate_huft *td; /* need separate declaration for Borland C++ */
|
||||
z_streamp z;
|
||||
{
|
||||
inflate_codes_statef *c;
|
||||
|
||||
if ((c = (inflate_codes_statef *)
|
||||
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
|
||||
{
|
||||
c->mode = START;
|
||||
c->lbits = (Byte)bl;
|
||||
c->dbits = (Byte)bd;
|
||||
c->ltree = tl;
|
||||
c->dtree = td;
|
||||
Tracev((stderr, "inflate: codes new\n"));
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
local int inflate_codes(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt j; /* temporary storage */
|
||||
inflate_huft *t; /* temporary pointer */
|
||||
uInt e; /* extra bits or operation */
|
||||
uLong b; /* bit buffer */
|
||||
uInt k; /* bits in bit buffer */
|
||||
Bytef *p; /* input data pointer */
|
||||
uInt n; /* bytes available there */
|
||||
Bytef *q; /* output window write pointer */
|
||||
uInt m; /* bytes to end of window or read pointer */
|
||||
Bytef *f; /* pointer to copy strings from */
|
||||
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
|
||||
|
||||
/* copy input/output information to locals (UPDATE macro restores) */
|
||||
LOAD
|
||||
|
||||
/* process input and output based on current state */
|
||||
while (1) switch (c->mode)
|
||||
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
|
||||
case START: /* x: set up for LEN */
|
||||
#ifndef SLOW
|
||||
if (m >= 258 && n >= 10)
|
||||
{
|
||||
UPDATE
|
||||
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
|
||||
LOAD
|
||||
if (r != Z_OK)
|
||||
{
|
||||
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* !SLOW */
|
||||
c->sub.code.need = c->lbits;
|
||||
c->sub.code.tree = c->ltree;
|
||||
c->mode = LEN;
|
||||
case LEN: /* i: get length/literal/eob next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e == 0) /* literal */
|
||||
{
|
||||
c->sub.lit = t->base;
|
||||
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
|
||||
"inflate: literal '%c'\n" :
|
||||
"inflate: literal 0x%02x\n", t->base));
|
||||
c->mode = LIT;
|
||||
break;
|
||||
}
|
||||
if (e & 16) /* length */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->len = t->base;
|
||||
c->mode = LENEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
if (e & 32) /* end of block */
|
||||
{
|
||||
Tracevv((stderr, "inflate: end of block\n"));
|
||||
c->mode = WASH;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid literal/length code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case LENEXT: /* i: getting length extra (have base) */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->len += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
c->sub.code.need = c->dbits;
|
||||
c->sub.code.tree = c->dtree;
|
||||
Tracevv((stderr, "inflate: length %u\n", c->len));
|
||||
c->mode = DIST;
|
||||
case DIST: /* i: get distance next */
|
||||
j = c->sub.code.need;
|
||||
NEEDBITS(j)
|
||||
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
|
||||
DUMPBITS(t->bits)
|
||||
e = (uInt)(t->exop);
|
||||
if (e & 16) /* distance */
|
||||
{
|
||||
c->sub.copy.get = e & 15;
|
||||
c->sub.copy.dist = t->base;
|
||||
c->mode = DISTEXT;
|
||||
break;
|
||||
}
|
||||
if ((e & 64) == 0) /* next table */
|
||||
{
|
||||
c->sub.code.need = e;
|
||||
c->sub.code.tree = t + t->base;
|
||||
break;
|
||||
}
|
||||
c->mode = BADCODE; /* invalid code */
|
||||
z->msg = (char*)"invalid distance code";
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
case DISTEXT: /* i: getting distance extra */
|
||||
j = c->sub.copy.get;
|
||||
NEEDBITS(j)
|
||||
c->sub.copy.dist += (uInt)b & inflate_mask[j];
|
||||
DUMPBITS(j)
|
||||
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
|
||||
c->mode = COPY;
|
||||
case COPY: /* o: copying bytes in window, waiting for space */
|
||||
f = q - c->sub.copy.dist;
|
||||
while (f < s->window) /* modulo window size-"while" instead */
|
||||
f += s->end - s->window; /* of "if" handles invalid distances */
|
||||
while (c->len)
|
||||
{
|
||||
NEEDOUT
|
||||
OUTBYTE(*f++)
|
||||
if (f == s->end)
|
||||
f = s->window;
|
||||
c->len--;
|
||||
}
|
||||
c->mode = START;
|
||||
break;
|
||||
case LIT: /* o: got literal, waiting for output space */
|
||||
NEEDOUT
|
||||
OUTBYTE(c->sub.lit)
|
||||
c->mode = START;
|
||||
break;
|
||||
case WASH: /* o: got eob, possibly more output */
|
||||
if (k > 7) /* return unused byte, if any */
|
||||
{
|
||||
Assert(k < 16, "inflate_codes grabbed too many bytes")
|
||||
k -= 8;
|
||||
n++;
|
||||
p--; /* can always return one */
|
||||
}
|
||||
FLUSH
|
||||
if (s->read != s->write)
|
||||
LEAVE
|
||||
c->mode = END;
|
||||
case END:
|
||||
r = Z_STREAM_END;
|
||||
LEAVE
|
||||
case BADCODE: /* x: got error */
|
||||
r = Z_DATA_ERROR;
|
||||
LEAVE
|
||||
default:
|
||||
r = Z_STREAM_ERROR;
|
||||
LEAVE
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
local void inflate_codes_free(c, z)
|
||||
inflate_codes_statef *c;
|
||||
z_streamp z;
|
||||
{
|
||||
ZFREE(z, c);
|
||||
Tracev((stderr, "inflate: codes free\n"));
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/* infcodes.h -- header to use infcodes.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
#ifndef _INFCODES_H
|
||||
#define _INFCODES_H
|
||||
|
||||
struct inflate_codes_state;
|
||||
typedef struct inflate_codes_state FAR inflate_codes_statef;
|
||||
|
||||
local inflate_codes_statef *inflate_codes_new OF((
|
||||
uInt, uInt,
|
||||
inflate_huft *, inflate_huft *,
|
||||
z_streamp ));
|
||||
|
||||
local int inflate_codes OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int));
|
||||
|
||||
local void inflate_codes_free OF((
|
||||
inflate_codes_statef *,
|
||||
z_streamp ));
|
||||
|
||||
#endif /* _INFCODES_H */
|
||||
@@ -0,0 +1,151 @@
|
||||
/* inffixed.h -- table for decoding fixed codes
|
||||
* Generated automatically by the maketree.c program
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
local uInt fixed_bl = 9;
|
||||
local uInt fixed_bd = 5;
|
||||
local inflate_huft fixed_tl[] = {
|
||||
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
|
||||
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
|
||||
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
|
||||
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
|
||||
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
|
||||
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
|
||||
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
|
||||
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
|
||||
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
|
||||
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
|
||||
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
|
||||
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
|
||||
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
|
||||
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
|
||||
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
|
||||
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
|
||||
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
|
||||
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
|
||||
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
|
||||
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
|
||||
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
|
||||
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
|
||||
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
|
||||
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
|
||||
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
|
||||
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
|
||||
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
|
||||
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
|
||||
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
|
||||
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
|
||||
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
|
||||
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
|
||||
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
|
||||
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
|
||||
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
|
||||
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
|
||||
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
|
||||
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
|
||||
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
|
||||
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
|
||||
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
|
||||
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
|
||||
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
|
||||
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
|
||||
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
|
||||
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
|
||||
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
|
||||
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
|
||||
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
|
||||
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
|
||||
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
|
||||
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
|
||||
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
|
||||
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
|
||||
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
|
||||
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
|
||||
{{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
|
||||
{{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
|
||||
{{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
|
||||
{{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
|
||||
{{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
|
||||
{{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
|
||||
{{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
|
||||
{{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
|
||||
{{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
|
||||
{{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
|
||||
{{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
|
||||
{{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
|
||||
{{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
|
||||
{{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
|
||||
{{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
|
||||
{{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
|
||||
{{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
|
||||
{{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
|
||||
{{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
|
||||
{{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
|
||||
{{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
|
||||
{{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
|
||||
{{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
|
||||
{{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
|
||||
{{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
|
||||
{{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
|
||||
{{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
|
||||
{{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
|
||||
{{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
|
||||
{{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
|
||||
{{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
|
||||
{{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
|
||||
{{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
|
||||
{{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
|
||||
{{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
|
||||
{{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
|
||||
{{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
|
||||
{{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
|
||||
{{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
|
||||
{{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
|
||||
{{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
|
||||
{{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
|
||||
{{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
|
||||
{{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
|
||||
{{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
|
||||
{{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
|
||||
{{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
|
||||
{{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
|
||||
{{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
|
||||
{{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
|
||||
{{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
|
||||
{{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
|
||||
{{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
|
||||
{{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
|
||||
{{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
|
||||
{{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
|
||||
{{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
|
||||
{{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
|
||||
{{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
|
||||
{{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
|
||||
{{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
|
||||
{{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
|
||||
{{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
|
||||
};
|
||||
local inflate_huft fixed_td[] = {
|
||||
{{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
|
||||
{{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
|
||||
{{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
|
||||
{{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
|
||||
{{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
|
||||
{{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
|
||||
{{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
|
||||
{{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
|
||||
};
|
||||
@@ -0,0 +1,273 @@
|
||||
/* inflate.c -- zlib interface to inflate modules
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
|
||||
#define DONE INFLATE_DONE
|
||||
#define BAD INFLATE_BAD
|
||||
|
||||
typedef enum {
|
||||
METHOD, /* waiting for method byte */
|
||||
FLAG, /* waiting for flag byte */
|
||||
DICT4, /* four dictionary check bytes to go */
|
||||
DICT3, /* three dictionary check bytes to go */
|
||||
DICT2, /* two dictionary check bytes to go */
|
||||
DICT1, /* one dictionary check byte to go */
|
||||
DICT0, /* waiting for inflateSetDictionary */
|
||||
BLOCKS, /* decompressing blocks */
|
||||
CHECK4, /* four check bytes to go */
|
||||
CHECK3, /* three check bytes to go */
|
||||
CHECK2, /* two check bytes to go */
|
||||
CHECK1, /* one check byte to go */
|
||||
DONE, /* finished check, done */
|
||||
BAD} /* got an error--stay here */
|
||||
inflate_mode;
|
||||
|
||||
/* inflate private state */
|
||||
struct internal_state {
|
||||
|
||||
/* mode */
|
||||
inflate_mode mode; /* current inflate mode */
|
||||
|
||||
/* mode dependent information */
|
||||
union {
|
||||
uInt method; /* if FLAGS, method byte */
|
||||
struct {
|
||||
uLong was; /* computed check value */
|
||||
uLong need; /* stream check value */
|
||||
} check; /* if CHECK, check values to compare */
|
||||
uInt marker; /* if BAD, inflateSync's marker bytes count */
|
||||
} sub; /* submode */
|
||||
|
||||
/* mode independent information */
|
||||
int nowrap; /* flag for no wrapper */
|
||||
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
|
||||
inflate_blocks_statef
|
||||
*blocks; /* current inflate_blocks state */
|
||||
|
||||
};
|
||||
|
||||
|
||||
int ZEXPORT inflateReset(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
z->total_in = z->total_out = 0;
|
||||
z->msg = Z_NULL;
|
||||
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
|
||||
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
|
||||
Tracev((stderr, "inflate: reset\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateEnd(z)
|
||||
z_streamp z;
|
||||
{
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
if (z->state->blocks != Z_NULL)
|
||||
inflate_blocks_free(z->state->blocks, z);
|
||||
ZFREE(z, z->state);
|
||||
z->state = Z_NULL;
|
||||
Tracev((stderr, "inflate: end\n"));
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
int ZEXPORT inflateInit2_(z, w, version, stream_size)
|
||||
z_streamp z;
|
||||
int w;
|
||||
const char *version;
|
||||
int stream_size;
|
||||
{
|
||||
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
|
||||
stream_size != sizeof(z_stream))
|
||||
return Z_VERSION_ERROR;
|
||||
|
||||
/* initialize state */
|
||||
if (z == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
z->msg = Z_NULL;
|
||||
if (z->zalloc == Z_NULL)
|
||||
{
|
||||
z->zalloc = zcalloc;
|
||||
z->opaque = (voidpf)0;
|
||||
}
|
||||
if (z->zfree == Z_NULL) z->zfree = zcfree;
|
||||
if ((z->state = (struct internal_state FAR *)
|
||||
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
z->state->blocks = Z_NULL;
|
||||
|
||||
/* handle undocumented nowrap option (no zlib header or check) */
|
||||
z->state->nowrap = 0;
|
||||
if (w < 0)
|
||||
{
|
||||
w = - w;
|
||||
z->state->nowrap = 1;
|
||||
}
|
||||
|
||||
/* set window size */
|
||||
if (w < 8 || w > 15)
|
||||
{
|
||||
inflateEnd(z);
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
z->state->wbits = (uInt)w;
|
||||
|
||||
/* create inflate_blocks state */
|
||||
if ((z->state->blocks =
|
||||
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
|
||||
== Z_NULL)
|
||||
{
|
||||
inflateEnd(z);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
Tracev((stderr, "inflate: allocated\n"));
|
||||
|
||||
/* reset state */
|
||||
inflateReset(z);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#undef NEEDBYTE
|
||||
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
|
||||
|
||||
#undef NEXTBYTE
|
||||
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
|
||||
|
||||
|
||||
int ZEXPORT inflate(z, f)
|
||||
z_streamp z;
|
||||
int f;
|
||||
{
|
||||
int r;
|
||||
uInt b;
|
||||
|
||||
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
|
||||
return Z_STREAM_ERROR;
|
||||
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
||||
r = Z_BUF_ERROR;
|
||||
while (1) switch (z->state->mode)
|
||||
{
|
||||
case METHOD:
|
||||
NEEDBYTE
|
||||
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"unknown compression method";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"invalid window size";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
z->state->mode = FLAG;
|
||||
case FLAG:
|
||||
NEEDBYTE
|
||||
b = NEXTBYTE;
|
||||
if (((z->state->sub.method << 8) + b) % 31)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"incorrect header check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib header ok\n"));
|
||||
if (!(b & PRESET_DICT))
|
||||
{
|
||||
z->state->mode = BLOCKS;
|
||||
break;
|
||||
}
|
||||
z->state->mode = DICT4;
|
||||
case DICT4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = DICT3;
|
||||
case DICT3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = DICT2;
|
||||
case DICT2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = DICT1;
|
||||
case DICT1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
z->adler = z->state->sub.check.need;
|
||||
z->state->mode = DICT0;
|
||||
return Z_NEED_DICT;
|
||||
case DICT0:
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"need dictionary";
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
return Z_STREAM_ERROR;
|
||||
case BLOCKS:
|
||||
r = inflate_blocks(z->state->blocks, z, r);
|
||||
if (r == Z_DATA_ERROR)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->state->sub.marker = 0; /* can try inflateSync */
|
||||
break;
|
||||
}
|
||||
if (r == Z_OK)
|
||||
r = f;
|
||||
if (r != Z_STREAM_END)
|
||||
return r;
|
||||
r = f;
|
||||
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
|
||||
if (z->state->nowrap)
|
||||
{
|
||||
z->state->mode = DONE;
|
||||
break;
|
||||
}
|
||||
z->state->mode = CHECK4;
|
||||
case CHECK4:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
|
||||
z->state->mode = CHECK3;
|
||||
case CHECK3:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
|
||||
z->state->mode = CHECK2;
|
||||
case CHECK2:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
|
||||
z->state->mode = CHECK1;
|
||||
case CHECK1:
|
||||
NEEDBYTE
|
||||
z->state->sub.check.need += (uLong)NEXTBYTE;
|
||||
|
||||
if (z->state->sub.check.was != z->state->sub.check.need)
|
||||
{
|
||||
z->state->mode = BAD;
|
||||
z->msg = (char*)"incorrect data check";
|
||||
z->state->sub.marker = 5; /* can't try inflateSync */
|
||||
break;
|
||||
}
|
||||
Tracev((stderr, "inflate: zlib check ok\n"));
|
||||
z->state->mode = DONE;
|
||||
case DONE:
|
||||
return Z_STREAM_END;
|
||||
case BAD:
|
||||
return Z_DATA_ERROR;
|
||||
default:
|
||||
return Z_STREAM_ERROR;
|
||||
}
|
||||
#ifdef NEED_DUMMY_RETURN
|
||||
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,453 @@
|
||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "inftrees.h"
|
||||
|
||||
#if !defined(BUILDFIXED) && !defined(STDC)
|
||||
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
|
||||
#endif
|
||||
|
||||
local const char inflate_copyright[] =
|
||||
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
|
||||
/*
|
||||
If you use the zlib library in a product, an acknowledgment is welcome
|
||||
in the documentation of your product. If for some reason you cannot
|
||||
include such an acknowledgment, I would appreciate that you keep this
|
||||
copyright string in the executable of your product.
|
||||
*/
|
||||
|
||||
/* simplify the use of the inflate_huft type with some defines */
|
||||
#define exop word.what.Exop
|
||||
#define bits word.what.Bits
|
||||
|
||||
|
||||
local int huft_build OF((
|
||||
uIntf *, /* code lengths in bits */
|
||||
uInt, /* number of codes */
|
||||
uInt, /* number of "simple" codes */
|
||||
const uIntf *, /* list of base values for non-simple codes */
|
||||
const uIntf *, /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR*,/* result: starting table */
|
||||
uIntf *, /* maximum lookup bits (returns actual) */
|
||||
inflate_huft *, /* space for trees */
|
||||
uInt *, /* hufts used in space */
|
||||
uIntf * )); /* space for values */
|
||||
|
||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||
/* see note #13 above about 258 */
|
||||
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
|
||||
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||
8193, 12289, 16385, 24577};
|
||||
local const uInt cpdext[30] = { /* Extra bits for distance codes */
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
|
||||
12, 12, 13, 13};
|
||||
|
||||
/*
|
||||
Huffman code decoding is performed using a multi-level table lookup.
|
||||
The fastest way to decode is to simply build a lookup table whose
|
||||
size is determined by the longest code. However, the time it takes
|
||||
to build this table can also be a factor if the data being decoded
|
||||
is not very long. The most common codes are necessarily the
|
||||
shortest codes, so those codes dominate the decoding time, and hence
|
||||
the speed. The idea is you can have a shorter table that decodes the
|
||||
shorter, more probable codes, and then point to subsidiary tables for
|
||||
the longer codes. The time it costs to decode the longer codes is
|
||||
then traded against the time it takes to make longer tables.
|
||||
|
||||
This results of this trade are in the variables lbits and dbits
|
||||
below. lbits is the number of bits the first level table for literal/
|
||||
length codes can decode in one step, and dbits is the same thing for
|
||||
the distance codes. Subsequent tables are also less than or equal to
|
||||
those sizes. These values may be adjusted either when all of the
|
||||
codes are shorter than that, in which case the longest code length in
|
||||
bits is used, or when the shortest code is *longer* than the requested
|
||||
table size, in which case the length of the shortest code in bits is
|
||||
used.
|
||||
|
||||
There are two different values for the two tables, since they code a
|
||||
different number of possibilities each. The literal/length table
|
||||
codes 286 possible values, or in a flat code, a little over eight
|
||||
bits. The distance table codes 30 possible values, or a little less
|
||||
than five bits, flat. The optimum values for speed end up being
|
||||
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
|
||||
The optimum values may differ though from machine to machine, and
|
||||
possibly even between compilers. Your mileage may vary.
|
||||
*/
|
||||
|
||||
|
||||
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
|
||||
#define BMAX 15 /* maximum bit length of any code */
|
||||
|
||||
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
|
||||
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
|
||||
uInt n; /* number of codes (assumed <= 288) */
|
||||
uInt s; /* number of simple-valued codes (0..s-1) */
|
||||
const uIntf *d; /* list of base values for non-simple codes */
|
||||
const uIntf *e; /* list of extra bits for non-simple codes */
|
||||
inflate_huft * FAR *t; /* result: starting table */
|
||||
uIntf *m; /* maximum lookup bits, returns actual */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
uInt *hn; /* hufts used in space */
|
||||
uIntf *v; /* working area: values in order of bit length */
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
|
||||
if the given code set is incomplete (the tables are still built in this
|
||||
case), or Z_DATA_ERROR if the input is invalid. */
|
||||
{
|
||||
|
||||
uInt a; /* counter for codes of length k */
|
||||
uInt c[BMAX+1]; /* bit length count table */
|
||||
uInt f; /* i repeats in table every f entries */
|
||||
int g; /* maximum code length */
|
||||
int h; /* table level */
|
||||
register uInt i; /* counter, current code */
|
||||
register uInt j; /* counter */
|
||||
register int k; /* number of bits in current code */
|
||||
int l; /* bits per table (returned in m) */
|
||||
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
|
||||
register uIntf *p; /* pointer into c[], b[], or v[] */
|
||||
inflate_huft *q; /* points to current table */
|
||||
struct inflate_huft_s r; /* table entry for structure assignment */
|
||||
inflate_huft *u[BMAX]; /* table stack */
|
||||
register int w; /* bits before this table == (l * h) */
|
||||
uInt x[BMAX+1]; /* bit offsets, then code stack */
|
||||
uIntf *xp; /* pointer into x */
|
||||
int y; /* number of dummy codes added */
|
||||
uInt z; /* number of entries in current table */
|
||||
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
p = c;
|
||||
#define C0 *p++ = 0;
|
||||
#define C2 C0 C0 C0 C0
|
||||
#define C4 C2 C2 C2 C2
|
||||
C4 /* clear c[]--assume BMAX+1 is 16 */
|
||||
p = b; i = n;
|
||||
do {
|
||||
c[*p++]++; /* assume all entries <= BMAX */
|
||||
} while (--i);
|
||||
if (c[0] == n) /* null input--all zero length codes */
|
||||
{
|
||||
*t = (inflate_huft *)Z_NULL;
|
||||
*m = 0;
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
l = *m;
|
||||
for (j = 1; j <= BMAX; j++)
|
||||
if (c[j])
|
||||
break;
|
||||
k = j; /* minimum code length */
|
||||
if ((uInt)l < j)
|
||||
l = j;
|
||||
for (i = BMAX; i; i--)
|
||||
if (c[i])
|
||||
break;
|
||||
g = i; /* maximum code length */
|
||||
if ((uInt)l > i)
|
||||
l = i;
|
||||
*m = l;
|
||||
|
||||
|
||||
/* Adjust last length count to fill out codes, if needed */
|
||||
for (y = 1 << j; j < i; j++, y <<= 1)
|
||||
if ((y -= c[j]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
if ((y -= c[i]) < 0)
|
||||
return Z_DATA_ERROR;
|
||||
c[i] += y;
|
||||
|
||||
|
||||
/* Generate starting offsets into the value table for each length */
|
||||
x[1] = j = 0;
|
||||
p = c + 1; xp = x + 2;
|
||||
while (--i) { /* note that i == g from above */
|
||||
*xp++ = (j += *p++);
|
||||
}
|
||||
|
||||
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = b; i = 0;
|
||||
do {
|
||||
if ((j = *p++) != 0)
|
||||
v[x[j]++] = i;
|
||||
} while (++i < n);
|
||||
n = x[g]; /* set n to length of v */
|
||||
|
||||
|
||||
/* Generate the Huffman codes and for each, make the table entries */
|
||||
x[0] = i = 0; /* first Huffman code is zero */
|
||||
p = v; /* grab values in bit order */
|
||||
h = -1; /* no tables yet--level -1 */
|
||||
w = -l; /* bits decoded == (l * h) */
|
||||
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
|
||||
q = (inflate_huft *)Z_NULL; /* ditto */
|
||||
z = 0; /* ditto */
|
||||
|
||||
/* go through the bit lengths (k already is bits in shortest code) */
|
||||
for (; k <= g; k++)
|
||||
{
|
||||
a = c[k];
|
||||
while (a--)
|
||||
{
|
||||
/* here i is the Huffman code of length k bits for value *p */
|
||||
/* make tables up to required level */
|
||||
while (k > w + l)
|
||||
{
|
||||
h++;
|
||||
w += l; /* previous table always l bits */
|
||||
|
||||
/* compute minimum size table less than or equal to l bits */
|
||||
z = g - w;
|
||||
z = z > (uInt)l ? (uInt)l : z; /* table size upper limit */
|
||||
if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
|
||||
{ /* too few codes for k-w bit table */
|
||||
f -= a + 1; /* deduct codes from patterns left */
|
||||
xp = c + k;
|
||||
if (j < z)
|
||||
while (++j < z) /* try smaller tables up to z bits */
|
||||
{
|
||||
if ((f <<= 1) <= *++xp)
|
||||
break; /* enough codes to use up j bits */
|
||||
f -= *xp; /* else deduct codes from patterns */
|
||||
}
|
||||
}
|
||||
z = 1 << j; /* table entries for j-bit table */
|
||||
|
||||
/* allocate new table */
|
||||
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
|
||||
return Z_DATA_ERROR; /* overflow of MANY */
|
||||
u[h] = q = hp + *hn;
|
||||
*hn += z;
|
||||
|
||||
/* connect to last table, if there is one */
|
||||
if (h)
|
||||
{
|
||||
x[h] = i; /* save pattern for backing up */
|
||||
r.bits = (Byte)l; /* bits to dump before this table */
|
||||
r.exop = (Byte)j; /* bits in this table */
|
||||
j = i >> (w - l);
|
||||
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
|
||||
u[h-1][j] = r; /* connect to last table */
|
||||
}
|
||||
else
|
||||
*t = q; /* first table is returned result */
|
||||
}
|
||||
|
||||
/* set up table entry in r */
|
||||
r.bits = (Byte)(k - w);
|
||||
if (p >= v + n)
|
||||
r.exop = 128 + 64; /* out of values--invalid code */
|
||||
else if (*p < s)
|
||||
{
|
||||
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
|
||||
r.base = *p++; /* simple code is just the value */
|
||||
}
|
||||
else
|
||||
{
|
||||
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
|
||||
r.base = d[*p++ - s];
|
||||
}
|
||||
|
||||
/* fill code-like entries with r */
|
||||
f = 1 << (k - w);
|
||||
for (j = i >> w; j < z; j += f)
|
||||
q[j] = r;
|
||||
|
||||
/* backwards increment the k-bit code i */
|
||||
for (j = 1 << (k - 1); i & j; j >>= 1)
|
||||
i ^= j;
|
||||
i ^= j;
|
||||
|
||||
/* backup over finished tables */
|
||||
mask = (1 << w) - 1; /* needed on HP, cc -O bug */
|
||||
while ((i & mask) != x[h])
|
||||
{
|
||||
h--; /* don't need to update q */
|
||||
w -= l;
|
||||
mask = (1 << w) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Return Z_BUF_ERROR if we were given an incomplete table */
|
||||
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
|
||||
}
|
||||
|
||||
|
||||
local int inflate_trees_bits(c, bb, tb, hp, z)
|
||||
uIntf *c; /* 19 code lengths */
|
||||
uIntf *bb; /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *tb; /* bits tree result */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
|
||||
tb, bb, hp, &hn, v);
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
|
||||
else if (r == Z_BUF_ERROR || *bb == 0)
|
||||
{
|
||||
z->msg = (char*)"incomplete dynamic bit lengths tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
local int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
|
||||
uInt nl; /* number of literal/length codes */
|
||||
uInt nd; /* number of distance codes */
|
||||
uIntf *c; /* that many (total) code lengths */
|
||||
uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
inflate_huft *hp; /* space for trees */
|
||||
z_streamp z; /* for messages */
|
||||
{
|
||||
int r;
|
||||
uInt hn = 0; /* hufts used in space */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* allocate work area */
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
|
||||
/* build literal/length tree */
|
||||
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
|
||||
if (r != Z_OK || *bl == 0)
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed literal/length tree";
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = (char*)"incomplete literal/length tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* build distance tree */
|
||||
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
|
||||
if (r != Z_OK || (*bd == 0 && nl > 257))
|
||||
{
|
||||
if (r == Z_DATA_ERROR)
|
||||
z->msg = (char*)"oversubscribed distance tree";
|
||||
else if (r == Z_BUF_ERROR) {
|
||||
#ifdef PKZIP_BUG_WORKAROUND
|
||||
r = Z_OK;
|
||||
}
|
||||
#else
|
||||
z->msg = (char*)"incomplete distance tree";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
else if (r != Z_MEM_ERROR)
|
||||
{
|
||||
z->msg = (char*)"empty distance tree with lengths";
|
||||
r = Z_DATA_ERROR;
|
||||
}
|
||||
ZFREE(z, v);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* done */
|
||||
ZFREE(z, v);
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
|
||||
/* build fixed tables only once--keep them here */
|
||||
#ifdef BUILDFIXED
|
||||
local int fixed_built = 0;
|
||||
#define FIXEDH 544 /* number of hufts used by fixed tables */
|
||||
local inflate_huft fixed_mem[FIXEDH];
|
||||
local uInt fixed_bl;
|
||||
local uInt fixed_bd;
|
||||
local inflate_huft *fixed_tl;
|
||||
local inflate_huft *fixed_td;
|
||||
#else
|
||||
#include "inffixed.h"
|
||||
#endif
|
||||
|
||||
|
||||
local int inflate_trees_fixed(bl, bd, tl, td, z)
|
||||
uIntf *bl; /* literal desired/actual bit depth */
|
||||
uIntf *bd; /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *tl; /* literal/length tree result */
|
||||
inflate_huft * FAR *td; /* distance tree result */
|
||||
z_streamp z; /* for memory allocation */
|
||||
{
|
||||
#ifdef BUILDFIXED
|
||||
/* build fixed tables if not already */
|
||||
if (!fixed_built)
|
||||
{
|
||||
int k; /* temporary variable */
|
||||
uInt f = 0; /* number of hufts used in fixed_mem */
|
||||
uIntf *c; /* length list for huft_build */
|
||||
uIntf *v; /* work area for huft_build */
|
||||
|
||||
/* allocate memory */
|
||||
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
return Z_MEM_ERROR;
|
||||
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
|
||||
{
|
||||
ZFREE(z, c);
|
||||
return Z_MEM_ERROR;
|
||||
}
|
||||
|
||||
/* literal table */
|
||||
for (k = 0; k < 144; k++)
|
||||
c[k] = 8;
|
||||
for (; k < 256; k++)
|
||||
c[k] = 9;
|
||||
for (; k < 280; k++)
|
||||
c[k] = 7;
|
||||
for (; k < 288; k++)
|
||||
c[k] = 8;
|
||||
fixed_bl = 9;
|
||||
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* distance table */
|
||||
for (k = 0; k < 30; k++)
|
||||
c[k] = 5;
|
||||
fixed_bd = 5;
|
||||
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
|
||||
fixed_mem, &f, v);
|
||||
|
||||
/* done */
|
||||
ZFREE(z, v);
|
||||
ZFREE(z, c);
|
||||
fixed_built = 1;
|
||||
}
|
||||
#endif
|
||||
*bl = fixed_bl;
|
||||
*bd = fixed_bd;
|
||||
*tl = fixed_tl;
|
||||
*td = fixed_td;
|
||||
return Z_OK;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/* inftrees.h -- header to use inftrees.c
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* Huffman code lookup table entry--this entry is four bytes for machines
|
||||
that have 16-bit pointers (e.g. PC's in the small or medium model). */
|
||||
|
||||
#ifndef _INFTREES_H
|
||||
#define _INFTREES_H
|
||||
|
||||
typedef struct inflate_huft_s FAR inflate_huft;
|
||||
|
||||
struct inflate_huft_s {
|
||||
union {
|
||||
struct {
|
||||
Byte Exop; /* number of extra bits or operation */
|
||||
Byte Bits; /* number of bits in this code or subcode */
|
||||
} what;
|
||||
uInt pad; /* pad structure to a power of 2 (4 bytes for */
|
||||
} word; /* 16-bit, 8 bytes for 32-bit int's) */
|
||||
uInt base; /* literal, length base, distance base,
|
||||
or table offset */
|
||||
};
|
||||
|
||||
/* Maximum size of dynamic tree. The maximum found in a long but non-
|
||||
exhaustive search was 1004 huft structures (850 for length/literals
|
||||
and 154 for distances, the latter actually the result of an
|
||||
exhaustive search). The actual maximum is not known, but the
|
||||
value below is more than safe. */
|
||||
#define MANY 1440
|
||||
|
||||
local int inflate_trees_bits OF((
|
||||
uIntf *, /* 19 code lengths */
|
||||
uIntf *, /* bits tree desired/actual depth */
|
||||
inflate_huft * FAR *, /* bits tree result */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
local int inflate_trees_dynamic OF((
|
||||
uInt, /* number of literal/length codes */
|
||||
uInt, /* number of distance codes */
|
||||
uIntf *, /* that many (total) code lengths */
|
||||
uIntf *, /* literal desired/actual bit depth */
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
inflate_huft *, /* space for trees */
|
||||
z_streamp)); /* for messages */
|
||||
|
||||
local int inflate_trees_fixed OF((
|
||||
uIntf *, /* literal desired/actual bit depth */
|
||||
uIntf *, /* distance desired/actual bit depth */
|
||||
inflate_huft * FAR *, /* literal/length tree result */
|
||||
inflate_huft * FAR *, /* distance tree result */
|
||||
z_streamp)); /* for memory allocation */
|
||||
|
||||
#endif /* _INFTREES_H */
|
||||
@@ -0,0 +1,86 @@
|
||||
/* inflate_util.c -- data and routines common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
#include "zutil.h"
|
||||
#include "infblock.h"
|
||||
#include "inftrees.h"
|
||||
#include "infcodes.h"
|
||||
#include "infutil.h"
|
||||
|
||||
|
||||
/* And'ing with mask[n] masks the lower n bits */
|
||||
local uInt inflate_mask[17] = {
|
||||
0x0000,
|
||||
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
|
||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||
};
|
||||
|
||||
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
local int inflate_flush(s, z, r)
|
||||
inflate_blocks_statef *s;
|
||||
z_streamp z;
|
||||
int r;
|
||||
{
|
||||
uInt n;
|
||||
Bytef *p;
|
||||
Bytef *q;
|
||||
|
||||
/* local copies of source and destination pointers */
|
||||
p = z->next_out;
|
||||
q = s->read;
|
||||
|
||||
/* compute number of bytes to copy as far as end of window */
|
||||
n = (uInt)((q <= s->write ? s->write : s->end) - q);
|
||||
if (n > z->avail_out) n = z->avail_out;
|
||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
/* update counters */
|
||||
z->avail_out -= n;
|
||||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy as far as end of window */
|
||||
zmemcpy(p, q, n);
|
||||
p += n;
|
||||
q += n;
|
||||
|
||||
/* see if more to copy at beginning of window */
|
||||
if (q == s->end)
|
||||
{
|
||||
/* wrap pointers */
|
||||
q = s->window;
|
||||
if (s->write == s->end)
|
||||
s->write = s->window;
|
||||
|
||||
/* compute bytes to copy */
|
||||
n = (uInt)(s->write - q);
|
||||
if (n > z->avail_out) n = z->avail_out;
|
||||
if (n && r == Z_BUF_ERROR) r = Z_OK;
|
||||
|
||||
/* update counters */
|
||||
z->avail_out -= n;
|
||||
z->total_out += n;
|
||||
|
||||
/* update check information */
|
||||
if (s->checkfn != Z_NULL)
|
||||
z->adler = s->check = (*s->checkfn)(s->check, q, n);
|
||||
|
||||
/* copy */
|
||||
zmemcpy(p, q, n);
|
||||
p += n;
|
||||
q += n;
|
||||
}
|
||||
|
||||
/* update pointers */
|
||||
z->next_out = p;
|
||||
s->read = q;
|
||||
|
||||
/* done */
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/* infutil.h -- types and macros common to blocks and codes
|
||||
* Copyright (C) 1995-2002 Mark Adler
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
#ifndef _INFUTIL_H
|
||||
#define _INFUTIL_H
|
||||
|
||||
typedef enum {
|
||||
TYPE, /* get type bits (3, including end bit) */
|
||||
LENS, /* get lengths for stored */
|
||||
STORED, /* processing stored block */
|
||||
TABLE, /* get table lengths */
|
||||
BTREE, /* get bit lengths tree for a dynamic block */
|
||||
DTREE, /* get length, distance trees for a dynamic block */
|
||||
CODES, /* processing fixed or dynamic block */
|
||||
DRY, /* output remaining window bytes */
|
||||
DONE, /* finished last block, done */
|
||||
BAD} /* got a data error--stuck here */
|
||||
inflate_block_mode;
|
||||
|
||||
/* inflate blocks semi-private state */
|
||||
struct inflate_blocks_state {
|
||||
|
||||
/* mode */
|
||||
inflate_block_mode mode; /* current inflate_block mode */
|
||||
|
||||
/* mode dependent information */
|
||||
union {
|
||||
uInt left; /* if STORED, bytes left to copy */
|
||||
struct {
|
||||
uInt table; /* table lengths (14 bits) */
|
||||
uInt index; /* index into blens (or border) */
|
||||
uIntf *blens; /* bit lengths of codes */
|
||||
uInt bb; /* bit length tree depth */
|
||||
inflate_huft *tb; /* bit length decoding tree */
|
||||
} trees; /* if DTREE, decoding info for trees */
|
||||
struct {
|
||||
inflate_codes_statef
|
||||
*codes;
|
||||
} decode; /* if CODES, current state */
|
||||
} sub; /* submode */
|
||||
uInt last; /* true if this block is the last block */
|
||||
|
||||
/* mode independent information */
|
||||
uInt bitk; /* bits in bit buffer */
|
||||
uLong bitb; /* bit buffer */
|
||||
inflate_huft *hufts; /* single malloc for tree space */
|
||||
Bytef *window; /* sliding window */
|
||||
Bytef *end; /* one byte after sliding window */
|
||||
Bytef *read; /* window read pointer */
|
||||
Bytef *write; /* window write pointer */
|
||||
check_func checkfn; /* check function */
|
||||
uLong check; /* check on output */
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* defines for inflate input/output */
|
||||
/* update pointers and return */
|
||||
#define UPDBITS {s->bitb=b;s->bitk=k;}
|
||||
#define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
|
||||
#define UPDOUT {s->write=q;}
|
||||
#define UPDATE {UPDBITS UPDIN UPDOUT}
|
||||
#define LEAVE {UPDATE return inflate_flush(s,z,r);}
|
||||
/* get bytes and bits */
|
||||
#define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
|
||||
#define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
|
||||
#define NEXTBYTE (n--,*p++)
|
||||
#define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
|
||||
#define DUMPBITS(j) {b>>=(j);k-=(j);}
|
||||
/* output bytes */
|
||||
#define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
|
||||
#define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
|
||||
#define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
|
||||
#define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
|
||||
#define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
|
||||
#define OUTBYTE(a) {*q++=(Byte)(a);m--;}
|
||||
/* load local pointers */
|
||||
#define LOAD {LOADIN LOADOUT}
|
||||
|
||||
/* masks for lower bits (size given to avoid silly warnings with Visual C++) */
|
||||
local uInt inflate_mask[17];
|
||||
|
||||
/* copy as much as possible from the sliding window to the output area */
|
||||
local int inflate_flush OF((
|
||||
inflate_blocks_statef *,
|
||||
z_streamp ,
|
||||
int));
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# FreeType 2 GZip support configuration rules
|
||||
#
|
||||
|
||||
|
||||
# Copyright 2002 by
|
||||
# David Turner, Robert Wilhelm, and Werner Lemberg.
|
||||
#
|
||||
# This file is part of the FreeType project, and may only be used, modified,
|
||||
# and distributed under the terms of the FreeType project license,
|
||||
# LICENSE.TXT. By continuing to use, modify, or distribute this file you
|
||||
# indicate that you have read the license and understand and accept it
|
||||
# fully.
|
||||
|
||||
|
||||
# gzip driver directory
|
||||
#
|
||||
GZIP_DIR := $(SRC_)gzip
|
||||
GZIP_DIR_ := $(GZIP_DIR)$(SEP)
|
||||
|
||||
|
||||
# compilation flags for the driver
|
||||
#
|
||||
GZIP_COMPILE := $(FT_COMPILE) $I$(GZIP_DIR)
|
||||
|
||||
|
||||
# gzip support sources (i.e., C files)
|
||||
#
|
||||
GZIP_DRV_SRC := $(GZIP_DIR_)ftgzip.c
|
||||
|
||||
# gzip support headers
|
||||
#
|
||||
GZIP_DRV_H :=
|
||||
|
||||
|
||||
# Pfr driver object(s)
|
||||
#
|
||||
# GZIP_DRV_OBJ_M is used during `multi' builds
|
||||
# GZIP_DRV_OBJ_S is used during `single' builds
|
||||
#
|
||||
GZIP_DRV_OBJ_M := $(GZIP_DRV_SRC:$(GZIP_DIR_)%.c=$(OBJ_)%.$O)
|
||||
GZIP_DRV_OBJ_S := $(OBJ_)ftgzip.$O
|
||||
|
||||
# gzip support source file for single build
|
||||
#
|
||||
GZIP_DRV_SRC_S := $(GZIP_DIR_)ftgzip.c
|
||||
|
||||
|
||||
# gzip support - single object
|
||||
#
|
||||
$(GZIP_DRV_OBJ_S): $(GZIP_DRV_SRC_S) $(GZIP_DRV_SRC) $(FREETYPE_H) $(GZIP_DRV_H)
|
||||
$(GZIP_COMPILE) $T$@ $(GZIP_DRV_SRC_S)
|
||||
|
||||
|
||||
# gzip support - multiple objects
|
||||
#
|
||||
$(OBJ_)%.$O: $(GZIP_DIR_)%.c $(FREETYPE_H) $(GZIP_DRV_H)
|
||||
$(GZIP_COMPILE) $T$@ $<
|
||||
|
||||
|
||||
# update main driver object lists
|
||||
#
|
||||
DRV_OBJS_S += $(GZIP_DRV_OBJ_S)
|
||||
DRV_OBJS_M += $(GZIP_DRV_OBJ_M)
|
||||
|
||||
# EOF
|
||||
@@ -0,0 +1,275 @@
|
||||
/* zconf.h -- configuration of the zlib compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zconf.h,v 1.1 2002/11/20 19:19:16 bonefish Exp $ */
|
||||
|
||||
#ifndef _ZCONF_H
|
||||
#define _ZCONF_H
|
||||
|
||||
/*
|
||||
* If you *really* need a unique prefix for all types and library functions,
|
||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||
*/
|
||||
#ifdef Z_PREFIX
|
||||
# define deflateInit_ z_deflateInit_
|
||||
# define deflate z_deflate
|
||||
# define deflateEnd z_deflateEnd
|
||||
# define inflateInit_ z_inflateInit_
|
||||
# define inflate z_inflate
|
||||
# define inflateEnd z_inflateEnd
|
||||
# define deflateInit2_ z_deflateInit2_
|
||||
# define deflateSetDictionary z_deflateSetDictionary
|
||||
# define deflateCopy z_deflateCopy
|
||||
# define deflateReset z_deflateReset
|
||||
# define deflateParams z_deflateParams
|
||||
# define inflateInit2_ z_inflateInit2_
|
||||
# define inflateSetDictionary z_inflateSetDictionary
|
||||
# define inflateSync z_inflateSync
|
||||
# define inflateSyncPoint z_inflateSyncPoint
|
||||
# define inflateReset z_inflateReset
|
||||
# define compress z_compress
|
||||
# define compress2 z_compress2
|
||||
# define uncompress z_uncompress
|
||||
# define adler32 z_adler32
|
||||
# define crc32 z_crc32
|
||||
# define get_crc_table z_get_crc_table
|
||||
|
||||
# define Byte z_Byte
|
||||
# define uInt z_uInt
|
||||
# define uLong z_uLong
|
||||
# define Bytef z_Bytef
|
||||
# define charf z_charf
|
||||
# define intf z_intf
|
||||
# define uIntf z_uIntf
|
||||
# define uLongf z_uLongf
|
||||
# define voidpf z_voidpf
|
||||
# define voidp z_voidp
|
||||
#endif
|
||||
|
||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||
# define WIN32
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
|
||||
# ifndef __32BIT__
|
||||
# define __32BIT__
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||
# define MSDOS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||
*/
|
||||
#if defined(MSDOS) && !defined(__32BIT__)
|
||||
# define MAXSEG_64K
|
||||
#endif
|
||||
#ifdef MSDOS
|
||||
# define UNALIGNED_OK
|
||||
#endif
|
||||
|
||||
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
|
||||
# define STDC
|
||||
#endif
|
||||
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
|
||||
# ifndef STDC
|
||||
# define STDC
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef STDC
|
||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||
# define const
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Some Mac compilers merge all .h files incorrectly: */
|
||||
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||
# define NO_DUMMY_DECL
|
||||
#endif
|
||||
|
||||
/* Old Borland C incorrectly complains about missing returns: */
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
|
||||
# define NEED_DUMMY_RETURN
|
||||
#endif
|
||||
|
||||
|
||||
/* Maximum value for memLevel in deflateInit2 */
|
||||
#ifndef MAX_MEM_LEVEL
|
||||
# ifdef MAXSEG_64K
|
||||
# define MAX_MEM_LEVEL 8
|
||||
# else
|
||||
# define MAX_MEM_LEVEL 9
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||
* created by gzip. (Files created by minigzip can still be extracted by
|
||||
* gzip.)
|
||||
*/
|
||||
#ifndef MAX_WBITS
|
||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||
#endif
|
||||
|
||||
/* The memory requirements for deflate are (in bytes):
|
||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||
the default memory requirements from 256K to 128K, compile with
|
||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||
Of course this will generally degrade compression (there's no free lunch).
|
||||
|
||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||
for small objects.
|
||||
*/
|
||||
|
||||
/* Type declarations */
|
||||
|
||||
#ifndef OF /* function prototypes */
|
||||
# ifdef STDC
|
||||
# define OF(args) args
|
||||
# else
|
||||
# define OF(args) ()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||
* model programming (small or medium model with some far allocations).
|
||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||
* just define FAR to be empty.
|
||||
*/
|
||||
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
|
||||
/* MSC small or medium model */
|
||||
# define SMALL_MEDIUM
|
||||
# ifdef _MSC_VER
|
||||
# define FAR _far
|
||||
# else
|
||||
# define FAR far
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
|
||||
# ifndef __32BIT__
|
||||
# define SMALL_MEDIUM
|
||||
# define FAR _far
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compile with -DZLIB_DLL for Windows DLL support */
|
||||
#if defined(ZLIB_DLL)
|
||||
# if defined(_WINDOWS) || defined(WINDOWS)
|
||||
# ifdef FAR
|
||||
# undef FAR
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# define ZEXPORT WINAPI
|
||||
# ifdef WIN32
|
||||
# define ZEXPORTVA WINAPIV
|
||||
# else
|
||||
# define ZEXPORTVA FAR _cdecl _export
|
||||
# endif
|
||||
# endif
|
||||
# if defined (__BORLANDC__)
|
||||
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
|
||||
# include <windows.h>
|
||||
# define ZEXPORT __declspec(dllexport) WINAPI
|
||||
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
|
||||
# else
|
||||
# if defined (_Windows) && defined (__DLL__)
|
||||
# define ZEXPORT _export
|
||||
# define ZEXPORTVA _export
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
#ifndef ZEXPORTVA
|
||||
# define ZEXPORTVA
|
||||
#endif
|
||||
#ifndef ZEXTERN
|
||||
# define ZEXTERN static
|
||||
#endif
|
||||
#ifndef ZEXTERNDEF
|
||||
# define ZEXTERNDEF static
|
||||
#endif
|
||||
|
||||
#ifndef FAR
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
|
||||
typedef unsigned char Byte; /* 8 bits */
|
||||
#endif
|
||||
typedef unsigned int uInt; /* 16 bits or more */
|
||||
typedef unsigned long uLong; /* 32 bits or more */
|
||||
|
||||
#ifdef SMALL_MEDIUM
|
||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||
# define Bytef Byte FAR
|
||||
#else
|
||||
typedef Byte FAR Bytef;
|
||||
#endif
|
||||
typedef char FAR charf;
|
||||
typedef int FAR intf;
|
||||
typedef uInt FAR uIntf;
|
||||
typedef uLong FAR uLongf;
|
||||
|
||||
#ifdef STDC
|
||||
typedef void FAR *voidpf;
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef Byte FAR *voidpf;
|
||||
typedef Byte *voidp;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <sys/types.h> /* for off_t */
|
||||
# include <unistd.h> /* for SEEK_* and off_t */
|
||||
# define z_off_t off_t
|
||||
#endif
|
||||
#ifndef SEEK_SET
|
||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||
# define SEEK_CUR 1 /* Seek from current position. */
|
||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||
#endif
|
||||
#ifndef z_off_t
|
||||
# define z_off_t long
|
||||
#endif
|
||||
|
||||
/* MVS linker does not support external names larger than 8 bytes */
|
||||
#if defined(__MVS__)
|
||||
# pragma map(deflateInit_,"DEIN")
|
||||
# pragma map(deflateInit2_,"DEIN2")
|
||||
# pragma map(deflateEnd,"DEEND")
|
||||
# pragma map(inflateInit_,"ININ")
|
||||
# pragma map(inflateInit2_,"ININ2")
|
||||
# pragma map(inflateEnd,"INEND")
|
||||
# pragma map(inflateSync,"INSY")
|
||||
# pragma map(inflateSetDictionary,"INSEDI")
|
||||
# pragma map(inflate_blocks,"INBL")
|
||||
# pragma map(inflate_blocks_new,"INBLNE")
|
||||
# pragma map(inflate_blocks_free,"INBLFR")
|
||||
# pragma map(inflate_blocks_reset,"INBLRE")
|
||||
# pragma map(inflate_codes_free,"INCOFR")
|
||||
# pragma map(inflate_codes,"INCO")
|
||||
# pragma map(inflate_fast,"INFA")
|
||||
# pragma map(inflate_flush,"INFLU")
|
||||
# pragma map(inflate_mask,"INMA")
|
||||
# pragma map(inflate_set_dictionary,"INSEDI2")
|
||||
# pragma map(inflate_copyright,"INCOPY")
|
||||
# pragma map(inflate_trees_bits,"INTRBI")
|
||||
# pragma map(inflate_trees_dynamic,"INTRDY")
|
||||
# pragma map(inflate_trees_fixed,"INTRFI")
|
||||
# pragma map(inflate_trees_free,"INTRFR")
|
||||
#endif
|
||||
|
||||
#endif /* _ZCONF_H */
|
||||
@@ -0,0 +1,830 @@
|
||||
/* zlib.h -- interface of the 'zlib' general purpose compression library
|
||||
version 1.1.4, March 11th, 2002
|
||||
|
||||
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
|
||||
The data format used by the zlib library is described by RFCs (Request for
|
||||
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
|
||||
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
|
||||
*/
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#define _ZLIB_H
|
||||
|
||||
#include "zconf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_VERSION "1.1.4"
|
||||
|
||||
/*
|
||||
The 'zlib' compression library provides in-memory compression and
|
||||
decompression functions, including integrity checks of the uncompressed
|
||||
data. This version of the library supports only one compression method
|
||||
(deflation) but other algorithms will be added later and will have the same
|
||||
stream interface.
|
||||
|
||||
Compression can be done in a single step if the buffers are large
|
||||
enough (for example if an input file is mmap'ed), or can be done by
|
||||
repeated calls of the compression function. In the latter case, the
|
||||
application must provide more input and/or consume the output
|
||||
(providing more output space) before each call.
|
||||
|
||||
The library also supports reading and writing files in gzip (.gz) format
|
||||
with an interface similar to that of stdio.
|
||||
|
||||
The library does not install any signal handler. The decoder checks
|
||||
the consistency of the compressed data, so the library should never
|
||||
crash even in case of corrupted input.
|
||||
*/
|
||||
|
||||
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
|
||||
typedef void (*free_func) OF((voidpf opaque, voidpf address));
|
||||
|
||||
struct internal_state;
|
||||
|
||||
typedef struct z_stream_s {
|
||||
Bytef *next_in; /* next input byte */
|
||||
uInt avail_in; /* number of bytes available at next_in */
|
||||
uLong total_in; /* total nb of input bytes read so far */
|
||||
|
||||
Bytef *next_out; /* next output byte should be put there */
|
||||
uInt avail_out; /* remaining free space at next_out */
|
||||
uLong total_out; /* total nb of bytes output so far */
|
||||
|
||||
char *msg; /* last error message, NULL if no error */
|
||||
struct internal_state FAR *state; /* not visible by applications */
|
||||
|
||||
alloc_func zalloc; /* used to allocate the internal state */
|
||||
free_func zfree; /* used to free the internal state */
|
||||
voidpf opaque; /* private data object passed to zalloc and zfree */
|
||||
|
||||
int data_type; /* best guess about the data type: ascii or binary */
|
||||
uLong adler; /* adler32 value of the uncompressed data */
|
||||
uLong reserved; /* reserved for future use */
|
||||
} z_stream;
|
||||
|
||||
typedef z_stream FAR *z_streamp;
|
||||
|
||||
/*
|
||||
The application must update next_in and avail_in when avail_in has
|
||||
dropped to zero. It must update next_out and avail_out when avail_out
|
||||
has dropped to zero. The application must initialize zalloc, zfree and
|
||||
opaque before calling the init function. All other fields are set by the
|
||||
compression library and must not be updated by the application.
|
||||
|
||||
The opaque value provided by the application will be passed as the first
|
||||
parameter for calls of zalloc and zfree. This can be useful for custom
|
||||
memory management. The compression library attaches no meaning to the
|
||||
opaque value.
|
||||
|
||||
zalloc must return Z_NULL if there is not enough memory for the object.
|
||||
If zlib is used in a multi-threaded application, zalloc and zfree must be
|
||||
thread safe.
|
||||
|
||||
On 16-bit systems, the functions zalloc and zfree must be able to allocate
|
||||
exactly 65536 bytes, but will not be required to allocate more than this
|
||||
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
|
||||
pointers returned by zalloc for objects of exactly 65536 bytes *must*
|
||||
have their offset normalized to zero. The default allocation function
|
||||
provided by this library ensures this (see zutil.c). To reduce memory
|
||||
requirements and avoid any allocation of 64K objects, at the expense of
|
||||
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
|
||||
|
||||
The fields total_in and total_out can be used for statistics or
|
||||
progress reports. After compression, total_in holds the total size of
|
||||
the uncompressed data and may be saved for use in the decompressor
|
||||
(particularly if the decompressor wants to decompress everything in
|
||||
a single step).
|
||||
*/
|
||||
|
||||
/* constants */
|
||||
|
||||
#define Z_NO_FLUSH 0
|
||||
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
|
||||
#define Z_SYNC_FLUSH 2
|
||||
#define Z_FULL_FLUSH 3
|
||||
#define Z_FINISH 4
|
||||
/* Allowed flush values; see deflate() below for details */
|
||||
|
||||
#define Z_OK 0
|
||||
#define Z_STREAM_END 1
|
||||
#define Z_NEED_DICT 2
|
||||
#define Z_ERRNO (-1)
|
||||
#define Z_STREAM_ERROR (-2)
|
||||
#define Z_DATA_ERROR (-3)
|
||||
#define Z_MEM_ERROR (-4)
|
||||
#define Z_BUF_ERROR (-5)
|
||||
#define Z_VERSION_ERROR (-6)
|
||||
/* Return codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values are used for special but normal events.
|
||||
*/
|
||||
|
||||
#define Z_NO_COMPRESSION 0
|
||||
#define Z_BEST_SPEED 1
|
||||
#define Z_BEST_COMPRESSION 9
|
||||
#define Z_DEFAULT_COMPRESSION (-1)
|
||||
/* compression levels */
|
||||
|
||||
#define Z_FILTERED 1
|
||||
#define Z_HUFFMAN_ONLY 2
|
||||
#define Z_DEFAULT_STRATEGY 0
|
||||
/* compression strategy; see deflateInit2() below for details */
|
||||
|
||||
#define Z_BINARY 0
|
||||
#define Z_ASCII 1
|
||||
#define Z_UNKNOWN 2
|
||||
/* Possible values of the data_type field */
|
||||
|
||||
#define Z_DEFLATED 8
|
||||
/* The deflate compression method (the only one supported in this version) */
|
||||
|
||||
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
|
||||
|
||||
|
||||
/* basic functions */
|
||||
|
||||
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
|
||||
If the first character differs, the library code actually used is
|
||||
not compatible with the zlib.h header file used by the application.
|
||||
This check is automatically made by deflateInit and inflateInit.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
|
||||
|
||||
Initializes the internal stream state for compression. The fields
|
||||
zalloc, zfree and opaque must be initialized before by the caller.
|
||||
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
|
||||
1 gives best speed, 9 gives best compression, 0 gives no compression at
|
||||
all (the input data is simply copied a block at a time).
|
||||
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
|
||||
compression (currently equivalent to level 6).
|
||||
|
||||
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
|
||||
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
|
||||
with the version assumed by the caller (ZLIB_VERSION).
|
||||
msg is set to null if there is no error message. deflateInit does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
deflate compresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may introduce some
|
||||
output latency (reading input without producing any output) except when
|
||||
forced to flush.
|
||||
|
||||
The detailed semantics are as follows. deflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Compress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in and avail_in are updated and
|
||||
processing will resume at this point for the next call of deflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. This action is forced if the parameter flush is non zero.
|
||||
Forcing flush frequently degrades the compression ratio, so this parameter
|
||||
should be set only when necessary (in interactive applications).
|
||||
Some output may be provided even if flush is not set.
|
||||
|
||||
Before the call of deflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating avail_in or avail_out accordingly; avail_out
|
||||
should never be zero before the call. The application can consume the
|
||||
compressed output when it wants, for example when the output buffer is full
|
||||
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
|
||||
and with zero avail_out, it must be called again after making room in the
|
||||
output buffer because there might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
|
||||
flushed to the output buffer and the output is aligned on a byte boundary, so
|
||||
that the decompressor can get all input data available so far. (In particular
|
||||
avail_in is zero after the call if enough output space has been provided
|
||||
before the call.) Flushing may degrade compression for some compression
|
||||
algorithms and so it should be used only when necessary.
|
||||
|
||||
If flush is set to Z_FULL_FLUSH, all output is flushed as with
|
||||
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
|
||||
restart from this point if previous compressed data has been damaged or if
|
||||
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
|
||||
the compression.
|
||||
|
||||
If deflate returns with avail_out == 0, this function must be called again
|
||||
with the same value of the flush parameter and more output space (updated
|
||||
avail_out), until the flush is complete (deflate returns with non-zero
|
||||
avail_out).
|
||||
|
||||
If the parameter flush is set to Z_FINISH, pending input is processed,
|
||||
pending output is flushed and deflate returns with Z_STREAM_END if there
|
||||
was enough output space; if deflate returns with Z_OK, this function must be
|
||||
called again with Z_FINISH and more output space (updated avail_out) but no
|
||||
more input data, until it returns with Z_STREAM_END or an error. After
|
||||
deflate has returned Z_STREAM_END, the only possible operations on the
|
||||
stream are deflateReset or deflateEnd.
|
||||
|
||||
Z_FINISH can be used immediately after deflateInit if all the compression
|
||||
is to be done in a single step. In this case, avail_out must be at least
|
||||
0.1% larger than avail_in plus 12 bytes. If deflate does not return
|
||||
Z_STREAM_END, then it must be called again as described above.
|
||||
|
||||
deflate() sets strm->adler to the adler32 checksum of all input read
|
||||
so far (that is, total_in bytes).
|
||||
|
||||
deflate() may update data_type if it can make a good guess about
|
||||
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
|
||||
binary. This field is only for information purposes and does not affect
|
||||
the compression algorithm in any manner.
|
||||
|
||||
deflate() returns Z_OK if some progress has been made (more input
|
||||
processed or more output produced), Z_STREAM_END if all input has been
|
||||
consumed and all output has been produced (only when flush is set to
|
||||
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
|
||||
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
|
||||
(for example avail_in or avail_out was zero).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
|
||||
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
|
||||
prematurely (some input or output was discarded). In the error case,
|
||||
msg may be set but then points to a static string (which must not be
|
||||
deallocated).
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
|
||||
|
||||
Initializes the internal stream state for decompression. The fields
|
||||
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
|
||||
value depends on the compression method), inflateInit determines the
|
||||
compression method from the zlib header and allocates all data structures
|
||||
accordingly; otherwise the allocation will be deferred to the first call of
|
||||
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
|
||||
use default allocation functions.
|
||||
|
||||
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
|
||||
version assumed by the caller. msg is set to null if there is no error
|
||||
message. inflateInit does not perform any decompression apart from reading
|
||||
the zlib header if present: this will be done by inflate(). (So next_in and
|
||||
avail_in may be modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
|
||||
/*
|
||||
inflate decompresses as much data as possible, and stops when the input
|
||||
buffer becomes empty or the output buffer becomes full. It may some
|
||||
introduce some output latency (reading input without producing any output)
|
||||
except when forced to flush.
|
||||
|
||||
The detailed semantics are as follows. inflate performs one or both of the
|
||||
following actions:
|
||||
|
||||
- Decompress more input starting at next_in and update next_in and avail_in
|
||||
accordingly. If not all input can be processed (because there is not
|
||||
enough room in the output buffer), next_in is updated and processing
|
||||
will resume at this point for the next call of inflate().
|
||||
|
||||
- Provide more output starting at next_out and update next_out and avail_out
|
||||
accordingly. inflate() provides as much output as possible, until there
|
||||
is no more input data or no more space in the output buffer (see below
|
||||
about the flush parameter).
|
||||
|
||||
Before the call of inflate(), the application should ensure that at least
|
||||
one of the actions is possible, by providing more input and/or consuming
|
||||
more output, and updating the next_* and avail_* values accordingly.
|
||||
The application can consume the uncompressed output when it wants, for
|
||||
example when the output buffer is full (avail_out == 0), or after each
|
||||
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
|
||||
must be called again after making room in the output buffer because there
|
||||
might be more output pending.
|
||||
|
||||
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
|
||||
output as possible to the output buffer. The flushing behavior of inflate is
|
||||
not specified for values of the flush parameter other than Z_SYNC_FLUSH
|
||||
and Z_FINISH, but the current implementation actually flushes as much output
|
||||
as possible anyway.
|
||||
|
||||
inflate() should normally be called until it returns Z_STREAM_END or an
|
||||
error. However if all decompression is to be performed in a single step
|
||||
(a single call of inflate), the parameter flush should be set to
|
||||
Z_FINISH. In this case all pending input is processed and all pending
|
||||
output is flushed; avail_out must be large enough to hold all the
|
||||
uncompressed data. (The size of the uncompressed data may have been saved
|
||||
by the compressor for this purpose.) The next operation on this stream must
|
||||
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
|
||||
is never required, but can be used to inform inflate that a faster routine
|
||||
may be used for the single inflate() call.
|
||||
|
||||
If a preset dictionary is needed at this point (see inflateSetDictionary
|
||||
below), inflate sets strm-adler to the adler32 checksum of the
|
||||
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
|
||||
it sets strm->adler to the adler32 checksum of all output produced
|
||||
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
|
||||
an error code as described below. At the end of the stream, inflate()
|
||||
checks that its computed adler32 checksum is equal to that saved by the
|
||||
compressor and returns Z_STREAM_END only if the checksum is correct.
|
||||
|
||||
inflate() returns Z_OK if some progress has been made (more input processed
|
||||
or more output produced), Z_STREAM_END if the end of the compressed data has
|
||||
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
|
||||
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
|
||||
corrupted (input stream not conforming to the zlib format or incorrect
|
||||
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
|
||||
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
|
||||
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
|
||||
case, the application may then call inflateSync to look for a good
|
||||
compression block.
|
||||
*/
|
||||
|
||||
|
||||
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
|
||||
/*
|
||||
All dynamically allocated data structures for this stream are freed.
|
||||
This function discards any unprocessed input and does not flush any
|
||||
pending output.
|
||||
|
||||
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
|
||||
was inconsistent. In the error case, msg may be set but then points to a
|
||||
static string (which must not be deallocated).
|
||||
*/
|
||||
|
||||
/* Advanced functions */
|
||||
|
||||
/*
|
||||
The following functions are needed only in some special applications.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
|
||||
int level,
|
||||
int method,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy));
|
||||
|
||||
This is another version of deflateInit with more compression options. The
|
||||
fields next_in, zalloc, zfree and opaque must be initialized before by
|
||||
the caller.
|
||||
|
||||
The method parameter is the compression method. It must be Z_DEFLATED in
|
||||
this version of the library.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the window size
|
||||
(the size of the history buffer). It should be in the range 8..15 for this
|
||||
version of the library. Larger values of this parameter result in better
|
||||
compression at the expense of memory usage. The default value is 15 if
|
||||
deflateInit is used instead.
|
||||
|
||||
The memLevel parameter specifies how much memory should be allocated
|
||||
for the internal compression state. memLevel=1 uses minimum memory but
|
||||
is slow and reduces compression ratio; memLevel=9 uses maximum memory
|
||||
for optimal speed. The default value is 8. See zconf.h for total memory
|
||||
usage as a function of windowBits and memLevel.
|
||||
|
||||
The strategy parameter is used to tune the compression algorithm. Use the
|
||||
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
|
||||
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
|
||||
string match). Filtered data consists mostly of small values with a
|
||||
somewhat random distribution. In this case, the compression algorithm is
|
||||
tuned to compress them better. The effect of Z_FILTERED is to force more
|
||||
Huffman coding and less string matching; it is somewhat intermediate
|
||||
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
|
||||
the compression ratio but not the correctness of the compressed output even
|
||||
if it is not set appropriately.
|
||||
|
||||
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
|
||||
method). msg is set to null if there is no error message. deflateInit2 does
|
||||
not perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
/*
|
||||
Initializes the compression dictionary from the given byte sequence
|
||||
without producing any compressed output. This function must be called
|
||||
immediately after deflateInit, deflateInit2 or deflateReset, before any
|
||||
call of deflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see inflateSetDictionary).
|
||||
|
||||
The dictionary should consist of strings (byte sequences) that are likely
|
||||
to be encountered later in the data to be compressed, with the most commonly
|
||||
used strings preferably put towards the end of the dictionary. Using a
|
||||
dictionary is most useful when the data to be compressed is short and can be
|
||||
predicted with good accuracy; the data can then be compressed better than
|
||||
with the default empty dictionary.
|
||||
|
||||
Depending on the size of the compression data structures selected by
|
||||
deflateInit or deflateInit2, a part of the dictionary may in effect be
|
||||
discarded, for example if the dictionary is larger than the window size in
|
||||
deflate or deflate2. Thus the strings most likely to be useful should be
|
||||
put at the end of the dictionary, not at the front.
|
||||
|
||||
Upon return of this function, strm->adler is set to the Adler32 value
|
||||
of the dictionary; the decompressor may later use this value to determine
|
||||
which dictionary has been used by the compressor. (The Adler32 value
|
||||
applies to the whole dictionary even if only a subset of the dictionary is
|
||||
actually used by the compressor.)
|
||||
|
||||
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent (for example if deflate has already been called for this stream
|
||||
or if the compression method is bsort). deflateSetDictionary does not
|
||||
perform any compression: this will be done by deflate().
|
||||
*/
|
||||
|
||||
/*
|
||||
Sets the destination stream as a complete copy of the source stream.
|
||||
|
||||
This function can be useful when several compression strategies will be
|
||||
tried, for example when there are several ways of pre-processing the input
|
||||
data with a filter. The streams that will be discarded should then be freed
|
||||
by calling deflateEnd. Note that deflateCopy duplicates the internal
|
||||
compression state which can be quite large, so this strategy is slow and
|
||||
can consume lots of memory.
|
||||
|
||||
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
|
||||
(such as zalloc being NULL). msg is left unchanged in both source and
|
||||
destination.
|
||||
*/
|
||||
|
||||
/*
|
||||
This function is equivalent to deflateEnd followed by deflateInit,
|
||||
but does not free and reallocate all the internal compression state.
|
||||
The stream will keep the same compression level and any other attributes
|
||||
that may have been set by deflateInit2.
|
||||
|
||||
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
/*
|
||||
Dynamically update the compression level and compression strategy. The
|
||||
interpretation of level and strategy is as in deflateInit2. This can be
|
||||
used to switch between compression and straight copy of the input data, or
|
||||
to switch to a different kind of input data requiring a different
|
||||
strategy. If the compression level is changed, the input available so far
|
||||
is compressed with the old level (and may be flushed); the new level will
|
||||
take effect only at the next call of deflate().
|
||||
|
||||
Before the call of deflateParams, the stream state must be set as for
|
||||
a call of deflate(), since the currently available input may have to
|
||||
be compressed and flushed. In particular, strm->avail_out must be non-zero.
|
||||
|
||||
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
|
||||
if strm->avail_out was zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
|
||||
int windowBits));
|
||||
|
||||
This is another version of inflateInit with an extra parameter. The
|
||||
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
|
||||
before by the caller.
|
||||
|
||||
The windowBits parameter is the base two logarithm of the maximum window
|
||||
size (the size of the history buffer). It should be in the range 8..15 for
|
||||
this version of the library. The default value is 15 if inflateInit is used
|
||||
instead. If a compressed stream with a larger window size is given as
|
||||
input, inflate() will return with the error code Z_DATA_ERROR instead of
|
||||
trying to allocate a larger window.
|
||||
|
||||
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
|
||||
memLevel). msg is set to null if there is no error message. inflateInit2
|
||||
does not perform any decompression apart from reading the zlib header if
|
||||
present: this will be done by inflate(). (So next_in and avail_in may be
|
||||
modified, but next_out and avail_out are unchanged.)
|
||||
*/
|
||||
|
||||
/*
|
||||
Initializes the decompression dictionary from the given uncompressed byte
|
||||
sequence. This function must be called immediately after a call of inflate
|
||||
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
|
||||
can be determined from the Adler32 value returned by this call of
|
||||
inflate. The compressor and decompressor must use exactly the same
|
||||
dictionary (see deflateSetDictionary).
|
||||
|
||||
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
|
||||
parameter is invalid (such as NULL dictionary) or the stream state is
|
||||
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
|
||||
expected one (incorrect Adler32 value). inflateSetDictionary does not
|
||||
perform any decompression: this will be done by subsequent calls of
|
||||
inflate().
|
||||
*/
|
||||
|
||||
/*
|
||||
Skips invalid compressed data until a full flush point (see above the
|
||||
description of deflate with Z_FULL_FLUSH) can be found, or until all
|
||||
available input is skipped. No output is provided.
|
||||
|
||||
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
|
||||
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
|
||||
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
|
||||
case, the application may save the current current value of total_in which
|
||||
indicates where valid compressed data was found. In the error case, the
|
||||
application may repeatedly call inflateSync, providing more input each time,
|
||||
until success or end of the input data.
|
||||
*/
|
||||
|
||||
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
|
||||
/*
|
||||
This function is equivalent to inflateEnd followed by inflateInit,
|
||||
but does not free and reallocate all the internal decompression state.
|
||||
The stream will keep attributes that may have been set by inflateInit2.
|
||||
|
||||
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
|
||||
stream state was inconsistent (such as zalloc or state being NULL).
|
||||
*/
|
||||
|
||||
|
||||
/* utility functions */
|
||||
|
||||
/*
|
||||
The following utility functions are implemented on top of the
|
||||
basic stream-oriented functions. To simplify the interface, some
|
||||
default options are assumed (compression level and memory usage,
|
||||
standard memory allocation functions). The source code of these
|
||||
utility functions can easily be modified if you need special options.
|
||||
*/
|
||||
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be at least 0.1% larger than
|
||||
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
|
||||
compressed buffer.
|
||||
This function can be used to compress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
compress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer.
|
||||
*/
|
||||
|
||||
/*
|
||||
Compresses the source buffer into the destination buffer. The level
|
||||
parameter has the same meaning as in deflateInit. sourceLen is the byte
|
||||
length of the source buffer. Upon entry, destLen is the total size of the
|
||||
destination buffer, which must be at least 0.1% larger than sourceLen plus
|
||||
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
|
||||
|
||||
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
|
||||
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
|
||||
Z_STREAM_ERROR if the level parameter is invalid.
|
||||
*/
|
||||
|
||||
/*
|
||||
Decompresses the source buffer into the destination buffer. sourceLen is
|
||||
the byte length of the source buffer. Upon entry, destLen is the total
|
||||
size of the destination buffer, which must be large enough to hold the
|
||||
entire uncompressed data. (The size of the uncompressed data must have
|
||||
been saved previously by the compressor and transmitted to the decompressor
|
||||
by some mechanism outside the scope of this compression library.)
|
||||
Upon exit, destLen is the actual size of the compressed buffer.
|
||||
This function can be used to decompress a whole file at once if the
|
||||
input file is mmap'ed.
|
||||
|
||||
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
|
||||
enough memory, Z_BUF_ERROR if there was not enough room in the output
|
||||
buffer, or Z_DATA_ERROR if the input data was corrupted.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Opens a gzip (.gz) file for reading or writing. The mode parameter
|
||||
is as in fopen ("rb" or "wb") but can also include a compression level
|
||||
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
|
||||
Huffman only compression as in "wb1h". (See the description
|
||||
of deflateInit2 for more information about the strategy parameter.)
|
||||
|
||||
gzopen can be used to read a file which is not in gzip format; in this
|
||||
case gzread will directly read from the file without decompression.
|
||||
|
||||
gzopen returns NULL if the file could not be opened or if there was
|
||||
insufficient memory to allocate the (de)compression state; errno
|
||||
can be checked to distinguish the two cases (if errno is zero, the
|
||||
zlib error is Z_MEM_ERROR). */
|
||||
|
||||
/*
|
||||
gzdopen() associates a gzFile with the file descriptor fd. File
|
||||
descriptors are obtained from calls like open, dup, creat, pipe or
|
||||
fileno (in the file has been previously opened with fopen).
|
||||
The mode parameter is as in gzopen.
|
||||
The next call of gzclose on the returned gzFile will also close the
|
||||
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
|
||||
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
|
||||
gzdopen returns NULL if there was insufficient memory to allocate
|
||||
the (de)compression state.
|
||||
*/
|
||||
|
||||
/*
|
||||
Dynamically update the compression level or strategy. See the description
|
||||
of deflateInit2 for the meaning of these parameters.
|
||||
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
|
||||
opened for writing.
|
||||
*/
|
||||
|
||||
/*
|
||||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
If the input file was not in gzip format, gzread copies the given number
|
||||
of bytes into the buffer.
|
||||
gzread returns the number of uncompressed bytes actually read (0 for
|
||||
end of file, -1 for error). */
|
||||
|
||||
/*
|
||||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of uncompressed bytes actually written
|
||||
(0 in case of error).
|
||||
*/
|
||||
|
||||
/*
|
||||
Converts, formats, and writes the args to the compressed file under
|
||||
control of the format string, as in fprintf. gzprintf returns the number of
|
||||
uncompressed bytes actually written (0 in case of error).
|
||||
*/
|
||||
|
||||
/*
|
||||
Writes the given null-terminated string to the compressed file, excluding
|
||||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
/*
|
||||
Reads bytes from the compressed file until len-1 characters are read, or
|
||||
a newline character is read and transferred to buf, or an end-of-file
|
||||
condition is encountered. The string is then terminated with a null
|
||||
character.
|
||||
gzgets returns buf, or Z_NULL in case of error.
|
||||
*/
|
||||
|
||||
/*
|
||||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
|
||||
/*
|
||||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
|
||||
/*
|
||||
Flushes all pending output into the compressed file. The parameter
|
||||
flush is as in the deflate() function. The return value is the zlib
|
||||
error number (see function gzerror below). gzflush returns Z_OK if
|
||||
the flush parameter is Z_FINISH and all output could be flushed.
|
||||
gzflush should be called only when strictly necessary because it can
|
||||
degrade compression.
|
||||
*/
|
||||
|
||||
/*
|
||||
Sets the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. The offset represents a number of bytes in the
|
||||
uncompressed data stream. The whence parameter is defined as in lseek(2);
|
||||
the value SEEK_END is not supported.
|
||||
If the file is opened for reading, this function is emulated but can be
|
||||
extremely slow. If the file is opened for writing, only forward seeks are
|
||||
supported; gzseek then compresses a sequence of zeroes up to the new
|
||||
starting position.
|
||||
|
||||
gzseek returns the resulting offset location as measured in bytes from
|
||||
the beginning of the uncompressed stream, or -1 in case of error, in
|
||||
particular if the file is opened for writing and the new starting position
|
||||
would be before the current position.
|
||||
*/
|
||||
|
||||
/*
|
||||
Rewinds the given file. This function is supported only for reading.
|
||||
|
||||
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
|
||||
*/
|
||||
|
||||
/*
|
||||
Returns the starting position for the next gzread or gzwrite on the
|
||||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
|
||||
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
|
||||
*/
|
||||
|
||||
/*
|
||||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
|
||||
/*
|
||||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state. The return value is the zlib
|
||||
error number (see function gzerror below).
|
||||
*/
|
||||
|
||||
/*
|
||||
Returns the error message for the last error which occurred on the
|
||||
given compressed file. errnum is set to zlib error number. If an
|
||||
error occurred in the file system and not in the compression library,
|
||||
errnum is set to Z_ERRNO and the application may consult errno
|
||||
to get the exact error code.
|
||||
*/
|
||||
|
||||
/* checksum functions */
|
||||
|
||||
/*
|
||||
These functions are not related to compression but are exported
|
||||
anyway because they might be useful in applications using the
|
||||
compression library.
|
||||
*/
|
||||
|
||||
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
|
||||
|
||||
/*
|
||||
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
|
||||
return the updated checksum. If buf is NULL, this function returns
|
||||
the required initial value for the checksum.
|
||||
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
|
||||
much faster. Usage example:
|
||||
|
||||
uLong adler = adler32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
adler = adler32(adler, buffer, length);
|
||||
}
|
||||
if (adler != original_adler) error();
|
||||
*/
|
||||
|
||||
/*
|
||||
Update a running crc with the bytes buf[0..len-1] and return the updated
|
||||
crc. If buf is NULL, this function returns the required initial value
|
||||
for the crc. Pre- and post-conditioning (one's complement) is performed
|
||||
within this function so it shouldn't be done by the application.
|
||||
Usage example:
|
||||
|
||||
uLong crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
crc = crc32(crc, buffer, length);
|
||||
}
|
||||
if (crc != original_crc) error();
|
||||
*/
|
||||
|
||||
|
||||
/* various hacks, don't look :) */
|
||||
|
||||
/* deflateInit and inflateInit are macros to allow checking the zlib version
|
||||
* and the compiler's view of z_stream:
|
||||
*/
|
||||
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
|
||||
const char *version, int stream_size));
|
||||
#define deflateInit(strm, level) \
|
||||
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit(strm) \
|
||||
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
|
||||
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
|
||||
(strategy), ZLIB_VERSION, sizeof(z_stream))
|
||||
#define inflateInit2(strm, windowBits) \
|
||||
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZLIB_H */
|
||||
@@ -0,0 +1,181 @@
|
||||
/* zutil.c -- target dependent utility functions for the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zutil.c,v 1.1 2002/11/20 19:19:19 bonefish Exp $ */
|
||||
|
||||
#include "zutil.h"
|
||||
|
||||
#ifndef STDC
|
||||
extern void exit OF((int));
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HAVE_MEMCPY
|
||||
|
||||
void zmemcpy(dest, source, len)
|
||||
Bytef* dest;
|
||||
const Bytef* source;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = *source++; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
|
||||
int zmemcmp(s1, s2, len)
|
||||
const Bytef* s1;
|
||||
const Bytef* s2;
|
||||
uInt len;
|
||||
{
|
||||
uInt j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void zmemzero(dest, len)
|
||||
Bytef* dest;
|
||||
uInt len;
|
||||
{
|
||||
if (len == 0) return;
|
||||
do {
|
||||
*dest++ = 0; /* ??? to be unrolled */
|
||||
} while (--len != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __TURBOC__
|
||||
#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
|
||||
/* Small and medium model in Turbo C are for now limited to near allocation
|
||||
* with reduced MAX_WBITS and MAX_MEM_LEVEL
|
||||
*/
|
||||
# define MY_ZCALLOC
|
||||
|
||||
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
|
||||
* and farmalloc(64K) returns a pointer with an offset of 8, so we
|
||||
* must fix the pointer. Warning: the pointer must be put back to its
|
||||
* original form in order to free it, use zcfree().
|
||||
*/
|
||||
|
||||
#define MAX_PTR 10
|
||||
/* 10*64K = 640K */
|
||||
|
||||
local int next_ptr = 0;
|
||||
|
||||
typedef struct ptr_table_s {
|
||||
voidpf org_ptr;
|
||||
voidpf new_ptr;
|
||||
} ptr_table;
|
||||
|
||||
local ptr_table table[MAX_PTR];
|
||||
/* This table is used to remember the original form of pointers
|
||||
* to large buffers (64K). Such pointers are normalized with a zero offset.
|
||||
* Since MSDOS is not a preemptive multitasking OS, this table is not
|
||||
* protected from concurrent access. This hack doesn't work anyway on
|
||||
* a protected system like OS/2. Use Microsoft C instead.
|
||||
*/
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
voidpf buf = opaque; /* just to make some compilers happy */
|
||||
ulg bsize = (ulg)items*size;
|
||||
|
||||
/* If we allocate less than 65520 bytes, we assume that farmalloc
|
||||
* will return a usable pointer which doesn't have to be normalized.
|
||||
*/
|
||||
if (bsize < 65520L) {
|
||||
buf = farmalloc(bsize);
|
||||
if (*(ush*)&buf != 0) return buf;
|
||||
} else {
|
||||
buf = farmalloc(bsize + 16L);
|
||||
}
|
||||
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
|
||||
table[next_ptr].org_ptr = buf;
|
||||
|
||||
/* Normalize the pointer to seg:0 */
|
||||
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
|
||||
*(ush*)&buf = 0;
|
||||
table[next_ptr++].new_ptr = buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
int n;
|
||||
if (*(ush*)&ptr != 0) { /* object < 64K */
|
||||
farfree(ptr);
|
||||
return;
|
||||
}
|
||||
/* Find the original pointer */
|
||||
for (n = 0; n < next_ptr; n++) {
|
||||
if (ptr != table[n].new_ptr) continue;
|
||||
|
||||
farfree(table[n].org_ptr);
|
||||
while (++n < next_ptr) {
|
||||
table[n-1] = table[n];
|
||||
}
|
||||
next_ptr--;
|
||||
return;
|
||||
}
|
||||
ptr = opaque; /* just to make some compilers happy */
|
||||
Assert(0, "zcfree: ptr not found");
|
||||
}
|
||||
#endif
|
||||
#endif /* __TURBOC__ */
|
||||
|
||||
|
||||
#if defined(M_I86) && !defined(__32BIT__)
|
||||
/* Microsoft C in 16-bit mode */
|
||||
|
||||
# define MY_ZCALLOC
|
||||
|
||||
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
|
||||
# define _halloc halloc
|
||||
# define _hfree hfree
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
return _halloc((long)items, size);
|
||||
}
|
||||
|
||||
void zcfree (voidpf opaque, voidpf ptr)
|
||||
{
|
||||
if (opaque) opaque = 0; /* to make compiler happy */
|
||||
_hfree(ptr);
|
||||
}
|
||||
|
||||
#endif /* MSC */
|
||||
|
||||
|
||||
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
|
||||
|
||||
#ifndef STDC
|
||||
extern voidp calloc OF((uInt items, uInt size));
|
||||
extern void free OF((voidpf ptr));
|
||||
#endif
|
||||
|
||||
voidpf zcalloc (opaque, items, size)
|
||||
voidpf opaque;
|
||||
unsigned items;
|
||||
unsigned size;
|
||||
{
|
||||
if (opaque) items += size - size; /* make compiler happy */
|
||||
return (voidpf)calloc(items, size);
|
||||
}
|
||||
|
||||
void zcfree (opaque, ptr)
|
||||
voidpf opaque;
|
||||
voidpf ptr;
|
||||
{
|
||||
free(ptr);
|
||||
if (opaque) return; /* make compiler happy */
|
||||
}
|
||||
|
||||
#endif /* MY_ZCALLOC */
|
||||
@@ -0,0 +1,216 @@
|
||||
/* zutil.h -- internal interface and configuration of the compression library
|
||||
* Copyright (C) 1995-2002 Jean-loup Gailly.
|
||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||
*/
|
||||
|
||||
/* WARNING: this file should *not* be used by applications. It is
|
||||
part of the implementation of the compression library and is
|
||||
subject to change. Applications should only use zlib.h.
|
||||
*/
|
||||
|
||||
/* @(#) $Id: zutil.h,v 1.1 2002/11/20 19:19:20 bonefish Exp $ */
|
||||
|
||||
#ifndef _Z_UTIL_H
|
||||
#define _Z_UTIL_H
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#ifdef STDC
|
||||
# include <stddef.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
#ifdef NO_ERRNO_H
|
||||
extern int errno;
|
||||
#else
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifndef local
|
||||
# define local static
|
||||
#endif
|
||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||
|
||||
typedef unsigned char uch;
|
||||
typedef uch FAR uchf;
|
||||
typedef unsigned short ush;
|
||||
typedef ush FAR ushf;
|
||||
typedef unsigned long ulg;
|
||||
|
||||
|
||||
#define ERR_RETURN(strm,err) \
|
||||
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||
/* To be used only when the state is known to be valid */
|
||||
|
||||
/* common constants */
|
||||
|
||||
#ifndef DEF_WBITS
|
||||
# define DEF_WBITS MAX_WBITS
|
||||
#endif
|
||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||
|
||||
#if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
#else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
#define STORED_BLOCK 0
|
||||
#define STATIC_TREES 1
|
||||
#define DYN_TREES 2
|
||||
/* The three kinds of block type */
|
||||
|
||||
#define MIN_MATCH 3
|
||||
#define MAX_MATCH 258
|
||||
/* The minimum and maximum match lengths */
|
||||
|
||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||
|
||||
/* target dependencies */
|
||||
|
||||
#ifdef MSDOS
|
||||
# define OS_CODE 0x00
|
||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||
/* Allow compilation with ANSI keywords only enabled */
|
||||
void _Cdecl farfree( void *block );
|
||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||
# else
|
||||
# include <alloc.h>
|
||||
# endif
|
||||
# else /* MSC or DJGPP */
|
||||
# include <malloc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef OS2
|
||||
# define OS_CODE 0x06
|
||||
#endif
|
||||
|
||||
#ifdef WIN32 /* Window 95 & Windows NT */
|
||||
# define OS_CODE 0x0b
|
||||
#endif
|
||||
|
||||
#if defined(VAXC) || defined(VMS)
|
||||
# define OS_CODE 0x02
|
||||
# define F_OPEN(name, mode) \
|
||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
# define OS_CODE 0x01
|
||||
#endif
|
||||
|
||||
#if defined(ATARI) || defined(atarist)
|
||||
# define OS_CODE 0x05
|
||||
#endif
|
||||
|
||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||
# define OS_CODE 0x07
|
||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||
# include <unix.h> /* for fdopen */
|
||||
# else
|
||||
# ifndef fdopen
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||
# define OS_CODE 0x0F
|
||||
#endif
|
||||
|
||||
#ifdef TOPS20
|
||||
# define OS_CODE 0x0a
|
||||
#endif
|
||||
|
||||
#if defined(_BEOS_) || defined(RISCOS)
|
||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||
# define fdopen(fd,type) _fdopen(fd,type)
|
||||
#endif
|
||||
|
||||
|
||||
/* Common defaults */
|
||||
|
||||
#ifndef OS_CODE
|
||||
# define OS_CODE 0x03 /* assume Unix */
|
||||
#endif
|
||||
|
||||
#ifndef F_OPEN
|
||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||
#endif
|
||||
|
||||
/* functions */
|
||||
|
||||
#ifdef HAVE_STRERROR
|
||||
extern char *strerror OF((int));
|
||||
# define zstrerror(errnum) strerror(errnum)
|
||||
#else
|
||||
# define zstrerror(errnum) ""
|
||||
#endif
|
||||
|
||||
#if defined(pyr)
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||
* You may have to use the same strategy for Borland C (untested).
|
||||
* The __SC__ check is for Symantec.
|
||||
*/
|
||||
# define NO_MEMCPY
|
||||
#endif
|
||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||
# define HAVE_MEMCPY
|
||||
#endif
|
||||
#ifdef HAVE_MEMCPY
|
||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||
# define zmemcpy _fmemcpy
|
||||
# define zmemcmp _fmemcmp
|
||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||
# else
|
||||
# define zmemcpy ft_memcpy
|
||||
# define zmemcmp memcmp
|
||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||
# endif
|
||||
#else
|
||||
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||
#endif
|
||||
|
||||
/* Diagnostic functions */
|
||||
#ifdef DEBUG
|
||||
# include <stdio.h>
|
||||
extern int z_verbose;
|
||||
extern void z_error OF((char *m));
|
||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||
#else
|
||||
# define Assert(cond,msg)
|
||||
# define Trace(x)
|
||||
# define Tracev(x)
|
||||
# define Tracevv(x)
|
||||
# define Tracec(c,x)
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
|
||||
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf,
|
||||
uInt len));
|
||||
local voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||
local void zcfree OF((voidpf opaque, voidpf ptr));
|
||||
|
||||
#define ZALLOC(strm, items, size) \
|
||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||
|
||||
#endif /* _Z_UTIL_H */
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "otlparse.h"
|
||||
#include "otlutils.h"
|
||||
|
||||
static void
|
||||
otl_string_ensure( OTL_String string,
|
||||
OTL_UInt count,
|
||||
OTL_Parser parser )
|
||||
{
|
||||
count += string->length;
|
||||
|
||||
if ( count > string->capacity )
|
||||
{
|
||||
OTL_UInt old_count = string->capacity;
|
||||
OTL_UInt new_count = old_count;
|
||||
OTL_Memory memory = parser->memory;
|
||||
|
||||
while ( new_count < count )
|
||||
new_count += (new_count >> 1) + 16;
|
||||
|
||||
if ( OTL_MEM_RENEW_ARRAY( string->glyphs, old_count, new_count ) )
|
||||
otl_parser_error( parser, OTL_Parse_Err_Memory );
|
||||
|
||||
string->capacity = new_count;
|
||||
}
|
||||
}
|
||||
|
||||
#define OTL_STRING_ENSURE(str,count,parser) \
|
||||
OTL_BEGIN_STMNT \
|
||||
if ( (str)->length + (count) > (str)>capacity ) \
|
||||
otl_string_ensure( str, count, parser ); \
|
||||
OTL_END_STMNT
|
||||
|
||||
|
||||
OTL_LOCALDEF( OTL_UInt )
|
||||
otl_parser_get_gindex( OTL_Parser parser )
|
||||
{
|
||||
OTL_String in = parser->str_in;
|
||||
|
||||
if ( in->cursor >= in->num_glyphs )
|
||||
otl_parser_error( parser, OTL_Err_Parser_Internal );
|
||||
|
||||
return in->str[ in->cursor ].gindex;
|
||||
}
|
||||
|
||||
|
||||
OTL_LOCALDEF( void )
|
||||
otl_parser_error( OTL_Parser parser,
|
||||
OTL_ParseError error; )
|
||||
{
|
||||
parser->error = error;
|
||||
otl_longjmp( parser->jump_buffer, 1 );
|
||||
}
|
||||
|
||||
#define OTL_PARSER_UNCOVERED(x) otl_parser_error( x, OTL_Parse_Err_UncoveredGlyph );
|
||||
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_check_property( OTL_Parser parser,
|
||||
OTL_UInt gindex,
|
||||
OTL_UInt flags,
|
||||
OTL_UInt *aproperty );
|
||||
|
||||
OTL_LOCALDEF( void )
|
||||
otl_parser_replace_1( OTL_Parser parser,
|
||||
OTL_UInt gindex )
|
||||
{
|
||||
OTL_String in = parser->str_in;
|
||||
OTL_String out = parser->str_out;
|
||||
OTL_StringGlyph glyph, in_glyph;
|
||||
|
||||
/* sanity check */
|
||||
if ( in == NULL ||
|
||||
out == NULL ||
|
||||
in->length == 0 ||
|
||||
in->cursor >= in->length )
|
||||
{
|
||||
/* report as internal error, since these should */
|
||||
/* never happen !! */
|
||||
otl_parser_error( parser, OTL_Err_Parse_Internal );
|
||||
}
|
||||
|
||||
OTL_STRING_ENSURE( out, 1, parser );
|
||||
glyph = out->glyphs + out->length;
|
||||
in_glyph = in->glyphs + in->cursor;
|
||||
|
||||
glyph->gindex = gindex;
|
||||
glyph->property = in_glyph->property;
|
||||
glyph->lig_component = in_glyph->lig_component;
|
||||
glyph->lig_id = in_glyph->lig_id;
|
||||
|
||||
out->length += 1;
|
||||
out->cursor = out->length;
|
||||
in->cursor += 1;
|
||||
}
|
||||
|
||||
OTL_LOCALDEF( void )
|
||||
otl_parser_replace_n( OTL_Parser parser,
|
||||
OTL_UInt count,
|
||||
OTL_Bytes indices )
|
||||
{
|
||||
OTL_UInt lig_component, lig_id, property;
|
||||
OTL_String in = parser->str_in;
|
||||
OTL_String out = parser->str_out;
|
||||
OTL_StringGlyph glyph, in_glyph;
|
||||
OTL_Bytes p = indices;
|
||||
|
||||
/* sanity check */
|
||||
if ( in == NULL ||
|
||||
out == NULL ||
|
||||
in->length == 0 ||
|
||||
in->cursor >= in->length )
|
||||
{
|
||||
/* report as internal error, since these should */
|
||||
/* never happen !! */
|
||||
otl_parser_error( parser, OTL_Err_Parse_Internal );
|
||||
}
|
||||
|
||||
OTL_STRING_ENSURE( out, count, parser );
|
||||
glyph = out->glyphs + out->length;
|
||||
in_glyph = in->glyphs + in->cursor;
|
||||
|
||||
glyph->gindex = gindex;
|
||||
|
||||
lig_component = in_glyph->lig_component;
|
||||
lig_id = in_glyph->lid_id;
|
||||
property = in_glyph->property;
|
||||
|
||||
for ( ; count > 0; count-- )
|
||||
{
|
||||
glyph->gindex = OTL_NEXT_USHORT(p);
|
||||
glyph->property = property;
|
||||
glyph->lig_component = lig_component;
|
||||
glyph->lig_id = lig_id;
|
||||
|
||||
out->length ++;
|
||||
}
|
||||
|
||||
out->cursor = out->length;
|
||||
in->cursor += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#ifndef __OTL_PARSER_H__
|
||||
#define __OTL_PARSER_H__
|
||||
|
||||
#include "otlayout.h"
|
||||
#include "otlgdef.h"
|
||||
#include "otlgsub.h"
|
||||
#include "otlgpos.h"
|
||||
|
||||
OTL_BEGIN_HEADER
|
||||
|
||||
typedef struct OTL_ParserRec_* OTL_Parser;
|
||||
|
||||
typedef struct OTL_StringRec_* OTL_String;
|
||||
|
||||
typedef struct OTL_StringGlyphRec_
|
||||
{
|
||||
OTL_UInt gindex;
|
||||
OTL_UInt properties;
|
||||
OTL_UInt lig_component;
|
||||
OTL_UInt lig_id;
|
||||
|
||||
} OTL_StringGlyphRec, *OTL_StringGlyph;
|
||||
|
||||
typedef struct OTL_StringRec_
|
||||
{
|
||||
OTL_StringGlyph glyphs;
|
||||
OTL_UInt cursor;
|
||||
OTL_UInt length;
|
||||
OTL_UInt capacity;
|
||||
|
||||
} OTL_StringRec;
|
||||
|
||||
typedef struct OTL_ParserRec_
|
||||
{
|
||||
OTL_Bytes tab_gdef;
|
||||
OTL_Bytes tab_gsub;
|
||||
OTL_Bytes tab_gpos;
|
||||
OTL_Bytes tab_base;
|
||||
OTL_Bytes tab_jstf;
|
||||
|
||||
OTL_Alternate alternate; /* external alternate handler */
|
||||
|
||||
OTL_UInt context_len;
|
||||
OTL_UInt markup_flags;
|
||||
|
||||
OTL_jmp_buf jump_buffer;
|
||||
OTL_Memory memory;
|
||||
OTL_Error error;
|
||||
|
||||
OTL_StringRec strings[2];
|
||||
OTL_String str_in;
|
||||
OTL_String str_out;
|
||||
|
||||
} OTL_ParserRec;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OTL_Err_Parser_Ok = 0,
|
||||
OTL_Err_Parser_InvalidData,
|
||||
OTL_Err_Parser_UncoveredGlyph
|
||||
|
||||
} OTL_ParseError;
|
||||
|
||||
OTL_LOCAL( OTL_UInt )
|
||||
otl_parser_get_gindex( OTL_Parser parser );
|
||||
|
||||
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_error( OTL_Parser parser, OTL_ParserError error );
|
||||
|
||||
#define OTL_PARSER_UNCOVERED(x) \
|
||||
otl_parser_error( x, OTL_Err_Parser_UncoveredGlyph )
|
||||
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_check_property( OTL_Parser parser,
|
||||
OTL_UInt gindex,
|
||||
OTL_UInt flags,
|
||||
OTL_UInt *aproperty );
|
||||
|
||||
/* copy current input glyph to output */
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_copy_1( OTL_Parser parser );
|
||||
|
||||
/* copy current input glyph to output, replacing its index */
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_replace_1( OTL_Parser parser,
|
||||
OTL_UInt gindex );
|
||||
|
||||
/* copy current input glyph to output, replacing it by several indices */
|
||||
/* read directly from the table */
|
||||
OTL_LOCAL( void )
|
||||
otl_parser_replace_n( OTL_Parser parser,
|
||||
OTL_UInt count,
|
||||
OTL_Bytes indices );
|
||||
|
||||
OTL_END_HEADER
|
||||
|
||||
#endif /* __OTL_PARSER_H__ */
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef __OTLAYOUT_UTILS_H__
|
||||
#define __OTLAYOUT_UTILS_H__
|
||||
|
||||
#include "otlayout.h"
|
||||
|
||||
OTL_BEGIN_HEADER
|
||||
|
||||
OTL_LOCAL( OTL_Error )
|
||||
otl_mem_alloc( OTL_Pointer* pblock,
|
||||
OTL_ULong size,
|
||||
OTL_Memory memory );
|
||||
|
||||
OTL_LOCAL( void )
|
||||
otl_mem_free( OTL_Pointer* pblock,
|
||||
OTL_Memory memory );
|
||||
|
||||
OTL_LOCAL( OTL_Error )
|
||||
otl_mem_realloc( OTL_Pointer *pblock,
|
||||
OTL_ULong cur_size,
|
||||
OTL_ULong new_size,
|
||||
OTL_Memory memory );
|
||||
|
||||
#define OTL_MEM_ALLOC(p,s) otl_mem_alloc( (void**)&(p), (s), memory )
|
||||
#define OTL_MEM_FREE(p) otl_mem_free( (void**)&(p), memory )
|
||||
#define OTL_MEM_REALLOC(p,c,n) otl_mem_realloc( (void**)&(p), (c), (s), memory )
|
||||
|
||||
#define OTL_MEM_NEW(p) OTL_MEM_ALLOC(p,sizeof(*(p)))
|
||||
#define OTL_MEM_NEW_ARRAY(p,c) OTL_MEM_ALLOC(p,(c)*sizeof(*(p)))
|
||||
#define OTL_MEM_RENEW_ARRAY(p,c,n) OTL_MEM_REALLOC(p,(c)*sizeof(*(p)),(n)*sizeof(*(p)))
|
||||
|
||||
OTL_END_HEADER
|
||||
|
||||
#endif /* __OTLAYOUT_UTILS_H__ */
|
||||
@@ -0,0 +1,670 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* pfrsbit.c */
|
||||
/* */
|
||||
/* FreeType PFR bitmap loader (body). */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#include "pfrsbit.h"
|
||||
#include "pfrload.h"
|
||||
#include FT_INTERNAL_DEBUG_H
|
||||
#include FT_INTERNAL_STREAM_H
|
||||
|
||||
#include "pfrerror.h"
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_pfr
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** PFR BIT WRITER *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
typedef struct PFR_BitWriter_
|
||||
{
|
||||
FT_Byte* line; /* current line start */
|
||||
FT_Int pitch; /* line size in bytes */
|
||||
FT_Int width; /* width in pixels/bits */
|
||||
FT_Int rows; /* number of remaining rows to scan */
|
||||
FT_Int total; /* total number of bits to draw */
|
||||
|
||||
} PFR_BitWriterRec, *PFR_BitWriter;
|
||||
|
||||
|
||||
static void
|
||||
pfr_bitwriter_init( PFR_BitWriter writer,
|
||||
FT_Bitmap* target,
|
||||
FT_Bool decreasing )
|
||||
{
|
||||
writer->line = target->buffer;
|
||||
writer->pitch = target->pitch;
|
||||
writer->width = target->width;
|
||||
writer->rows = target->rows;
|
||||
writer->total = writer->width * writer->rows;
|
||||
|
||||
if ( !decreasing )
|
||||
{
|
||||
writer->line += writer->pitch * ( target->rows-1 );
|
||||
writer->pitch = -writer->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pfr_bitwriter_decode_bytes( PFR_BitWriter writer,
|
||||
FT_Byte* p,
|
||||
FT_Byte* limit )
|
||||
{
|
||||
FT_Int n, reload;
|
||||
FT_Int left = writer->width;
|
||||
FT_Byte* cur = writer->line;
|
||||
FT_UInt mask = 0x80;
|
||||
FT_UInt val = 0;
|
||||
FT_UInt c = 0;
|
||||
|
||||
|
||||
n = (FT_Int)( limit - p ) * 8;
|
||||
if ( n > writer->total )
|
||||
n = writer->total;
|
||||
|
||||
reload = n & 7;
|
||||
|
||||
for ( ; n > 0; n-- )
|
||||
{
|
||||
if ( ( n & 7 ) == reload )
|
||||
val = *p++;
|
||||
|
||||
if ( val & 0x80 )
|
||||
c |= mask;
|
||||
|
||||
val <<= 1;
|
||||
mask >>= 1;
|
||||
|
||||
if ( --left <= 0 )
|
||||
{
|
||||
cur[0] = (FT_Byte)c;
|
||||
left = writer->width;
|
||||
mask = 0x80;
|
||||
|
||||
writer->line += writer->pitch;
|
||||
cur = writer->line;
|
||||
c = 0;
|
||||
}
|
||||
else if ( mask == 0 )
|
||||
{
|
||||
cur[0] = c;
|
||||
mask = 0x80;
|
||||
c = 0;
|
||||
cur ++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( mask != 0x80 )
|
||||
cur[0] = c;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pfr_bitwriter_decode_rle1( PFR_BitWriter writer,
|
||||
FT_Byte* p,
|
||||
FT_Byte* limit )
|
||||
{
|
||||
FT_Int n, phase, count, counts[2], reload;
|
||||
FT_Int left = writer->width;
|
||||
FT_Byte* cur = writer->line;
|
||||
FT_UInt mask = 0x80;
|
||||
FT_UInt c = 0;
|
||||
|
||||
|
||||
n = writer->total;
|
||||
|
||||
phase = 1;
|
||||
counts[0] = 0;
|
||||
counts[1] = 0;
|
||||
count = 0;
|
||||
reload = 1;
|
||||
|
||||
for ( ; n > 0; n-- )
|
||||
{
|
||||
if ( reload )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( phase )
|
||||
{
|
||||
FT_Int v;
|
||||
|
||||
|
||||
if ( p >= limit )
|
||||
break;
|
||||
|
||||
v = *p++;
|
||||
counts[0] = v >> 4;
|
||||
counts[1] = v & 15;
|
||||
phase = 0;
|
||||
count = counts[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
phase = 1;
|
||||
count = counts[1];
|
||||
}
|
||||
|
||||
} while ( count == 0 );
|
||||
}
|
||||
|
||||
if ( phase )
|
||||
c |= mask;
|
||||
|
||||
mask >>= 1;
|
||||
|
||||
if ( --left <= 0 )
|
||||
{
|
||||
cur[0] = (FT_Byte) c;
|
||||
left = writer->width;
|
||||
mask = 0x80;
|
||||
|
||||
writer->line += writer->pitch;
|
||||
cur = writer->line;
|
||||
c = 0;
|
||||
}
|
||||
else if ( mask == 0 )
|
||||
{
|
||||
cur[0] = c;
|
||||
mask = 0x80;
|
||||
c = 0;
|
||||
cur ++;
|
||||
}
|
||||
|
||||
reload = ( --count <= 0 );
|
||||
}
|
||||
|
||||
if ( mask != 0x80 )
|
||||
cur[0] = (FT_Byte) c;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pfr_bitwriter_decode_rle2( PFR_BitWriter writer,
|
||||
FT_Byte* p,
|
||||
FT_Byte* limit )
|
||||
{
|
||||
FT_Int n, phase, count, reload;
|
||||
FT_Int left = writer->width;
|
||||
FT_Byte* cur = writer->line;
|
||||
FT_UInt mask = 0x80;
|
||||
FT_UInt c = 0;
|
||||
|
||||
|
||||
n = writer->total;
|
||||
|
||||
phase = 1;
|
||||
count = 0;
|
||||
reload = 1;
|
||||
|
||||
for ( ; n > 0; n-- )
|
||||
{
|
||||
if ( reload )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( p >= limit )
|
||||
break;
|
||||
|
||||
count = *p++;
|
||||
phase = phase ^ 1;
|
||||
|
||||
} while ( count == 0 );
|
||||
}
|
||||
|
||||
if ( phase )
|
||||
c |= mask;
|
||||
|
||||
mask >>= 1;
|
||||
|
||||
if ( --left <= 0 )
|
||||
{
|
||||
cur[0] = (FT_Byte) c;
|
||||
c = 0;
|
||||
mask = 0x80;
|
||||
left = writer->width;
|
||||
|
||||
writer->line += writer->pitch;
|
||||
cur = writer->line;
|
||||
}
|
||||
else if ( mask == 0 )
|
||||
{
|
||||
cur[0] = c;
|
||||
c = 0;
|
||||
mask = 0x80;
|
||||
cur ++;
|
||||
}
|
||||
|
||||
reload = ( --count <= 0 );
|
||||
}
|
||||
|
||||
if ( mask != 0x80 )
|
||||
cur[0] = (FT_Byte) c;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** BITMAP DATA DECODING *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
static void
|
||||
pfr_lookup_bitmap_data( FT_Byte* base,
|
||||
FT_Byte* limit,
|
||||
FT_Int count,
|
||||
FT_Byte flags,
|
||||
FT_UInt char_code,
|
||||
FT_ULong* found_offset,
|
||||
FT_ULong* found_size )
|
||||
{
|
||||
FT_UInt left, right, char_len;
|
||||
FT_Bool two = flags & 1;
|
||||
FT_Byte* buff;
|
||||
|
||||
|
||||
char_len = 4;
|
||||
if ( two ) char_len += 1;
|
||||
if ( flags & 2 ) char_len += 1;
|
||||
if ( flags & 4 ) char_len += 1;
|
||||
|
||||
left = 0;
|
||||
right = count;
|
||||
|
||||
while ( left < right )
|
||||
{
|
||||
FT_UInt middle, code;
|
||||
|
||||
|
||||
middle = ( left + right ) >> 1;
|
||||
buff = base + middle * char_len;
|
||||
|
||||
/* check that we are not outside of the table -- */
|
||||
/* this is possible with broken fonts... */
|
||||
if ( buff + char_len > limit )
|
||||
goto Fail;
|
||||
|
||||
if ( two )
|
||||
code = PFR_NEXT_USHORT( buff );
|
||||
else
|
||||
code = PFR_NEXT_BYTE( buff );
|
||||
|
||||
if ( code == char_code )
|
||||
goto Found_It;
|
||||
|
||||
if ( code < char_code )
|
||||
left = middle;
|
||||
else
|
||||
right = middle;
|
||||
}
|
||||
|
||||
Fail:
|
||||
/* Not found */
|
||||
*found_size = 0;
|
||||
*found_offset = 0;
|
||||
return;
|
||||
|
||||
Found_It:
|
||||
if ( flags & 2 )
|
||||
*found_size = PFR_NEXT_USHORT( buff );
|
||||
else
|
||||
*found_size = PFR_NEXT_BYTE( buff );
|
||||
|
||||
if ( flags & 4 )
|
||||
*found_offset = PFR_NEXT_ULONG( buff );
|
||||
else
|
||||
*found_offset = PFR_NEXT_USHORT( buff );
|
||||
}
|
||||
|
||||
|
||||
/* load bitmap metrics. "*padvance" must be set to the default value */
|
||||
/* before calling this function... */
|
||||
/* */
|
||||
static FT_Error
|
||||
pfr_load_bitmap_metrics( FT_Byte** pdata,
|
||||
FT_Byte* limit,
|
||||
FT_Long scaled_advance,
|
||||
FT_Long *axpos,
|
||||
FT_Long *aypos,
|
||||
FT_UInt *axsize,
|
||||
FT_UInt *aysize,
|
||||
FT_Long *aadvance,
|
||||
FT_UInt *aformat )
|
||||
{
|
||||
FT_Error error = 0;
|
||||
FT_Byte flags;
|
||||
FT_Char b;
|
||||
FT_Byte* p = *pdata;
|
||||
FT_Long xpos, ypos, advance;
|
||||
FT_UInt xsize, ysize;
|
||||
|
||||
|
||||
PFR_CHECK( 1 );
|
||||
flags = PFR_NEXT_BYTE( p );
|
||||
|
||||
xpos = 0;
|
||||
ypos = 0;
|
||||
xsize = 0;
|
||||
ysize = 0;
|
||||
advance = 0;
|
||||
|
||||
switch ( flags & 3 )
|
||||
{
|
||||
case 0:
|
||||
PFR_CHECK( 1 );
|
||||
b = PFR_NEXT_INT8( p );
|
||||
xpos = b >> 4;
|
||||
ypos = ( (FT_Char)( b << 4 ) ) >> 4;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PFR_CHECK( 2 );
|
||||
xpos = PFR_NEXT_INT8( p );
|
||||
ypos = PFR_NEXT_INT8( p );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PFR_CHECK( 4 );
|
||||
xpos = PFR_NEXT_SHORT( p );
|
||||
ypos = PFR_NEXT_SHORT( p );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PFR_CHECK( 6 );
|
||||
xpos = PFR_NEXT_LONG( p );
|
||||
ypos = PFR_NEXT_LONG( p );
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
flags >>= 2;
|
||||
switch ( flags & 3 )
|
||||
{
|
||||
case 0:
|
||||
/* blank image */
|
||||
xsize = 0;
|
||||
ysize = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PFR_CHECK( 1 );
|
||||
b = PFR_NEXT_BYTE( p );
|
||||
xsize = ( b >> 4 ) & 0xF;
|
||||
ysize = b & 0xF;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PFR_CHECK( 2 );
|
||||
xsize = PFR_NEXT_BYTE( p );
|
||||
ysize = PFR_NEXT_BYTE( p );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PFR_CHECK( 4 );
|
||||
xsize = PFR_NEXT_USHORT( p );
|
||||
ysize = PFR_NEXT_USHORT( p );
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
flags >>= 2;
|
||||
switch ( flags & 3 )
|
||||
{
|
||||
case 0:
|
||||
advance = scaled_advance;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PFR_CHECK( 1 );
|
||||
advance = PFR_NEXT_INT8( p ) << 8;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PFR_CHECK( 2 );
|
||||
advance = PFR_NEXT_SHORT( p );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PFR_CHECK( 3 );
|
||||
advance = PFR_NEXT_LONG( p );
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
*axpos = xpos;
|
||||
*aypos = ypos;
|
||||
*axsize = xsize;
|
||||
*aysize = ysize;
|
||||
*aadvance = advance;
|
||||
*aformat = flags >> 2;
|
||||
*pdata = p;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
|
||||
Too_Short:
|
||||
error = PFR_Err_Invalid_Table;
|
||||
FT_ERROR(( "pfr_load_bitmap_metrics: invalid glyph data\n" ));
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
pfr_load_bitmap_bits( FT_Byte* p,
|
||||
FT_Byte* limit,
|
||||
FT_UInt format,
|
||||
FT_UInt decreasing,
|
||||
FT_Bitmap* target )
|
||||
{
|
||||
FT_Error error = 0;
|
||||
PFR_BitWriterRec writer;
|
||||
|
||||
|
||||
if ( target->rows > 0 && target->width > 0 )
|
||||
{
|
||||
pfr_bitwriter_init( &writer, target, decreasing );
|
||||
|
||||
switch ( format )
|
||||
{
|
||||
case 0: /* packed bits */
|
||||
pfr_bitwriter_decode_bytes( &writer, p, limit );
|
||||
break;
|
||||
|
||||
case 1: /* RLE1 */
|
||||
pfr_bitwriter_decode_rle1( &writer, p, limit );
|
||||
break;
|
||||
|
||||
case 2: /* RLE2 */
|
||||
pfr_bitwriter_decode_rle2( &writer, p, limit );
|
||||
break;
|
||||
|
||||
default:
|
||||
FT_ERROR(( "pfr_read_bitmap_data: invalid image type\n" ));
|
||||
error = FT_Err_Invalid_File_Format;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/***** *****/
|
||||
/***** BITMAP LOADING *****/
|
||||
/***** *****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
FT_LOCAL( FT_Error )
|
||||
pfr_slot_load_bitmap( PFR_Slot glyph,
|
||||
PFR_Size size,
|
||||
FT_UInt glyph_index )
|
||||
{
|
||||
FT_Error error;
|
||||
PFR_Face face = (PFR_Face) glyph->root.face;
|
||||
FT_Stream stream = face->root.stream;
|
||||
PFR_PhyFont phys = &face->phy_font;
|
||||
FT_ULong gps_offset;
|
||||
FT_ULong gps_size;
|
||||
PFR_Char character;
|
||||
PFR_Strike strike;
|
||||
|
||||
|
||||
character = &phys->chars[glyph_index];
|
||||
|
||||
/* Look-up a bitmap strike corresponding to the current */
|
||||
/* character dimensions */
|
||||
{
|
||||
FT_UInt n;
|
||||
|
||||
|
||||
strike = phys->strikes;
|
||||
for ( n = 0; n < phys->num_strikes; n++ )
|
||||
{
|
||||
if ( strike->x_ppm == (FT_UInt)size->root.metrics.x_ppem &&
|
||||
strike->y_ppm == (FT_UInt)size->root.metrics.y_ppem )
|
||||
{
|
||||
goto Found_Strike;
|
||||
}
|
||||
|
||||
strike++;
|
||||
}
|
||||
|
||||
/* couldn't find it */
|
||||
return FT_Err_Invalid_Argument;
|
||||
}
|
||||
|
||||
Found_Strike:
|
||||
|
||||
/* Now lookup the glyph's position within the file */
|
||||
{
|
||||
FT_UInt char_len;
|
||||
|
||||
|
||||
char_len = 4;
|
||||
if ( strike->flags & 1 ) char_len += 1;
|
||||
if ( strike->flags & 2 ) char_len += 1;
|
||||
if ( strike->flags & 4 ) char_len += 1;
|
||||
|
||||
/* Access data directly in the frame to speed lookups */
|
||||
if ( FT_STREAM_SEEK( phys->bct_offset + strike->bct_offset ) ||
|
||||
FT_FRAME_ENTER( char_len * strike->num_bitmaps ) )
|
||||
goto Exit;
|
||||
|
||||
pfr_lookup_bitmap_data( stream->cursor,
|
||||
stream->limit,
|
||||
strike->num_bitmaps,
|
||||
strike->flags,
|
||||
character->char_code,
|
||||
&gps_offset,
|
||||
&gps_size );
|
||||
|
||||
FT_FRAME_EXIT();
|
||||
|
||||
if ( gps_size == 0 )
|
||||
{
|
||||
/* Could not find a bitmap program string for this glyph */
|
||||
error = FT_Err_Invalid_Argument;
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the bitmap metrics */
|
||||
{
|
||||
FT_Long xpos, ypos, advance;
|
||||
FT_UInt xsize, ysize, format;
|
||||
FT_Byte* p;
|
||||
|
||||
|
||||
advance = FT_MulDiv( size->root.metrics.x_ppem << 8,
|
||||
character->advance,
|
||||
phys->metrics_resolution );
|
||||
|
||||
/* XXX: handle linearHoriAdvance correctly! */
|
||||
|
||||
if ( FT_STREAM_SEEK( face->header.gps_section_offset + gps_offset ) ||
|
||||
FT_FRAME_ENTER( gps_size ) )
|
||||
goto Exit;
|
||||
|
||||
p = stream->cursor;
|
||||
error = pfr_load_bitmap_metrics( &p, stream->limit,
|
||||
advance,
|
||||
&xpos, &ypos,
|
||||
&xsize, &ysize,
|
||||
&advance, &format );
|
||||
if ( !error )
|
||||
{
|
||||
glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
|
||||
|
||||
/* Set up glyph bitmap and metrics */
|
||||
glyph->root.bitmap.width = (FT_Int)xsize;
|
||||
glyph->root.bitmap.rows = (FT_Int)ysize;
|
||||
glyph->root.bitmap.pitch = (FT_Long)( xsize + 7 ) >> 3;
|
||||
glyph->root.bitmap.pixel_mode = FT_PIXEL_MODE_MONO;
|
||||
|
||||
glyph->root.metrics.width = (FT_Long)xsize << 6;
|
||||
glyph->root.metrics.height = (FT_Long)ysize << 6;
|
||||
glyph->root.metrics.horiBearingX = xpos << 6;
|
||||
glyph->root.metrics.horiBearingY = ypos << 6;
|
||||
glyph->root.metrics.horiAdvance = ( ( advance >> 2 ) + 32 ) & -64;
|
||||
glyph->root.metrics.vertBearingX = - glyph->root.metrics.width >> 1;
|
||||
glyph->root.metrics.vertBearingY = 0;
|
||||
glyph->root.metrics.vertAdvance = size->root.metrics.height;
|
||||
|
||||
glyph->root.bitmap_left = xpos;
|
||||
glyph->root.bitmap_top = ypos + ysize;
|
||||
|
||||
/* Allocate and read bitmap data */
|
||||
{
|
||||
FT_Memory memory = face->root.memory;
|
||||
FT_Long len = glyph->root.bitmap.pitch * ysize;
|
||||
|
||||
|
||||
if ( !FT_ALLOC( glyph->root.bitmap.buffer, len ) )
|
||||
{
|
||||
error = pfr_load_bitmap_bits( p,
|
||||
stream->limit,
|
||||
format,
|
||||
face->header.color_flags & 2,
|
||||
&glyph->root.bitmap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FT_FRAME_EXIT();
|
||||
}
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
/* END */
|
||||
@@ -0,0 +1,36 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* pfrsbit.h */
|
||||
/* */
|
||||
/* FreeType PFR bitmap loader (specification). */
|
||||
/* */
|
||||
/* Copyright 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __PFRSBIT_H__
|
||||
#define __PFRSBIT_H__
|
||||
|
||||
#include "pfrobjs.h"
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
FT_LOCAL( FT_Error )
|
||||
pfr_slot_load_bitmap( PFR_Slot glyph,
|
||||
PFR_Size size,
|
||||
FT_UInt glyph_index );
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* __PFR_SBIT_H__ */
|
||||
|
||||
|
||||
/* END */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,254 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* pshalgo3.h */
|
||||
/* */
|
||||
/* PostScript hinting algorithm 3 (specification). */
|
||||
/* */
|
||||
/* Copyright 2001, 2002 by */
|
||||
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __PSHALGO3_H__
|
||||
#define __PSHALGO3_H__
|
||||
|
||||
|
||||
#include "pshrec.h"
|
||||
#include "pshglob.h"
|
||||
#include FT_TRIGONOMETRY_H
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/* handle to Hint structure */
|
||||
typedef struct PSH3_HintRec_* PSH3_Hint;
|
||||
|
||||
/* hint bit-flags */
|
||||
typedef enum
|
||||
{
|
||||
PSH3_HINT_GHOST = PS_HINT_FLAG_GHOST,
|
||||
PSH3_HINT_BOTTOM = PS_HINT_FLAG_BOTTOM,
|
||||
PSH3_HINT_ACTIVE = 4,
|
||||
PSH3_HINT_FITTED = 8
|
||||
|
||||
} PSH3_Hint_Flags;
|
||||
|
||||
|
||||
#define psh3_hint_is_active( x ) ( ( (x)->flags & PSH3_HINT_ACTIVE ) != 0 )
|
||||
#define psh3_hint_is_ghost( x ) ( ( (x)->flags & PSH3_HINT_GHOST ) != 0 )
|
||||
#define psh3_hint_is_fitted( x ) ( ( (x)->flags & PSH3_HINT_FITTED ) != 0 )
|
||||
|
||||
#define psh3_hint_activate( x ) (x)->flags |= PSH3_HINT_ACTIVE
|
||||
#define psh3_hint_deactivate( x ) (x)->flags &= ~PSH3_HINT_ACTIVE
|
||||
#define psh3_hint_set_fitted( x ) (x)->flags |= PSH3_HINT_FITTED
|
||||
|
||||
/* hint structure */
|
||||
typedef struct PSH3_HintRec_
|
||||
{
|
||||
FT_Int org_pos;
|
||||
FT_Int org_len;
|
||||
FT_Pos cur_pos;
|
||||
FT_Pos cur_len;
|
||||
FT_UInt flags;
|
||||
PSH3_Hint parent;
|
||||
FT_Int order;
|
||||
|
||||
} PSH3_HintRec;
|
||||
|
||||
|
||||
/* this is an interpolation zone used for strong points; */
|
||||
/* weak points are interpolated according to their strong */
|
||||
/* neighbours */
|
||||
typedef struct PSH3_ZoneRec_
|
||||
{
|
||||
FT_Fixed scale;
|
||||
FT_Fixed delta;
|
||||
FT_Pos min;
|
||||
FT_Pos max;
|
||||
|
||||
} PSH3_ZoneRec, *PSH3_Zone;
|
||||
|
||||
|
||||
typedef struct PSH3_Hint_TableRec_
|
||||
{
|
||||
FT_UInt max_hints;
|
||||
FT_UInt num_hints;
|
||||
PSH3_Hint hints;
|
||||
PSH3_Hint* sort;
|
||||
PSH3_Hint* sort_global;
|
||||
FT_UInt num_zones;
|
||||
PSH3_ZoneRec* zones;
|
||||
PSH3_Zone zone;
|
||||
PS_Mask_Table hint_masks;
|
||||
PS_Mask_Table counter_masks;
|
||||
|
||||
} PSH3_Hint_TableRec, *PSH3_Hint_Table;
|
||||
|
||||
|
||||
typedef struct PSH3_PointRec_* PSH3_Point;
|
||||
typedef struct PSH3_ContourRec_* PSH3_Contour;
|
||||
|
||||
enum
|
||||
{
|
||||
PSH3_DIR_NONE = 4,
|
||||
PSH3_DIR_UP = -1,
|
||||
PSH3_DIR_DOWN = 1,
|
||||
PSH3_DIR_LEFT = -2,
|
||||
PSH3_DIR_RIGHT = 2
|
||||
};
|
||||
|
||||
#define PSH3_DIR_HORIZONTAL 2
|
||||
#define PSH3_DIR_VERTICAL 1
|
||||
|
||||
#define PSH3_DIR_COMPARE( d1, d2 ) ( (d1) == (d2) || (d1) == -(d2) )
|
||||
#define PSH3_DIR_IS_HORIZONTAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_HORIZONTAL )
|
||||
#define PSH3_DIR_IS_VERTICAL( d ) PSH3_DIR_COMPARE( d, PSH3_DIR_VERTICAL )
|
||||
|
||||
|
||||
/* the following bit-flags are computed once by the glyph */
|
||||
/* analyzer, for both dimensions */
|
||||
enum
|
||||
{
|
||||
PSH3_POINT_OFF = 1, /* point is off the curve */
|
||||
PSH3_POINT_SMOOTH = 2, /* point is smooth */
|
||||
PSH3_POINT_INFLEX = 4 /* point is inflection */
|
||||
};
|
||||
|
||||
#define psh3_point_is_smooth( p ) ( (p)->flags & PSH3_POINT_SMOOTH )
|
||||
#define psh3_point_is_off( p ) ( (p)->flags & PSH3_POINT_OFF )
|
||||
#define psh3_point_is_inflex( p ) ( (p)->flags & PSH3_POINT_INFLEX )
|
||||
|
||||
#define psh3_point_set_smooth( p ) (p)->flags |= PSH3_POINT_SMOOTH
|
||||
#define psh3_point_set_off( p ) (p)->flags |= PSH3_POINT_OFF
|
||||
#define psh3_point_set_inflex( p ) (p)->flags |= PSH3_POINT_INFLEX
|
||||
|
||||
/* the following bit-flags are re-computed for each dimension */
|
||||
enum
|
||||
{
|
||||
PSH3_POINT_STRONG = 16, /* point is strong */
|
||||
PSH3_POINT_FITTED = 32, /* point is already fitted */
|
||||
PSH3_POINT_EXTREMUM = 64, /* point is local extremum */
|
||||
PSH3_POINT_POSITIVE = 128, /* extremum has positive contour flow */
|
||||
PSH3_POINT_NEGATIVE = 256, /* extremum has negative contour flow */
|
||||
PSH3_POINT_EDGE_MIN = 512, /* point is aligned to left/bottom stem edge */
|
||||
PSH3_POINT_EDGE_MAX = 1024 /* point is aligned to top/right stem edge */
|
||||
};
|
||||
|
||||
#define psh3_point_is_strong( p ) ( (p)->flags2 & PSH3_POINT_STRONG )
|
||||
#define psh3_point_is_fitted( p ) ( (p)->flags2 & PSH3_POINT_FITTED )
|
||||
#define psh3_point_is_extremum( p ) ( (p)->flags2 & PSH3_POINT_EXTREMUM )
|
||||
#define psh3_point_is_positive( p ) ( (p)->flags2 & PSH3_POINT_POSITIVE )
|
||||
#define psh3_point_is_negative( p ) ( (p)->flags2 & PSH3_POINT_NEGATIVE )
|
||||
#define psh3_point_is_edge_min( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MIN )
|
||||
#define psh3_point_is_edge_max( p ) ( (p)->flags2 & PSH3_POINT_EDGE_MAX )
|
||||
|
||||
#define psh3_point_set_strong( p ) (p)->flags2 |= PSH3_POINT_STRONG
|
||||
#define psh3_point_set_fitted( p ) (p)->flags2 |= PSH3_POINT_FITTED
|
||||
#define psh3_point_set_extremum( p ) (p)->flags2 |= PSH3_POINT_EXTREMUM
|
||||
#define psh3_point_set_positive( p ) (p)->flags2 |= PSH3_POINT_POSITIVE
|
||||
#define psh3_point_set_negative( p ) (p)->flags2 |= PSH3_POINT_NEGATIVE
|
||||
#define psh3_point_set_edge_min( p ) (p)->flags2 |= PSH3_POINT_EDGE_MIN
|
||||
#define psh3_point_set_edge_max( p ) (p)->flags2 |= PSH3_POINT_EDGE_MAX
|
||||
|
||||
|
||||
typedef struct PSH3_PointRec_
|
||||
{
|
||||
PSH3_Point prev;
|
||||
PSH3_Point next;
|
||||
PSH3_Contour contour;
|
||||
FT_UInt flags;
|
||||
FT_UInt flags2;
|
||||
FT_Char dir_in;
|
||||
FT_Char dir_out;
|
||||
FT_Angle angle_in;
|
||||
FT_Angle angle_out;
|
||||
PSH3_Hint hint;
|
||||
FT_Pos org_u;
|
||||
FT_Pos org_v;
|
||||
FT_Pos cur_u;
|
||||
#ifdef DEBUG_HINTER
|
||||
FT_Pos org_x;
|
||||
FT_Pos cur_x;
|
||||
FT_Pos org_y;
|
||||
FT_Pos cur_y;
|
||||
FT_UInt flags_x;
|
||||
FT_UInt flags_y;
|
||||
#endif
|
||||
|
||||
} PSH3_PointRec;
|
||||
|
||||
|
||||
#define PSH3_POINT_EQUAL_ORG( a, b ) ( (a)->org_u == (b)->org_u && \
|
||||
(a)->org_v == (b)->org_v )
|
||||
|
||||
#define PSH3_POINT_ANGLE( a, b ) FT_Atan2( (b)->org_u - (a)->org_u, \
|
||||
(b)->org_v - (a)->org_v )
|
||||
|
||||
typedef struct PSH3_ContourRec_
|
||||
{
|
||||
PSH3_Point start;
|
||||
FT_UInt count;
|
||||
|
||||
} PSH3_ContourRec;
|
||||
|
||||
|
||||
typedef struct PSH3_GlyphRec_
|
||||
{
|
||||
FT_UInt num_points;
|
||||
FT_UInt num_contours;
|
||||
|
||||
PSH3_Point points;
|
||||
PSH3_Contour contours;
|
||||
|
||||
FT_Memory memory;
|
||||
FT_Outline* outline;
|
||||
PSH_Globals globals;
|
||||
PSH3_Hint_TableRec hint_tables[2];
|
||||
|
||||
FT_Bool vertical;
|
||||
FT_Int major_dir;
|
||||
FT_Int minor_dir;
|
||||
|
||||
FT_Bool do_horz_hints;
|
||||
FT_Bool do_vert_hints;
|
||||
FT_Bool do_horz_snapping;
|
||||
FT_Bool do_vert_snapping;
|
||||
|
||||
} PSH3_GlyphRec, *PSH3_Glyph;
|
||||
|
||||
|
||||
#ifdef DEBUG_HINTER
|
||||
extern PSH3_Hint_Table ps3_debug_hint_table;
|
||||
|
||||
typedef void
|
||||
(*PSH3_HintFunc)( PSH3_Hint hint,
|
||||
FT_Bool vertical );
|
||||
|
||||
extern PSH3_HintFunc ps3_debug_hint_func;
|
||||
|
||||
extern PSH3_Glyph ps3_debug_glyph;
|
||||
#endif
|
||||
|
||||
|
||||
extern FT_Error
|
||||
ps3_hints_apply( PS_Hints ps_hints,
|
||||
FT_Outline* outline,
|
||||
PSH_Globals globals,
|
||||
FT_Render_Mode hint_mode );
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
|
||||
#endif /* __PSHALGO3_H__ */
|
||||
|
||||
|
||||
/* END */
|
||||
@@ -0,0 +1,547 @@
|
||||
#
|
||||
# this file contains routines used to parse the content of documentation
|
||||
# comment block and build a more structured objects out of them
|
||||
#
|
||||
|
||||
from sources import *
|
||||
from utils import *
|
||||
import string, re
|
||||
|
||||
|
||||
# this regular expresion is used to detect code sequences. these
|
||||
# are simply code fragments embedded in '{' and '}' like in:
|
||||
#
|
||||
# {
|
||||
# x = y + z;
|
||||
# if ( zookoo == 2 )
|
||||
# {
|
||||
# foobar();
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# note that identation of the starting and ending accolades must be
|
||||
# exactly the same. the code sequence can contain accolades at greater
|
||||
# indentation
|
||||
#
|
||||
re_code_start = re.compile( r"(\s*){\s*$" )
|
||||
re_code_end = re.compile( r"(\s*)}\s*$" )
|
||||
|
||||
|
||||
# this regular expression is used to isolate identifiers from
|
||||
# other text
|
||||
#
|
||||
re_identifier = re.compile( r'(\w*)' )
|
||||
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# The DocCode class is used to store source code lines.
|
||||
#
|
||||
# 'self.lines' contains a set of source code lines that will be dumped as
|
||||
# HTML in a <PRE> tag.
|
||||
#
|
||||
# The object is filled line by line by the parser; it strips the leading
|
||||
# "margin" space from each input line before storing it in 'self.lines'.
|
||||
#
|
||||
class DocCode:
|
||||
|
||||
def __init__( self, margin, lines ):
|
||||
self.lines = []
|
||||
self.words = None
|
||||
|
||||
# remove margin spaces
|
||||
for l in lines:
|
||||
if string.strip( l[:margin] ) == "":
|
||||
l = l[margin:]
|
||||
self.lines.append( l )
|
||||
|
||||
def dump( self, prefix = "", width=60 ):
|
||||
for l in self.lines:
|
||||
print prefix + l
|
||||
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# The DocPara class is used to store "normal" text paragraph.
|
||||
#
|
||||
# 'self.words' contains the list of words that make up the paragraph
|
||||
#
|
||||
class DocPara:
|
||||
|
||||
def __init__( self, lines ):
|
||||
self.lines = None
|
||||
self.words = []
|
||||
for l in lines:
|
||||
l = string.strip(l)
|
||||
self.words.extend( string.split( l ) )
|
||||
|
||||
def dump( self, prefix = "", width = 60 ):
|
||||
cur = "" # current line
|
||||
col = 0 # current width
|
||||
|
||||
for word in self.words:
|
||||
ln = len(word)
|
||||
if col > 0:
|
||||
ln = ln+1
|
||||
|
||||
if col + ln > width:
|
||||
print prefix + cur
|
||||
cur = word
|
||||
col = len(word)
|
||||
else:
|
||||
if col > 0:
|
||||
cur = cur + " "
|
||||
cur = cur + word
|
||||
col = col + ln
|
||||
|
||||
if col > 0:
|
||||
print prefix + cur
|
||||
|
||||
|
||||
|
||||
#############################################################################
|
||||
#
|
||||
# The DocField class is used to store a list containing either DocPara or
|
||||
# DocCode objects. Each DocField also has an optional "name" which is used
|
||||
# when the object corresponds to a field of value definition
|
||||
#
|
||||
class DocField:
|
||||
|
||||
def __init__( self, name, lines ):
|
||||
|
||||
self.name = name # can be None for normal paragraphs/sources
|
||||
self.items = [] # list of items
|
||||
|
||||
mode_none = 0 # start parsing mode
|
||||
mode_code = 1 # parsing code sequences
|
||||
mode_para = 3 # parsing normal paragraph
|
||||
|
||||
margin = -1 # current code sequence indentation
|
||||
cur_lines = []
|
||||
|
||||
# now analyze the markup lines to see if they contain paragraphs,
|
||||
# code sequences or fields definitions
|
||||
#
|
||||
start = 0
|
||||
mode = mode_none
|
||||
for l in lines:
|
||||
|
||||
# are we parsing a code sequence ?
|
||||
if mode == mode_code:
|
||||
|
||||
m = re_code_end.match( l )
|
||||
if m and len(m.group(1)) <= margin:
|
||||
# that's it, we finised the code sequence
|
||||
code = DocCode( 0, cur_lines )
|
||||
self.items.append( code )
|
||||
margin = -1
|
||||
cur_lines = []
|
||||
mode = mode_none
|
||||
else:
|
||||
# nope, continue the code sequence
|
||||
cur_lines.append( l[margin:] )
|
||||
else:
|
||||
# start of code sequence ?
|
||||
m = re_code_start.match( l )
|
||||
if m:
|
||||
# save current lines
|
||||
if cur_lines:
|
||||
para = DocPara( cur_lines )
|
||||
self.items.append( para )
|
||||
cur_lines = []
|
||||
|
||||
# switch to code extraction mode
|
||||
margin = len(m.group(1))
|
||||
mode = mode_code
|
||||
|
||||
else:
|
||||
if not string.split( l ) and cur_lines:
|
||||
# if the line is empty, we end the current paragraph,
|
||||
# if any
|
||||
para = DocPara( cur_lines )
|
||||
self.items.append( para )
|
||||
cur_lines = []
|
||||
else:
|
||||
# otherwise, simply add the line to the current
|
||||
# paragraph
|
||||
cur_lines.append( l )
|
||||
|
||||
if mode == mode_code:
|
||||
# unexpected end of code sequence
|
||||
code = DocCode( margin, cur_lines )
|
||||
self.items.append( code )
|
||||
|
||||
elif cur_lines:
|
||||
para = DocPara( cur_lines )
|
||||
self.items.append( para )
|
||||
|
||||
def dump( self, prefix = "" ):
|
||||
if self.field:
|
||||
print prefix + self.field + " ::"
|
||||
prefix = prefix + "----"
|
||||
|
||||
first = 1
|
||||
for p in self.items:
|
||||
if not first:
|
||||
print ""
|
||||
p.dump( prefix )
|
||||
first = 0
|
||||
|
||||
|
||||
# this regular expression is used to detect field definitions
|
||||
#
|
||||
re_field = re.compile( r"\s*(\w*)\s*::" )
|
||||
|
||||
|
||||
|
||||
class DocMarkup:
|
||||
|
||||
def __init__( self, tag, lines ):
|
||||
self.tag = string.lower(tag)
|
||||
self.fields = []
|
||||
|
||||
cur_lines = []
|
||||
field = None
|
||||
mode = 0
|
||||
|
||||
for l in lines:
|
||||
m = re_field.match( l )
|
||||
if m:
|
||||
# we detected the start of a new field definition
|
||||
|
||||
# first, save the current one
|
||||
if cur_lines:
|
||||
f = DocField( field, cur_lines )
|
||||
self.fields.append( f )
|
||||
cur_lines = []
|
||||
field = None
|
||||
|
||||
field = m.group(1) # record field name
|
||||
ln = len(m.group(0))
|
||||
l = " "*ln + l[ln:]
|
||||
cur_lines = [ l ]
|
||||
else:
|
||||
cur_lines.append( l )
|
||||
|
||||
if field or cur_lines:
|
||||
f = DocField( field, cur_lines )
|
||||
self.fields.append( f )
|
||||
|
||||
def get_name( self ):
|
||||
try:
|
||||
return self.fields[0].items[0].words[0]
|
||||
|
||||
except:
|
||||
return None
|
||||
|
||||
def dump( self, margin ):
|
||||
print " "*margin + "<" + self.tag + ">"
|
||||
for f in self.fields:
|
||||
f.dump( " " )
|
||||
print " "*margin + "</" + self.tag + ">"
|
||||
|
||||
|
||||
|
||||
|
||||
class DocChapter:
|
||||
|
||||
def __init__( self, block ):
|
||||
self.block = block
|
||||
self.sections = []
|
||||
if block:
|
||||
self.name = block.name
|
||||
self.title = block.get_markup_words( "title" )
|
||||
self.order = block.get_markup_words( "sections" )
|
||||
else:
|
||||
self.name = "Other"
|
||||
self.title = string.split( "Miscellaneous" )
|
||||
self.order = []
|
||||
|
||||
|
||||
|
||||
class DocSection:
|
||||
|
||||
def __init__( self, name = "Other" ):
|
||||
self.name = name
|
||||
self.blocks = {}
|
||||
self.block_names = [] # ordered block names in section
|
||||
self.defs = []
|
||||
self.abstract = ""
|
||||
self.description = ""
|
||||
self.order = []
|
||||
self.title = "ERROR"
|
||||
self.chapter = None
|
||||
|
||||
def add_def( self, block ):
|
||||
self.defs.append( block )
|
||||
|
||||
def add_block( self, block ):
|
||||
self.block_names.append( block.name )
|
||||
self.blocks[ block.name ] = block
|
||||
|
||||
def process( self ):
|
||||
# lookup one block that contains a valid section description
|
||||
for block in self.defs:
|
||||
title = block.get_markup_text( "Title" )
|
||||
if title:
|
||||
self.title = title
|
||||
self.abstract = block.get_markup_words( "abstract" )
|
||||
self.description = block.get_markup_items( "description" )
|
||||
self.order = block.get_markup_words( "order" )
|
||||
return
|
||||
|
||||
def reorder( self ):
|
||||
|
||||
self.block_names = sort_order_list( self.block_names, self.order )
|
||||
|
||||
|
||||
class ContentProcessor:
|
||||
|
||||
def __init__( self ):
|
||||
"""initialize a block content processor"""
|
||||
self.reset()
|
||||
|
||||
self.sections = {} # dictionary of documentation sections
|
||||
self.section = None # current documentation section
|
||||
|
||||
self.chapters = [] # list of chapters
|
||||
|
||||
def set_section( self, section_name ):
|
||||
"""set current section during parsing"""
|
||||
if not self.sections.has_key( section_name ):
|
||||
section = DocSection( section_name )
|
||||
self.sections[ section_name ] = section
|
||||
self.section = section
|
||||
else:
|
||||
self.section = self.sections[ section_name ]
|
||||
|
||||
def add_chapter( self, block ):
|
||||
chapter = DocChapter( block )
|
||||
self.chapters.append( chapter )
|
||||
|
||||
|
||||
def reset( self ):
|
||||
"""reset the content processor for a new block"""
|
||||
self.markups = []
|
||||
self.markup = None
|
||||
self.markup_lines = []
|
||||
|
||||
def add_markup( self ):
|
||||
"""add a new markup section"""
|
||||
if self.markup and self.markup_lines:
|
||||
|
||||
# get rid of last line of markup if it's empty
|
||||
marks = self.markup_lines
|
||||
if len(marks) > 0 and not string.strip(marks[-1]):
|
||||
self.markup_lines = marks[:-1]
|
||||
|
||||
m = DocMarkup( self.markup, self.markup_lines )
|
||||
|
||||
self.markups.append( m )
|
||||
|
||||
self.markup = None
|
||||
self.markup_lines = []
|
||||
|
||||
|
||||
def process_content( self, content ):
|
||||
"""process a block content and return a list of DocMarkup objects
|
||||
corresponding to it"""
|
||||
markup = None
|
||||
markup_lines = []
|
||||
first = 1
|
||||
|
||||
for line in content:
|
||||
found = None
|
||||
for t in re_markup_tags:
|
||||
m = t.match( line )
|
||||
if m:
|
||||
found = string.lower(m.group(1))
|
||||
prefix = len(m.group(0))
|
||||
line = " "*prefix + line[prefix:] # remove markup from line
|
||||
break
|
||||
|
||||
# is it the start of a new markup section ?
|
||||
if found:
|
||||
first = 0
|
||||
self.add_markup() # add current markup content
|
||||
self.markup = found
|
||||
if len(string.strip( line )) > 0:
|
||||
self.markup_lines.append( line )
|
||||
elif first == 0:
|
||||
self.markup_lines.append( line )
|
||||
|
||||
self.add_markup()
|
||||
|
||||
return self.markups
|
||||
|
||||
|
||||
def parse_sources( self, source_processor ):
|
||||
blocks = source_processor.blocks
|
||||
count = len(blocks)
|
||||
for n in range(count):
|
||||
|
||||
source = blocks[n]
|
||||
if source.content:
|
||||
# this is a documentation comment, we need to catch
|
||||
# all following normal blocks in the "follow" list
|
||||
#
|
||||
follow = []
|
||||
m = n+1
|
||||
while m < count and not blocks[m].content:
|
||||
follow.append( blocks[m] )
|
||||
m = m+1
|
||||
|
||||
doc_block = DocBlock( source, follow, self )
|
||||
|
||||
|
||||
def finish( self ):
|
||||
|
||||
# process all sections to extract their abstract, description
|
||||
# and ordered list of items
|
||||
#
|
||||
for sec in self.sections.values():
|
||||
sec.process()
|
||||
|
||||
# process chapters to check that all sections are correctly
|
||||
# listed there
|
||||
for chap in self.chapters:
|
||||
for sec in chap.order:
|
||||
if self.sections.has_key(sec):
|
||||
section = self.sections[ sec ]
|
||||
section.chapter = chap
|
||||
section.reorder()
|
||||
chap.sections.append( section )
|
||||
else:
|
||||
sys.stderr.write( "WARNING: chapter '" +
|
||||
chap.name + "' in " + chap.block.location() + \
|
||||
" lists unknown section '" + sec + "'\n" )
|
||||
|
||||
# check that all sections are in a chapter
|
||||
#
|
||||
others = []
|
||||
for sec in self.sections.values():
|
||||
if not sec.chapter:
|
||||
others.append(sec)
|
||||
|
||||
# create a new special chapter for all remaining sections
|
||||
# when necessary
|
||||
#
|
||||
if others:
|
||||
chap = DocChapter( None )
|
||||
chap.sections = others
|
||||
self.chapters.append( chap )
|
||||
|
||||
|
||||
|
||||
class DocBlock:
|
||||
|
||||
def __init__( self, source, follow, processor ):
|
||||
|
||||
processor.reset()
|
||||
|
||||
self.source = source
|
||||
self.code = []
|
||||
self.type = "ERRTYPE"
|
||||
self.name = "ERRNAME"
|
||||
self.section = processor.section
|
||||
self.markups = processor.process_content( source.content )
|
||||
|
||||
# compute block type from first markup tag
|
||||
try:
|
||||
self.type = self.markups[0].tag
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
# compute block name from first markup paragraph
|
||||
try:
|
||||
markup = self.markups[0]
|
||||
para = markup.fields[0].items[0]
|
||||
name = para.words[0]
|
||||
m = re_identifier.match( name )
|
||||
if m:
|
||||
name = m.group(1)
|
||||
self.name = name
|
||||
except:
|
||||
pass
|
||||
|
||||
# detect new section starts
|
||||
if self.type == "section":
|
||||
processor.set_section( self.name )
|
||||
processor.section.add_def( self )
|
||||
|
||||
# detect new chapter
|
||||
elif self.type == "chapter":
|
||||
processor.add_chapter( self )
|
||||
|
||||
else:
|
||||
processor.section.add_block( self )
|
||||
|
||||
# now, compute the source lines relevant to this documentation
|
||||
# block. We keep normal comments in for obvious reasons (??)
|
||||
source = []
|
||||
for b in follow:
|
||||
if b.format:
|
||||
break
|
||||
for l in b.lines:
|
||||
# we use "/* */" as a separator
|
||||
if re_source_sep.match( l ):
|
||||
break
|
||||
source.append( l )
|
||||
|
||||
# now strip the leading and trailing empty lines from the sources
|
||||
start = 0
|
||||
end = len( source )-1
|
||||
|
||||
while start < end and not string.strip( source[start] ):
|
||||
start = start + 1
|
||||
|
||||
while start < end and not string.strip( source[end] ):
|
||||
end = end - 1
|
||||
|
||||
source = source[start:end+1]
|
||||
|
||||
self.code = source
|
||||
|
||||
|
||||
def location( self ):
|
||||
return self.source.location()
|
||||
|
||||
|
||||
|
||||
def get_markup( self, tag_name ):
|
||||
"""return the DocMarkup corresponding to a given tag in a block"""
|
||||
for m in self.markups:
|
||||
if m.tag == string.lower(tag_name):
|
||||
return m
|
||||
return None
|
||||
|
||||
|
||||
def get_markup_name( self, tag_name ):
|
||||
"""return the name of a given primary markup in a block"""
|
||||
try:
|
||||
m = self.get_markup( tag_name )
|
||||
return m.get_name()
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def get_markup_words( self, tag_name ):
|
||||
try:
|
||||
m = self.get_markup( tag_name )
|
||||
return m.fields[0].items[0].words
|
||||
except:
|
||||
return []
|
||||
|
||||
|
||||
def get_markup_text( self, tag_name ):
|
||||
result = self.get_markup_words( tag_name )
|
||||
return string.join( result )
|
||||
|
||||
|
||||
def get_markup_items( self, tag_name ):
|
||||
try:
|
||||
m = self.get_markup( tag_name )
|
||||
return m.fields[0].items
|
||||
except:
|
||||
return None
|
||||
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# DocMaker 0.2 (c) 2002 David Turner <[email protected]>
|
||||
#
|
||||
# This program is a re-write of the original DocMaker took used
|
||||
# to generate the API Reference of the FreeType font engine
|
||||
# by converting in-source comments into structured HTML
|
||||
#
|
||||
# This new version is capable of outputting XML data, as well
|
||||
# as accepts more liberal formatting options
|
||||
#
|
||||
# It also uses regular expression matching and substitution
|
||||
# to speed things significantly
|
||||
#
|
||||
|
||||
from sources import *
|
||||
from content import *
|
||||
from utils import *
|
||||
from formatter import *
|
||||
from tohtml import *
|
||||
|
||||
import utils
|
||||
|
||||
import sys, os, time, string, glob, getopt
|
||||
|
||||
|
||||
def file_exists( pathname ):
|
||||
"""checks that a given file exists"""
|
||||
result = 1
|
||||
try:
|
||||
file = open( pathname, "r" )
|
||||
file.close()
|
||||
except:
|
||||
result = None
|
||||
sys.stderr.write( pathname + " couldn't be accessed\n" )
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def make_file_list( args = None ):
|
||||
"""builds a list of input files from command-line arguments"""
|
||||
|
||||
file_list = []
|
||||
# sys.stderr.write( repr( sys.argv[1 :] ) + '\n' )
|
||||
|
||||
if not args:
|
||||
args = sys.argv[1 :]
|
||||
|
||||
for pathname in args:
|
||||
if string.find( pathname, '*' ) >= 0:
|
||||
newpath = glob.glob( pathname )
|
||||
newpath.sort() # sort files -- this is important because
|
||||
# of the order of files
|
||||
else:
|
||||
newpath = [pathname]
|
||||
|
||||
file_list.extend( newpath )
|
||||
|
||||
if len( file_list ) == 0:
|
||||
file_list = None
|
||||
else:
|
||||
# now filter the file list to remove non-existing ones
|
||||
file_list = filter( file_exists, file_list )
|
||||
|
||||
return file_list
|
||||
|
||||
|
||||
|
||||
def usage():
|
||||
print "\nDocMaker 0.2 Usage information\n"
|
||||
print " docmaker [options] file1 [ file2 ... ]\n"
|
||||
print "using the following options:\n"
|
||||
print " -h : print this page"
|
||||
print " -t : set project title, as in '-t \"My Project\"'"
|
||||
print " -o : set output directory, as in '-o mydir'"
|
||||
print " -p : set documentation prefix, as in '-p ft2'"
|
||||
print ""
|
||||
print " --title : same as -t, as in '--title=\"My Project\"'"
|
||||
print " --output : same as -o, as in '--output=mydir'"
|
||||
print " --prefix : same as -p, as in '--prefix=ft2'"
|
||||
|
||||
|
||||
def main( argv ):
|
||||
"""main program loop"""
|
||||
|
||||
global output_dir
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt( sys.argv[1:],
|
||||
"ht:o:p:",
|
||||
[ "help", "title=", "output=", "prefix=" ] )
|
||||
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit( 2 )
|
||||
|
||||
if args == []:
|
||||
usage()
|
||||
sys.exit( 1 )
|
||||
|
||||
# process options
|
||||
#
|
||||
project_title = "Project"
|
||||
project_prefix = None
|
||||
output_dir = None
|
||||
|
||||
for opt in opts:
|
||||
if opt[0] in ( "-h", "--help" ):
|
||||
usage()
|
||||
sys.exit( 0 )
|
||||
|
||||
if opt[0] in ( "-t", "--title" ):
|
||||
project_title = opt[1]
|
||||
|
||||
if opt[0] in ( "-o", "--output" ):
|
||||
utils.output_dir = opt[1]
|
||||
|
||||
if opt[0] in ( "-p", "--prefix" ):
|
||||
project_prefix = opt[1]
|
||||
|
||||
check_output( )
|
||||
|
||||
# create context and processor
|
||||
source_processor = SourceProcessor()
|
||||
content_processor = ContentProcessor()
|
||||
|
||||
# retrieve the list of files to process
|
||||
file_list = make_file_list( args )
|
||||
for filename in file_list:
|
||||
source_processor.parse_file( filename )
|
||||
content_processor.parse_sources( source_processor )
|
||||
|
||||
# process sections
|
||||
content_processor.finish()
|
||||
|
||||
formatter = HtmlFormatter( content_processor, project_title, project_prefix )
|
||||
|
||||
formatter.toc_dump()
|
||||
formatter.index_dump()
|
||||
formatter.section_dump_all()
|
||||
|
||||
|
||||
# if called from the command line
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
main( sys.argv )
|
||||
|
||||
|
||||
# eof
|
||||
@@ -0,0 +1,194 @@
|
||||
from sources import *
|
||||
from content import *
|
||||
from utils import *
|
||||
|
||||
class Formatter:
|
||||
|
||||
def __init__( self, processor ):
|
||||
|
||||
self.processor = processor
|
||||
self.identifiers = {}
|
||||
self.chapters = processor.chapters
|
||||
self.sections = processor.sections.values()
|
||||
self.block_index = []
|
||||
|
||||
# store all blocks in a dictionary
|
||||
self.blocks = []
|
||||
for section in self.sections:
|
||||
for block in section.blocks.values():
|
||||
self.add_identifier( block.name, block )
|
||||
|
||||
# add enumeration values to the index, since this is useful
|
||||
for markup in block.markups:
|
||||
if markup.tag == 'values':
|
||||
for field in markup.fields:
|
||||
self.add_identifier( field.name, block )
|
||||
|
||||
|
||||
self.block_index = self.identifiers.keys()
|
||||
self.block_index.sort( index_sort )
|
||||
|
||||
|
||||
def add_identifier( self, name, block ):
|
||||
if self.identifiers.has_key( name ):
|
||||
# duplicate name !!
|
||||
sys.stderr.write( \
|
||||
"WARNING: duplicate definition for '" + name + "' in " + \
|
||||
block.location() + ", previous definition in " + \
|
||||
self.identifiers[ name ].location() + "\n" )
|
||||
else:
|
||||
self.identifiers[name] = block
|
||||
|
||||
|
||||
#
|
||||
# Formatting the table of contents
|
||||
#
|
||||
|
||||
def toc_enter( self ):
|
||||
pass
|
||||
|
||||
def toc_chapter_enter( self, chapter ):
|
||||
pass
|
||||
|
||||
def toc_section_enter( self, section ):
|
||||
pass
|
||||
|
||||
def toc_section_exit( self, section ):
|
||||
pass
|
||||
|
||||
def toc_chapter_exit( self, chapter ):
|
||||
pass
|
||||
|
||||
def toc_index( self, index_filename ):
|
||||
pass
|
||||
|
||||
def toc_exit( self ):
|
||||
pass
|
||||
|
||||
def toc_dump( self, toc_filename = None, index_filename = None ):
|
||||
|
||||
output = None
|
||||
if toc_filename:
|
||||
output = open_output( toc_filename )
|
||||
|
||||
self.toc_enter()
|
||||
|
||||
for chap in self.processor.chapters:
|
||||
|
||||
self.toc_chapter_enter( chap )
|
||||
|
||||
for section in chap.sections:
|
||||
self.toc_section_enter( section )
|
||||
self.toc_section_exit( section )
|
||||
|
||||
self.toc_chapter_exit ( chap )
|
||||
|
||||
self.toc_index( index_filename )
|
||||
|
||||
self.toc_exit()
|
||||
|
||||
if output:
|
||||
close_output( output )
|
||||
|
||||
#
|
||||
# Formatting the index
|
||||
#
|
||||
|
||||
def index_enter( self ):
|
||||
pass
|
||||
|
||||
def index_name_enter( self, name ):
|
||||
pass
|
||||
|
||||
def index_name_exit( self, name ):
|
||||
pass
|
||||
|
||||
def index_exit( self ):
|
||||
pass
|
||||
|
||||
def index_dump( self, index_filename = None ):
|
||||
|
||||
output = None
|
||||
if index_filename:
|
||||
output = open_output( index_filename )
|
||||
|
||||
self.index_enter()
|
||||
|
||||
for name in self.block_index:
|
||||
self.index_name_enter( name )
|
||||
self.index_name_exit ( name )
|
||||
|
||||
self.index_exit()
|
||||
|
||||
if output:
|
||||
close_output( output )
|
||||
|
||||
#
|
||||
# Formatting a section
|
||||
#
|
||||
def section_enter( self, section ):
|
||||
pass
|
||||
|
||||
def block_enter( self, block ):
|
||||
pass
|
||||
|
||||
def markup_enter( self, markup, block = None ):
|
||||
pass
|
||||
|
||||
def field_enter( self, field, markup = None, block = None ):
|
||||
pass
|
||||
|
||||
def field_exit( self, field, markup = None, block = None ):
|
||||
pass
|
||||
|
||||
def markup_exit( self, markup, block = None ):
|
||||
pass
|
||||
|
||||
def block_exit( self, block ):
|
||||
pass
|
||||
|
||||
def section_exit( self, section ):
|
||||
pass
|
||||
|
||||
|
||||
def section_dump( self, section, section_filename = None ):
|
||||
|
||||
output = None
|
||||
if section_filename:
|
||||
output = open_output( section_filename )
|
||||
|
||||
self.section_enter( section )
|
||||
|
||||
for name in section.block_names:
|
||||
block = self.identifiers[ name ]
|
||||
self.block_enter( block )
|
||||
|
||||
for markup in block.markups[1:]: # always ignore first markup !!
|
||||
self.markup_enter( markup, block )
|
||||
|
||||
for field in markup.fields:
|
||||
self.field_enter( field, markup, block )
|
||||
|
||||
self.field_exit ( field, markup, block )
|
||||
|
||||
self.markup_exit( markup, block )
|
||||
|
||||
self.block_exit( block )
|
||||
|
||||
self.section_exit ( section )
|
||||
|
||||
if output:
|
||||
close_output( output )
|
||||
|
||||
|
||||
def section_dump_all( self ):
|
||||
for section in self.sections:
|
||||
self.section_dump( section )
|
||||
|
||||
#
|
||||
# Formatting a block
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
#
|
||||
# this file contains definitions of classes needed to decompose
|
||||
# C sources files into a series of multi-line "blocks". There are
|
||||
# two kinds of blocks:
|
||||
#
|
||||
# - normal blocks, which contain source code or ordinary comments
|
||||
#
|
||||
# - documentation blocks, which have restricted formatting, and
|
||||
# whose text always start with a documentation markup tag like
|
||||
# "<Function>", "<Type>", etc..
|
||||
#
|
||||
# the routines used to process the content of documentation blocks
|
||||
# are not contained here, but in "content.py"
|
||||
#
|
||||
# the classes and methods found here only deal with text parsing
|
||||
# and basic documentation block extraction
|
||||
#
|
||||
import fileinput, re, sys, os, string
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
################################################################
|
||||
##
|
||||
## BLOCK FORMAT PATTERN
|
||||
##
|
||||
## A simple class containing compiled regular expressions used
|
||||
## to detect potential documentation format block comments within
|
||||
## C source code
|
||||
##
|
||||
## note that the 'column' pattern must contain a group that will
|
||||
## be used to "unbox" the content of documentation comment blocks
|
||||
##
|
||||
class SourceBlockFormat:
|
||||
|
||||
def __init__( self, id, start, column, end ):
|
||||
"""create a block pattern, used to recognize special documentation blocks"""
|
||||
|
||||
self.id = id
|
||||
self.start = re.compile( start, re.VERBOSE )
|
||||
self.column = re.compile( column, re.VERBOSE )
|
||||
self.end = re.compile( end, re.VERBOSE )
|
||||
|
||||
|
||||
|
||||
#
|
||||
# format 1 documentation comment blocks look like the following:
|
||||
#
|
||||
# /************************************/
|
||||
# /* */
|
||||
# /* */
|
||||
# /* */
|
||||
# /************************************/
|
||||
#
|
||||
# we define a few regular expressions here to detect them
|
||||
#
|
||||
|
||||
start = r'''
|
||||
\s* # any number of whitespace
|
||||
/\*{2,}/ # followed by '/' and at least two asterisks then '/'
|
||||
\s*$ # eventually followed by whitespace
|
||||
'''
|
||||
|
||||
column = r'''
|
||||
\s* # any number of whitespace
|
||||
/\*{1} # followed by '/' and precisely one asterisk
|
||||
([^*].*) # followed by anything (group 1)
|
||||
\*{1}/ # followed by one asterisk and a '/'
|
||||
\s*$ # enventually followed by whitespace
|
||||
'''
|
||||
|
||||
re_source_block_format1 = SourceBlockFormat( 1, start, column, start )
|
||||
|
||||
#
|
||||
# format 2 documentation comment blocks look like the following:
|
||||
#
|
||||
# /************************************ (at least 2 asterisks)
|
||||
# *
|
||||
# *
|
||||
# *
|
||||
# *
|
||||
# **/ (1 or more asterisks at the end)
|
||||
#
|
||||
# we define a few regular expressions here to detect them
|
||||
#
|
||||
start = r'''
|
||||
\s* # any number of whitespace
|
||||
/\*{2,} # followed by '/' and at least two asterisks
|
||||
\s*$ # eventually followed by whitespace
|
||||
'''
|
||||
|
||||
column = r'''
|
||||
\s* # any number of whitespace
|
||||
\*{1} # followed by precisely one asterisk
|
||||
(.*) # then anything (group1)
|
||||
'''
|
||||
|
||||
end = r'''
|
||||
\s* # any number of whitespace
|
||||
\*+/ # followed by at least one asterisk, then '/'
|
||||
'''
|
||||
|
||||
re_source_block_format2 = SourceBlockFormat( 2, start, column, end )
|
||||
|
||||
#
|
||||
# the list of supported documentation block formats, we could add new ones
|
||||
# relatively easily
|
||||
#
|
||||
re_source_block_formats = [ re_source_block_format1, re_source_block_format2 ]
|
||||
|
||||
|
||||
#
|
||||
# the following regular expressions corresponds to markup tags
|
||||
# within the documentation comment blocks. they're equivalent
|
||||
# despite their different syntax
|
||||
#
|
||||
# notice how each markup tag _must_ begin a new line
|
||||
#
|
||||
re_markup_tag1 = re.compile( r'''\s*<(\w*)>''' ) # <xxxx> format
|
||||
re_markup_tag2 = re.compile( r'''\s*@(\w*):''' ) # @xxxx: format
|
||||
|
||||
#
|
||||
# the list of supported markup tags, we could add new ones relatively
|
||||
# easily
|
||||
#
|
||||
re_markup_tags = [ re_markup_tag1, re_markup_tag2 ]
|
||||
|
||||
#
|
||||
# used to detect a cross-reference, after markup tags have been stripped
|
||||
#
|
||||
re_crossref = re.compile( r'@(\w*)' )
|
||||
|
||||
#
|
||||
# used to detect italic and bold styles in paragraph text
|
||||
#
|
||||
re_italic = re.compile( r'_(\w+)_' )
|
||||
re_bold = re.compile( r'\*(\w+)\*' )
|
||||
|
||||
#
|
||||
# used to detect the end of commented source lines
|
||||
#
|
||||
re_source_sep = re.compile( r'\s*/\*\s*\*/' )
|
||||
|
||||
#
|
||||
# used to perform cross-reference within source output
|
||||
#
|
||||
re_source_crossref = re.compile( r'(\W*)(\w*)' )
|
||||
|
||||
#
|
||||
# a list of reserved source keywords
|
||||
#
|
||||
re_source_keywords = re.compile( '''( typedef |
|
||||
struct |
|
||||
enum |
|
||||
union |
|
||||
const |
|
||||
char |
|
||||
int |
|
||||
short |
|
||||
long |
|
||||
void |
|
||||
signed |
|
||||
unsigned |
|
||||
\#include |
|
||||
\#define |
|
||||
\#undef |
|
||||
\#if |
|
||||
\#ifdef |
|
||||
\#ifndef |
|
||||
\#else |
|
||||
\#endif )''', re.VERBOSE )
|
||||
|
||||
################################################################
|
||||
##
|
||||
## SOURCE BLOCK CLASS
|
||||
##
|
||||
## A SourceProcessor is in charge or reading a C source file
|
||||
## and decomposing it into a series of different "SourceBlocks".
|
||||
## each one of these blocks can be made of the following data:
|
||||
##
|
||||
## - A documentation comment block that starts with "/**" and
|
||||
## whose exact format will be discussed later
|
||||
##
|
||||
## - normal sources lines, include comments
|
||||
##
|
||||
## the important fields in a text block are the following ones:
|
||||
##
|
||||
## self.lines : a list of text lines for the corresponding block
|
||||
##
|
||||
## self.content : for documentation comment blocks only, this is the
|
||||
## block content that has been "unboxed" from its
|
||||
## decoration. This is None for all other blocks
|
||||
## (i.e. sources or ordinary comments with no starting
|
||||
## markup tag)
|
||||
##
|
||||
class SourceBlock:
|
||||
def __init__( self, processor, filename, lineno, lines ):
|
||||
self.processor = processor
|
||||
self.filename = filename
|
||||
self.lineno = lineno
|
||||
self.lines = lines
|
||||
self.format = processor.format
|
||||
self.content = []
|
||||
|
||||
if self.format == None:
|
||||
return
|
||||
|
||||
words = []
|
||||
|
||||
# extract comment lines
|
||||
lines = []
|
||||
|
||||
for line0 in self.lines[1:]:
|
||||
m = self.format.column.match( line0 )
|
||||
if m:
|
||||
lines.append( m.group(1) )
|
||||
|
||||
# now, look for a markup tag
|
||||
for l in lines:
|
||||
l = string.strip(l)
|
||||
if len(l) > 0:
|
||||
for tag in re_markup_tags:
|
||||
if tag.match( l ):
|
||||
self.content = lines
|
||||
return
|
||||
|
||||
def location( self ):
|
||||
return "(" + self.filename + ":" + repr(self.lineno) + ")"
|
||||
|
||||
|
||||
# debugging only - not used in normal operations
|
||||
def dump( self ):
|
||||
|
||||
if self.content:
|
||||
print "{{{content start---"
|
||||
for l in self.content:
|
||||
print l
|
||||
print "---content end}}}"
|
||||
return
|
||||
|
||||
fmt = ""
|
||||
if self.format:
|
||||
fmt = repr(self.format.id) + " "
|
||||
|
||||
for line in self.lines:
|
||||
print line
|
||||
|
||||
|
||||
################################################################
|
||||
##
|
||||
## SOURCE PROCESSOR CLASS
|
||||
##
|
||||
## The SourceProcessor is in charge or reading a C source file
|
||||
## and decomposing it into a series of different "SourceBlock"
|
||||
## objects.
|
||||
##
|
||||
## each one of these blocks can be made of the following data:
|
||||
##
|
||||
## - A documentation comment block that starts with "/**" and
|
||||
## whose exact format will be discussed later
|
||||
##
|
||||
## - normal sources lines, include comments
|
||||
##
|
||||
##
|
||||
class SourceProcessor:
|
||||
|
||||
def __init__( self ):
|
||||
"""initialize a source processor"""
|
||||
self.blocks = []
|
||||
self.filename = None
|
||||
self.format = None
|
||||
self.lines = []
|
||||
|
||||
def reset( self ):
|
||||
"""reset a block processor, clean all its blocks"""
|
||||
self.blocks = []
|
||||
self.format = None
|
||||
|
||||
|
||||
def parse_file( self, filename ):
|
||||
"""parse a C source file, and adds its blocks to the processor's list"""
|
||||
|
||||
self.reset()
|
||||
|
||||
self.filename = filename
|
||||
|
||||
fileinput.close()
|
||||
self.format = None
|
||||
self.lineno = 0
|
||||
self.lines = []
|
||||
|
||||
for line in fileinput.input( filename ):
|
||||
|
||||
# strip trailing newlines, important on Windows machines !!
|
||||
if line[-1] == '\012':
|
||||
line = line[0:-1]
|
||||
|
||||
if self.format == None:
|
||||
self.process_normal_line( line )
|
||||
|
||||
else:
|
||||
if self.format.end.match( line ):
|
||||
# that's a normal block end, add it to lines and
|
||||
# create a new block
|
||||
# self.lines.append( line )
|
||||
self.add_block_lines()
|
||||
|
||||
elif self.format.column.match( line ):
|
||||
# that's a normal column line, add it to 'lines'
|
||||
self.lines.append( line )
|
||||
|
||||
else:
|
||||
# humm.. this is an unexcepted block end,
|
||||
# create a new block, but don't process the line
|
||||
self.add_block_lines()
|
||||
|
||||
# we need to process the line again
|
||||
self.process_normal_line( line )
|
||||
|
||||
# record the last lines
|
||||
self.add_block_lines()
|
||||
|
||||
|
||||
|
||||
def process_normal_line( self, line ):
|
||||
"""process a normal line and check if it's the start of a new block"""
|
||||
for f in re_source_block_formats:
|
||||
if f.start.match( line ):
|
||||
self.add_block_lines()
|
||||
self.format = f
|
||||
self.lineno = fileinput.filelineno()
|
||||
|
||||
self.lines.append( line )
|
||||
|
||||
|
||||
|
||||
def add_block_lines( self ):
|
||||
"""add the current accumulated lines, and create a new block"""
|
||||
if self.lines != []:
|
||||
block = SourceBlock( self, self.filename, self.lineno, self.lines )
|
||||
|
||||
self.blocks.append( block )
|
||||
self.format = None
|
||||
self.lines = []
|
||||
|
||||
|
||||
# debugging only, not used in normal operations
|
||||
def dump( self ):
|
||||
"""print all blocks in a processor"""
|
||||
for b in self.blocks:
|
||||
b.dump()
|
||||
|
||||
# eof
|
||||
@@ -0,0 +1,476 @@
|
||||
from sources import *
|
||||
from content import *
|
||||
from formatter import *
|
||||
|
||||
import time
|
||||
|
||||
# The following defines the HTML header used by all generated pages.
|
||||
#
|
||||
html_header_1 = """\
|
||||
<html>
|
||||
<header>
|
||||
<title>"""
|
||||
|
||||
html_header_2= """ API Reference</title>
|
||||
<basefont face="Verdana,Geneva,Arial,Helvetica">
|
||||
<style content="text/css">
|
||||
P { text-align=justify }
|
||||
H1 { text-align=center }
|
||||
LI { text-align=justify }
|
||||
</style>
|
||||
</header>
|
||||
<body text=#000000
|
||||
bgcolor=#FFFFFF
|
||||
link=#0000EF
|
||||
vlink=#51188E
|
||||
alink=#FF0000>
|
||||
<center><h1>"""
|
||||
|
||||
html_header_3=""" API Reference</h1></center>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
# The HTML footer used by all generated pages.
|
||||
#
|
||||
html_footer = """\
|
||||
</body>
|
||||
</html>"""
|
||||
|
||||
# The header and footer used for each section.
|
||||
#
|
||||
section_title_header = "<center><h1>"
|
||||
section_title_footer = "</h1></center>"
|
||||
|
||||
# The header and footer used for code segments.
|
||||
#
|
||||
code_header = "<font color=blue><pre>"
|
||||
code_footer = "</pre></font>"
|
||||
|
||||
# Paragraph header and footer.
|
||||
#
|
||||
para_header = "<p>"
|
||||
para_footer = "</p>"
|
||||
|
||||
# Block header and footer.
|
||||
#
|
||||
block_header = "<center><table width=75%><tr><td>"
|
||||
block_footer = "</td></tr></table><hr width=75%></center>"
|
||||
|
||||
# Description header/footer.
|
||||
#
|
||||
description_header = "<center><table width=87%><tr><td>"
|
||||
description_footer = "</td></tr></table></center><br>"
|
||||
|
||||
# Marker header/inter/footer combination.
|
||||
#
|
||||
marker_header = "<center><table width=87% cellpadding=5><tr bgcolor=#EEEEFF><td><em><b>"
|
||||
marker_inter = "</b></em></td></tr><tr><td>"
|
||||
marker_footer = "</td></tr></table></center>"
|
||||
|
||||
# Source code extracts header/footer.
|
||||
#
|
||||
source_header = "<center><table width=87%><tr bgcolor=#D6E8FF width=100%><td><pre>\n"
|
||||
source_footer = "\n</pre></table></center><br>"
|
||||
|
||||
# Chapter header/inter/footer.
|
||||
#
|
||||
chapter_header = "<br><center><table width=75%><tr><td><h2>"
|
||||
chapter_inter = "</h2><ul>"
|
||||
chapter_footer = "</ul></td></tr></table></center>"
|
||||
|
||||
|
||||
# source language keyword coloration/styling
|
||||
#
|
||||
keyword_prefix = '<font color="darkblue">'
|
||||
keyword_suffix = '</font>'
|
||||
|
||||
section_synopsis_header = '<h2>Synopsys</h2><font color="cyan">'
|
||||
section_synopsis_footer = '</font>'
|
||||
|
||||
# Translate a single line of source to HTML. This will convert
|
||||
# a "<" into "<.", ">" into ">.", etc.
|
||||
#
|
||||
def html_quote( line ):
|
||||
result = string.replace( line, "&", "&" )
|
||||
result = string.replace( result, "<", "<" )
|
||||
result = string.replace( result, ">", ">" )
|
||||
return result
|
||||
|
||||
|
||||
# same as 'html_quote', but ignores left and right brackets
|
||||
#
|
||||
def html_quote0( line ):
|
||||
return string.replace( line, "&", "&" )
|
||||
|
||||
|
||||
def dump_html_code( lines, prefix = "" ):
|
||||
# clean the last empty lines
|
||||
#
|
||||
l = len( self.lines )
|
||||
while l > 0 and string.strip( self.lines[l - 1] ) == "":
|
||||
l = l - 1
|
||||
|
||||
# The code footer should be directly appended to the last code
|
||||
# line to avoid an additional blank line.
|
||||
#
|
||||
print prefix + code_header,
|
||||
for line in self.lines[0 : l+1]:
|
||||
print '\n' + prefix + html_quote(line),
|
||||
print prefix + code_footer,
|
||||
|
||||
|
||||
|
||||
class HtmlFormatter(Formatter):
|
||||
|
||||
def __init__( self, processor, project_title, file_prefix ):
|
||||
|
||||
Formatter.__init__( self, processor )
|
||||
|
||||
global html_header_1, html_header_2, html_header_3, html_footer
|
||||
|
||||
if file_prefix:
|
||||
file_prefix = file_prefix + "-"
|
||||
else:
|
||||
file_prefix = ""
|
||||
|
||||
self.project_title = project_title
|
||||
self.file_prefix = file_prefix
|
||||
self.html_header = html_header_1 + project_title + html_header_2 + \
|
||||
project_title + html_header_3
|
||||
|
||||
self.html_footer = "<p><center><font size=""-2"">generated on " + \
|
||||
time.asctime( time.localtime( time.time() ) ) + \
|
||||
"</font></p></center>" + html_footer
|
||||
|
||||
self.columns = 3
|
||||
|
||||
def make_section_url( self, section ):
|
||||
return self.file_prefix + section.name + ".html"
|
||||
|
||||
|
||||
def make_block_url( self, block ):
|
||||
return self.make_section_url( block.section ) + "#" + block.name
|
||||
|
||||
|
||||
def make_html_words( self, words ):
|
||||
""" convert a series of simple words into some HTML text """
|
||||
line = ""
|
||||
if words:
|
||||
line = html_quote( words[0] )
|
||||
for w in words[1:]:
|
||||
line = line + " " + html_quote( w )
|
||||
|
||||
return line
|
||||
|
||||
|
||||
def make_html_word( self, word ):
|
||||
"""analyze a simple word to detect cross-references and styling"""
|
||||
# look for cross-references
|
||||
#
|
||||
m = re_crossref.match( word )
|
||||
if m:
|
||||
try:
|
||||
name = m.group(1)
|
||||
block = self.identifiers[ name ]
|
||||
url = self.make_block_url( block )
|
||||
return '<a href="' + url + '">' + name + '</a>'
|
||||
except:
|
||||
return '?' + name + '?'
|
||||
|
||||
# look for italics and bolds
|
||||
m = re_italic.match( word )
|
||||
if m:
|
||||
name = m.group(1)
|
||||
return '<i>'+name+'</i>'
|
||||
|
||||
m = re_bold.match( word )
|
||||
if m:
|
||||
name = m.group(1)
|
||||
return '<b>'+name+'</b>'
|
||||
|
||||
return html_quote(word)
|
||||
|
||||
|
||||
def make_html_para( self, words ):
|
||||
""" convert a paragraph's words into tagged HTML text, handle xrefs """
|
||||
line = ""
|
||||
if words:
|
||||
line = self.make_html_word( words[0] )
|
||||
for word in words[1:]:
|
||||
line = line + " " + self.make_html_word( word )
|
||||
|
||||
return "<p>" + line + "</p>"
|
||||
|
||||
|
||||
def make_html_code( self, lines ):
|
||||
""" convert a code sequence to HTML """
|
||||
line = code_header + '\n'
|
||||
for l in lines:
|
||||
line = line + html_quote( l ) + '\n'
|
||||
|
||||
return line + code_footer
|
||||
|
||||
|
||||
def make_html_items( self, items ):
|
||||
""" convert a field's content into some valid HTML """
|
||||
lines = []
|
||||
for item in items:
|
||||
if item.lines:
|
||||
lines.append( self.make_html_code( item.lines ) )
|
||||
else:
|
||||
lines.append( self.make_html_para( item.words ) )
|
||||
|
||||
return string.join( lines, '\n' )
|
||||
|
||||
|
||||
def print_html_items( self, items ):
|
||||
print self.make_html_items( items )
|
||||
|
||||
|
||||
def print_html_field( self, field ):
|
||||
if field.name:
|
||||
print "<table valign=top><tr><td><b>"+field.name+"</b></td><td>"
|
||||
|
||||
print self.make_html_items( field.items )
|
||||
|
||||
if field.name:
|
||||
print "</td></tr></table>"
|
||||
|
||||
|
||||
def html_source_quote( self, line, block_name = None ):
|
||||
result = ""
|
||||
while line:
|
||||
m = re_source_crossref.match( line )
|
||||
if m:
|
||||
name = m.group(2)
|
||||
prefix = html_quote( m.group(1) )
|
||||
length = len( m.group(0) )
|
||||
|
||||
if name == block_name:
|
||||
# this is the current block name, if any
|
||||
result = result + prefix + '<b>' + name + '</b>'
|
||||
|
||||
elif re_source_keywords.match(name):
|
||||
# this is a C keyword
|
||||
result = result + prefix + keyword_prefix + name + keyword_suffix
|
||||
|
||||
elif self.identifiers.has_key(name):
|
||||
# this is a known identifier
|
||||
block = self.identifiers[name]
|
||||
result = result + prefix + '<a href="' + \
|
||||
self.make_block_url(block) + '">' + name + '</a>'
|
||||
else:
|
||||
result = result + html_quote(line[ : length ])
|
||||
|
||||
line = line[ length : ]
|
||||
else:
|
||||
result = result + html_quote(line)
|
||||
line = []
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def print_html_field_list( self, fields ):
|
||||
print "<table valign=top cellpadding=3>"
|
||||
for field in fields:
|
||||
print "<tr valign=top><td><b>" + field.name + "</b></td><td>"
|
||||
self.print_html_items( field.items )
|
||||
print "</td></tr>"
|
||||
print "</table>"
|
||||
|
||||
|
||||
def print_html_markup( self, markup ):
|
||||
table_fields = []
|
||||
for field in markup.fields:
|
||||
if field.name:
|
||||
# we begin a new series of field or value definitions, we
|
||||
# will record them in the 'table_fields' list before outputting
|
||||
# all of them as a single table
|
||||
#
|
||||
table_fields.append( field )
|
||||
|
||||
else:
|
||||
if table_fields:
|
||||
self.print_html_field_list( table_fields )
|
||||
table_fields = []
|
||||
|
||||
self.print_html_items( field.items )
|
||||
|
||||
if table_fields:
|
||||
self.print_html_field_list( table_fields )
|
||||
|
||||
#
|
||||
# Formatting the index
|
||||
#
|
||||
|
||||
def index_enter( self ):
|
||||
print self.html_header
|
||||
self.index_items = {}
|
||||
|
||||
def index_name_enter( self, name ):
|
||||
block = self.identifiers[ name ]
|
||||
url = self.make_block_url( block )
|
||||
self.index_items[ name ] = url
|
||||
|
||||
def index_exit( self ):
|
||||
|
||||
# block_index already contains the sorted list of index names
|
||||
count = len( self.block_index )
|
||||
rows = (count + self.columns - 1)/self.columns
|
||||
|
||||
print "<center><table border=0 cellpadding=0 cellspacing=0>"
|
||||
for r in range(rows):
|
||||
line = "<tr>"
|
||||
for c in range(self.columns):
|
||||
i = r + c*rows
|
||||
if i < count:
|
||||
bname = self.block_index[ r + c*rows ]
|
||||
url = self.index_items[ bname ]
|
||||
line = line + '<td><a href="' + url + '">' + bname + '</a></td>'
|
||||
else:
|
||||
line = line + '<td></td>'
|
||||
line = line + "</tr>"
|
||||
print line
|
||||
|
||||
print "</table></center>"
|
||||
print self.html_footer
|
||||
self.index_items = {}
|
||||
|
||||
def index_dump( self, index_filename = None ):
|
||||
|
||||
if index_filename == None:
|
||||
index_filename = self.file_prefix + "index.html"
|
||||
|
||||
Formatter.index_dump( self, index_filename )
|
||||
|
||||
#
|
||||
# Formatting the table of content
|
||||
#
|
||||
def toc_enter( self ):
|
||||
print self.html_header
|
||||
print "<center><h1>Table of Contents</h1></center>"
|
||||
|
||||
def toc_chapter_enter( self, chapter ):
|
||||
print chapter_header + string.join(chapter.title) + chapter_inter
|
||||
print "<table cellpadding=5>"
|
||||
|
||||
def toc_section_enter( self, section ):
|
||||
print "<tr valign=top><td>"
|
||||
print '<a href="' + self.make_section_url( section ) + '">' + \
|
||||
section.title + '</a></td><td>'
|
||||
|
||||
print self.make_html_para( section.abstract )
|
||||
|
||||
def toc_section_exit( self, section ):
|
||||
print "</td></tr>"
|
||||
|
||||
def toc_chapter_exit( self, chapter ):
|
||||
print "</table>"
|
||||
print chapter_footer
|
||||
|
||||
def toc_index( self, index_filename ):
|
||||
print chapter_header + '<a href="' + index_filename + '">Global Index</a>' + chapter_inter + chapter_footer
|
||||
|
||||
def toc_exit( self ):
|
||||
print "</table></center>"
|
||||
print self.html_footer
|
||||
|
||||
def toc_dump( self, toc_filename = None, index_filename = None ):
|
||||
if toc_filename == None:
|
||||
toc_filename = self.file_prefix + "toc.html"
|
||||
|
||||
if index_filename == None:
|
||||
index_filename = self.file_prefix + "index.html"
|
||||
|
||||
Formatter.toc_dump( self, toc_filename, index_filename )
|
||||
|
||||
#
|
||||
# Formatting sections
|
||||
#
|
||||
def section_enter( self, section ):
|
||||
print self.html_header
|
||||
|
||||
print section_title_header
|
||||
print section.title
|
||||
print section_title_footer
|
||||
|
||||
# print section synopsys
|
||||
print section_synopsis_header
|
||||
print "<center><table cellspacing=5 cellpadding=0 border=0>"
|
||||
|
||||
maxwidth = 0
|
||||
for b in section.blocks.values():
|
||||
if len(b.name) > maxwidth:
|
||||
maxwidth = len(b.name)
|
||||
|
||||
width = 70 # XXX magic number
|
||||
columns = width / maxwidth
|
||||
if columns < 1:
|
||||
columns = 1
|
||||
|
||||
count = len(section.block_names)
|
||||
rows = (count + columns-1)/columns
|
||||
for r in range(rows):
|
||||
line = "<tr>"
|
||||
for c in range(columns):
|
||||
i = r + c*rows
|
||||
line = line + '<td></td><td>'
|
||||
if i < count:
|
||||
name = section.block_names[i]
|
||||
line = line + '<a href="#' + name + '">' + name + '</a>'
|
||||
|
||||
line = line + '</td>'
|
||||
line = line + "</tr>"
|
||||
print line
|
||||
|
||||
print "</table></center><br><br>"
|
||||
print section_synopsis_footer
|
||||
|
||||
print description_header
|
||||
print self.make_html_items( section.description )
|
||||
print description_footer
|
||||
|
||||
def block_enter( self, block ):
|
||||
print block_header
|
||||
|
||||
# place html anchor if needed
|
||||
if block.name:
|
||||
print '<a name="' + block.name + '">'
|
||||
print "<h4>" + block.name + "</h4>"
|
||||
print "</a>"
|
||||
|
||||
# dump the block C source lines now
|
||||
if block.code:
|
||||
print source_header
|
||||
for l in block.code:
|
||||
print self.html_source_quote( l, block.name )
|
||||
print source_footer
|
||||
|
||||
|
||||
def markup_enter( self, markup, block ):
|
||||
if markup.tag == "description":
|
||||
print description_header
|
||||
else:
|
||||
print marker_header + markup.tag + marker_inter
|
||||
|
||||
self.print_html_markup( markup )
|
||||
|
||||
def markup_exit( self, markup, block ):
|
||||
if markup.tag == "description":
|
||||
print description_footer
|
||||
else:
|
||||
print marker_footer
|
||||
|
||||
def block_exit( self, block ):
|
||||
print block_footer
|
||||
|
||||
|
||||
def section_exit( self, section ):
|
||||
print html_footer
|
||||
|
||||
|
||||
def section_dump_all( self ):
|
||||
for section in self.sections:
|
||||
self.section_dump( section, self.file_prefix + section.name + '.html' )
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import string, sys, os
|
||||
|
||||
# current output directory
|
||||
#
|
||||
output_dir = None
|
||||
|
||||
|
||||
# This function is used to sort the index. It is a simple lexicographical
|
||||
# sort, except that it places capital letters before lowercase ones.
|
||||
#
|
||||
def index_sort( s1, s2 ):
|
||||
if not s1:
|
||||
return -1
|
||||
|
||||
if not s2:
|
||||
return 1
|
||||
|
||||
l1 = len( s1 )
|
||||
l2 = len( s2 )
|
||||
m1 = string.lower( s1 )
|
||||
m2 = string.lower( s2 )
|
||||
|
||||
for i in range( l1 ):
|
||||
if i >= l2 or m1[i] > m2[i]:
|
||||
return 1
|
||||
|
||||
if m1[i] < m2[i]:
|
||||
return -1
|
||||
|
||||
if s1[i] < s2[i]:
|
||||
return -1
|
||||
|
||||
if s1[i] > s2[i]:
|
||||
return 1
|
||||
|
||||
if l2 > l1:
|
||||
return -1
|
||||
|
||||
return 0
|
||||
|
||||
# Sort input_list, placing the elements of order_list in front.
|
||||
#
|
||||
def sort_order_list( input_list, order_list ):
|
||||
new_list = order_list[:]
|
||||
for id in input_list:
|
||||
if not id in order_list:
|
||||
new_list.append( id )
|
||||
return new_list
|
||||
|
||||
|
||||
|
||||
# Open the standard output to a given project documentation file. Use
|
||||
# "output_dir" to determine the filename location if necessary and save the
|
||||
# old stdout in a tuple that is returned by this function.
|
||||
#
|
||||
def open_output( filename ):
|
||||
global output_dir
|
||||
|
||||
if output_dir and output_dir != "":
|
||||
filename = output_dir + os.sep + filename
|
||||
|
||||
old_stdout = sys.stdout
|
||||
new_file = open( filename, "w" )
|
||||
sys.stdout = new_file
|
||||
|
||||
return ( new_file, old_stdout )
|
||||
|
||||
|
||||
# Close the output that was returned by "close_output".
|
||||
#
|
||||
def close_output( output ):
|
||||
output[0].close()
|
||||
sys.stdout = output[1]
|
||||
|
||||
|
||||
# Check output directory.
|
||||
#
|
||||
def check_output( ):
|
||||
global output_dir
|
||||
if output_dir:
|
||||
if output_dir != "":
|
||||
if not os.path.isdir( output_dir ):
|
||||
sys.stderr.write( "argument" + " '" + output_dir + "' " +
|
||||
"is not a valid directory" )
|
||||
sys.exit( 2 )
|
||||
else:
|
||||
output_dir = None
|
||||
Reference in New Issue
Block a user