misc/libfreetype/src/bzip2/ftbzip2.c
author koda
Sat, 06 Apr 2013 01:19:47 +0200
changeset 8880 71ed64b18540
parent 5172 88f2e05288ba
permissions -rw-r--r--
reintroduce the notice for restarting frontend after changing language
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftbzip2.c                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType support for .bz2 compressed files.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  This optional component relies on libbz2.  It should mainly be used to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  parse compressed PCF fonts, as found with many X11 server              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  distributions.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  Copyright 2010 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  Joel Klinghed.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  Based on src/gzip/ftgzip.c, Copyright 2002 - 2010 by                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
#include FT_INTERNAL_MEMORY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include FT_BZIP2_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#include FT_CONFIG_STANDARD_LIBRARY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#include FT_MODULE_ERRORS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#undef __FTERRORS_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#define FT_ERR_PREFIX  Bzip2_Err_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define FT_ERR_BASE    FT_Mod_Err_Bzip2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#include FT_ERRORS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
#ifdef FT_CONFIG_OPTION_USE_BZIP2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
#ifdef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
#error "bzip2 code does not support PIC yet"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#define BZ_NO_STDIO /* Do not need FILE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#include <bzlib.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
/*****           B Z I P 2   M E M O R Y   M A N A G E M E N T         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  /* it is better to use FreeType memory routines instead of raw
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
     'malloc/free' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  typedef void *(* alloc_func)(void*, int, int);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  typedef void (* free_func)(void*, void*);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  static void*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  ft_bzip2_alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
                  int        items,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
                  int        size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    FT_ULong    sz = (FT_ULong)size * items;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    FT_Pointer  p  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    (void)FT_ALLOC( p, sz );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    return p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  ft_bzip2_free( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
                 void*      address )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    FT_MEM_FREE( address );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
/*****              B Z I P 2   F I L E   D E S C R I P T O R          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
#define FT_BZIP2_BUFFER_SIZE  4096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  typedef struct  FT_BZip2FileRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Stream  source;         /* parent/source stream        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    FT_Stream  stream;         /* embedding stream            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    FT_Memory  memory;         /* memory allocator            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    bz_stream  bzstream;       /* bzlib input stream          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    FT_Byte    input[FT_BZIP2_BUFFER_SIZE];  /* input read buffer  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    FT_Byte    buffer[FT_BZIP2_BUFFER_SIZE]; /* output buffer      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    FT_ULong   pos;                          /* position in output */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    FT_Byte*   cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    FT_Byte*   limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  } FT_BZip2FileRec, *FT_BZip2File;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /* check and skip .bz2 header - we don't support `transparent' compression */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  ft_bzip2_check_header( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    FT_Error  error = Bzip2_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    FT_Byte   head[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    if ( FT_STREAM_SEEK( 0 )       ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
         FT_STREAM_READ( head, 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    /* head[0] && head[1] are the magic numbers;    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    /* head[2] is the version, and head[3] the blocksize */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    if ( head[0] != 0x42  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
         head[1] != 0x5a  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
         head[2] != 0x68  )  /* only support bzip2 (huffman) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      error = Bzip2_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  ft_bzip2_file_init( FT_BZip2File  zip,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
                      FT_Stream     stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
                      FT_Stream     source )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    bz_stream*  bzstream = &zip->bzstream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    FT_Error    error    = Bzip2_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    zip->stream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    zip->source = source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    zip->memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    zip->limit  = zip->buffer + FT_BZIP2_BUFFER_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    zip->cursor = zip->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    zip->pos    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    /* check .bz2 header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      stream = source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      error = ft_bzip2_check_header( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      if ( FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    /* initialize bzlib */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    bzstream->bzalloc = (alloc_func)ft_bzip2_alloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    bzstream->bzfree  = (free_func) ft_bzip2_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    bzstream->opaque  = zip->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    bzstream->avail_in = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    bzstream->next_in  = (char*)zip->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
    if ( BZ2_bzDecompressInit( bzstream, 0, 0 ) != BZ_OK ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
         bzstream->next_in == NULL                       )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
      error = Bzip2_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
  ft_bzip2_file_done( FT_BZip2File  zip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    bz_stream*  bzstream = &zip->bzstream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    BZ2_bzDecompressEnd( bzstream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    /* clear the rest */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    bzstream->bzalloc   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    bzstream->bzfree    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    bzstream->opaque    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    bzstream->next_in   = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    bzstream->next_out  = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    bzstream->avail_in  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    bzstream->avail_out = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    zip->memory = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    zip->source = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    zip->stream = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  ft_bzip2_file_reset( FT_BZip2File  zip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    FT_Stream  stream = zip->source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    if ( !FT_STREAM_SEEK( 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
      bz_stream*  bzstream = &zip->bzstream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      BZ2_bzDecompressEnd( bzstream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      bzstream->avail_in  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      bzstream->next_in   = (char*)zip->input;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      bzstream->avail_out = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      bzstream->next_out  = (char*)zip->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      zip->limit  = zip->buffer + FT_BZIP2_BUFFER_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
      zip->cursor = zip->limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      zip->pos    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      BZ2_bzDecompressInit( bzstream, 0, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  ft_bzip2_file_fill_input( FT_BZip2File  zip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    bz_stream*  bzstream = &zip->bzstream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    FT_Stream   stream    = zip->source;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FT_ULong    size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    if ( stream->read )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      size = stream->read( stream, stream->pos, zip->input,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
                           FT_BZIP2_BUFFER_SIZE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
      if ( size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        return Bzip2_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      size = stream->size - stream->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      if ( size > FT_BZIP2_BUFFER_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
        size = FT_BZIP2_BUFFER_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
      if ( size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
        return Bzip2_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
      FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    stream->pos += size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
    bzstream->next_in  = (char*)zip->input;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    bzstream->avail_in = size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    return Bzip2_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
  ft_bzip2_file_fill_output( FT_BZip2File  zip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    bz_stream*  bzstream = &zip->bzstream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
    FT_Error    error    = Bzip2_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    zip->cursor         = zip->buffer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    bzstream->next_out  = (char*)zip->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    bzstream->avail_out = FT_BZIP2_BUFFER_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    while ( bzstream->avail_out > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      int  err;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      if ( bzstream->avail_in == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
        error = ft_bzip2_file_fill_input( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      err = BZ2_bzDecompress( bzstream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
      if ( err == BZ_STREAM_END )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        zip->limit = (FT_Byte*)bzstream->next_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        if ( zip->limit == zip->cursor )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
          error = Bzip2_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      else if ( err != BZ_OK )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        error = Bzip2_Err_Invalid_Stream_Operation;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
  /* fill output buffer; `count' must be <= FT_BZIP2_BUFFER_SIZE */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
  ft_bzip2_file_skip_output( FT_BZip2File  zip,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
                             FT_ULong      count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    FT_Error  error = Bzip2_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
    FT_ULong  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      delta = (FT_ULong)( zip->limit - zip->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      if ( delta >= count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
        delta = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
      zip->cursor += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      zip->pos    += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      count -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      if ( count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      error = ft_bzip2_file_fill_output( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
  static FT_ULong
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
  ft_bzip2_file_io( FT_BZip2File  zip,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
                    FT_ULong      pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
                    FT_Byte*      buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
                    FT_ULong      count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    FT_ULong  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    /* Reset inflate stream if we're seeking backwards.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    /* Yes, that is not too efficient, but it saves memory :-) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    if ( pos < zip->pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
      error = ft_bzip2_file_reset( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    /* skip unwanted bytes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    if ( pos > zip->pos )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      error = ft_bzip2_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    if ( count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    /* now read the data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
      FT_ULong  delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      delta = (FT_ULong)( zip->limit - zip->cursor );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      if ( delta >= count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
        delta = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      FT_MEM_COPY( buffer, zip->cursor, delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      buffer      += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      result      += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      zip->cursor += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      zip->pos    += delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      count -= delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
      if ( count == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      error = ft_bzip2_file_fill_output( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
/*****               B Z   E M B E D D I N G   S T R E A M             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
/*****                                                                 *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
  ft_bzip2_stream_close( FT_Stream  stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    FT_BZip2File  zip    = (FT_BZip2File)stream->descriptor.pointer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    FT_Memory     memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    if ( zip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      /* finalize bzip file descriptor */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      ft_bzip2_file_done( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      FT_FREE( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      stream->descriptor.pointer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
  static FT_ULong
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
  ft_bzip2_stream_io( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
                      FT_ULong   pos,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
                      FT_Byte*   buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
                      FT_ULong   count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    FT_BZip2File  zip = (FT_BZip2File)stream->descriptor.pointer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
    return ft_bzip2_file_io( zip, pos, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  FT_Stream_OpenBzip2( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
                       FT_Stream  source )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    FT_Memory     memory = source->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    FT_BZip2File  zip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
     *  check the header right now; this prevents allocating unnecessary
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
     *  objects when we don't need them
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    error = ft_bzip2_check_header( source );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    FT_ZERO( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    stream->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    if ( !FT_QNEW( zip ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      error = ft_bzip2_file_init( zip, stream, source );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
        FT_FREE( zip );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
      stream->descriptor.pointer = zip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    stream->size  = 0x7FFFFFFFL;  /* don't know the real size! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    stream->pos   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    stream->base  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
    stream->read  = ft_bzip2_stream_io;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
    stream->close = ft_bzip2_stream_close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
#else  /* !FT_CONFIG_OPTION_USE_BZIP2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
  FT_EXPORT_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
  FT_Stream_OpenBzip2( FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
                       FT_Stream  source )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    FT_UNUSED( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    FT_UNUSED( source );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    return Bzip2_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
#endif /* !FT_CONFIG_OPTION_USE_BZIP2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
/* END */