comparison src/variables.cc @ 1488:89c587478067

[project @ 1995-09-26 22:49:48 by jwe]
author jwe
date Tue, 26 Sep 1995 22:49:48 +0000
parents 20e9c40d10f6
children 3e705c864019
comparison
equal deleted inserted replaced
1487:eaf4f68d3757 1488:89c587478067
152 } 152 }
153 153
154 return ans; 154 return ans;
155 } 155 }
156 156
157 // Does this function take the right number of arguments? 157 DEFUN ("is_global", Fis_global, Sis_global, 10,
158
159 int
160 takes_correct_nargs (tree_fvc *fcn, int expected_nargin, char *warn_for,
161 int warn)
162 {
163 int nargin = fcn->max_expected_args ();
164 int e_nargin = expected_nargin;
165 if (nargin != e_nargin)
166 {
167 if (warn)
168 error ("%s: expecting function to take %d argument%s",
169 warn_for, e_nargin, (e_nargin == 1 ? "" : "s"));
170 return 0;
171 }
172 return 1;
173 }
174
175 DEFUN ("is_global", Fis_global, Sis_global, 1, 1,
176 "is_global (X): return 1 if the string X names a global variable\n\ 158 "is_global (X): return 1 if the string X names a global variable\n\
177 otherwise, return 0.") 159 otherwise, return 0.")
178 { 160 {
179 Octave_object retval = 0.0; 161 Octave_object retval = 0.0;
180 162
199 retval = (double) (sr && sr->is_linked_to_global ()); 181 retval = (double) (sr && sr->is_linked_to_global ());
200 182
201 return retval; 183 return retval;
202 } 184 }
203 185
204 DEFUN ("exist", Fexist, Sexist, 1, 1, 186 DEFUN ("exist", Fexist, Sexist, 10,
205 "exist (NAME): check if variable or file exists\n\ 187 "exist (NAME): check if variable or file exists\n\
206 \n\ 188 \n\
207 return 0 if NAME is undefined, 1 if it is a variable, or 2 if it is\n\ 189 return 0 if NAME is undefined, 1 if it is a variable, or 2 if it is\n\
208 a function.") 190 a function.")
209 { 191 {
1186 delete [] symbols; 1168 delete [] symbols;
1187 } 1169 }
1188 return status; 1170 return status;
1189 } 1171 }
1190 1172
1191 DEFUN_TEXT ("document", Fdocument, Sdocument, -1, 1, 1173 DEFUN_TEXT ("document", Fdocument, Sdocument, 10,
1192 "document symbol string ...\n\ 1174 "document symbol string ...\n\
1193 \n\ 1175 \n\
1194 Associate a cryptic message with a variable name.") 1176 Associate a cryptic message with a variable name.")
1195 { 1177 {
1196 Octave_object retval; 1178 Octave_object retval;
1224 1206
1225 // XXX FIXME XXX -- this should take a list of regular expressions 1207 // XXX FIXME XXX -- this should take a list of regular expressions
1226 // naming the variables to look for. 1208 // naming the variables to look for.
1227 1209
1228 static Octave_object 1210 static Octave_object
1229 do_who (int argc, char **argv, int nargout) 1211 do_who (int argc, char **argv)
1230 { 1212 {
1231 Octave_object retval; 1213 Octave_object retval;
1232 1214
1233 int show_builtins = 0; 1215 int show_builtins = 0;
1234 int show_functions = (curr_sym_tab == top_level_sym_tab); 1216 int show_functions = (curr_sym_tab == top_level_sym_tab);
1320 maybe_page_output (output_buf); 1302 maybe_page_output (output_buf);
1321 1303
1322 return retval; 1304 return retval;
1323 } 1305 }
1324 1306
1325 DEFUN_TEXT ("who", Fwho, Swho, -1, 1, 1307 DEFUN_TEXT ("who", Fwho, Swho, 10,
1326 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\ 1308 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\
1327 \n\ 1309 \n\
1328 List currently defined symbol(s). Options may be shortened to one\n\ 1310 List currently defined symbol(s). Options may be shortened to one\n\
1329 character, but may not be combined.") 1311 character, but may not be combined.")
1330 { 1312 {
1331 Octave_object retval; 1313 Octave_object retval;
1332 1314
1333 DEFINE_ARGV("who"); 1315 DEFINE_ARGV("who");
1334 1316
1335 retval = do_who (argc, argv, nargout); 1317 retval = do_who (argc, argv);
1336 1318
1337 DELETE_ARGV; 1319 DELETE_ARGV;
1338 1320
1339 return retval; 1321 return retval;
1340 } 1322 }
1341 1323
1342 DEFUN_TEXT ("whos", Fwhos, Swhos, -1, 1, 1324 DEFUN_TEXT ("whos", Fwhos, Swhos, 10,
1343 "whos [-all] [-builtins] [-functions] [-long] [-variables]\n\ 1325 "whos [-all] [-builtins] [-functions] [-long] [-variables]\n\
1344 \n\ 1326 \n\
1345 List currently defined symbol(s). Options may be shortened to one\n\ 1327 List currently defined symbol(s). Options may be shortened to one\n\
1346 character, but may not be combined.") 1328 character, but may not be combined.")
1347 { 1329 {
1358 char **argv = make_argv (tmp_args, "whos"); 1340 char **argv = make_argv (tmp_args, "whos");
1359 1341
1360 if (error_state) 1342 if (error_state)
1361 return retval; 1343 return retval;
1362 1344
1363 retval = do_who (argc, argv, nargout); 1345 retval = do_who (argc, argv);
1364 1346
1365 while (--argc >= 0) 1347 while (--argc >= 0)
1366 delete [] argv[argc]; 1348 delete [] argv[argc];
1367 delete [] argv; 1349 delete [] argv;
1368 1350
1384 mfcn.upper_limit = mf->upper_limit; 1366 mfcn.upper_limit = mf->upper_limit;
1385 mfcn.d_d_mapper = mf->d_d_mapper; 1367 mfcn.d_d_mapper = mf->d_d_mapper;
1386 mfcn.d_c_mapper = mf->d_c_mapper; 1368 mfcn.d_c_mapper = mf->d_c_mapper;
1387 mfcn.c_c_mapper = mf->c_c_mapper; 1369 mfcn.c_c_mapper = mf->c_c_mapper;
1388 1370
1389 tree_builtin *def = new tree_builtin (1, 1, mfcn, mf->name); 1371 tree_builtin *def = new tree_builtin (mfcn, mf->name);
1390 1372
1391 sym_rec->define (def); 1373 sym_rec->define (def);
1392 1374
1393 sym_rec->document (mf->help_string); 1375 sym_rec->document (mf->help_string);
1394 sym_rec->make_eternal (); 1376 sym_rec->make_eternal ();
1399 install_builtin_function (builtin_function *f) 1381 install_builtin_function (builtin_function *f)
1400 { 1382 {
1401 symbol_record *sym_rec = global_sym_tab->lookup (f->name, 1); 1383 symbol_record *sym_rec = global_sym_tab->lookup (f->name, 1);
1402 sym_rec->unprotect (); 1384 sym_rec->unprotect ();
1403 1385
1404 tree_builtin *def = new tree_builtin (f->nargin_max, f->nargout_max, 1386 tree_builtin *def = new tree_builtin (f->fcn, f->name);
1405 f->fcn, f->name);
1406 1387
1407 sym_rec->define (def, f->is_text_fcn); 1388 sym_rec->define (def, f->is_text_fcn);
1408 1389
1409 sym_rec->document (f->help_string); 1390 sym_rec->document (f->help_string);
1410 sym_rec->make_eternal (); 1391 sym_rec->make_eternal ();
1810 "control auto-insertion of commas and semicolons in literal matrices"); 1791 "control auto-insertion of commas and semicolons in literal matrices");
1811 } 1792 }
1812 1793
1813 // Deleting names from the symbol tables. 1794 // Deleting names from the symbol tables.
1814 1795
1815 DEFUN_TEXT ("clear", Fclear, Sclear, -1, 1, 1796 DEFUN_TEXT ("clear", Fclear, Sclear, 10,
1816 "clear [-x] [name ...]\n\ 1797 "clear [-x] [name ...]\n\
1817 \n\ 1798 \n\
1818 Clear symbol(s) matching a list of globbing patterns.\n\ 1799 Clear symbol(s) matching a list of globbing patterns.\n\
1819 \n\ 1800 \n\
1820 If no arguments are given, clear all user-defined variables and 1801 If no arguments are given, clear all user-defined variables and