Sync OpenBSD patchset 159:

There are relatively few arguments to tty_cmd_* functions now, so tidy them up
by using a struct rather than hiding everything with varargs.
This commit is contained in:
Tiago Cunha
2009-07-22 18:08:56 +00:00
parent 75a44d856e
commit b6afa30c39
4 changed files with 155 additions and 130 deletions

167
tty.c
View File

@@ -1,4 +1,4 @@
/* $Id: tty.c,v 1.114 2009-07-22 17:58:42 tcunha Exp $ */
/* $Id: tty.c,v 1.115 2009-07-22 18:08:56 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -38,23 +38,23 @@ void tty_attributes(struct tty *, const struct grid_cell *);
void tty_attributes_fg(struct tty *, const struct grid_cell *);
void tty_attributes_bg(struct tty *, const struct grid_cell *);
void tty_cmd_alignmenttest(struct tty *, struct window_pane *, va_list);
void tty_cmd_cell(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearendofline(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearendofscreen(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearline(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearscreen(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearstartofline(struct tty *, struct window_pane *, va_list);
void tty_cmd_clearstartofscreen(struct tty *, struct window_pane *, va_list);
void tty_cmd_deletecharacter(struct tty *, struct window_pane *, va_list);
void tty_cmd_deleteline(struct tty *, struct window_pane *, va_list);
void tty_cmd_insertcharacter(struct tty *, struct window_pane *, va_list);
void tty_cmd_insertline(struct tty *, struct window_pane *, va_list);
void tty_cmd_linefeed(struct tty *, struct window_pane *, va_list);
void tty_cmd_utf8character(struct tty *, struct window_pane *, va_list);
void tty_cmd_reverseindex(struct tty *, struct window_pane *, va_list);
void tty_cmd_alignmenttest(struct tty *, struct tty_ctx *);
void tty_cmd_cell(struct tty *, struct tty_ctx *);
void tty_cmd_clearendofline(struct tty *, struct tty_ctx *);
void tty_cmd_clearendofscreen(struct tty *, struct tty_ctx *);
void tty_cmd_clearline(struct tty *, struct tty_ctx *);
void tty_cmd_clearscreen(struct tty *, struct tty_ctx *);
void tty_cmd_clearstartofline(struct tty *, struct tty_ctx *);
void tty_cmd_clearstartofscreen(struct tty *, struct tty_ctx *);
void tty_cmd_deletecharacter(struct tty *, struct tty_ctx *);
void tty_cmd_deleteline(struct tty *, struct tty_ctx *);
void tty_cmd_insertcharacter(struct tty *, struct tty_ctx *);
void tty_cmd_insertline(struct tty *, struct tty_ctx *);
void tty_cmd_linefeed(struct tty *, struct tty_ctx *);
void tty_cmd_utf8character(struct tty *, struct tty_ctx *);
void tty_cmd_reverseindex(struct tty *, struct tty_ctx *);
void (*tty_cmds[])(struct tty *, struct window_pane *, va_list) = {
void (*tty_cmds[])(struct tty *, struct tty_ctx *) = {
tty_cmd_alignmenttest,
tty_cmd_cell,
tty_cmd_clearendofline,
@@ -555,66 +555,61 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy)
}
void
tty_vwrite(
struct tty *tty, struct window_pane *wp, enum tty_cmd cmd, va_list ap)
tty_write(struct tty *tty, enum tty_cmd cmd, struct tty_ctx *ctx)
{
if (tty->flags & TTY_FREEZE || tty->term == NULL)
return;
if (tty_cmds[cmd] != NULL)
tty_cmds[cmd](tty, wp, ap);
tty_cmds[cmd](tty, ctx);
}
void
tty_cmd_insertcharacter(struct tty *tty, struct window_pane *wp, va_list ap)
tty_cmd_insertcharacter(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int ua;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx) {
tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff);
return;
}
ua = va_arg(ap, u_int);
tty_reset(tty);
tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff);
if (tty_term_has(tty->term, TTYC_ICH) ||
tty_term_has(tty->term, TTYC_ICH1))
tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ua);
tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ctx->num);
else {
tty_putcode(tty, TTYC_SMIR);
while (ua-- > 0)
while (ctx->num-- > 0)
tty_putc(tty, ' ');
tty_putcode(tty, TTYC_RMIR);
}
}
void
tty_cmd_deletecharacter(struct tty *tty, struct window_pane *wp, va_list ap)
tty_cmd_deletecharacter(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int ua;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx) {
tty_draw_line(tty, wp->screen, s->old_cy, wp->xoff, wp->yoff);
return;
}
ua = va_arg(ap, u_int);
tty_reset(tty);
tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff);
tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ua);
tty_emulate_repeat(tty, TTYC_DCH, TTYC_DCH1, ctx->num);
}
void
tty_cmd_insertline(struct tty *tty, struct window_pane *wp, va_list ap)
tty_cmd_insertline(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int ua;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx ||
!tty_term_has(tty->term, TTYC_CSR)) {
@@ -622,21 +617,19 @@ tty_cmd_insertline(struct tty *tty, struct window_pane *wp, va_list ap)
return;
}
ua = va_arg(ap, u_int);
tty_reset(tty);
tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff);
tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff);
tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ua);
tty_emulate_repeat(tty, TTYC_IL, TTYC_IL1, ctx->num);
}
void
tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap)
tty_cmd_deleteline(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int ua;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx ||
!tty_term_has(tty->term, TTYC_CSR)) {
@@ -644,21 +637,20 @@ tty_cmd_deleteline(struct tty *tty, struct window_pane *wp, va_list ap)
return;
}
ua = va_arg(ap, u_int);
tty_reset(tty);
tty_region(tty, s->old_rupper, s->old_rlower, wp->yoff);
tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff);
tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ua);
tty_emulate_repeat(tty, TTYC_DL, TTYC_DL1, ctx->num);
}
void
tty_cmd_clearline(struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearline(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i;
tty_reset(tty);
@@ -673,11 +665,11 @@ tty_cmd_clearline(struct tty *tty, struct window_pane *wp, unused va_list ap)
}
void
tty_cmd_clearendofline(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearendofline(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i;
tty_reset(tty);
@@ -692,11 +684,11 @@ tty_cmd_clearendofline(
}
void
tty_cmd_clearstartofline(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearstartofline(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i;
tty_reset(tty);
@@ -711,9 +703,10 @@ tty_cmd_clearstartofline(
}
void
tty_cmd_reverseindex(struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_reverseindex(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx ||
!tty_term_has(tty->term, TTYC_CSR)) {
@@ -732,9 +725,10 @@ tty_cmd_reverseindex(struct tty *tty, struct window_pane *wp, unused va_list ap)
}
void
tty_cmd_linefeed(struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_linefeed(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
if (wp->xoff != 0 || screen_size_x(s) < tty->sx ||
!tty_term_has(tty->term, TTYC_CSR)) {
@@ -753,11 +747,11 @@ tty_cmd_linefeed(struct tty *tty, struct window_pane *wp, unused va_list ap)
}
void
tty_cmd_clearendofscreen(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearendofscreen(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i, j;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i, j;
tty_reset(tty);
@@ -788,11 +782,11 @@ tty_cmd_clearendofscreen(
}
void
tty_cmd_clearstartofscreen(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearstartofscreen(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i, j;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i, j;
tty_reset(tty);
@@ -817,11 +811,11 @@ tty_cmd_clearstartofscreen(
}
void
tty_cmd_clearscreen(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_clearscreen(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i, j;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i, j;
tty_reset(tty);
@@ -846,11 +840,11 @@ tty_cmd_clearscreen(
}
void
tty_cmd_alignmenttest(
struct tty *tty, struct window_pane *wp, unused va_list ap)
tty_cmd_alignmenttest(struct tty *tty, struct tty_ctx *ctx)
{
struct screen *s = wp->screen;
u_int i, j;
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
u_int i, j;
tty_reset(tty);
@@ -864,33 +858,26 @@ tty_cmd_alignmenttest(
}
void
tty_cmd_cell(struct tty *tty, struct window_pane *wp, va_list ap)
tty_cmd_cell(struct tty *tty, struct tty_ctx *ctx)
{
struct window_pane *wp = ctx->wp;
struct screen *s = wp->screen;
struct grid_cell *gc;
struct grid_utf8 *gu;
gc = va_arg(ap, struct grid_cell *);
gu = va_arg(ap, struct grid_utf8 *);
tty_cursor(tty, s->old_cx, s->old_cy, wp->xoff, wp->yoff);
tty_cell(tty, gc, gu);
tty_cell(tty, ctx->cell, ctx->utf8);
}
void
tty_cmd_utf8character(
struct tty *tty, unused struct window_pane *wp, va_list ap)
tty_cmd_utf8character(struct tty *tty, struct tty_ctx *ctx)
{
u_char *buf;
u_char *ptr = ctx->ptr;
size_t i;
buf = va_arg(ap, u_char *);
for (i = 0; i < UTF8_SIZE; i++) {
if (buf[i] == 0xff)
if (ptr[i] == 0xff)
break;
tty_putc(tty, buf[i]);
tty_putc(tty, ptr[i]);
}
}