termiosproc.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. { checked against glibc 2.3.3 (FK) }
  56. Procedure CFMakeRaw(var tios:TermIOS);
  57. begin
  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. c_cc[VMIN]:=1;
  66. c_cc[VTIME]:=0;
  67. end;
  68. end;
  69. Function TCSendBreak(fd,duration:cint):cint;
  70. begin
  71. TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
  72. end;
  73. Function TCSetPGrp(fd,id:cint):cint;
  74. begin
  75. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
  76. end;
  77. Function TCGetPGrp(fd:cint;var id:cint):cint;
  78. begin
  79. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  80. end;
  81. Function TCDrain(fd:cint):cint;
  82. begin
  83. {$ifndef BSD}
  84. TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
  85. {$else}
  86. TCDrain:=fpIOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
  87. {$endif}
  88. end;
  89. Function TCFlow(fd,act:cint):cint;
  90. begin
  91. {$ifndef BSD}
  92. TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
  93. {$else}
  94. case act OF
  95. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,0);
  96. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,0);
  97. TCIOFF : {N/I}
  98. end;
  99. {$endif}
  100. end;
  101. Function TCFlush(fd,qsel:cint):cint;
  102. begin
  103. {$ifndef BSD}
  104. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
  105. {$else}
  106. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(ptrint(qsel)));
  107. {$endif}
  108. end;
  109. Function IsATTY (Handle:cint):cint;
  110. {
  111. Check if the filehandle described by 'handle' is a TTY (Terminal)
  112. }
  113. var
  114. t : Termios;
  115. begin
  116. if TCGetAttr(Handle,t)=0 then
  117. IsAtty:=1
  118. else
  119. IsAtty:=0;
  120. end;
  121. Function IsATTY(var f: text):cint;
  122. {
  123. Idem as previous, only now for text variables.
  124. }
  125. begin
  126. IsATTY:=IsaTTY(textrec(f).handle);
  127. end;
  128. {
  129. $Log$
  130. Revision 1.6 2004-12-28 12:45:54 florian
  131. * fixed CFMakeRaw
  132. Revision 1.5 2004/11/03 10:03:39 peter
  133. * fix isatty, ioctl returns 0 on success, but isatty needs to return 1
  134. Revision 1.4 2004/07/09 19:03:35 peter
  135. * isatty return cint again
  136. }