* termio unit

This commit is contained in:
marco 2003-11-19 17:11:39 +00:00
parent 5e5462edd1
commit 0610caa107
16 changed files with 95 additions and 303 deletions

View File

@ -338,7 +338,7 @@ uses
{$ifdef VER1_0}
Linux,
{$else}
Unix,
termio,
{$endif}
{$endif Unix}
Systems,Globals,
@ -3603,7 +3603,10 @@ end.
{
$Log$
Revision 1.47 2003-11-17 10:05:51 marco
Revision 1.48 2003-11-19 17:11:39 marco
* termio unit
Revision 1.47 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.46 2003/03/30 12:12:12 armin

View File

@ -27,7 +27,7 @@ uses
linux,
{$else}
baseunix,
unix,
termio,
{$endif}
{$endif}
video,Objects;
@ -783,7 +783,7 @@ begin
'0'..'9' :
begin { running Linux on native console or native-emulation }
FName:='/dev/vcsa' + ThisTTY[9];
TTYFd:={$ifdef ver1_0}fdOpen{$else}fpOpen{$endif}(FName, &666, Open_RdWr); { open console }
TTYFd:={$ifdef ver1_0}fdOpen{$else}fpOpen{$endif}(FName, &666, O_RdWr); { open console }
If TTYFd <>-1 Then
Console:=ttyLinux;
end;
@ -1441,7 +1441,10 @@ end;
end.
{
$Log$
Revision 1.30 2003-11-17 10:05:51 marco
Revision 1.31 2003-11-19 17:11:40 marco
* termio unit
Revision 1.30 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.29 2003/11/14 21:52:58 marco

View File

@ -22,7 +22,7 @@ interface
{$Ifdef ver1_0}
linux;
{$else}
Unix;
termio;
{$endif}
{$endif UNIX}
@ -80,7 +80,10 @@ end.
{
$Log$
Revision 1.5 2002-10-12 19:42:01 hajny
Revision 1.6 2003-11-19 17:11:40 marco
* termio unit
Revision 1.5 2002/10/12 19:42:01 hajny
+ OS/2 support
Revision 1.4 2002/09/07 15:40:48 peter

View File

@ -30,7 +30,7 @@ Uses
linux,
{$else}
baseunix,
unix,
termio,
{$endif}
{$endif}
ncurses;
@ -47,7 +47,10 @@ Begin
End. { of Unit nCrt }
{
$Log$
Revision 1.4 2003-09-27 12:19:20 peter
Revision 1.5 2003-11-19 17:11:40 marco
* termio unit
Revision 1.4 2003/09/27 12:19:20 peter
* fixed for unix
Revision 1.3 2002/09/07 15:43:01 peter

View File

@ -154,7 +154,7 @@ Uses
linux,
{$else}
baseunix,
unix,
termio,
{$endif}
{$endif}
ncurses,panel,menu;
@ -3272,7 +3272,10 @@ End. { of Unit oCrt }
{
$Log$
Revision 1.3 2003-09-27 12:19:20 peter
Revision 1.4 2003-11-19 17:11:40 marco
* termio unit
Revision 1.3 2003/09/27 12:19:20 peter
* fixed for unix
Revision 1.2 2002/09/07 15:43:01 peter

View File

@ -190,6 +190,18 @@ CONST
WUNTRACED = 2; { report status of stopped children }
{ For File control mechanism }
F_GetFd = 1;
F_SetFd = 2;
F_GetFl = 3;
F_SetFl = 4;
F_GetLk = 5;
F_SetLk = 6;
F_SetLkW = 7;
F_SetOwn = 8;
F_GetOwn = 9;
{*************************************************************************}
{ SIGNALS }
@ -202,7 +214,10 @@ CONST
{
$Log$
Revision 1.4 2003-09-14 20:15:01 marco
Revision 1.5 2003-11-19 17:11:40 marco
* termio unit
Revision 1.4 2003/09/14 20:15:01 marco
* Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
Revision 1.3 2003/08/21 22:23:34 olle

View File

@ -81,13 +81,15 @@ function FPsysctlnametomib (Name: pchar; mibp:plongint;sizep:psize_t):cint;
Implementation
Uses Syscall;
{temporarily}
{$ifdef FreeBSD}
CONST syscall_nr___sysctl = 202;
{$endif}
{$I sysnr.inc}
{$I syscallh.inc}
{I sysnr.inc}
{I syscallh.inc}
function FPsysctl (Name: pchar; namelen:cuint; oldp:pointer;oldlenp:psize_t; newp:pointer;newlen:size_t):cint;
@ -138,7 +140,10 @@ end.
{
$Log$
Revision 1.4 2003-01-05 19:01:28 marco
Revision 1.5 2003-11-19 17:11:40 marco
* termio unit
Revision 1.4 2003/01/05 19:01:28 marco
* FreeBSD compiles now with baseunix mods.
Revision 1.3 2002/09/07 16:01:17 peter

View File

@ -1,5 +1,5 @@
#
# Don't edit, this file is generated by FPCMake Version 1.1 [2003/11/18]
# Don't edit, this file is generated by FPCMake Version 1.1 [2003/11/19]
#
default: all
MAKEFILETARGETS=linux go32v2 win32 os2 freebsd beos netbsd amiga atari sunos qnx netware openbsd wdosx palmos macos darwin emx watcom
@ -231,7 +231,7 @@ GRAPHDIR=$(INC)/graph
ifndef USELIBGGI
USELIBGGI=NO
endif
override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings syscall baseunix unixutil unix initc dos dl crt objects printer sysutils typinfo systhrds classes math varutils cpu mmx charset ucomplex getopts heaptrc lineinfo errors sockets gpm ipc terminfo video mouse keyboard console serial variants types sysctl
override TARGET_UNITS+=$(SYSTEMUNIT) objpas strings syscall baseunix unixutil unix initc dos dl termio objects printer sysutils typinfo systhrds classes math varutils cpu mmx charset ucomplex crt getopts heaptrc lineinfo errors sockets gpm ipc terminfo video mouse keyboard console serial variants types sysctl
override TARGET_LOADERS+=prt0 cprt0 gprt0
override TARGET_RSTS+=math varutils typinfo classes variants
override INSTALL_FPCPACKAGE=y y

View File

@ -12,9 +12,9 @@ fpcpackage=y
loaders=prt0 cprt0 gprt0
units=$(SYSTEMUNIT) objpas strings syscall baseunix unixutil \
unix initc \
dos dl crt objects printer \
dos dl termio objects printer \
sysutils typinfo systhrds classes math varutils \
cpu mmx charset ucomplex getopts heaptrc lineinfo \
cpu mmx charset ucomplex crt getopts heaptrc lineinfo \
errors sockets gpm ipc terminfo \
video mouse keyboard console serial variants types sysctl
rsts=math varutils typinfo classes variants

View File

@ -1821,7 +1821,7 @@ function physicalconsole(fd:longint) : boolean;
IMPLEMENTATION
Uses BaseUnix,Unix;
Uses BaseUnix,termio;
function physicalconsole(fd:longint) : boolean;

View File

@ -75,10 +75,10 @@ begin
do_syscall(syscall_nr_gettimeofday,longint(@tv),longint(@tz));
end;
}
Function fdFlush (fd : cint) : cint;
Function fsync (fd : cint) : cint;
begin
fdflush:=do_syscall(syscall_nr_fsync,fd);
fsync:=do_syscall(syscall_nr_fsync,fd);
end;
Function Flock (fd,mode : longint) : cint;
@ -246,7 +246,10 @@ end;
{
$Log$
Revision 1.15 2003-11-19 10:12:02 marco
Revision 1.16 2003-11-19 17:11:40 marco
* termio unit
Revision 1.15 2003/11/19 10:12:02 marco
* more cleanups
Revision 1.14 2003/11/17 10:05:51 marco

View File

@ -111,7 +111,7 @@ procedure CursorOff;
Implementation
uses BaseUnix ,unix;
uses BaseUnix ,unix, termio;
{
The definitions of TextRec and FileRec are in separate files.
@ -1509,10 +1509,10 @@ end;
******************************************************************************}
var
OldIO : Unix.TermIos;
OldIO : termio.TermIos;
inputRaw, outputRaw: boolean;
procedure saveRawSettings(const tio: Unix.termios);
procedure saveRawSettings(const tio: termio.termios);
Begin
with tio do
begin
@ -1527,7 +1527,7 @@ Begin
end;
end;
procedure restoreRawSettings(tio: Unix.termios);
procedure restoreRawSettings(tio: termio.termios);
begin
with tio do
begin
@ -1681,7 +1681,10 @@ Finalization
End.
{
$Log$
Revision 1.14 2003-11-17 10:05:51 marco
Revision 1.15 2003-11-19 17:11:40 marco
* termio unit
Revision 1.14 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.13 2003/09/16 20:52:24 marco

View File

@ -42,7 +42,7 @@ uses
Strings,
TermInfo,
{$endif NotUseTree}
Unix,baseUnix;
termio,baseUnix;
{$i keyboard.inc}
@ -1532,7 +1532,10 @@ begin
end.
{
$Log$
Revision 1.16 2003-11-17 10:05:51 marco
Revision 1.17 2003-11-19 17:11:40 marco
* termio unit
Revision 1.16 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.15 2003/09/16 16:13:56 marco

View File

@ -10,7 +10,7 @@ unit Serial;
interface
uses BaseUnix,Unix;
uses BaseUnix,termio,unix;
type
@ -70,7 +70,7 @@ implementation
function SerOpen(const DeviceName: String): TSerialHandle;
begin
Result := fpopen(DeviceName, OPEN_RDWR or OPEN_NOCTTY);
Result := fpopen(DeviceName, O_RDWR or O_NOCTTY);
end;
procedure SerClose(Handle: TSerialHandle);
@ -215,7 +215,10 @@ end.
{
$Log$
Revision 1.9 2003-11-19 10:54:32 marco
Revision 1.10 2003-11-19 17:11:40 marco
* termio unit
Revision 1.9 2003/11/19 10:54:32 marco
* some simple restructures
Revision 1.8 2003/09/14 20:15:01 marco

View File

@ -24,7 +24,7 @@ Uses UnixUtil,BaseUnix;
{Get error numbers, some more signal definitions and other OS dependant
types (that are not POSIX) }
{$i errno.inc}
{i errno.inc}
{$I signal.inc}
{$i ostypes.inc}
@ -51,13 +51,6 @@ Type
next : pglob;
end;
{********************
IOCtl(TermIOS)
********************}
{Is too freebsd/Linux specific}
{$I termios.inc}
{******************************************************************************
Procedure/Functions
@ -156,25 +149,6 @@ Function GetDomainName:String;
Function GetHostName:String;
{$endif}
{**************************
IOCtl/Termios Functions
***************************}
Function TCGetAttr (fd:cint;var tios:TermIOS):cint;
Function TCSetAttr (fd:cint;OptAct:cint;const tios:TermIOS):cint;
Procedure CFSetISpeed (var tios:TermIOS;speed:Cardinal);
Procedure CFSetOSpeed (var tios:TermIOS;speed:Cardinal);
Procedure CFMakeRaw (var tios:TermIOS);
Function TCSendBreak (fd,duration:cint):cint;
Function TCSetPGrp (fd,id:cint) :cint;
Function TCGetPGrp (fd:cint;var id:cint):cint;
Function TCFlush (fd,qsel:cint):cint;
Function TCDrain (fd:cint) :cint;
Function TCFlow (fd,act:cint) :cint;
Function IsATTY (Handle:cint) :cint;
Function IsATTY (var f:text) :cint;
function TTYname (Handle:cint):string;
function TTYname (var F:Text) :string;
{**************************
Memory functions
@ -1230,241 +1204,6 @@ begin
fpKill(fpGetPid,Sig);
end;
{******************************************************************************
IOCtl and Termios calls
******************************************************************************}
Function TCGetAttr(fd:cint;var tios:TermIOS):cint;
begin
{$ifndef BSD}
TCGetAttr:=fpIOCtl(fd,TCGETS,@tios);
{$else}
TCGETAttr:=fpIoCtl(Fd,TIOCGETA,@tios);
{$endif}
end;
Function TCSetAttr(fd:cint;OptAct:cint;const tios:TermIOS):cint;
var
nr:cint;
begin
{$ifndef BSD}
case OptAct of
TCSANOW : nr:=TCSETS;
TCSADRAIN : nr:=TCSETSW;
TCSAFLUSH : nr:=TCSETSF;
{$else}
case OptAct of
TCSANOW : nr:=TIOCSETA;
TCSADRAIN : nr:=TIOCSETAW;
TCSAFLUSH : nr:=TIOCSETAF;
{$endif}
else
begin
fpsetErrNo(ESysEINVAL);
TCSetAttr:=-1;
exit;
end;
end;
TCSetAttr:=fpIOCtl(fd,nr,@Tios);
end;
Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
begin
{$ifndef BSD}
tios.c_cflag:=(tios.c_cflag and (not CBAUD)) or speed;
{$else}
tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
{$endif}
end;
Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
begin
{$ifndef BSD}
CFSetISpeed(tios,speed);
{$else}
tios.c_ospeed:=speed;
{$endif}
end;
Procedure CFMakeRaw(var tios:TermIOS);
begin
{$ifndef BSD}
with tios do
begin
c_iflag:=c_iflag and (not (IGNBRK or BRKINT or PARMRK or ISTRIP or
INLCR or IGNCR or ICRNL or IXON));
c_oflag:=c_oflag and (not OPOST);
c_lflag:=c_lflag and (not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or CS8;
end;
{$else}
with tios do
begin
c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
IGNPAR));
c_iflag:=c_iflag OR IGNBRK;
c_oflag:=c_oflag and (not OPOST);
c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
c_cc[VMIN]:=1;
c_cc[VTIME]:=0;
end;
{$endif}
end;
Function TCSendBreak(fd,duration:cint):cint;
begin
{$ifndef BSD}
TCSendBreak:=fpIOCtl(fd,TCSBRK,pointer(duration));
{$else}
TCSendBreak:=fpIOCtl(fd,TIOCSBRK,0);
{$endif}
end;
Function TCSetPGrp(fd,id:cint):cint;
begin
TCSetPGrp:=fpIOCtl(fd,TIOCSPGRP,pointer(id));
end;
Function TCGetPGrp(fd:cint;var id:cint):cint;
begin
TCGetPGrp:=fpIOCtl(fd,TIOCGPGRP,@id);
end;
Function TCDrain(fd:cint):cint;
begin
{$ifndef BSD}
TCDrain:=fpIOCtl(fd,TCSBRK,pointer(1));
{$else}
TCDrain:=fpIOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
{$endif}
end;
Function TCFlow(fd,act:cint):cint;
begin
{$ifndef BSD}
TCFlow:=fpIOCtl(fd,TCXONC,pointer(act));
{$else}
case act OF
TCOOFF : TCFlow:=fpIoctl(fd,TIOCSTOP,0);
TCOOn : TCFlow:=fpIOctl(Fd,TIOCStart,0);
TCIOFF : {N/I}
end;
{$endif}
end;
Function TCFlush(fd,qsel:cint):cint;
begin
{$ifndef BSD}
TCFlush:=fpIOCtl(fd,TCFLSH,pointer(qsel));
{$else}
TCFlush:=fpIOCtl(fd,TIOCFLUSH,pointer(qsel));
{$endif}
end;
Function IsATTY (Handle:cint):cint;
{
Check if the filehandle described by 'handle' is a TTY (Terminal)
}
var
t : Termios;
begin
IsAtty:=TCGetAttr(Handle,t);
end;
Function IsATTY(var f: text):cint;
{
Idem as previous, only now for text variables.
}
begin
IsATTY:=IsaTTY(textrec(f).handle);
end;
function TTYName(Handle:cint):string;
{
Return the name of the current tty described by handle f.
returns empty string in case of an error.
}
var
mydev : dev_t;
myino : ino_t;
st : stat;
function mysearch(n:string): boolean;
{searches recursively for the device in the directory given by n,
returns true if found and sets the name of the device in ttyname}
var dirstream : pdir;
d : pdirent;
name : string;
st : stat;
begin
dirstream:=fpopendir(n);
if (dirstream=nil) then
exit(false);
d:=fpReaddir(dirstream^);
while (d<>nil) do
begin
name:=n+'/'+strpas(@(d^.d_name));
// fpstat(name,st);
if fpstat(name,st)=0 then
begin
if (fpS_ISDIR(st.st_mode)) and { if it is a directory }
(strpas(@(d^.d_name))<>'.') and { but not ., .. and fd subdirs }
(strpas(@(d^.d_name))<>'..') and
(strpas(@(d^.d_name))<>'') and
(strpas(@(d^.d_name))<>'fd') then
begin {we found a directory, search inside it}
if mysearch(name) then
begin {the device is here}
fpclosedir(dirstream^); {then don't continue searching}
mysearch:=true;
exit;
end;
end
else if (ino_t(d^.d_fileno)=myino) and (st.st_dev=mydev) then
begin
fpclosedir(dirstream^);
ttyname:=name;
mysearch:=true;
exit;
end;
end;
d:=fpReaddir(dirstream^);
end;
fpclosedir(dirstream^);
mysearch:=false;
end;
begin
TTYName:='';
if (fpfstat(handle,st)=-1) and (isatty (handle)<>-1) then
exit;
mydev:=st.st_dev;
myino:=st.st_ino;
mysearch('/dev');
end;
function TTYName(var F:Text):string;
{
Idem as previous, only now for text variables;
}
begin
TTYName:=TTYName(textrec(f).handle);
end;
{******************************************************************************
Utility calls
@ -1641,7 +1380,10 @@ End.
{
$Log$
Revision 1.50 2003-11-19 10:54:32 marco
Revision 1.51 2003-11-19 17:11:40 marco
* termio unit
Revision 1.50 2003/11/19 10:54:32 marco
* some simple restructures
Revision 1.49 2003/11/17 11:28:08 marco

View File

@ -23,7 +23,7 @@ interface
implementation
uses
BaseUnix, Unix, Strings, TermInfo;
BaseUnix, Strings, TermInfo, termio;
{$i video.inc}
@ -534,10 +534,10 @@ begin
end;
var
InitialVideoTio, preInitVideoTio, postInitVideoTio: Unix.termios;
InitialVideoTio, preInitVideoTio, postInitVideoTio: termio.termios;
inputRaw, outputRaw: boolean;
procedure saveRawSettings(const tio: Unix.termios);
procedure saveRawSettings(const tio: termio.termios);
Begin
with tio do
begin
@ -552,7 +552,7 @@ Begin
end;
end;
procedure restoreRawSettings(tio: Unix.termios);
procedure restoreRawSettings(tio: termio.termios);
begin
with tio do
begin
@ -596,7 +596,7 @@ end;
procedure prepareDoneVideo;
var
tio: Unix.termios;
tio: termio.termios;
begin
TCGetAttr(1,tio);
saveRawSettings(tio);
@ -641,7 +641,7 @@ begin
Case ThisTTY[9] of
'0'..'9' : begin { running Linux on native console or native-emulation }
FName:='/dev/vcsa' + ThisTTY[9];
TTYFd:=fpOpen(FName, &666, Open_RdWr); { open console }
TTYFd:=fpOpen(FName, &666, O_RdWr); { open console }
IF TTYFd <>-1 Then
Console:=ttyLinux;
end;
@ -898,7 +898,10 @@ initialization
end.
{
$Log$
Revision 1.19 2003-11-17 10:05:51 marco
Revision 1.20 2003-11-19 17:11:40 marco
* termio unit
Revision 1.19 2003/11/17 10:05:51 marco
* threads for FreeBSD. Not working tho
Revision 1.18 2003/10/26 15:32:25 marco