]> git.wh0rd.org Git - nano.git/commitdiff
revert last changes, but disable all the same features that
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Tue, 18 Dec 2007 15:55:48 +0000 (15:55 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Tue, 18 Dec 2007 15:55:48 +0000 (15:55 +0000)
--enable-tiny does when --with-slang is used

git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4204 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
configure.ac
doc/texinfo/nano.texi
src/nano.c
src/nano.h
src/proto.h
src/winio.c

index dda32cd499a15b8b60b8b5a2e700b0dc8bec1231..d345097fdf7f6c81b2c84cc99e70390fc47191db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -46,13 +46,10 @@ CVS code -
          do_statusbar_mouse(), reset_statusbar_cursor(),
          update_statusbar_line(), and
          need_statusbar_horizontal_update(). (DLR)
-       - Simplify terminal handling by using raw mode instead of cbreak
-         mode.  Changes to main(); removal of disable_signals(). (DLR)
-       - Remove slang curses emulation support, as it's hopelessly
-         broken, and it doesn't make the binary very much smaller,
-         especially when --enable-tiny is used.  Changes to
-         configure.ac, doc/texinfo/nano.texi, version(),
-         handle_sigwinch(), terminal_init(), and total_redraw(). (DLR)
+       - Change slang curses emulation support to turn off the same
+         options as --enable-tiny, as it's hopelessly broken otherwise.
+         Changes to configure.ac, doc/texinfo/nano.texi, and
+         terminal_init(). (DLR)
 - chars.c:
   nstrncasecmp(), mbstrncasecmp()
        - For efficiency, return zero immediately if s1 and s2 point to
@@ -99,6 +96,8 @@ CVS code -
          uncutting text with the mark on. (DLR)
   main()
        - Exit if initscr() fails. (DLR)
+       - Simplify terminal handling by using raw mode instead of cbreak
+         mode. (DLR)
 - prompt.c:
   do_yesno_prompt()
        - Remove redundant check for NO_HELP's being FALSE. (DLR)
index f8fe6f818a00984500ff3c907e4970785d94db28..7c8c708fdae3290661179b4d10931beeb1c4a1ac 100644 (file)
@@ -185,6 +185,205 @@ fi],
 [enable_utf8=auto])
 AC_MSG_RESULT($enable_utf8)
 
