Example #1
0
static int write_cp949(charset_spec const *charset, long int input_chr,
		       charset_state *state,
		       void (*emit)(void *ctx, long int output),
		       void *emitctx)
{
    UNUSEDARG(charset);
    UNUSEDARG(state);

    if (input_chr == -1)
	return TRUE;		       /* stateless; no cleanup required */

    if (input_chr < 0x80) {
	emit(emitctx, input_chr);
	return TRUE;
    } else {
	int r, c;
	if (unicode_to_cp949(input_chr, &r, &c)) {
	    emit(emitctx, r + 0x80);
	    emit(emitctx, c + 0x40);
	    return TRUE;
	} else {
	    return FALSE;
	}
    }
}
Example #2
0
void read_sbcs(charset_spec const *charset, long int input_chr,
	       charset_state *state,
	       void (*emit)(void *ctx, long int output), void *emitctx)
{
    const struct sbcs_data *sd = charset->data;

    UNUSEDARG(state);

    emit(emitctx, sbcs_to_unicode(sd, input_chr));
}
Example #3
0
/*
 *   Push any used temporary registers.
 *
 *   This is necessary across function calls
 *   The reason for this hacking is actually that temp_inv()
 *   should dump the registers in the correct order,
 *
 *   The least recently allocate register first.
 *   The most recently allocated register last.
 */
