Mercurial > hg > octave-shane
changeset 2944:e9c24f32f175
[project @ 1997-05-08 02:42:22 by jwe]
author | jwe |
---|---|
date | Thu, 08 May 1997 02:42:41 +0000 |
parents | e6dfc3ea6299 |
children | 3ca5a67dcf55 |
files | NEWS PROJECTS doc/interpreter/func.texi src/ChangeLog src/Makefile.in src/input.cc |
diffstat | 6 files changed, 84 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -84,6 +84,25 @@ defines a function that returns the number of times that it has been called. + * Within user-defined functions, the new automatic variable `argn' + contains the names of the arguments that were passed to the + function. For example, + + function f (...) + for i = 1:nargin + stdout << "argn(" << i << ") = `" << deblank (argn(i,:)) \ + << "' and its value is " << va_arg () << "\n"; + endfor + endfunction + f (1+2, "foo", sin (pi/2)) + + prints + + argn(1) = `1 + 2' and its value is 3 + argn(2) = `"foo"' and its value is foo + argn(3) = `sin (pi)' and its value is 1 + + on the standard output stream. If nargin is zero, argn is not defined. * Functions like quad, fsolve, and lsode can take either a function name or a simple function body as a string. For example,
--- a/PROJECTS +++ b/PROJECTS @@ -314,9 +314,6 @@ corresponding to the first argument if the number of requested points is 1. - * Make it possible to get the names of the arguments that are passed - to functions, at least if simple variables are passed. - * Consider allowing an arbitrary property list to be attached to any variable. This could be a more general way to handle the help string that can currently be added with `document'.
--- a/doc/interpreter/func.texi +++ b/doc/interpreter/func.texi @@ -408,6 +408,7 @@ function foo (heading, ...) disp (heading); va_start (); + ## Pre-decrement to skip `heading' arg. while (--nargin) disp (va_arg ()); endwhile
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,34 @@ +Wed May 7 21:17:00 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + + * input.cc (generate_completion): Rename from command_generator. + Use string objects instead of char*. + (generate_possible_completions): Let qsort also make matches unique. + (initialize_command_input): Register generate_completion with the + command_editor class. + (completion_matches): Simplify using generate_completion. + + * pt-pr-code.cc (tree_print_code::visit_constant): For val, call + print_raw, not print. + + * oct-usr-fcn.h (octave_user_function::argn_sr): New data member. + (octave_user_function::install_automatic_vars): Rename from + install_nargin_and_nargout. + (octave_user_function::bind_automatic_vars): Rename from + bind_nargin_and_nargout. + * oct-usr-fcn.cc (octave_user_function::eval): Extract arg names + from args vector and bind them to argn. + * oct-obj.h (octave_value_list::names): New data member. + * oct-obj.cc (octave_value_list::stash_name_tags): New function. + (octave_value_list::name_tags): Ditto. + * pt-const.h, pt-const.cc (tree_constant::print_raw): New function. + * pt-misc.h, pt-misc.cc (tree_argument_list::get_arg_names): + New function. + * pt-mvr.h, pt-mvr.cc (class index_expression): Cache arg names. + * toplev.cc (feval): Now static. Handle arg names. + + * mkops: Cope with moving files defining operators to OPERATORS + subdirectory. + Tue May 6 00:48:59 1997 John W. Eaton <jwe@bevo.che.wisc.edu> * DLD-FUNCTIONS/getgrent.cc: Use new octave_group class.
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -81,7 +81,7 @@ oct-builtin.h oct-fcn.h oct-fstrm.h oct-hist.h oct-iostrm.h \ oct-map.h oct-mapper.h oct-obj.h oct-prcstrm.h oct-procbuf.h \ oct-stdstrm.h oct-stream.h oct-strstrm.h oct-sym.h \ - oct-usr-fcn.h oct.h ops.h pager.h parse.h pathlen.h \ + oct-usr-fcn.h oct.h ops.h pager.h parse.h \ pr-output.h procstream.h sighandlers.h symtab.h sysdep.h \ systime.h syswait.h token.h toplev.h unwind-prot.h utils.h \ variables.h version.h xdiv.h xpow.h $(OV_INCLUDES) $(PT_INCLUDES) @@ -119,11 +119,12 @@ load-save.cc mappers.cc oct-fstrm.cc oct-hist.cc \ oct-iostrm.cc oct-map.cc oct-obj.cc oct-prcstrm.cc \ oct-procbuf.cc oct-stdstrm.cc oct-stream.cc oct-strstrm.cc \ - pager.cc parse.y pr-output.cc procstream.cc sighandlers.cc \ - strcasecmp.c strncase.c strfns.cc strftime.c symtab.cc \ - syscalls.cc sysdep.cc token.cc toplev.cc unwind-prot.cc \ - utils.cc variables.cc xdiv.cc xpow.cc oct-fcn.cc \ - oct-builtin.cc oct-mapper.cc oct-usr-fcn.cc \ + pager.cc parse.y pr-output.cc procstream.cc \ + sighandlers.cc strcasecmp.c strncase.c strfns.cc \ + strftime.c symtab.cc syscalls.cc sysdep.cc token.cc \ + toplev.cc unwind-prot.cc utils.cc variables.cc xdiv.cc \ + xpow.cc oct-fcn.cc oct-builtin.cc oct-mapper.cc \ + oct-usr-fcn.cc \ $(OP_SRC) $(OV_SRC) $(PT_SRC) $(TI_SRC) OBJECTS_4 := $(notdir $(SOURCES)) @@ -244,9 +245,9 @@ @$(srcdir)/mkbuiltins def-files var-files > $@.t @$(top_srcdir)/move-if-change $@.t $@ -ops.cc: $(OP_SOURCES) mkops - @echo making $@ from $(OP_SOURCES) - @$(srcdir)/mkops $(OP_SOURCES) > $@.t +ops.cc: $(OP_SRC) mkops + @echo making $@ from $(OP_SRC) + @$(srcdir)/mkops $(OP_SRC) > $@.t @$(top_srcdir)/move-if-change $@.t $@ $(DEF_FILES): mkdefs defun-int.h defun-dld.h defun.h defaults.h oct-conf.h
--- a/src/input.cc +++ b/src/input.cc @@ -360,35 +360,18 @@ else names = make_name_list (); - names.qsort (); - - // Remove duplicates. - - // XXX FIXME XXX -- maybe this should be defined for all Array objects. - - int k = 0; - - int len = names.length (); + // Sort and remove duplicates. - for (int i = 1; i < len; i++) - { - if (names[i] != names[k]) - { - k++; - - if (k != i) - names[k] = names[i]; - } - } - - names.resize (k+1); + names.qsort (true); return names; } -static char * -command_generator (const char *text, int state) +static string +generate_completion (const string& text, int state) { + string retval; + static string prefix; static string hint; @@ -434,43 +417,25 @@ if (! name.compare (hint, 0, hint_len)) { - int len = 2 + prefix_len + name.length (); - - char *buf = static_cast<char *> (malloc (len)); + if (! prefix.empty ()) + retval = prefix + "." + name; + else + retval = name; - if (! prefix.empty ()) - { - strcpy (buf, prefix.c_str ()); - strcat (buf, "."); - strcat (buf, name.c_str ()); - } - else - strcpy (buf, name.c_str ()); - - if (matches == 1 && looks_like_struct (buf)) + if (matches == 1 && looks_like_struct (retval)) command_editor::set_completion_append_character ('.'); else command_editor::set_completion_append_character (Vcompletion_append_char); - return buf; + break; } } } - return 0; + return retval; } -#if 0 -static char ** -command_completer (char *text, int /* start */, int /* end */) -{ - char **matches = 0; - matches = completion_matches (text, command_generator); - return matches; -} -#endif - void initialize_command_input (void) { @@ -480,6 +445,8 @@ command_editor::set_name ("Octave"); command_editor::set_paren_string_delimiters ("\""); + + command_editor::set_completion_function (generate_completion); } static bool @@ -705,7 +672,7 @@ if (nargin == 1) { - string hint_string = args(0).string_value (); + string hint = args(0).string_value (); if (! error_state) { @@ -713,26 +680,21 @@ string_vector list (n); - const char *hint = hint_string.c_str (); - int k = 0; for (;;) { - const char *cmd = command_generator (hint, k); + string cmd = generate_completion (hint, k); - if (cmd) + if (! cmd.empty ()) { - if (*cmd) + if (k == n) { - if (k == n) - { - n *= 2; - list.resize (n); - } + n *= 2; + list.resize (n); + } - list[k++] = cmd; - } + list[k++] = cmd; } else {