# HG changeset patch # User jwe # Date 863057872 0 # Node ID b779a5b8aed42aa083dcd6fab3c4a1cad6137948 # Parent c05d4e1a9beec9eda68641ba1ddafa29231b2e2e [project @ 1997-05-08 02:14:34 by jwe] diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/ChangeLog Thu May 08 02:17:52 1997 +0000 @@ -1,5 +1,16 @@ +Wed May 7 21:14:06 1997 John W. Eaton + + * oct-syscalls.h, oct-syscalls.cc: New files. + + * cmd-edit.h, cmd-edit.cc: Handle completion function. + + * str-vec.h, str-vec.cc (string_vector::uniq): New function. + Tue May 6 00:52:02 1997 John W. Eaton + * Makefile.in (INCLUDES_FOR_INSTALL): New variable. + (install-inc): Use it. + * file-ops.h, file-ops.cc (tempnam): Add DIR and PREFIX args. Handle errors and missing functions consistently. diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/Makefile.in --- a/liboctave/Makefile.in Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/Makefile.in Thu May 08 02:17:52 1997 +0000 @@ -91,6 +91,8 @@ EXTRAS := mx-inlines.cc +INCLUDES_FOR_INSTALL := $(INCLUDES) $(TEMPLATE_SRC) $(EXTRAS) + DISTFILES := Makefile.in ChangeLog safe-xstat.cin safe-xstat.hin \ $(SOURCES) $(INCLUDES) $(EXTRAS) @@ -198,7 +200,7 @@ install-inc: $(top_srcdir)/mkinstalldirs $(octincludedir) - for f in $(INCLUDES) $(TEMPLATE_SRC) ; do \ + for f in $(INCLUDES_FOR_INSTALL) ; do \ rm -f $(octincludedir)/$$f ; \ $(INSTALL_DATA) $(srcdir)/$$f $(octincludedir)/$$f ; \ done diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/cmd-edit.cc --- a/liboctave/cmd-edit.cc Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/cmd-edit.cc Thu May 08 02:17:52 1997 +0000 @@ -68,6 +68,8 @@ typedef command_editor::fcn fcn; + typedef command_editor::completion_fcn completion_fcn; + gnu_readline (void); ~gnu_readline (void) { } @@ -100,7 +102,9 @@ void do_set_completion_append_character (char c); - void do_set_attempted_completion_function (fcn f); + void do_set_completion_function (completion_fcn f); + + completion_fcn do_get_completion_function (void) const; void do_insert_text (const string& text); @@ -118,12 +122,15 @@ fcn previous_startup_hook; - fcn attempted_completion_function; + completion_fcn completion_function; + + static char *command_generator (const char *text, int state); + + static char **command_completer (char *text, int start, int end); }; gnu_readline::gnu_readline () - : command_editor (), previous_startup_hook (0), - attempted_completion_function (0) + : command_editor (), previous_startup_hook (0), completion_function (0) { rl_initialize (); @@ -263,9 +270,21 @@ } void -gnu_readline::do_set_attempted_completion_function (fcn f) +gnu_readline::do_set_completion_function (completion_fcn f) { - attempted_completion_function = f; + completion_function = f; + + typedef char** (*foo) (...); + + rl_attempted_completion_function + = completion_function + ? static_cast (gnu_readline::command_completer) : 0; +} + +gnu_readline::completion_fcn +gnu_readline::do_get_completion_function (void) const +{ + return completion_function; } void @@ -328,6 +347,35 @@ command_editor::set_startup_hook (command_history::goto_mark); } +char * +gnu_readline::command_generator (const char *text, int state) +{ + char *retval = 0; + + completion_fcn f = command_editor::get_completion_function (); + + string tmp = f (text, state); + + size_t len = tmp.length (); + + if (len > 0) + { + retval = static_cast (malloc (len+1)); + + strcpy (retval, tmp.c_str ()); + } + + return retval; +} + +char ** +gnu_readline::command_completer (char *text, int /* start */, int /* end */) +{ + char **matches = 0; + matches = completion_matches (text, gnu_readline::command_generator); + return matches; +} + #endif class @@ -416,7 +464,7 @@ if (! instance) { - (*current_liboctave_error_handler) + current_liboctave_error_handler ("unable to create command history object!"); retval = false; @@ -548,10 +596,17 @@ } void -command_editor::set_attempted_completion_function (fcn f) +command_editor::set_completion_function (completion_fcn f) { if (instance_ok ()) - instance->do_set_attempted_completion_function (f); + instance->do_set_completion_function (f); +} + +command_editor::completion_fcn +command_editor::get_completion_function (void) +{ + return (instance_ok ()) + ? instance->do_get_completion_function () : 0; } void @@ -834,13 +889,13 @@ void command_editor::error (int err_num) { - (*current_liboctave_error_handler) ("%s", strerror (err_num)); + current_liboctave_error_handler ("%s", strerror (err_num)); } void command_editor::error (const string& s) { - (*current_liboctave_error_handler) ("%s", s.c_str ()); + current_liboctave_error_handler ("%s", s.c_str ()); } /* diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/cmd-edit.h --- a/liboctave/cmd-edit.h Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/cmd-edit.h Thu May 08 02:17:52 1997 +0000 @@ -39,6 +39,8 @@ typedef int (*fcn) (...); + typedef string (*completion_fcn) (const string&, int); + virtual ~command_editor (void) { } static void set_name (const string& n); @@ -69,7 +71,9 @@ static void set_completion_append_character (char c); - static void set_attempted_completion_function (fcn f); + static void set_completion_function (completion_fcn f); + + static completion_fcn get_completion_function (void); static void insert_text (const string& text); @@ -136,7 +140,9 @@ virtual void do_set_completion_append_character (char) { } - virtual void do_set_attempted_completion_function (fcn) { } + virtual void do_set_completion_function (completion_fcn) { } + + virtual completion_fcn do_get_completion_function (void) const { return 0; } virtual void do_insert_text (const string&) = 0; diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/oct-syscalls.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/oct-syscalls.cc Thu May 08 02:17:52 1997 +0000 @@ -0,0 +1,283 @@ +/* + +Copyright (C) 1996, 1997 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_FCNTL_H +#include +#endif + +#include "oct-syscalls.h" +#include "str-vec.h" +#include "syswait.h" + +#define NOT_SUPPORTED(nm) \ + nm ## ": not supported on this system" + +int +octave_syscalls::dup2 (int old_fd, int new_fd) +{ + string msg; + return dup2 (old_fd, new_fd, msg); +} + +int +octave_syscalls::dup2 (int old_fd, int new_fd, string& msg) +{ + msg = string (); + + int status = -1; + +#if defined (HAVE_DUP2) + status = ::dup2 (old_fd, new_fd); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("dup2"); +#endif + + return status; +} + +int +octave_syscalls::execvp (const string& file, const string_vector& argv) +{ + string msg; + return execvp (file, argv, msg); +} + +int +octave_syscalls::execvp (const string& file, const string_vector& args, + string& msg) +{ + msg = string (); + + int status = -1; + +#if defined (HAVE_EXECVP) + char **argv = args.c_str_vec (); + + status = ::execvp (file.c_str (), argv); + + string_vector::delete_c_str_vec (argv); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("execvp"); +#endif + + return status; +} + +int +octave_syscalls::fcntl (int fd, int cmd, long arg) +{ + string msg; + return fcntl (fd, cmd, arg, msg); +} + +int +octave_syscalls::fcntl (int fd, int cmd, long arg, string& msg) +{ + msg = string (); + + int status = -1; + +#if defined (HAVE_FCNTL) + status = ::fcntl (fd, cmd, arg); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("fcntl"); +#endif + + return status; +} + +pid_t +octave_syscalls::fork (string& msg) +{ + pid_t status = -1; + +#if defined (HAVE_FORK) + status = ::fork (); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("fork"); +#endif + + return status; +} + +pid_t +octave_syscalls::getpgrp (string& msg) +{ + pid_t status = -1; + +#if defined (HAVE_GETPGRP) + status = ::getpgrp (); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("getpgrp"); +#endif + + return status; +} + +pid_t +octave_syscalls::getpid (void) +{ +#if defined (HAVE_GETPID) + return ::getpid (); +#else + return 0; +#endif +} + +pid_t +octave_syscalls::getppid (void) +{ +#if defined (HAVE_GETPPID) + return ::getppid (); +#else + return 0; +#endif +} + +gid_t +octave_syscalls::getgid (void) +{ +#if defined (HAVE_GETGID) + return ::getgid (); +#else + return 0; +#endif +} + +gid_t +octave_syscalls::getegid (void) +{ +#if defined (HAVE_GETEGID) + return ::getegid (); +#else + return 0; +#endif +} + +uid_t +octave_syscalls::getuid (void) +{ +#if defined (HAVE_GETUID) + return ::getuid (); +#else + return 0; +#endif +} + +uid_t +octave_syscalls::geteuid (void) +{ +#if defined (HAVE_GETEUID) + return ::geteuid (); +#else + return 0; +#endif +} + +int +octave_syscalls::pipe (int *fildes) +{ + string msg; + return pipe (fildes); +} + +int +octave_syscalls::pipe (int *fildes, string& msg) +{ + msg = string (); + + int status = -1; + +#if defined (HAVE_PIPE) + status = ::pipe (fildes); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("pipe"); +#endif + + return status; +} + +pid_t +octave_syscalls::waitpid (pid_t pid, int options) +{ + string msg; + return waitpid (pid, options, msg); +} + +pid_t +octave_syscalls::waitpid (pid_t pid, int options, string& msg) +{ + msg = string (); + + int status = -1; + +#if defined (HAVE_WAITPID) + status = ::waitpid (pid, 0, options); + + if (status < 0) + msg = ::strerror (errno); +#else + msg = NOT_SUPPORTED ("waitpid"); +#endif + + return status; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/oct-syscalls.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/oct-syscalls.h Thu May 08 02:17:52 1997 +0000 @@ -0,0 +1,72 @@ +/* + +Copyright (C) 1996, 1997 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if !defined (octave_syscalls_h) +#define octave_syscalls_h 1 + +#include + +class string_vector; + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +struct +octave_syscalls +{ + static int dup2 (int, int); + static int dup2 (int, int, string&); + + static int execvp (const string&, const string_vector&); + static int execvp (const string&, const string_vector&, string&); + + static int fcntl (int, int, long); + static int fcntl (int, int, long, string&); + + static pid_t fork (string&); + + static pid_t getpgrp (string&); + + static pid_t getpid (void); + static pid_t getppid (void); + + static gid_t getgid (void); + static gid_t getegid (void); + + static uid_t getuid (void); + static uid_t geteuid (void); + + static int pipe (int *); + static int pipe (int *, string&); + + static pid_t waitpid (pid_t, int); + static pid_t waitpid (pid_t, int, string&); +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/ diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/str-vec.cc --- a/liboctave/str-vec.cc Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/str-vec.cc Thu May 08 02:17:52 1997 +0000 @@ -66,6 +66,27 @@ elem (i) = s[i]; } +string_vector& +string_vector::uniq (void) +{ + int len = length (); + + if (len > 0) + { + int k = 0; + + for (int i = 1; i < len; i++) + if (elem(i) != elem(k)) + if (++k != i) + elem(k) = elem(i); + + if (len != ++k) + resize (k); + } + + return *this; +} + char ** string_vector::c_str_vec (void) const { diff -r c05d4e1a9bee -r b779a5b8aed4 liboctave/str-vec.h --- a/liboctave/str-vec.h Tue May 06 16:40:51 1997 +0000 +++ b/liboctave/str-vec.h Thu May 08 02:17:52 1997 +0000 @@ -58,42 +58,48 @@ string_vector (const char * const *s, int n); string_vector& operator = (const string_vector& s) - { - if (this != &s) - Array::operator = (s); + { + if (this != &s) + Array::operator = (s); - return *this; - } + return *this; + } ~string_vector (void) { } int empty (void) const { return length () == 0; } int max_length (void) const - { - int n = length (); - int longest = 0; + { + int n = length (); + int longest = 0; - for (int i = 0; i < n; i++) - { - int tmp = elem(i).length (); + for (int i = 0; i < n; i++) + { + int tmp = elem(i).length (); - if (tmp > longest) - longest = tmp; - } + if (tmp > longest) + longest = tmp; + } - return longest; - } + return longest; + } string& operator[] (int i) { return Array::elem (i); } string operator[] (int i) const { return Array::elem (i); } - string_vector& qsort (void) - { - Array::qsort (str_vec_compare); - return *this; - } + string_vector& qsort (bool make_unique = false) + { + Array::qsort (str_vec_compare); + + if (make_unique) + uniq (); + + return *this; + } + + string_vector& uniq (void); char **c_str_vec (void) const; diff -r c05d4e1a9bee -r b779a5b8aed4 src/mkops --- a/src/mkops Tue May 06 16:40:51 1997 +0000 +++ b/src/mkops Thu May 08 02:17:52 1997 +0000 @@ -12,7 +12,7 @@ EOF for file in "$@"; do - f=`echo $file | sed 's/^op-//; s/\.cc//; s/-/_/g'` + f=`echo $file | sed 's%^OPERATORS/op-%%; s%\.cc%%; s%-%_%g'` echo "extern void install_${f}_ops (void);" done @@ -26,7 +26,7 @@ EOF for file in "$@"; do - f=`echo $file | sed 's/^op-//; s/\.cc//; s/-/_/g'` + f=`echo $file | sed 's%^OPERATORS/op-%%; s%\.cc%%; s%-%_%g'` echo " install_${f}_ops ();" done