/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
*/
#include <curses.priv.h>
-#include <term.h> /* cur_term */
+#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_ttyflags.c,v 1.3 1999/10/22 21:38:55 tom Exp $")
+MODULE_ID("$Id: lib_ttyflags.c,v 1.11 2003/05/17 23:50:37 tom Exp $")
#undef tabs
# endif
#endif
-int _nc_get_tty_mode(TTY *buf)
+NCURSES_EXPORT(int)
+_nc_get_tty_mode(TTY * buf)
{
- if (cur_term == 0
- || GET_TTY(cur_term->Filedes, buf) != 0)
- return(ERR);
- TR(TRACE_BITS,("_nc_get_tty_mode: %s", _nc_tracebits()));
- return (OK);
+ if (cur_term == 0
+ || GET_TTY(cur_term->Filedes, buf) != 0) {
+ memset(buf, 0, sizeof(*buf));
+ return (ERR);
+ }
+ TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
+ cur_term->Filedes, _nc_trace_ttymode(buf)));
+ return (OK);
}
-int _nc_set_tty_mode(TTY *buf)
+NCURSES_EXPORT(int)
+_nc_set_tty_mode(TTY * buf)
{
- if (cur_term == 0
- || SET_TTY(cur_term->Filedes, buf) != 0)
- return(ERR);
- TR(TRACE_BITS,("_nc_set_tty_mode: %s", _nc_tracebits()));
- return (OK);
+ if (cur_term == 0
+ || SET_TTY(cur_term->Filedes, buf) != 0) {
+ if ((errno == ENOTTY) && (SP != 0))
+ SP->_notty = TRUE;
+ return (ERR);
+ }
+ TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
+ cur_term->Filedes, _nc_trace_ttymode(buf)));
+ return (OK);
}
-int def_shell_mode(void)
+NCURSES_EXPORT(int)
+def_shell_mode(void)
{
- T((T_CALLED("def_shell_mode()")));
+ T((T_CALLED("def_shell_mode()")));
- /*
- * Turn off the XTABS bit in the tty structure if it was on. If XTABS
- * was on, remove the tab and backtab capabilities.
- */
+ /*
+ * Turn off the XTABS bit in the tty structure if it was on. If XTABS
+ * was on, remove the tab and backtab capabilities.
+ */
- if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
- returnCode(ERR);
+ if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
+ returnCode(ERR);
#ifdef TERMIOS
- if (cur_term->Ottyb.c_oflag & tabs)
- tab = back_tab = NULL;
+ if (cur_term->Ottyb.c_oflag & tabs)
+ tab = back_tab = NULL;
#else
- if (cur_term->Ottyb.sg_flags & XTABS)
- tab = back_tab = NULL;
+ if (cur_term->Ottyb.sg_flags & XTABS)
+ tab = back_tab = NULL;
#endif
- returnCode(OK);
+ returnCode(OK);
}
-int def_prog_mode(void)
+NCURSES_EXPORT(int)
+def_prog_mode(void)
{
- T((T_CALLED("def_prog_mode()")));
+ T((T_CALLED("def_prog_mode()")));
- if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
- returnCode(ERR);
+ if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
+ returnCode(ERR);
#ifdef TERMIOS
- cur_term->Nttyb.c_oflag &= ~tabs;
+ cur_term->Nttyb.c_oflag &= ~tabs;
#else
- cur_term->Nttyb.sg_flags &= ~XTABS;
+ cur_term->Nttyb.sg_flags &= ~XTABS;
#endif
- returnCode(OK);
+ returnCode(OK);
}
-int reset_prog_mode(void)
+NCURSES_EXPORT(int)
+reset_prog_mode(void)
{
- T((T_CALLED("reset_prog_mode()")));
-
- if (cur_term != 0) {
- _nc_set_tty_mode(&cur_term->Nttyb);
- if (SP) {
- if (stdscr && stdscr->_use_keypad)
- _nc_keypad(TRUE);
- NC_BUFFERED(TRUE);
- }
- returnCode(OK);
+ T((T_CALLED("reset_prog_mode()")));
+
+ if (cur_term != 0) {
+ if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
+ if (SP) {
+ if (SP->_keypad_on)
+ _nc_keypad(TRUE);
+ NC_BUFFERED(TRUE);
+ }
+ returnCode(OK);
}
- returnCode(ERR);
+ }
+ returnCode(ERR);
}
-int reset_shell_mode(void)
+NCURSES_EXPORT(int)
+reset_shell_mode(void)
{
- T((T_CALLED("reset_shell_mode()")));
-
- if (cur_term != 0) {
- if (SP)
- {
- _nc_keypad(FALSE);
- _nc_flush();
- NC_BUFFERED(FALSE);
- }
- returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
+ T((T_CALLED("reset_shell_mode()")));
+
+ if (cur_term != 0) {
+ if (SP) {
+ _nc_keypad(FALSE);
+ _nc_flush();
+ NC_BUFFERED(FALSE);
}
- returnCode(ERR);
+ returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
+ }
+ returnCode(ERR);
}
/*
**
*/
-static TTY buf;
+static TTY buf;
-int savetty(void)
+NCURSES_EXPORT(int)
+savetty(void)
{
- T((T_CALLED("savetty()")));
+ T((T_CALLED("savetty()")));
- returnCode(_nc_get_tty_mode(&buf));
+ returnCode(_nc_get_tty_mode(&buf));
}
-int resetty(void)
+NCURSES_EXPORT(int)
+resetty(void)
{
- T((T_CALLED("resetty()")));
+ T((T_CALLED("resetty()")));
- returnCode(_nc_set_tty_mode(&buf));
+ returnCode(_nc_set_tty_mode(&buf));
}