otlayout.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef __OT_LAYOUT_H__
  2. #define __OT_LAYOUT_H__
  3. #include "otlconf.h"
  4. OTL_BEGIN_HEADER
  5. /************************************************************************/
  6. /************************************************************************/
  7. /***** *****/
  8. /***** BASE DATA TYPES *****/
  9. /***** *****/
  10. /************************************************************************/
  11. /************************************************************************/
  12. typedef unsigned char OTL_Byte;
  13. typedef const OTL_Byte* OTL_Bytes;
  14. typedef int OTL_Error;
  15. typedef void* OTL_Pointer;
  16. typedef int OTL_Int;
  17. typedef unsigned int OTL_UInt;
  18. typedef long OTL_Long;
  19. typedef unsigned long OTL_ULong;
  20. typedef short OTL_Int16;
  21. typedef unsigned short OTL_UInt16;
  22. #if OTL_SIZEOF_INT == 4
  23. typedef int OTL_Int32;
  24. typedef unsigned int OTL_UInt32;
  25. #elif OTL_SIZEOF_LONG == 4
  26. typedef long OTL_Int32;
  27. typedef unsigned long OTL_UInt32;
  28. #else
  29. # error "no 32-bits type found"
  30. #endif
  31. typedef OTL_UInt32 OTL_Tag;
  32. /************************************************************************/
  33. /************************************************************************/
  34. /***** *****/
  35. /***** ERROR CODES *****/
  36. /***** *****/
  37. /************************************************************************/
  38. /************************************************************************/
  39. typedef enum
  40. {
  41. OTL_Err_Ok = 0,
  42. OTL_Err_InvalidArgument,
  43. OTL_Err_InvalidFormat,
  44. OTL_Err_InvalidOffset,
  45. OTL_Err_Max
  46. } OTL_Error;
  47. /************************************************************************/
  48. /************************************************************************/
  49. /***** *****/
  50. /***** MEMORY MANAGEMENT *****/
  51. /***** *****/
  52. /************************************************************************/
  53. /************************************************************************/
  54. typedef OTL_Pointer (*OTL_AllocFunc)( OTL_ULong size,
  55. OTL_Pointer data );
  56. typedef OTL_Pointer (*OTL_ReallocFunc)( OTL_Pointer block,
  57. OTL_ULong size,
  58. OTL_Pointer data );
  59. typedef void (*OTL_FreeFunc)( OTL_Pointer block,
  60. OTL_Pointer data );
  61. typedef struct OTL_MemoryRec_
  62. {
  63. OTL_Pointer mem_data;
  64. OTL_AllocFunc mem_alloc;
  65. OTL_ReallocFunc mem_realloc;
  66. OTL_FreeFunc mem_free;
  67. } OTL_MemoryRec, *OTL_Memory;
  68. /************************************************************************/
  69. /************************************************************************/
  70. /***** *****/
  71. /***** ENUMERATIONS *****/
  72. /***** *****/
  73. /************************************************************************/
  74. /************************************************************************/
  75. /* re-define OTL_MAKE_TAG to something different if you're not */
  76. /* using an ASCII-based character set (Vaxes anyone ?) */
  77. #ifndef OTL_MAKE_TAG
  78. #define OTL_MAKE_TAG(c1,c2,c3,c4) \
  79. ( ( (OTL_UInt32)(c1) << 24 ) | \
  80. (OTL_UInt32)(c2) << 16 ) | \
  81. (OTL_UInt32)(c3) << 8 ) | \
  82. (OTL_UInt32)(c4) )
  83. #endif
  84. typedef enum OTL_ScriptTag_
  85. {
  86. OTL_SCRIPT_NONE = 0,
  87. #define OTL_SCRIPT_TAG(c1,c2,c3,c4,s,n) OTL_SCRIPT_TAG_ ## n = OTL_MAKE_TAG(c1,c2,c3,c4),
  88. #include "otltags.h"
  89. OTL_SCRIPT_MAX
  90. } OTL_ScriptTag;
  91. typedef enum OTL_LangTag_
  92. {
  93. OTL_LANG_DEFAULT = 0,
  94. #define OTL_LANG_TAG(c1,c2,c3,c4,s,n) OTL_LANG_TAG_ ## n = OTL_MAKE_TAG(c1,c2,c3,c4),
  95. #include "otltags.h"
  96. OTL_LANG_MAX
  97. } OTL_LangTag;
  98. /************************************************************************/
  99. /************************************************************************/
  100. /***** *****/
  101. /***** MEMORY READS *****/
  102. /***** *****/
  103. /************************************************************************/
  104. /************************************************************************/
  105. #define OTL_PEEK_USHORT(p) ( ((OTL_UInt)((p)[0]) << 8) | \
  106. ((OTL_UInt)((p)[1]) ) )
  107. #define OTL_PEEK_ULONG(p) ( ((OTL_UInt32)((p)[0]) << 24) | \
  108. ((OTL_UInt32)((p)[1]) << 16) | \
  109. ((OTL_UInt32)((p)[2]) << 8) | \
  110. ((OTL_UInt32)((p)[3]) ) )
  111. #define OTL_PEEK_SHORT(p) ((OTL_Int16)OTL_PEEK_USHORT(p))
  112. #define OTL_PEEK_LONG(p) ((OTL_Int32)OTL_PEEK_ULONG(p))
  113. #define OTL_NEXT_USHORT(p) ( (p) += 2, OTL_PEEK_USHORT((p)-2) )
  114. #define OTL_NEXT_ULONG(p) ( (p) += 4, OTL_PEEK_ULONG((p)-4) )
  115. #define OTL_NEXT_SHORT(p) ((OTL_Int16)OTL_NEXT_USHORT(p))
  116. #define OTL_NEXT_LONG(p) ((OTL_Int32)OTL_NEXT_ULONG(p))
  117. /************************************************************************/
  118. /************************************************************************/
  119. /***** *****/
  120. /***** VALIDATION *****/
  121. /***** *****/
  122. /************************************************************************/
  123. /************************************************************************/
  124. typedef struct OTL_ValidatorRec_* OTL_Validator;
  125. typedef struct OTL_ValidatorRec_
  126. {
  127. OTL_Bytes limit;
  128. OTL_Bytes base;
  129. OTL_Error error;
  130. OTL_jmp_buf jump_buffer;
  131. } OTL_ValidatorRec;
  132. typedef void (*OTL_ValidateFunc)( OTL_Bytes table,
  133. OTL_Valid valid );
  134. OTL_API( void )
  135. otl_validator_error( OTL_Validator validator,
  136. OTL_Error error );
  137. #define OTL_INVALID(e) otl_validator_error( valid, e )
  138. #define OTL_INVALID_TOO_SHORT OTL_INVALID( OTL_Err_InvalidOffset )
  139. #define OTL_INVALID_DATA OTL_INVALID( OTL_Err_InvalidFormat )
  140. #define OTL_CHECK(_count) OTL_BEGIN_STMNT \
  141. if ( p + (_count) > valid->limit ) \
  142. OTL_INVALID_TOO_SHORT; \
  143. OTL_END_STMNT
  144. /* */
  145. OTL_END_HEADER
  146. #endif /* __OPENTYPE_LAYOUT_H__ */