termiosproc.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {
  2. }
  3. {******************************************************************************
  4. IOCtl and Termios calls
  5. ******************************************************************************}
  6. Function TCGetAttr(fd:cint;var tios:TermIOS):cint; {$ifdef VER2_0}inline;{$endif}
  7. begin
  8. TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
  9. end;
  10. Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
  11. var
  12. nr:culong;
  13. begin
  14. case OptAct of
  15. TCSANOW : nr:=TCSETS;
  16. TCSADRAIN : nr:=TCSETSW;
  17. TCSAFLUSH : nr:=TCSETSF;
  18. else
  19. begin
  20. fpsetErrNo(ESysEINVAL);
  21. TCSetAttr:=-1;
  22. exit;
  23. end;
  24. end;
  25. TCSetAttr:=fpIOCtl(fd,nr,@Tios);
  26. end;
  27. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
  28. begin
  29. tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
  30. end;
  31. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal); {$ifdef VER2_0}inline;{$endif}
  32. begin
  33. CFSetISpeed(tios,speed);
  34. end;
  35. { checked against glibc 2.3.3 (FK) }
  36. Procedure CFMakeRaw(var tios:TermIOS);
  37. begin
  38. with tios do
  39. begin
  40. c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  41. INLCR or IGNCR or ICRNL or IXON));
  42. c_oflag:=c_oflag and (not OPOST);
  43. c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  44. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
  45. c_cc[VMIN]:=1;
  46. c_cc[VTIME]:=0;
  47. end;
  48. end;
  49. Function TCSendBreak(fd,duration:cint):cint; {$ifdef VER2_0}inline;{$endif}
  50. begin
  51. TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(ptrint(duration)));
  52. end;
  53. Function TCSetPGrp(fd,id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  54. begin
  55. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(ptrint(id)));
  56. end;
  57. Function TCGetPGrp(fd:cint;var id:cint):cint; {$ifdef VER2_0}inline;{$endif}
  58. begin
  59. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  60. end;
  61. Function TCDrain(fd:cint):cint; {$ifdef VER2_0}inline;{$endif}
  62. begin
  63. TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
  64. end;
  65. Function TCFlow(fd,act:cint):cint; {$ifdef VER2_0}inline;{$endif}
  66. begin
  67. TCFlow:=fpIOCtl(fd,TCXONC,pointer(ptrint(act)));
  68. end;
  69. Function TCFlush(fd,qsel:cint):cint; {$ifdef VER2_0}inline;{$endif}
  70. begin
  71. TCFlush:=fpIOCtl(fd,TCFLSH,pointer(ptrint(qsel)));
  72. end;
  73. Function IsATTY (Handle:cint):cint;
  74. {
  75. Check if the filehandle described by 'handle' is a TTY (Terminal)
  76. }
  77. var
  78. t : Termios;
  79. begin
  80. if TCGetAttr(Handle,t)=0 then
  81. IsAtty:=1
  82. else
  83. IsAtty:=0;
  84. end;
  85. Function IsATTY(var f: text):cint; {$ifdef VER2_0}inline;{$endif}
  86. {
  87. Idem as previous, only now for text variables.
  88. }
  89. begin
  90. IsATTY:=IsaTTY(textrec(f).handle);
  91. end;