1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1988 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 /*LINTLIBRARY*/ 41 42 /* 43 * Routines to deal with setting and resetting modes in the tty driver. 44 * See also setupterm.c in the termlib part. 45 */ 46 #include <sys/types.h> 47 #include "curses_inc.h" 48 49 int 50 cbreak(void) 51 { 52 /* 53 * This optimization is here because till SVR3.1 curses did not come up 54 * in cbreak mode and now it does. Therefore, most programs when they 55 * call cbreak won't pay for it since we'll know we're in the right 56 * mode. 57 */ 58 59 if (cur_term->_fl_rawmode != 1) { 60 #ifdef SYSV 61 /* 62 * You might ask why ICRNL has anything to do with cbreak. 63 * The problem is that there are function keys that send 64 * a carriage return (some hp's). Curses cannot virtualize 65 * these function keys if CR is being mapped to a NL. Sooo, 66 * when we start a program up we unmap those but if you are 67 * in nocbreak then we map them back. The reason for that is that 68 * if a getch or getstr is done and you are in nocbreak the tty 69 * driver won't return until it sees a new line and since we've 70 * turned it off any program that has nl() and nocbreak() would 71 * force the user to type a NL. The problem with the function keys 72 * only gets solved if you are in cbreak mode which is OK 73 * since program taking action on a function key is probably 74 * in cbreak because who would expect someone to press a function 75 * key and then return ????? 76 */ 77 78 PROGTTYS.c_iflag &= ~ICRNL; 79 PROGTTYS.c_lflag &= ~ICANON; 80 PROGTTYS.c_cc[VMIN] = 1; 81 PROGTTYS.c_cc[VTIME] = 0; 82 #else 83 PROGTTY.sg_flags |= (CBREAK | CRMOD); 84 #endif 85 86 #ifdef DEBUG 87 #ifdef SYSV 88 if (outf) 89 fprintf(outf, "cbreak(), file %x, flags %x\n", 90 cur_term->Filedes, PROGTTYS.c_lflag); 91 #else 92 if (outf) 93 fprintf(outf, "cbreak(), file %x, flags %x\n", 94 cur_term->Filedes, PROGTTY.sg_flags); 95 #endif 96 #endif 97 cur_term->_fl_rawmode = 1; 98 cur_term->_delay = -1; 99 (void) reset_prog_mode(); 100 #ifdef FIONREAD 101 cur_term->timeout = 0; 102 #endif /* FIONREAD */ 103 } 104 return (OK); 105 } 106