+/* otf.h -- Header file for the OTF (OpenType font) library.
+
+Copyright (C) 2002
+ by AIST (National Institute of Advanced Industrial Science and Technology)
+ Registration Number H14PRO???
+
+This file is part of the OTF library.
+
+The OTF library is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2, or (at
+your option) any later version.
+
+The OTF library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with the OTF library; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
#ifndef _OTF_H_
#define _OTF_H_
/***
- @file otf.h
+ Table of contents:
- @brief This file defines APIs for the OTF library.
+ (1) Structures for OTF tables and OTF itself
+ (1-1) Basic types
+ (1-2) "head" table
+ (1-3) "name" table
+ (1-4) "cmap" table
+ (1-5) Structures common to the following tables
+ (1-6) "GDEF" table
+ (1-7) "GSUB" table
+ (1-8) "GPOS" table
+ (1-9) OTF
- The @e OTF @e library is for reading and driving OpenType font
- tables. It can handle the tables of the following names.
+ (2) APIs for reading OTF
+ (2-1) otf_open ()
+ (2-2) otf_close ()
+ (2-3) otf_get_table ()
- @li @e head:
+ (3) APIs for driving OTF
+ (3-1) Structure for glyph string
+ (3-2) otf_drive_cmap ()
+ (3-3) otf_drive_gdef ()
+ (3-4) otf_drive_gsub ()
+ (3-5) otf_drive_gpos ()
- @li @e name:
+ (4) APIs for error handling
+ (4-1) Error codes
+ (4-2) otf_perror ()
- @li @e cmap:
+ (5) APIs miscellaneous
+***/
- @li @e GDEF:
- @li @e GSUB:
+/*** (1) Structures for OTF tables and OTF itself */
- @li @e GPOS:
+/*** (1-1) Basic types */
-*/
+typedef unsigned OTF_Tag;
+typedef unsigned OTF_GlyphID;
+typedef unsigned OTF_Offset;
+typedef struct
+{
+ unsigned high;
+ unsigned low;
+} OTF_Fixed;
-////
-/***
- @defgroup Error handling
+/*** (1-2) "head" table */
- @brief Handling errors that occur in the OTF library.
- */
+typedef struct
+{
+ OTF_Fixed TableVersionNumber;
+ OTF_Fixed fontRevision;
+ unsigned checkSumAdjustment;
+ unsigned magicNumber;
+ unsigned flags;
+ int unitsPerEm;
+} OTF_head;
-/*** @{ */
-/***
- @brief Global variable holding an error code.
+/*** (1-3) "name" table */
- The variable otf_error is set to one of OTF_ERROR_XXX when an
- error is detected in OTF library. */
-extern int otf_error;
+typedef struct
+{
+ int platformID;
+ int encodingID;
+ int languageID;
+ int nameID;
+ int length;
+ int offset;
+} OTF_NameRecord;
-/***
- @brief Print error message.
+#define OTF_max_nameID 23
- The function otf_perror () prints $PREFIX and an error message to
- the standard output according to the value of otf_error. If this
- variable is zero, do nothing. */
+typedef struct
+{
+ int format;
+ int count;
+ int stringOffset;
+ OTF_NameRecord *nameRecord;
+ char *name[OTF_max_nameID + 1];
+} OTF_name;
-extern void otf_perror (char *prefix, int exit_code);
+/*** (1-4) "cmap" table */
-/*** Macros for error codes. */
+typedef struct
+{
+ unsigned char glyphIdArray[256];
+} OTF_EncodingSubtable0;
-/***
- @brief Memory allocation error.
+typedef struct
+{
+ unsigned firstCode;
+ unsigned entryCount;
+ int idDelta;
+ unsigned idRangeOffset;
+} OTF_cmapSubHeader;
- When the OTF library fails to allocate memory, the variable
- otf_error is set to this value. */
-#define OTF_ERROR_MEMORY -1
+typedef struct
+{
+ unsigned subHeaderKeys[256];
+ OTF_cmapSubHeader *subHeaders;
+ unsigned *glyphIndexArray;
+} OTF_EncodingSubtable2;
-/***
- @brief File read error.
+typedef struct
+{
+ unsigned startCount;
+ unsigned endCount;
+ int idDelta;
+ unsigned idRangeOffset;
+} OTF_cmapSegument;
- When the OTF library fails to read a file, the variable otf_error
- is set to this value. */
-#define OTF_ERROR_FILE -2
+typedef struct
+{
+ unsigned segCountX2;
+ unsigned searchRange;
+ unsigned entrySelector;
+ unsigned rangeShift;
+ OTF_cmapSegument *segments;
+ int GlyphCount;
+ unsigned *glyphIdArray;
+} OTF_EncodingSubtable4;
-/***
- @brief OTF table read error.
+typedef struct
+{
+ unsigned firstCode;
+ unsigned entryCount;
+ unsigned *glyphIdArray;
+} OTF_EncodingSubtable6;
- When the OTF library detects an invalid data in an OTF table, the
- variable otf_error is set to this value. */
-#define OTF_ERROR_TABLE -3
+typedef struct
+{
+ unsigned startCharCode;
+ unsigned endCharCode;
+ unsigned startGlyphID;
+} OTF_cmapGroup;
-/***
- @brief CMAP driving error.
+typedef struct
+{
+ unsigned char is32[8192];
+ unsigned nGroups;
+ OTF_cmapGroup *Groups;
+} OTF_EncodingSubtable8;
- When the OTF library an invalid data in an OTF table, the variable
- otf_error is set to this value. */
-#define OTF_ERROR_CMAP_DRIVE -4
-#define OTF_ERROR_GDEF_DRIVE -5
-#define OTF_ERROR_GSUB_DRIVE -6
-#define OTF_ERROR_GPOS_DRIVE -7
+typedef struct
+{
+ unsigned startCharCode;
+ unsigned numChars;
+ unsigned *glyphs;
+} OTF_EncodingSubtable10;
-/*** @} */
+typedef struct
+{
+ unsigned nGroups;
+ OTF_cmapGroup *Groups;
+} OTF_EncodingSubtable12;
-////
+typedef struct
+{
+ unsigned format;
+ unsigned length;
+ unsigned language;
+ union {
+ OTF_EncodingSubtable0 *f0;
+ OTF_EncodingSubtable2 *f2;
+ OTF_EncodingSubtable4 *f4;
+ OTF_EncodingSubtable6 *f6;
+ OTF_EncodingSubtable8 *f8;
+ OTF_EncodingSubtable10 *f10;
+ OTF_EncodingSubtable12 *f12;
+ }f;
+} OTF_EncodingSubtable;
-/*** */
+typedef struct
+{
+ unsigned platformID;
+ unsigned encodingID;
+ unsigned offset;
+ OTF_EncodingSubtable subtable;
+} OTF_EncodingRecord;
-/* BASIC */
+typedef struct
+{
+ unsigned version;
+ unsigned numTables;
+ OTF_EncodingRecord *EncodingRecord;
+ OTF_EncodingRecord *Unicode;
+} OTF_cmap;
-typedef unsigned OTF_Tag;
-typedef unsigned OTF_GlyphID;
-typedef unsigned OTF_Offset;
+
+/*** (1-5) Structures common to GDEF, GSUB, GPOS */
typedef struct
{
- unsigned high;
- unsigned low;
-} OTF_Fixed;
+ OTF_GlyphID Start;
+ OTF_GlyphID End;
+ unsigned StartCoverageIndex;
+} OTF_RangeRecord;
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned CoverageFormat;
+ unsigned Count;
+ union {
+ OTF_GlyphID *GlyphArray;
+ OTF_RangeRecord *RangeRecord;
+ } table;
+} OTF_Coverage;
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned StartSize;
+ unsigned EndSize;
+ unsigned DeltaFormat;
+ char *DeltaValue;
+} OTF_DeviceTable;
+
+typedef struct
+{
+ OTF_GlyphID Start;
+ OTF_GlyphID End;
+ unsigned Class;
+} OTF_ClassRangeRecord;
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned ClassFormat;
+ union {
+ struct {
+ OTF_GlyphID StartGlyph;
+ unsigned GlyphCount;
+ unsigned *ClassValueArray;
+ } f1;
+ struct {
+ unsigned ClassRangeCount;
+ OTF_ClassRangeRecord *ClassRangeRecord;
+ } f2;
+ } f;
+} OTF_ClassDef;
+
+/*** (1-6) "GDEF" table */
+
+typedef struct
+{
+ OTF_Fixed Version;
+ OTF_Offset GlyphClassDef;
+ OTF_Offset AttachList;
+ OTF_Offset LigCaretList;
+ OTF_Offset MarkAttachClassDef;
+} OTF_GDEFHeader;
+
+enum OTF_GlyphClassDef
+ {
+ OTF_GlyphClass0 = 0,
+ OTF_GlyphClassBase = 1,
+ OTF_GlyphClassLigature = 2,
+ OTF_GlyphClassMark = 3,
+ OTF_GlyphClassComponent = 4
+ };
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned PointCount;
+ unsigned *PointIndex;
+} OTF_AttachPoint;
+
+typedef struct
+{
+ OTF_Coverage Coverage;
+ unsigned GlyphCount;
+ OTF_AttachPoint *AttachPoint;
+} OTF_AttachList;
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned CaretValueFormat; /* 1, 2, or 3 */
+ union {
+ union {
+ int Coordinate;
+ } f1;
+ union {
+ unsigned CaretValuePoint;
+ } f2;
+ union {
+ int Coordinate;
+ OTF_DeviceTable DeviceTable;
+ } f3;
+ } f;
+} OTF_CaretValue;
+
+typedef struct
+{
+ OTF_Offset offset;
+ unsigned CaretCount;
+ OTF_CaretValue *CaretValue;
+} OTF_LigGlyph;
+
+typedef struct
+{
+ OTF_Coverage Coverage;
+ unsigned LigGlyphCount;
+ OTF_LigGlyph *LigGlyph;
+} OTF_LigCaretList;
+
+typedef struct
+{
+ OTF_GDEFHeader header;
+ OTF_ClassDef glyph_class_def;
+ OTF_AttachList attach_list;
+ OTF_LigCaretList lig_caret_list;
+ OTF_ClassDef mark_attach_class_def;
+} OTF_GDEF;
\f
+
+
+
/* COMMON */
/* ScriptList
OTF_IgnoreBaseGlyphs = 0x0002,
OTF_IgnoreLigatures = 0x0004,
OTF_IgnoreMarks = 0x8000,
- OTF_Reserved = 0x00F0,
- OTF_MarkAttachmentType = 0xFF00
- };
-
-typedef struct
-{
- OTF_GlyphID Start;
- OTF_GlyphID End;
- unsigned StartCoverageIndex;
-} OTF_RangeRecord;
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned CoverageFormat;
- unsigned Count;
- union {
- OTF_GlyphID *GlyphArray;
- OTF_RangeRecord *RangeRecord;
- } table;
-} OTF_Coverage;
-
-typedef struct
-{
- OTF_GlyphID Start;
- OTF_GlyphID End;
- unsigned Class;
-} OTF_ClassRangeRecord;
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned ClassFormat;
- union {
- struct {
- OTF_GlyphID StartGlyph;
- unsigned GlyphCount;
- unsigned *ClassValueArray;
- } f1;
- struct {
- unsigned ClassRangeCount;
- OTF_ClassRangeRecord *ClassRangeRecord;
- } f2;
- } f;
-} OTF_ClassDef;
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned StartSize;
- unsigned EndSize;
- unsigned DeltaFormat;
- char *DeltaValue;
-} OTF_DeviceTable;
-
-\f
-/* head */
-typedef struct
-{
- OTF_Fixed TableVersionNumber;
- OTF_Fixed fontRevision;
- unsigned checkSumAdjustment;
- unsigned magicNumber;
- unsigned flags;
- int unitsPerEm;
-} OTF_head;
-
+ OTF_Reserved = 0x00F0,
+ OTF_MarkAttachmentType = 0xFF00
+ };
+
\f
-
/* GSUB */
typedef struct
} OTF_JSTF;
\f
-/* GDEF */
-typedef struct
-{
- OTF_Fixed Version;
- OTF_Offset GlyphClassDef;
- OTF_Offset AttachList;
- OTF_Offset LigCaretList;
- OTF_Offset MarkAttachClassDef;
-} OTF_GDEFHeader;
-
-enum OTF_GlyphClassDef
- {
- OTF_GlyphClass0 = 0,
- OTF_GlyphClassBase = 1,
- OTF_GlyphClassLigature = 2,
- OTF_GlyphClassMark = 3,
- OTF_GlyphClassComponent = 4
- };
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned PointCount;
- unsigned *PointIndex;
-} OTF_AttachPoint;
-
-typedef struct
-{
- OTF_Coverage Coverage;
- unsigned GlyphCount;
- OTF_AttachPoint *AttachPoint;
-} OTF_AttachList;
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned CaretValueFormat; /* 1, 2, or 3 */
- union {
- union {
- int Coordinate;
- } f1;
- union {
- unsigned CaretValuePoint;
- } f2;
- union {
- int Coordinate;
- OTF_DeviceTable DeviceTable;
- } f3;
- } f;
-} OTF_CaretValue;
-
-typedef struct
-{
- OTF_Offset offset;
- unsigned CaretCount;
- OTF_CaretValue *CaretValue;
-} OTF_LigGlyph;
-
-typedef struct
-{
- OTF_Coverage Coverage;
- unsigned LigGlyphCount;
- OTF_LigGlyph *LigGlyph;
-} OTF_LigCaretList;
-
-typedef struct
-{
- OTF_GDEFHeader header;
- OTF_ClassDef glyph_class_def;
- OTF_AttachList attach_list;
- OTF_LigCaretList lig_caret_list;
- OTF_ClassDef mark_attach_class_def;
-} OTF_GDEF;
-
-\f
-
-/* cmap */
-
-typedef struct
-{
- unsigned char glyphIdArray[256];
-} OTF_EncodingSubtable0;
-
-typedef struct
-{
- unsigned firstCode;
- unsigned entryCount;
- int idDelta;
- unsigned idRangeOffset;
-} OTF_cmapSubHeader;
-
-typedef struct
-{
- unsigned subHeaderKeys[256];
- OTF_cmapSubHeader *subHeaders;
- unsigned *glyphIndexArray;
-} OTF_EncodingSubtable2;
-
-typedef struct
-{
- unsigned startCount;
- unsigned endCount;
- int idDelta;
- unsigned idRangeOffset;
-} OTF_cmapSegument;
-
-typedef struct
-{
- unsigned segCountX2;
- unsigned searchRange;
- unsigned entrySelector;
- unsigned rangeShift;
- OTF_cmapSegument *segments;
- int GlyphCount;
- unsigned *glyphIdArray;
-} OTF_EncodingSubtable4;
-
-typedef struct
-{
- unsigned firstCode;
- unsigned entryCount;
- unsigned *glyphIdArray;
-} OTF_EncodingSubtable6;
-
-typedef struct
-{
- unsigned startCharCode;
- unsigned endCharCode;
- unsigned startGlyphID;
-} OTF_cmapGroup;
-
-typedef struct
-{
- unsigned char is32[8192];
- unsigned nGroups;
- OTF_cmapGroup *Groups;
-} OTF_EncodingSubtable8;
-
-typedef struct
-{
- unsigned startCharCode;
- unsigned numChars;
- unsigned *glyphs;
-} OTF_EncodingSubtable10;
-
-typedef struct
-{
- unsigned nGroups;
- OTF_cmapGroup *Groups;
-} OTF_EncodingSubtable12;
-
-typedef struct
-{
- unsigned format;
- unsigned length;
- unsigned language;
- union {
- OTF_EncodingSubtable0 *f0;
- OTF_EncodingSubtable2 *f2;
- OTF_EncodingSubtable4 *f4;
- OTF_EncodingSubtable6 *f6;
- OTF_EncodingSubtable8 *f8;
- OTF_EncodingSubtable10 *f10;
- OTF_EncodingSubtable12 *f12;
- }f;
-} OTF_EncodingSubtable;
-
-typedef struct
-{
- unsigned platformID;
- unsigned encodingID;
- unsigned offset;
- OTF_EncodingSubtable subtable;
-} OTF_EncodingRecord;
-
-typedef struct
-{
- unsigned version;
- unsigned numTables;
- OTF_EncodingRecord *EncodingRecord;
- OTF_EncodingRecord *Unicode;
-} OTF_cmap;
-
-\f
-/* name */
-typedef struct
-{
- int platformID;
- int encodingID;
- int languageID;
- int nameID;
- int length;
- int offset;
-} OTF_NameRecord;
-
-#define OTF_max_nameID 23
-
-typedef struct
-{
- int format;
- int count;
- int stringOffset;
- OTF_NameRecord *nameRecord;
- char *name[OTF_max_nameID + 1];
-} OTF_name;
-\f
/* OTF */
typedef struct
{
typedef struct
{
/* Character code of the glyph. This is the only member that a
- client has to set before calling the OTF library function
- otfdrive. */
+ client has to set before calling the function otfdrive(). */
int c;
/* Glyph ID of the glyph. */
/***
- @brief Convert a string to OTF tag.
-
- The function otf_tag () converts the string $STR to OTF tag, and
- return that tag. If $STR is NULL, return 0.
-
- If $STR is not NULL, the length should be at least 4, and the
- first 4 characters are took into an account. */
-
-extern OTF_Tag otf_tag (char *str);
-
-/***
@brief Open an OpenType font file.
The function otf_open () reads the OpenType font file whose name
OTF_GlyphString *gstring);
+/*** (4) APIs for error handling ***/
+
+/*** (4-1) Error codes ***/
+
+/***
+ Global variable holding an error code.
+
+ The variable otf_error is set to one of OTF_ERROR_XXX macros when
+ an error is detected in the OTF library. */
+extern int otf_error;
+
+/***
+ Memory allocation error.
+
+ This error indicates that the library couldn't allocate
+ memory. */
+#define OTF_ERROR_MEMORY 1
+
+/***
+ File error.
+
+ This error indicates that the library fails in opening, reading,
+ or seeking an OTF file. */
+#define OTF_ERROR_FILE 2
+
+/***
+ Invalid table contents.
+
+ This error indicates that an OTF file contains invalid data. */
+#define OTF_ERROR_TABLE 3
+
+/***
+ CMAP driving error.
+
+ See the function otf_drive_cmap() for more detail. */
+#define OTF_ERROR_CMAP_DRIVE 4
+
+/***
+ GDEF driving error.
+
+ See the function otf_drive_gdef() for more detail. */
+#define OTF_ERROR_GDEF_DRIVE 5
+
+/***
+ GSUB driving error.
+
+ See the function otf_drive_gsub() for more detail. */
+#define OTF_ERROR_GSUB_DRIVE 6
+
+/***
+ GPOS driving error.
+
+ See the function otf_drive_gpos() for more detail. */
+#define OTF_ERROR_GPOS_DRIVE 7
+
+
+/***
+ Print an OTF error message
+
+ The otf_perror() function produces a message on the standard error
+ output, describing the last error encountered during a call to the
+ OTF library function. If $PREFIX is not NULL, is is printed
+ first, followed by a colon and a blank. Then the message and a
+ newline. */
+
+extern void otf_perror (char *prefix);
+
+
+/*** (5) APIs miscellaneous ***/
+
+/***
+ Return OTF tag of a specified name string.
+
+ The otf_tag() function returns OTF tag of name $NAME. If $NAME is
+ NULL, return 0. Otherwise, $NAME must be at least 4-byte length.
+ Only the first 4 characters are took into an account. */
+
+extern OTF_Tag otf_tag (char *name);
+
+/***
+ Convert OTF tag to name string.
+
+ The otf_tag_name() function converts OTF tag $TAG to a 5-byte
+ name string (including the terminating NUL), and store it in
+ $NAME. At least 5-byte space must be at $NAME. */
+
+extern void otf_tag_name (OTF_Tag tag, char *name);
+
+
#endif /* not _OTF_H_ */
typedef struct
{
- /* Points to one of OTF->head, OTF->name, etc. */
- void **address;
- /* Function to read one of OTF tables. */
- void *(*reader) (OTF *otf, OTF_Stream *stream);
- /* Stream given to <reader>. */
- OTF_Stream *stream;
+ /* Points to one of OTF->head, OTF->name, etc. */
+ void **address;
+ /* Function to read one of OTF tables. */
+ void *(*reader) (OTF *otf, OTF_Stream *stream);
+ /* Stream given to <reader>. */
+ OTF_Stream *stream;
} OTF_TableInfo;
struct OTF_InternalData
allocate_memory_record (OTF *otf)
{
OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
- OTF_MemoryRecord *memrec = calloc (1, sizeof (OTF_MemoryRecord));
+ OTF_MemoryRecord *memrec = malloc (sizeof (OTF_MemoryRecord));
if (! memrec)
return NULL;
} while (0)
-#define OTF_CALLOC(p, size, arg) \
- do { \
- (p) = calloc ((size), sizeof (*(p))); \
- if (! (p) \
- || ((((OTF_InternalData *) otf->internal_data)->memory_record->used \
- >= OTF_MEMORY_RECORD_SIZE) \
- && (allocate_memory_record (otf) < 0))) \
- OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
- ((OTF_InternalData *) otf->internal_data)->memory_record->memory \
- [((OTF_InternalData *) otf->internal_data)->memory_record->used++] \
- = (p); \
+#define OTF_CALLOC(p, size, arg) \
+ do { \
+ if (size == 0) \
+ (p) = NULL; \
+ else \
+ { \
+ OTF_MemoryRecord *memrec \
+ = ((OTF_InternalData *) otf->internal_data)->memory_record; \
+ (p) = calloc ((size), sizeof (*(p))); \
+ if (! (p) \
+ || (memrec->used >= OTF_MEMORY_RECORD_SIZE \
+ && ! (memrec = allocate_memory_record (otf)))) \
+ OTF_ERROR (OTF_ERROR_MEMORY, (arg)); \
+ memrec->memory[memrec->used++] = (p); \
+ } \
} while (0)
{
char *errfmt = "otf header%s";
int errret = -1;
- OTF_InternalData *internal_data;
OTF_Tag head_tag, name_tag, cmap_tag, gdef_tag, gsub_tag, gpos_tag;
OTF_Stream *stream;
int i;
+ OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
- internal_data = calloc (1, sizeof (OTF_InternalData));
- if (! internal_data)
- OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
- otf->internal_data = internal_data;
internal_data->table_info[OTF_TABLE_TYPE_HEAD].address = (void *) &otf->head;
internal_data->table_info[OTF_TABLE_TYPE_HEAD].reader = read_head_table;
internal_data->table_info[OTF_TABLE_TYPE_NAME].address = (void *) &otf->name;
internal_data->table_info[OTF_TABLE_TYPE_GPOS].address = (void *) &otf->gpos;
internal_data->table_info[OTF_TABLE_TYPE_GPOS].reader = read_gpos_table;
- if (allocate_memory_record (otf) < 0)
- OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
-
head_tag = otf_tag ("head");
name_tag = otf_tag ("name");
cmap_tag = otf_tag ("cmap");
/* APIs */
+OTF_Tag
+otf_tag (char *name)
+{
+ unsigned char *p = (unsigned char *) name;
+
+ if (! name)
+ return (OTF_Tag) 0;
+ return (OTF_Tag) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+}
+
+void
+otf_tag_name (OTF_Tag tag, char *name)
+{
+ name[0] = (char) (tag >> 24);
+ name[1] = (char) ((tag >> 16) & 0xFF);
+ name[2] = (char) ((tag >> 8) & 0xFF);
+ name[3] = (char) (tag & 0xFF);
+ name[4] = '\0';
+}
+
+
/* We can't use memory allocation macros in the following functions
because those macros returns from the functions before freeing
memory previously allocated. */
char *errfmt = "opening otf (%s)";
void *errret = NULL;
OTF *otf;
+ OTF_InternalData *internal_data;
fp = fopen (otf_name, "r");
if (! fp)
OTF_ERROR (OTF_ERROR_MEMORY, "filename allocation");
}
+ internal_data = calloc (1, sizeof (OTF_InternalData));
+ if (! internal_data)
+ OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData");
+ otf->internal_data = internal_data;
+ if (! allocate_memory_record (otf))
+ OTF_ERROR (OTF_ERROR_MEMORY, " (InternalData)");
+
+ /* Here after, all pointers to allocated memory are recorded in
+ otf->internal_data->memory_record except for what allocated by
+ the functions allocate_memory_record and make_stream. */
+
if (read_header_part (otf, fp) < 0)
{
otf_close (otf);
OTF_InternalData *internal_data = otf->internal_data;
int i;
- if (otf->filename)
- free (otf->filename);
- if (otf->table_dirs)
- free (otf->table_dirs);
+ //if (otf->filename)
+ //free (otf->filename);
if (internal_data)
{
OTF_MemoryRecord *memrec = internal_data->memory_record;
{
OTF_MemoryRecord *next = memrec->next;
- for (i = 0; i < memrec->used; i++)
+ for (i = memrec->used - 1; i >= 0; i--)
free (memrec->memory[i]);
free (memrec);
memrec = next;