termiosproc.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. Function TCGetAttr(fd:cint;var tios:TermIOS):cint;
  16. begin
  17. TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios);
  18. end;
  19. Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
  20. var
  21. nr:cint;
  22. begin
  23. case OptAct of
  24. TCSANOW : nr:=TIOCSETA;
  25. TCSADRAIN : nr:=TIOCSETAW;
  26. TCSAFLUSH : nr:=TIOCSETAF;
  27. else
  28. begin
  29. fpsetErrNo(ESysEINVAL);
  30. TCSetAttr:=-1;
  31. exit;
  32. end;
  33. end;
  34. TCSetAttr:=fpIOCtl(fd,nr,@Tios);
  35. end;
  36. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  37. begin
  38. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  39. end;
  40. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  41. begin
  42. tios.c_ospeed:=speed;
  43. end;
  44. Procedure CFMakeRaw(var tios:TermIOS);
  45. begin
  46. with tios do
  47. begin
  48. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  49. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  50. IGNPAR));
  51. c_iflag:=c_iflag OR IGNBRK;
  52. c_oflag:=c_oflag and (not OPOST);
  53. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  54. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  55. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  56. c_cc[VMIN]:=1;
  57. c_cc[VTIME]:=0;
  58. end;
  59. end;
  60. Function TCSendBreak(fd,duration:cint):cint;
  61. begin
  62. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  63. end;
  64. Function TCSetPGrp(fd,id:cint):cint;
  65. begin
  66. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
  67. end;
  68. Function TCGetPGrp(fd:cint;var id:cint):cint;
  69. begin
  70. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  71. end;
  72. Function TCDrain(fd:cint):cint;
  73. begin
  74. TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
  75. end;
  76. Function TCFlow(fd,act:cint):cint;
  77. begin
  78. case act OF
  79. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
  80. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
  81. TCIOFF : {N/I}
  82. end;
  83. end;
  84. Function TCFlush(fd,qsel:cint):cint;
  85. begin
  86. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
  87. end;
  88. Function IsATTY (Handle:cint):cint;
  89. {
  90. Check if the filehandle described by 'handle' is a TTY (Terminal)
  91. }
  92. var
  93. t : Termios;
  94. begin
  95. IsAtty:=ord(TCGetAttr(Handle,t) <> -1);
  96. end;
  97. Function IsATTY(var f: text):cint;
  98. {
  99. Idem as previous, only now for text variables.
  100. }
  101. begin
  102. IsATTY:=IsaTTY(textrec(f).handle);
  103. end;