| 1 |
#ifdef HAVE_CONFIG_H |
| 2 |
#include <config.h> |
| 3 |
#endif |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
#include <string.h> |
| 8 |
#include "ttf.h" |
| 9 |
#include "ttfutil.h" |
| 10 |
|
| 11 |
/* $Id: ttfutil.c,v 1.1.1.1 1998/06/05 07:47:52 robert Exp $ */ |
| 12 |
|
| 13 |
/* FixedSplit: split Fixed in to two interger (16.16) */ |
| 14 |
void FixedSplit(Fixed f,int b[]) |
| 15 |
{ |
| 16 |
b[0] = f & 0xff00; |
| 17 |
b[1] = f >> 16; |
| 18 |
} |
| 19 |
|
| 20 |
char * |
| 21 |
TagToStr(ULONG tag) |
| 22 |
{ |
| 23 |
static char str[5] = "XXXX"; |
| 24 |
|
| 25 |
str[0] = (tag >> 24) & 0xff; |
| 26 |
str[1] = (tag >> 16) & 0xff; |
| 27 |
str[2] = (tag >> 8) & 0xff; |
| 28 |
str[3] = tag & 0xff; |
| 29 |
return str; |
| 30 |
} |
| 31 |
|
| 32 |
void ttfError(const char * msg) |
| 33 |
{ |
| 34 |
fprintf(stderr,"%s",msg); |
| 35 |
exit(EXIT_FAILURE); |
| 36 |
} |
| 37 |
|
| 38 |
#ifndef KPATHSEA |
| 39 |
/* Functions copied or adapted from kpathsea. */ |
| 40 |
long |
| 41 |
xftell (FILE *fp, const char *funcname) |
| 42 |
{ |
| 43 |
long where = ftell (fp); |
| 44 |
|
| 45 |
if (where < 0) |
| 46 |
FATAL_PERROR(funcname); |
| 47 |
|
| 48 |
return where; |
| 49 |
} |
| 50 |
|
| 51 |
void |
| 52 |
xfseek (FILE *f, long offset, int wherefrom, const char *funcname) |
| 53 |
{ |
| 54 |
if (fseek (f, offset, wherefrom) < 0) |
| 55 |
FATAL_PERROR(funcname); |
| 56 |
} |
| 57 |
|
| 58 |
void * |
| 59 |
xmalloc (size_t size) |
| 60 |
{ |
| 61 |
void *new_mem = (void *)malloc(size ? size : 1); |
| 62 |
|
| 63 |
if (new_mem == NULL) { |
| 64 |
fprintf(stderr, "fatal: memory exhausted (xmalloc of %lu bytes).\n", |
| 65 |
(unsigned long)size); |
| 66 |
exit(EXIT_FAILURE); |
| 67 |
} |
| 68 |
|
| 69 |
return new_mem; |
| 70 |
} |
| 71 |
|
| 72 |
void * |
| 73 |
xcalloc (size_t nelem, size_t elsize) |
| 74 |
{ |
| 75 |
void *new_mem = (void*)calloc(nelem ? nelem : 1, elsize ? elsize : 1); |
| 76 |
|
| 77 |
if (new_mem == NULL) { |
| 78 |
fprintf(stderr, |
| 79 |
"xcalloc: request for %lu elements of size %lu failed.\n", |
| 80 |
(unsigned long)nelem, (unsigned long)elsize); |
| 81 |
exit(EXIT_FAILURE); |
| 82 |
} |
| 83 |
|
| 84 |
return new_mem; |
| 85 |
} |
| 86 |
|
| 87 |
char * |
| 88 |
xstrdup (const char *s) |
| 89 |
{ |
| 90 |
char *new_string = xmalloc(strlen (s) + 1); |
| 91 |
return strcpy(new_string, s); |
| 92 |
} |
| 93 |
#endif /* !KPATHSEA */ |