Example #1
0
static void conv_output_closer(ScmPort *port)
{
    ScmConvInfo *info = (ScmConvInfo*)port->src.buf.data;

    /* if there's remaining bytes in buf, send them to the remote port. */
    if (info->ptr > info->buf) {
        Scm_Putz(info->buf, (int)(info->ptr - info->buf), info->remote);
        info->ptr = info->buf;
    }
    /* sends out the closing sequence, if any */
    int r = (int)jconv_reset(info, info->buf, info->bufsiz);
#ifdef JCONV_DEBUG
    fprintf(stderr, "<= r=%d(reset), buf(%p)\n",
            r, info->buf);
#endif
    if (r < 0) {
        Scm_Error("something wrong in resetting output character encoding conversion (%s -> %s).  possibly an implementation error.",
                  info->fromCode, info->toCode);
    }
    if (r > 0) {
        Scm_Putz(info->buf, r, info->remote);
    }
    /* flush remove port */
    Scm_Flush(info->remote);
    if (info->ownerp) {
        Scm_ClosePort(info->remote);
        info->remoteClosed = TRUE;
    }
    jconv_close(info);
}
Example #2
0
void Scm_WriteBinaryF64(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_f64_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetDouble(sval);
    SWAP_D(endian, v);
    Scm_Putz(v.buf, 8, oport);
}
Example #3
0
void Scm_WriteBinaryF32(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_f32_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = (float)Scm_GetDouble(sval);
    SWAP_32(endian, v);
    Scm_Putz(v.buf, 4, oport);
}
Example #4
0
void Scm_WriteBinaryF16(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_f16_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_DoubleToHalf(Scm_GetDouble(sval));
    SWAP_16(endian, v);
    Scm_Putz(v.buf, 2, oport);
}
Example #5
0
void Scm_WriteBinaryS64(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_s64_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetInteger64Clamp(sval, FALSE, FALSE);
    SWAP_64(endian, v);
    Scm_Putz(v.buf, 8, oport);
}
Example #6
0
void Scm_WriteBinaryU32(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_u32_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetIntegerU32Clamp(sval, FALSE, FALSE);
    SWAP_32(endian, v);
    Scm_Putz(v.buf, 4, oport);
}
Example #7
0
void Scm_WriteBinaryS16(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_s16_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetInteger16Clamp(sval, SCM_CLAMP_NONE, NULL);
    SWAP_16(endian, v);
    Scm_Putz(v.buf, 2, oport);
}
Example #8
0
/*
 * utilities for sigset
 */
static void display_sigset(sigset_t *set, ScmPort *port)
{
    struct sigdesc *desc = sigDesc;
    int cnt = 0;
    for (; desc->name; desc++) {
        if (sigismember(set, desc->num)) {
            if (cnt++) Scm_Putc('|', port);
            Scm_Putz(desc->name+3, -1, port);
        }
    }
}
Example #9
0
static int conv_output_flusher(ScmPort *port, int cnt, int forcep)
{
    ScmConvInfo *info = (ScmConvInfo*)port->src.buf.data;
    size_t inroom = SCM_PORT_BUFFER_AVAIL(port);
    size_t len = inroom;
    const char *inbuf = port->src.buf.buffer;

    for (;;) {
        /* Conversion. */
        char *outbuf = info->ptr;
        size_t outroom = info->bufsiz - (info->ptr - info->buf);
#ifdef JCONV_DEBUG
        fprintf(stderr, "=> in(%p,%p)%d out(%p,%p)%d\n",
                inbuf, len, inroom,
                info->buf, info->ptr, outroom);
#endif
        size_t result = jconv(info, &inbuf, &inroom, &outbuf, &outroom);
#ifdef JCONV_DEBUG
        fprintf(stderr, "<= r=%d, in(%p)%d out(%p)%d\n",
                result, inbuf, inroom, outbuf, outroom);
#endif
        if (result == INPUT_NOT_ENOUGH) {
#ifndef GLIBC_2_1_ICONV_BUG
            /* Conversion stopped due to an incomplete character at the
               end of the input buffer.  We just return # of bytes
               flushed.  (Shifting unconverted characters is done by
               buffered port routine) */
            info->ptr = outbuf;
#else
            /* See the above notes.  We always flush the output buffer
               here, so that we can avoid output buffer overrun. */
            Scm_Putz(info->buf, (int)(outbuf - info->buf), info->remote);
            info->ptr = info->buf;
#endif
            return (int)(len - inroom);
        } else if (result == OUTPUT_NOT_ENOUGH) {
            /* Output buffer got full.  Flush it, and continue
               conversion. */
            Scm_Putz(info->buf, (int)(outbuf - info->buf), info->remote);
            info->ptr = info->buf;
            continue;
        } else if (result == ILLEGAL_SEQUENCE) {
            /* it's likely that input contains invalid sequence.
               TODO: we should handle this case gracefully. */
            Scm_Error("invalid character sequence in the input stream");
            return 0;           /* dummy */
        } else {
#ifndef GLIBC_2_1_ICONV_BUG
            /* Conversion is done completely.  Update outptr. */
            info->ptr = outbuf;
#else
            /* See the above notes.  We always flush the output buffer here,
               so that we can avoid output buffer overrun. */
            Scm_Putz(info->buf, (int)(outbuf - info->buf), info->remote);
            info->ptr = info->buf;
#endif
            if (forcep && len - inroom != cnt) continue;
            return (int)(len - inroom);
        }
    }
}