misc/libfreetype/builds/amiga/src/base/ftsystem.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
/*  ftsystem.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
/*    Amiga-specific FreeType low-level system interface (body).           */
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
/*  Copyright 1996-2001, 2002, 2005, 2006, 2007, 2010 by                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, Werner Lemberg and Detlef Würkner.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  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
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  /* This file contains the Amiga interface used by FreeType to access     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* low-level, i.e. memory management, i/o access as well as thread       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /* synchronisation.                                                      */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /* Maintained by Detlef Würkner <TetiSoft@apg.lahn.de>                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* Based on the original ftsystem.c,                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* modified to avoid fopen(), fclose(), fread(), fseek(), ftell(),       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* malloc(), realloc(), and free().                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /* Those C library functions are often not thread-safe or cant be        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  /* used in a shared Amiga library. If that's not a problem for you,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /* you can of course use the default ftsystem.c with C library calls     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* instead.                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  /* This implementation needs exec V39+ because it uses AllocPooled() etc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*                                                                       */
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
#define __NOLIBBASE__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
#define __NOGLOBALIFACE__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
#define __USE_INLINE__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
#include <proto/exec.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
#include <dos/stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
#include <proto/dos.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
extern struct ExecIFace *IExec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
extern struct DOSIFace  *IDOS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
extern struct Library   *SysBase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
extern struct Library   *DOSBase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
#define IOBUF_SIZE 512
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
/* structure that helps us to avoid
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
 * useless calls of Seek() and Read()
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
struct SysFile
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
  BPTR  file;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  ULONG iobuf_start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  ULONG iobuf_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  UBYTE iobuf[IOBUF_SIZE];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
};
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
#ifndef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
/* C implementation of AllocVecPooled (see autodoc exec/AllocPooled) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
APTR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
Alloc_VecPooled( APTR   poolHeader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
                 ULONG  memSize )
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
  ULONG  newSize = memSize + sizeof ( ULONG );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  ULONG  *mem = AllocPooled( poolHeader, newSize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  if ( !mem )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  *mem = newSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
  return mem + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
/* C implementation of FreeVecPooled (see autodoc exec/AllocPooled) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
Free_VecPooled( APTR  poolHeader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
                APTR  memory )
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
  ULONG  *realmem = (ULONG *)memory - 1;
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
  FreePooled( poolHeader, realmem, *realmem );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
}
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
#endif
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
#include FT_CONFIG_CONFIG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
#include FT_SYSTEM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
#include FT_ERRORS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
#include FT_TYPES_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
#include <stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
#include <stdlib.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
#include <string.h>
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  /*                       MEMORY MANAGEMENT INTERFACE                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  /*************************************************************************/
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
  /*************************************************************************/
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
  /* It is not necessary to do any error checking for the                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  /* allocation-related functions.  This is done by the higher level       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  /* routines like ft_mem_alloc() or ft_mem_realloc().                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
  /*                                                                       */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  /*    ft_alloc                                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  /*    The memory allocation function.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
  /*    memory :: A pointer to the memory object.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  /*    size   :: The requested size in bytes.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
  /*    The address of newly allocated block.                              */
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
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  ft_alloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
            long       size )
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
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    return AllocVecPooled( memory->user, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    return Alloc_VecPooled( memory->user, size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  /*    ft_realloc                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  /*    The memory reallocation function.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
  /*    memory   :: A pointer to the memory object.                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
  /*    cur_size :: The current size of the allocated memory block.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
  /*    new_size :: The newly requested size in bytes.                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  /*    block    :: The current address of the block in memory.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
  /*    The address of the reallocated memory block.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  FT_CALLBACK_DEF( void* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
  ft_realloc( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
              long       cur_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
              long       new_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
              void*      block )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    void* new_block;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    new_block = AllocVecPooled ( memory->user, new_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    new_block = Alloc_VecPooled ( memory->user, new_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    if ( new_block != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      CopyMem ( block, new_block,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
                ( new_size > cur_size ) ? cur_size : new_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      FreeVecPooled ( memory->user, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      Free_VecPooled ( memory->user, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    return new_block;
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
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
  /*    ft_free                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
  /*    The memory release function.                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  /*    memory  :: A pointer to the memory object.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /*    block   :: The address of block in memory to be freed.             */
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
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
  ft_free( FT_Memory  memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
           void*      block )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
    FreeVecPooled( memory->user, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    Free_VecPooled( memory->user, block );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  }
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
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
  /*                     RESOURCE MANAGEMENT INTERFACE                     */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
  /*************************************************************************/
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
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
#define FT_COMPONENT  trace_io
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
  /* We use the macro STREAM_FILE for convenience to extract the       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  /* system-specific stream handle from a given FreeType stream object */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
#define STREAM_FILE( stream )  ( (struct SysFile *)stream->descriptor.pointer )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  /*************************************************************************/
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  /*    ft_amiga_stream_close                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
  /*    The function to close a stream.                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
  /*    stream :: A pointer to the stream object.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  FT_CALLBACK_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  ft_amiga_stream_close( FT_Stream  stream )
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
    struct SysFile* sysfile;
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
    sysfile = STREAM_FILE( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    Close ( sysfile->file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    FreeMem ( sysfile, sizeof ( struct SysFile ));
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
    stream->descriptor.pointer = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    stream->size               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    stream->base               = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  }
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
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
  /*    ft_amiga_stream_io                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
  /*    The function to open a stream.                                     */
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
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
  /*    stream :: A pointer to the stream object.                          */
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
  /*    offset :: The position in the data stream to start reading.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
  /*    buffer :: The address of buffer to store the read data.            */
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
  /*    count  :: The number of bytes to read from the stream.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
  /* <Return>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  /*    The number of bytes actually read.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
  FT_CALLBACK_DEF( unsigned long )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
  ft_amiga_stream_io( FT_Stream       stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
                      unsigned long   offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
                      unsigned char*  buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
                      unsigned long   count )
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
    struct SysFile* sysfile;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    unsigned long   read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    if ( count != 0 )
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
      sysfile = STREAM_FILE( stream );
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
      /* handle the seek */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      if ( (offset < sysfile->iobuf_start) || (offset + count > sysfile->iobuf_end) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        /* requested offset implies we need a buffer refill */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        if ( !sysfile->iobuf_end || offset != sysfile->iobuf_end )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
          /* a physical seek is necessary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
          Seek( sysfile->file, offset, OFFSET_BEGINNING );
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
        sysfile->iobuf_start = offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        sysfile->iobuf_end = 0; /* trigger a buffer refill */
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
      /* handle the read */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
      if ( offset + count <= sysfile->iobuf_end )
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
        /* we have buffer and requested bytes are all inside our buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
        CopyMem( &sysfile->iobuf[offset - sysfile->iobuf_start], buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
        read_bytes = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
        /* (re)fill buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
        if ( count <= IOBUF_SIZE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
          /* requested bytes is a subset of the buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
          read_bytes = Read( sysfile->file, sysfile->iobuf, IOBUF_SIZE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
          if ( read_bytes == -1UL )
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
            /* error */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
            read_bytes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
            sysfile->iobuf_end = offset + read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
            CopyMem( sysfile->iobuf, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
            if ( read_bytes > count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
              read_bytes = count;
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
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        else
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
          /* we actually need more than our buffer can hold, so we decide
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
          ** to do a single big read, and then copy the last IOBUF_SIZE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
          ** bytes of that to our internal buffer for later use */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
          read_bytes = Read( sysfile->file, buffer, count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
          if ( read_bytes == -1UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
            /* error */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
            read_bytes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
          else
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
            ULONG bufsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
            bufsize = ( read_bytes > IOBUF_SIZE ) ? IOBUF_SIZE : read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
            sysfile->iobuf_end = offset + read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
            sysfile->iobuf_start = sysfile->iobuf_end - bufsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
            CopyMem( &buffer[read_bytes - bufsize] , sysfile->iobuf, bufsize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
          }
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
    else
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
      read_bytes = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    return read_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  /* documentation is in ftobjs.h */
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
  FT_BASE_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
  FT_Stream_Open( FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
                  const char*  filepathname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    struct FileInfoBlock*  fib;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    struct SysFile*        sysfile;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
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
    if ( !stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      return FT_Err_Invalid_Stream_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
    sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_SHARED );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_PUBLIC );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( !sysfile )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      FT_ERROR(( " could not open `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      return FT_Err_Cannot_Open_Resource;
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
    sysfile->file = Open( (STRPTR)filepathname, MODE_OLDFILE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    if ( !sysfile->file )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
      FreeMem ( sysfile, sizeof ( struct SysFile ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      FT_ERROR(( " could not open `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      return FT_Err_Cannot_Open_Resource;
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
    fib = AllocDosObject( DOS_FIB, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
    if ( !fib )
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
      Close ( sysfile->file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      FreeMem ( sysfile, sizeof ( struct SysFile ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      FT_ERROR(( " could not open `%s'\n", filepathname ));
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
      return FT_Err_Cannot_Open_Resource;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    if ( !( ExamineFH( sysfile->file, fib ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      FreeDosObject( DOS_FIB, fib );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      Close ( sysfile->file );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      FreeMem ( sysfile, sizeof ( struct SysFile ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      FT_ERROR(( " could not open `%s'\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      return FT_Err_Cannot_Open_Resource;
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
    stream->size = fib->fib_Size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
    FreeDosObject( DOS_FIB, fib );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    stream->descriptor.pointer = (void *)sysfile;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
    stream->pathname.pointer   = (char*)filepathname;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    sysfile->iobuf_start       = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
    sysfile->iobuf_end         = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
    stream->pos                = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
    stream->read  = ft_amiga_stream_io;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    stream->close = ft_amiga_stream_close;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    if ( !stream->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      ft_amiga_stream_close( stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
      FT_ERROR(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
      FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
      return FT_Err_Cannot_Open_Stream;;
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_TRACE1(( "FT_Stream_Open:" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
                filepathname, stream->size ));
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
    return FT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
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
#ifdef FT_DEBUG_MEMORY
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
  extern FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  ft_mem_debug_init( FT_Memory  memory );
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
  extern void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
  ft_mem_debug_done( FT_Memory  memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  FT_BASE_DEF( FT_Memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
  FT_New_Memory( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    FT_Memory  memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_SHARED );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    if ( memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
#ifdef __amigaos4__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      memory->user = CreatePool( MEMF_SHARED, 16384, 16384 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      memory->user = CreatePool( MEMF_PUBLIC, 16384, 16384 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
      if ( memory->user == NULL )
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
        FreeVec( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
        memory = NULL;
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
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        memory->alloc   = ft_alloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
        memory->realloc = ft_realloc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
        memory->free    = ft_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
        ft_mem_debug_init( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    return memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  /* documentation is in ftobjs.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
  FT_BASE_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  FT_Done_Memory( FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
#ifdef FT_DEBUG_MEMORY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    ft_mem_debug_done( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    DeletePool( memory->user );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    FreeVec( memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
/*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
Local Variables:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
coding: latin-1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
End:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
/* END */