[Nickle] nickle: Branch 'master' - 3 commits

Keith Packard keithp at keithp.com
Fri Apr 21 11:47:29 PDT 2023


 Makefile.am    |    2 --
 builtin-date.c |    2 +-
 configure.ac   |   48 +++++++++++++++++++++++++++++++++++++-----------
 lex.l          |   22 ++++------------------
 main.c         |    2 +-
 5 files changed, 43 insertions(+), 33 deletions(-)

New commits:
commit c9d84b4a8790f9bf7664fd10b592810cf72f429b
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 21 11:45:15 2023 -0700

    Add ctype.h, remove explicit lex func prototypes from lex.l
    
    lex.l uses 'tolower', so it needs ctype.h, which may not be included
    accidentally by other files.
    
    It looks like recent flex versions do declare all of their internal
    functions, so we can get rid of the redundant (and potentially
    incorrect) explicit prototypes.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/lex.l b/lex.l
index 33771fc..376f420 100644
--- a/lex.l
+++ b/lex.l
@@ -9,6 +9,7 @@
 #include	"nickle.h"
 #include	"gram.h"
 #include	"ref.h"
+#include	<ctype.h>
 #include	<strings.h>
 #include	<errno.h>
 #ifdef HAVE_LIBREADLINE
@@ -16,21 +17,6 @@
 #include	HISTORY_H
 #endif
     
-/*
- * Silence gcc by providing prototypes for these functions
- */
-int yyget_lineno (void);
-FILE *yyget_in (void);
-FILE *yyget_out (void);
-int yyget_leng (void);
-char *yyget_text (void);
-void yyset_lineno (int);
-void yyset_in (FILE *);
-void yyset_out (FILE *);
-int yyget_debug (void);
-void yyset_debug (int);
-int yylex_destroy (void);
-
 typedef struct _lexInput {
     DataType		data;
     struct _lexInput	*next;
commit 2d056412969c08e3d121a940f6c74b5e0a8058bc
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 21 11:43:02 2023 -0700

    Remove 'const' attribute when assigning to tm_zone field
    
    Storage management for this field is poorly defined, but all of the
    usage in nickle has well confined lifetimes, so adapt to various
    definitions which may or may not include 'const'.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/builtin-date.c b/builtin-date.c
index 021866e..f29431f 100644
--- a/builtin-date.c
+++ b/builtin-date.c
@@ -121,7 +121,7 @@ from_date(Value date, struct tm *tm)
     tm->tm_gmtoff = value_int(date, "gmtoff", "invalid gmtoff", 0);
 #endif
 #ifdef HAVE_STRUCT_TM_TM_ZONE
-    tm->tm_zone = value_string(date, "zone", "invalid zone", "NONE");
+    tm->tm_zone = (char *) value_string(date, "zone", "invalid zone", "NONE");
 #endif
 }
 
commit 9a0844d6429314639216d360612145ee7dae7594
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 21 11:30:52 2023 -0700

    Allow use of libedit in place of readline
    
    Configure with --with-libedit to select libedit instead of readline
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Makefile.am b/Makefile.am
index 472b99f..3d97551 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -52,8 +52,6 @@ nickle_SOURCES = \
 	builtin-date.c builtin.c builtin.h \
 	builtin-foreign.c gram.y lex.l
 
-nickle_LDFLAGS=$(NICKLE_LDFLAGS)
-
 pkgdata_DATA = $(NICKLEFILES) COPYING
 
 man_MANS = nickle.1
