termiosproc.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. { Old version directly called the C code but
  16. this is wrong if the constant is pusehd directly on stack,
  17. without passing the address as is done for i386 code generator PM }
  18. function tcsetattr(_para1:cint; _para2:cint; const _para3:termios):cint;cdecl;
  19. begin
  20. tcsetattr:=tcsetattr(_para1,_para2,@_para3);
  21. end;
  22. Procedure CFMakeRaw(var tios:TermIOS);
  23. begin
  24. with tios do
  25. begin
  26. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  27. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  28. IGNPAR));
  29. c_iflag:=c_iflag OR IGNBRK;
  30. c_oflag:=c_oflag and (not OPOST);
  31. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  32. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  33. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  34. c_cc[VMIN]:=1;
  35. c_cc[VTIME]:=0;
  36. end;
  37. end;
  38. Function TCSendBreak(fd,duration:cint):cint; {$ifdef VER2_0}inline;{$endif}
  39. begin
  40. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  41. end;
  42. Function TCSetPGrp(fd,id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  43. begin
  44. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
  45. end;
  46. Function TCGetPGrp(fd:cint;var id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  47. begin
  48. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  49. end;
  50. Function TCDrain(fd:cint):cint; {$ifdef VER2_0}inline;{$endif}
  51. begin
  52. TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
  53. end;
  54. Function TCFlow(fd,act:cint):cint; {$ifdef VER2_0}inline;{$endif}
  55. begin
  56. case act OF
  57. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
  58. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
  59. TCIOFF : {N/I}
  60. end;
  61. end;
  62. Function TCFlush(fd,qsel:cint):cint; {$ifdef VER2_0}inline;{$endif}
  63. begin
  64. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(qsel));
  65. end;
  66. Function IsATTY (Handle:cint):cint;
  67. {
  68. Check if the filehandle described by 'handle' is a TTY (Terminal)
  69. }
  70. var
  71. t : Termios;
  72. begin
  73. IsAtty:=ord(TCGetAttr(Handle,t) <> -1);
  74. end;
  75. Function IsATTY(var f: text):cint; {$ifdef VER2_0}inline;{$endif}
  76. {
  77. Idem as previous, only now for text variables.
  78. }
  79. begin
  80. IsATTY:=IsaTTY(textrec(f).handle);
  81. end;