diff --git a/EcConsole.m b/EcConsole.m index 037ac6d..78200f9 100644 --- a/EcConsole.m +++ b/EcConsole.m @@ -32,10 +32,11 @@ #import "EcProcess.h" #import "NSFileHandle+Printf.h" -#include +#import "config.h" -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) # include +# include # include # include #endif @@ -70,7 +71,11 @@ static BOOL commandIsRepeat (NSString *string) int pos; } - (void) connectionBecameInvalid: (NSNotification*)notification; -#if !WITH_READLINE +#if defined(HAVE_LIBREADLINE) +- (void) activateReadline; +- (void) deactivateReadline; +- (void) setupConnection; +#else - (void) didRead: (NSNotification*)notification; #endif - (void) didWrite: (NSNotification*)notification; @@ -92,7 +97,7 @@ static BOOL commandIsRepeat (NSString *string) { [ochan puts: @"\nExiting\n"]; -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) [self deactivateReadline]; #endif @@ -182,11 +187,11 @@ static BOOL commandIsRepeat (NSString *string) extra: (void*)extra forMode: (NSString*)mode { -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) rl_callback_read_char(); #else NSLog(@"ERROR: this should not get called w/o readline: %s", - __PRETTY_FUNCTION__); + __PRETTY_FUNCTION__); #endif } @@ -223,7 +228,7 @@ static BOOL commandIsRepeat (NSString *string) [arp release]; } -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) - (char **)complete:(const char *)_text range:(NSRange)_range { @@ -232,7 +237,7 @@ static BOOL commandIsRepeat (NSString *string) #endif -#if !WITH_READLINE +#if !defined(HAVE_LIBREADLINE) - (void) didRead: (NSNotification*)notification { NSDictionary *userInfo = [notification userInfo]; @@ -471,7 +476,7 @@ static BOOL commandIsRepeat (NSString *string) return; } -#if !WITH_READLINE +#if !defined(HAVE_LIBREADLINE) if (user == nil) { if ([cmd length] > 0) @@ -556,7 +561,7 @@ static BOOL commandIsRepeat (NSString *string) } } else -#endif /* WITH_READLINE */ +#endif /* defined(HAVE_LIBREADLINE) */ if (commandIsRepeat(cmd)) { if (pastWords == nil) @@ -712,7 +717,7 @@ static BOOL commandIsRepeat (NSString *string) ichan = [[NSFileHandle fileHandleWithStandardInput] retain]; ochan = [[NSFileHandle fileHandleWithStandardOutput] retain]; -#if !WITH_READLINE +#if !defined(HAVE_LIBREADLINE) [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(didRead:) name: NSFileHandleReadCompletionNotification @@ -728,7 +733,7 @@ static BOOL commandIsRepeat (NSString *string) { NSRunLoop *loop; -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) [self setupConnection]; [self activateReadline]; #endif @@ -742,7 +747,7 @@ static BOOL commandIsRepeat (NSString *string) } } -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) [self deactivateReadline]; #endif return 0; @@ -755,10 +760,10 @@ static BOOL commandIsRepeat (NSString *string) /* readline handling */ -#if WITH_READLINE +#if defined(HAVE_LIBREADLINE) /* readline callbacks have no context, so we need this one ... */ -static Console *rlConsole = nil; +static EcConsole *rlConsole = nil; static void readlineReadALine(char *_line) { @@ -779,7 +784,8 @@ static char **consoleCompleter(const char *text, int start, int end) return [rlConsole complete:text range:NSMakeRange(start, end - start)]; } -- (void)activateReadline { +- (void) activateReadline +{ rlConsole = self; /* setup readline */ @@ -798,7 +804,7 @@ static char **consoleCompleter(const char *text, int start, int end) forMode: NSDefaultRunLoopMode]; } -- (void)deactivateReadline +- (void) deactivateReadline { [[NSRunLoop currentRunLoop] removeEvent: (void*)(uintptr_t)0 type: ET_RDESC @@ -809,7 +815,7 @@ static char **consoleCompleter(const char *text, int start, int end) rlConsole = nil; } -- (void) setupConnectionr +- (void) setupConnection { while (self->server == nil) { @@ -906,6 +912,6 @@ static char **consoleCompleter(const char *text, int start, int end) } } -#endif /* WITH_READLINE */ +#endif /* defined(HAVE_LIBREADLINE) */ @end diff --git a/GNUmakefile b/GNUmakefile index 7df8c9f..56ca0ea 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -28,7 +28,7 @@ Ec_INTERFACE_VERSION=0.1 NEEDS_GUI=NO # The libraries to be compiled -LIBRARY_NAME = ECCL EcTools +LIBRARY_NAME = ECCL # The Objective-C source files to be compiled ECCL_OBJC_FILES = \ @@ -53,13 +53,6 @@ ECCL_HEADER_FILES = \ EcProcess.h \ EcUserDefaults.h \ -EcTools_OBJC_FILES = \ - EcCommand.m \ - EcConsole.m \ - EcControl.m \ - EcClientI.m \ - NSFileHandle+Printf.m \ - TOOL_NAME = \ Command \ @@ -67,16 +60,16 @@ TOOL_NAME = \ Control \ -Command_OBJC_FILES = Command.m -Command_TOOL_LIBS += -lECCL -lEcTools +Command_OBJC_FILES = Command.m EcCommand.m EcClientI.m NSFileHandle+Printf.m +Command_TOOL_LIBS += -lECCL Command_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR) -Console_OBJC_FILES = Console.m -Console_TOOL_LIBS += -lECCL -lEcTools +Console_OBJC_FILES = Console.m EcConsole.m NSFileHandle+Printf.m +Console_TOOL_LIBS += -lECCL Console_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR) -Control_OBJC_FILES = Control.m -Control_TOOL_LIBS += -lECCL -lEcTools +Control_OBJC_FILES = Control.m EcControl.m EcClientI.m NSFileHandle+Printf.m +Control_TOOL_LIBS += -lECCL Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR) diff --git a/config.h b/config.h index 10b1e52..288b62a 100644 --- a/config.h +++ b/config.h @@ -1,5 +1,5 @@ /* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.in by autoheader. */ +/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to the type of elements in the array set by `getgroups'. Usually this is either `int' or `gid_t'. */ @@ -20,6 +20,9 @@ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 +/* Define if you have libreadline */ +#define HAVE_LIBREADLINE 1 + /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 diff --git a/config.h.in b/config.h.in index df36938..afce74a 100644 --- a/config.h.in +++ b/config.h.in @@ -1,4 +1,4 @@ -/* config.h.in. Generated from configure.in by autoheader. */ +/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to the type of elements in the array set by `getgroups'. Usually this is either `int' or `gid_t'. */ @@ -19,6 +19,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define if you have libreadline */ +#undef HAVE_LIBREADLINE + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H diff --git a/config.make.in b/config.make.in index e69de29..b06f10a 100644 --- a/config.make.in +++ b/config.make.in @@ -0,0 +1,3 @@ + +Console_TOOL_LIBS += @LIBREADLINE@ + diff --git a/configure b/configure index c02ec7a..458fa7a 100755 --- a/configure +++ b/configure @@ -637,6 +637,7 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS LIBOBJS +LIBREADLINE EGREP GREP host_os @@ -695,6 +696,7 @@ SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking +with_readline ' ac_precious_vars='build_alias host_alias @@ -1324,6 +1326,11 @@ if test -n "$ac_init_help"; then cat <<\_ACEOF +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-readline support fancy command line editing [default=check] + Some influential environment variables: CC C compiler command CFLAGS C compiler flags @@ -4204,6 +4211,101 @@ fi done + +# Check whether --with-readline was given. +if test "${with_readline+set}" = set; then + withval=$with_readline; +else + with_readline=no +fi + + +LIBREADLINE= + if test "x$with_readline" = xyes; then + { $as_echo "$as_me:$LINENO: checking for main in -lreadline" >&5 +$as_echo_n "checking for main in -lreadline... " >&6; } +if test "${ac_cv_lib_readline_main+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lreadline -lncurses $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +return main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then + ac_cv_lib_readline_main=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_lib_readline_main=no +fi + +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_readline_main" >&5 +$as_echo "$ac_cv_lib_readline_main" >&6; } +if test "x$ac_cv_lib_readline_main" = x""yes; then + LIBREADLINE="-lreadline -lncurses" + + +cat >>confdefs.h <<\_ACEOF +#define HAVE_LIBREADLINE 1 +_ACEOF + + +else + if test "x$with_readline" != xcheck; then + { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ { $as_echo "$as_me:$LINENO: error: --with-readline was given, but test for readline failed +See \`config.log' for more details." >&5 +$as_echo "$as_me: error: --with-readline was given, but test for readline failed +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; }; } + fi + +fi + +fi + + ac_config_files="$ac_config_files config.make" cat >confcache <<\_ACEOF @@ -5445,3 +5547,4 @@ $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..675a852 --- /dev/null +++ b/configure.ac @@ -0,0 +1,45 @@ +dnl Process this file with autoconf to produce configure. + +AC_INIT(EcProcess.h) +AC_CONFIG_HEADER(config.h) +AC_PROG_CC +AC_PROG_CPP + +AC_CANONICAL_HOST + +dnl start proper config checks +AC_TYPE_SIGNAL + +AC_HEADER_STDC +AC_HEADER_TIME +AC_HEADER_SYS_WAIT +AC_CHECK_HEADERS(arpa/inet.h arpa/telnet.h netinet/in.h netdb.h pwd.h string.h fcntl.h sys/fcntl.h sys/file.h sys/resource.h sys/time.h sys/types.h sys/socket.h sys/signal.h stdlib.h unistd.h) + +AC_TYPE_GETGROUPS +AC_TYPE_SIGNAL +AC_TYPE_MODE_T + +AC_CHECK_FUNCS(getpid setpgid) + +AC_ARG_WITH([readline], + [AS_HELP_STRING([--with-readline], + [support fancy command line editing @<:@default=check@:>@])], + [], + [with_readline=no]) + +LIBREADLINE= + AS_IF([test "x$with_readline" = xyes], + [AC_CHECK_LIB([readline], [main], + [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"]) + AC_DEFINE([HAVE_LIBREADLINE], [1], + [Define if you have libreadline]) + ], + [if test "x$with_readline" != xcheck; then + AC_MSG_FAILURE( + [--with-readline was given, but test for readline failed]) + fi + ], -lncurses)]) + +AC_OUTPUT(config.make) + + diff --git a/configure.in b/configure.in deleted file mode 100644 index 2719a7e..0000000 --- a/configure.in +++ /dev/null @@ -1,25 +0,0 @@ -dnl Process this file with autoconf to produce configure. - -AC_INIT(EcProcess.h) -AC_CONFIG_HEADER(config.h) -AC_PROG_CC -AC_PROG_CPP - -AC_CANONICAL_HOST - -dnl start proper config checks -AC_TYPE_SIGNAL - -AC_HEADER_STDC -AC_HEADER_TIME -AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS(arpa/inet.h arpa/telnet.h netinet/in.h netdb.h pwd.h string.h fcntl.h sys/fcntl.h sys/file.h sys/resource.h sys/time.h sys/types.h sys/socket.h sys/signal.h stdlib.h unistd.h) - -AC_TYPE_GETGROUPS -AC_TYPE_SIGNAL -AC_TYPE_MODE_T - -AC_CHECK_FUNCS(getpid setpgid) - -AC_OUTPUT(config.make) -