3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * cscope - interactive C symbol cross-reference
31 *
32 * terminal input functions
33 */
34
35 #include "global.h"
36 #include <curses.h> /* KEY_BACKSPACE, KEY_BREAK, and KEY_ENTER */
37 #include <setjmp.h> /* jmp_buf */
38
39 static jmp_buf env; /* setjmp/longjmp buffer */
40 static int prevchar; /* previous, ungotten character */
41
42 /* catch the interrupt signal */
46 catchint(int sig)
47 {
48 (void) signal(SIGINT, catchint);
49 longjmp(env, 1);
50 }
51
52 /* unget a character */
53
54 int
55 ungetch(int c)
56 {
57 prevchar = c;
58 return (0);
59 }
60
61 /* get a character from the terminal */
62
63 int
64 mygetch(void)
65 {
66 SIGTYPE (*savesig)(); /* old value of signal */
67 int c;
68
69 /* change an interrupt signal to a break key character */
70 if (setjmp(env) == 0) {
71 savesig = signal(SIGINT, catchint);
72 (void) refresh(); /* update the display */
73 reinitmouse(); /* curses can change the menu number */
74 if (prevchar) {
75 c = prevchar;
76 prevchar = 0;
77 } else {
78 c = getch(); /* get a character from the terminal */
79 }
80 } else { /* longjmp to here from signal handler */
81 c = KEY_BREAK;
82 }
83 (void) signal(SIGINT, savesig);
84 return (c);
85 }
86
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 Gary Mills
24 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * cscope - interactive C symbol cross-reference
32 *
33 * terminal input functions
34 */
35
36 #include "global.h"
37 #include <curses.h> /* KEY_BACKSPACE, KEY_BREAK, and KEY_ENTER */
38 #include <setjmp.h> /* jmp_buf */
39
40 static jmp_buf env; /* setjmp/longjmp buffer */
41 static int prevchar; /* previous, ungotten character */
42
43 /* catch the interrupt signal */
47 catchint(int sig)
48 {
49 (void) signal(SIGINT, catchint);
50 longjmp(env, 1);
51 }
52
53 /* unget a character */
54
55 int
56 ungetch(int c)
57 {
58 prevchar = c;
59 return (0);
60 }
61
62 /* get a character from the terminal */
63
64 int
65 mygetch(void)
66 {
67 SIGTYPE (*volatile savesig)() = SIG_DFL; /* old value of signal */
68 int c;
69
70 /* change an interrupt signal to a break key character */
71 if (setjmp(env) == 0) {
72 savesig = signal(SIGINT, catchint);
73 (void) refresh(); /* update the display */
74 reinitmouse(); /* curses can change the menu number */
75 if (prevchar) {
76 c = prevchar;
77 prevchar = 0;
78 } else {
79 c = getch(); /* get a character from the terminal */
80 }
81 } else { /* longjmp to here from signal handler */
82 c = KEY_BREAK;
83 }
84 (void) signal(SIGINT, savesig);
85 return (c);
86 }
87
|