home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / INAME.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  5KB  |  134 lines

  1. /* Copyright (C) 1989, 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* iname.h */
  20. /* Name table interface */
  21.  
  22. /* Define a name table as an opaque type. */
  23. struct name_table_s;
  24. typedef struct name_table_s name_table;
  25.  
  26. /* Name structure.  The name table is a simple chained hash table. */
  27. /* There is an optimization to avoid lookup for operator and other */
  28. /* global names. */
  29. struct name_s {
  30.     ushort next_index;    /* next name in chain or 0 */
  31.     unsigned foreign_string : 1; /* string is allocated statically */
  32.     unsigned mark : 1;    /* GC mark bit */
  33.     unsigned string_size : 14;
  34. #define max_name_string 0x3fff
  35.     const byte *string_bytes;
  36. /* pvalue specifies the definition status of the name: */
  37. /*    pvalue == pv_no_defn: no definitions */
  38. #define pv_no_defn ((ref *)0)
  39. /*    pvalue == pv_other: other status */
  40. #define pv_other ((ref *)1)
  41. #define pv_valid(pvalue) ((unsigned long)(pvalue) > 1)
  42. /*    pvalue != pv_no_defn, pvalue != pv_other: pvalue is valid */
  43.     ref *pvalue;        /* if only defined in systemdict */
  44.                 /* or userdict, this points to */
  45.                 /* the value */
  46. };
  47. /*typedef struct name_s name;*/        /* in iref.h */
  48.  
  49. /* Procedures for the name table. */
  50.  
  51. /* Allocate and initialize a name table. */
  52. name_table *name_init(P1(gs_memory_t *));
  53.  
  54. /*
  55.  * The size argument for name_ref should be a ushort, but this confuses
  56.  * the Apollo compiler.  The values of enterflag are:
  57.  *    -1 -- don't enter (return an error) if missing;
  58.  *     0 -- enter if missing, don't copy the string, which was allocated
  59.  *        statically;
  60.  *     1 -- enter if missing, copy the string;
  61.  *     2 -- enter if missing, don't copy the string, which was already
  62.  *        allocated dynamically.
  63.  */
  64. int name_ref(P4(const byte *ptr, uint size, ref *pnref, int enterflag));
  65. void name_string_ref(P2(const ref *pnref, ref *psref));
  66. /* name_enter_string calls name_ref with a (permanent) C string. */
  67. int name_enter_string(P2(const char *str, ref *pnref));
  68. /* name_from_string essentially implements cvn. */
  69. /* It always enters the name, and copies the executable attribute. */
  70. int name_from_string(P2(const ref *psref, ref *pnref));
  71.  
  72. /* Compare two names for equality. */
  73. #define name_eq(pnref1, pnref2)\
  74.   (name_index(pnref1) == name_index(pnref2))
  75.  
  76. /* Conversion between names and indices. */
  77. #define name_index(pnref) r_size(pnref)
  78. void name_index_ref(P2(uint index /* should be ushort */,
  79.                ref *pnref));
  80. name *name_index_ptr(P1(uint index /* should be ushort */));
  81.  
  82. /*
  83.  * The name table is a two-level indexed table, consisting of
  84.  * nt_sub_count sub-tables of size nt_sub_size each.
  85.  */
  86. #define nt_log2_sub_size 7
  87. #define nt_sub_size (1 << nt_log2_sub_size)
  88. #define nt_sub_index_mask (nt_sub_size - 1)
  89. #define nt_sub_count (1 << (16 - nt_log2_sub_size))
  90. #define max_name_count ((uint)0xffff)
  91.  
  92. /*
  93.  * We scramble the assignment order within a sub-table, so that
  94.  * dictionary lookup doesn't have to scramble the index.
  95.  * The scrambling algorithm must have three properties:
  96.  *    - It must map 0 to 0;
  97.  *    - It must only scramble the sub-table index;
  98.  *    - It must be a permutation on the sub-table index.
  99.  * We do something very simple for now.
  100.  */
  101. #define name_count_to_index(cnt)\
  102.   (((cnt) & (-nt_sub_size)) +\
  103.    (((cnt) * 59) & nt_sub_index_mask))
  104. #define max_name_index ((uint)0xffff)
  105. /*
  106.  * The reverse permutation requires finding a number R such that
  107.  * 59*R = 1 mod nt_sub_size.  For nt_sub_size any power of 2 up to 2048,
  108.  * R = 243 will work.
  109.  */
  110. #define name_index_to_count(idx)\
  111.   (((idx) & (-nt_sub_size)) +\
  112.    (((idx) * 243) & nt_sub_index_mask))
  113.  
  114. /* Name count interface for GC and save/restore. */
  115. uint name_count(P0());
  116. #define name_is_since_count(pnref, ncnt)\
  117.   name_index_is_since_count(name_index(pnref), ncnt)
  118. #define name_index_is_since_count(nidx, ncnt)\
  119.   (name_index_to_count(nidx) >= ncnt)
  120. gs_memory_t *name_memory(P0());
  121.  
  122. /* Mark a name for the garbage collector. */
  123. /* Return true if this is a new mark. */
  124. bool name_mark_index(P1(uint));
  125.  
  126. /* Get the object (sub-table) containing a name. */
  127. /* The garbage collector needs this so it can relocate pointers to names. */
  128. void/*obj_header_t*/ *name_ref_sub_table(P1(ref *));
  129. void/*obj_header_t*/ *name_index_ptr_sub_table(P2(uint, name *));
  130.  
  131. /* Clean up the name table before a restore, */
  132. /* by removing names whose count is less than old_count. */
  133. void name_restore(P1(uint old_count));
  134.