From 80a243f5e1ce1a023cb45c6ecfa9ccc2b83312d7 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 9 Sep 2002 22:04:25 +0000 Subject: libcons/ 2002-09-09 Marcus Brinkmann * Makefile (SRCS): Add vcons-scrollback.c. * vcons-scrollback.c: New file. * cons.h (struct vcons): Add SCROLLING member. * file-changed.c: Include . (cons_S_file_changed): Be careful to take VCONS->scrolling into account when doing clipping and scrolling. * cons-switch.c: Roll back to earlier version with vcons -> vcons_entry adjustments. The user is now expected to hold a reference to the VCONS. * cons.h: Fix prototype, too. * vcons-open.c (cons_vcons_open): Initialize VCONS->lock, VCONS->input and VCONS->display. utils/ 2002-09-09 Marcus Brinkmann * console-ncurses.c (console_switch): Keep a reference to the port instead refering to it by number. --- libcons/cons-switch.c | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'libcons/cons-switch.c') diff --git a/libcons/cons-switch.c b/libcons/cons-switch.c index d9aa64af..c39e83da 100644 --- a/libcons/cons-switch.c +++ b/libcons/cons-switch.c @@ -23,44 +23,47 @@ #include "cons.h" -/* Open the virtual console ID or the ACTIVE_ID plus DELTA one in CONS - and return it in R_VCONS, which will be locked. */ +/* Open the virtual console ID or the virtual console DELTA steps away + from VCONS in the linked list and return it in R_VCONS, which will + be locked. */ error_t -cons_switch (cons_t cons, int active_id, int id, int delta, vcons_t *r_vcons) +cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons) { error_t err = 0; + cons_t cons = vcons->cons; vcons_list_t vcons_entry = NULL; if (!id && !delta) return 0; mutex_lock (&cons->lock); - vcons_entry = cons->vcons_list; - while (vcons_entry && vcons_entry->id != (id ?: active_id)) - vcons_entry = vcons_entry->next; - - if (!id && vcons_entry) + if (id) + { + vcons_entry = cons->vcons_list; + while (vcons_entry && vcons_entry->id != id) + vcons_entry = vcons_entry->next; + } + else if (delta > 0) + { + vcons_entry = vcons->vcons_entry; + while (delta-- > 0) + { + vcons_entry = vcons_entry->next; + if (!vcons_entry) + vcons_entry = cons->vcons_list; + } + } + else { - if (delta > 0) - { - while (delta-- > 0) - { - vcons_entry = vcons_entry->next; - if (!vcons_entry) - vcons_entry = cons->vcons_list; - } - } - else - { - assert (delta < 0); - while (delta++ < 0) - { - vcons_entry = vcons_entry->prev; - if (!vcons_entry) - vcons_entry = cons->vcons_last; - } - } + assert (delta < 0); + while (delta++ < 0) + { + vcons_entry = vcons_entry->prev; + if (!vcons_entry) + vcons_entry = cons->vcons_last; + } } + if (!vcons_entry) { mutex_unlock (&cons->lock); @@ -78,6 +81,7 @@ cons_switch (cons_t cons, int active_id, int id, int delta, vcons_t *r_vcons) if (!err) vcons_entry->vcons = *r_vcons; } + mutex_unlock (&cons->lock); return err; } -- cgit v1.2.3