1{ 2 This file is part of the Free Pascal run time library. 3 (c) 2000-2003 by Marco van de Voort 4 member of the Free Pascal development team. 5 6 See the file COPYING.FPC, included in this distribution, 7 for details about the copyright. 8 9 Termios implementation for FreeBSD 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY;without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14} 15 16 17{****************************************************************************** 18 IOCtl and Termios calls 19******************************************************************************} 20 21Function TCGetAttr(fd:cint;var tios:TermIOS):cint; 22begin 23 TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios); 24end; 25 26 27Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint; 28var 29 nr:TIOCtlRequest; 30begin 31 case OptAct of 32 TCSANOW : nr:=TIOCSETA; 33 TCSADRAIN : nr:=TIOCSETAW; 34 TCSAFLUSH : nr:=TIOCSETAF; 35 else 36 begin 37 fpsetErrNo(ESysEINVAL); 38 TCSetAttr:=-1; 39 exit; 40 end; 41 end; 42 TCSetAttr:=fpIOCtl(fd,nr,@Tios); 43end; 44 45 46Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); 47begin 48 // field unused under BeOS 49 tios.c_ixxxxx:=speed; 50end; 51 52 53Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); 54begin 55 // field unused under BeOS 56 tios.c_oxxxxx:=speed; 57end; 58 59 60 61Procedure CFMakeRaw(var tios:TermIOS); 62begin 63 with tios do 64 begin 65 c_iflag:=c_iflag and (not (IXOFF or INPCK or BRKINT or 66 PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or 67 IGNPAR)); 68 c_iflag:=c_iflag OR IGNBRK; 69 c_oflag:=c_oflag and (not OPOST); 70 c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or 71 ISIG or IEXTEN or NOFLSH or TOSTOP)); 72 c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread); 73 c_cc[VMIN]:= 1; 74 c_cc[VTIME]:= 0; 75 end; 76end; 77 78Function TCSendBreak(fd,duration:cint):cint; 79begin 80 TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil); 81end; 82 83Function be_tcsetpgrp(fd, pgrpid : pid_t) : cint; cdecl; external 'root' name 'tcsetpgrp'; 84Function be_tcgetpgrp(fd : cint) : pid_t; cdecl; external 'root' name 'tcgetpgrp'; 85Function be_tcdrain(fd : cint) : cint; cdecl; external 'root' name 'tcdrain'; 86Function be_tcflow(fd, action : cint) : cint; cdecl; external 'root' name 'tcflow'; 87Function be_tcflush(fd, queue_selector : cint) : cint; cdecl; external 'root' name 'tcflush'; 88 89 90Function TCSetPGrp(fd,id:cint):cint; 91begin 92 TCSetPGrp := be_tcsetpgrp(fd, id); 93end; 94 95 96Function TCGetPGrp(fd:cint;var id:cint):cint; 97begin 98 id := be_tcgetpgrp(fd); 99end; 100 101Function TCDrain(fd:cint):cint; 102begin 103 TCDrain := be_tcdrain(fd); 104end; 105 106 107Function TCFlow(fd,act:cint):cint; 108begin 109 TCFlow := be_tcflow(fd, act); 110end; 111 112Function TCFlush(fd,qsel:cint):cint; 113begin 114 TCFlush := be_tcflush(fd, qsel); 115end; 116 117Function BeOSIsATTY (Handle:cint):cint; cdecl; external 'root' name 'isatty'; 118 119Function IsATTY (Handle:cint):cint; 120{ 121 Check if the filehandle described by 'handle' is a TTY (Terminal) 122} 123begin 124 IsAtty:= BeOSIsATTY(Handle); 125end; 126 127Function IsATTY(var f: text):cint; 128{ 129 Idem as previous, only now for text variables. 130} 131begin 132 IsATTY:=IsaTTY(textrec(f).handle); 133end; 134 135