Back: A Sample Shell Application
Forward: sic_syntax.c
Up: A Sample Shell Application
FastForward: Introducing GNU Libtool
Top: Autoconf, Automake, and Libtool
Contents: Table of Contents
Index: Index
About: About this document

9.3.1 `sic_repl.c'

In `sic_repl.c'(13) there is a loop for reading strings typed by the user, evaluating them and printing the results. GNU readline is ideally suited to this, but it is not always available -- or sometimes people simply may not wish to use it.

With the help of GNU Autotools, it is very easy to cater for building with and without GNU readline. `sic_repl.c' uses this function to read lines of input from the user:

static char *
getline (FILE *in, const char *prompt)
  static char *buf = NULL;        /* Always allocated and freed
                                   from inside this function.  */
  XFREE (buf);

  buf = (char *) readline ((char *) prompt);

  if (buf && *buf)
    add_history (buf);
  return buf;

To make this work, I must write an Autoconf macro which adds an option to `configure', so that when the package is installed, it will use the readline library if `--with-readline' is used:

[  --with-readline         compile with the system readline library],
[if test x"${withval-no}" != xno; then
  AC_CHECK_LIB(readline, readline)
  if test x"${ac_cv_lib_readline_readline}" = xno; then
    AC_MSG_ERROR(libreadline not found)
AM_CONDITIONAL(WITH_READLINE, test x"${with_readline-no}" != xno)

Having put this macro in the file `config/readline.m4', I must also call the new macro (SIC_WITH_READLINE) from `'.

This document was generated by Gary V. Vaughan on February, 8 2006 using texi2html