4343
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
4343
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <iostream> |
5765
|
29 #include <sstream> |
5164
|
30 #include <vector> |
4343
|
31 |
|
32 #include "defun.h" |
4654
|
33 #include "error.h" |
|
34 #include "gripes.h" |
5663
|
35 #include "input.h" |
4343
|
36 #include "oct-map.h" |
|
37 #include "ov-base.h" |
|
38 #include "ov-fcn-handle.h" |
4980
|
39 #include "ov-usr-fcn.h" |
4343
|
40 #include "pr-output.h" |
4980
|
41 #include "pt-pr-code.h" |
|
42 #include "pt-misc.h" |
|
43 #include "pt-stmt.h" |
|
44 #include "pt-cmd.h" |
|
45 #include "pt-exp.h" |
|
46 #include "pt-assign.h" |
4343
|
47 #include "variables.h" |
4988
|
48 #include "parse.h" |
|
49 |
|
50 #include "byte-swap.h" |
|
51 #include "ls-oct-ascii.h" |
|
52 #include "ls-hdf5.h" |
|
53 #include "ls-utils.h" |
4343
|
54 |
|
55 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); |
|
56 |
4612
|
57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle, |
|
58 "function handle", |
|
59 "function handle"); |
4343
|
60 |
5663
|
61 void |
|
62 octave_fcn_handle::reload_warning (const std::string& fcn_type) const |
|
63 { |
|
64 if (warn_reload) |
|
65 { |
|
66 warn_reload = false; |
|
67 |
|
68 warning ("reloading %s functions referenced by function handles is not implemented", |
|
69 fcn_type.c_str ()); |
|
70 } |
|
71 } |
|
72 |
4924
|
73 octave_value_list |
|
74 octave_fcn_handle::subsref (const std::string& type, |
|
75 const std::list<octave_value_list>& idx, |
|
76 int nargout) |
|
77 { |
|
78 octave_value_list retval; |
|
79 |
|
80 switch (type[0]) |
|
81 { |
|
82 case '(': |
|
83 { |
|
84 octave_function *f = function_value (); |
5312
|
85 |
5663
|
86 if (f && f->time_checked () < Vlast_prompt_time) |
|
87 { |
|
88 std::string ff_nm = f->fcn_file_name (); |
|
89 |
|
90 time_t tp = f->time_parsed (); |
|
91 |
|
92 if (ff_nm.empty ()) |
|
93 { |
5775
|
94 // FIXME -- need to handle inline and |
5663
|
95 // command-line functions here. |
|
96 } |
|
97 else |
|
98 { |
|
99 if (fcn_out_of_date (f, ff_nm, tp)) |
|
100 { |
5775
|
101 // FIXME -- there is currently no way to |
5663
|
102 // parse a .m file or reload a .oct file that |
|
103 // leaves the fbi symbol table untouched. We need |
|
104 // a function that will parse the file and return |
|
105 // a pointer to the new function definition |
|
106 // without altering the symbol table. |
|
107 |
|
108 if (f->is_nested_function ()) |
|
109 reload_warning ("nested"); |
|
110 else |
|
111 reload_warning ("functions"); |
|
112 } |
|
113 } |
|
114 } |
5312
|
115 |
|
116 if (f) |
|
117 retval = f->subsref (type, idx, nargout); |
|
118 else |
|
119 error ("invalid function handle"); |
4924
|
120 } |
|
121 break; |
|
122 |
|
123 |
|
124 case '{': |
|
125 case '.': |
|
126 { |
4930
|
127 std::string typ_nm = type_name (); |
|
128 error ("%s cannot be indexed with %c", typ_nm.c_str (), type[0]); |
4924
|
129 } |
|
130 break; |
|
131 |
|
132 default: |
|
133 panic_impossible (); |
|
134 } |
|
135 |
5775
|
136 // FIXME -- perhaps there should be an |
4924
|
137 // octave_value_list::next_subsref member function? See also |
|
138 // octave_builtin::subsref. |
|
139 |
|
140 if (idx.size () > 1) |
4994
|
141 retval = retval(0).next_subsref (nargout, type, idx); |
4924
|
142 |
|
143 return retval; |
|
144 } |
|
145 |
4988
|
146 bool |
|
147 octave_fcn_handle::save_ascii (std::ostream& os, bool&, bool) |
|
148 { |
|
149 os << nm << "\n"; |
4989
|
150 |
4988
|
151 if (nm == "@<anonymous>") |
|
152 { |
4989
|
153 print_raw (os, true); |
|
154 os << "\n"; |
4988
|
155 } |
|
156 |
|
157 return true; |
|
158 } |
|
159 |
|
160 bool |
|
161 octave_fcn_handle::load_ascii (std::istream& is) |
|
162 { |
|
163 is >> nm; |
4989
|
164 |
4988
|
165 if (nm == "@<anonymous>") |
|
166 { |
|
167 char c; |
5765
|
168 std::ostringstream buf; |
4988
|
169 |
4989
|
170 // Skip preceeding newline(s). |
|
171 while (is.get (c) && c == '\n') |
|
172 /* do nothing */; |
4988
|
173 |
|
174 if (is) |
|
175 { |
|
176 buf << c; |
|
177 |
|
178 // Get a line of text whitespace characters included, leaving |
4989
|
179 // newline in the stream. |
|
180 |
4988
|
181 while (is.peek () != '\n') |
|
182 { |
|
183 is.get (c); |
|
184 if (! is) |
|
185 break; |
|
186 buf << c; |
|
187 } |
|
188 } |
|
189 |
|
190 int parse_status; |
5765
|
191 octave_value anon_fcn_handle = eval_string (buf.str (), true, |
|
192 parse_status); |
4988
|
193 |
4989
|
194 if (parse_status == 0) |
|
195 { |
|
196 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
|
197 if (fh) |
|
198 fcn = fh->fcn; |
|
199 else |
|
200 return false; |
|
201 } |
|
202 else |
|
203 return false; |
4988
|
204 } |
|
205 else |
|
206 { |
|
207 fcn = lookup_function (nm); |
|
208 if (! fcn.is_function ()) |
|
209 return false; |
|
210 } |
|
211 |
|
212 return true; |
|
213 } |
|
214 |
|
215 bool |
|
216 octave_fcn_handle::save_binary (std::ostream& os, bool&) |
|
217 { |
5828
|
218 int32_t tmp = nm.length (); |
5760
|
219 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988
|
220 os.write (nm.c_str (), nm.length ()); |
|
221 if (nm == "@<anonymous>") |
|
222 { |
5765
|
223 std::ostringstream buf; |
4988
|
224 print_raw (buf, true); |
5765
|
225 std::string stmp = buf.str (); |
4988
|
226 tmp = stmp.length (); |
5760
|
227 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988
|
228 os.write (stmp.c_str (), stmp.length ()); |
|
229 } |
|
230 return true; |
|
231 } |
|
232 |
|
233 bool |
|
234 octave_fcn_handle::load_binary (std::istream& is, bool swap, |
|
235 oct_mach_info::float_format) |
|
236 { |
5828
|
237 int32_t tmp; |
5760
|
238 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988
|
239 return false; |
|
240 if (swap) |
|
241 swap_bytes<4> (&tmp); |
|
242 |
|
243 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); |
|
244 is.read (ctmp1, tmp); |
|
245 nm = std::string (ctmp1); |
|
246 |
|
247 if (! is) |
|
248 return false; |
|
249 |
|
250 if (nm == "@<anonymous>") |
|
251 { |
5760
|
252 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988
|
253 return false; |
|
254 if (swap) |
|
255 swap_bytes<4> (&tmp); |
|
256 |
|
257 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); |
|
258 is.read (ctmp2, tmp); |
|
259 |
|
260 int parse_status; |
|
261 octave_value anon_fcn_handle = eval_string (ctmp2, true, parse_status); |
|
262 |
4989
|
263 if (parse_status == 0) |
|
264 { |
|
265 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
|
266 if (fh) |
|
267 fcn = fh->fcn; |
|
268 else |
|
269 return false; |
|
270 } |
|
271 else |
|
272 return false; |
4988
|
273 } |
|
274 else |
|
275 { |
|
276 fcn = lookup_function (nm); |
|
277 if (! fcn.is_function ()) |
|
278 return false; |
|
279 } |
|
280 return true; |
|
281 } |
|
282 |
|
283 #if defined (HAVE_HDF5) |
|
284 bool |
|
285 octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, |
|
286 bool /* save_as_floats */) |
|
287 { |
|
288 hid_t group_hid = -1; |
|
289 group_hid = H5Gcreate (loc_id, name, 0); |
|
290 if (group_hid < 0 ) return false; |
|
291 |
|
292 hid_t space_hid = -1, data_hid = -1, type_hid = -1;; |
|
293 bool retval = true; |
|
294 |
|
295 // attach the type of the variable |
|
296 type_hid = H5Tcopy (H5T_C_S1); |
|
297 H5Tset_size (type_hid, nm.length () + 1); |
|
298 if (type_hid < 0) |
|
299 { |
|
300 H5Gclose (group_hid); |
|
301 return false; |
|
302 } |
|
303 |
|
304 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); |
|
305 hdims[0] = 0; |
|
306 hdims[1] = 0; |
5760
|
307 space_hid = H5Screate_simple (0 , hdims, 0); |
4988
|
308 if (space_hid < 0) |
|
309 { |
|
310 H5Tclose (type_hid); |
|
311 H5Gclose (group_hid); |
|
312 return false; |
|
313 } |
|
314 |
|
315 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); |
|
316 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
5760
|
317 H5P_DEFAULT, nm.c_str ()) < 0) |
4988
|
318 { |
|
319 H5Sclose (space_hid); |
|
320 H5Tclose (type_hid); |
|
321 H5Gclose (group_hid); |
|
322 return false; |
|
323 } |
|
324 H5Dclose (data_hid); |
|
325 |
|
326 if (nm == "@<anonymous>") |
|
327 { |
5765
|
328 std::ostringstream buf; |
4988
|
329 print_raw (buf, true); |
5765
|
330 std::string stmp = buf.str (); |
4988
|
331 |
|
332 // attach the type of the variable |
|
333 H5Tset_size (type_hid, stmp.length () + 1); |
|
334 if (type_hid < 0) |
|
335 { |
|
336 H5Gclose (group_hid); |
|
337 return false; |
|
338 } |
|
339 |
|
340 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
|
341 H5P_DEFAULT); |
|
342 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
5760
|
343 H5P_DEFAULT, stmp.c_str ()) < 0) |
4988
|
344 { |
|
345 H5Sclose (space_hid); |
|
346 H5Tclose (type_hid); |
|
347 H5Gclose (group_hid); |
|
348 return false; |
|
349 } |
|
350 |
|
351 H5Dclose (data_hid); |
|
352 } |
|
353 |
|
354 H5Sclose (space_hid); |
|
355 H5Tclose (type_hid); |
|
356 H5Gclose (group_hid); |
|
357 |
|
358 return retval; |
|
359 } |
|
360 |
|
361 bool |
|
362 octave_fcn_handle::load_hdf5 (hid_t loc_id, const char *name, |
|
363 bool /* have_h5giterate_bug */) |
|
364 { |
|
365 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
|
366 hsize_t rank; |
|
367 int slen; |
|
368 |
|
369 group_hid = H5Gopen (loc_id, name); |
|
370 if (group_hid < 0 ) return false; |
|
371 |
|
372 data_hid = H5Dopen (group_hid, "nm"); |
|
373 |
|
374 if (data_hid < 0) |
|
375 { |
|
376 H5Gclose (group_hid); |
|
377 return false; |
|
378 } |
|
379 |
|
380 type_hid = H5Dget_type (data_hid); |
|
381 type_class_hid = H5Tget_class (type_hid); |
|
382 |
|
383 if (type_class_hid != H5T_STRING) |
|
384 { |
|
385 H5Tclose (type_hid); |
|
386 H5Dclose (data_hid); |
|
387 H5Gclose (group_hid); |
|
388 return false; |
|
389 } |
|
390 |
|
391 space_hid = H5Dget_space (data_hid); |
|
392 rank = H5Sget_simple_extent_ndims (space_hid); |
|
393 |
|
394 if (rank != 0) |
|
395 { |
|
396 H5Sclose (space_hid); |
|
397 H5Tclose (type_hid); |
|
398 H5Dclose (data_hid); |
|
399 H5Gclose (group_hid); |
|
400 return false; |
|
401 } |
|
402 |
|
403 slen = H5Tget_size (type_hid); |
|
404 if (slen < 0) |
|
405 { |
|
406 H5Sclose (space_hid); |
|
407 H5Tclose (type_hid); |
|
408 H5Dclose (data_hid); |
|
409 H5Gclose (group_hid); |
|
410 return false; |
|
411 } |
|
412 |
|
413 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); |
|
414 |
|
415 // create datatype for (null-terminated) string to read into: |
|
416 st_id = H5Tcopy (H5T_C_S1); |
|
417 H5Tset_size (st_id, slen); |
|
418 |
5760
|
419 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4988
|
420 { |
|
421 H5Sclose (space_hid); |
|
422 H5Tclose (type_hid); |
|
423 H5Gclose (group_hid); |
|
424 return false; |
|
425 } |
|
426 H5Tclose (st_id); |
|
427 H5Dclose (data_hid); |
|
428 nm = nm_tmp; |
|
429 |
|
430 if (nm == "@<anonymous>") |
|
431 { |
|
432 data_hid = H5Dopen (group_hid, "fcn"); |
|
433 |
|
434 if (data_hid < 0) |
|
435 { |
|
436 H5Gclose (group_hid); |
|
437 return false; |
|
438 } |
|
439 |
|
440 type_hid = H5Dget_type (data_hid); |
|
441 type_class_hid = H5Tget_class (type_hid); |
|
442 |
|
443 if (type_class_hid != H5T_STRING) |
|
444 { |
|
445 H5Tclose (type_hid); |
|
446 H5Dclose (data_hid); |
|
447 H5Gclose (group_hid); |
|
448 return false; |
|
449 } |
|
450 |
|
451 space_hid = H5Dget_space (data_hid); |
|
452 rank = H5Sget_simple_extent_ndims (space_hid); |
|
453 |
|
454 if (rank != 0) |
|
455 { |
|
456 H5Sclose (space_hid); |
|
457 H5Tclose (type_hid); |
|
458 H5Dclose (data_hid); |
|
459 H5Gclose (group_hid); |
|
460 return false; |
|
461 } |
|
462 |
|
463 slen = H5Tget_size (type_hid); |
|
464 if (slen < 0) |
|
465 { |
|
466 H5Sclose (space_hid); |
|
467 H5Tclose (type_hid); |
|
468 H5Dclose (data_hid); |
|
469 H5Gclose (group_hid); |
|
470 return false; |
|
471 } |
|
472 |
|
473 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); |
|
474 |
|
475 // create datatype for (null-terminated) string to read into: |
|
476 st_id = H5Tcopy (H5T_C_S1); |
|
477 H5Tset_size (st_id, slen); |
|
478 |
5760
|
479 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) |
4988
|
480 { |
|
481 H5Sclose (space_hid); |
|
482 H5Tclose (type_hid); |
|
483 H5Gclose (group_hid); |
|
484 return false; |
|
485 } |
|
486 H5Dclose (data_hid); |
|
487 H5Tclose (st_id); |
|
488 |
|
489 int parse_status; |
|
490 octave_value anon_fcn_handle = eval_string (fcn_tmp, true, parse_status); |
|
491 |
4989
|
492 if (parse_status == 0) |
|
493 { |
|
494 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
|
495 if (fh) |
|
496 fcn = fh->fcn; |
|
497 else |
|
498 return false; |
|
499 } |
|
500 else |
|
501 return false; |
4988
|
502 } |
|
503 else |
|
504 { |
|
505 fcn = lookup_function (nm); |
|
506 if (! fcn.is_function ()) |
|
507 return false; |
|
508 } |
|
509 |
|
510 return true; |
|
511 } |
|
512 #endif |
|
513 |
4343
|
514 void |
|
515 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const |
|
516 { |
|
517 print_raw (os, pr_as_read_syntax); |
|
518 newline (os); |
|
519 } |
|
520 |
|
521 void |
|
522 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
|
523 { |
4980
|
524 bool printed = false; |
|
525 |
|
526 if (nm == "@<anonymous>") |
|
527 { |
|
528 tree_print_code tpc (os); |
|
529 |
4989
|
530 // FCN is const because this member function is, so we can't |
4980
|
531 // use it to call user_function_value, so we make a copy first. |
|
532 |
|
533 octave_value ftmp = fcn; |
|
534 |
|
535 octave_user_function *f = ftmp.user_function_value (); |
|
536 |
|
537 if (f) |
|
538 { |
|
539 tree_parameter_list *p = f->parameter_list (); |
|
540 |
|
541 os << "@("; |
|
542 |
|
543 if (p) |
|
544 p->accept (tpc); |
|
545 |
|
546 os << ") "; |
|
547 |
|
548 tree_statement_list *b = f->body (); |
|
549 |
|
550 if (b) |
|
551 { |
|
552 assert (b->length () == 1); |
|
553 |
|
554 tree_statement *s = b->front (); |
|
555 |
|
556 if (s) |
|
557 { |
|
558 if (s->is_expression ()) |
|
559 { |
|
560 tree_expression *e = s->expression (); |
|
561 |
|
562 if (e) |
|
563 { |
|
564 if (e->is_assignment_expression ()) |
|
565 { |
|
566 // The parser builds an assignment to |
|
567 // __retval__, and we don't want to |
|
568 // display that part. |
|
569 |
|
570 tree_simple_assignment *tsa |
|
571 = reinterpret_cast <tree_simple_assignment *> (e); |
|
572 tree_expression *rhs = tsa->right_hand_side (); |
|
573 |
|
574 if (rhs) |
|
575 rhs->accept (tpc); |
|
576 } |
|
577 else |
|
578 e->accept (tpc); |
|
579 } |
|
580 } |
|
581 else |
|
582 { |
|
583 tree_command *c = s->command (); |
|
584 |
|
585 tpc.suspend_newline (); |
|
586 c->accept (tpc); |
|
587 tpc.resume_newline (); |
|
588 } |
|
589 } |
|
590 } |
|
591 |
|
592 printed = true; |
|
593 } |
|
594 } |
|
595 |
|
596 if (! printed) |
|
597 octave_print_internal (os, nm, pr_as_read_syntax, |
|
598 current_print_indent_level ()); |
4343
|
599 } |
|
600 |
|
601 octave_value |
|
602 make_fcn_handle (const std::string& nm) |
|
603 { |
|
604 octave_value retval; |
|
605 |
4930
|
606 octave_value f = lookup_function (nm); |
4343
|
607 |
4930
|
608 if (f.is_function ()) |
|
609 retval = octave_value (new octave_fcn_handle (f, nm)); |
4343
|
610 else |
|
611 error ("error creating function handle \"@%s\"", nm.c_str ()); |
|
612 |
|
613 return retval; |
|
614 } |
|
615 |
4933
|
616 DEFUN (functions, args, , |
4343
|
617 "-*- texinfo -*-\n\ |
4933
|
618 @deftypefn {Built-in Function} {} functions (@var{fcn_handle})\n\ |
|
619 Return a struct containing information about the function handle\n\ |
|
620 @var{fcn_handle}.\n\ |
|
621 @end deftypefn") |
4343
|
622 { |
|
623 octave_value retval; |
|
624 |
4933
|
625 if (args.length () == 1) |
4343
|
626 { |
4933
|
627 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4343
|
628 |
|
629 if (! error_state) |
|
630 { |
4933
|
631 octave_function *fcn = fh ? fh->function_value (true) : 0; |
4343
|
632 |
4933
|
633 if (fcn) |
4930
|
634 { |
4933
|
635 Octave_map m; |
4649
|
636 |
4933
|
637 std::string fh_nm = fh->fcn_name (); |
|
638 |
4978
|
639 m.assign ("function", fh_nm); |
4343
|
640 |
4933
|
641 if (fcn->is_nested_function ()) |
|
642 m.assign ("type", "subfunction"); |
|
643 else |
|
644 m.assign ("type", "simple"); |
|
645 |
|
646 std::string nm = fcn->fcn_file_name (); |
4343
|
647 |
4933
|
648 if (nm.empty ()) |
4935
|
649 { |
|
650 if (fh_nm == "@<anonymous>") |
|
651 m.assign ("file", "none"); |
5313
|
652 else if (fcn->is_user_function ()) |
|
653 m.assign ("file", "command-line function"); |
4935
|
654 else |
|
655 m.assign ("file", "built-in function"); |
|
656 } |
4343
|
657 else |
4933
|
658 m.assign ("file", nm); |
|
659 |
|
660 retval = m; |
4343
|
661 } |
|
662 else |
4933
|
663 error ("functions: invalid function handle object"); |
4343
|
664 } |
|
665 else |
4933
|
666 error ("functions: argument must be a function handle object"); |
4343
|
667 } |
|
668 else |
5823
|
669 print_usage (); |
4343
|
670 |
|
671 return retval; |
|
672 } |
|
673 |
4933
|
674 DEFUN (func2str, args, , |
4343
|
675 "-*- texinfo -*-\n\ |
4933
|
676 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\ |
|
677 Return a string containing the name of the function referenced by\n\ |
|
678 the function handle @var{fcn_handle}.\n\ |
|
679 @end deftypefn") |
4343
|
680 { |
|
681 octave_value retval; |
|
682 |
4933
|
683 if (args.length () == 1) |
4930
|
684 { |
4933
|
685 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4930
|
686 |
4933
|
687 if (! error_state && fh) |
|
688 { |
|
689 std::string fh_nm = fh->fcn_name (); |
4978
|
690 retval = fh_nm; |
4933
|
691 } |
4343
|
692 else |
4933
|
693 error ("func2str: expecting valid function handle as first argument"); |
4343
|
694 } |
|
695 else |
5823
|
696 print_usage (); |
4343
|
697 |
|
698 return retval; |
|
699 } |
|
700 |
4933
|
701 DEFUN (str2func, args, , |
4343
|
702 "-*- texinfo -*-\n\ |
4933
|
703 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\ |
|
704 Return a function handle constructed from the string @var{fcn_name}.\n\ |
|
705 @end deftypefn") |
4343
|
706 { |
|
707 octave_value retval; |
|
708 |
4933
|
709 if (args.length () == 1) |
4343
|
710 { |
4933
|
711 std::string nm = args(0).string_value (); |
4343
|
712 |
4933
|
713 if (! error_state) |
|
714 retval = make_fcn_handle (nm); |
4343
|
715 else |
4933
|
716 error ("str2func: expecting string as first argument"); |
4343
|
717 } |
|
718 else |
5823
|
719 print_usage (); |
4343
|
720 |
|
721 return retval; |
|
722 } |
|
723 |
|
724 /* |
|
725 ;;; Local Variables: *** |
|
726 ;;; mode: C++ *** |
|
727 ;;; End: *** |
|
728 */ |