1
|
1 // user-prefs.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #include <string.h> |
|
29 |
|
30 #include "user-prefs.h" |
|
31 #include "error.h" |
|
32 #include "variables.h" |
|
33 #include "utils.h" |
|
34 |
|
35 // The list of user preferences. Values change when global variables |
|
36 // change, so we don\'t have to do a variable look up every time we |
|
37 // need to check a preference. |
|
38 user_preferences user_pref; |
|
39 |
720
|
40 // Initialize global user_pref structure. |
|
41 |
831
|
42 void |
720
|
43 init_user_prefs (void) |
|
44 { |
|
45 user_pref.automatic_replot = 0; |
984
|
46 user_pref.whitespace_in_literal_matrix = 0; |
720
|
47 user_pref.do_fortran_indexing = 0; |
|
48 user_pref.empty_list_elements_ok = 0; |
|
49 user_pref.ignore_function_time_stamp = 0; |
|
50 user_pref.implicit_str_to_num_ok = 0; |
|
51 user_pref.ok_to_lose_imaginary_part = 0; |
|
52 user_pref.output_max_field_width = 0; |
|
53 user_pref.output_precision = 0; |
|
54 user_pref.page_screen_output = 0; |
|
55 user_pref.prefer_column_vectors = 0; |
|
56 user_pref.prefer_zero_one_indexing = 0; |
|
57 user_pref.print_answer_id_name = 0; |
|
58 user_pref.print_empty_dimensions = 0; |
|
59 user_pref.propagate_empty_matrices = 0; |
|
60 user_pref.resize_on_range_error = 0; |
|
61 user_pref.return_last_computed_value = 0; |
|
62 user_pref.save_precision = 0; |
|
63 user_pref.silent_functions = 0; |
|
64 user_pref.split_long_rows = 0; |
|
65 user_pref.treat_neg_dim_as_zero = 0; |
|
66 user_pref.warn_assign_as_truth_value = 0; |
|
67 user_pref.warn_comma_in_global_decl = 0; |
|
68 user_pref.warn_divide_by_zero = 0; |
|
69 |
|
70 user_pref.default_save_format = 0; |
|
71 user_pref.editor = 0; |
|
72 user_pref.gnuplot_binary = 0; |
|
73 user_pref.imagepath = 0; |
|
74 user_pref.info_file = 0; |
|
75 user_pref.loadpath = 0; |
|
76 user_pref.pager_binary = 0; |
|
77 user_pref.ps1 = 0; |
|
78 user_pref.ps2 = 0; |
|
79 user_pref.pwd = 0; |
|
80 } |
661
|
81 |
|
82 // Check the value of a string variable to see if it it's ok to do |
|
83 // something. |
|
84 // |
673
|
85 // return of 1 => always ok. |
|
86 // return of 0 => never ok. |
661
|
87 // return of -1 => ok, but give me warning (default). |
|
88 |
1
|
89 static int |
|
90 check_str_pref (char *var) |
|
91 { |
195
|
92 char *val = builtin_string_variable (var); |
1
|
93 int pref = -1; |
529
|
94 if (val) |
1
|
95 { |
|
96 if (strncmp (val, "yes", 3) == 0 |
|
97 || strncmp (val, "true", 4) == 0) |
|
98 pref = 1; |
|
99 else if (strncmp (val, "never", 5) == 0 |
|
100 || strncmp (val, "no", 2) == 0 |
|
101 || strncmp (val, "false", 5) == 0) |
|
102 pref = 0; |
|
103 } |
|
104 return pref; |
|
105 } |
|
106 |
661
|
107 // Should a replot command be generated automatically each time a plot |
|
108 // changes in some way? |
|
109 |
|
110 int |
|
111 automatic_replot (void) |
|
112 { |
|
113 user_pref.automatic_replot = check_str_pref ("automatic_replot"); |
|
114 |
|
115 return 0; |
|
116 } |
|
117 |
|
118 |
984
|
119 // Should whitespace in a literal matrix list be automatically |
|
120 // converted to commas and semicolons? |
661
|
121 // |
|
122 // user specifies value of pref |
|
123 // -------------- ------------- |
987
|
124 // "ignore" 2 |
661
|
125 // "traditional" 1 |
|
126 // anything else 0 |
|
127 // |
|
128 // Octave will never insert a comma in a literal matrix list if the |
987
|
129 // user specifies "ignore". For example, the statement [1 2] will |
984
|
130 // result in an error instead of being treated the same as [1, 2], and |
|
131 // the statement |
|
132 // |
|
133 // [ 1, 2, |
|
134 // 3, 4 ] |
|
135 // |
|
136 // will result in the vector [1 2 3 4] instead of a matrix. |
661
|
137 // |
|
138 // Traditional behavior makes Octave convert spaces to a comma between |
|
139 // identifiers and `('. For example, the statement |
|
140 // |
|
141 // [eye (2)] |
|
142 // |
|
143 // will be parsed as |
|
144 // |
|
145 // [eye, (2)] |
|
146 // |
|
147 // and will result in an error since the `eye' function will be |
|
148 // called with no arguments. To get around this, you would have to |
|
149 // omit the space between `eye' and the `('. |
|
150 // |
|
151 // The default value is 0, which results in behavior that is the same |
|
152 // as traditional, except that Octave does not convert spaces to a |
|
153 // comma between identifiers and `('. For example, the statement |
|
154 // |
|
155 // [eye (2)] |
|
156 // |
|
157 // will result in a call to `eye' with the argument `2'. |
|
158 |
430
|
159 int |
984
|
160 whitespace_in_literal_matrix (void) |
430
|
161 { |
|
162 int pref = 0; |
984
|
163 char *val = builtin_string_variable ("whitespace_in_literal_matrix"); |
529
|
164 if (val) |
430
|
165 { |
984
|
166 if (strncmp (val, "ignore", 6) == 0) |
430
|
167 pref = 2; |
|
168 else if (strncmp (val, "traditional", 11) == 0) |
|
169 pref = 1; |
|
170 } |
984
|
171 user_pref.whitespace_in_literal_matrix = pref; |
430
|
172 return 0; |
|
173 } |
|
174 |
661
|
175 |
|
176 // Should we allow assignments like: |
|
177 // |
|
178 // octave> A(1) = 3; A(2) = 5 |
|
179 // |
|
180 // for A already defined and a matrix type? |
|
181 |
1
|
182 int |
|
183 do_fortran_indexing (void) |
|
184 { |
|
185 user_pref.do_fortran_indexing = |
|
186 check_str_pref ("do_fortran_indexing"); |
|
187 |
|
188 return 0; |
|
189 } |
|
190 |
661
|
191 |
|
192 // Should ignore empty elements in a matrix list (i.e., is an |
|
193 // expression like `[[], 1]' ok? |
|
194 |
1
|
195 int |
|
196 empty_list_elements_ok (void) |
|
197 { |
|
198 user_pref.empty_list_elements_ok = |
|
199 check_str_pref ("empty_list_elements_ok"); |
|
200 |
|
201 return 0; |
|
202 } |
|
203 |
661
|
204 |
|
205 // Should Octave always check to see if function files have changed |
|
206 // since they were last compiled? |
|
207 |
430
|
208 int |
|
209 ignore_function_time_stamp (void) |
|
210 { |
|
211 int pref = 0; |
|
212 |
|
213 char *val = builtin_string_variable ("ignore_function_time_stamp"); |
|
214 |
529
|
215 if (val) |
430
|
216 { |
|
217 if (strncmp (val, "all", 3) == 0) |
|
218 pref = 2; |
|
219 if (strncmp (val, "system", 6) == 0) |
|
220 pref = 1; |
|
221 } |
|
222 |
|
223 user_pref.ignore_function_time_stamp = pref; |
|
224 |
|
225 return 0; |
|
226 } |
|
227 |
661
|
228 |
|
229 // Should we allow things like: |
|
230 // |
|
231 // octave> 'abc' + 0 |
|
232 // 97 98 99 |
|
233 // |
|
234 // to happen? |
|
235 |
1
|
236 int |
|
237 implicit_str_to_num_ok (void) |
|
238 { |
|
239 user_pref.implicit_str_to_num_ok = |
|
240 check_str_pref ("implicit_str_to_num_ok"); |
|
241 |
|
242 return 0; |
|
243 } |
|
244 |
661
|
245 |
|
246 // Should we allow silent conversion of complex to real when a real |
|
247 // type is what we\'re really looking for? |
|
248 |
1
|
249 int |
|
250 ok_to_lose_imaginary_part (void) |
|
251 { |
|
252 user_pref.ok_to_lose_imaginary_part = |
|
253 check_str_pref ("ok_to_lose_imaginary_part"); |
|
254 |
|
255 return 0; |
|
256 } |
|
257 |
661
|
258 |
|
259 // If possible, send all output intended for the screen through the |
|
260 // pager. |
|
261 |
430
|
262 int |
|
263 page_screen_output (void) |
|
264 { |
|
265 user_pref.page_screen_output = check_str_pref ("page_screen_output"); |
|
266 |
|
267 return 0; |
|
268 } |
|
269 |
661
|
270 |
|
271 // When doing assignments like: |
|
272 // |
|
273 // octave> A(1) = 3; A(2) = 5 |
|
274 // |
|
275 // (for A undefined) should we build column vectors? Returning true |
|
276 // only matters when resize_on_range_error is also true. |
|
277 |
1
|
278 int |
|
279 prefer_column_vectors (void) |
|
280 { |
|
281 user_pref.prefer_column_vectors = |
|
282 check_str_pref ("prefer_column_vectors"); |
|
283 |
|
284 return 0; |
|
285 } |
|
286 |
661
|
287 |
|
288 // For things like |
|
289 // |
|
290 // a = [2,3]; a([1,1]) |
|
291 // |
|
292 // return [2 3] instead of [2 2]. |
|
293 |
1
|
294 int |
|
295 prefer_zero_one_indexing (void) |
|
296 { |
|
297 user_pref.prefer_zero_one_indexing = |
|
298 check_str_pref ("prefer_zero_one_indexing"); |
|
299 |
|
300 return 0; |
|
301 } |
|
302 |
661
|
303 |
|
304 // Should we print things like |
|
305 // |
|
306 // octave> a = [1,2;3,4] |
|
307 // a = |
|
308 // |
|
309 // 1 2 |
|
310 // 3 4 |
|
311 |
1
|
312 int |
|
313 print_answer_id_name (void) |
|
314 { |
|
315 user_pref.print_answer_id_name = |
|
316 check_str_pref ("print_answer_id_name"); |
|
317 |
|
318 return 0; |
|
319 } |
|
320 |
661
|
321 |
|
322 // Should we also print the dimensions of empty matrices? |
|
323 |
430
|
324 int |
|
325 print_empty_dimensions (void) |
|
326 { |
|
327 user_pref.print_empty_dimensions = |
|
328 check_str_pref ("print_empty_dimensions"); |
|
329 |
|
330 return 0; |
|
331 } |
|
332 |
661
|
333 |
|
334 // Should operations on empty matrices return empty matrices or an |
|
335 // error? |
|
336 |
1
|
337 int |
|
338 propagate_empty_matrices (void) |
|
339 { |
|
340 user_pref.propagate_empty_matrices = |
|
341 check_str_pref ("propagate_empty_matrices"); |
|
342 |
|
343 return 0; |
|
344 } |
|
345 |
661
|
346 |
|
347 // When doing assignments, should we resize matrices if the indices |
|
348 // are outside the current bounds? |
|
349 |
1
|
350 int |
|
351 resize_on_range_error (void) |
|
352 { |
|
353 user_pref.resize_on_range_error = |
|
354 check_str_pref ("resize_on_range_error"); |
|
355 |
|
356 return 0; |
|
357 } |
|
358 |
661
|
359 |
|
360 // If a function does not return any values explicitly, return the |
|
361 // last computed value. |
|
362 |
1
|
363 int |
|
364 return_last_computed_value (void) |
|
365 { |
|
366 user_pref.return_last_computed_value = |
|
367 check_str_pref ("return_last_computed_value"); |
|
368 |
|
369 return 0; |
|
370 } |
|
371 |
661
|
372 |
|
373 // Suppress printing results in called functions. |
|
374 |
1
|
375 int |
|
376 silent_functions (void) |
|
377 { |
|
378 user_pref.silent_functions = |
|
379 check_str_pref ("silent_functions"); |
|
380 |
|
381 return 0; |
|
382 } |
|
383 |
661
|
384 |
|
385 // Should should big matrices be split into smaller slices for output? |
|
386 |
1
|
387 int |
|
388 split_long_rows (void) |
|
389 { |
|
390 user_pref.split_long_rows = check_str_pref ("split_long_rows"); |
|
391 |
|
392 return 0; |
|
393 } |
|
394 |
661
|
395 |
|
396 // Should things like: |
|
397 // |
|
398 // octave> ones (-1, 5) |
|
399 // |
|
400 // result in an empty matrix or an error? |
|
401 |
1
|
402 int |
|
403 treat_neg_dim_as_zero (void) |
|
404 { |
|
405 user_pref.treat_neg_dim_as_zero = |
|
406 check_str_pref ("treat_neg_dim_as_zero"); |
|
407 |
|
408 return 0; |
|
409 } |
|
410 |
661
|
411 |
|
412 // Generate a warning for the assignment in things like |
|
413 // |
|
414 // octave> if (a = 2 < n) |
|
415 // |
|
416 // but not |
|
417 // |
|
418 // octave> if ((a = 2) < n) |
|
419 |
430
|
420 int |
|
421 warn_assign_as_truth_value (void) |
|
422 { |
|
423 user_pref.warn_assign_as_truth_value = |
|
424 check_str_pref ("warn_assign_as_truth_value"); |
|
425 |
|
426 return 0; |
|
427 } |
|
428 |
661
|
429 |
|
430 // Generate a warning for the comma in things like |
|
431 // |
|
432 // octave> global a, b = 2 |
|
433 |
1
|
434 int |
|
435 warn_comma_in_global_decl (void) |
|
436 { |
|
437 user_pref.warn_comma_in_global_decl = |
|
438 check_str_pref ("warn_comma_in_global_decl"); |
|
439 |
|
440 return 0; |
|
441 } |
|
442 |
661
|
443 |
|
444 // On IEEE machines, allow divide by zero errors to be suppressed. |
|
445 |
1
|
446 int |
|
447 warn_divide_by_zero (void) |
|
448 { |
|
449 user_pref.warn_divide_by_zero = check_str_pref ("warn_divide_by_zero"); |
|
450 |
|
451 return 0; |
|
452 } |
|
453 |
|
454 int |
|
455 set_output_max_field_width (void) |
|
456 { |
|
457 int status = 0; |
|
458 |
|
459 static int kludge = 0; |
|
460 |
|
461 double val; |
195
|
462 if (builtin_real_scalar_variable ("output_max_field_width", val) == 0) |
1
|
463 { |
|
464 int ival = NINT (val); |
|
465 if (ival > 0 && (double) ival == val) |
|
466 { |
|
467 user_pref.output_max_field_width= ival; |
|
468 return status; |
|
469 } |
|
470 } |
|
471 |
|
472 if (kludge == 0) |
|
473 kludge++; |
|
474 else |
|
475 { |
|
476 warning ("invalid value specified for output_max_field_width"); |
|
477 status = -1; |
|
478 } |
|
479 |
|
480 return status; |
|
481 } |
|
482 |
|
483 int |
|
484 set_output_precision (void) |
|
485 { |
|
486 int status = 0; |
|
487 |
|
488 static int kludge = 0; |
|
489 |
|
490 double val; |
195
|
491 if (builtin_real_scalar_variable ("output_precision", val) == 0) |
1
|
492 { |
|
493 int ival = NINT (val); |
|
494 if (ival >= 0 && (double) ival == val) |
|
495 { |
|
496 user_pref.output_precision = ival; |
|
497 return status; |
|
498 } |
|
499 } |
|
500 |
|
501 if (kludge == 0) |
|
502 kludge++; |
|
503 else |
|
504 { |
|
505 warning ("invalid value specified for output_precision"); |
|
506 status = -1; |
|
507 } |
|
508 |
|
509 return status; |
|
510 } |
|
511 |
|
512 int |
275
|
513 set_save_precision (void) |
|
514 { |
|
515 int status = 0; |
|
516 |
|
517 static int kludge = 0; |
|
518 |
|
519 double val; |
|
520 if (builtin_real_scalar_variable ("save_precision", val) == 0) |
|
521 { |
|
522 int ival = NINT (val); |
|
523 if (ival >= 0 && (double) ival == val) |
|
524 { |
|
525 user_pref.save_precision = ival; |
|
526 return status; |
|
527 } |
|
528 } |
|
529 |
|
530 if (kludge == 0) |
|
531 kludge++; |
|
532 else |
|
533 { |
|
534 warning ("invalid value specified for save_precision"); |
|
535 status = -1; |
|
536 } |
|
537 |
|
538 return status; |
|
539 } |
|
540 |
|
541 int |
430
|
542 sv_editor (void) |
1
|
543 { |
|
544 int status = 0; |
|
545 |
430
|
546 char *s = builtin_string_variable ("EDITOR"); |
529
|
547 if (s) |
1
|
548 { |
430
|
549 delete [] user_pref.editor; |
|
550 user_pref.editor = s; |
1
|
551 } |
|
552 else |
|
553 { |
430
|
554 warning ("invalid value specified for EDITOR"); |
|
555 status = -1; |
|
556 } |
|
557 |
|
558 return status; |
|
559 } |
|
560 |
|
561 int |
605
|
562 sv_default_save_format (void) |
|
563 { |
|
564 int status = 0; |
|
565 |
|
566 char *s = builtin_string_variable ("default_save_format"); |
|
567 if (s) |
|
568 { |
|
569 delete [] user_pref.default_save_format; |
|
570 user_pref.default_save_format = s; |
|
571 } |
|
572 else |
|
573 { |
|
574 warning ("invalid value specified for default_save_format"); |
|
575 status = -1; |
|
576 } |
|
577 |
|
578 return status; |
|
579 } |
|
580 |
|
581 int |
430
|
582 sv_gnuplot_binary (void) |
|
583 { |
|
584 int status = 0; |
|
585 |
|
586 char *s = builtin_string_variable ("gnuplot_binary"); |
529
|
587 if (s) |
430
|
588 { |
|
589 delete [] user_pref.gnuplot_binary; |
|
590 user_pref.gnuplot_binary = s; |
|
591 } |
|
592 else |
|
593 { |
|
594 warning ("invalid value specified for gnuplot_binary"); |
1
|
595 status = -1; |
|
596 } |
|
597 |
|
598 return status; |
|
599 } |
|
600 |
|
601 int |
686
|
602 sv_imagepath (void) |
|
603 { |
|
604 int status = 0; |
|
605 |
|
606 char *s = builtin_string_variable ("IMAGEPATH"); |
|
607 if (s) |
|
608 { |
|
609 delete [] user_pref.imagepath; |
|
610 user_pref.imagepath = s; |
|
611 } |
|
612 else |
|
613 { |
|
614 warning ("invalid value specified for IMAGEPATH"); |
|
615 status = -1; |
|
616 } |
|
617 |
|
618 return status; |
|
619 } |
|
620 |
|
621 int |
186
|
622 sv_info_file (void) |
|
623 { |
|
624 int status = 0; |
|
625 |
195
|
626 char *s = builtin_string_variable ("INFO_FILE"); |
529
|
627 if (s) |
186
|
628 { |
|
629 delete [] user_pref.info_file; |
|
630 user_pref.info_file = s; |
|
631 } |
|
632 else |
|
633 { |
|
634 warning ("invalid value specified for INFO_FILE"); |
|
635 status = -1; |
|
636 } |
|
637 |
|
638 return status; |
|
639 } |
|
640 |
|
641 int |
430
|
642 sv_loadpath (void) |
195
|
643 { |
|
644 int status = 0; |
|
645 |
430
|
646 char *s = builtin_string_variable ("LOADPATH"); |
529
|
647 if (s) |
195
|
648 { |
430
|
649 delete [] user_pref.loadpath; |
|
650 user_pref.loadpath = s; |
195
|
651 } |
|
652 else |
|
653 { |
430
|
654 warning ("invalid value specified for LOADPATH"); |
|
655 status = -1; |
|
656 } |
|
657 |
|
658 return status; |
|
659 } |
|
660 |
|
661 int |
|
662 sv_pager_binary (void) |
|
663 { |
|
664 int status = 0; |
|
665 |
|
666 char *s = builtin_string_variable ("PAGER"); |
529
|
667 if (s) |
430
|
668 { |
|
669 delete [] user_pref.pager_binary; |
|
670 user_pref.pager_binary = s; |
|
671 } |
|
672 else |
|
673 { |
|
674 warning ("invalid value specified for PAGER"); |
195
|
675 status = -1; |
|
676 } |
|
677 |
|
678 return status; |
|
679 } |
|
680 |
|
681 int |
1
|
682 sv_ps1 (void) |
|
683 { |
|
684 int status = 0; |
|
685 |
195
|
686 char *s = builtin_string_variable ("PS1"); |
529
|
687 if (s) |
1
|
688 { |
|
689 delete [] user_pref.ps1; |
|
690 user_pref.ps1 = s; |
|
691 } |
|
692 else |
|
693 { |
|
694 warning ("invalid value specified for PS1"); |
|
695 status = -1; |
|
696 } |
|
697 |
|
698 return status; |
|
699 } |
|
700 |
|
701 int |
|
702 sv_ps2 (void) |
|
703 { |
|
704 int status = 0; |
|
705 |
195
|
706 char *s = builtin_string_variable ("PS2"); |
529
|
707 if (s) |
1
|
708 { |
|
709 delete [] user_pref.ps2; |
|
710 user_pref.ps2 = s; |
|
711 } |
|
712 else |
|
713 { |
|
714 warning ("invalid value specified for PS2"); |
|
715 status = -1; |
|
716 } |
|
717 |
|
718 return status; |
|
719 } |
|
720 |
|
721 int |
|
722 sv_pwd (void) |
|
723 { |
|
724 int status = 0; |
|
725 |
195
|
726 char *s = builtin_string_variable ("PWD"); |
529
|
727 if (s) |
1
|
728 { |
|
729 delete [] user_pref.pwd; |
|
730 user_pref.pwd = s; |
|
731 } |
|
732 else |
|
733 { |
|
734 warning ("invalid value specified for PWD"); |
|
735 status = -1; |
|
736 } |
|
737 |
|
738 return status; |
|
739 } |
|
740 |
|
741 /* |
|
742 ;;; Local Variables: *** |
|
743 ;;; mode: C++ *** |
|
744 ;;; page-delimiter: "^/\\*" *** |
|
745 ;;; End: *** |
|
746 */ |