termiosproc.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Peter Vreman
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This file contains the implementation of several termio(s) functions
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {******************************************************************************
  14. IOCtl and Termios calls
  15. ******************************************************************************}
  16. Function TCGetAttr(fd:cint;var tios:TermIOS):cint;
  17. begin
  18. TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios);
  19. end;
  20. Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
  21. var
  22. nr:cint;
  23. begin
  24. case OptAct of
  25. TCSANOW : nr:=TIOCSETA;
  26. TCSADRAIN : nr:=TIOCSETAW;
  27. TCSAFLUSH : nr:=TIOCSETAF;
  28. else
  29. begin
  30. fpsetErrNo(ESysEINVAL);
  31. TCSetAttr:=-1;
  32. exit;
  33. end;
  34. end;
  35. TCSetAttr:=fpIOCtl(fd,nr,@Tios);
  36. end;
  37. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  38. begin
  39. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  40. end;
  41. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  42. begin
  43. tios.c_ospeed:=speed;
  44. end;
  45. Procedure CFMakeRaw(var tios:TermIOS);
  46. begin
  47. with tios do
  48. begin
  49. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  50. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  51. IGNPAR));
  52. c_iflag:=c_iflag OR IGNBRK;
  53. c_oflag:=c_oflag and (not OPOST);
  54. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  55. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  56. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  57. c_cc[VMIN]:=1;
  58. c_cc[VTIME]:=0;
  59. end;
  60. end;
  61. //Function TCGetAttr(fd:cint;var tios:TermIOS):cint; cdecl; external 'c' name 'tcgetattr';
  62. //Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint; cdecl; external 'c' name 'tcsetattr';
  63. //Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); cdecl; external 'c' name 'cfsetispeed';
  64. //Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); cdecl; external 'c' name 'cfsetospeed';
  65. //Procedure CFMakeRaw(var tios:TermIOS); cdecl; external 'c' name 'cfmakeraw';
  66. Function TCSendBreak(fd,duration:cint):cint;
  67. begin
  68. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  69. end;
  70. Function TCSetPGrp(fd,id:cint):cint;
  71. begin
  72. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
  73. end;
  74. Function TCGetPGrp(fd:cint;var id:cint):cint;
  75. begin
  76. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  77. end;
  78. Function TCDrain(fd:cint):cint;
  79. begin
  80. TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
  81. end;
  82. Function TCFlow(fd,act:cint):cint;
  83. begin
  84. case act OF
  85. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
  86. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
  87. TCIOFF : {N/I}
  88. end;
  89. end;
  90. Function TCFlush(fd,qsel:cint):cint;
  91. begin
  92. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
  93. end;
  94. Function IsATTY (Handle:cint):cint;
  95. {
  96. Check if the filehandle described by 'handle' is a TTY (Terminal)
  97. }
  98. var
  99. t : Termios;
  100. begin
  101. IsAtty:=TCGetAttr(Handle,t);
  102. end;
  103. Function IsATTY(var f: text):cint;
  104. {
  105. Idem as previous, only now for text variables.
  106. }
  107. begin
  108. IsATTY:=IsaTTY(textrec(f).handle);
  109. end;
  110. {
  111. $Log$
  112. Revision 1.4 2004-07-09 21:41:47 peter
  113. * revert back isatty
  114. Revision 1.2 2004/02/05 14:00:45 jonas
  115. + some declarations added from other bsds and /usr/include/sys/termios.h
  116. to termios.inc and termiosproc.inc (by Karl-Michael Schindler)
  117. + added crt, mouse (because required by keyboard), keyboard, termio,
  118. console to Darwin makefile (thanks to the above they now compile,
  119. functionality untested)
  120. * fixed wrong dependency for sysconst unit (it was always recompiled)
  121. Revision 1.1 2004/01/04 20:05:38 jonas
  122. * first working version of the Darwin/Mac OS X (for PowerPC) RTL
  123. Several non-essential units are still missing, but make cycle works
  124. Revision 1.2 2003/12/16 19:43:53 marco
  125. * nil <-> 0 changes
  126. Revision 1.1 2003/11/19 17:15:31 marco
  127. * termio new includefile
  128. }