Mercurial > hg > octave-nkf
changeset 2941:b779a5b8aed4
[project @ 1997-05-08 02:14:34 by jwe]
author | jwe |
---|---|
date | Thu, 08 May 1997 02:17:52 +0000 |
parents | c05d4e1a9bee |
children | 026f342c2019 |
files | liboctave/ChangeLog liboctave/Makefile.in liboctave/cmd-edit.cc liboctave/cmd-edit.h liboctave/oct-syscalls.cc liboctave/oct-syscalls.h liboctave/str-vec.cc liboctave/str-vec.h src/mkops |
diffstat | 9 files changed, 493 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,16 @@ +Wed May 7 21:14:06 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * 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 <jwe@bevo.che.wisc.edu> + * 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.
--- a/liboctave/Makefile.in +++ b/liboctave/Makefile.in @@ -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
--- a/liboctave/cmd-edit.cc +++ b/liboctave/cmd-edit.cc @@ -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<foo> (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<char *> (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 ()); } /*
--- a/liboctave/cmd-edit.h +++ b/liboctave/cmd-edit.h @@ -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;
new file mode 100644 --- /dev/null +++ b/liboctave/oct-syscalls.cc @@ -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 <config.h> +#endif + +#include <cerrno> + +#include <string.h> + +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#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: *** +*/
new file mode 100644 --- /dev/null +++ b/liboctave/oct-syscalls.h @@ -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 <string> + +class string_vector; + +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#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: *** +*/
--- a/liboctave/str-vec.cc +++ b/liboctave/str-vec.cc @@ -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 {
--- a/liboctave/str-vec.h +++ b/liboctave/str-vec.h @@ -58,42 +58,48 @@ string_vector (const char * const *s, int n); string_vector& operator = (const string_vector& s) - { - if (this != &s) - Array<string>::operator = (s); + { + if (this != &s) + Array<string>::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<string>::elem (i); } string operator[] (int i) const { return Array<string>::elem (i); } - string_vector& qsort (void) - { - Array<string>::qsort (str_vec_compare); - return *this; - } + string_vector& qsort (bool make_unique = false) + { + Array<string>::qsort (str_vec_compare); + + if (make_unique) + uniq (); + + return *this; + } + + string_vector& uniq (void); char **c_str_vec (void) const;
--- a/src/mkops +++ b/src/mkops @@ -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