Skip to content

Commit

Permalink
Make readline mandatory (and fix readline flags for macOS GitHub CI)
Browse files Browse the repository at this point in the history
It’s possible to use anything that supplies a basic readline API, e.g.
libedit, so this is not onerous, and allows us to delete some #ifdefs and
some #ifdef’d code for the case where readline is missing.

Also, remove a static buffer.
  • Loading branch information
rrthomas committed Jul 6, 2024
1 parent 32775e9 commit fd075a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 51 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
shell: bash
- os: macos-latest
shell: bash
env:
LDFLAGS: "-L$(brew --prefix readline)/lib"
CPPFLAGS: "-I$(brew --prefix readline)/include"
runs-on: ${{ matrix.os }}
defaults:
run:
Expand All @@ -32,5 +29,7 @@ jobs:
run: |
brew install coreutils readline pkg-config libtool automake gettext macfuse
echo "$(brew --prefix m4)/bin:/usr/local/opt/gettext/bin" >> $GITHUB_PATH
echo "LDFLAGS=-L$(brew --prefix readline)/lib" >> "$GITHUB_ENV"
echo "CPPFLAGS=-I$(brew --prefix readline)/include" >> "$GITHUB_ENV"
- name: Build
run: ./build-aux/build.sh
8 changes: 3 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ AM_GNU_GETTEXT_VERSION([0.19.6])
dnl readline and history for plpftp
MIN_LIBREADLINE_VERSION=4.3
AX_LIB_READLINE([$MIN_LIBREADLINE_VERSION])
if test "$ax_cv_lib_readline_version_ok" != "yes"; then
AC_MSG_ERROR([readline version $MIN_LIBREADLINE_VERSION or later is required])
fi

# FUSE and libattr for plpfuse
PKG_CHECK_MODULES([FUSE], [fuse >= 2.6], [enable_fuse=yes], [enable_fuse=no])
Expand Down Expand Up @@ -196,8 +199,3 @@ AC_CONFIG_FILES(
doc/plpprintd.man
)
AC_OUTPUT

dnl Warn if readline is absent or too old
if test "$ax_cv_lib_readline_version_ok" != "yes"; then
AC_MSG_WARN([To use readline, version $MIN_LIBREADLINE_VERSION or later is required!])
fi
59 changes: 16 additions & 43 deletions plpftp/ftp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@

#include "ftp.h"

#if HAVE_LIBREADLINE
extern "C" {
# if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
# elif defined(HAVE_READLINE_H)
# include <readline.h>
# else /* !defined(HAVE_READLINE_H) */
#if defined(HAVE_READLINE_READLINE_H)
# include <readline/readline.h>
#elif defined(HAVE_READLINE_H)
# include <readline.h>
#else /* !defined(HAVE_READLINE_H) */
extern char *readline ();
# endif /* !defined(HAVE_READLINE_H) */
#endif /* !defined(HAVE_READLINE_H) */
#include <readline/readline.h>
#ifdef HAVE_READLINE_HISTORY
# if defined(HAVE_READLINE_HISTORY_H)
Expand All @@ -72,7 +71,6 @@ extern char *readline ();
# endif /* !defined(HAVE_READLINE_HISTORY_H) */
#endif /* !defined(HAVE_READLINE_HISTORY) */
}
#endif

using namespace std;

Expand Down Expand Up @@ -1424,7 +1422,6 @@ session(rfsv & a, rpcs & r, rclip & rc, ppsocket & rclipSocket, int xargc, char
return a.getStatus();
}

#if HAVE_LIBREADLINE
#define MATCHFUNCTION rl_completion_matches

static const char *all_commands[] = {
Expand Down Expand Up @@ -1520,11 +1517,7 @@ do_completion(const char *text, int start, int end)
rl_completion_append_character = ' ';
rl_attempted_completion_over = 1;
if (start == 0)
{
#if HAVE_LIBREADLINE
matches = MATCHFUNCTION(text, command_generator);
#endif
}
else {
int idx = 0;
const char *name;
Expand Down Expand Up @@ -1552,56 +1545,37 @@ do_completion(const char *text, int start, int end)
maskAttr = rfsv::PSI_A_DIR;
}

#if HAVE_LIBREADLINE
matches = MATCHFUNCTION(text, filename_generator);
#endif
}
return matches;
}
#endif

void ftp::
initReadline(void)
{
#if HAVE_LIBREADLINE
rl_readline_name = "plpftp";
rl_completion_entry_function = null_completion;
rl_attempted_completion_function = do_completion;
rl_basic_word_break_characters = " \t\n\"\\'`@><=;|&{(";
#endif
}

void ftp::
getCommand(int &argc, char **argv)
{
int ws, quote;
static char *buf = NULL;

static char buf[1024];

buf[0] = 0; argc = 0;
while (!strlen(buf) && continueRunning) {
argc = 0;
while (continueRunning) {
signal(SIGINT, sigint_handler2);
#if HAVE_LIBREADLINE
char *bp = readline("> ");
if (!bp) {
strcpy(buf, "bye");
cout << buf << endl;
} else {
strcpy(buf, bp);
#ifdef HAVE_READLINE_HISTORY
free(buf);
buf = readline("> ");
if (!buf)
cout << "bye" << endl;
else {
add_history(buf);
#endif
free(bp);
break;
}
#else
cout << "> ";
cout.flush();
cin.getline(buf, 1023);
if (cin.eof()) {
strcpy(buf, "bye");
cout << buf << endl;
}
#endif
signal(SIGINT, sigint_handler);
}
ws = 1; quote = 0;
Expand All @@ -1620,9 +1594,8 @@ getCommand(int &argc, char **argv)
*p = 0;
break;
default:
if (ws) {
if (ws)
argv[argc++] = p;
}
ws = 0;
}
}

0 comments on commit fd075a1

Please sign in to comment.