From 9cc0d6d3f8a89f35ddea92e30bdc2822c4164358 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 22 Aug 2002 19:24:19 +0000 Subject: libcons/ 2002-08-22 Marcus Brinkmann * 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. --- libcons/cons-lookup.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 libcons/cons-lookup.c (limited to 'libcons/cons-lookup.c') diff --git a/libcons/cons-lookup.c b/libcons/cons-lookup.c new file mode 100644 index 00000000..f3bdabef --- /dev/null +++ b/libcons/cons-lookup.c @@ -0,0 +1,134 @@ +/* cons-lookup.c - Looking up virtual consoles. + 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 +#include +#include + +#include "cons.h" + +/* Lookup the virtual console with number ID in the console CONS, + acquire a reference for it, and return it in R_VCONS. If CREATE is + true, the virtual console will be created if it doesn't exist yet. + If CREATE is true, and ID 0, the first free virtual console id is + used. CONS must be locked. */ +error_t +cons_lookup (cons_t cons, int id, int create, vcons_t *r_vcons) +{ + vcons_t previous_vcons = 0; + vcons_t vcons; + + if (!id && !create) + return EINVAL; + + if (id) + { + if (cons->vcons_list && cons->vcons_list->id <= id) + { + previous_vcons = cons->vcons_list; + while (previous_vcons->next && previous_vcons->next->id <= id) + previous_vcons = previous_vcons->next; + if (previous_vcons->id == id) + { + /* previous_vcons->refcnt++; */ + *r_vcons = previous_vcons; + return 0; + } + } + else if (!create) + return ESRCH; + } + else + { + id = 1; + if (cons->vcons_list && cons->vcons_list->id == 1) + { + previous_vcons = cons->vcons_list; + while (previous_vcons && previous_vcons->id == id) + { + id++; + previous_vcons = previous_vcons->next; + } + } + } + + vcons = calloc (1, sizeof (struct vcons)); + if (!vcons) + { + mutex_unlock (&vcons->cons->lock); + return ENOMEM; + } + vcons->cons = cons; + /* vcons->refcnt = 1; */ + vcons->id = id; + mutex_init (&vcons->lock); + vcons->input = -1; + vcons->display = MAP_FAILED; + vcons->notify = NULL; + +#if 0 + err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING, + cons->foreground, cons->background); + if (err) + { + free (vcons->name); + free (vcons); + return err; + } + + err = input_create (&vcons->input, cons->encoding ?: DEFAULT_ENCODING); + if (err) + { + display_destroy (vcons->display); + free (vcons->name); + free (vcons); + return err; + } +#endif + + cons_vcons_add (vcons); + + /* Insert the virtual console into the doubly linked list. */ + if (previous_vcons) + { + vcons->prev = previous_vcons; + if (previous_vcons->next) + { + previous_vcons->next->prev = vcons; + vcons->next = previous_vcons->next; + } + else + cons->vcons_last = vcons; + previous_vcons->next = vcons; + } + else + { + if (cons->vcons_list) + { + cons->vcons_list->prev = vcons; + vcons->next = cons->vcons_list; + } + else + cons->vcons_last = vcons; + cons->vcons_list = vcons; + } + *r_vcons = vcons; + return 0; +} -- cgit v1.2.3