Andrew,
Thanks for this ... it addresses a long-standing annoyance.
However, apart from the "it only works with flex" issue that I worked
around in a slightly different way, there are some more serious problems
with this patch ...
1. does not honour the -i and -e flags
2. does not handle initial reading from .dbpmdarc if it exists (and the
associated change in prompt)
3. loops forever, i.e. does not exit when ^D read from tty stdin or EOF
encountered on file/pipe stdin
I suspect the readline change really needs to go into dbpmdaFlexInput()
in lex.l and call yypush_buffer_state() and yypop_buffer_state(). This
would also make it easier to localize them to be for flex only.
I also suspect the configure.in changes need rework to handle the
possible (?) case where readline() is in libc, not libreadline ... which
in the previous patch (but not this one) was checked for in
configure.in, but did not set any variables there ... I fixed this by
separating HAVE_READLINE from lib_for_readline.
Once this is clean for Linux (and I'm guessing Solaris is checked out by
you guys) we'll need to be sure it builds cleanly on Windows (no idea if
readline() is there) and Mac OS X (where the shipped readline() is
apparently broken and without a man page, but the current one from GNU
can be installed).
Oh, the joy ...
On Tue, 2010-01-19 at 01:10 +1100, Andrew Wansink wrote:
> Might have another go at this, didn't turn out to be very
> portable.
>
> commit e0fb28877a19404389eb0a168fae0906bca60044
> Author: Andrew Wansink <ajwans@xxxxxxxxxxx>
> Date: Mon Jan 18 18:30:08 2010 +1100
>
> Add readline support to dbpdma.
>
> diff --git a/configure.in b/configure.in
> index 5554437..8f78847 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -1726,6 +1726,38 @@ int main () {
> }
> ], AC_DEFINE(HAVE_STRFTIME_z) AC_MSG_RESULT(yes) , AC_MSG_RESULT(no), 0)
>
> +savedLIBS=$LIBS
> +LIBS=
> +dnl Need flex if we are to get a lexer which can read from a buffer
> +if test $LEX = flex
> +then
> + lib_for_curses=
> + lib_for_readline=
> +
> + dnl first check for readline on its own then with curses
> + AC_CHECK_LIB(readline, readline,,
> + [
> + dnl AC seems to cache lib/func results
> + dnl so use another readline func here
> + AC_CHECK_LIB(readline, add_history,,, [-lcurses])
> + ])
> +
> + if test $ac_cv_lib_readline_readline = yes
> + then
> + lib_for_readline=-lreadline
> + fi
> +
> + if test $ac_cv_lib_readline_add_history = yes
> + then
> + lib_for_curses=-lcurses
> + lib_for_readline=-lreadline
> + fi
> +
> + AC_SUBST(lib_for_readline)
> + AC_SUBST(lib_for_curses)
> +fi
> +LIBS=$savedLIBS
> +
> dnl
> dnl output files
> dnl
> diff --git a/src/dbpmda/src/GNUmakefile b/src/dbpmda/src/GNUmakefile
> index 859177b..700b4ac 100644
> --- a/src/dbpmda/src/GNUmakefile
> +++ b/src/dbpmda/src/GNUmakefile
> @@ -27,7 +27,7 @@ LFILES = lex.l
> YFILES = gram.y
>
> LDIRT = *.log foo.* gram.h $(YFILES:%.y=%.tab.?) $(LFILES:%.l=%.c)
> -LLDLIBS = -lpcp $(LIB_FOR_DLOPEN)
> +LLDLIBS = -lpcp $(LIB_FOR_DLOPEN) $(LIB_FOR_READLINE) $(LIB_FOR_CURSES)
>
> default: $(CMDTARGET)
>
> diff --git a/src/dbpmda/src/dbpmda.c b/src/dbpmda/src/dbpmda.c
> index 1f42ce2..4205453 100644
> --- a/src/dbpmda/src/dbpmda.c
> +++ b/src/dbpmda/src/dbpmda.c
> @@ -21,6 +21,14 @@
> #include "gram.h"
> #include <ctype.h>
>
> +#if HAVE_LIBREADLINE
> +#include <readline/readline.h>
> +#include <readline/history.h>
> +
> +struct yy_buffer_state;
> +
> +#endif
> +
> char *configfile = NULL;
> __pmLogCtl logctl;
> int parse_done = 0;
> @@ -46,6 +54,11 @@ main(int argc, char **argv)
> int errflag = 0;
> char *endnum;
> int i;
> +#if HAVE_LIBREADLINE
> + char *readline_str;
> + char str[1024];
> + struct yy_buffer_state *buf;
> +#endif
>
> __pmSetProgname(argv[0]);
>
> @@ -156,7 +169,23 @@ main(int argc, char **argv)
>
> for ( ; ; ) {
> initmetriclist();
> +
> +#if HAVE_LIBREADLINE
> + readline_str = readline("> ");
> + if (readline_str && *readline_str)
> + add_history(readline_str);
> + /* put back the newline that readline stripped off */
> + sprintf(str, "%s\n", readline_str);
> + buf = yy_scan_string(str);
> + yy_switch_to_buffer(buf);
> +#endif
> +
> yyparse();
> +
> +#if HAVE_LIBREADLINE
> + yy_delete_buffer(buf);
> + free(readline_str);
> +#endif
> if (yywrap()) {
> if (iflag)
> putchar('\n');
> diff --git a/src/include/builddefs.in b/src/include/builddefs.in
> index d934852..d2675e2 100644
> --- a/src/include/builddefs.in
> +++ b/src/include/builddefs.in
> @@ -181,6 +181,8 @@ LIB_FOR_BASENAME = @lib_for_basename@
> LIB_FOR_DLOPEN = @lib_for_dlopen@
> LIB_FOR_REGEX = @lib_for_regex@
> LIB_FOR_MATH = @lib_for_math@
> +LIB_FOR_READLINE = @lib_for_readline@
> +LIB_FOR_CURSES = @lib_for_curses@
>
> SHELL = /bin/sh
> IMAGES_DIR = $(TOPDIR)/all-images
> diff --git a/src/include/platform_defs.h.in b/src/include/platform_defs.h.in
> index 88f39bd..e5948ca 100644
> --- a/src/include/platform_defs.h.in
> +++ b/src/include/platform_defs.h.in
> @@ -137,6 +137,7 @@ extern "C" {
> #undef HAVE_SYS_ENDIAN_H
> #undef HAVE_SYS_MACHINE_H
> #undef HAVE_MACHINE_ENDIAN_H
> +#undef HAVE_LIBREADLINE
>
> #if defined(HAVE_MALLOC_H)
> #include <malloc.h>
>
>
> _______________________________________________
> pcp mailing list
> pcp@xxxxxxxxxxx
> http://oss.sgi.com/mailman/listinfo/pcp
|