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