Mercurial > hg > octave-nkf
diff scripts/java/javaclasspath.m @ 19093:93805f9256a9
javaclasspath: refactor to avoid duplication and skip check of nargout.
* scripts/java/javaclasspath.m: check nargout to first decide between return
cells or 'pretty print' to reduce code duplication in separate blocks. In
addition, do not check for correct number of nargout. Previous implementation
would simply return nothing if nargout was 3.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 08 Jul 2014 20:45:50 +0100 |
parents | d63878346099 |
children | 0e1f5a750d00 |
line wrap: on
line diff
--- a/scripts/java/javaclasspath.m +++ b/scripts/java/javaclasspath.m @@ -54,7 +54,11 @@ ## @seealso{javaaddpath, javarmpath} ## @end deftypefn -function varargout = javaclasspath (which) +function [path1, path2] = javaclasspath (which) + + if (nargin > 1) + print_usage (); + endif ## dynamic classpath dynamic_path = javaMethod ("getClassPath", "org.octave.ClassHelper"); @@ -70,46 +74,39 @@ static_path_list = {}; endif - switch (nargin) - case 0 - switch (nargout) - case 0 - disp_path_list ("STATIC", static_path_list) - disp (""); - disp_path_list ("DYNAMIC", dynamic_path_list) + if (nargout == 0) + if (! nargin) + which = "-all"; + endif + switch (tolower (which)) + case "-dynamic", disp_path_list ("DYNAMIC", dynamic_path_list); + case "-static", disp_path_list ("STATIC", static_path_list); + case "-all" + disp_path_list ("STATIC", static_path_list); + disp (""); + disp_path_list ("DYNAMIC", dynamic_path_list); + otherwise + error ("javaclasspath: invalid value for WHAT"); + endswitch - case 1 - varargout{1} = cellstr (dynamic_path_list); - - case 2 - varargout{1} = cellstr (dynamic_path_list); - varargout{2} = cellstr (static_path_list); + else + if (! nargin) + ## This is to allow retrieval of both paths in separate variables with + ## a single call to javaclasspath(). Matlab returns only the -dynamic + ## path in this case but this won't break compatibility. + path1 = cellstr (dynamic_path_list); + path2 = cellstr (static_path_list); + else + switch (tolower (which)) + case "-all", path1 = cellstr ([static_path_list, dynamic_path_list]); + case "-dynamic", path1 = cellstr (dynamic_path_list); + case "-static", path1 = cellstr (static_path_list); + otherwise + error ("javaclasspath: invalid value for WHAT"); endswitch - - case 1 - switch (nargout) - case 0 - if (strcmp (which, "-static")) - disp_path_list ("STATIC", static_path_list) - elseif (strcmp (which, "-dynamic")) - disp_path_list ("DYNAMIC", dynamic_path_list) - elseif (strcmp (which, "-all") == 1) - disp_path_list ("STATIC", static_path_list) - disp (""); - disp_path_list ("DYNAMIC", dynamic_path_list) - endif + endif + endif - case 1 - if (strcmp (which, "-static") == 1) - varargout{1} = cellstr (static_path_list); - elseif (strcmp (which, "-dynamic") == 1) - varargout{1} = cellstr (dynamic_path_list); - elseif (strcmp (which, "-all") == 1) - varargout{1} = cellstr ([static_path_list, dynamic_path_list]); - endif - endswitch - endswitch - endfunction ## Display cell array of paths