/*
$Id: Encode.xs,v 1.56 2003/06/18 09:29:02 dankogai Exp $
*/
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "encode.h"
# define PERLIO_MODNAME "PerlIO::encoding"
# define PERLIO_FILENAME "PerlIO/encoding.pm"
/* set 1 or more to profile. t/encoding.t dumps core because of
Perl_warner and PerlIO don't work well */
#define ENCODE_XS_PROFILE 0
/* set 0 to disable floating point to calculate buffer size for
encode_method(). 1 is recommended. 2 restores NI-S original */
#define ENCODE_XS_USEFP 1
return (y)0; /* fool picky compilers */ \
}
/**/
void
{
dSP;
int i = 0;
}
}
void
{
/* Exists for breakpointing */
}
static SV *
{
/* We allocate slen+1.
PerlIO dumps core if this value is smaller than this. */
int code = 0;
if (offset) {
s += *offset;
}else{
slen = 0;
}
}
if (slen == 0){
goto ENCODE_END;
}
{
code == ENCODE_FOUND_TERM) {
break;
}
switch (code) {
case ENCODE_NOSPACE:
{
#if ENCODE_XS_PROFILE >= 2
"more=%d, sdone=%d, sleft=%d, SvLEN(dst)=%d\n",
#endif
if (sdone != 0) { /* has src ever been processed ? */
#if ENCODE_XS_USEFP == 2
#else
/* safe until SvLEN(dst) == MAX_INT/16 */
#endif
}
/* dst need to grow need MORE bytes! */
}
d += ddone;
s += slen;
continue;
}
case ENCODE_NOREP:
/* encoding */
if (check & ENCODE_DIE_ON_ERR) {
return &PL_sv_undef; /* never reaches but be safe */
}
if (check & ENCODE_WARN_ON_ERR){
}
if (check & ENCODE_RETURN_ON_ERR){
goto ENCODE_SET_SRC;
}
if (check & ENCODE_PERLQQ){
}else if (check & ENCODE_HTMLCREF){
}else if (check & ENCODE_XMLCREF){
} else {
/* fallback char */
}
}
/* decoding */
else {
if (check & ENCODE_DIE_ON_ERR){
return &PL_sv_undef; /* never reaches but be safe */
}
if (check & ENCODE_WARN_ON_ERR){
}
if (check & ENCODE_RETURN_ON_ERR){
goto ENCODE_SET_SRC;
}
if (check &
} else {
}
}
/* settle variables when fallback */
break;
default:
return &PL_sv_undef;
}
}
if (sdone) {
}
}
/* warn("check = 0x%X, code = 0x%d\n", check, code); */
"SvLEN(dst)=%d, SvCUR(dst)=%d. %d bytes unused(%f %%)\n",
}
#endif
if (offset)
return dst;
}
void
CODE:
{
XSRETURN(1);
}
void
int check
CODE:
{
s = utf8_to_bytes(s,&slen);
if (s) {
e = s+slen;
}
else {
croak("Cannot decode string with wide characters");
}
}
while (s < e) {
if (UTF8_IS_INVARIANT(*s) || UTF8_IS_START(*s)) {
if ((s + skip) > e) {
/* Partial character - done */
break;
}
else if (is_utf8_char(s)) {
/* Whole char is good */
s += skip;
continue;
}
else {
/* starts ok but isn't "good" */
}
}
else {
/* Invalid start byte */
}
/* If we get here there is something wrong with alleged UTF-8 */
if (check & ENCODE_DIE_ON_ERR){
XSRETURN(0);
}
if (check & ENCODE_WARN_ON_ERR){
}
if (check & ENCODE_RETURN_ON_ERR) {
break;
}
} else {
}
s++;
}
/* Clear out translated part of source unless asked not to */
slen = e-s;
if (slen) {
}
}
XSRETURN(1);
}
void
int check
CODE:
{
/* Already encoded - trust it and just copy the octets */
s = e;
}
else {
/* Native bytes - can always encode */
while (s < e) {
if (UNI_IS_INVARIANT(uv))
else {
}
}
}
/* Clear out translated part of source unless asked not to */
slen = e-s;
if (slen) {
}
}
XSRETURN(1);
}
void
CODE:
{
XSRETURN(1);
}
void
CODE:
{
XSRETURN(1);
}
void
int check
CODE:
{
int code = 0;
}
if (code == ENCODE_FOUND_TERM) {
}else{
}
XSRETURN(1);
}
void
int check
CODE:
{
}
XSRETURN(1);
}
void
int check
CODE:
{
XSRETURN(1);
}
void
CODE:
{
/* encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj))); */
XSRETURN(1);
}
void
CODE:
{
/* encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj))); */
/* require_pv(PERLIO_FILENAME); */
eval_pv("require PerlIO::encoding", 0);
}else{
}
XSRETURN(1);
}
_bytes_to_utf8(sv, ...)
CODE:
{
if (encoding)
else {
}
}
_utf8_to_bytes(sv, ...)
CODE:
{
if (to) {
} else {
RETVAL = 0;
/* Must do things the slow way */
/* We need a copy to pass to check() */
while (s < send) {
if (*s < 0x80){
*dest++ = *s++;
} else {
/* Have to do it all ourselves because of error routine,
aargh. */
/* Note change to utf8.c variable naming, for variety */
while (ulen--) {
if ((*s & 0xc0) != 0x80){
goto failure;
} else {
}
}
if (uv > 256) {
/* Now what happens? */
}
}
}
} else {
}
}
}
bool
int check
CODE:
{
if (RETVAL &&
check &&
} else {
}
}
SV *
CODE:
{
} else {
RETVAL = &PL_sv_undef;
}
}
SV *
CODE:
{
SvUTF8_off(sv);
} else {
RETVAL = &PL_sv_undef;
}
}
int
CODE:
int
CODE:
int
CODE:
int
CODE:
int
PERLQQ()
CODE:
int
HTMLCREF()
CODE:
int
XMLCREF()
CODE:
int
CODE:
int
FB_CROAK()
CODE:
int
FB_QUIET()
CODE:
int
FB_WARN()
CODE:
int
CODE:
int
CODE:
int
CODE:
BOOT:
{
#include "def_t.h"
#include "def_t.exh"
}