1 /*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: src/sys/dev/syscons/scterm.c,v 1.2 2000/01/29 15:08:46 peter Exp $
27 * $DragonFly: src/sys/dev/misc/syscons/scterm.c,v 1.5 2005/10/30 10:07:10 swildner Exp $
28 */
29
30 #include "opt_syscons.h"
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/consio.h>
36
37 #include "syscons.h"
38 #include "sctermvar.h"
39
40 SET_DECLARE(scterm_set, sc_term_sw_t);
41
42 /* exported subroutines */
43
44 /*
45 * Move the cursor, make sure reentrancy doesn't implode fields
46 * on panic.
47 */
48 void
sc_move_cursor(scr_stat * scp,int x,int y)49 sc_move_cursor(scr_stat *scp, int x, int y)
50 {
51 if (x < 0)
52 x = 0;
53 if (y < 0)
54 y = 0;
55 if (x >= scp->xsize)
56 x = scp->xsize - 1;
57 if (y >= scp->ysize)
58 y = scp->ysize - 1;
59 scp->xpos = x;
60 scp->ypos = y;
61 scp->cursor_pos = scp->ypos*scp->xsize + x;
62 }
63
64 void
sc_clear_screen(scr_stat * scp)65 sc_clear_screen(scr_stat *scp)
66 {
67 (*scp->tsw->te_clear)(scp);
68 scp->cursor_oldpos = scp->cursor_pos;
69 sc_remove_cutmarking(scp);
70 }
71
72 /* terminal emulator manager routines */
73
74 static LIST_HEAD(, sc_term_sw) sc_term_list =
75 LIST_HEAD_INITIALIZER(sc_term_list);
76
77 int
sc_term_add(sc_term_sw_t * sw)78 sc_term_add(sc_term_sw_t *sw)
79 {
80 LIST_INSERT_HEAD(&sc_term_list, sw, link);
81 return 0;
82 }
83
84 int
sc_term_remove(sc_term_sw_t * sw)85 sc_term_remove(sc_term_sw_t *sw)
86 {
87 LIST_REMOVE(sw, link);
88 return 0;
89 }
90
91 sc_term_sw_t *
sc_term_match(char * name)92 sc_term_match(char *name)
93 {
94 sc_term_sw_t **list;
95 sc_term_sw_t *p;
96
97 if (!LIST_EMPTY(&sc_term_list)) {
98 LIST_FOREACH(p, &sc_term_list, link) {
99 if ((strcmp(name, p->te_name) == 0)
100 || (strcmp(name, "*") == 0)) {
101 return p;
102 }
103 }
104 } else {
105 SET_FOREACH(list, scterm_set) {
106 p = *list;
107 if ((strcmp(name, p->te_name) == 0)
108 || (strcmp(name, "*") == 0)) {
109 return p;
110 }
111 }
112 }
113
114 return NULL;
115 }
116
117 sc_term_sw_t *
sc_term_match_by_number(int index)118 sc_term_match_by_number(int index)
119 {
120 sc_term_sw_t *p;
121
122 if (index <= 0)
123 return NULL;
124 LIST_FOREACH(p, &sc_term_list, link) {
125 if (--index <= 0)
126 return p;
127 }
128
129 return NULL;
130 }
131