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
6   See the file COPYING.FPC, included in this distribution,
7   for details about the copyright.
8
9   Termios header for FreeBSD
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY;without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14}
15
16CONST
17
18{
19 * Special Control Characters
20 *
21 * Index into c_cc[] character array.
22 *
23 *      Name         Subscript  Enabled by
24 }
25 VEOF           =0;
26 VEOL           =1;
27 VEOL2          =2;
28 VERASE         =3;
29 VWERASE        =4;
30 VKILL          =5;
31 VREPRINT       =6;
32{               =7;        spare 1 }
33 VINTR          =8;
34 VQUIT          =9;
35 VSUSP          =10;
36 VDSUSP         =11;
37 VSTART         =12;
38 VSTOP          =13;
39 VLNEXT         =14;
40 VDISCARD       =15;
41 VMIN           =16;
42 VTIME          =17;
43 VSTATUS        =18;
44{               =19        spare 2 }
45 NCCS           =20;
46
47Type
48  winsize = packed record
49    ws_row,
50    ws_col,
51    ws_xpixel,
52    ws_ypixel : word;
53  end;
54  TWinSize=winsize;
55
56
57type
58  Termios = packed record
59    c_iflag,
60    c_oflag,
61    c_cflag,
62    c_lflag  : longint;
63    c_line   : char;
64    c_cc     : array[0..NCCS-1] of byte;
65   {$IFDEF BSD}
66    c_ispeed,
67    c_ospeed : longint;
68   {$endif}
69  end;
70  TTermios=Termios;
71
72CONST
73
74
75 POSIX_VDISABLE=Chr($ff);
76{
77
78#define CCEQ(val, c)    ((c) == (val) ? (val) != _POSIX_VDISABLE : 0)
79}
80
81{ * Input flags - software input processing}
82
83        IGNBRK          =       $1;     { ignore BREAK condition }
84        BRKINT          =       $2;     { map BREAK to SIGINTR }
85        IGNPAR          =       $4;     { ignore (discard) parity errors }
86        PARMRK          =       $8;     { mark parity and framing errors }
87        INPCK           =      $10;     { enable checking of parity errors }
88        ISTRIP          =      $20;     { strip 8th bit off chars }
89        INLCR           =      $40;     { map NL into CR }
90        IGNCR           =      $80;     { ignore CR }
91        ICRNL           =     $100;     { map CR to NL (ala CRMOD) }
92        IXON            =     $200;     { enable output flow control }
93        IXOFF           =     $400;     { enable input flow control }
94        IXANY           =     $800;     { any char will restart after stop }
95        IMAXBEL         =    $2000;     { ring bell on input queue full }
96
97{
98 * Output flags - software output processing
99}
100        OPOST           =       $1;     { enable following output processing }
101        ONLCR           =       $2;     { map NL to CR-NL (ala CRMOD) }
102        OXTABS          =       $4;     { expand tabs to spaces }
103        ONOEOT          =       $8;     { discard EOT's (^D) on output) }
104
105{
106 * Control flags - hardware control of terminal
107}
108        CIGNORE         =       $1;     { ignore control flags }
109        CSIZE           =     $300;     { character size mask }
110        CS5             =       $0;         { 5 bits (pseudo) }
111        CS6             =     $100;         { 6 bits }
112        CS7             =     $200;         { 7 bits }
113        CS8             =     $300;         { 8 bits }
114        CSTOPB          =     $400;     { send 2 stop bits }
115        CREAD           =     $800;     { enable receiver }
116        PARENB          =    $1000;     { parity enable }
117        PARODD          =    $2000;     { odd parity, else even }
118        HUPCL           =    $4000;     { hang up on last close }
119        CLOCAL          =    $8000;     { ignore modem status lines }
120        CCTS_OFLOW      =   $10000;     { CTS flow control of output }
121        CRTS_IFLOW      =   $20000;     { RTS flow control of input }
122        CRTSCTS         =   (CCTS_OFLOW or CRTS_IFLOW);
123        CDTR_IFLOW      =   $40000;     { DTR flow control of input }
124        CDSR_OFLOW      =   $80000;     { DSR flow control of output }
125        CCAR_OFLOW      =  $100000;     { DCD flow control of output }
126        MDMBUF          =  $100000;     { old name for CCAR_OFLOW }
127
128{
129 * "Local" flags - dumping ground for other state
130 *
131 * Warning: some flags in this structure begin with
132 * the letter "I" and look like they belong in the
133 * input flag.
134 }
135
136        ECHOKE          =       $1;     { visual erase for line kill }
137        ECHOE           =       $2;     { visually erase chars }
138        ECHOK           =       $4;     { echo NL after line kill }
139        ECHO            =       $8;     { enable echoing }
140        ECHONL          =      $10;     { echo NL even if ECHO is off }
141        ECHOPRT         =      $20;     { visual erase mode for hardcopy }
142        ECHOCTL         =      $40;     { echo control chars as ^(Char) }
143        ISIG            =      $80;     { enable signals INTR, QUIT, [D]SUSP }
144        ICANON          =     $100;     { canonicalize input lines }
145        ALTWERASE       =     $200;     { use alternate WERASE algorithm }
146        IEXTEN          =     $400;     { enable DISCARD and LNEXT }
147        EXTPROC         =     $800;      { external processing }
148        TOSTOP          =  $400000;     { stop background jobs from output }
149        FLUSHO          =  $800000;     { output being flushed (state) }
150        NOKERNINFO      = $2000000;     { no kernel output from VSTATUS }
151        PENDIN          =$20000000;     { XXX retype pending input (state) }
152        NOFLSH          =$80000000;     { don't flush after interrupt }
153
154
155
156{
157 * Commands passed to tcsetattr() for setting the termios structure.
158}
159
160CONST
161
162        TCSANOW         =0;             { make change immediate }
163        TCSADRAIN       =1;             { drain output, then change }
164        TCSAFLUSH       =2;             { drain output, flush input }
165        TCSASOFT        =$10;           { flag - don't alter h.w. state }
166
167{
168 * Standard speeds
169}
170        B0      =     0;
171        B50     =    50;
172        B75     =    75;
173        B110    =   110;
174        B134    =   134;
175        B150    =   150;
176        B200    =   200;
177        B300    =   300;
178        B600    =   600;
179        B1200   =  1200;
180        B1800   =  1800;
181        B2400   =  2400;
182        B4800   =  4800;
183        B9600   =  9600;
184        B19200  = 19200;
185        B38400  = 38400;
186        B7200   =  7200;
187        B14400  = 14400;
188        B28800  = 28800;
189        B57600  = 57600;
190        B76800  = 76800;
191        B115200 =115200;
192        B230400 =230400;
193        EXTA    = 19200;
194        EXTB    = 38400;
195
196        TCIFLUSH        =1;
197        TCOFLUSH        =2;
198        TCIOFLUSH       =3;
199        TCOOFF          =1;
200        TCOON           =2;
201        TCIOFF          =3;
202        TCION           =4;
203
204{
205#include <sys/cdefs.h>
206
207__BEGIN_DECLS
208speed_t cfgetispeed __P((const struct termios *));
209speed_t cfgetospeed __P((const struct termios *));
210int     cfsetispeed __P((struct termios *, speed_t));
211int     cfsetospeed __P((struct termios *, speed_t));
212int     tcgetattr __P((int, struct termios *));
213int     tcsetattr __P((int, int, const struct termios *));
214int     tcdrain __P((int));
215int     tcflow __P((int, int));
216int     tcflush __P((int, int));
217int     tcsendbreak __P((int, int));
218
219#ifndef _POSIX_SOURCE
220void    cfmakeraw __P((struct termios *));
221int     cfsetspeed __P((struct termios *, speed_t));
222#endif { !_POSIX_SOURCE }
223__END_DECLS
224
225#endif { !_KERNEL }
226
227
228
229struct winsize {
230        unsigned short  ws_row;         { rows, in characters }
231        unsigned short  ws_col;         { columns, in characters }
232        unsigned short  ws_xpixel;      { horizontal size, pixels }
233        unsigned short  ws_ypixel;      { vertical size, pixels }
234};
235
236}
237       IOCTLREAD        = $40000000;
238       IOCTLWRITE       = $80000000;
239       IOCTLVOID        = $20000000;
240
241        TIOCMODG        = IOCTLREAD+$47400+ 3;  { get modem control state }
242        TIOCMODS        = IOCTLWRITE+$47400+ 4; { set modem control state }
243                TIOCM_LE        =$0001;         { line enable }
244                TIOCM_DTR       =$0002;         { data terminal ready }
245                TIOCM_RTS       =$0004;         { request to send }
246                TIOCM_ST        =$0010;         { secondary transmit }
247                TIOCM_SR        =$0020;         { secondary receive }
248                TIOCM_CTS       =$0040;         { clear to send }
249                TIOCM_CAR       =$0100;         { carrier detect }
250                TIOCM_CD        =TIOCM_CAR;
251                TIOCM_RNG       =$0200;         { ring }
252                TIOCM_RI        =TIOCM_RNG;
253                TIOCM_DSR       =$0400;         { data set ready }
254                                                { 8-10 compat }
255        TIOCEXCL         =IOCTLVOID+$7400+ 13;          { set exclusive use of tty }
256        TIOCNXCL         =IOCTLVOID+$7400+ 14;          { reset exclusive use of tty }
257                                                { 15 unused }
258        TIOCFLUSH        =IOCTLWRITE+$47400+ 16;        { flush buffers }
259                                                { 17-18 compat }
260        TIOCGETA         =IOCTLREAD+$2C7400+ 19; { get termios struct }
261        TIOCSETA         =IOCTLWRITE+$2C7400+ 20; { set termios struct }
262        TIOCSETAW        =IOCTLWRITE+$2C7400+ 21; { drain output, set }
263        TIOCSETAF        =IOCTLWRITE+$2C7400+ 22; { drn out, fls in, set }
264        TIOCGETD         =IOCTLREAD+$47400+ 26; { get line discipline }
265        TIOCSETD         =IOCTLWRITE+$47400+ 27;        { set line discipline }
266                                                { 127-124 compat }
267        TIOCSBRK         =IOCTLVOID+$7400+ 123;         { set break bit }
268        TIOCCBRK         =IOCTLVOID+$7400+ 122;         { clear break bit }
269        TIOCSDTR         =IOCTLVOID+$7400+ 121;         { set data terminal ready }
270        TIOCCDTR         =IOCTLVOID+$7400+ 120;         { clear data terminal ready }
271        TIOCGPGRP        =IOCTLREAD+$47400+ 119;        { get pgrp of tty }
272        TIOCSPGRP        =IOCTLWRITE+$47400+ 118;       { set pgrp of tty }
273                                                { 117-116 compat }
274        TIOCOUTQ         =IOCTLREAD+$47400+ 115;        { output queue size }
275        TIOCSTI          =IOCTLWRITE+$17400+ 114;       { simulate terminal input }
276        TIOCNOTTY        =IOCTLVOID+$7400+ 113;         { void tty association }
277        TIOCPKT          =IOCTLWRITE+$47400+ 112;       { pty: set/clear packet mode }
278                TIOCPKT_DATA            =$00;   { data packet }
279                TIOCPKT_FLUSHREAD       =$01;   { flush packet }
280                TIOCPKT_FLUSHWRITE      =$02;   { flush packet }
281                TIOCPKT_STOP            =$04;   { stop output }
282                TIOCPKT_START           =$08;   { start output }
283                TIOCPKT_NOSTOP          =$10;   { no more ^S, ^Q }
284                TIOCPKT_DOSTOP          =$20;   { now do ^S ^Q }
285                TIOCPKT_IOCTL           =$40;   { state change of pty driver }
286        TIOCSTOP         =IOCTLVOID+$7400+ 111;         { stop output, like ^S }
287        TIOCSTART        =IOCTLVOID+$7400+ 110;         { start output, like ^Q }
288        TIOCMSET         =IOCTLWRITE+$47400+ 109;       { set all modem bits }
289        TIOCMBIS         =IOCTLWRITE+$47400+ 108;       { bis modem bits }
290        TIOCMBIC         =IOCTLWRITE+$47400+ 107;       { bic modem bits }
291        TIOCMGET         =IOCTLREAD+$47400+ 106;        { get all modem bits }
292        TIOCREMOTE       =IOCTLWRITE+$47400+ 105;       { remote input editing }
293        TIOCGWINSZ       =IOCTLREAD+$87400+ 104;        { get window size }
294        TIOCSWINSZ       =IOCTLWRITE+$87400+ 103;       { set window size }
295        TIOCUCNTL        =IOCTLWRITE+$47400+ 102;       { pty: set/clr usr cntl mode }
296        TIOCSTAT         =IOCTLVOID+$7400+ 101;         { simulate ^T status message }
297  //                       UIOCCMD(n)   _IO('u', n)     { usr cntl op "n" }
298        TIOCCONS         =IOCTLWRITE+$47400+ 98;        { become virtual console }
299        TIOCSCTTY        =IOCTLVOID+$7400+ 97;          { become controlling tty }
300        TIOCEXT          =IOCTLWRITE+$47400+ 96;        { pty: external processing }
301        TIOCSIG          =IOCTLVOID+$7400+ 95;          { pty: generate signal }
302        TIOCDRAIN        =IOCTLVOID+$7400+ 94;          { wait till output drained }
303        TIOCMSDTRWAIT    =IOCTLWRITE+$47400+ 91;        { modem: set wait on close }
304        TIOCMGDTRWAIT    =IOCTLREAD+$47400+ 90; { modem: get wait on close }
305        TIOCTIMESTAMP    =IOCTLREAD+$87400+ 89;         { enable/get timestamp
306                                                 * of last input event }
307        TIOCDCDTIMESTAMP =IOCTLREAD+$87400+ 88; { enable/get timestamp
308                                                 * of last DCd rise }
309        TIOCSDRAINWAIT   =IOCTLWRITE+$47400+ 87;        { set ttywait timeout }
310        TIOCGDRAINWAIT   =IOCTLREAD+$47400+ 86; { get ttywait timeout }
311
312        TTYDISC          =0;            { termios tty line discipline }
313        SLIPDISC         =4;            { serial IP discipline }
314        PPPDISC          =5;            { PPP discipline }
315        NETGRAPHDISC     =6;            { Netgraph tty node discipline }
316
317
318{
319 * Defaults on "first" open.
320 }
321        TTYDEF_IFLAG     =(BRKINT       or ICRNL        or IMAXBEL or IXON or IXANY);
322       TTYDEF_OFLAG      =(OPOST or ONLCR);
323       TTYDEF_LFLAG      =(ECHO or ICANON or ISIG or IEXTEN or ECHOE or ECHOKE or ECHOCTL);
324        TTYDEF_CFLAG     =(CREAD or CS8 or HUPCL);
325       TTYDEF_SPEED      =(B9600);
326
327
328
329{
330 * Control Character Defaults
331 }
332        CtrlMask        = $1f;  {\037}
333        CEOF            =chr( ORD('d') and CtrlMask);
334        CEOL            =chr( $ff and CtrlMask);{ XXX avoid _POSIX_VDISABLE }
335        CERASE          =chr( $7F and CtrlMask);
336        CINTR           =chr(ORD('c') and CtrlMask);
337        CSTATUS         =chr(ORD('t') and CtrlMask);
338        CKILL           =chr(ORD('u') and CtrlMask);
339        CMIN            =chr(1);
340        CQUIT           =chr(034  and CtrlMask);        { FS, ^\ }
341        CSUSP           =chr(ORD('z') and CtrlMask);
342        CTIME           =chr(0);
343        CDSUSP          =chr(ORD('y') and CtrlMask);
344        CSTART          =chr(ORD('q') and CtrlMask);
345        CSTOP           =chr(ORD('s') and CtrlMask);
346        CLNEXT          =chr(ORD('v') and CtrlMask);
347        CDISCARD        =chr(ORD('o') and CtrlMask);
348        CWERASE         =chr(ORD('w') and CtrlMask);
349        CREPRINT        =chr(ORD('r') and CtrlMask);
350        CEOT            =CEOF;
351{ compat }
352        CBRK            =CEOL;
353        CRPRNT          =CREPRINT;
354        CFLUSH          =CDISCARD;
355
356
357{
358 *        TTYDEFCHARS to include an array of default control characters.
359}
360    ttydefchars : array[0..NCCS-1] OF char =(
361        CEOF,   CEOL,   CEOL,   CERASE, CWERASE, CKILL, CREPRINT,
362        POSIX_VDISABLE, CINTR,  CQUIT,  CSUSP,  CDSUSP, CSTART, CSTOP,  CLNEXT,
363        CDISCARD, CMIN, CTIME,  CSTATUS, POSIX_VDISABLE);
364
365
366// from /usr/include/sys/iocomm.h
367  { parameter length, at most 13 bits }
368  IOCPARM_MASK = $1fff;
369
370  {  max size of ioctl args  }
371  IOCPARM_MAX = IOCPARM_MASK + 1;
372
373  { no parameters }
374  IOC_VOID = culong($20000000);
375
376  { copy parameters out }
377  IOC_OUT = culong($40000000);
378
379  { copy parameters in }
380  IOC_IN = culong($80000000);
381
382  { copy paramters in and out }
383  IOC_INOUT = (IOC_IN or IOC_OUT);
384
385  { mask for IN/OUT/VOID }
386  IOC_DIRMASK = culong($e0000000);
387
388// from /usr/include/sys/filio.h
389
390  FIOCLEX = (IOC_VOID or (0 and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 1);
391  FIONCLEX = (IOC_VOID or (0 and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 2);
392  FIONREAD = (IOC_OUT or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 127);
393  FIONBIO = (IOC_IN or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 126);
394  FIOASYNC = (IOC_IN or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 125);
395  FIOSETOWN = (IOC_IN or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 124);
396  FIOGETOWN = (IOC_OUT or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 123);
397  FIODTYPE = (IOC_OUT or (sizeof(cint) and IOCPARM_MASK) << 16) or ((ord('f') << 8) or 122);
398