#include "globals.h"
#include "debug.h"
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#ifdef HAVE_PTHREAD_H
static pthread_mutex_t map_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
static _cups_cmap_t *cmap_cache = NULL;
static _cups_vmap_t *vmap_cache = NULL;
static int compare_wide(const void *k1, const void *k2);
static int conv_sbcs_to_utf8(cups_utf8_t *dest,
const cups_sbcs_t *src,
int maxout,
const cups_encoding_t encoding);
static int conv_utf8_to_sbcs(cups_sbcs_t *dest,
const cups_utf8_t *src,
int maxout,
const cups_encoding_t encoding);
static int conv_utf8_to_vbcs(cups_sbcs_t *dest,
const cups_utf8_t *src,
int maxout,
const cups_encoding_t encoding);
static int conv_vbcs_to_utf8(cups_utf8_t *dest,
const cups_sbcs_t *src,
int maxout,
const cups_encoding_t encoding);
static void free_sbcs_charmap(_cups_cmap_t *sbcs);
static void free_vbcs_charmap(_cups_vmap_t *vbcs);
static void *get_charmap(const cups_encoding_t encoding);
static int get_charmap_count(cups_file_t *fp);
static _cups_cmap_t *get_sbcs_charmap(const cups_encoding_t encoding,
const char *filename);
static _cups_vmap_t *get_vbcs_charmap(const cups_encoding_t encoding,
const char *filename);
void
_cupsCharmapFlush(void)
{
_cups_cmap_t *cmap,
*cnext;
_cups_vmap_t *vmap,
*vnext;
#ifdef HAVE_PTHREAD_H
pthread_mutex_lock(&map_mutex);
#endif
for (cmap = cmap_cache; cmap; cmap = cnext)
{
cnext = cmap->next;
free_sbcs_charmap(cmap);
}
cmap_cache = NULL;
for (vmap = vmap_cache; vmap; vmap = vnext)
{
vnext = vmap->next;
free_vbcs_charmap(vmap);
free(vmap);
}
vmap_cache = NULL;
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&map_mutex);
#endif
}
void
_cupsCharmapFree(
const cups_encoding_t encoding)
{
_cups_cmap_t *cmap;
_cups_vmap_t *vmap;
#ifdef HAVE_PTHREAD_H
pthread_mutex_lock(&map_mutex);
#endif
for (cmap = cmap_cache; cmap; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
if (cmap->used > 0)
cmap->used --;
break;
}
}
for (vmap = vmap_cache; vmap; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
if (vmap->used > 0)
vmap->used --;
break;
}
}
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&map_mutex);
#endif
}
void *
_cupsCharmapGet(
const cups_encoding_t encoding)
{
void *charmap;
DEBUG_printf(("_cupsCharmapGet(encoding=%d)\n", encoding));
if (encoding < 0 || encoding >= CUPS_ENCODING_VBCS_END)
{
DEBUG_puts(" Bad encoding, returning NULL!");
return (NULL);
}
#ifdef HAVE_PTHREAD_H
pthread_mutex_lock(&map_mutex);
#endif
charmap = get_charmap(encoding);
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&map_mutex);
#endif
return (charmap);
}
int
cupsCharsetToUTF8(
cups_utf8_t *dest,
const char *src,
const int maxout,
const cups_encoding_t encoding)
{
int bytes;
DEBUG_printf(("cupsCharsetToUTF8(dest=%p, src=\"%s\", maxout=%d, encoding=%d)\n",
dest, src, maxout, encoding));
if (dest)
*dest = '\0';
if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
{
DEBUG_puts(" Bad arguments, returning -1");
return (-1);
}
if (encoding == CUPS_UTF8 ||
encoding < 0 || encoding >= CUPS_ENCODING_VBCS_END)
{
strlcpy((char *)dest, src, maxout);
return ((int)strlen((char *)dest));
}
if (encoding == CUPS_ISO8859_1)
{
int ch;
cups_utf8_t *destptr,
*destend;
destptr = dest;
destend = dest + maxout - 2;
while (*src && destptr < destend)
{
ch = *src++ & 255;
if (ch & 128)
{
*destptr++ = 0xc0 | (ch >> 6);
*destptr++ = 0x80 | (ch & 0x3f);
}
else
*destptr++ = ch;
}
*destptr = '\0';
return ((int)(destptr - dest));
}
#ifdef HAVE_PTHREAD_H
pthread_mutex_lock(&map_mutex);
#endif
if (encoding < CUPS_ENCODING_SBCS_END)
bytes = conv_sbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding);
else if (encoding < CUPS_ENCODING_VBCS_END)
bytes = conv_vbcs_to_utf8(dest, (cups_sbcs_t *)src, maxout, encoding);
else
{
DEBUG_puts(" Bad encoding, returning -1");
bytes = -1;
}
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&map_mutex);
#endif
return (bytes);
}
int
cupsUTF8ToCharset(
char *dest,
const cups_utf8_t *src,
const int maxout,
const cups_encoding_t encoding)
{
int bytes;
if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
{
if (dest)
*dest = '\0';
return (-1);
}
if (encoding == CUPS_UTF8 ||
encoding < 0 || encoding >= CUPS_ENCODING_VBCS_END)
{
strlcpy(dest, (char *)src, maxout);
return ((int)strlen(dest));
}
if (encoding == CUPS_ISO8859_1)
{
int ch;
char *destptr,
*destend;
destptr = dest;
destend = dest + maxout - 1;
while (*src && destptr < destend)
{
ch = *src++;
if ((ch & 0xe0) == 0xc0)
{
ch = ((ch & 0x1f) << 6) | (*src++ & 0x3f);
if (ch < 256)
*destptr++ = ch;
else
*destptr++ = '?';
}
else if ((ch & 0xf0) == 0xe0 ||
(ch & 0xf8) == 0xf0)
*destptr++ = '?';
else if (!(ch & 0x80))
*destptr++ = ch;
}
*destptr = '\0';
return ((int)(destptr - dest));
}
#ifdef HAVE_PTHREAD_H
pthread_mutex_lock(&map_mutex);
#endif
if (encoding < CUPS_ENCODING_SBCS_END)
bytes = conv_utf8_to_sbcs((cups_sbcs_t *)dest, src, maxout, encoding);
else if (encoding < CUPS_ENCODING_VBCS_END)
bytes = conv_utf8_to_vbcs((cups_sbcs_t *)dest, src, maxout, encoding);
else
bytes = -1;
#ifdef HAVE_PTHREAD_H
pthread_mutex_unlock(&map_mutex);
#endif
return (bytes);
}
int
cupsUTF8ToUTF32(
cups_utf32_t *dest,
const cups_utf8_t *src,
const int maxout)
{
int i;
cups_utf8_t ch;
cups_utf8_t next;
cups_utf32_t ch32;
if (dest)
*dest = 0;
if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
return (-1);
*dest++ = 0xfeff;
for (i = maxout - 1; *src && i > 0; i --)
{
ch = *src++;
if (!(ch & 0x80))
{
*dest++ = ch;
continue;
}
else if ((ch & 0xe0) == 0xc0)
{
next = *src++;
if (!next)
return (-1);
ch32 = ((ch & 0x1f) << 6) | (next & 0x3f);
if (ch32 < 0x80)
return (-1);
*dest++ = ch32;
}
else if ((ch & 0xf0) == 0xe0)
{
next = *src++;
if (!next)
return (-1);
ch32 = ((ch & 0x0f) << 6) | (next & 0x3f);
next = *src++;
if (!next)
return (-1);
ch32 = (ch32 << 6) | (next & 0x3f);
if (ch32 < 0x800)
return (-1);
*dest++ = ch32;
}
else if ((ch & 0xf8) == 0xf0)
{
next = *src++;
if (!next)
return (-1);
ch32 = ((ch & 0x07) << 6) | (next & 0x3f);
next = *src++;
if (!next)
return (-1);
ch32 = (ch32 << 6) | (next & 0x3f);
next = *src++;
if (!next)
return (-1);
ch32 = (ch32 << 6) | (next & 0x3f);
if (ch32 < 0x10000)
return (-1);
*dest++ = ch32;
}
else
{
return (-1);
}
if (ch32 >= 0xd800 && ch32 <= 0xdfff)
return (-1);
}
*dest = 0;
return (i);
}
int
cupsUTF32ToUTF8(
cups_utf8_t *dest,
const cups_utf32_t *src,
const int maxout)
{
cups_utf8_t *start;
int i;
int swap;
cups_utf32_t ch;
if (dest)
*dest = '\0';
if (!dest || !src || maxout < 1)
return (-1);
start = dest;
swap = *src == 0xfffe0000;
if (*src == 0xfffe0000 || *src == 0xfeff)
src ++;
for (i = maxout - 1; *src && i > 0;)
{
ch = *src++;
if (swap)
ch = ((ch >> 24) | ((ch >> 8) & 0xff00) | ((ch << 8) & 0xff0000));
if (ch > 0x10ffff)
return (-1);
if (ch < 0x80)
{
*dest++ = (cups_utf8_t)ch;
i --;
}
else if (ch < 0x800)
{
if (i < 2)
return (-1);
*dest++ = (cups_utf8_t)(0xc0 | ((ch >> 6) & 0x1f));
*dest++ = (cups_utf8_t)(0x80 | (ch & 0x3f));
i -= 2;
}
else if (ch < 0x10000)
{
if (i < 3)
return (-1);
*dest++ = (cups_utf8_t)(0xe0 | ((ch >> 12) & 0x0f));
*dest++ = (cups_utf8_t)(0x80 | ((ch >> 6) & 0x3f));
*dest++ = (cups_utf8_t)(0x80 | (ch & 0x3f));
i -= 3;
}
else
{
if (i < 4)
return (-1);
*dest++ = (cups_utf8_t)(0xf0 | ((ch >> 18) & 0x07));
*dest++ = (cups_utf8_t)(0x80 | ((ch >> 12) & 0x3f));
*dest++ = (cups_utf8_t)(0x80 | ((ch >> 6) & 0x3f));
*dest++ = (cups_utf8_t)(0x80 | (ch & 0x3f));
i -= 4;
}
}
*dest = '\0';
return ((int)(dest - start));
}
static int
compare_wide(const void *k1,
const void *k2)
{
cups_vbcs_t key;
cups_vbcs_t map;
key = *((cups_vbcs_t *)k1);
map = ((_cups_wide2uni_t *)k2)->widechar;
return ((int)(key - map));
}
static int
conv_sbcs_to_utf8(
cups_utf8_t *dest,
const cups_sbcs_t *src,
int maxout,
const cups_encoding_t encoding)
{
_cups_cmap_t *cmap;
cups_ucs2_t *crow;
cups_sbcs_t legchar;
cups_utf32_t work[CUPS_MAX_USTRING],
*workptr;
if ((cmap = (_cups_cmap_t *)get_charmap(encoding)) == NULL)
return (-1);
work[0] = 0xfeff;
for (workptr = work + 1; *src && workptr < (work + CUPS_MAX_USTRING - 1);)
{
legchar = *src++;
if (legchar < 0x80)
*workptr++ = (cups_utf32_t)legchar;
else
{
crow = cmap->char2uni + legchar;
if (!*crow)
*workptr++ = 0xfffd;
else
*workptr++ = (cups_utf32_t)*crow;
}
}
*workptr = 0;
cmap->used --;
return (cupsUTF32ToUTF8(dest, work, maxout));
}
static int
conv_utf8_to_sbcs(
cups_sbcs_t *dest,
const cups_utf8_t *src,
int maxout,
const cups_encoding_t encoding)
{
cups_sbcs_t *start;
_cups_cmap_t *cmap;
cups_sbcs_t *srow;
cups_utf32_t unichar;
cups_utf32_t work[CUPS_MAX_USTRING],
*workptr;
if ((cmap = (_cups_cmap_t *)get_charmap(encoding)) == NULL)
return (-1);
if (cupsUTF8ToUTF32(work, src, CUPS_MAX_USTRING) < 0)
return (-1);
for (workptr = work + 1, start = dest; *workptr && maxout > 1; maxout --)
{
unichar = *workptr++;
if (!unichar)
break;
if (unichar < 0x80)
{
*dest++ = (cups_sbcs_t)unichar;
continue;
}
srow = cmap->uni2char[(int)((unichar >> 8) & 0xff)];
if (srow)
srow += (int)(unichar & 0xff);
if (!srow || !*srow)
*dest++ = '?';
else
*dest++ = *srow;
}
*dest = '\0';
cmap->used --;
return ((int)(dest - start));
}
static int
conv_utf8_to_vbcs(
cups_sbcs_t *dest,
const cups_utf8_t *src,
int maxout,
const cups_encoding_t encoding)
{
cups_sbcs_t *start;
_cups_vmap_t *vmap;
cups_vbcs_t *vrow;
cups_utf32_t unichar;
cups_vbcs_t legchar;
cups_utf32_t work[CUPS_MAX_USTRING],
*workptr;
if ((vmap = (_cups_vmap_t *)get_charmap(encoding)) == NULL)
return (-1);
if (cupsUTF8ToUTF32(work, src, CUPS_MAX_USTRING) < 0)
return (-1);
for (start = dest, workptr = work + 1; *workptr && maxout > 1; maxout --)
{
unichar = *workptr++;
if (!unichar)
break;
if (unichar < 0x80)
{
*dest++ = (cups_sbcs_t)unichar;
continue;
}
vrow = vmap->uni2char[(int)((unichar >> 8) & 0xff)];
if (vrow)
vrow += (int)(unichar & 0xff);
if (!vrow || !*vrow)
legchar = (cups_vbcs_t)'?';
else
legchar = (cups_vbcs_t)*vrow;
if (legchar > 0xffffff)
{
if (maxout < 5)
return (-1);
*dest++ = (cups_sbcs_t)(legchar >> 24);
*dest++ = (cups_sbcs_t)(legchar >> 16);
*dest++ = (cups_sbcs_t)(legchar >> 8);
*dest++ = (cups_sbcs_t)legchar;
maxout -= 3;
}
else if (legchar > 0xffff)
{
if (maxout < 4)
return (-1);
*dest++ = (cups_sbcs_t)(legchar >> 16);
*dest++ = (cups_sbcs_t)(legchar >> 8);
*dest++ = (cups_sbcs_t)legchar;
maxout -= 2;
}
else if (legchar > 0xff)
{
*dest++ = (cups_sbcs_t)(legchar >> 8);
*dest++ = (cups_sbcs_t)legchar;
maxout --;
}
}
*dest = '\0';
vmap->used --;
return ((int)(dest - start));
}
static int
conv_vbcs_to_utf8(
cups_utf8_t *dest,
const cups_sbcs_t *src,
int maxout,
const cups_encoding_t encoding)
{
_cups_vmap_t *vmap;
cups_ucs2_t *crow;
_cups_wide2uni_t *wide2uni;
cups_sbcs_t leadchar;
cups_vbcs_t legchar;
cups_utf32_t work[CUPS_MAX_USTRING],
*workptr;
if ((vmap = (_cups_vmap_t *)get_charmap(encoding)) == NULL)
return (-1);
work[0] = 0xfeff;
for (workptr = work + 1; *src && workptr < (work + CUPS_MAX_USTRING - 1);)
{
legchar = *src++;
leadchar = (cups_sbcs_t)legchar;
if (legchar < 0x80)
{
*workptr++ = (cups_utf32_t)legchar;
continue;
}
if (vmap->lead2char[(int)leadchar] == leadchar)
{
if (!*src)
return (-1);
legchar = (legchar << 8) | *src++;
crow = vmap->char2uni[(int)((legchar >> 8) & 0xff)];
if (crow)
crow += (int) (legchar & 0xff);
if (!crow || !*crow)
*workptr++ = 0xfffd;
else
*workptr++ = (cups_utf32_t)*crow;
continue;
}
if (vmap->lead3char[(int)leadchar] == leadchar)
{
if (!*src || !src[1])
return (-1);
legchar = (legchar << 8) | *src++;
legchar = (legchar << 8) | *src++;
}
else if (vmap->lead4char[(int)leadchar] == leadchar)
{
if (!*src || !src[1] || !src[2])
return (-1);
legchar = (legchar << 8) | *src++;
legchar = (legchar << 8) | *src++;
legchar = (legchar << 8) | *src++;
}
else
return (-1);
wide2uni = (_cups_wide2uni_t *)bsearch(&legchar,
vmap->wide2uni,
vmap->widecount,
sizeof(_cups_wide2uni_t),
compare_wide);
if (!wide2uni || !wide2uni->unichar)
*workptr++ = 0xfffd;
else
*workptr++ = wide2uni->unichar;
}
*workptr = 0;
vmap->used --;
return (cupsUTF32ToUTF8(dest, work, maxout));
}
static void
free_sbcs_charmap(_cups_cmap_t *cmap)
{
int i;
for (i = 0; i < 256; i ++)
if (cmap->uni2char[i])
free(cmap->uni2char[i]);
free(cmap);
}
static void
free_vbcs_charmap(_cups_vmap_t *vmap)
{
int i;
for (i = 0; i < 256; i ++)
if (vmap->char2uni[i])
free(vmap->char2uni[i]);
for (i = 0; i < 256; i ++)
if (vmap->uni2char[i])
free(vmap->uni2char[i]);
if (vmap->wide2uni)
free(vmap->wide2uni);
free(vmap);
}
static void *
get_charmap(
const cups_encoding_t encoding)
{
char filename[1024];
_cups_globals_t *cg = _cupsGlobals();
snprintf(filename, sizeof(filename), "%s/charmaps/%s.txt",
cg->cups_datadir, _cupsEncodingName(encoding));
DEBUG_printf((" filename=\"%s\"\n", filename));
if (encoding < CUPS_ENCODING_SBCS_END)
return (get_sbcs_charmap(encoding, filename));
else if (encoding < CUPS_ENCODING_VBCS_END)
return (get_vbcs_charmap(encoding, filename));
else
return (NULL);
}
static int
get_charmap_count(cups_file_t *fp)
{
int count;
char line[256];
count = 0;
while (cupsFileGets(fp, line, sizeof(line)))
if (line[0] == '0')
count ++;
if (count > 0)
return (count);
else
return (-1);
}
static _cups_cmap_t *
get_sbcs_charmap(
const cups_encoding_t encoding,
const char *filename)
{
unsigned long legchar;
cups_utf32_t unichar;
_cups_cmap_t *cmap;
cups_file_t *fp;
char *s;
cups_ucs2_t *crow;
cups_sbcs_t *srow;
char line[256];
for (cmap = cmap_cache; cmap; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
cmap->used ++;
DEBUG_printf((" returning existing cmap=%p\n", cmap));
return ((void *)cmap);
}
}
if ((fp = cupsFileOpen(filename, "r")) == NULL)
return (NULL);
if ((cmap = (_cups_cmap_t *)calloc(1, sizeof(_cups_cmap_t))) == NULL)
{
cupsFileClose(fp);
DEBUG_puts(" Unable to allocate memory!");
return (NULL);
}
cmap->used ++;
cmap->encoding = encoding;
while (cupsFileGets(fp, line, sizeof(line)))
{
if (line[0] != '0')
continue;
legchar = strtol(line, &s, 16);
if (legchar < 0 || legchar > 0xff)
goto sbcs_error;
unichar = strtol(s, NULL, 16);
if (unichar < 0 || unichar > 0xffff)
goto sbcs_error;
crow = cmap->char2uni + legchar;
*crow = (cups_ucs2_t)(unichar & 0xffff);
srow = cmap->uni2char[(unichar >> 8) & 0xff];
if (!srow)
{
srow = (cups_sbcs_t *)calloc(256, sizeof(cups_sbcs_t));
if (!srow)
goto sbcs_error;
cmap->uni2char[(unichar >> 8) & 0xff] = srow;
}
srow += unichar & 0xff;
if (unichar == 0xfffd)
legchar = (unsigned long)'?';
if (!*srow)
*srow = (cups_sbcs_t)legchar;
}
cupsFileClose(fp);
cmap->next = cmap_cache;
cmap_cache = cmap;
DEBUG_printf((" returning new cmap=%p\n", cmap));
return (cmap);
sbcs_error:
free_sbcs_charmap(cmap);
cupsFileClose(fp);
DEBUG_puts(" Error, returning NULL!");
return (NULL);
}
static _cups_vmap_t *
get_vbcs_charmap(
const cups_encoding_t encoding,
const char *filename)
{
_cups_vmap_t *vmap;
cups_ucs2_t *crow;
cups_vbcs_t *vrow;
_cups_wide2uni_t *wide2uni;
cups_sbcs_t leadchar;
unsigned long legchar;
cups_utf32_t unichar;
int mapcount;
cups_file_t *fp;
char *s;
char line[256];
int i;
int legacy;
DEBUG_printf(("get_vbcs_charmap(encoding=%d, filename=\"%s\")\n",
encoding, filename));
for (vmap = vmap_cache; vmap; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
vmap->used ++;
DEBUG_printf((" returning existing vmap=%p\n", vmap));
return ((void *)vmap);
}
}
if ((fp = cupsFileOpen(filename, "r")) == NULL)
{
DEBUG_printf((" Unable to open file: %s\n", strerror(errno)));
return (NULL);
}
if ((mapcount = get_charmap_count(fp)) <= 0)
{
DEBUG_puts(" Unable to get charmap count!");
return (NULL);
}
DEBUG_printf((" mapcount=%d\n", mapcount));
if ((vmap = (_cups_vmap_t *)calloc(1, sizeof(_cups_vmap_t))) == NULL)
{
cupsFileClose(fp);
DEBUG_puts(" Unable to allocate memory!");
return (NULL);
}
vmap->used ++;
vmap->encoding = encoding;
leadchar = 0;
wide2uni = NULL;
cupsFileRewind(fp);
i = 0;
legacy = 0;
while (cupsFileGets(fp, line, sizeof(line)))
{
if (line[0] != '0')
continue;
legchar = strtoul(line, &s, 16);
if (legchar == ULONG_MAX)
goto vbcs_error;
unichar = strtol(s, NULL, 16);
if (unichar < 0 || unichar > 0xffff)
goto vbcs_error;
i ++;
if (legchar > 0xff && legchar <= 0xffff)
{
leadchar = (cups_sbcs_t)(legchar >> 8);
vmap->lead2char[leadchar] = leadchar;
}
if (legchar > 0xffff && legchar <= 0xffffff)
{
leadchar = (cups_sbcs_t)(legchar >> 16);
vmap->lead3char[leadchar] = leadchar;
}
if (legchar > 0xffffff)
{
leadchar = (cups_sbcs_t)(legchar >> 24);
vmap->lead4char[leadchar] = leadchar;
}
if (legchar <= 0xffff)
{
crow = vmap->char2uni[(int)leadchar];
if (!crow)
{
crow = (cups_ucs2_t *)calloc(256, sizeof(cups_ucs2_t));
if (!crow)
goto vbcs_error;
vmap->char2uni[(int)leadchar] = crow;
}
crow[(int)(legchar & 0xff)] = (cups_ucs2_t)unichar;
}
else
{
if (!legacy)
{
legacy = 1;
vmap->widecount = (mapcount - i + 1);
wide2uni = (_cups_wide2uni_t *)calloc(vmap->widecount,
sizeof(_cups_wide2uni_t));
if (!wide2uni)
goto vbcs_error;
vmap->wide2uni = wide2uni;
}
wide2uni->widechar = (cups_vbcs_t)legchar;
wide2uni->unichar = (cups_ucs2_t)unichar;
wide2uni ++;
}
vrow = vmap->uni2char[(int)((unichar >> 8) & 0xff)];
if (!vrow)
{
vrow = (cups_vbcs_t *)calloc(256, sizeof(cups_vbcs_t));
if (!vrow)
goto vbcs_error;
vmap->uni2char[(int) ((unichar >> 8) & 0xff)] = vrow;
}
vrow += (int)(unichar & 0xff);
if (unichar == 0xfffd)
legchar = (unsigned long)'?';
if (!*vrow)
*vrow = (cups_vbcs_t)legchar;
}
vmap->charcount = (i - vmap->widecount);
cupsFileClose(fp);
vmap->next = vmap_cache;
vmap_cache = vmap;
DEBUG_printf((" returning new vmap=%p\n", vmap));
return (vmap);
vbcs_error:
free_vbcs_charmap(vmap);
cupsFileClose(fp);
DEBUG_puts(" Error, returning NULL!");
return (NULL);
}