# HG changeset patch # User Rik # Date 1403732919 25200 # Node ID da6ffbf75edf48bd08825c4c7d6c43ab68dec901 # Parent a1dde4d4c45c698e8fefd7da2080d65dfd83d48d Simplify exist() code for recognizing command line functions. * variables.cc (symbol_exist): Short-circuit out quickly if search type is builtin and no builtin is found. Use the fact that all other cases have been checked by the end of the function to make the test for a command line function short. * variables.cc (Fexist): Expand %!tests. diff -r a1dde4d4c45c -r da6ffbf75edf libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc Wed Jun 25 14:03:20 2014 -0700 +++ b/libinterp/corefcn/variables.cc Wed Jun 25 14:48:39 2014 -0700 @@ -421,6 +421,9 @@ if ((search_any || search_builtin) && val.is_builtin_function ()) return 5; + + if (search_builtin) + return 0; } if (search_any || search_file || search_dir) @@ -474,21 +477,9 @@ return 0; } - if (val.is_defined ()) - { - if ((search_any || search_file) - && (val.is_user_function () || val.is_dld_function ())) - { - octave_function *f = val.function_value (true); - std::string s = f ? f->fcn_file_name () : std::string (); - - // FIXME: I believe that by this point in the code the only - // return value is 103. User functions should have - // been located above. Maybe replace entire if block - // code with "return 103;" - return s.empty () ? 103 : (val.is_user_function () ? 2 : 3); - } - } + // Command line function which Matlab does not support + if (search_any && val.is_defined () && val.is_user_function ()) + return 103; return 0; } @@ -610,6 +601,8 @@ %!assert (exist ("colon"), 2) %!assert (exist ("colon.m"), 2) +%!assert (exist ("colon", "file"), 2) +%!assert (exist ("colon", "dir"), 0) %!testif HAVE_CHOLMOD %! assert (exist ("chol"), 3); @@ -618,6 +611,8 @@ %! assert (exist ("chol", "builtin"), 0); %!assert (exist ("sin"), 5) +%!assert (exist ("sin", "builtin"), 5) +%!assert (exist ("sin", "file"), 0) %!assert (exist (dirtmp), 7) %!assert (exist (dirtmp, "dir"), 7)