+AC_MSG_CHECKING([whether to use slang])
+CURSES_LIB_NAME=""
+AC_ARG_WITH(slang,
+[  --with-slang[=DIR]      Use the slang library instead of curses],
+[    case "$with_slang" in
+    no)
+       AC_MSG_RESULT(no)
+       ;;
+    *)
+       AC_MSG_RESULT(yes)
+
+       if test x$with_slang != xyes; then
+           # Add additional search path
+           LDFLAGS="-L$with_slang/lib $LDFLAGS"
+           CPPFLAGS="-I$with_slang/include $CPPFLAGS"
+       fi
+
+       if test x$enable_utf8 != xno; then
+           AC_CHECK_HEADER(slcurses.h,
+               AC_MSG_CHECKING([for SLutf8_enable in -lslang])
+               _libs=$LIBS
+               LIBS="$LIBS -lslang"
+               AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLutf8_enable(1);
+    return 0;
+}],
+                   [AC_MSG_RESULT(yes)
+                   AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                   CURSES_LIB_WIDE=yes
+                   if test x$with_slang != xyes; then
+                       CURSES_LIB="-L${with_slang}/lib -lslang"
+                   else
+                       CURSES_LIB="-lslang"
+                   fi
+                   CURSES_LIB_NAME=slang],
+                   [AC_MSG_RESULT(no)
+
+                   # We might need the term library
+                   for termlib in ncurses curses termcap terminfo termlib; do
+                       AC_CHECK_LIB([${termlib}], tputs, [tcap="-l$termlib"])
+                       test -n "$tcap" && break
+                   done
+
+                   AC_MSG_CHECKING([for SLutf8_enable in -lslang $tcap])
+                   LIBS="$LIBS $tcap"
+                   AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLutf8_enable(1);
+    return 0;
+}],
+                       [AC_MSG_RESULT(yes)
+                       AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                       CURSES_LIB_WIDE=yes
+                       if test x$with_slang != xyes; then
+                           CURSES_LIB="-L${with_slang}/lib -lslang $tcap"
+                       else
+                           CURSES_LIB="-lslang $tcap"
+                       fi
+                       CURSES_LIB_NAME=slang],
+                       [AC_MSG_RESULT(no)
+
+                       # We might need the math library
+                       AC_MSG_CHECKING([for SLutf8_enable in -lslang $tcap -lm])
+                       LIBS="$LIBS -lm"
+                       AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLutf8_enable(1);
+    return 0;
+}],
+                           [AC_MSG_RESULT(yes)
+                           AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                           CURSES_LIB_WIDE=yes
+                           if test x$with_slang != xyes; then
+                               CURSES_LIB="-L${with_slang}/lib -lslang $tcap -lm"
+                           else
+                               CURSES_LIB="-lslang $tcap -lm"
+                           fi
+                           CURSES_LIB_NAME=slang],
+                           [AC_MSG_RESULT(no)],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling]))],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling]))],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling])),
+           AC_MSG_ERROR([
+*** The header file slcurses.h was not found.  If you wish to use
+*** slang support this header file is required.  Please either
+*** install a version of slang that includes the slcurses.h file or
+*** do not call the configure script with --with-slang.]))
+       fi
+
+       if eval "test x$CURSES_LIB_NAME = x"; then
+           # Reset libs if the above slang tests failed
+           if test x$enable_utf8 != xno; then
+               LIBS=$_libs
+           fi
+
+           AC_CHECK_HEADER(slcurses.h,
+               AC_MSG_CHECKING([for SLtt_initialize in -lslang])
+               _libs=$LIBS
+               LIBS="$LIBS -lslang"
+               AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLtt_initialize(NULL);
+    return 0;
+}],
+                   [AC_MSG_RESULT(yes)
+                   AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                   if test x$with_slang != xyes; then
+                       CURSES_LIB="-L${with_slang}/lib -lslang"
+                   else
+                       CURSES_LIB="-lslang"
+                   fi
+                   CURSES_LIB_NAME=slang],
+                   [AC_MSG_RESULT(no)
+
+                   # We might need the term library
+                   for termlib in ncurses curses termcap terminfo termlib; do
+                       AC_CHECK_LIB([${termlib}], tputs, [tcap="-l$termlib"])
+                       test -n "$tcap" && break
+                   done
+
+                   AC_MSG_CHECKING([for SLtt_initialize in -lslang $tcap])
+                   LIBS="$LIBS $tcap"
+                   AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLtt_initialize(NULL);
+    return 0;
+}],
+                       [AC_MSG_RESULT(yes)
+                       AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                       if test x$with_slang != xyes; then
+                           CURSES_LIB="-L${with_slang}/lib -lslang $tcap"
+                       else
+                           CURSES_LIB="-lslang $tcap"
+                       fi
+                       CURSES_LIB_NAME=slang],
+                       [AC_MSG_RESULT(no)
+
+                       # We might need the math library
+                       AC_MSG_CHECKING([for SLtt_initialize in -lslang $tcap -lm])
+                       LIBS="$LIBS -lm"
+                       AC_TRY_RUN([
+#include <slcurses.h>
+int main(void)
+{
+    SLtt_initialize(NULL);
+    return 0;
+}],
+                           [AC_MSG_RESULT(yes)
+                           AC_DEFINE(USE_SLANG, 1, [Define to use the slang wrappers for curses instead of native curses.]) slang_support=yes
+                           if test x$with_slang != xyes; then
+                               CURSES_LIB="-L${with_slang}/lib -lslang $tcap -lm"
+                           else
+                               CURSES_LIB="-lslang $tcap -lm"
+                           fi
+                           CURSES_LIB_NAME=slang],
+                           [AC_MSG_RESULT(no)],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling]))],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling]))],
+    AC_MSG_WARN([*** Can not use slang when cross-compiling])),
+           AC_MSG_ERROR([
+*** The header file slcurses.h was not found.  If you wish to use
+*** slang support this header file is required.  Please either
+*** install a version of slang that includes the slcurses.h file or
+*** do not call the configure script with --with-slang.]))
+       fi
+
+       if test "${_libs+set}" = "set"; then
+           LIBS=$_libs
+       fi
+
+       if test x$with_slang != xyes; then
+           LDFLAGS=${_ldflags}
+       fi
+       ;;
+    esac], [AC_MSG_RESULT(no)])
+
+    if test x$with_slang != xno; then
+       AC_DEFINE(NANO_TINY, 1, [Define this to make the nano executable as small as possible.]) tiny_support=yes
+       AC_DEFINE(DISABLE_BROWSER, 1, [Define this to disable the built-in file browser.])
+       AC_DEFINE(DISABLE_HELP, 1, [Define this to disable the help text display.])
+       AC_DEFINE(DISABLE_JUSTIFY, 1, [Define this to disable the justify routines.])
+       AC_DEFINE(DISABLE_MOUSE, 1, [Define this to disable the mouse functions.])
+       AC_DEFINE(DISABLE_OPERATINGDIR, 1, [Define this to disable the setting of the operating directory (chroot of sorts).])
+       AC_DEFINE(DISABLE_SPELLER, 1, [Define this to disable the spell checker functions.])
+       AC_DEFINE(DISABLE_TABCOMP, 1, [Define to disable the tab completion functions for files and search strings.])
+       AC_DEFINE(DISABLE_WRAPPING, 1, [Define this to disable all text wrapping.])
+    fi
+
 AM_CONDITIONAL(USE_COLOR, test x$color_support = xyes)
 AM_CONDITIONAL(USE_NANORC, test x$nanorc_support = xyes)
 
