termiosproc.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. }
  3. {******************************************************************************
  4. IOCtl and Termios calls
  5. ******************************************************************************}
  6. Function TCGetAttr(fd:cint;var tios:TermIOS):cint;
  7. begin
  8. {$ifndef BSD}
  9. TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
  10. {$else}
  11. TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios);
  12. {$endif}
  13. end;
  14. Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
  15. var
  16. nr:cint;
  17. begin
  18. {$ifndef BSD}
  19. case OptAct of
  20. TCSANOW : nr:=TCSETS;
  21. TCSADRAIN : nr:=TCSETSW;
  22. TCSAFLUSH : nr:=TCSETSF;
  23. {$else}
  24. case OptAct of
  25. TCSANOW : nr:=TIOCSETA;
  26. TCSADRAIN : nr:=TIOCSETAW;
  27. TCSAFLUSH : nr:=TIOCSETAF;
  28. {$endif}
  29. else
  30. begin
  31. fpsetErrNo(ESysEINVAL);
  32. TCSetAttr:=-1;
  33. exit;
  34. end;
  35. end;
  36. TCSetAttr:=fpIOCtl(fd,nr,@Tios);
  37. end;
  38. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  39. begin
  40. {$ifndef BSD}
  41. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  42. {$else}
  43. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  44. {$endif}
  45. end;
  46. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  47. begin
  48. {$ifndef BSD}
  49. CFSetISpeed(tios,speed);
  50. {$else}
  51. tios.c_ospeed:=speed;
  52. {$endif}
  53. end;
  54. { checked against glibc 2.3.3 (FK) }
  55. Procedure CFMakeRaw(var tios:TermIOS);
  56. begin
  57. with tios do
  58. begin
  59. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  60. INLCR or IGNCR or ICRNL or IXON));
  61. c_oflag:=c_oflag and (not OPOST);
  62. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  63. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  64. c_cc[VMIN]:=1;
  65. c_cc[VTIME]:=0;
  66. end;
  67. end;
  68. Function TCSendBreak(fd,duration:cint):cint;
  69. begin
  70. TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
  71. end;
  72. Function TCSetPGrp(fd,id:cint):cint;
  73. begin
  74. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
  75. end;
  76. Function TCGetPGrp(fd:cint;var id:cint):cint;
  77. begin
  78. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  79. end;
  80. Function TCDrain(fd:cint):cint;
  81. begin
  82. {$ifndef BSD}
  83. TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
  84. {$else}
  85. TCDrain:=fpIOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
  86. {$endif}
  87. end;
  88. Function TCFlow(fd,act:cint):cint;
  89. begin
  90. {$ifndef BSD}
  91. TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
  92. {$else}
  93. case act OF
  94. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,0);
  95. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,0);
  96. TCIOFF : {N/I}
  97. end;
  98. {$endif}
  99. end;
  100. Function TCFlush(fd,qsel:cint):cint;
  101. begin
  102. {$ifndef BSD}
  103. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
  104. {$else}
  105. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(ptrint(qsel)));
  106. {$endif}
  107. end;
  108. Function IsATTY (Handle:cint):cint;
  109. {
  110. Check if the filehandle described by 'handle' is a TTY (Terminal)
  111. }
  112. var
  113. t : Termios;
  114. begin
  115. if TCGetAttr(Handle,t)=0 then
  116. IsAtty:=1
  117. else
  118. IsAtty:=0;
  119. end;
  120. Function IsATTY(var f: text):cint;
  121. {
  122. Idem as previous, only now for text variables.
  123. }
  124. begin
  125. IsATTY:=IsaTTY(textrec(f).handle);
  126. end;