diff options
author | Marcus Brinkmann <marcus@gnu.org> | 2002-08-22 19:24:19 +0000 |
---|---|---|
committer | Marcus Brinkmann <marcus@gnu.org> | 2002-08-22 19:24:19 +0000 |
commit | 9cc0d6d3f8a89f35ddea92e30bdc2822c4164358 (patch) | |
tree | d182cfe90532231aaff4411a9d0118e9e5a15e7e /libcons/cons-switch.c | |
parent | 4062fb2fcf938bb6a9c5d8f6404586cab11fe227 (diff) |
libcons/
2002-08-22 Marcus Brinkmann <marcus@gnu.org>
* demuxer.c, init-init.c, init-loop.c, opts-version.c,
extra-version.c, dir-changed.c, file-changed.c,
opts-std-startup.c, cons-lookup.c, cons-switch.c, vcons-remove.c,
vcons-add.c, vcons-open.c, vcons-close.c, vcons-refresh.c, priv.h,
mutations.h, cons.h: New files.
Diffstat (limited to 'libcons/cons-switch.c')
-rw-r--r-- | libcons/cons-switch.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/libcons/cons-switch.c b/libcons/cons-switch.c new file mode 100644 index 00000000..f2b72daf --- /dev/null +++ b/libcons/cons-switch.c @@ -0,0 +1,95 @@ +/* cons-switch.c - Switch to another virtual console. + Copyright (C) 2002 Free Software Foundation, Inc. + Written by Marcus Brinkmann. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include <errno.h> +#include <error.h> +#include <assert.h> + +#include "cons.h" + +/* Switch the active console in CONS to ID or the current one plus + DELTA. This will call back into the user code by doing a + cons_vcons_activate. */ +error_t +cons_switch (cons_t cons, int id, int delta) +{ + vcons_t vcons = NULL; + vcons_t active; + + if (!id && !delta) + return 0; + + mutex_lock (&cons->lock); + active = cons->active; + + if (!id && !active) + { + mutex_unlock (&cons->lock); + return EINVAL; + } + + if (id) + { + vcons = cons->vcons_list; + while (vcons && vcons->id != id) + vcons = vcons->next; + } + else if (delta > 0) + { + vcons = cons->active; + while (delta-- > 0) + { + vcons = vcons->next; + if (!vcons) + vcons = cons->vcons_list; + } + } + else + { + assert (delta < 0); + while (delta++ < 0) + { + vcons = vcons->prev; + if (!vcons) + vcons = cons->vcons_last; + } + } + + if (!vcons) + { + mutex_unlock (&cons->lock); + return ESRCH; + } + + if (vcons != active) + { + error_t err = cons_vcons_activate (vcons); + if (err) + { + mutex_unlock (&cons->lock); + return err; + } + + cons->active = vcons; + cons_vcons_refresh (vcons); + } + mutex_unlock (&cons->lock); + return 0; +} |