@@ -278,14 +477,16 @@ else
        AC_MSG_ERROR([
 *** UTF-8 support was requested, but insufficient UTF-8 support was
 *** detected in your curses and/or C libraries.  Please verify that your
-*** curses was built with wide character support, and that your C
-*** library was built with wide character support.])
+*** slang was built with UTF-8 support or your curses was built with
+*** wide character support, and that your C library was built with wide
+*** character support.])
     elif test x$enable_utf8 != xno; then
        AC_MSG_WARN([
 *** Insufficient UTF-8 support was detected in your curses and/or C
-*** libraries.  If you want UTF-8 support, please verify that your
-*** curses was built with wide character support, and that your C
-*** library was built with wide character support.])
+*** libraries.  If you want UTF-8 support, please verify that your slang
+*** was built with UTF-8 support or your curses was built with wide
+*** character support, and that your C library was built with wide
+*** character support.])
     fi
 fi
 
index 847756fb4ad1545224af8f3ca12c2c03517047e3..5cc1f0d18f733503b54b0fd1fbee017dbcd7cbed 100644 (file)
@@ -842,11 +842,15 @@ Disable long line wrapping by default when nano is run as root.
 
 @item --enable-utf8
 Enable support for reading and writing Unicode files.  This will require
-a wide version of curses.
+either a wide version of curses, or a UTF-8-enabled version of Slang.
 
 @item --disable-utf8
 Disable support for reading and writing Unicode files.
 
+@item --with-slang
+Compiling @code{nano} with Slang is supported, and will make the binary
+notably smaller than if compiled with ncurses or other curses libraries.
+
 @end table
 
 @contents
index 439adf72c93ed1fc6fda01b2e2f0d2ddce357def..bf59a14b87e4301818ecd24b8001ece062d2bcec 100644 (file)
@@ -942,6 +942,9 @@ void version(void)
 #endif
 #ifdef ENABLE_UTF8
     printf(" --enable-utf8");
+#endif
+#ifdef USE_SLANG
+    printf(" --with-slang");
 #endif
     printf("\n");
 }
@@ -1141,10 +1144,19 @@ RETSIGTYPE handle_sigwinch(int signal)
     if (filepart != NULL)
        unpartition_filestruct(&filepart);
 
+#ifdef USE_SLANG
+    /* Slang curses emulation brain damage, part 1: If we just do what
+     * curses does here, it'll only work properly if the resize made the
+     * window smaller.  Do what mutt does: Leave and immediately reenter
+     * Slang screen management mode. */
+    SLsmg_reset_smg();
+    SLsmg_init_smg();
+#else
     /* Do the equivalent of what Minimum Profit does: Leave and
      * immediately reenter curses mode. */
     endwin();
     doupdate();
