termiosproc.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. (c) 2000-2003 by Marco van de Voort
  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. Termios implementation for FreeBSD
  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 TCSendBreak(fd,duration:cint):cint;
  62. begin
  63. TCSendBreak:=fpIOCtl(fd,TIOCSBRK,nil);
  64. end;
  65. Function TCSetPGrp(fd,id:cint):cint;
  66. begin
  67. TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
  68. end;
  69. Function TCGetPGrp(fd:cint;var id:cint):cint;
  70. begin
  71. TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
  72. end;
  73. Function TCDrain(fd:cint):cint;
  74. begin
  75. TCDrain:=fpIOCtl(fd,TIOCDRAIN,nil); {Should set timeout to 1 first?}
  76. end;
  77. Function TCFlow(fd,act:cint):cint;
  78. begin
  79. case act OF
  80. TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,nil);
  81. TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,nil);
  82. TCIOFF : {N/I}
  83. end;
  84. end;
  85. Function TCFlush(fd,qsel:cint):cint;
  86. begin
  87. TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
  88. end;
  89. Function IsATTY (Handle:cint):cint;
  90. {
  91. Check if the filehandle described by 'handle' is a TTY (Terminal)
  92. }
  93. var
  94. t : Termios;
  95. begin
  96. IsAtty:=TCGetAttr(Handle,t);
  97. end;
  98. Function IsATTY(var f: text):cint;
  99. {
  100. Idem as previous, only now for text variables.
  101. }
  102. begin
  103. IsATTY:=IsaTTY(textrec(f).handle);
  104. end;
  105. {
  106. $Log$
  107. Revision 1.1 2004-01-22 13:55:02 marco
  108. * first port that shows some life based on FPC_USE_LIBC
  109. Revision 1.1 2004/01/04 01:13:23 marco
  110. * first 1.1 netbsd rtl, basically freebsd copy and paste with 1.0.10 netbsd structures
  111. Revision 1.3 2004/01/03 12:18:29 marco
  112. * a lot of copyright notices and CVS logs added and fixed
  113. Revision 1.2 2003/12/16 19:43:53 marco
  114. * nil <-> 0 changes
  115. Revision 1.1 2003/11/19 17:15:31 marco
  116. * termio new includefile
  117. }