1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/*
** Copyright 2001-2003 Double Precision, Inc.
** See COPYING for distribution information.
**
** $Id: windows874u.c,v 1.2 2003/03/07 00:47:31 mrsam Exp $
*/
#include "unicode_config.h"
#include "unicode.h"
#include <string.h>
#include <stdlib.h>
char *unicode_windows874_u2c(const unicode_char *uc, int *errflag,
const unicode_char *tab)
{
size_t l;
char *p;
for (l=0; uc[l]; l++)
;
if (errflag) *errflag= -1;
p=malloc(l+1);
if (!p)
return (0);
for (l=0; uc[l]; l++)
{
int c;
unicode_char ucc=uc[l];
/* First, guess */
if ((ucc & 0x7F) == ucc)
c=(unsigned char)ucc;
else if (tab[ ucc & 0x7F ] == ucc)
c=(int)(ucc & 0x7F) | 0x80;
else if (ucc > 0x0E00 && ucc < 0x0E60 &&
tab[ (ucc + 0x20) & 0x7F] == ucc)
c=(int)( (ucc + 0x20) & 0x7F) | 0x80;
else
{
for (c=0; c<128; c++)
if (tab[c] == uc[l])
break;
if (c >= 128)
{
if (errflag)
{
*errflag=l;
free(p);
return (0);
}
c=uc[l];
}
c |= 0x80;
}
if (c == 0)
c=255;
p[l]=(char)c;
}
p[l]=0;
return (p);
}
|