1 /* Copyright (c) 1997-1998 by Juliusz Chroboczek */
12 #define ALIAS_FILE_TO_FILECOOKIE
14 #include "libc-extension.hh"
17 mymalloc (size_t size)
20 if ((p = malloc (size)) == NULL)
21 error ("Unable to allocate memory\n");
26 mycalloc (size_t nelem, size_t elsize)
29 if ((p = calloc (nelem, elsize)) == NULL)
30 error ("Unable to allocate memory\n");
35 myrealloc (void *ptr, size_t size)
38 if ((p = realloc (ptr, size)) == NULL)
39 error ("Unable to allocate memory\n");
44 surely_lseek (int fildes, off_t offset, int whence)
47 if ((result = lseek (fildes, offset, whence)) < 0)
48 error ("Bad TTF file");
55 fprintf (stderr, "%s\n", string);
60 syserror (char *string)
67 surely_read (int fildes, void *buf, size_t nbyte)
70 if ((n = read (fildes, buf, nbyte)) < nbyte)
71 error ("Bad TTF file");
76 unistrncpy (char *dst, char *str, size_t length)
80 for (i = j = 0; i < length; i += 2)
82 dst[j++] = str[i + 1];
88 fputpss (char *s, FILE * stream)
92 if ((*s & 0200) == 0 && *s >= 040 && *s != '(' && *s != ')')
95 fprintf (stream, "\\%03o", (unsigned char) *s);
107 for (i = 0; string[i] != '\0'; i++)
108 u = (u << 2) + string[i];
113 make_hashtable (int size)
117 t = mymalloc (sizeof (struct hashtable));
119 t->buckets = mycalloc (size, sizeof (struct hashtable_bucket *));
125 puthash (struct hashtable *t, char *key, int value)
129 i = hash (key) % t->size;
131 if (t->buckets[i] == 0)
133 t->buckets[i] = mymalloc (sizeof (struct hashtable_bucket));
134 t->buckets[i]->entries = mymalloc (4 * sizeof (struct hashtable_entry));
135 t->buckets[i]->size = 4;
136 t->buckets[i]->nentries = 0;
139 if (t->buckets[i]->nentries >= t->buckets[i]->size)
141 t->buckets[i]->entries = myrealloc (t->buckets[i]->entries,
142 t->buckets[i]->size * 2 *
143 sizeof (struct hashtable_entry));
144 t->buckets[i]->size *= 2;
147 t->buckets[i]->entries[t->buckets[i]->nentries].key = key;
148 t->buckets[i]->entries[t->buckets[i]->nentries].value = value;
149 t->buckets[i]->nentries++;
155 gethash (struct hashtable *t, char *key)
159 i = hash (key) % t->size;
161 for (j = 0; j < t->buckets[i]->nentries; j++)
162 if (!strcmp (key, t->buckets[i]->entries[j].key))
163 return t->buckets[i]->entries[j].value;