void temp_inv P1 (REGUSAGE *, regusage)
{
    DEEP    deep;

    UNUSEDARG (regusage);

    for (deep = EMPTY; deep < alloc_depth; deep++)
        if (!reg_alloc[deep].pushed) {
            g_push (reg_alloc[deep].reg, deep);
            /* mark the register void */
            reg_in_use[reg_alloc[deep].reg] = UNUSED;
        }
}
Example #4
0
int write_sbcs(charset_spec const *charset, long int input_chr,
	       charset_state *state,
	       void (*emit)(void *ctx, long int output), void *emitctx)
{
    const struct sbcs_data *sd = charset->data;
    long int ret;

    UNUSEDARG(state);

    if (input_chr == -1)
	return TRUE;		       /* stateless; no cleanup required */

    ret = sbcs_from_unicode(sd, input_chr);
    if (ret == ERROR)
	return FALSE;

    emit(emitctx, ret);
    return TRUE;
}
Example #5
0
static void read_cp949(charset_spec const *charset, long int input_chr,
		       charset_state *state,
		       void (*emit)(void *ctx, long int output), void *emitctx)
{
    UNUSEDARG(charset);

    /*
     * For reading CP949, state->s0 simply contains the single
     * stored lead byte when we are half way through a double-byte
     * character, or 0 if we aren't.
     */

    if (state->s0 == 0) {
	if (input_chr >= 0x81 && input_chr <= 0xFE) {
	    /*
	     * Lead byte. Just store it.
	     */
	    state->s0 = input_chr;
	} else {
	    /*
	     * Anything else we pass straight through unchanged.
	     */
	    emit(emitctx, input_chr);
	}
    } else {
	/*
	 * We have a stored lead byte. We expect a valid followup
	 * byte.
	 */
	if ((input_chr >= 0x40 && input_chr <= 0xFF)) {
	    emit(emitctx, cp949_to_unicode(state->s0 - 0x80,
					   input_chr - 0x40));
	} else {
	    emit(emitctx, ERROR);
	}
	state->s0 = 0;
    }
}
Example #6
0
static void geninit P2 (const EXPR *, ep, unsigned char *, data)
{
    UNUSEDARG (data);
    if (!code_option)
	return;

    switch (ep->nodetype) {
    case en_list:
	for (; ep != NIL_EXPR; ep = ep->v.p[1]) {
	    geninit (ep->v.p[0], data);
	}
	break;
    case en_icon:
    case en_fcon:
    case en_str:
	geninittype (ep, data);
	break;
    case en_litval:
	geninit (ep->v.p[0], data);
	break;
    default:
	CANNOT_REACH_HERE ();
    }
}
Example #7
0
File: utf7.c Project: mloar/charset
static void read_utf7(charset_spec const *charset, long int input_chr,
                      charset_state *state,
                      void (*emit)(void *ctx, long int output), void *emitctx)
{
    long int hw;

    UNUSEDARG(charset);

    /*
     * state->s0 is used to handle the conversion of the UTF-7
     * transport format into a stream of halfwords. Its layout is:
     *
     *  - In normal ASCII mode, it is zero.
     *
     * 	- Otherwise, it holds a leading 1 followed by all the bits
     * 	  so far accumulated in base64 digits.
     *
     * 	- Special case: when we have only just seen the initial `+'
     * 	  which enters base64 mode, it is set to 2 rather than 1
     * 	  (this is an otherwise unused value since base64 always
     * 	  accumulates an even number of bits at a time), so that
     * 	  the special sequence `+-' can be made to encode `+'
     * 	  easily.
     *
     * state->s1 is used to handle the conversion of those
     * halfwords into Unicode values. It contains a high surrogate
     * value if we've just seen one, and 0 otherwise.
     */

    if (!state->s0) {
        if (input_chr == '+')
            state->s0 = 2;
        else
            emit(emitctx, input_chr);
        return;
    } else {
        if (!SET_B(input_chr)) {
            /*
             * base64 mode ends here. Emit the character we have,
             * unless it's a minus in which case we should swallow
             * it.
             */
            if (input_chr != '-')
                emit(emitctx, input_chr);
            else if (state->s0 == 2)
                emit(emitctx, '+');    /* special case */
            state->s0 = 0;
            return;
        }

        /*
         * Now we have a base64 character, so add it to our state,
         * first correcting the special case value of s0.
         */
        if (state->s0 == 2)
            state->s0 = 1;
        state->s0 = (state->s0 << 6) | base64_value(input_chr);
    }

    /*
     * If we don't have a whole halfword at this point, bale out.
     */
    if (!(state->s0 & 0xFFFF0000))
        return;

    /*
     * Otherwise, extract the halfword. There are three
     * possibilities for where the top set bit might be.
     */
    if (state->s0 & 0x00100000) {
        hw = (state->s0 >> 4) & 0xFFFF;
        state->s0 = (state->s0 & 0xF) | 0x10;
    } else if (state->s0 & 0x00040000) {
Example #8
0
static void geninittype P2 (const EXPR *, ep, unsigned char *, data)
{
    TYP    *tp = ep->etp;
    UVAL    uval;

    
#ifdef FLOAT_SUPPORT
    RVAL    rvl;

    
#endif /* FLOAT_SUPPORT */
	UNUSEDARG (data);
    switch (tp->type) {
    case bt_bool:
	put_char (ep);
	break;
    case bt_char:
    case bt_charu:
    case bt_uchar:
    case bt_schar:
	put_char (ep);
	break;
    case bt_short:
    case bt_ushort:
    case bt_int16:
    case bt_uint16:
	put_short (ep);
	break;
    case bt_pointer16:
    case bt_pointer32:
	break;
    case bt_bitfield:
    case bt_ubitfield:
    case bt_bbitfield:
	uval = ep->v.u & bitmask (bitfield_width (tp));
	break;
    case bt_int32:
    case bt_uint32:
    case bt_ulong:
    case bt_long:
	put_long (ep);
	break;
    case bt_struct:
	break;
    case bt_union:
	break;
	
#ifdef FLOAT_SUPPORT
    case bt_float:
	floatexpr (tp, &rvl);
	put_float (&rvl);
	break;
    case bt_double:
	floatexpr (tp, &rvl);
	put_double (&rval);
	break;
    case bt_longdouble:
	floatexpr (tp, &rvl);
	put_longdouble (&rvl);
	break;
	
#endif /* FLOAT_SUPPORT */
    case bt_func:
	break;
    default:
	break;
    }
}