Esempio n. 1
0
int
wsemul_sun_output_control(struct wsemul_sun_emuldata *edp,
    struct wsemul_inputstate *instate)
{
	int oargs;
	int rc;

	switch (instate->inchar) {
	case '0': case '1': case '2': case '3': case '4': /* argument digit */
	case '5': case '6': case '7': case '8': case '9':
		/*
		 * If we receive more arguments than we are expecting,
		 * discard the earliest arguments.
		 */
		if (edp->nargs > SUN_EMUL_NARGS - 1) {
			bcopy(edp->args + 1, edp->args,
			    (SUN_EMUL_NARGS - 1) * sizeof(edp->args[0]));
			edp->args[edp->nargs = SUN_EMUL_NARGS - 1] = 0;
		}
		edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
		    (instate->inchar - '0');
		break;

	case ';':		/* argument terminator */
		edp->nargs++;
		break;

	default:		/* end of escape sequence */
		oargs = edp->nargs++;
		if (edp->nargs > SUN_EMUL_NARGS)
			edp->nargs = SUN_EMUL_NARGS;
		rc = wsemul_sun_control(edp, instate);
		if (rc != 0) {
			/* undo nargs progress */
			edp->nargs = oargs;

			return rc;
		}
		edp->state = SUN_EMUL_STATE_NORMAL;
		break;
	}

	return 0;
}
Esempio n. 2
0
u_int
wsemul_sun_output_control(struct wsemul_sun_emuldata *edp, u_char c)
{
    u_int newstate = SUN_EMUL_STATE_CONTROL;

    switch (c) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4': /* argument digit */
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        /*
         * If we receive more arguments than we are expecting,
         * discard the earliest arguments.
         */
        if (edp->nargs > SUN_EMUL_NARGS - 1) {
            bcopy(edp->args + 1, edp->args,
                  (SUN_EMUL_NARGS - 1) * sizeof(edp->args[0]));
            edp->args[edp->nargs = SUN_EMUL_NARGS - 1] = 0;
        }
        edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) +
                                (c - '0');
        break;

    case ';':		/* argument terminator */
        edp->nargs++;
        break;

    default:		/* end of escape sequence */
        edp->nargs++;
        if (edp->nargs > SUN_EMUL_NARGS)
            edp->nargs = SUN_EMUL_NARGS;
        wsemul_sun_control(edp, c);
        newstate = SUN_EMUL_STATE_NORMAL;
        break;
    }
    return (newstate);
}