+#endif
 
     /* Restore the terminal to its previous state. */
     terminal_init();
@@ -1244,6 +1256,19 @@ void disable_extended_io(void)
     tcsetattr(0, TCSANOW, &term);
 }
 
+#ifdef USE_SLANG
+/* Disable interpretation of the special control keys in our terminal
+ * settings. */
+void disable_signals(void)
+{
+    struct termios term;
+
+    tcgetattr(0, &term);
+    term.c_lflag &= ~ISIG;
+    tcsetattr(0, TCSANOW, &term);
+}
+#endif
+
 #ifndef NANO_TINY
 /* Enable interpretation of the special control keys in our terminal
  * settings. */
@@ -1289,12 +1314,34 @@ void enable_flow_control(void)
  * control characters. */
 void terminal_init(void)
 {
-    raw();
-    nonl();
-    noecho();
-    disable_extended_io();
-    if (ISSET(PRESERVE))
-       enable_flow_control();
+#ifdef USE_SLANG
+    /* Slang curses emulation brain damage, part 2: Slang doesn't
+     * implement raw(), nonl(), or noecho() properly, so there's no way
+     * to properly reinitialize the terminal using them.  We have to
+     * disable the special control keys using termios, save the terminal
+     * state after the first call, and restore it on subsequent
+     * calls. */
+    static struct termios newterm;
+    static bool newterm_set = FALSE;
+
+    if (!newterm_set) {
+#endif
+
+       raw();
+       nonl();
+       noecho();
+       disable_extended_io();
+       if (ISSET(PRESERVE))
+           enable_flow_control();
+
+#ifdef USE_SLANG
+       disable_signals();
+
+       tcgetattr(0, &newterm);
+       newterm_set = TRUE;
+    } else
+       tcsetattr(0, TCSANOW, &newterm);
+#endif
 }
 
 /* Read in a character, interpret it as a shortcut or toggle if
@@ -1729,8 +1776,12 @@ int main(int argc, char **argv)
        char *locale = setlocale(LC_ALL, "");
 
        if (locale != NULL && (strcasestr(locale, "UTF8") != NULL ||
-               strcasestr(locale, "UTF-8") != NULL))
+               strcasestr(locale, "UTF-8") != NULL)) {
+#ifdef USE_SLANG
+           SLutf8_enable(1);
+#endif
            utf8_init();
+       }
     }
 #else
     setlocale(LC_ALL, "");
index 28b225913ae463c1e6f24e96f4400e697320ad8e..370d6d33b94125783c2ea3fbed0b1c2a1fe41640 100644 (file)
 #define PATH_MAX 4096
 #endif
 
+#ifdef USE_SLANG
+/* Slang support. */
+#include <slcurses.h>
+/* Slang curses emulation brain damage, part 3: Slang doesn't define the
+ * curses equivalents of the Insert or Delete keys. */
+#define KEY_DC SL_KEY_DELETE
+#define KEY_IC SL_KEY_IC
 /* Ncurses support. */
-#ifdef HAVE_NCURSES_H
+#elif defined(HAVE_NCURSES_H)
 #include <ncurses.h>
 #else
 /* Curses support. */
index 055e59dc0a39b2a4e2c14c9669173b56ff2c8eb5..43b8746c6cdfcae188941937fc1532fc392f23cb 100644 (file)
@@ -475,6 +475,9 @@ void allow_pending_sigwinch(bool allow);
 void do_toggle(const toggle *which);
 #endif
 void disable_extended_io(void);
+#ifdef USE_SLANG
+void disable_signals(void);
+#endif
 #ifndef NANO_TINY
 void enable_signals(void);
 #endif
index bf4be4d392f132a0fcb650e74abce7897402b124..b205b1df5c9232592c8ff29e3eac9213ea84f011 100644 (file)
@@ -3167,7 +3167,14 @@ void edit_update(update_type location)
 /* Unconditionally redraw the entire screen. */
 void total_redraw(void)
 {
+#ifdef USE_SLANG
+    /* Slang curses emulation brain damage, part 4: Slang doesn't define
+     * curscr. */
+    SLsmg_touch_screen();
+    SLsmg_refresh();
+#else
     wrefresh(curscr);
+#endif
 }
 
 /* Unconditionally redraw the entire screen, and then refresh it using