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.
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.
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]
23 * Copyright 2015 Gary Mills
24 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * cscope - interactive C symbol cross-reference
33 * terminal input functions
37 #include <curses.h> /* KEY_BACKSPACE, KEY_BREAK, and KEY_ENTER */
38 #include <setjmp.h> /* jmp_buf */
40 static jmp_buf env
; /* setjmp/longjmp buffer */
41 static int prevchar
; /* previous, ungotten character */
43 /* catch the interrupt signal */
49 (void) signal(SIGINT
, catchint
);
53 /* unget a character */
62 /* get a character from the terminal */
67 SIGTYPE (*volatile savesig
)() = SIG_DFL
; /* old value of signal */
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 */
79 c
= getch(); /* get a character from the terminal */
81 } else { /* longjmp to here from signal handler */
84 (void) signal(SIGINT
, savesig
);
88 /* get a line from the terminal in non-canonical mode */
91 getaline(char s
[], size_t size
, int firstchar
, BOOL iscaseless
)
96 /* if a character already has been typed */
97 if (firstchar
!= '\0') {
98 if (iscaseless
== YES
) {
99 firstchar
= tolower(firstchar
);
101 (void) addch((unsigned)firstchar
); /* display it */
102 s
[i
++] = firstchar
; /* save it */
104 /* until the end of the line is reached */
105 while ((c
= mygetch()) != '\r' && c
!= '\n' && c
!= KEY_ENTER
&&
106 c
!= '\003' && c
!= KEY_BREAK
) {
107 if (c
== erasechar() || c
== '\b' || /* erase */
108 c
== KEY_BACKSPACE
) {
110 (void) addstr("\b \b");
113 } else if (c
== killchar()) { /* kill */
114 for (j
= 0; j
< i
; ++j
) {
117 for (j
= 0; j
< i
; ++j
) {
120 for (j
= 0; j
< i
; ++j
) {
124 } else if (isprint(c
) || c
== '\t') { /* printable */
125 if (iscaseless
== YES
) {
128 /* if it will fit on the line */
130 (void) addch((unsigned)c
); /* display it */
131 s
[i
++] = c
; /* save it */
133 } else if (c
== ctrl('X')) {
135 (void) getmouseevent(); /* ignore it */
136 } else if (c
== EOF
) { /* end-of-file */
139 /* return on an empty line to allow a command to be entered */
140 if (firstchar
!= '\0' && i
== 0) {
148 /* ask user to enter a character after reading the message */
153 (void) addstr("Type any character to continue: ");
157 /* ask user to press the RETURN key after reading the message */
162 if (linemode
== NO
) {
163 (void) fprintf(stderr
, "Press the RETURN key to continue: ");
168 /* expand the ~ and $ shell meta characters in a path */
171 shellpath(char *out
, int limit
, char *in
)
176 /* skip leading white space */
177 while (isspace(*in
)) {
180 lastchar
= out
+ limit
- 1;
183 * a tilde (~) by itself represents $HOME; followed by a name it
184 * represents the $LOGDIR of that login name
187 *out
++ = *in
++; /* copy the ~ because it may not be expanded */
189 /* get the login name */
191 while (s
< lastchar
&& *in
!= '/' && *in
!= '\0' &&
197 /* if the login name is null, then use $HOME */
200 } else { /* get the home directory of the login name */
203 /* copy the directory name */
205 (void) strcpy(out
- 1, v
);
206 out
+= strlen(v
) - 1;
208 /* login not found so ~ must be part of the file name */
212 /* get the rest of the path */
213 while (out
< lastchar
&& *in
!= '\0' && !isspace(*in
)) {
215 /* look for an environment variable */
217 /* copy the $ because it may not be expanded */
220 /* get the variable name */
222 while (s
< lastchar
&& *in
!= '/' && *in
!= '\0' &&
229 if ((v
= getenv(out
)) != NULL
) {
230 (void) strcpy(out
- 1, v
);
231 out
+= strlen(v
) - 1;
234 * var not found, so $ must be part of
239 } else { /* ordinary character */