2
0

termiosproc.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. // field unused under BeOS
  39. tios.c_ixxxxx:=speed;
  40. end;
  41. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  42. begin
  43. // field unused under BeOS
  44. tios.c_oxxxxx:=speed;
  45. end;
  46. Procedure CFMakeRaw(var tios:TermIOS);
  47. begin
  48. with tios do
  49. begin
  50. c_iflag:=c_iflag and (not (IXOFF or INPCK or BRKINT or
  51. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  52. IGNPAR));
  53. c_iflag:=c_iflag OR IGNBRK;
  54. c_oflag:=c_oflag and (not OPOST);
  55. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  56. ISIG or IEXTEN or NOFLSH or TOSTOP));
  57. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  58. c_cc[VMIN]:= 1;
  59. c_cc[VTIME]:= 0;
  60. end;
  61. end;
  62. Function TCSendBreak(fd,duration:cint):cint;
  63. begin
  64. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  65. end;
  66. Function be_tcsetpgrp(fd, pgrpid : pid_t) : cint; cdecl; external 'root' name 'tcsetpgrp';
  67. Function be_tcgetpgrp(fd : cint) : pid_t; cdecl; external 'root' name 'tcgetpgrp';
  68. Function be_tcdrain(fd : cint) : cint; cdecl; external 'root' name 'tcdrain';
  69. Function be_tcflow(fd, action : cint) : cint; cdecl; external 'root' name 'tcflow';
  70. Function be_tcflush(fd, queue_selector : cint) : cint; cdecl; external 'root' name 'tcflush';
  71. Function TCSetPGrp(fd,id:cint):cint;
  72. begin
  73. TCSetPGrp := be_tcsetpgrp(fd, id);
  74. end;
  75. Function TCGetPGrp(fd:cint;var id:cint):cint;
  76. begin
  77. id := be_tcgetpgrp(fd);
  78. end;
  79. Function TCDrain(fd:cint):cint;
  80. begin
  81. TCDrain := be_tcdrain(fd);
  82. end;
  83. Function TCFlow(fd,act:cint):cint;
  84. begin
  85. TCFlow := be_tcflow(fd, act);
  86. end;
  87. Function TCFlush(fd,qsel:cint):cint;
  88. begin
  89. TCFlush := be_tcflush(fd, qsel);
  90. end;
  91. Function BeOSIsATTY (Handle:cint):cint; cdecl; external 'root' name 'isatty';
  92. Function IsATTY (Handle:cint):cint;
  93. {
  94. Check if the filehandle described by 'handle' is a TTY (Terminal)
  95. }
  96. begin
  97. IsAtty:= BeOSIsATTY(Handle);
  98. end;
  99. Function IsATTY(var f: text):cint;
  100. {
  101. Idem as previous, only now for text variables.
  102. }
  103. begin
  104. IsATTY:=IsaTTY(textrec(f).handle);
  105. end;