termios.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. {
  2. This file is part of the Free Pascal run time library.
  3. (c) 2000-2003 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. Termios header for FreeBSD
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY;without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. CONST
  13. {
  14. * Special Control Characters
  15. *
  16. * Index into c_cc[] character array.
  17. *
  18. * Name Subscript Enabled by
  19. }
  20. { control characters }
  21. VINTR = 0;
  22. VQUIT = 1;
  23. VERASE = 2;
  24. VKILL = 3;
  25. VEOF = 4;
  26. VEOL = 5;
  27. VMIN = 4;
  28. VTIME = 5;
  29. VEOL2 = 6;
  30. VSWTCH = 7;
  31. VSTART = 8;
  32. VSTOP = 9;
  33. VSUSP = 10;
  34. { number of control characters }
  35. NCC = 11;
  36. NCCS =NCC;
  37. Type
  38. winsize = packed record
  39. ws_row,
  40. ws_col,
  41. ws_xpixel,
  42. ws_ypixel : word;
  43. end;
  44. TWinSize=winsize;
  45. // typedef unsigned long tcflag_t;
  46. // typedef unsigned char speed_t;
  47. // typedef unsigned char cc_t;
  48. tcflag_t = Cardinal;
  49. speed_t = byte;
  50. cc_t = char;
  51. type
  52. Termios = packed record
  53. c_iflag,
  54. c_oflag,
  55. c_cflag,
  56. c_lflag : tcflag_t;
  57. c_line : char;
  58. c_ixxxxx : speed_t;
  59. c_oxxxxx : speed_t;
  60. c_cc : array[0..NCCS-1] of speed_t;
  61. end;
  62. TTermios=Termios;
  63. CONST
  64. POSIX_VDISABLE=Chr($ff);
  65. {
  66. #define CCEQ(val, c) ((c) == (val) ? (val) != _POSIX_VDISABLE : 0)
  67. }
  68. { * Input flags - software input processing}
  69. IGNBRK = $1; { ignore BREAK condition }
  70. BRKINT = $2; { map BREAK to SIGINTR }
  71. IGNPAR = $4; { ignore (discard) parity errors }
  72. PARMRK = $8; { mark parity and framing errors }
  73. INPCK = $10; { enable checking of parity errors }
  74. ISTRIP = $20; { strip 8th bit off chars }
  75. INLCR = $40; { map NL into CR }
  76. IGNCR = $80; { ignore CR }
  77. ICRNL = $100; { map CR to NL (ala CRMOD) }
  78. IUCLC = $200; { maps all upper case to lower }
  79. IXON = $400; { enable output flow control }
  80. IXANY = $800; { enable input flow control }
  81. IXOFF = $1000; { any char will restart after stop }
  82. {
  83. * Output flags - software output processing
  84. }
  85. OPOST = $01; { enable postprocessing of output }
  86. OLCUC = $02; { maps lowercase to uppercase }
  87. ONLCR = $04; { maps NL to CR-NL on output }
  88. OCRNL = $08; { maps CR to NL on output }
  89. ONOCR = $10; { no CR output when at column 0 }
  90. ONLRET = $20; { newline performs CR function }
  91. OFILL = $40; { uses fill characters for delays }
  92. OFDEL = $80; { Fills are DEL, otherwise NUL }
  93. NLDLY = $100; { Newline delays: }
  94. NL0 = $000;
  95. NL1 = $100;
  96. CRDLY = $600; { Carriage return delays: }
  97. CR0 = $000;
  98. CR1 = $200;
  99. CR2 = $400;
  100. CR3 = $600;
  101. TABDLY = $1800; { Tab delays: }
  102. TAB0 = $0000;
  103. TAB1 = $0800;
  104. TAB2 = $1000;
  105. TAB3 = $1800;
  106. BSDLY = $2000; { Backspace delays: }
  107. BS0 = $0000;
  108. BS1 = $2000;
  109. VTDLY = $4000; { Vertical tab delays: }
  110. VT0 = $0000;
  111. VT1 = $4000;
  112. FFDLY = $8000; { Form feed delays: }
  113. FF0 = $0000;
  114. FF1 = $8000;
  115. {
  116. c_cflag - control modes
  117. }
  118. CBAUD = $1F; { line speed definitions }
  119. B0 = $00;
  120. B50 = $01;
  121. B75 = $02;
  122. B110 = $03;
  123. B134 = $04;
  124. B150 = $05;
  125. B200 = $06;
  126. B300 = $07;
  127. B600 = $08;
  128. B1200 = $09;
  129. B1800 = $0A;
  130. B2400 = $0B;
  131. B4800 = $0C;
  132. B9600 = $0D;
  133. B19200 = $0E;
  134. B38400 = $0F;
  135. B57600 = $10;
  136. B115200 = $11;
  137. B230400 = $12;
  138. B31250 = $13; { for MIDI }
  139. CSIZE = $20; { character size }
  140. CS5 = $00; { only 7 and 8 bits supported }
  141. CS6 = $00;
  142. CS7 = $00;
  143. CS8 = $20;
  144. CSTOPB = $40; { send 2 stop bits, not 1 }
  145. CREAD = $80; { enables receiver }
  146. PARENB = $100; { xmit parity enable }
  147. PARODD = $200; { odd parity, else even }
  148. HUPCL = $400; { hangs up on last close }
  149. CLOCAL = $800; { indicates local line }
  150. XLOBLK = $1000; { block layer output ?}
  151. CTSFLOW = $2000; { enable CTS flow }
  152. RTSFLOW = $4000; { enable RTS flow }
  153. CRTSCTS = RTSFLOW or CTSFLOW;
  154. {
  155. * "Local" flags - dumping ground for other state
  156. *
  157. * Warning: some flags in this structure begin with
  158. * the letter "I" and look like they belong in the
  159. * input flag.
  160. }
  161. {
  162. c_lflag - local modes
  163. }
  164. ISIG = $01; { enable signals }
  165. ICANON = $02; { Canonical input }
  166. XCASE = $04; { Canonical u/l case }
  167. ECHO = $08; { Enable echo }
  168. ECHOE = $10; { Echo erase as bs-sp-bs }
  169. ECHOK = $20; { Echo nl after kill }
  170. ECHONL = $40; { Echo nl }
  171. NOFLSH = $80; { Disable flush after int or quit }
  172. TOSTOP = $100; { stop bg processes that write to tty }
  173. IEXTEN = $200; { implementation defined extensions }
  174. {
  175. Event codes. Returned from TCWAITEVENT
  176. }
  177. EV_RING = $0001;
  178. EV_BREAK = $0002;
  179. EV_CARRIER = $0004;
  180. EV_CARRIERLOST = $0008;
  181. {
  182. * Commands passed to tcsetattr() for setting the termios structure.
  183. }
  184. CONST
  185. TCSANOW = $01; { make change immediate }
  186. TCSADRAIN = $02; { drain output, then change }
  187. TCSAFLUSH = $04; { drain output, flush input }
  188. // TCASOFT undefined under BeOS
  189. TCSASOFT = $10; { flag - don't alter h.w. state }
  190. TCIFLUSH = $01;
  191. TCOFLUSH = $02;
  192. TCIOFLUSH = (TCIFLUSH or TCOFLUSH);
  193. TCOOFF = $01;
  194. TCOON = $02;
  195. TCIOFF = $04;
  196. TCION = $08;
  197. {
  198. #include <sys/cdefs.h>
  199. __BEGIN_DECLS
  200. speed_t cfgetispeed __P((const struct termios *));
  201. speed_t cfgetospeed __P((const struct termios *));
  202. int cfsetispeed __P((struct termios *, speed_t));
  203. int cfsetospeed __P((struct termios *, speed_t));
  204. int tcgetattr __P((int, struct termios *));
  205. int tcsetattr __P((int, int, const struct termios *));
  206. int tcdrain __P((int));
  207. int tcflow __P((int, int));
  208. int tcflush __P((int, int));
  209. int tcsendbreak __P((int, int));
  210. #ifndef _POSIX_SOURCE
  211. void cfmakeraw __P((struct termios *));
  212. int cfsetspeed __P((struct termios *, speed_t));
  213. #endif { !_POSIX_SOURCE }
  214. __END_DECLS
  215. #endif { !_KERNEL }
  216. struct winsize {
  217. unsigned short ws_row; { rows, in characters }
  218. unsigned short ws_col; { columns, in characters }
  219. unsigned short ws_xpixel; { horizontal size, pixels }
  220. unsigned short ws_ypixel; { vertical size, pixels }
  221. };
  222. }
  223. (* IOCTLREAD = $40000000;
  224. IOCTLWRITE = $80000000;
  225. IOCTLVOID = $20000000;
  226. TIOCMODG = IOCTLREAD+$47400+ 3; { get modem control state }
  227. TIOCMODS = IOCTLWRITE+$47400+ 4; { set modem control state }
  228. TIOCM_LE =$0001; { line enable }
  229. TIOCM_DTR =$0002; { data terminal ready }
  230. TIOCM_RTS =$0004; { request to send }
  231. TIOCM_ST =$0010; { secondary transmit }
  232. TIOCM_SR =$0020; { secondary receive }
  233. TIOCM_CTS =$0040; { clear to send }
  234. TIOCM_CAR =$0100; { carrier detect }
  235. TIOCM_CD =TIOCM_CAR;
  236. TIOCM_RNG =$0200; { ring }
  237. TIOCM_RI =TIOCM_RNG;
  238. TIOCM_DSR =$0400; { data set ready }
  239. { 8-10 compat }
  240. TIOCEXCL =IOCTLVOID+$7400+ 13; { set exclusive use of tty }
  241. TIOCNXCL =IOCTLVOID+$7400+ 14; { reset exclusive use of tty }
  242. *) { 15 unused }
  243. // TIOCFLUSH =IOCTLWRITE+$47400+ 16; { flush buffers }
  244. { 17-18 compat }
  245. // TIOCGETA =IOCTLREAD+$2C7400+ 19; { get termios struct }
  246. // TIOCSETA =IOCTLWRITE+$2C7400+ 20; { set termios struct }
  247. // TIOCSETAW =IOCTLWRITE+$2C7400+ 21; { drain output, set }
  248. // TIOCSETAF =IOCTLWRITE+$2C7400+ 22; { drn out, fls in, set }
  249. // TIOCGETD =IOCTLREAD+$47400+ 26; { get line discipline }
  250. // TIOCSETD =IOCTLWRITE+$47400+ 27; { set line discipline }
  251. { 127-124 compat }
  252. // BeOS values
  253. TIOCGETA = $8000;
  254. TIOCSETA = TIOCGETA + 1;
  255. TIOCSETAF = TIOCGETA + 2;
  256. TIOCSETAW = TIOCGETA + 3;
  257. TCWAITEVENT = TIOCGETA + 4;
  258. TIOCSBRK = TIOCGETA + 5;
  259. TIOCFLUSH = TIOCGETA + 6;
  260. TCXONC = TIOCGETA + 7;
  261. TCQUERYCONNECTED= TIOCGETA + 8;
  262. TCGETBITS = TIOCGETA + 9;
  263. TIOCSDTR = TIOCGETA + 10;
  264. TCSETRTS = TIOCGETA + 11;
  265. TIOCGWINSZ = TIOCGETA + 12;
  266. TIOCSWINSZ = TIOCGETA + 13;
  267. TCVTIME = TIOCGETA + 14;
  268. // TIOCTIMESTAMP = TCVTIME;
  269. // end BeOS values
  270. (*
  271. // TIOCSBRK =IOCTLVOID+$7400+ 123; { set break bit }
  272. TIOCCBRK =IOCTLVOID+$7400+ 122; { clear break bit }
  273. // TIOCSDTR =IOCTLVOID+$7400+ 121; { set data terminal ready }
  274. TIOCCDTR =IOCTLVOID+$7400+ 120; { clear data terminal ready }
  275. TIOCGPGRP =IOCTLREAD+$47400+ 119; { get pgrp of tty }
  276. TIOCSPGRP =IOCTLWRITE+$47400+ 118; { set pgrp of tty }
  277. { 117-116 compat }
  278. TIOCOUTQ =IOCTLREAD+$47400+ 115; { output queue size }
  279. TIOCSTI =IOCTLWRITE+$17400+ 114; { simulate terminal input }
  280. TIOCNOTTY =IOCTLVOID+$7400+ 113; { void tty association }
  281. TIOCPKT =IOCTLWRITE+$47400+ 112; { pty: set/clear packet mode }
  282. TIOCPKT_DATA =$00; { data packet }
  283. TIOCPKT_FLUSHREAD =$01; { flush packet }
  284. TIOCPKT_FLUSHWRITE =$02; { flush packet }
  285. TIOCPKT_STOP =$04; { stop output }
  286. TIOCPKT_START =$08; { start output }
  287. TIOCPKT_NOSTOP =$10; { no more ^S, ^Q }
  288. TIOCPKT_DOSTOP =$20; { now do ^S ^Q }
  289. TIOCPKT_IOCTL =$40; { state change of pty driver }
  290. TIOCSTOP =IOCTLVOID+$7400+ 111; { stop output, like ^S }
  291. TIOCSTART =IOCTLVOID+$7400+ 110; { start output, like ^Q }
  292. TIOCMSET =IOCTLWRITE+$47400+ 109; { set all modem bits }
  293. TIOCMBIS =IOCTLWRITE+$47400+ 108; { bis modem bits }
  294. TIOCMBIC =IOCTLWRITE+$47400+ 107; { bic modem bits }
  295. TIOCMGET =IOCTLREAD+$47400+ 106; { get all modem bits }
  296. TIOCREMOTE =IOCTLWRITE+$47400+ 105; { remote input editing }
  297. // TIOCGWINSZ =IOCTLREAD+$87400+ 104; { get window size }
  298. // TIOCSWINSZ =IOCTLWRITE+$87400+ 103; { set window size }
  299. TIOCUCNTL =IOCTLWRITE+$47400+ 102; { pty: set/clr usr cntl mode }
  300. TIOCSTAT =IOCTLVOID+$7400+ 101; { simulate ^T status message }
  301. // UIOCCMD(n) _IO('u', n) { usr cntl op "n" }
  302. TIOCCONS =IOCTLWRITE+$47400+ 98; { become virtual console }
  303. TIOCSCTTY =IOCTLVOID+$7400+ 97; { become controlling tty }
  304. TIOCEXT =IOCTLWRITE+$47400+ 96; { pty: external processing }
  305. TIOCSIG =IOCTLVOID+$7400+ 95; { pty: generate signal }
  306. TIOCDRAIN =IOCTLVOID+$7400+ 94; { wait till output drained }
  307. TIOCMSDTRWAIT =IOCTLWRITE+$47400+ 91; { modem: set wait on close }
  308. TIOCMGDTRWAIT =IOCTLREAD+$47400+ 90; { modem: get wait on close }
  309. // TIOCTIMESTAMP =IOCTLREAD+$87400+ 89; { enable/get timestamp
  310. // * of last input event }
  311. TIOCDCDTIMESTAMP =IOCTLREAD+$87400+ 88; { enable/get timestamp
  312. * of last DCd rise }
  313. TIOCSDRAINWAIT =IOCTLWRITE+$47400+ 87; { set ttywait timeout }
  314. TIOCGDRAINWAIT =IOCTLREAD+$47400+ 86; { get ttywait timeout }
  315. TTYDISC =0; { termios tty line discipline }
  316. SLIPDISC =4; { serial IP discipline }
  317. PPPDISC =5; { PPP discipline }
  318. NETGRAPHDISC =6; { Netgraph tty node discipline }
  319. // OCO 31/10/2005 For compatiblity (defined to compile ShiftState function
  320. // in keyboard.pp)
  321. // Maybe, it should not work but it compile at least...
  322. TIOCLINUX = $541C;
  323. *)
  324. {
  325. * Defaults on "first" open.
  326. }
  327. TTYDEF_IFLAG =(BRKINT or ICRNL or IXON or IXANY);
  328. TTYDEF_OFLAG =(OPOST or ONLCR);
  329. TTYDEF_LFLAG =(ECHO or ICANON or ISIG or IEXTEN or ECHOE );
  330. TTYDEF_CFLAG =(CREAD or CS8 or HUPCL);
  331. TTYDEF_SPEED =(B9600);
  332. {
  333. * Control Character Defaults
  334. }
  335. (* CtrlMask = $1f; {\037}
  336. CEOF =chr( ORD('d') and CtrlMask);
  337. CEOL =chr( $ff and CtrlMask);{ XXX avoid _POSIX_VDISABLE }
  338. CERASE =chr( $7F and CtrlMask);
  339. CINTR =chr(ORD('c') and CtrlMask);
  340. CSTATUS =chr(ORD('t') and CtrlMask);
  341. CKILL =chr(ORD('u') and CtrlMask);
  342. CMIN =chr(1);
  343. CQUIT =chr(034 and CtrlMask); { FS, ^\ }
  344. CSUSP =chr(ORD('z') and CtrlMask);
  345. CTIME =chr(0);
  346. CDSUSP =chr(ORD('y') and CtrlMask);
  347. CSTART =chr(ORD('q') and CtrlMask);
  348. CSTOP =chr(ORD('s') and CtrlMask);
  349. CLNEXT =chr(ORD('v') and CtrlMask);
  350. CDISCARD =chr(ORD('o') and CtrlMask);
  351. CWERASE =chr(ORD('w') and CtrlMask);
  352. CREPRINT =chr(ORD('r') and CtrlMask);
  353. CEOT =CEOF;
  354. { compat }
  355. CBRK =CEOL;
  356. CRPRNT =CREPRINT;
  357. CFLUSH =CDISCARD;
  358. *)
  359. {
  360. * TTYDEFCHARS to include an array of default control characters.
  361. }
  362. ttydefchars : array[0..NCCS-1] OF char =(
  363. Chr(VINTR), Chr(VQUIT), Chr(VERASE), Chr(VKILL), Chr(VEOF), Chr(VEOL),
  364. Chr(VEOL2), Chr(VSWTCH), Chr(VSTART), Chr(VSTOP), Chr(VSUSP));
  365. {
  366. According to posix/sys/ioctl.h
  367. /* these currently work only on sockets */
  368. }
  369. FIONBIO = $be000000;
  370. FIONREAD = $be000001;