termiosproc.inc 3.4 KB

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