2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "Array-flags.h" |
|
32 |
|
33 #include "ov.h" |
|
34 #include "ov-base.h" |
|
35 #include "ov-scalar.h" |
|
36 #include "ov-re-mat.h" |
|
37 #include "ov-complex.h" |
|
38 #include "ov-cx-mat.h" |
|
39 #include "ov-ch-mat.h" |
|
40 #include "ov-str-mat.h" |
|
41 #include "ov-range.h" |
|
42 #include "ov-struct.h" |
|
43 #include "ov-colon.h" |
|
44 #include "ov-va-args.h" |
|
45 #include "ov-typeinfo.h" |
|
46 |
|
47 #include "defun.h" |
|
48 #include "gripes.h" |
|
49 #include "pager.h" |
|
50 #include "pr-output.h" |
|
51 #include "utils.h" |
|
52 #include "variables.h" |
|
53 |
|
54 // If TRUE, allow assignments like |
|
55 // |
|
56 // octave> A(1) = 3; A(2) = 5 |
|
57 // |
|
58 // for A already defined and a matrix type. |
|
59 bool Vdo_fortran_indexing; |
|
60 |
|
61 // Should we allow things like: |
|
62 // |
|
63 // octave> 'abc' + 0 |
|
64 // 97 98 99 |
|
65 // |
|
66 // to happen? A positive value means yes. A negative value means |
|
67 // yes, but print a warning message. Zero means it should be |
|
68 // considered an error. |
|
69 int Vimplicit_str_to_num_ok; |
|
70 |
|
71 // Should we allow silent conversion of complex to real when a real |
|
72 // type is what we're really looking for? A positive value means yes. |
|
73 // A negative value means yes, but print a warning message. Zero |
|
74 // means it should be considered an error. |
|
75 int Vok_to_lose_imaginary_part; |
|
76 |
|
77 // If TRUE, create column vectors when doing assignments like: |
|
78 // |
|
79 // octave> A(1) = 3; A(2) = 5 |
|
80 // |
|
81 // (for A undefined). Only matters when resize_on_range_error is also |
|
82 // TRUE. |
|
83 bool Vprefer_column_vectors; |
|
84 |
|
85 // If TRUE, prefer logical (zore-one) indexing over normal indexing |
|
86 // when there is a conflice. For example, given a = [2, 3], the |
|
87 // expression a ([1, 1]) would return [2 3] (instead of [2 2], which |
|
88 // would be returned if prefer_zero_one_indxing were FALSE). |
|
89 bool Vprefer_zero_one_indexing; |
|
90 |
|
91 // If TRUE, print the name along with the value. |
|
92 bool Vprint_answer_id_name; |
|
93 |
|
94 // Should operations on empty matrices return empty matrices or an |
|
95 // error? A positive value means yes. A negative value means yes, |
|
96 // but print a warning message. Zero means it should be considered an |
|
97 // error. |
|
98 int Vpropagate_empty_matrices; |
|
99 |
|
100 // If TRUE, resize matrices when performing and indexed assignment and |
|
101 // the indices are outside the current bounds. |
|
102 bool Vresize_on_range_error; |
|
103 |
|
104 // How many levels of structure elements should we print? |
|
105 int Vstruct_levels_to_print; |
|
106 |
|
107 // Allow divide by zero errors to be suppressed. |
|
108 bool Vwarn_divide_by_zero; |
|
109 |
|
110 // Indentation level for structures. |
|
111 int struct_indent = 0; |
|
112 |
|
113 // XXX FIXME XXX |
|
114 void |
|
115 increment_struct_indent (void) |
|
116 { |
|
117 struct_indent += 2; |
|
118 } |
|
119 |
|
120 void |
|
121 decrement_struct_indent (void) |
|
122 { |
|
123 struct_indent -= 2; |
|
124 } |
|
125 |
|
126 // Octave's value type. |
|
127 |
|
128 string |
|
129 octave_value::binary_op_as_string (binary_op op) |
|
130 { |
|
131 string retval; |
|
132 |
|
133 switch (op) |
|
134 { |
|
135 case add: |
|
136 retval = "+"; |
|
137 break; |
|
138 |
|
139 case sub: |
|
140 retval = "-"; |
|
141 break; |
|
142 |
|
143 case mul: |
|
144 retval = "*"; |
|
145 break; |
|
146 |
|
147 case div: |
|
148 retval = "/"; |
|
149 break; |
|
150 |
|
151 case pow: |
|
152 retval = "^"; |
|
153 break; |
|
154 |
|
155 case ldiv: |
|
156 retval = "\\"; |
|
157 break; |
|
158 |
|
159 case lt: |
|
160 retval = "<"; |
|
161 break; |
|
162 |
|
163 case le: |
|
164 retval = "<="; |
|
165 break; |
|
166 |
|
167 case eq: |
|
168 retval = "=="; |
|
169 break; |
|
170 |
|
171 case ge: |
|
172 retval = ">="; |
|
173 break; |
|
174 |
|
175 case gt: |
|
176 retval = ">"; |
|
177 break; |
|
178 |
|
179 case ne: |
|
180 retval = "!="; |
|
181 break; |
|
182 |
|
183 case el_mul: |
|
184 retval = ".*"; |
|
185 break; |
|
186 |
|
187 case el_div: |
|
188 retval = "./"; |
|
189 break; |
|
190 |
|
191 case el_pow: |
|
192 retval = ".^"; |
|
193 break; |
|
194 |
|
195 case el_ldiv: |
|
196 retval = ".\\"; |
|
197 break; |
|
198 |
|
199 case el_and: |
|
200 retval = "&"; |
|
201 break; |
|
202 |
|
203 case el_or: |
|
204 retval = "|"; |
|
205 break; |
|
206 |
|
207 case struct_ref: |
|
208 retval = "."; |
|
209 break; |
|
210 |
|
211 default: |
|
212 retval = "<unknown>"; |
|
213 } |
|
214 |
|
215 return retval; |
|
216 } |
|
217 |
|
218 octave_value::octave_value (void) |
|
219 : rep (new octave_base_value ()) { rep->count = 1; } |
|
220 |
|
221 octave_value::octave_value (double d) |
|
222 : rep (new octave_scalar (d)) { rep->count = 1; } |
|
223 |
|
224 octave_value::octave_value (const Matrix& m) |
|
225 : rep (new octave_matrix (m)) { rep->count = 1; } |
|
226 |
|
227 octave_value::octave_value (const DiagMatrix& d) |
|
228 : rep (new octave_matrix (d)) { rep->count = 1; } |
|
229 |
|
230 octave_value::octave_value (const RowVector& v, int pcv) |
|
231 : rep (new octave_matrix (v, pcv)) { rep->count = 1; } |
|
232 |
|
233 octave_value::octave_value (const ColumnVector& v, int pcv) |
|
234 : rep (new octave_matrix (v, pcv)) { rep->count = 1; } |
|
235 |
|
236 octave_value::octave_value (const Complex& C) |
|
237 : rep (new octave_complex (C)) { rep->count = 1; } |
|
238 |
|
239 octave_value::octave_value (const ComplexMatrix& m) |
|
240 : rep (new octave_complex_matrix (m)) { rep->count = 1; } |
|
241 |
|
242 octave_value::octave_value (const ComplexDiagMatrix& d) |
|
243 : rep (new octave_complex_matrix (d)) { rep->count = 1; } |
|
244 |
|
245 octave_value::octave_value (const ComplexRowVector& v, int pcv) |
|
246 : rep (new octave_complex_matrix (v, pcv)) { rep->count = 1; } |
|
247 |
|
248 octave_value::octave_value (const ComplexColumnVector& v, int pcv) |
|
249 : rep (new octave_complex_matrix (v, pcv)) { rep->count = 1; } |
|
250 |
|
251 octave_value::octave_value (const char *s) |
|
252 : rep (new octave_char_matrix_str (s)) { rep->count = 1; } |
|
253 |
|
254 octave_value::octave_value (const string& s) |
|
255 : rep (new octave_char_matrix_str (s)) { rep->count = 1; } |
|
256 |
|
257 octave_value::octave_value (const string_vector& s) |
|
258 : rep (new octave_char_matrix_str (s)) { rep->count = 1; } |
|
259 |
|
260 octave_value::octave_value (const charMatrix& chm, bool is_string) |
2409
|
261 : rep (0) |
|
262 { |
|
263 if (is_string) |
|
264 rep = new octave_char_matrix_str (chm); |
|
265 else |
|
266 rep = new octave_char_matrix (chm); |
2376
|
267 |
2409
|
268 rep->count = 1; |
|
269 } |
2376
|
270 |
|
271 octave_value::octave_value (double base, double limit, double inc) |
|
272 : rep (new octave_range (base, limit, inc)) { rep->count = 1; } |
|
273 |
|
274 octave_value::octave_value (const Range& r) |
|
275 : rep (new octave_range (r)) { rep->count = 1; } |
|
276 |
|
277 octave_value::octave_value (const Octave_map& m) |
|
278 : rep (new octave_struct (m)) { rep->count = 1; } |
|
279 |
|
280 octave_value::octave_value (octave_value::magic_colon) |
|
281 : rep (new octave_magic_colon ()) { rep->count = 1; } |
|
282 |
|
283 octave_value::octave_value (octave_value::all_va_args) |
|
284 : rep (new octave_all_va_args ()) { rep->count = 1; } |
|
285 |
|
286 octave_value::octave_value (octave_value *new_rep) |
|
287 : rep (new_rep) { rep->count = 1; } |
|
288 |
|
289 octave_value::~octave_value (void) |
|
290 { |
|
291 #if defined (MDEBUG) |
|
292 cerr << "~octave_value: rep: " << rep |
|
293 << " rep->count: " << rep->count << "\n"; |
|
294 #endif |
|
295 |
|
296 if (rep && --rep->count == 0) |
|
297 { |
|
298 delete rep; |
|
299 rep = 0; |
|
300 } |
|
301 } |
|
302 |
2409
|
303 void |
|
304 octave_value::maybe_mutate (void) |
|
305 { |
2410
|
306 octave_value *tmp = rep->try_narrowing_conversion (); |
2409
|
307 |
|
308 if (tmp && tmp != rep) |
|
309 { |
|
310 if (--rep->count == 0) |
|
311 delete rep; |
|
312 |
|
313 rep = tmp; |
|
314 rep->count = 1; |
|
315 } |
|
316 } |
|
317 |
2376
|
318 static void |
|
319 gripe_no_conversion (const string& tn1, const string& tn2) |
|
320 { |
|
321 error ("no suitable conversion found for assignment of %s to indexed %s", |
|
322 tn2.c_str (), tn1.c_str ()); |
|
323 } |
|
324 |
2409
|
325 octave_value& |
|
326 octave_value::assign (const octave_value_list& idx, const octave_value& rhs) |
|
327 { |
|
328 make_unique (); |
2376
|
329 |
2409
|
330 bool assignment_ok = try_assignment (idx, rhs); |
|
331 |
|
332 if (! (error_state || assignment_ok)) |
|
333 { |
|
334 assignment_ok = try_assignment_with_conversion (idx, rhs); |
|
335 |
|
336 if (! (error_state || assignment_ok)) |
2376
|
337 gripe_no_conversion (type_name (), rhs.type_name ()); |
|
338 } |
|
339 |
2409
|
340 if (! error_state) |
|
341 maybe_mutate (); |
|
342 |
2376
|
343 return *this; |
|
344 } |
|
345 |
|
346 Octave_map |
|
347 octave_value::map_value (void) const |
|
348 { |
|
349 return rep->map_value (); |
|
350 } |
|
351 |
|
352 ColumnVector |
|
353 octave_value::vector_value (bool force_string_conv, |
|
354 bool force_vector_conversion) const |
|
355 { |
|
356 ColumnVector retval; |
|
357 |
|
358 Matrix m = matrix_value (force_string_conv); |
|
359 |
|
360 if (error_state) |
|
361 return retval; |
|
362 |
|
363 int nr = m.rows (); |
|
364 int nc = m.columns (); |
|
365 |
|
366 if (nr == 1) |
|
367 { |
|
368 retval.resize (nc); |
|
369 for (int i = 0; i < nc; i++) |
|
370 retval (i) = m (0, i); |
|
371 } |
|
372 else if (nc == 1) |
|
373 { |
|
374 retval.resize (nr); |
|
375 for (int i = 0; i < nr; i++) |
|
376 retval (i) = m (i, 0); |
|
377 } |
|
378 else if (nr > 0 && nc > 0 |
|
379 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
380 { |
|
381 retval.resize (nr * nc); |
|
382 int k = 0; |
|
383 for (int j = 0; j < nc; j++) |
|
384 for (int i = 0; i < nr; i++) |
|
385 retval (k++) = m (i, j); |
|
386 } |
|
387 else |
|
388 { |
|
389 string tn = type_name (); |
|
390 gripe_invalid_conversion (tn.c_str (), "real vector"); |
|
391 } |
|
392 |
|
393 return retval; |
|
394 } |
|
395 |
|
396 ComplexColumnVector |
|
397 octave_value::complex_vector_value (bool force_string_conv, |
|
398 bool force_vector_conversion) const |
|
399 { |
|
400 ComplexColumnVector retval; |
|
401 |
|
402 ComplexMatrix m = complex_matrix_value (force_string_conv); |
|
403 |
|
404 if (error_state) |
|
405 return retval; |
|
406 |
|
407 int nr = m.rows (); |
|
408 int nc = m.columns (); |
|
409 |
|
410 if (nr == 1) |
|
411 { |
|
412 retval.resize (nc); |
|
413 for (int i = 0; i < nc; i++) |
|
414 retval (i) = m (0, i); |
|
415 } |
|
416 else if (nc == 1) |
|
417 { |
|
418 retval.resize (nr); |
|
419 for (int i = 0; i < nr; i++) |
|
420 retval (i) = m (i, 0); |
|
421 } |
|
422 else if (nr > 0 && nc > 0 |
|
423 && (Vdo_fortran_indexing || force_vector_conversion)) |
|
424 { |
|
425 retval.resize (nr * nc); |
|
426 int k = 0; |
|
427 for (int j = 0; j < nc; j++) |
|
428 for (int i = 0; i < nr; i++) |
|
429 retval (k++) = m (i, j); |
|
430 } |
|
431 else |
|
432 { |
|
433 string tn = type_name (); |
|
434 gripe_invalid_conversion (tn.c_str (), "complex vector"); |
|
435 } |
|
436 |
|
437 return retval; |
|
438 } |
|
439 |
|
440 void |
|
441 octave_value::print (void) |
|
442 { |
|
443 print (octave_stdout); |
|
444 } |
|
445 |
|
446 void |
|
447 octave_value::print_with_name (const string& name, bool print_padding) |
|
448 { |
|
449 print_with_name (octave_stdout, name, print_padding); |
|
450 } |
|
451 |
|
452 void |
|
453 octave_value::print_with_name (ostream& output_buf, const string& name, |
|
454 bool print_padding) |
|
455 { |
|
456 bool pad_after = false; |
|
457 |
|
458 if (Vprint_answer_id_name) |
|
459 { |
|
460 if (print_as_scalar ()) |
|
461 output_buf << name << " = "; |
|
462 else if (print_as_structure ()) |
|
463 { |
|
464 pad_after = true; |
|
465 output_buf << name << " ="; |
|
466 } |
|
467 else |
|
468 { |
|
469 pad_after = true; |
|
470 output_buf << name << " =\n\n"; |
|
471 } |
|
472 } |
|
473 |
|
474 print (output_buf); |
|
475 |
|
476 if (print_padding && pad_after) |
|
477 output_buf << "\n"; |
|
478 } |
|
479 |
|
480 bool |
|
481 octave_value::print_as_scalar (void) |
|
482 { |
|
483 int nr = rows (); |
|
484 int nc = columns (); |
|
485 |
|
486 return (is_scalar_type () |
|
487 || (is_string () && nr <= 1) |
|
488 || (is_matrix_type () |
|
489 && ((nr == 1 && nc == 1) |
|
490 || nr == 0 |
|
491 || nc == 0))); |
|
492 } |
|
493 |
|
494 static void |
2413
|
495 gripe_indexed_assignment (const string& tn1, const string& tn2) |
|
496 { |
|
497 error ("assignment of %s to indexed %s not implemented", |
|
498 tn2.c_str (), tn1.c_str ()); |
|
499 } |
|
500 |
|
501 static void |
|
502 gripe_conversion_failed (const string& tn1, const string& tn2) |
|
503 { |
|
504 error ("type conversion for assignment of %s to indexed %s failed", |
|
505 tn2.c_str (), tn1.c_str ()); |
|
506 } |
|
507 |
|
508 bool |
|
509 octave_value::convert_and_assign (const octave_value_list& idx, |
|
510 const octave_value& rhs) |
|
511 { |
|
512 bool assignment_ok = false; |
|
513 |
|
514 int t_lhs = type_id (); |
|
515 int t_rhs = rhs.type_id (); |
|
516 |
|
517 int t_result |
|
518 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
519 |
|
520 if (t_result >= 0) |
|
521 { |
|
522 octave_value::type_conv_fcn cf |
|
523 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
524 |
|
525 if (cf) |
|
526 { |
|
527 octave_value *tmp = cf (*rep); |
|
528 |
|
529 if (tmp) |
|
530 { |
|
531 if (tmp != rep) |
|
532 { |
|
533 if (--rep->count == 0) |
|
534 delete rep; |
|
535 |
|
536 rep = tmp; |
|
537 rep->count = 1; |
|
538 } |
|
539 else |
|
540 delete tmp; |
|
541 |
|
542 assignment_ok = try_assignment (idx, rhs); |
|
543 } |
|
544 else |
|
545 gripe_conversion_failed (type_name (), rhs.type_name ()); |
|
546 } |
|
547 else |
|
548 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
549 } |
|
550 |
|
551 return (assignment_ok && ! error_state); |
|
552 } |
|
553 |
|
554 bool |
|
555 octave_value::try_assignment_with_conversion (const octave_value_list& idx, |
|
556 const octave_value& rhs) |
|
557 { |
|
558 bool assignment_ok = convert_and_assign (idx, rhs); |
|
559 |
|
560 if (! (error_state || assignment_ok)) |
|
561 { |
|
562 octave_value tmp_rhs; |
|
563 octave_value::type_conv_fcn cf_rhs = rhs.numeric_conversion_function (); |
|
564 |
|
565 if (cf_rhs) |
|
566 tmp_rhs = octave_value (cf_rhs (*rhs.rep)); |
|
567 else |
|
568 tmp_rhs = rhs; |
|
569 |
|
570 octave_value *old_rep = 0; |
|
571 octave_value::type_conv_fcn cf_this = numeric_conversion_function (); |
|
572 |
|
573 if (cf_this) |
|
574 { |
|
575 old_rep = rep; |
|
576 rep = cf_this (*rep); |
|
577 rep->count = 1; |
|
578 } |
|
579 |
|
580 cerr << type_name () << "\n"; |
|
581 cerr << tmp_rhs.type_name () << "\n"; |
|
582 |
|
583 if (cf_this || cf_rhs) |
|
584 { |
|
585 assignment_ok = try_assignment (idx, tmp_rhs); |
|
586 |
|
587 if (! (error_state || assignment_ok)) |
|
588 assignment_ok = convert_and_assign (idx, tmp_rhs); |
|
589 } |
|
590 |
|
591 if (! assignment_ok && old_rep) |
|
592 { |
|
593 if (--rep->count == 0) |
|
594 delete rep; |
|
595 |
|
596 rep = old_rep; |
|
597 old_rep = 0; |
|
598 } |
|
599 |
|
600 if (old_rep && --old_rep->count == 0) |
|
601 delete old_rep; |
|
602 } |
|
603 |
|
604 return (assignment_ok && ! error_state); |
|
605 } |
|
606 |
|
607 bool |
|
608 octave_value::try_assignment (const octave_value_list& idx, |
|
609 const octave_value& rhs) |
|
610 { |
|
611 bool retval = false; |
|
612 |
|
613 int t_lhs = type_id (); |
|
614 int t_rhs = rhs.type_id (); |
|
615 |
|
616 octave_value::assign_op_fcn f |
|
617 = octave_value_typeinfo::lookup_assign_op (t_lhs, t_rhs); |
|
618 |
|
619 if (f) |
|
620 { |
|
621 f (*rep, idx, *(rhs.rep)); |
|
622 |
|
623 retval = (! error_state); |
|
624 } |
|
625 |
|
626 return retval; |
|
627 } |
|
628 |
|
629 static void |
2376
|
630 gripe_binary_op (const string& on, const string& tn1, const string& tn2) |
|
631 { |
|
632 error ("binary operator %s not implemented for %s by %s operations", |
|
633 on.c_str (), tn1.c_str (), tn2.c_str ()); |
|
634 } |
|
635 |
|
636 octave_value |
|
637 do_binary_op (octave_value::binary_op op, const octave_value& v1, |
|
638 const octave_value& v2) |
|
639 { |
|
640 octave_value retval; |
|
641 |
|
642 int t1 = v1.type_id (); |
|
643 int t2 = v2.type_id (); |
|
644 |
|
645 octave_value::binary_op_fcn f |
|
646 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
|
647 |
|
648 if (f) |
|
649 retval = f (*v1.rep, *v2.rep); |
|
650 else |
|
651 { |
|
652 octave_value tv1; |
2409
|
653 octave_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
2376
|
654 |
|
655 if (cf1) |
|
656 { |
|
657 tv1 = octave_value (cf1 (*v1.rep)); |
|
658 t1 = tv1.type_id (); |
|
659 } |
|
660 else |
|
661 tv1 = v1; |
|
662 |
|
663 octave_value tv2; |
2409
|
664 octave_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
2376
|
665 |
|
666 if (cf2) |
|
667 { |
|
668 tv2 = octave_value (cf2 (*v2.rep)); |
|
669 t2 = tv2.type_id (); |
|
670 } |
|
671 else |
|
672 tv2 = v2; |
|
673 |
|
674 if (cf1 || cf2) |
|
675 { |
|
676 octave_value::binary_op_fcn f |
|
677 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
|
678 |
|
679 if (f) |
|
680 retval = f (*tv1.rep, *tv2.rep); |
|
681 else |
|
682 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
683 v1.type_name (), v2.type_name ()); |
|
684 } |
|
685 else |
|
686 gripe_binary_op (octave_value::binary_op_as_string (op), |
|
687 v1.type_name (), v2.type_name ()); |
|
688 } |
|
689 |
|
690 return retval; |
|
691 } |
|
692 |
|
693 void |
|
694 install_types (void) |
|
695 { |
|
696 octave_base_value::register_type (); |
|
697 octave_scalar::register_type (); |
|
698 octave_complex::register_type (); |
|
699 octave_matrix::register_type (); |
|
700 octave_complex_matrix::register_type (); |
|
701 octave_range::register_type (); |
|
702 octave_char_matrix::register_type (); |
|
703 octave_char_matrix_str::register_type (); |
|
704 octave_struct::register_type (); |
|
705 octave_all_va_args::register_type (); |
|
706 octave_magic_colon::register_type (); |
|
707 } |
|
708 |
|
709 static int |
|
710 do_fortran_indexing (void) |
|
711 { |
|
712 Vdo_fortran_indexing = check_preference ("do_fortran_indexing"); |
|
713 |
|
714 liboctave_dfi_flag = Vdo_fortran_indexing; |
|
715 |
|
716 return 0; |
|
717 } |
|
718 |
|
719 static int |
|
720 implicit_str_to_num_ok (void) |
|
721 { |
|
722 Vimplicit_str_to_num_ok = check_preference ("implicit_str_to_num_ok"); |
|
723 |
|
724 return 0; |
|
725 } |
|
726 |
|
727 static int |
|
728 ok_to_lose_imaginary_part (void) |
|
729 { |
|
730 Vok_to_lose_imaginary_part = check_preference ("ok_to_lose_imaginary_part"); |
|
731 |
|
732 return 0; |
|
733 } |
|
734 |
|
735 static int |
|
736 prefer_column_vectors (void) |
|
737 { |
|
738 Vprefer_column_vectors |
|
739 = check_preference ("prefer_column_vectors"); |
|
740 |
|
741 liboctave_pcv_flag = Vprefer_column_vectors; |
|
742 |
|
743 return 0; |
|
744 } |
|
745 |
|
746 static int |
|
747 prefer_zero_one_indexing (void) |
|
748 { |
|
749 Vprefer_zero_one_indexing = check_preference ("prefer_zero_one_indexing"); |
|
750 |
|
751 liboctave_pzo_flag = Vprefer_zero_one_indexing; |
|
752 |
|
753 return 0; |
|
754 } |
|
755 |
|
756 static int |
|
757 print_answer_id_name (void) |
|
758 { |
|
759 Vprint_answer_id_name = check_preference ("print_answer_id_name"); |
|
760 |
|
761 return 0; |
|
762 } |
|
763 |
|
764 static int |
|
765 propagate_empty_matrices (void) |
|
766 { |
|
767 Vpropagate_empty_matrices = check_preference ("propagate_empty_matrices"); |
|
768 |
|
769 return 0; |
|
770 } |
|
771 |
|
772 static int |
|
773 resize_on_range_error (void) |
|
774 { |
|
775 Vresize_on_range_error = check_preference ("resize_on_range_error"); |
|
776 |
|
777 liboctave_rre_flag = Vresize_on_range_error; |
|
778 |
|
779 return 0; |
|
780 } |
|
781 |
|
782 static int |
|
783 struct_levels_to_print (void) |
|
784 { |
|
785 double val; |
|
786 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
|
787 && ! xisnan (val)) |
|
788 { |
|
789 int ival = NINT (val); |
|
790 if (ival >= 0 && (double) ival == val) |
|
791 { |
|
792 Vstruct_levels_to_print = ival; |
|
793 return 0; |
|
794 } |
|
795 } |
|
796 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
797 return -1; |
|
798 } |
|
799 |
|
800 static int |
|
801 warn_divide_by_zero (void) |
|
802 { |
|
803 Vwarn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
|
804 |
|
805 return 0; |
|
806 } |
|
807 |
|
808 void |
|
809 symbols_of_value (void) |
|
810 { |
|
811 DEFVAR (do_fortran_indexing, 0.0, 0, do_fortran_indexing, |
|
812 "allow single indices for matrices"); |
|
813 |
|
814 DEFVAR (implicit_str_to_num_ok, 0.0, 0, implicit_str_to_num_ok, |
|
815 "allow implicit string to number conversion"); |
|
816 |
|
817 DEFVAR (ok_to_lose_imaginary_part, "warn", 0, ok_to_lose_imaginary_part, |
|
818 "silently convert from complex to real by dropping imaginary part"); |
|
819 |
|
820 DEFVAR (prefer_column_vectors, 1.0, 0, prefer_column_vectors, |
|
821 "prefer column/row vectors"); |
|
822 |
|
823 DEFVAR (prefer_zero_one_indexing, 0.0, 0, prefer_zero_one_indexing, |
|
824 "when there is a conflict, prefer zero-one style indexing"); |
|
825 |
|
826 DEFVAR (print_answer_id_name, 1.0, 0, print_answer_id_name, |
|
827 "set output style to print `var_name = ...'"); |
|
828 |
|
829 DEFVAR (propagate_empty_matrices, 1.0, 0, propagate_empty_matrices, |
|
830 "operations on empty matrices return an empty matrix, not an error"); |
|
831 |
|
832 DEFVAR (resize_on_range_error, 1.0, 0, resize_on_range_error, |
|
833 "enlarge matrices on assignment"); |
|
834 |
|
835 DEFVAR (struct_levels_to_print, 2.0, 0, struct_levels_to_print, |
|
836 "number of levels of structure elements to print"); |
|
837 |
|
838 DEFVAR (warn_divide_by_zero, 1.0, 0, warn_divide_by_zero, |
|
839 "If TRUE, warn about division by zero"); |
|
840 } |
|
841 |
|
842 /* |
|
843 ;;; Local Variables: *** |
|
844 ;;; mode: C++ *** |
|
845 ;;; End: *** |
|
846 */ |