1
|
1 // user-prefs.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
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 { |
|
51 char *val = octave_string_variable (var); |
|
52 int pref = -1; |
|
53 if (val != (char *) NULL) |
|
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 /* |
|
67 * Should we allow assignments like: |
|
68 * |
|
69 * octave> A(1) = 3; A(2) = 5 |
|
70 * |
|
71 * for A already defined and a matrix type? |
|
72 */ |
|
73 int |
|
74 do_fortran_indexing (void) |
|
75 { |
|
76 user_pref.do_fortran_indexing = |
|
77 check_str_pref ("do_fortran_indexing"); |
|
78 |
|
79 return 0; |
|
80 } |
|
81 |
|
82 /* |
|
83 * Should ignore empty elements in a matrix list (i.e., is an |
|
84 * expression like `[[], 1]' ok? |
|
85 */ |
|
86 int |
|
87 empty_list_elements_ok (void) |
|
88 { |
|
89 user_pref.empty_list_elements_ok = |
|
90 check_str_pref ("empty_list_elements_ok"); |
|
91 |
|
92 return 0; |
|
93 } |
|
94 |
|
95 /* |
|
96 * Should we allow things like: |
|
97 * |
|
98 * octave> 'abc' + 0 |
|
99 * 97 98 99 |
|
100 * |
|
101 * to happen? |
|
102 */ |
|
103 int |
|
104 implicit_str_to_num_ok (void) |
|
105 { |
|
106 user_pref.implicit_str_to_num_ok = |
|
107 check_str_pref ("implicit_str_to_num_ok"); |
|
108 |
|
109 return 0; |
|
110 } |
|
111 |
|
112 /* |
|
113 * Should we allow silent conversion of complex to real when a real |
|
114 * type is what we\'re really looking for? |
|
115 */ |
|
116 int |
|
117 ok_to_lose_imaginary_part (void) |
|
118 { |
|
119 user_pref.ok_to_lose_imaginary_part = |
|
120 check_str_pref ("ok_to_lose_imaginary_part"); |
|
121 |
|
122 return 0; |
|
123 } |
|
124 |
|
125 /* |
|
126 * When doing assignments like: |
|
127 * |
|
128 * octave> A(1) = 3; A(2) = 5 |
|
129 * |
|
130 * (for A undefined) should we build column vectors? Returning true |
|
131 * only matters when resize_on_range_error is also true. |
|
132 */ |
|
133 int |
|
134 prefer_column_vectors (void) |
|
135 { |
|
136 user_pref.prefer_column_vectors = |
|
137 check_str_pref ("prefer_column_vectors"); |
|
138 |
|
139 return 0; |
|
140 } |
|
141 |
|
142 /* |
|
143 * For things like |
|
144 * |
|
145 * a = [2,3]; a([1,1]) |
|
146 * |
|
147 * return [2 3] instead of [2 2]. |
|
148 */ |
|
149 int |
|
150 prefer_zero_one_indexing (void) |
|
151 { |
|
152 user_pref.prefer_zero_one_indexing = |
|
153 check_str_pref ("prefer_zero_one_indexing"); |
|
154 |
|
155 return 0; |
|
156 } |
|
157 |
|
158 /* |
|
159 * Should we print things like |
|
160 * |
|
161 * octave> a = [1,2;3,4] |
|
162 * a = |
|
163 * |
|
164 * 1 2 |
|
165 * 3 4 |
|
166 */ |
|
167 int |
|
168 print_answer_id_name (void) |
|
169 { |
|
170 user_pref.print_answer_id_name = |
|
171 check_str_pref ("print_answer_id_name"); |
|
172 |
|
173 return 0; |
|
174 } |
|
175 |
|
176 /* |
|
177 * Should operations on empty matrices return empty matrices or an |
|
178 * error? |
|
179 */ |
|
180 int |
|
181 propagate_empty_matrices (void) |
|
182 { |
|
183 user_pref.propagate_empty_matrices = |
|
184 check_str_pref ("propagate_empty_matrices"); |
|
185 |
|
186 return 0; |
|
187 } |
|
188 |
|
189 /* |
|
190 * Should we also print the dimensions of empty matrices? |
|
191 */ |
|
192 int |
|
193 print_empty_dimensions (void) |
|
194 { |
|
195 user_pref.print_empty_dimensions = |
|
196 check_str_pref ("print_empty_dimensions"); |
|
197 |
|
198 return 0; |
|
199 } |
|
200 |
|
201 /* |
|
202 * When doing assignments, should we resize matrices if the indices |
|
203 * are outside the current bounds? |
|
204 */ |
|
205 int |
|
206 resize_on_range_error (void) |
|
207 { |
|
208 user_pref.resize_on_range_error = |
|
209 check_str_pref ("resize_on_range_error"); |
|
210 |
|
211 return 0; |
|
212 } |
|
213 |
|
214 /* |
|
215 * If a function does not return any values explicitly, return the |
|
216 * last computed value. |
|
217 */ |
|
218 int |
|
219 return_last_computed_value (void) |
|
220 { |
|
221 user_pref.return_last_computed_value = |
|
222 check_str_pref ("return_last_computed_value"); |
|
223 |
|
224 return 0; |
|
225 } |
|
226 |
|
227 /* |
|
228 * Suppress printing results in called functions. |
|
229 */ |
|
230 int |
|
231 silent_functions (void) |
|
232 { |
|
233 user_pref.silent_functions = |
|
234 check_str_pref ("silent_functions"); |
|
235 |
|
236 return 0; |
|
237 } |
|
238 |
|
239 /* |
|
240 * Should should big matrices be split into smaller slices for output? |
|
241 */ |
|
242 int |
|
243 split_long_rows (void) |
|
244 { |
|
245 user_pref.split_long_rows = check_str_pref ("split_long_rows"); |
|
246 |
|
247 return 0; |
|
248 } |
|
249 |
|
250 /* |
|
251 * Should things like: |
|
252 * |
|
253 * octave> ones (-1, 5) |
|
254 * |
|
255 * result in an empty matrix or an error? |
|
256 */ |
|
257 int |
|
258 treat_neg_dim_as_zero (void) |
|
259 { |
|
260 user_pref.treat_neg_dim_as_zero = |
|
261 check_str_pref ("treat_neg_dim_as_zero"); |
|
262 |
|
263 return 0; |
|
264 } |
|
265 |
|
266 /* |
|
267 * Generate a warning for the comma in things like |
|
268 * |
|
269 * octave> global a, b = 2 |
|
270 */ |
|
271 int |
|
272 warn_comma_in_global_decl (void) |
|
273 { |
|
274 user_pref.warn_comma_in_global_decl = |
|
275 check_str_pref ("warn_comma_in_global_decl"); |
|
276 |
|
277 return 0; |
|
278 } |
|
279 |
|
280 /* |
|
281 * On IEEE machines, allow divide by zero errors to be suppressed. |
|
282 */ |
|
283 int |
|
284 warn_divide_by_zero (void) |
|
285 { |
|
286 user_pref.warn_divide_by_zero = check_str_pref ("warn_divide_by_zero"); |
|
287 |
|
288 return 0; |
|
289 } |
|
290 |
|
291 /* |
|
292 * Generate a warning for the assignment in things like |
|
293 * |
|
294 * octave> if (a = 2 < n) |
|
295 * |
|
296 * but not |
|
297 * |
|
298 * octave> if ((a = 2) < n) |
|
299 */ |
|
300 int |
|
301 warn_assign_as_truth_value (void) |
|
302 { |
|
303 user_pref.warn_assign_as_truth_value = |
|
304 check_str_pref ("user_pref.warn_assign_as_truth_value"); |
|
305 |
|
306 return 0; |
|
307 } |
|
308 |
|
309 /* |
|
310 * If possible, send all output intended for the screen through the |
|
311 * pager. |
|
312 */ |
|
313 int |
|
314 page_screen_output (void) |
|
315 { |
|
316 user_pref.page_screen_output = check_str_pref ("page_screen_output"); |
|
317 |
|
318 return 0; |
|
319 } |
|
320 |
|
321 int |
|
322 set_output_max_field_width (void) |
|
323 { |
|
324 int status = 0; |
|
325 |
|
326 static int kludge = 0; |
|
327 |
|
328 double val; |
|
329 if (octave_real_scalar_variable ("output_max_field_width", val) == 0) |
|
330 { |
|
331 int ival = NINT (val); |
|
332 if (ival > 0 && (double) ival == val) |
|
333 { |
|
334 user_pref.output_max_field_width= ival; |
|
335 return status; |
|
336 } |
|
337 } |
|
338 |
|
339 if (kludge == 0) |
|
340 kludge++; |
|
341 else |
|
342 { |
|
343 warning ("invalid value specified for output_max_field_width"); |
|
344 status = -1; |
|
345 } |
|
346 |
|
347 return status; |
|
348 } |
|
349 |
|
350 int |
|
351 set_output_precision (void) |
|
352 { |
|
353 int status = 0; |
|
354 |
|
355 static int kludge = 0; |
|
356 |
|
357 double val; |
|
358 if (octave_real_scalar_variable ("output_precision", val) == 0) |
|
359 { |
|
360 int ival = NINT (val); |
|
361 if (ival >= 0 && (double) ival == val) |
|
362 { |
|
363 user_pref.output_precision = ival; |
|
364 return status; |
|
365 } |
|
366 } |
|
367 |
|
368 if (kludge == 0) |
|
369 kludge++; |
|
370 else |
|
371 { |
|
372 warning ("invalid value specified for output_precision"); |
|
373 status = -1; |
|
374 } |
|
375 |
|
376 return status; |
|
377 } |
|
378 |
|
379 int |
|
380 sv_loadpath (void) |
|
381 { |
|
382 int status = 0; |
|
383 |
|
384 char *s = octave_string_variable ("LOADPATH"); |
|
385 if (s != (char *) NULL) |
|
386 { |
|
387 delete [] user_pref.loadpath; |
|
388 user_pref.loadpath = s; |
|
389 } |
|
390 else |
|
391 { |
|
392 warning ("invalid value specified for LOADPATH"); |
|
393 status = -1; |
|
394 } |
|
395 |
|
396 return status; |
|
397 } |
|
398 |
|
399 int |
|
400 sv_ps1 (void) |
|
401 { |
|
402 int status = 0; |
|
403 |
|
404 char *s = octave_string_variable ("PS1"); |
|
405 if (s != (char *) NULL) |
|
406 { |
|
407 delete [] user_pref.ps1; |
|
408 user_pref.ps1 = s; |
|
409 } |
|
410 else |
|
411 { |
|
412 warning ("invalid value specified for PS1"); |
|
413 status = -1; |
|
414 } |
|
415 |
|
416 return status; |
|
417 } |
|
418 |
|
419 int |
|
420 sv_ps2 (void) |
|
421 { |
|
422 int status = 0; |
|
423 |
|
424 char *s = octave_string_variable ("PS2"); |
|
425 if (s != (char *) NULL) |
|
426 { |
|
427 delete [] user_pref.ps2; |
|
428 user_pref.ps2 = s; |
|
429 } |
|
430 else |
|
431 { |
|
432 warning ("invalid value specified for PS2"); |
|
433 status = -1; |
|
434 } |
|
435 |
|
436 return status; |
|
437 } |
|
438 |
|
439 int |
|
440 sv_pwd (void) |
|
441 { |
|
442 int status = 0; |
|
443 |
|
444 char *s = octave_string_variable ("PWD"); |
|
445 if (s != (char *) NULL) |
|
446 { |
|
447 delete [] user_pref.pwd; |
|
448 user_pref.pwd = s; |
|
449 } |
|
450 else |
|
451 { |
|
452 warning ("invalid value specified for PWD"); |
|
453 status = -1; |
|
454 } |
|
455 |
|
456 return status; |
|
457 } |
|
458 |
|
459 int |
|
460 sv_gnuplot_binary (void) |
|
461 { |
|
462 int status = 0; |
|
463 |
|
464 char *s = octave_string_variable ("gnuplot_binary"); |
|
465 if (s != (char *) NULL) |
|
466 { |
|
467 delete [] user_pref.gnuplot_binary; |
|
468 user_pref.gnuplot_binary = s; |
|
469 } |
|
470 else |
|
471 { |
|
472 warning ("invalid value specified for gnuplot_binary"); |
|
473 status = -1; |
|
474 } |
|
475 |
|
476 return status; |
|
477 } |
|
478 |
|
479 int |
|
480 sv_pager_binary (void) |
|
481 { |
|
482 int status = 0; |
|
483 |
|
484 char *s = octave_string_variable ("PAGER"); |
|
485 if (s != (char *) NULL) |
|
486 { |
|
487 delete [] user_pref.pager_binary; |
|
488 user_pref.pager_binary = s; |
|
489 } |
|
490 else |
|
491 { |
|
492 warning ("invalid value specified for PAGER"); |
|
493 status = -1; |
|
494 } |
|
495 |
|
496 return status; |
|
497 } |
|
498 |
|
499 /* |
|
500 ;;; Local Variables: *** |
|
501 ;;; mode: C++ *** |
|
502 ;;; page-delimiter: "^/\\*" *** |
|
503 ;;; End: *** |
|
504 */ |