From: Nathan Scott Date: Wed, 16 Apr 2003 23:38:03 +0000 (+0000) Subject: Add editline support in for cases where readline is unavailable. X-Git-Tag: XFS-1_3_0pre1~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4b9ebda67cabf50ba9865880403a89e6b4bc3e7;p=thirdparty%2Fxfsprogs-dev.git Add editline support in for cases where readline is unavailable. --- diff --git a/configure.in b/configure.in index b618aca67..646af3f19 100644 --- a/configure.in +++ b/configure.in @@ -166,13 +166,21 @@ AC_ARG_ENABLE(readline, [ --enable-readline=[yes/no] Enable readline command editing [default=no]],, enable_readline=no) if test $enable_readline = yes; then - libreadline="-lreadline -lncurses" -else - libreadline="" + libreadline="-lreadline -ltermcap" fi AC_SUBST(libreadline) AC_SUBST(enable_readline) +dnl will we be making use of editline? +AC_ARG_ENABLE(editline, +[ --enable-editline=[yes/no] Enable editline command editing [default=no]],, + enable_editline=no) +if test $enable_editline = yes; then + libeditline="-ledit -ltermcap" +fi +AC_SUBST(libeditline) +AC_SUBST(enable_editline) + dnl will we be making use of gettext? AC_ARG_ENABLE(gettext, [ --enable-gettext=[yes/no] Enable alternate language support [default=yes]],, diff --git a/db/Makefile b/db/Makefile index b98459d07..1e5b815e4 100644 --- a/db/Makefile +++ b/db/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. +# Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. # # This program is free software; you can redistribute it and/or modify it # under the terms of version 2 of the GNU General Public License as @@ -52,6 +52,11 @@ LLDLIBS += $(LIBREADLINE) CFLAGS += -DENABLE_READLINE endif +ifeq ($(ENABLE_EDITLINE),yes) +LLDLIBS += $(LIBEDITLINE) +CFLAGS += -DENABLE_EDITLINE +endif + default: $(LTCOMMAND) include $(BUILDRULES) diff --git a/db/input.c b/db/input.c index f92b2f095..3d828d924 100644 --- a/db/input.c +++ b/db/input.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. + * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -39,9 +39,11 @@ #include "malloc.h" #include "init.h" -#ifdef ENABLE_READLINE +#if defined(ENABLE_READLINE) # include # include +#elif defined(ENABLE_EDITLINE) +# include #endif int inputstacksize; @@ -147,6 +149,16 @@ doneline( xfree(vec); } +static char * +get_prompt(void) +{ + static char prompt[FILENAME_MAX + 1]; + + if (!prompt[0]) + snprintf(prompt, sizeof(prompt), "%s> ", progname); + return prompt; +} + static char * fetchline_internal(void) { @@ -162,7 +174,7 @@ fetchline_internal(void) if (iscont) dbprintf("... "); else - dbprintf("%s> ", progname); + dbprintf(get_prompt(), progname); fflush(stdin); } if (seenint() || @@ -223,29 +235,57 @@ fetchline_internal(void) char * fetchline(void) { - static char prompt[FILENAME_MAX + 1]; - char *line; - - if (!prompt[0]) - snprintf(prompt, sizeof(prompt), "%s> ", progname); + char *line; if (inputstacksize == 1) { - line = readline(prompt); - if (line && *line) + line = readline(get_prompt()); + if (line && *line) { add_history(line); - else logprintf("%s", line); + } } else { line = fetchline_internal(); } return line; } -#else +#elif defined(ENABLE_EDITLINE) +static char *el_get_prompt(EditLine *e) { return get_prompt(); } char * fetchline(void) -{ - return fetchline_internal(); +{ + static EditLine *el; + static History *hist; + HistEvent hevent; + char *line; + int count; + + if (!el) { + hist = history_init(); + history(hist, &hevent, H_SETSIZE, 100); + el = el_init(progname, stdin, stdout, stderr); + el_source(el, NULL); + el_set(el, EL_SIGNAL, 1); + el_set(el, EL_PROMPT, el_get_prompt); + el_set(el, EL_HIST, history, (const char *)hist); + } + + if (inputstacksize == 1) { + line = xstrdup(el_gets(el, &count)); + if (line) { + if (count > 0) + line[count-1] = '\0'; + if (*line) { + history(hist, &hevent, H_ENTER, line); + logprintf("%s", line); + } + } + } else { + line = fetchline_internal(); + } + return line; } +#else +char * fetchline(void) { return fetchline_internal(); } #endif static void diff --git a/doc/CHANGES b/doc/CHANGES index 5e110964c..08a1e6835 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -2,6 +2,9 @@ xfsprogs-2.4.6 (11 April 2003) - Fix a bug in detection of "clean" and "error" states with MD devices. - Fix configure tests that used AC_PATH_PROG incorrectly. + - Add support for libedit, if libreadline is unavailable. + - Fix the libxfs build on big endian platforms. + - Sync up user/kernel source in libxfs and headers. xfsprogs-2.4.5 (03 April 2003) - Sync up xfs_inode.c in libxfs. diff --git a/include/builddefs.in b/include/builddefs.in index f0c8e95cb..886e07306 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -40,6 +40,7 @@ OPTIMIZER = @opt_build@ MALLOCLIB = @malloc_lib@ LIBUUID = @libuuid@ +LIBEDITLINE = @libeditline@ LIBREADLINE = @libreadline@ LIBXFS = $(TOPDIR)/libxfs/libxfs.la LIBXLOG = $(TOPDIR)/libxlog/libxlog.la @@ -89,6 +90,7 @@ RPM_VERSION = @rpm_version@ ENABLE_SHARED = @enable_shared@ ENABLE_GETTEXT = @enable_gettext@ +ENABLE_EDITLINE = @enable_editline@ ENABLE_READLINE = @enable_readline@ HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@ diff --git a/io/Makefile b/io/Makefile index a069d67d0..e24caeff6 100644 --- a/io/Makefile +++ b/io/Makefile @@ -45,6 +45,11 @@ LLDLIBS += $(LIBREADLINE) CFLAGS += -DENABLE_READLINE endif +ifeq ($(ENABLE_EDITLINE),yes) +LLDLIBS += $(LIBEDITLINE) +CFLAGS += -DENABLE_EDITLINE +endif + default: $(LTCOMMAND) include $(BUILDRULES) diff --git a/io/input.c b/io/input.c index c3d0c01d7..c6263285b 100644 --- a/io/input.c +++ b/io/input.c @@ -34,19 +34,73 @@ #include "input.h" #include "init.h" -#ifdef ENABLE_READLINE +#if defined(ENABLE_READLINE) # include # include +#elif defined(ENABLE_EDITLINE) +# include +#endif + +static char * +get_prompt(void) +{ + static char prompt[FILENAME_MAX + 1]; + + if (!prompt[0]) + snprintf(prompt, sizeof(prompt), "%s> ", progname); + return prompt; +} + +#if defined(ENABLE_READLINE) +char * +fetchline(void) +{ + char *line; + + line = readline(get_prompt()); + if (line && *line) + add_history(line); + return line; +} +#elif defined(ENABLE_EDITLINE) +static char *el_get_prompt(EditLine *e) { return get_prompt(); } +char * +fetchline(void) +{ + static EditLine *el; + static History *hist; + HistEvent hevent; + char *line; + int count; + + if (!el) { + hist = history_init(); + history(hist, &hevent, H_SETSIZE, 100); + el = el_init(progname, stdin, stdout, stderr); + el_source(el, NULL); + el_set(el, EL_SIGNAL, 1); + el_set(el, EL_PROMPT, el_get_prompt); + el_set(el, EL_HIST, history, (const char *)hist); + } + line = strdup(el_gets(el, &count)); + if (line) { + if (count > 0) + line[count-1] = '\0'; + if (*line) + history(hist, &hevent, H_ENTER, line); + } + return line; +} #else # define MAXREADLINESZ 1024 -static char * -readline(char *prompt) +char * +fetchline(void) { char *p, *line = malloc(MAXREADLINESZ); if (!line) return NULL; - printf(prompt); + printf(get_prompt()); fflush(stdout); if (!fgets(line, MAXREADLINESZ, stdin)) { free(line); @@ -57,24 +111,8 @@ readline(char *prompt) p[-1] = '\0'; return line; } -static void add_history(char *line) { } -# undef MAXREADLINESZ #endif -char * -fetchline(void) -{ - static char prompt[FILENAME_MAX + 1]; - char *line; - - if (!prompt[0]) - snprintf(prompt, sizeof(prompt), "%s> ", progname); - line = readline(prompt); - if (line && *line) - add_history(line); - return line; -} - char ** breakline( char *input, diff --git a/libxfs/xfs_inode.c b/libxfs/xfs_inode.c index 5c9e5ad29..538ab6cc3 100644 --- a/libxfs/xfs_inode.c +++ b/libxfs/xfs_inode.c @@ -430,14 +430,12 @@ xfs_iformat_extents( xfs_dinode_t *dip, int whichfork) { + xfs_bmbt_rec_t *ep, *dp; xfs_ifork_t *ifp; int nex; int real_size; int size; -#if ARCH_CONVERT != ARCH_NOCONVERT int i; -#endif - xfs_bmbt_rec_t *ep, *dp; ifp = XFS_IFORK_PTR(ip, whichfork); nex = XFS_DFORK_NEXTENTS_ARCH(dip, whichfork, ARCH_CONVERT); @@ -565,66 +563,69 @@ xfs_iformat_btree( * -ve -> native to disk * arch = on-disk architecture */ - void -xfs_xlate_dinode_core(xfs_caddr_t buf, xfs_dinode_core_t *dip, - int dir, xfs_arch_t arch) +xfs_xlate_dinode_core( + xfs_caddr_t buf, + xfs_dinode_core_t *dip, + int dir, + xfs_arch_t arch) { - xfs_dinode_core_t *buf_core; - xfs_dinode_core_t *mem_core; - - ASSERT(dir); - - buf_core=(xfs_dinode_core_t*)buf; - mem_core=(xfs_dinode_core_t*)dip; + xfs_dinode_core_t *buf_core = (xfs_dinode_core_t *)buf; + xfs_dinode_core_t *mem_core = (xfs_dinode_core_t *)dip; + + ASSERT(dir); + if (arch == ARCH_NOCONVERT) { + if (dir > 0) { + memcpy((xfs_caddr_t)mem_core, (xfs_caddr_t)buf_core, + sizeof(xfs_dinode_core_t)); + } else { + memcpy((xfs_caddr_t)buf_core, (xfs_caddr_t)mem_core, + sizeof(xfs_dinode_core_t)); + } + return; + } - if (arch == ARCH_NOCONVERT) { - if (dir>0) { - memcpy((xfs_caddr_t)mem_core, (xfs_caddr_t)buf_core, sizeof(xfs_dinode_core_t)); + INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch); + INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch); + INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch); + INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch); + INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch); + INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch); + INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch); + INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch); + INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch); + + if (dir > 0) { + memcpy(mem_core->di_pad, buf_core->di_pad, + sizeof(buf_core->di_pad)); } else { - memcpy((xfs_caddr_t)buf_core, (xfs_caddr_t)mem_core, sizeof(xfs_dinode_core_t)); + memcpy(buf_core->di_pad, mem_core->di_pad, + sizeof(buf_core->di_pad)); } - return; - } - - INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch); - INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch); - INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch); - INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch); - INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch); - INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch); - INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch); - INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch); - INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch); - - if (dir>0) { - memcpy(mem_core->di_pad, buf_core->di_pad, sizeof(buf_core->di_pad)); - } else { - memcpy(buf_core->di_pad, mem_core->di_pad, sizeof(buf_core->di_pad)); - } - - INT_XLATE(buf_core->di_atime.t_sec, mem_core->di_atime.t_sec, dir, arch); - INT_XLATE(buf_core->di_atime.t_nsec,mem_core->di_atime.t_nsec, dir, arch); - - INT_XLATE(buf_core->di_mtime.t_sec, mem_core->di_mtime.t_sec, dir, arch); - INT_XLATE(buf_core->di_mtime.t_nsec,mem_core->di_mtime.t_nsec, dir, arch); - - INT_XLATE(buf_core->di_ctime.t_sec, mem_core->di_ctime.t_sec, dir, arch); - INT_XLATE(buf_core->di_ctime.t_nsec,mem_core->di_ctime.t_nsec, dir, arch); - - INT_XLATE(buf_core->di_size, mem_core->di_size, dir, arch); - INT_XLATE(buf_core->di_nblocks, mem_core->di_nblocks, dir, arch); - INT_XLATE(buf_core->di_extsize, mem_core->di_extsize, dir, arch); - - INT_XLATE(buf_core->di_nextents, mem_core->di_nextents, dir, arch); - INT_XLATE(buf_core->di_anextents, mem_core->di_anextents, dir, arch); - INT_XLATE(buf_core->di_forkoff, mem_core->di_forkoff, dir, arch); - INT_XLATE(buf_core->di_aformat, mem_core->di_aformat, dir, arch); - INT_XLATE(buf_core->di_dmevmask, mem_core->di_dmevmask, dir, arch); - INT_XLATE(buf_core->di_dmstate, mem_core->di_dmstate, dir, arch); - INT_XLATE(buf_core->di_flags, mem_core->di_flags, dir, arch); - INT_XLATE(buf_core->di_gen, mem_core->di_gen, dir, arch); + INT_XLATE(buf_core->di_atime.t_sec, mem_core->di_atime.t_sec, + dir, arch); + INT_XLATE(buf_core->di_atime.t_nsec, mem_core->di_atime.t_nsec, + dir, arch); + INT_XLATE(buf_core->di_mtime.t_sec, mem_core->di_mtime.t_sec, + dir, arch); + INT_XLATE(buf_core->di_mtime.t_nsec, mem_core->di_mtime.t_nsec, + dir, arch); + INT_XLATE(buf_core->di_ctime.t_sec, mem_core->di_ctime.t_sec, + dir, arch); + INT_XLATE(buf_core->di_ctime.t_nsec, mem_core->di_ctime.t_nsec, + dir, arch); + INT_XLATE(buf_core->di_size, mem_core->di_size, dir, arch); + INT_XLATE(buf_core->di_nblocks, mem_core->di_nblocks, dir, arch); + INT_XLATE(buf_core->di_extsize, mem_core->di_extsize, dir, arch); + INT_XLATE(buf_core->di_nextents, mem_core->di_nextents, dir, arch); + INT_XLATE(buf_core->di_anextents, mem_core->di_anextents, dir, arch); + INT_XLATE(buf_core->di_forkoff, mem_core->di_forkoff, dir, arch); + INT_XLATE(buf_core->di_aformat, mem_core->di_aformat, dir, arch); + INT_XLATE(buf_core->di_dmevmask, mem_core->di_dmevmask, dir, arch); + INT_XLATE(buf_core->di_dmstate, mem_core->di_dmstate, dir, arch); + INT_XLATE(buf_core->di_flags, mem_core->di_flags, dir, arch); + INT_XLATE(buf_core->di_gen, mem_core->di_gen, dir, arch); } /*