diff --git a/configure.ac b/configure.ac
index bdccb3d..36227af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,12 +60,11 @@ AC_DEFUN([AS_COMPILER_FLAG],
 
 AS_COMPILER_FLAG([-Wl,-E], GCC_EXTERN="yes", GCC_EXTERN="no")
 if test $GCC_EXTERN = yes; then
-	NICKLE_LDFLAGS="-Wl,-E"
+	LDFLAGS="-Wl,-E"
 	AC_DEFINE([HAVE_EXTERN_SYMS], 1, [C compilers can extern program symbols])
 else
-	NICKLE_LDFLAGS=""
+	LDFLAGS=""
 fi
-AC_SUBST(NICKLE_LDFLAGS)
 
 dnl Checks for header files.
 AC_HEADER_STDC
@@ -120,20 +119,47 @@ AC_FUNC_GETPGRP
 dnl Handle large files
 AC_SYS_LARGEFILE
 
-dnl The readline test is complicated enough to rate its own file
-AC_LIB_READLINE
+AC_ARG_WITH(libedit, "use libedit for command line editing", [use_libedit=yes], [use_libedit=no])
+
+case "$use_libedit" in
+ yes)
+   PKG_CHECK_MODULES([LIBEDIT], [libedit])
+   have_libreadline=yes
+   LIBREADLINE_CFLAGS="${LIBEDIT_CFLAGS}"
+   LIBREADLINE_LIBS="${LIBEDIT_LIBS}"
+   READLINE_H="<readline.h>"
+   HISTORY_H="<history.h>"
+   ;;
+ *)
+   AC_LIB_READLINE
+   echo "done checking for readline"
+   if test "x$ac_cv_header_readline_readline_h" = xyes; then
+       have_libreadline=yes
+       READLINE_H="<readline/readline.h>"
+       HISTORY_H="<readline/history.h>"
+    fi
+   ;;
+esac
+
+if test "x$have_libreadline" = "xyes"; then
+
+    AC_DEFINE(HAVE_LIBREADLINE, 1, [Has readline library])
+    AC_DEFINE_UNQUOTED(READLINE_H, ${READLINE_H}, [readline.h include path])
+    AC_DEFINE_UNQUOTED(HISTORY_H, ${HISTORY_H}, [history.h include path])
+
+    CFLAGS="${LIBREADLINE_CFLAGS} ${CFLAGS}"
+    LIBS="${LIBREADLINE_LIBS} ${LIBS}"
 
-if test "x$ac_cv_header_readline_readline_h" = xyes; then
     AC_CHECK_DECL(rl_catch_signals,
-		  AC_DEFINE(HAVE_RL_CATCH_SIGNALS,1,[Has rl_catch_signals]),,[#include <readline/readline.h>])
+		  AC_DEFINE(HAVE_RL_CATCH_SIGNALS,1,[Has rl_catch_signals]),,[#include ${READLINE_H}])
     AC_CHECK_DECL(rl_reset_after_signal,
-		  AC_DEFINE(HAVE_RL_RESET_AFTER_SIGNAL,1,[Has rl_reset_after_signal]),,[#include <readline/readline.h>])
+		  AC_DEFINE(HAVE_RL_RESET_AFTER_SIGNAL,1,[Has rl_reset_after_signal]),,[#include ${READLINE_H}])
     AC_CHECK_DECL(rl_cleanup_after_signal,
-		  AC_DEFINE(HAVE_RL_CLEANUP_AFTER_SIGNAL,1,[Has rl_cleanup_after_signal]),,[#include <readline/readline.h>])
+		  AC_DEFINE(HAVE_RL_CLEANUP_AFTER_SIGNAL,1,[Has rl_cleanup_after_signal]),,[#include ${READLINE_H}])
     AC_CHECK_DECL(rl_echo_signal_char,
-		  AC_DEFINE(HAVE_RL_ECHO_SIGNAL_CHAR,1,[Has rl_echo_signal_char]),,[#include <readline/readline.h>])
+		  AC_DEFINE(HAVE_RL_ECHO_SIGNAL_CHAR,1,[Has rl_echo_signal_char]),,[#include ${READLINE_H}])
     AC_CHECK_DECL(rl_free_line_state,
-		  AC_DEFINE(HAVE_RL_FREE_LINE_STATE,1,[Has rl_free_line_state]),,[#include <readline/readline.h>])
+		  AC_DEFINE(HAVE_RL_FREE_LINE_STATE,1,[Has rl_free_line_state]),,[#include ${READLINE_H}])
 fi
 
 if test "x$prefix" = xNONE; then
diff --git a/lex.l b/lex.l
index 7c8e53b..33771fc 100644
--- a/lex.l
+++ b/lex.l
@@ -12,8 +12,8 @@
 #include	<strings.h>
 #include	<errno.h>
 #ifdef HAVE_LIBREADLINE
-#include	<readline/readline.h>
-#include	<readline/history.h>
+#include	READLINE_H
+#include	HISTORY_H
 #endif
     
 /*
@@ -125,7 +125,7 @@ LexInit (void)
 
 #if HAVE_LIBREADLINE
     rl_getc_function = ReadlineGetChar;
-    rl_prep_term_function = my_prep_terminal;
+    rl_prep_term_function = (void *) my_prep_terminal;
     rl_deprep_term_function = my_deprep_terminal;
     rl_catch_signals = 0;
 #endif
diff --git a/main.c b/main.c
index 85fc70b..0787bee 100644
--- a/main.c
+++ b/main.c
@@ -28,7 +28,7 @@
 #endif
 
 #if HAVE_LIBREADLINE
-#include <readline/readline.h>
+#include READLINE_H
 #endif
 
 int	stdin_interactive;


More information about the Nickle mailing list