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