w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Dict.cc
Go to the documentation of this file.
1 //========================================================================
2 //
3 // Dict.cc
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #include <aconf.h>
10 
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14 
15 #include <stddef.h>
16 #include <string.h>
17 #include "gmem.h"
18 #include "gmempp.h"
19 #include "Object.h"
20 #include "XRef.h"
21 #include "Dict.h"
22 
23 //------------------------------------------------------------------------
24 
25 struct DictEntry {
26  char *key;
29 };
30 
31 //------------------------------------------------------------------------
32 // Dict
33 //------------------------------------------------------------------------
34 
35 Dict::Dict(XRef *xrefA) {
36  xref = xrefA;
37  size = 8;
38  length = 0;
39  entries = (DictEntry *)gmallocn(size, sizeof(DictEntry));
40  hashTab = (DictEntry **)gmallocn(2 * size - 1, sizeof(DictEntry *));
41  memset(hashTab, 0, (2 * size - 1) * sizeof(DictEntry *));
42  ref = 1;
43 }
44 
46  int i;
47 
48  for (i = 0; i < length; ++i) {
49  gfree(entries[i].key);
50  entries[i].val.free();
51  }
52  gfree(entries);
53  gfree(hashTab);
54 }
55 
56 void Dict::add(char *key, Object *val) {
57  DictEntry *e;
58  int h;
59 
60  if ((e = find(key))) {
61  e->val.free();
62  e->val = *val;
63  gfree(key);
64  } else {
65  if (length == size) {
66  expand();
67  }
68  h = hash(key);
69  entries[length].key = key;
70  entries[length].val = *val;
72  hashTab[h] = &entries[length];
73  ++length;
74  }
75 }
76 
77 void Dict::expand() {
78  int h, i;
79 
80  size *= 2;
82  hashTab = (DictEntry **)greallocn(hashTab, 2 * size - 1,
83  sizeof(DictEntry *));
84  memset(hashTab, 0, (2 * size - 1) * sizeof(DictEntry *));
85  for (i = 0; i < length; ++i) {
86  h = hash(entries[i].key);
87  entries[i].next = hashTab[h];
88  hashTab[h] = &entries[i];
89  }
90 }
91 
92 inline DictEntry *Dict::find(const char *key) {
93  DictEntry *e;
94  int h;
95 
96  h = hash(key);
97  for (e = hashTab[h]; e; e = e->next) {
98  if (!strcmp(key, e->key)) {
99  return e;
100  }
101  }
102  return NULL;
103 }
104 
105 int Dict::hash(const char *key) {
106  const char *p;
107  unsigned int h;
108 
109  h = 0;
110  for (p = key; *p; ++p) {
111  h = 17 * h + (int)(*p & 0xff);
112  }
113  return (int)(h % (2 * size - 1));
114 }
115 
116 GBool Dict::is(const char *type) {
117  DictEntry *e;
118 
119  return (e = find("Type")) && e->val.isName(type);
120 }
121 
122 Object *Dict::lookup(const char *key, Object *obj, int recursion) {
123  DictEntry *e;
124 
125  return (e = find(key)) ? e->val.fetch(xref, obj, recursion)
126  : obj->initNull();
127 }
128 
129 Object *Dict::lookupNF(const char *key, Object *obj) {
130  DictEntry *e;
131 
132  return (e = find(key)) ? e->val.copy(obj) : obj->initNull();
133 }
134 
135 char *Dict::getKey(int i) {
136  return entries[i].key;
137 }
138 
140  return entries[i].val.fetch(xref, obj);
141 }
142 
144  return entries[i].val.copy(obj);
145 }
#define type(a)
Definition: aptex-macros.h:171
DictEntry * find(const char *key)
Definition: Dict.cc:92
char * getKey(int i)
Definition: Dict.cc:135
DictEntry ** hashTab
Definition: Dict.h:75
long ref
Definition: Dict.h:81
~Dict()
Definition: Dict.cc:45
void add(char *key, Object *val)
Definition: Dict.cc:56
GBool is(const char *type)
Definition: Dict.cc:116
XRef * xref
Definition: Dict.h:73
Dict(XRef *xrefA)
Definition: Dict.cc:35
int hash(const char *key)
Definition: Dict.cc:105
int length
Definition: Dict.h:77
void expand()
Definition: Dict.cc:77
DictEntry * entries
Definition: Dict.h:74
Object * lookupNF(const char *key, Object *obj)
Definition: Dict.cc:129
Object * getVal(int i, Object *obj)
Definition: Dict.cc:139
Object * lookup(const char *key, Object *obj, int recursion=0)
Definition: Dict.cc:122
Object * getValNF(int i, Object *obj)
Definition: Dict.cc:143
int size
Definition: Dict.h:76
Definition: Object.h:84
void free()
Definition: Object.cc:119
Object * copy(Object *obj)
Definition: Object.cc:80
Object * fetch(XRef *xref, Object *obj, int recursion=0)
Definition: Object.cc:114
Object * initNull()
Definition: Object.h:102
Definition: XRef.h:58
#define gfree(p)
Definition: dt2dv.c:326
int h
Definition: dviconv.c:9
int strcmp()
Definition: coll.cpp:143
void * greallocn(void *p, int nObjs, int objSize)
Definition: gmem.cc:291
void * gmallocn(int nObjs, int objSize)
Definition: gmem.cc:204
int GBool
Definition: gtypes.h:16
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
bstring c int memset(void *s, int c, int length)
ShellFileEnvironment e
Definition: sh6.c:388
char * key
Definition: Dict.cc:26
DictEntry * next
Definition: Dict.cc:28
Object val
Definition: Dict.cc:27
Definition: strexpr.c:21
#define key
Definition: tex2xindy.c:753
val
Definition: tex4ht.c:3227
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)