comparison libinterp/corefcn/help.cc @ 20922:49081851fddc

Eliminate duplicate input arg checking in which.m and __which__. * which.m: Put input validation and print_usage call at top of fcn. * help.cc (F__which__): Don't check number of inputs or call print_usage in internal function. Call make_argv() with no argument to avoid a lot of +1/-1 arithmetic.
author Rik <rik@octave.org>
date Wed, 16 Dec 2015 16:47:18 -0800
parents f1b2a2dbc0e1
children b17fda023ca6
comparison
equal deleted inserted replaced
20921:4d3daf7e43f3 20922:49081851fddc
1280 "-*- texinfo -*-\n\ 1280 "-*- texinfo -*-\n\
1281 @deftypefn {} {} __which__ (@var{name}, @dots{})\n\ 1281 @deftypefn {} {} __which__ (@var{name}, @dots{})\n\
1282 Undocumented internal function.\n\ 1282 Undocumented internal function.\n\
1283 @end deftypefn") 1283 @end deftypefn")
1284 { 1284 {
1285 string_vector argv = args.make_argv ("which"); 1285 string_vector argv = args.make_argv ("");
1286 1286
1287 int argc = argv.numel (); 1287 int nargin = argv.numel ();
1288 1288
1289 if (argc < 2) 1289 octave_map m (dim_vector (1, nargin));
1290 print_usage (); 1290
1291 1291 Cell names (1, nargin);
1292 octave_map m (dim_vector (1, argc-1)); 1292 Cell files (1, nargin);
1293 1293 Cell types (1, nargin);
1294 Cell names (1, argc-1); 1294
1295 Cell files (1, argc-1); 1295 for (int i = 0; i < nargin; i++)
1296 Cell types (1, argc-1);
1297
1298 for (int i = 1; i < argc; i++)
1299 { 1296 {
1300 std::string name = argv[i]; 1297 std::string name = argv[i];
1301 1298
1302 std::string type; 1299 std::string type;
1303 1300
1304 std::string file = do_which (name, type); 1301 std::string file = do_which (name, type);
1305 1302
1306 names(i-1) = name; 1303 names(i) = name;
1307 files(i-1) = file; 1304 files(i) = file;
1308 types(i-1) = type; 1305 types(i) = type;
1309 } 1306 }
1310 1307
1311 m.assign ("name", names); 1308 m.assign ("name", names);
1312 m.assign ("file", files); 1309 m.assign ("file", files);
1313 m.assign ("type", types); 1310 m.assign ("type", types);
1314 1311
1315 return octave_value (m); 1312 return ovl (m);
1316 } 1313 }
1317 1314
1318 // FIXME: Are we sure this function always does the right thing? 1315 // FIXME: Are we sure this function always does the right thing?
1319 inline bool 1316 inline bool
1320 file_is_in_dir (const std::string filename, const std::string dir) 1317 file_is_in_dir (const std::string filename, const std::string dir)