termiosproc.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. Termios implementation for FreeBSD
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. {******************************************************************************
  13. IOCtl and Termios calls
  14. ******************************************************************************}
  15. Procedure CFMakeRaw(var tios:TermIOS);
  16. begin
  17. with tios do
  18. begin
  19. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  20. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  21. IGNPAR));
  22. c_iflag:=c_iflag OR IGNBRK;
  23. c_oflag:=c_oflag and (not OPOST);
  24. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  25. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  26. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  27. c_cc[VMIN]:=1;
  28. c_cc[VTIME]:=0;
  29. end;
  30. end;
  31. Function TCSendBreak(fd,duration:cint):cint; {$ifdef VER2_0}inline;{$endif}
  32. begin
  33. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  34. end;
  35. Function TCSetPGrp(fd,id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  36. begin
  37. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
  38. end;
  39. Function TCGetPGrp(fd:cint;var id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  40. begin
  41. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  42. end;
  43. Function TCDrain(fd:cint):cint; {$ifdef VER2_0}inline;{$endif}
  44. begin
  45. TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
  46. end;
  47. Function TCFlow(fd,act:cint):cint; {$ifdef VER2_0}inline;{$endif}
  48. begin
  49. case act OF
  50. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
  51. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
  52. TCIOFF : {N/I}
  53. end;
  54. end;
  55. Function TCFlush(fd,qsel:cint):cint; {$ifdef VER2_0}inline;{$endif}
  56. begin
  57. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
  58. end;
  59. Function IsATTY (Handle:cint):cint;
  60. {
  61. Check if the filehandle described by 'handle' is a TTY (Terminal)
  62. }
  63. var
  64. t : Termios;
  65. begin
  66. IsAtty:=ord(TCGetAttr(Handle,t) <> -1);
  67. end;
  68. Function IsATTY(var f: text):cint; {$ifdef VER2_0}inline;{$endif}
  69. {
  70. Idem as previous, only now for text variables.
  71. }
  72. begin
  73. IsATTY:=IsaTTY(textrec(f).handle);
  74. end;