Extra spaces in functions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extra spaces in functions

Eyal Doron
Hi,
  On the subject of extra spaces screwing up .M files in
whitespace_in_literal_matrix = "traditional" mode, you might me
interested in the following:

 grep -n "\[.*zeros (" lib/octave/1.1.1/m/*/*.m

gives

lib/octave/1.1.1/m/control/c2d.m:52:  matexp = expm ([[Ac, Bc] * T; zeros (nb, na+nb)]);
lib/octave/1.1.1/m/control/tzero.m:44: b = [b, zeros (n, p-m)];
lib/octave/1.1.1/m/control/tzero.m:45: d = [d, zeros (p, p-m)];
lib/octave/1.1.1/m/control/tzero.m:49: c = [c; zeros (m-p, n)];
lib/octave/1.1.1/m/control/tzero.m:50: d = [d; zeros (m-p, m)];
lib/octave/1.1.1/m/control/tzero.m:56:    bb = [eye (n), zeros (n, m); zeros (p, n), zeros (p, m)];
lib/octave/1.1.1/m/polynomial/conv.m:59:      x = [b, zeros (1, ly - lb)];
lib/octave/1.1.1/m/polynomial/conv.m:66:      x = [a, zeros (1, ly - la)];
lib/octave/1.1.1/m/polynomial/deconv.m:51:    b = filter (y, a, [1 zeros (1, ly - la)]);
lib/octave/1.1.1/m/polynomial/poly.m:48:  y = [1, zeros (1, n)];
lib/octave/1.1.1/m/polynomial/roots.m:52: r = [r; zeros (n - f (m), 1)];


So, these 6 files have to be fixed.

Eyal

Reply | Threaded
Open this post in threaded view
|

function calls vs indexing (was Re: Extra spaces in functions)

Doug Warner
>>>>> "Eyal" == Eyal Doron <[hidden email]> writes:

    Eyal> Hi, On the subject of extra spaces screwing up .M files in
    Eyal> whitespace_in_literal_matrix = "traditional" mode, you might
    Eyal> me interested in the following:

    Eyal>  grep -n "\[.*zeros (" lib/octave/1.1.1/m/*/*.m

The command

  grep -n "\[[^]]*[[:alpha:]]\{1,\} (" lib/octave/1.1.1/m/*/*.m

shows other function calls besides zeros.  It does miss a few cases
because of nested literal matrices.  But it can't distinguish between
function calls and variables, so that some matches to the given REGEXP
could be valid as written.  It's also impossible to distinguish
between function calls and variable indexing.  This makes automatic
dependency generation difficult.  Is there an unused symbol that could
be used to distinguish variable indexing from function calls?  Does
anyone else want such a feature?

Doug Warner

Reply | Threaded
Open this post in threaded view
|

function calls vs indexing (was Re: Extra spaces in functions)

John W. Eaton-6
Doug Warner <[hidden email]> wrote:

: >>>>> "Eyal" == Eyal Doron <[hidden email]> writes:
:
:     Eyal> Hi, On the subject of extra spaces screwing up .M files in
:     Eyal> whitespace_in_literal_matrix = "traditional" mode, you might
:     Eyal> me interested in the following:
:
:     Eyal>  grep -n "\[.*zeros (" lib/octave/1.1.1/m/*/*.m
:
: The command
:
:   grep -n "\[[^]]*[[:alpha:]]\{1,\} (" lib/octave/1.1.1/m/*/*.m
:
: shows other function calls besides zeros.

Here is a way to check all the function files, without having to write
a sed/grep/awk/perl parser yourself:

1. Save the following script in a file, say ~/check_octave_functions

  # script to check for dependency on whitespace_in_literal_matrix
  #
  # Originally by R. D. Auchterlounie <[hidden email]>

  1;  # Don't interpret this a file that defines a single function.

  function t = wlm_check (wlm, fname)
    whitespace_in_literal_matrix = wlm;
    bc = "printf (\" %s\", wlm)";
    eval (["t = type ", fname, ";"], ["t = \"failed\";", bc]);
  endfunction

  # Someone should make fgets work for a single argument, or implement
  # fgetl!  :-)

  while (isstr (fname = fgets (stdin, 100)))

    # Someone should improve Octave's string handling capabilities! :-)

    tmp = toascii (fname);
    tmp (length (tmp)) = 0;
    fname = setstr (tmp);

    printf ("checking %s ...", fname);

    eval (["clear ", fname]); trd = wlm_check ("traditional", fname);
    eval (["clear ", fname]); ign = wlm_check ("ignore", fname);
    eval (["clear ", fname]); def = wlm_check ("default", fname);

    if (strcmp  (trd, "failed")
        || strcmp (ign, "failed")
        || strcmp (def, "failed"))
      printf (" FAILED\n");
    else
      printf (" ok\n");
    endif

  endwhile

2. cd to the top of the directory tree that you want to check.

3. Execute the following command:

  find . -name '*.m' -print | \
    sed -e 's,^.*/,,' -e 's,\.m$,,' | \
    octave --silent --path "`pwd`//:" ~/check_octave_functions

  This will print a list of all the functions as they are checked and
  tell you which functions pass or fail the test.

Thanks to R. D. Auchterlounie <[hidden email]> for writing the
initial version of this.

I've used it to find and remove all dependencies on
whitespace_in_literal_matrix in my sources.  I'll be using some
variant of it to check for other similar problems, and it should
eventually end up in Octave's test suite so that these kinds of
problems don't reappear in the future.

Thanks,

jwe