]> code.delx.au - gnu-emacs/blobdiff - src/sysdep.c
Add ifdef NS_IMPL_COCOA aound OSX version check (for clang)
[gnu-emacs] / src / sysdep.c
index e5b29205e9650409f8693c88705840802ae04114..c5b3c43ea6dbd71b42726236f57cd986ada23574 100644 (file)
@@ -105,8 +105,8 @@ int _cdecl _getpid (void);
 #include "syssignal.h"
 #include "systime.h"
 
-static void emacs_get_tty (int, struct emacs_tty *);
-static int emacs_set_tty (int, struct emacs_tty *, bool);
+void emacs_get_tty (int, struct emacs_tty *) EXTERNALLY_VISIBLE;
+int emacs_set_tty (int, struct emacs_tty *, bool) EXTERNALLY_VISIBLE;
 
 /* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781.  */
 #ifndef ULLONG_MAX
@@ -222,7 +222,9 @@ discard_tty_input (void)
 void
 stuff_char (char c)
 {
-  if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
+  if (! (FRAMEP (selected_frame)
+        && FRAME_LIVE_P (XFRAME (selected_frame))
+        && FRAME_TERMCAP_P (XFRAME (selected_frame))))
     return;
 
 /* Should perhaps error if in batch mode */
@@ -659,7 +661,29 @@ ignore_sigio (void)
   signal (SIGIO, SIG_IGN);
 #endif
 }
+\f
+#ifndef MSDOS
+/* Block SIGCHLD.  */
+
+void
+block_child_signal (sigset_t *oldset)
+{
+  sigset_t blocked;
+  sigemptyset (&blocked);
+  sigaddset (&blocked, SIGCHLD);
+  sigaddset (&blocked, SIGINT);
+  pthread_sigmask (SIG_BLOCK, &blocked, oldset);
+}
+
+/* Unblock SIGCHLD.  */
+
+void
+unblock_child_signal (sigset_t const *oldset)
+{
+  pthread_sigmask (SIG_SETMASK, oldset, 0);
+}
 
+#endif /* !MSDOS */
 \f
 /* Saving and restoring the process group of Emacs's terminal.  */
 
@@ -755,13 +779,24 @@ widen_foreground_group (int fd)
 
 /* Set *TC to the parameters associated with the terminal FD,
    or clear it if the parameters are not available.  */
-static void
+void
 emacs_get_tty (int fd, struct emacs_tty *settings)
 {
   /* Retrieve the primary parameters - baud rate, character size, etcetera.  */
-#ifndef DOS_NT
-  /* We have those nifty POSIX tcmumbleattr functions.  */
   memset (&settings->main, 0, sizeof (settings->main));
+#ifdef DOS_NT
+#ifdef WINDOWSNT
+  HANDLE h = (HANDLE)_get_osfhandle (fd);
+  DWORD console_mode;
+
+  if (h && h != INVALID_HANDLE_VALUE)
+    {
+      if (GetConsoleMode (h, &console_mode))
+       settings->main = console_mode;
+    }
+#endif /* WINDOWSNT */
+#else  /* !DOS_NT */
+  /* We have those nifty POSIX tcmumbleattr functions.  */
   tcgetattr (fd, &settings->main);
 #endif
 }
@@ -771,11 +806,26 @@ emacs_get_tty (int fd, struct emacs_tty *settings)
    *SETTINGS.  If FLUSHP, discard input.
    Return 0 if all went well, and -1 (setting errno) if anything failed.  */
 
-static int
+int
 emacs_set_tty (int fd, struct emacs_tty *settings, bool flushp)
 {
   /* Set the primary parameters - baud rate, character size, etcetera.  */
-#ifndef DOS_NT
+#ifdef DOS_NT
+#ifdef WINDOWSNT
+  HANDLE h = (HANDLE)_get_osfhandle (fd);
+
+  if (h && h != INVALID_HANDLE_VALUE)
+    {
+      DWORD new_mode;
+
+      /* Assume the handle is open for input.  */
+      if (flushp)
+       FlushConsoleInputBuffer (h);
+      new_mode = settings->main;
+      SetConsoleMode (h, new_mode);
+    }
+#endif /* WINDOWSNT */
+#else  /* !DOS_NT */
   int i;
   /* We have those nifty POSIX tcmumbleattr functions.
      William J. Smith <wjs@wiis.wang.com> writes:
@@ -1116,6 +1166,24 @@ tabs_safe_p (int fd)
   return 0;
 #endif /* DOS_NT */
 }
+
+/* Discard echoing.  */
+
+void
+suppress_echo_on_tty (int fd)
+{
+  struct emacs_tty etty;
+
+  emacs_get_tty (fd, &etty);
+#ifdef DOS_NT
+  /* Set raw input mode.  */
+  etty.main = 0;
+#else
+  etty.main.c_lflag &= ~ICANON;        /* Disable buffering */
+  etty.main.c_lflag &= ~ECHO;  /* Disable echoing */
+#endif /* ! WINDOWSNT */
+  emacs_set_tty (fd, &etty, 0);
+}
 \f
 /* Get terminal size from system.
    Store number of lines into *HEIGHTP and width into *WIDTHP.
@@ -1248,7 +1316,7 @@ reset_sys_modes (struct tty_display_info *tty_out)
       int i;
       tty_turn_off_insert (tty_out);
 
-      for (i = curX (tty_out); i < FrameCols (tty_out) - 1; i++)
+      for (i = cursorX (tty_out); i < FrameCols (tty_out) - 1; i++)
         {
           fputc (' ', tty_out->output);
         }
@@ -1645,10 +1713,7 @@ deliver_fatal_thread_signal (int sig)
 static _Noreturn void
 handle_arith_signal (int sig)
 {
-  sigset_t blocked;
-  sigemptyset (&blocked);
-  sigaddset (&blocked, sig);
-  pthread_sigmask (SIG_UNBLOCK, &blocked, 0);
+  pthread_sigmask (SIG_SETMASK, &empty_mask, 0);
   xsignal0 (Qarith_error);
 }