termiosproc.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. {
  2. $Id$
  3. }
  4. {******************************************************************************
  5. IOCtl and Termios calls
  6. ******************************************************************************}
  7. Function TCGetAttr(fd:cint;var tios:TermIOS):cint;
  8. begin
  9. {$ifndef BSD}
  10. TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
  11. {$else}
  12. TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios);
  13. {$endif}
  14. end;
  15. Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
  16. var
  17. nr:cint;
  18. begin
  19. {$ifndef BSD}
  20. case OptAct of
  21. TCSANOW : nr:=TCSETS;
  22. TCSADRAIN : nr:=TCSETSW;
  23. TCSAFLUSH : nr:=TCSETSF;
  24. {$else}
  25. case OptAct of
  26. TCSANOW : nr:=TIOCSETA;
  27. TCSADRAIN : nr:=TIOCSETAW;
  28. TCSAFLUSH : nr:=TIOCSETAF;
  29. {$endif}
  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);
  40. begin
  41. {$ifndef BSD}
  42. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  43. {$else}
  44. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  45. {$endif}
  46. end;
  47. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  48. begin
  49. {$ifndef BSD}
  50. CFSetISpeed(tios,speed);
  51. {$else}
  52. tios.c_ospeed:=speed;
  53. {$endif}
  54. end;
  55. Procedure CFMakeRaw(var tios:TermIOS);
  56. begin
  57. {$ifndef BSD}
  58. with tios do
  59. begin
  60. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  61. INLCR or IGNCR or ICRNL or IXON));
  62. c_oflag:=c_oflag and (not OPOST);
  63. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  64. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  65. end;
  66. {$else}
  67. with tios do
  68. begin
  69. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  70. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  71. IGNPAR));
  72. c_iflag:=c_iflag OR IGNBRK;
  73. c_oflag:=c_oflag and (not OPOST);
  74. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  75. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  76. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  77. c_cc[VMIN]:=1;
  78. c_cc[VTIME]:=0;
  79. end;
  80. {$endif}
  81. end;
  82. Function TCSendBreak(fd,duration:cint):cint;
  83. begin
  84. {$ifndef BSD}
  85. TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
  86. {$else}
  87. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,0);
  88. {$endif}
  89. end;
  90. Function TCSetPGrp(fd,id:cint):cint;
  91. begin
  92. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
  93. end;
  94. Function TCGetPGrp(fd:cint;var id:cint):cint;
  95. begin
  96. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  97. end;
  98. Function TCDrain(fd:cint):cint;
  99. begin
  100. {$ifndef BSD}
  101. TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
  102. {$else}
  103. TCDrain:=fpIOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
  104. {$endif}
  105. end;
  106. Function TCFlow(fd,act:cint):cint;
  107. begin
  108. {$ifndef BSD}
  109. TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
  110. {$else}
  111. case act OF
  112. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,0);
  113. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,0);
  114. TCIOFF : {N/I}
  115. end;
  116. {$endif}
  117. end;
  118. Function TCFlush(fd,qsel:cint):cint;
  119. begin
  120. {$ifndef BSD}
  121. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
  122. {$else}
  123. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(ptrint(qsel)));
  124. {$endif}
  125. end;
  126. Function IsATTY (Handle:cint):cint;
  127. {
  128. Check if the filehandle described by 'handle' is a TTY (Terminal)
  129. }
  130. var
  131. t : Termios;
  132. begin
  133. IsAtty:=TCGetAttr(Handle,t);
  134. end;
  135. Function IsATTY(var f: text):cint;
  136. {
  137. Idem as previous, only now for text variables.
  138. }
  139. begin
  140. IsATTY:=IsaTTY(textrec(f).handle);
  141. end;
  142. {
  143. $Log$
  144. Revision 1.4 2004-07-09 19:03:35 peter
  145. * isatty return cint again
  146. }