jehanne: draft termios functions

This commit is contained in:
Giacomo Tesio 2017-09-25 00:14:44 +02:00
parent d094dcaecf
commit 80499253a7
3 changed files with 94 additions and 5 deletions

View File

@ -7,7 +7,8 @@ noinst_LIBRARIES = lib.a
if MAY_SUPPLY_SYSCALLS
extra_objs = syscalls.o libposix_conf.o chown.o getrusage.o ids.o \
chmod.o sigsets.o sigaction.o sigsuspend.o sigwaitinfo.o \
sigtimedwait.o sigwait.o alarm.o sigqueue.o siglongjmp.o
sigtimedwait.o sigwait.o alarm.o sigqueue.o siglongjmp.o \
termios.o
else
extra_objs =
endif
@ -18,7 +19,8 @@ lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \
ids.c chmod.c sigsets.c sigaction.c sigsuspend.c sigwaitinfo.c \
sigtimedwait.c sigwait.c alarm.c sigqueue.c siglongjmp.c
sigtimedwait.c sigwait.c alarm.c sigqueue.c siglongjmp.c \
termios.c
lib_a_DEPENDENCIES = $(extra_objs)
lib_a_CCASFLAGS = $(AM_CCASFLAGS)
lib_a_CFLAGS = $(AM_CFLAGS)

View File

@ -56,7 +56,7 @@ lib_a_AR = $(AR) $(ARFLAGS)
@MAY_SUPPLY_SYSCALLS_TRUE@ ids.o chmod.o sigsets.o sigaction.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ sigsuspend.o sigwaitinfo.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ sigtimedwait.o sigwait.o alarm.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ sigqueue.o siglongjmp.o
@MAY_SUPPLY_SYSCALLS_TRUE@ sigqueue.o siglongjmp.o termios.o
am_lib_a_OBJECTS = lib_a-getenv_r.$(OBJEXT) lib_a-getenv.$(OBJEXT) \
lib_a-malloc.$(OBJEXT) lib_a-mallocr.$(OBJEXT) \
lib_a-free.$(OBJEXT) lib_a-freer.$(OBJEXT) \
@ -184,7 +184,8 @@ noinst_LIBRARIES = lib.a
@MAY_SUPPLY_SYSCALLS_FALSE@extra_objs =
@MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = syscalls.o libposix_conf.o chown.o getrusage.o ids.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ chmod.o sigsets.o sigaction.o sigsuspend.o sigwaitinfo.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ sigtimedwait.o sigwait.o alarm.o sigqueue.o siglongjmp.o
@MAY_SUPPLY_SYSCALLS_TRUE@ sigtimedwait.o sigwait.o alarm.o sigqueue.o siglongjmp.o \
@MAY_SUPPLY_SYSCALLS_TRUE@ termios.o
lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \
calloc.c callocr.c realloc.c reallocr.c environ.c signal.c
@ -192,7 +193,8 @@ lib_a_SOURCES = getenv_r.c getenv.c malloc.c mallocr.c free.c freer.c \
lib_a_LIBADD = $(extra_objs)
EXTRA_lib_a_SOURCES = libposix_conf.c syscalls.c chown.c getrusage.c \
ids.c chmod.c sigsets.c sigaction.c sigsuspend.c sigwaitinfo.c \
sigtimedwait.c sigwait.c alarm.c sigqueue.c siglongjmp.c
sigtimedwait.c sigwait.c alarm.c sigqueue.c siglongjmp.c \
termios.c
lib_a_DEPENDENCIES = $(extra_objs)
lib_a_CCASFLAGS = $(AM_CCASFLAGS)
@ -423,6 +425,12 @@ lib_a-siglongjmp.o: siglongjmp.c
lib_a-siglongjmp.obj: siglongjmp.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-siglongjmp.obj `if test -f 'siglongjmp.c'; then $(CYGPATH_W) 'siglongjmp.c'; else $(CYGPATH_W) '$(srcdir)/siglongjmp.c'; fi`
lib_a-termios.o: termios.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-termios.o `test -f 'termios.c' || echo '$(srcdir)/'`termios.c
lib_a-termios.obj: termios.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-termios.obj `if test -f 'termios.c'; then $(CYGPATH_W) 'termios.c'; else $(CYGPATH_W) '$(srcdir)/termios.c'; fi`
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \

View File

@ -0,0 +1,79 @@
/*
* This file is part of Jehanne.
*
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* Jehanne is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
*/
#include <u.h>
#include <libc.h>
#include <posix.h>
#include <reent.h>
#include <termios.h>
int
tcgetpgrp(int fd)
{
int *errnop = &_REENT->_errno;
return POSIX_tcgetpgrp(errnop, fd);
}
int
tcsetpgrp(int fd, int pgrp)
{
int *errnop = &_REENT->_errno;
return POSIX_tcsetpgrp(errnop, fd, pgrp);
}
#define CESC '\\'
#define CINTR 0177 /* DEL */
#define CQUIT 034 /* FS, cntl | */
#define CERASE 010 /* BS */
#define CKILL 025 /* cntl u */
#define CEOF 04 /* cntl d */
#define CSTART 021 /* cntl q */
#define CSTOP 023 /* cntl s */
#define CSWTCH 032 /* cntl z */
#define CEOL 000
#define CNSWTCH 0
int
tcgetattr(int fd, struct termios *t)
{
int *errnop = &_REENT->_errno;
if(POSIX_isatty(errnop, fd)) {
t->c_iflag = ISTRIP|ICRNL|IXON|IXOFF;
t->c_oflag = OPOST|TAB3|ONLCR;
t->c_cflag = B9600;
t->c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK;
t->c_cc[VINTR] = CINTR;
t->c_cc[VQUIT] = CQUIT;
t->c_cc[VERASE] = CERASE;
t->c_cc[VKILL] = CKILL;
t->c_cc[VEOF] = CEOF;
t->c_cc[VEOL] = CEOL;
t->c_cc[VSTART] = CSTART;
t->c_cc[VSTOP] = CSTOP;
return 0;
}
return -1;
}
int
tcsetattr(int fd, int optactions, const struct termios *t)
{
int *errnop = &_REENT->_errno;
if(POSIX_isatty(errnop, fd))
return 0;
return -1;
}