euc.multibyte.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1989 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
static char *sccsid = "%Z%%M% %I% %E% SMI";
#endif
#include "codeset.h"
#include "mbextern.h"
#include "euc.h"
#include <limits.h>
int _mbtowc_euc(wchar, s, n)
char *s;
size_t n;
{
register int length;
register c;
char *olds = (char *)s;
if(n <= 0)
return(-1);
if(s == (char *)0)
return 0;
c = (unsigned char)*s++;
if(c < 0200) {
if(wchar)
*wchar = c;
return(c ? 1 : 0);
}
intcode = 0;
if (c == SS2) {
if(wchar)
*wchar = c;
return(1);
}
} else if(c == SS3) {
if(wchar)
*wchar = c;
return(1);
}
} else {
if(iscntrl(c)) {
if(wchar)
*wchar = c;
return(1);
}
intcode = c & 0177;
}
if(length + 1 > n)
return(-1);
while(length--) {
if((c = (unsigned char)*s++) < 0200 || iscntrl(c))
return(-1);
}
if(wchar)
return((char *)s - olds);
}
_mbstowcs_euc(pwcs, s, n)
char *s;
size_t n;
{
register int i, j;
j=0;
while(*s) {
if(j>=n)
break;
if(i==-1)
return -1;
s+=i;
++j;
}
if(j<n)
pwcs[j]=0;
return j;
}
_wcstombs_euc(s, pwcs, n)
char *s;
size_t n;
{
register int i;
register int r=n; /* Rest of bytes. */
register char *t;
if (i>r)
break;
if (i==-1) return -1;
r-=i;
for (t=mbbuf;i>0;--i){
/* Copy each byte. */
*(s++)=*(t++);
}
}
if (r>0)
/* Has enough room for NUL. */
*s=0;
return n-r;
}
int _wctomb_euc(s, wchar)
char *s;
{
char *olds = s;
unsigned char d;
if(!s)
return(0);
*s++ = wchar;
return(wchar ? 1 : 0);
}
case MASK1:
break;
case MASK2:
*s++ = SS2;
break;
case MASK3:
*s++ = SS3;
break;
default:
return(-1);
}
while(index--) {
d = wchar | 0200;
wchar >>= 8;
if(iscntrl(d))
return(-1);
s[index] = d;
}
}