Mercurial > octave-nkf
annotate src/ov-fcn-inline.cc @ 12642:f96b9b9f141b stable
doc: Periodic grammarcheck and spellcheck of documentation.
* func.txi: Correct two misspellings
* cumtrapz.m, dblquad.m, quadgk.m, quadl.m, quadv.m, trapz.m, triplequad.m,
cond.m, gmres.m, bzip2.m, compare_versions.m, getappdata.m, unpack.m, ver.m,
glpk.m, pkg.m, axis.m, uigetdir.m, uigetfile.m, view.m, prctile.m, quantile.m,
unidcdf.m, unidinv.m, isstrprop.m, balance.cc, besselj.cc, cellfun.cc,
colamd.cc, dot.cc, eigs.cc, fftw.cc, matrix_type.cc, pinv.cc, qr.cc, quad.cc,
quadcc.cc, qz.cc, regexp.cc, schur.cc, time.cc (gmtime), typecast.cc
urlwrite.cc bitfcns.cc (bitshift), data.cc (rem, norm, merge) debug.cc
(dbstatus), dirfns.cc (glob), file-io.cc (freport), load-path.cc (genpath),
load-save.cc (save), mappers.cc (islower, isupper, tolower, toupper)
oct-hist.cc (edit_history), ov-fcn-inline.cc (vectorize), ov.cc (subsref),
syscalls.cc (stat), variables.cc (whos, clear): Improve docstrings.
Removed trailing whitespace characters on line.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 01 May 2011 11:39:50 -0700 |
parents | 2dbac27e0e40 |
children | ebf41239e47e |
rev | line source |
---|---|
4933 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2004-2011 David Bateman |
4933 | 4 |
7016 | 5 This file is part of Octave. |
4933 | 6 |
7016 | 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 3 of the License, or (at your | |
10 option) any 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. | |
4933 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4933 | 20 |
21 In addition to the terms of the GPL, you are permitted to link | |
22 this program with any Open Source program, as defined by the | |
23 Open Source Initiative (www.opensource.org) | |
24 | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
4988 | 31 #include <istream> |
4933 | 32 #include <iostream> |
5765 | 33 #include <sstream> |
5164 | 34 #include <vector> |
4933 | 35 |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
36 #include "oct-locbuf.h" |
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
37 |
4933 | 38 #include "defun.h" |
39 #include "error.h" | |
40 #include "gripes.h" | |
41 #include "oct-map.h" | |
42 #include "ov-base.h" | |
43 #include "ov-fcn-inline.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
44 #include "ov-usr-fcn.h" |
4933 | 45 #include "pr-output.h" |
46 #include "variables.h" | |
47 #include "parse.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
48 #include "toplev.h" |
4933 | 49 |
4972 | 50 #include "byte-swap.h" |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
51 #include "ls-ascii-helper.h" |
4972 | 52 #include "ls-oct-ascii.h" |
53 #include "ls-hdf5.h" | |
54 #include "ls-utils.h" | |
55 | |
4933 | 56 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_inline); |
57 | |
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_inline, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
59 "inline function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 "function_handle"); |
4933 | 61 |
62 octave_fcn_inline::octave_fcn_inline (const std::string& f, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
63 const string_vector& a, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 const std::string& n) |
5007 | 65 : octave_fcn_handle (n), iftext (f), ifargs (a) |
4933 | 66 { |
4973 | 67 // Form a string representing the function. |
4933 | 68 |
5765 | 69 std::ostringstream buf; |
4933 | 70 |
5007 | 71 buf << "@("; |
4933 | 72 |
73 for (int i = 0; i < ifargs.length (); i++) | |
74 { | |
75 if (i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 buf << ", "; |
4933 | 77 |
78 buf << ifargs(i); | |
79 } | |
80 | |
5765 | 81 buf << ") " << iftext; |
4933 | 82 |
5007 | 83 int parse_status; |
5765 | 84 octave_value anon_fcn_handle = eval_string (buf.str (), true, parse_status); |
4933 | 85 |
5007 | 86 if (parse_status == 0) |
4933 | 87 { |
5007 | 88 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
4933 | 89 |
5007 | 90 if (fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 fcn = fh->fcn_val (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
93 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
94 octave_user_function *uf = fcn.user_function_value (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
95 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 octave_function *curr_fcn = octave_call_stack::current (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
99 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 if (curr_fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 symbol_table::scope_id parent_scope |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 = curr_fcn->parent_fcn_scope (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 if (parent_scope < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 parent_scope = curr_fcn->scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 uf->stash_parent_fcn_scope (parent_scope); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 } |
4933 | 112 } |
5007 | 113 |
114 if (fcn.is_undefined ()) | |
4933 | 115 error ("inline: unable to define function"); |
116 } | |
117 | |
6625 | 118 // This function is supplied to allow a Matlab style class structure |
119 // to be returned.. | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
120 octave_map |
6625 | 121 octave_fcn_inline::map_value (void) const |
122 { | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
123 octave_scalar_map m; |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
124 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
125 m.assign ("version", 1.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
126 m.assign ("isEmpty", 0.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
127 m.assign ("expr", fcn_text ()); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
128 |
6625 | 129 string_vector args = fcn_arg_names (); |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
130 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
131 m.assign ("numArgs", args.length ()); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
132 m.assign ("args", args); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
133 |
6625 | 134 std::ostringstream buf; |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
135 |
6625 | 136 for (int i = 0; i < args.length (); i++) |
137 buf << args(i) << " = INLINE_INPUTS_{" << i + 1 << "}; "; | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
138 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
139 m.assign ("inputExpr", buf.str ()); |
6625 | 140 |
141 return m; | |
142 } | |
143 | |
4972 | 144 bool |
6974 | 145 octave_fcn_inline::save_ascii (std::ostream& os) |
4972 | 146 { |
4973 | 147 os << "# nargs: " << ifargs.length () << "\n"; |
4972 | 148 for (int i = 0; i < ifargs.length (); i++) |
4973 | 149 os << ifargs(i) << "\n"; |
150 if (nm.length () < 1) | |
151 // Write an invalid value to flag empty fcn handle name. | |
4972 | 152 os << "0\n"; |
153 else | |
154 os << nm << "\n"; | |
155 os << iftext << "\n"; | |
156 return true; | |
157 } | |
158 | |
159 bool | |
160 octave_fcn_inline::load_ascii (std::istream& is) | |
161 { | |
162 int nargs; | |
163 if (extract_keyword (is, "nargs", nargs, true)) | |
164 { | |
165 ifargs.resize (nargs); | |
166 for (int i = 0; i < nargs; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 is >> ifargs(i); |
4972 | 168 is >> nm; |
169 if (nm == "0") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 nm = ""; |
4988 | 171 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
172 skip_preceeding_newline (is); |
4988 | 173 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
174 std::string buf; |
4988 | 175 |
176 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 { |
4988 | 178 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 // Get a line of text whitespace characters included, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 // leaving newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 buf = read_until_newline (is, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 } |
4988 | 183 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
184 iftext = buf; |
4972 | 185 |
186 octave_fcn_inline tmp (iftext, ifargs, nm); | |
187 fcn = tmp.fcn; | |
188 | |
189 return true; | |
190 } | |
191 else | |
192 return false; | |
193 } | |
194 | |
4973 | 195 bool |
4972 | 196 octave_fcn_inline::save_binary (std::ostream& os, bool&) |
197 { | |
5828 | 198 int32_t tmp = ifargs.length (); |
5760 | 199 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 200 for (int i = 0; i < ifargs.length (); i++) |
4972 | 201 { |
4973 | 202 tmp = ifargs(i).length (); |
5760 | 203 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 204 os.write (ifargs(i).c_str (), ifargs(i).length ()); |
4972 | 205 } |
4973 | 206 tmp = nm.length (); |
5760 | 207 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 208 os.write (nm.c_str (), nm.length ()); |
209 tmp = iftext.length (); | |
5760 | 210 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 211 os.write (iftext.c_str (), iftext.length ()); |
4972 | 212 return true; |
213 } | |
214 | |
4973 | 215 bool |
4972 | 216 octave_fcn_inline::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 oct_mach_info::float_format) |
4972 | 218 { |
5828 | 219 int32_t nargs; |
5760 | 220 if (! is.read (reinterpret_cast<char *> (&nargs), 4)) |
4972 | 221 return false; |
222 if (swap) | |
223 swap_bytes<4> (&nargs); | |
224 | |
225 if (nargs < 1) | |
226 return false; | |
227 else | |
228 { | |
5828 | 229 int32_t tmp; |
4973 | 230 ifargs.resize (nargs); |
4972 | 231 for (int i = 0; i < nargs; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
233 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 swap_bytes<4> (&tmp); |
4972 | 237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 is.read (ctmp, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 ifargs(i) = std::string (ctmp); |
4972 | 241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 } |
4972 | 245 |
5760 | 246 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 return false; |
4972 | 248 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 swap_bytes<4> (&tmp); |
4972 | 250 |
251 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
252 is.read (ctmp1, tmp); | |
253 nm = std::string (ctmp1); | |
254 | |
255 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 return false; |
4972 | 257 |
5760 | 258 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 return false; |
4972 | 260 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 swap_bytes<4> (&tmp); |
4972 | 262 |
263 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
264 is.read (ctmp2, tmp); | |
265 iftext = std::string (ctmp2); | |
266 | |
267 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 return false; |
4972 | 269 |
270 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
271 fcn = ftmp.fcn; | |
272 } | |
273 return true; | |
274 } | |
275 | |
276 #if defined (HAVE_HDF5) | |
277 bool | |
278 octave_fcn_inline::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 bool /* save_as_floats */) |
4972 | 280 { |
281 hid_t group_hid = -1; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
282 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
283 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
284 #else |
4972 | 285 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
286 #endif |
4972 | 287 if (group_hid < 0 ) return false; |
288 | |
289 size_t len = 0; | |
4973 | 290 for (int i = 0; i < ifargs.length (); i++) |
291 if (len < ifargs(i).length ()) | |
292 len = ifargs(i).length (); | |
4972 | 293 |
294 hid_t space_hid = -1, data_hid = -1, type_hid = -1;; | |
295 bool retval = true; | |
296 | |
5775 | 297 // FIXME Is there a better way of saving string vectors, than a |
4972 | 298 // null padded matrix? |
299 | |
300 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
301 | |
302 // Octave uses column-major, while HDF5 uses row-major ordering | |
4973 | 303 hdims[1] = ifargs.length (); |
4972 | 304 hdims[0] = len + 1; |
305 | |
306 space_hid = H5Screate_simple (2, hdims, 0); | |
307 if (space_hid < 0) | |
308 { | |
309 H5Gclose (group_hid); | |
310 return false; | |
311 } | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
312 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
313 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
315 #else |
4973 | 316 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
317 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
318 #endif |
4972 | 319 if (data_hid < 0) |
320 { | |
321 H5Sclose (space_hid); | |
322 H5Gclose (group_hid); | |
323 return false; | |
324 } | |
325 | |
4973 | 326 OCTAVE_LOCAL_BUFFER (char, s, ifargs.length () * (len + 1)); |
4972 | 327 |
328 // Save the args as a null teminated list | |
4973 | 329 for (int i = 0; i < ifargs.length (); i++) |
4972 | 330 { |
4973 | 331 const char * cptr = ifargs(i).c_str (); |
332 for (size_t j = 0; j < ifargs(i).length (); j++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
333 s[i*(len+1)+j] = *cptr++; |
4973 | 334 s[ifargs(i).length ()] = '\0'; |
4972 | 335 } |
336 | |
4973 | 337 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 H5P_DEFAULT, s) >= 0; |
4972 | 339 |
340 H5Dclose (data_hid); | |
341 H5Sclose (space_hid); | |
342 | |
343 if (!retval) | |
344 { | |
345 H5Gclose (group_hid); | |
346 return false; | |
4973 | 347 } |
4972 | 348 |
349 // attach the type of the variable | |
4973 | 350 type_hid = H5Tcopy (H5T_C_S1); |
4972 | 351 H5Tset_size (type_hid, nm.length () + 1); |
352 if (type_hid < 0) | |
353 { | |
354 H5Gclose (group_hid); | |
355 return false; | |
4973 | 356 } |
4972 | 357 |
358 hdims[0] = 0; | |
5760 | 359 space_hid = H5Screate_simple (0 , hdims, 0); |
4972 | 360 if (space_hid < 0) |
361 { | |
362 H5Tclose (type_hid); | |
363 H5Gclose (group_hid); | |
364 return false; | |
4973 | 365 } |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
366 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
367 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
369 #else |
4972 | 370 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
371 #endif |
4973 | 372 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 H5P_DEFAULT, nm.c_str ()) < 0) |
4972 | 374 { |
375 H5Sclose (space_hid); | |
376 H5Tclose (type_hid); | |
377 H5Gclose (group_hid); | |
378 return false; | |
4973 | 379 } |
4972 | 380 H5Dclose (data_hid); |
381 | |
382 // attach the type of the variable | |
383 H5Tset_size (type_hid, iftext.length () + 1); | |
384 if (type_hid < 0) | |
385 { | |
386 H5Gclose (group_hid); | |
387 return false; | |
4973 | 388 } |
4972 | 389 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
390 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
391 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
393 #else |
4973 | 394 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
396 #endif |
4973 | 397 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 H5P_DEFAULT, iftext.c_str ()) < 0) |
4972 | 399 { |
400 H5Sclose (space_hid); | |
401 H5Tclose (type_hid); | |
402 H5Gclose (group_hid); | |
403 return false; | |
4973 | 404 } |
4972 | 405 |
406 H5Dclose (data_hid); | |
4988 | 407 H5Sclose (space_hid); |
408 H5Tclose (type_hid); | |
409 H5Gclose (group_hid); | |
4972 | 410 |
411 return retval; | |
412 } | |
413 | |
414 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9038
diff
changeset
|
415 octave_fcn_inline::load_hdf5 (hid_t loc_id, const char *name) |
4972 | 416 { |
417 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; | |
418 hsize_t rank; | |
419 int slen; | |
420 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
421 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
422 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
423 #else |
4972 | 424 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
425 #endif |
4972 | 426 if (group_hid < 0 ) return false; |
427 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
428 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
429 data_hid = H5Dopen (group_hid, "args", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
430 #else |
4972 | 431 data_hid = H5Dopen (group_hid, "args"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
432 #endif |
4972 | 433 space_hid = H5Dget_space (data_hid); |
434 rank = H5Sget_simple_extent_ndims (space_hid); | |
435 | |
436 if (rank != 2) | |
4973 | 437 { |
4972 | 438 H5Dclose (data_hid); |
439 H5Sclose (space_hid); | |
440 H5Gclose (group_hid); | |
441 return false; | |
442 } | |
443 | |
444 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
445 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
446 | |
447 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
448 | |
4973 | 449 ifargs.resize (hdims[1]); |
4972 | 450 |
451 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]); | |
452 | |
4973 | 453 if (H5Dread (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 H5P_DEFAULT, s1) < 0) |
4973 | 455 { |
4972 | 456 H5Dclose (data_hid); |
457 H5Sclose (space_hid); | |
458 H5Gclose (group_hid); | |
459 return false; | |
460 } | |
461 | |
462 H5Dclose (data_hid); | |
463 H5Sclose (space_hid); | |
464 | |
465 for (size_t i = 0; i < hdims[1]; i++) | |
466 ifargs(i) = std::string (s1 + i*hdims[0]); | |
467 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
468 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
469 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
470 #else |
4972 | 471 data_hid = H5Dopen (group_hid, "nm"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
472 #endif |
4972 | 473 |
474 if (data_hid < 0) | |
475 { | |
476 H5Gclose (group_hid); | |
477 return false; | |
478 } | |
479 | |
480 type_hid = H5Dget_type (data_hid); | |
481 type_class_hid = H5Tget_class (type_hid); | |
482 | |
483 if (type_class_hid != H5T_STRING) | |
484 { | |
485 H5Tclose (type_hid); | |
486 H5Dclose (data_hid); | |
487 H5Gclose (group_hid); | |
488 return false; | |
489 } | |
4973 | 490 |
4972 | 491 space_hid = H5Dget_space (data_hid); |
492 rank = H5Sget_simple_extent_ndims (space_hid); | |
493 | |
494 if (rank != 0) | |
495 { | |
496 H5Sclose (space_hid); | |
497 H5Tclose (type_hid); | |
498 H5Dclose (data_hid); | |
499 H5Gclose (group_hid); | |
500 return false; | |
501 } | |
502 | |
503 slen = H5Tget_size (type_hid); | |
504 if (slen < 0) | |
505 { | |
506 H5Sclose (space_hid); | |
507 H5Tclose (type_hid); | |
508 H5Dclose (data_hid); | |
509 H5Gclose (group_hid); | |
510 return false; | |
511 } | |
512 | |
513 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
514 | |
515 // create datatype for (null-terminated) string to read into: | |
516 st_id = H5Tcopy (H5T_C_S1); | |
517 H5Tset_size (st_id, slen); | |
518 | |
5760 | 519 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4972 | 520 { |
521 H5Sclose (space_hid); | |
522 H5Tclose (type_hid); | |
523 H5Gclose (group_hid); | |
524 return false; | |
525 } | |
526 H5Tclose (st_id); | |
527 H5Dclose (data_hid); | |
528 nm = nm_tmp; | |
529 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
530 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
531 data_hid = H5Dopen (group_hid, "iftext", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
532 #else |
4972 | 533 data_hid = H5Dopen (group_hid, "iftext"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
534 #endif |
4972 | 535 |
536 if (data_hid < 0) | |
537 { | |
538 H5Gclose (group_hid); | |
539 return false; | |
540 } | |
541 | |
542 type_hid = H5Dget_type (data_hid); | |
543 type_class_hid = H5Tget_class (type_hid); | |
544 | |
545 if (type_class_hid != H5T_STRING) | |
546 { | |
547 H5Tclose (type_hid); | |
548 H5Dclose (data_hid); | |
549 H5Gclose (group_hid); | |
550 return false; | |
551 } | |
4973 | 552 |
4972 | 553 space_hid = H5Dget_space (data_hid); |
554 rank = H5Sget_simple_extent_ndims (space_hid); | |
555 | |
556 if (rank != 0) | |
557 { | |
558 H5Sclose (space_hid); | |
559 H5Tclose (type_hid); | |
560 H5Dclose (data_hid); | |
561 H5Gclose (group_hid); | |
562 return false; | |
563 } | |
564 | |
565 slen = H5Tget_size (type_hid); | |
566 if (slen < 0) | |
567 { | |
568 H5Sclose (space_hid); | |
569 H5Tclose (type_hid); | |
570 H5Dclose (data_hid); | |
571 H5Gclose (group_hid); | |
572 return false; | |
573 } | |
574 | |
575 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen); | |
576 | |
577 // create datatype for (null-terminated) string to read into: | |
578 st_id = H5Tcopy (H5T_C_S1); | |
579 H5Tset_size (st_id, slen); | |
580 | |
5760 | 581 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, iftext_tmp) < 0) |
4972 | 582 { |
583 H5Sclose (space_hid); | |
584 H5Tclose (type_hid); | |
585 H5Gclose (group_hid); | |
586 return false; | |
587 } | |
588 H5Tclose (st_id); | |
589 H5Dclose (data_hid); | |
590 iftext = iftext_tmp; | |
591 | |
592 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
593 fcn = ftmp.fcn; | |
594 | |
595 return true; | |
596 } | |
597 #endif | |
598 | |
4933 | 599 void |
600 octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) const | |
601 { | |
602 print_raw (os, pr_as_read_syntax); | |
603 newline (os); | |
604 } | |
605 | |
606 void | |
607 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
608 { | |
5765 | 609 std::ostringstream buf; |
4933 | 610 |
611 if (nm.empty ()) | |
612 buf << "f("; | |
613 else | |
614 buf << nm << "("; | |
615 | |
616 for (int i = 0; i < ifargs.length (); i++) | |
617 { | |
618 if (i) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
619 buf << ", "; |
4933 | 620 |
621 buf << ifargs(i); | |
622 } | |
623 | |
5765 | 624 buf << ") = " << iftext; |
4933 | 625 |
5765 | 626 octave_print_internal (os, buf.str (), pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
627 current_print_indent_level ()); |
4933 | 628 } |
629 | |
630 octave_value | |
5279 | 631 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const |
4933 | 632 { |
5279 | 633 return octave_value (fcn_text (), type); |
4933 | 634 } |
635 | |
6973 | 636 DEFUNX ("inline", Finline, args, , |
4933 | 637 "-*- texinfo -*-\n\ |
10840 | 638 @deftypefn {Built-in Function} {} inline (@var{str})\n\ |
6547 | 639 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{arg1}, @dots{})\n\ |
4933 | 640 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{n})\n\ |
641 Create an inline function from the character string @var{str}.\n\ | |
5034 | 642 If called with a single argument, the arguments of the generated\n\ |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
643 function are extracted from the function itself. The generated\n\ |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
644 function arguments will then be in alphabetical order. It should\n\ |
5034 | 645 be noted that i, and j are ignored as arguments due to the\n\ |
646 ambiguity between their use as a variable or their use as an inbuilt\n\ | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
647 constant. All arguments followed by a parenthesis are considered\n\ |
5034 | 648 to be functions.\n\ |
4933 | 649 \n\ |
650 If the second and subsequent arguments are character strings,\n\ | |
651 they are the names of the arguments of the function.\n\ | |
652 \n\ | |
653 If the second argument is an integer @var{n}, the arguments are\n\ | |
654 @code{\"x\"}, @code{\"P1\"}, @dots{}, @code{\"P@var{N}\"}.\n\ | |
5642 | 655 @seealso{argnames, formula, vectorize}\n\ |
656 @end deftypefn") | |
4933 | 657 { |
658 octave_value retval; | |
659 | |
660 int nargin = args.length (); | |
661 | |
662 if (nargin > 0) | |
663 { | |
664 std::string fun = args(0).string_value (); | |
665 | |
666 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
668 string_vector fargs; |
4933 | 669 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 if (nargin == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 bool is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 bool in_string = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
674 std::string tmp_arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
675 size_t i = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
676 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
677 while (i < fun.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
678 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
679 bool terminate_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 char c = fun[i++]; |
4933 | 681 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
682 if (in_string) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 if (c == '\'' || c == '\"') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 in_string = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
687 else if (c == '\'' || c == '\"') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
688 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
689 in_string = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
690 if (is_arg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
691 terminate_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
693 else if (! isalpha (c) && c != '_') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 if (! is_arg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
695 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 else if (isdigit (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 tmp_arg.append (1, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
700 // Before we do anything remove trailing whitespaces. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
701 while (i < fun.length () && isspace (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 c = fun[i++]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
703 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 // Do we have a variable or a function? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 if (c != '(') |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 terminate_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 tmp_arg = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
711 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
712 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
713 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
715 tmp_arg.append (1, c); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 is_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
717 } |
5034 | 718 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 if (terminate_arg || (i == fun.length () && is_arg)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
721 bool have_arg = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
722 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
723 for (int j = 0; j < fargs.length (); j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 if (tmp_arg == fargs (j)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 have_arg = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
729 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 if (! have_arg && tmp_arg != "i" && tmp_arg != "j" && |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
731 tmp_arg != "NaN" && tmp_arg != "nan" && |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
732 tmp_arg != "Inf" && tmp_arg != "inf" && |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 tmp_arg != "NA" && tmp_arg != "pi" && |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
734 tmp_arg != "eps") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
735 fargs.append (tmp_arg); |
5037 | 736 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 tmp_arg = std::string (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 is_arg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
739 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 } |
5034 | 741 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
742 // Sort the arguments into ascii order. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
743 fargs.sort (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
744 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
745 else if (nargin == 2 && args(1).is_numeric_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
746 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 int n = args(1).int_value (); |
4933 | 748 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
749 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
751 if (n >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 fargs.resize (n+1); |
4933 | 754 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 fargs(0) = "x"; |
4933 | 756 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
757 for (int i = 1; i < n+1; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
760 buf << "P" << i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 fargs(i) = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
763 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
766 error ("inline: N must be positive or zero"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
767 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
768 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
769 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
770 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
771 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
772 error ("inline: N must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
774 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
775 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 fargs.resize (nargin - 1); |
4933 | 779 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
780 for (int i = 1; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
782 std::string s = args(i).string_value (); |
4933 | 783 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
784 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
785 fargs(i-1) = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
786 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
787 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 error ("inline: expecting string arguments"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
789 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
792 } |
4933 | 793 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
794 retval = octave_value (new octave_fcn_inline (fun, fargs)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
795 } |
4933 | 796 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
797 error ("inline: STR argument must be a string"); |
4933 | 798 } |
799 else | |
5823 | 800 print_usage (); |
4933 | 801 |
802 return retval; | |
803 } | |
804 | |
7394 | 805 /* |
806 %!shared fn | |
807 %! fn = inline ("x.^2 + 1","x"); | |
808 %!assert (feval (fn, 6), 37) | |
809 %!assert (fn (6), 37) | |
810 */ | |
811 | |
4933 | 812 DEFUN (formula, args, , |
813 "-*- texinfo -*-\n\ | |
814 @deftypefn {Built-in Function} {} formula (@var{fun})\n\ | |
815 Return a character string representing the inline function @var{fun}.\n\ | |
816 Note that @code{char (@var{fun})} is equivalent to\n\ | |
817 @code{formula (@var{fun})}.\n\ | |
5642 | 818 @seealso{argnames, inline, vectorize}\n\ |
819 @end deftypefn") | |
4933 | 820 { |
821 octave_value retval; | |
822 | |
823 int nargin = args.length (); | |
824 | |
825 if (nargin == 1) | |
826 { | |
827 octave_fcn_inline* fn = args(0).fcn_inline_value (true); | |
828 | |
829 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
830 retval = octave_value (fn->fcn_text ()); |
4933 | 831 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
832 error ("formula: FUN must be an inline function"); |
4933 | 833 } |
834 else | |
5823 | 835 print_usage (); |
4933 | 836 |
837 return retval; | |
838 } | |
839 | |
840 DEFUN (argnames, args, , | |
841 "-*- texinfo -*-\n\ | |
842 @deftypefn {Built-in Function} {} argnames (@var{fun})\n\ | |
843 Return a cell array of character strings containing the names of\n\ | |
844 the arguments of the inline function @var{fun}.\n\ | |
6529 | 845 @seealso{inline, formula, vectorize}\n\ |
5642 | 846 @end deftypefn") |
4933 | 847 { |
848 octave_value retval; | |
849 | |
850 int nargin = args.length (); | |
851 | |
852 if (nargin == 1) | |
853 { | |
854 octave_fcn_inline *fn = args(0).fcn_inline_value (true); | |
855 | |
856 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
857 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
858 string_vector t1 = fn->fcn_arg_names (); |
4933 | 859 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
860 Cell t2 (dim_vector (t1.length (), 1)); |
4933 | 861 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
862 for (int i = 0; i < t1.length (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
863 t2(i) = t1(i); |
4933 | 864 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 retval = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 } |
4933 | 867 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
868 error ("argnames: FUN must be an inline function"); |
4933 | 869 } |
870 else | |
5823 | 871 print_usage (); |
4933 | 872 |
873 return retval; | |
874 } | |
875 | |
876 DEFUN (vectorize, args, , | |
877 "-*- texinfo -*-\n\ | |
6635 | 878 @deftypefn {Built-in Function} {} vectorize (@var{fun})\n\ |
4933 | 879 Create a vectorized version of the inline function @var{fun}\n\ |
880 by replacing all occurrences of @code{*}, @code{/}, etc., with\n\ | |
881 @code{.*}, @code{./}, etc.\n\ | |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
882 \n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
883 This may be useful, for example, when using inline functions with\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
884 numerical integration or optimization where a vector-valued function\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
885 is expected.\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
886 \n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
887 @example\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
888 @group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
889 fcn = vectorize (inline (\"x^2 - 1\"))\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
890 @result{} fcn = f(x) = x.^2 - 1\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
891 quadv (fcn, 0, 3)\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
892 @result{} 6\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
893 @end group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
894 @end example\n\ |
5642 | 895 @end deftypefn") |
4933 | 896 { |
897 octave_value retval; | |
898 | |
899 int nargin = args.length (); | |
900 | |
901 if (nargin == 1) | |
902 { | |
5409 | 903 std::string old_func; |
904 octave_fcn_inline* old = 0; | |
905 bool func_is_string = true; | |
4933 | 906 |
5409 | 907 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 old_func = args(0).string_value (); |
5409 | 909 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
910 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 old = args(0).fcn_inline_value (true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
912 func_is_string = false; |
5409 | 913 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 if (old) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
915 old_func = old->fcn_text (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
916 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 error ("vectorize: must be a string or inline function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
918 } |
5409 | 919 |
920 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
922 std::string new_func; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 size_t i = 0; |
4933 | 924 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
925 while (i < old_func.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
926 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
927 std::string t1 = old_func.substr (i, 1); |
4933 | 928 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
929 if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
930 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
931 if (i && old_func.substr (i-1, 1) != ".") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 new_func.append ("."); |
4933 | 933 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
934 // Special case for ** operator. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
935 if (t1 == "*" && i < (old_func.length () - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
936 && old_func.substr (i+1, 1) == "*") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
937 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
938 new_func.append ("*"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
939 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
940 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
941 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
942 new_func.append (t1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
943 i++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
944 } |
4933 | 945 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
946 if (func_is_string) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
947 retval = octave_value (new_func); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
948 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
949 retval = octave_value (new octave_fcn_inline |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
950 (new_func, old->fcn_arg_names ())); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
951 } |
4933 | 952 } |
953 else | |
5823 | 954 print_usage (); |
4933 | 955 |
956 return retval; | |
957 } |