1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
1
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1613
|
27 #include <cstdio> |
|
28 #include <cstdlib> |
1343
|
29 #include <cstring> |
1
|
30 |
1907
|
31 #include "Array-flags.h" |
|
32 |
1352
|
33 #include "error.h" |
1416
|
34 #include "gripes.h" |
1086
|
35 #include "mappers.h" |
1799
|
36 #include "oct-hist.h" |
|
37 #include "sysdep.h" |
1352
|
38 #include "user-prefs.h" |
|
39 #include "utils.h" |
1
|
40 #include "variables.h" |
|
41 |
|
42 // The list of user preferences. Values change when global variables |
1358
|
43 // change, so we don't have to do a variable look up every time we |
1
|
44 // need to check a preference. |
|
45 user_preferences user_pref; |
|
46 |
720
|
47 // Initialize global user_pref structure. |
|
48 |
831
|
49 void |
720
|
50 init_user_prefs (void) |
|
51 { |
|
52 user_pref.automatic_replot = 0; |
1423
|
53 user_pref.beep_on_error = 0; |
1093
|
54 user_pref.define_all_return_values = 0; |
720
|
55 user_pref.do_fortran_indexing = 0; |
|
56 user_pref.empty_list_elements_ok = 0; |
1502
|
57 user_pref.gnuplot_has_multiplot = 0; |
1646
|
58 user_pref.history_size = 0; |
720
|
59 user_pref.ignore_function_time_stamp = 0; |
|
60 user_pref.implicit_str_to_num_ok = 0; |
|
61 user_pref.ok_to_lose_imaginary_part = 0; |
|
62 user_pref.output_max_field_width = 0; |
|
63 user_pref.output_precision = 0; |
|
64 user_pref.page_screen_output = 0; |
|
65 user_pref.prefer_column_vectors = 0; |
|
66 user_pref.prefer_zero_one_indexing = 0; |
|
67 user_pref.print_answer_id_name = 0; |
|
68 user_pref.print_empty_dimensions = 0; |
|
69 user_pref.propagate_empty_matrices = 0; |
1045
|
70 user_pref.read_only_constants = 1; |
720
|
71 user_pref.resize_on_range_error = 0; |
|
72 user_pref.return_last_computed_value = 0; |
|
73 user_pref.save_precision = 0; |
1642
|
74 user_pref.saving_history = 0; |
720
|
75 user_pref.silent_functions = 0; |
|
76 user_pref.split_long_rows = 0; |
1198
|
77 user_pref.struct_levels_to_print = 0; |
1116
|
78 user_pref.suppress_verbose_help_message = 0; |
720
|
79 user_pref.treat_neg_dim_as_zero = 0; |
|
80 user_pref.warn_assign_as_truth_value = 0; |
|
81 user_pref.warn_comma_in_global_decl = 0; |
|
82 user_pref.warn_divide_by_zero = 0; |
1037
|
83 user_pref.warn_function_name_clash = 0; |
1093
|
84 user_pref.whitespace_in_literal_matrix = 0; |
720
|
85 |
1429
|
86 user_pref.completion_append_char = '\0'; |
|
87 |
1755
|
88 user_pref.default_save_format = string (); |
|
89 user_pref.editor = string (); |
|
90 user_pref.exec_path = string (); |
|
91 user_pref.gnuplot_binary = string (); |
|
92 user_pref.history_file = string (); |
|
93 user_pref.imagepath = string (); |
|
94 user_pref.info_file = string (); |
|
95 user_pref.info_prog = string (); |
|
96 user_pref.loadpath = string (); |
|
97 user_pref.pager_binary = string (); |
|
98 user_pref.ps1 = string (); |
|
99 user_pref.ps2 = string (); |
|
100 user_pref.ps4 = string (); |
|
101 user_pref.pwd = string (); |
720
|
102 } |
661
|
103 |
|
104 // Check the value of a string variable to see if it it's ok to do |
|
105 // something. |
|
106 // |
673
|
107 // return of 1 => always ok. |
|
108 // return of 0 => never ok. |
661
|
109 // return of -1 => ok, but give me warning (default). |
|
110 |
1416
|
111 // XXX FIXME XXX -- should also allow zero to mean "false" and nonzero |
|
112 // to mean "true". |
|
113 |
1
|
114 static int |
1755
|
115 check_preference (const string& var) |
1
|
116 { |
1505
|
117 int pref = -1; |
|
118 |
1755
|
119 string val = builtin_string_variable (var); |
1505
|
120 |
1755
|
121 if (val.empty ()) |
1505
|
122 { |
|
123 double dval = 0; |
|
124 if (builtin_real_scalar_variable (var, dval)) |
|
125 pref = NINT (dval); |
|
126 } |
1755
|
127 else |
|
128 { |
|
129 if (val.compare ("yes", 0, 3) == 0 |
|
130 || val.compare ("true", 0, 4) == 0) |
|
131 pref = 1; |
|
132 else if (val.compare ("never", 0, 5) == 0 |
|
133 || val.compare ("no", 0, 2) == 0 |
|
134 || val.compare ("false", 0, 5) == 0) |
|
135 pref = 0; |
|
136 } |
1505
|
137 |
1
|
138 return pref; |
|
139 } |
|
140 |
1198
|
141 // XXX FIXME XXX -- some of these should do their own checking to be |
|
142 // able to provide more meaningful warning or error messages. |
|
143 |
661
|
144 // Should a replot command be generated automatically each time a plot |
|
145 // changes in some way? |
|
146 |
|
147 int |
|
148 automatic_replot (void) |
|
149 { |
1505
|
150 user_pref.automatic_replot = check_preference ("automatic_replot"); |
661
|
151 |
|
152 return 0; |
|
153 } |
|
154 |
|
155 |
1423
|
156 // Should we beep obnoxiously before printing error messages? |
|
157 |
|
158 int |
|
159 beep_on_error (void) |
|
160 { |
1505
|
161 user_pref.beep_on_error = check_preference ("beep_on_error"); |
1423
|
162 |
|
163 return 0; |
|
164 } |
|
165 |
|
166 |
1093
|
167 // Should variables returned from functions have default values if |
|
168 // they are otherwise uninitialized? |
661
|
169 |
430
|
170 int |
1093
|
171 define_all_return_values (void) |
430
|
172 { |
1093
|
173 user_pref.define_all_return_values = |
1505
|
174 check_preference ("define_all_return_values"); |
1093
|
175 |
430
|
176 return 0; |
|
177 } |
|
178 |
661
|
179 |
|
180 // Should we allow assignments like: |
|
181 // |
|
182 // octave> A(1) = 3; A(2) = 5 |
|
183 // |
|
184 // for A already defined and a matrix type? |
|
185 |
1
|
186 int |
|
187 do_fortran_indexing (void) |
|
188 { |
|
189 user_pref.do_fortran_indexing = |
1505
|
190 check_preference ("do_fortran_indexing"); |
1
|
191 |
1907
|
192 liboctave_dfi_flag = user_pref.do_fortran_indexing; |
|
193 |
1
|
194 return 0; |
|
195 } |
|
196 |
661
|
197 |
1588
|
198 // Echo commands as they are executed? |
|
199 // |
|
200 // 1 ==> echo commands read from script files |
|
201 // 2 ==> echo commands from functions |
|
202 // 4 ==> echo commands read from command line |
|
203 // |
|
204 // more than one state can be active at once. |
|
205 |
|
206 int |
|
207 echo_executing_commands (void) |
|
208 { |
|
209 user_pref.echo_executing_commands = |
|
210 check_preference ("echo_executing_commands"); |
|
211 |
|
212 return 0; |
|
213 } |
|
214 |
|
215 |
661
|
216 // Should ignore empty elements in a matrix list (i.e., is an |
|
217 // expression like `[[], 1]' ok? |
|
218 |
1
|
219 int |
|
220 empty_list_elements_ok (void) |
|
221 { |
|
222 user_pref.empty_list_elements_ok = |
1505
|
223 check_preference ("empty_list_elements_ok"); |
1
|
224 |
|
225 return 0; |
|
226 } |
|
227 |
661
|
228 |
1502
|
229 // Does gnuplot appear to support multiplot? |
|
230 |
|
231 int |
|
232 gnuplot_has_multiplot (void) |
|
233 { |
|
234 user_pref.gnuplot_has_multiplot = |
1505
|
235 check_preference ("gnuplot_has_multiplot"); |
1502
|
236 |
|
237 return 0; |
|
238 } |
|
239 |
|
240 |
1646
|
241 // How many lines of command history should we save? |
|
242 |
|
243 int |
|
244 history_size (void) |
|
245 { |
|
246 double val; |
|
247 if (builtin_real_scalar_variable ("history_size", val) |
|
248 && ! xisnan (val)) |
|
249 { |
|
250 int ival = NINT (val); |
|
251 if (ival >= 0 && (double) ival == val) |
|
252 { |
|
253 user_pref.history_size = ival; |
1799
|
254 octave_command_history.set_size (ival); |
1646
|
255 return 0; |
|
256 } |
|
257 } |
|
258 gripe_invalid_value_specified ("history_size"); |
|
259 return -1; |
|
260 } |
|
261 |
|
262 |
661
|
263 // Should Octave always check to see if function files have changed |
|
264 // since they were last compiled? |
|
265 |
430
|
266 int |
|
267 ignore_function_time_stamp (void) |
|
268 { |
|
269 int pref = 0; |
|
270 |
1755
|
271 string val = builtin_string_variable ("ignore_function_time_stamp"); |
430
|
272 |
1755
|
273 if (! val.empty ()) |
430
|
274 { |
1755
|
275 if (val.compare ("all", 0, 3) == 0) |
430
|
276 pref = 2; |
1755
|
277 if (val.compare ("system", 0, 6) == 0) |
430
|
278 pref = 1; |
|
279 } |
|
280 |
|
281 user_pref.ignore_function_time_stamp = pref; |
|
282 |
|
283 return 0; |
|
284 } |
|
285 |
661
|
286 |
|
287 // Should we allow things like: |
|
288 // |
|
289 // octave> 'abc' + 0 |
|
290 // 97 98 99 |
|
291 // |
|
292 // to happen? |
|
293 |
1
|
294 int |
|
295 implicit_str_to_num_ok (void) |
|
296 { |
|
297 user_pref.implicit_str_to_num_ok = |
1505
|
298 check_preference ("implicit_str_to_num_ok"); |
1
|
299 |
|
300 return 0; |
|
301 } |
|
302 |
661
|
303 |
|
304 // Should we allow silent conversion of complex to real when a real |
1358
|
305 // type is what we're really looking for? |
661
|
306 |
1
|
307 int |
|
308 ok_to_lose_imaginary_part (void) |
|
309 { |
|
310 user_pref.ok_to_lose_imaginary_part = |
1505
|
311 check_preference ("ok_to_lose_imaginary_part"); |
1
|
312 |
|
313 return 0; |
|
314 } |
|
315 |
661
|
316 |
|
317 // If possible, send all output intended for the screen through the |
|
318 // pager. |
|
319 |
430
|
320 int |
|
321 page_screen_output (void) |
|
322 { |
1505
|
323 user_pref.page_screen_output = check_preference ("page_screen_output"); |
430
|
324 |
|
325 return 0; |
|
326 } |
|
327 |
661
|
328 |
|
329 // When doing assignments like: |
|
330 // |
|
331 // octave> A(1) = 3; A(2) = 5 |
|
332 // |
|
333 // (for A undefined) should we build column vectors? Returning true |
|
334 // only matters when resize_on_range_error is also true. |
|
335 |
1
|
336 int |
|
337 prefer_column_vectors (void) |
|
338 { |
|
339 user_pref.prefer_column_vectors = |
1505
|
340 check_preference ("prefer_column_vectors"); |
1
|
341 |
1907
|
342 liboctave_pcv_flag = user_pref.prefer_column_vectors; |
|
343 |
1
|
344 return 0; |
|
345 } |
|
346 |
661
|
347 |
|
348 // For things like |
|
349 // |
|
350 // a = [2,3]; a([1,1]) |
|
351 // |
|
352 // return [2 3] instead of [2 2]. |
|
353 |
1
|
354 int |
|
355 prefer_zero_one_indexing (void) |
|
356 { |
|
357 user_pref.prefer_zero_one_indexing = |
1505
|
358 check_preference ("prefer_zero_one_indexing"); |
1
|
359 |
1907
|
360 liboctave_pzo_flag = user_pref.prefer_zero_one_indexing; |
|
361 |
1
|
362 return 0; |
|
363 } |
|
364 |
661
|
365 |
|
366 // Should we print things like |
|
367 // |
|
368 // octave> a = [1,2;3,4] |
|
369 // a = |
|
370 // |
|
371 // 1 2 |
|
372 // 3 4 |
|
373 |
1
|
374 int |
|
375 print_answer_id_name (void) |
|
376 { |
|
377 user_pref.print_answer_id_name = |
1505
|
378 check_preference ("print_answer_id_name"); |
1
|
379 |
|
380 return 0; |
|
381 } |
|
382 |
661
|
383 |
|
384 // Should we also print the dimensions of empty matrices? |
|
385 |
430
|
386 int |
|
387 print_empty_dimensions (void) |
|
388 { |
|
389 user_pref.print_empty_dimensions = |
1505
|
390 check_preference ("print_empty_dimensions"); |
430
|
391 |
|
392 return 0; |
|
393 } |
|
394 |
661
|
395 |
|
396 // Should operations on empty matrices return empty matrices or an |
|
397 // error? |
|
398 |
1
|
399 int |
|
400 propagate_empty_matrices (void) |
|
401 { |
|
402 user_pref.propagate_empty_matrices = |
1505
|
403 check_preference ("propagate_empty_matrices"); |
1
|
404 |
|
405 return 0; |
|
406 } |
|
407 |
1045
|
408 // Should built-in constants always be read only? |
|
409 |
|
410 int |
|
411 read_only_constants (void) |
|
412 { |
1505
|
413 user_pref.read_only_constants = check_preference ("read_only_constants"); |
1045
|
414 |
|
415 return 0; |
|
416 } |
661
|
417 |
|
418 // When doing assignments, should we resize matrices if the indices |
|
419 // are outside the current bounds? |
|
420 |
1
|
421 int |
|
422 resize_on_range_error (void) |
|
423 { |
|
424 user_pref.resize_on_range_error = |
1505
|
425 check_preference ("resize_on_range_error"); |
1
|
426 |
1907
|
427 liboctave_rre_flag = user_pref.resize_on_range_error; |
|
428 |
1
|
429 return 0; |
|
430 } |
|
431 |
661
|
432 |
|
433 // If a function does not return any values explicitly, return the |
|
434 // last computed value. |
|
435 |
1
|
436 int |
|
437 return_last_computed_value (void) |
|
438 { |
|
439 user_pref.return_last_computed_value = |
1505
|
440 check_preference ("return_last_computed_value"); |
1
|
441 |
|
442 return 0; |
|
443 } |
|
444 |
661
|
445 |
1642
|
446 // Should we save command history? |
|
447 |
|
448 int |
|
449 saving_history (void) |
|
450 { |
|
451 user_pref.saving_history = check_preference ("saving_history"); |
1799
|
452 octave_command_history.ignore_entries (! user_pref.saving_history); |
1642
|
453 return 0; |
|
454 } |
|
455 |
|
456 |
661
|
457 // Suppress printing results in called functions. |
|
458 |
1
|
459 int |
|
460 silent_functions (void) |
|
461 { |
|
462 user_pref.silent_functions = |
1505
|
463 check_preference ("silent_functions"); |
1
|
464 |
|
465 return 0; |
|
466 } |
|
467 |
661
|
468 |
|
469 // Should should big matrices be split into smaller slices for output? |
|
470 |
1
|
471 int |
|
472 split_long_rows (void) |
|
473 { |
1505
|
474 user_pref.split_long_rows = check_preference ("split_long_rows"); |
1
|
475 |
|
476 return 0; |
|
477 } |
|
478 |
661
|
479 |
1198
|
480 // How many levels of structure elements should we print? |
|
481 |
|
482 int |
|
483 struct_levels_to_print (void) |
|
484 { |
|
485 double val; |
1505
|
486 if (builtin_real_scalar_variable ("struct_levels_to_print", val) |
1198
|
487 && ! xisnan (val)) |
|
488 { |
|
489 int ival = NINT (val); |
1201
|
490 if (ival >= 0 && (double) ival == val) |
1198
|
491 { |
|
492 user_pref.struct_levels_to_print = ival; |
1422
|
493 return 0; |
1198
|
494 } |
|
495 } |
1422
|
496 gripe_invalid_value_specified ("struct_levels_to_print"); |
|
497 return -1; |
1198
|
498 } |
|
499 |
|
500 |
1116
|
501 // Suppress printing of additional help message in help and usage |
|
502 // functions? |
|
503 |
|
504 int |
|
505 suppress_verbose_help_message (void) |
|
506 { |
|
507 user_pref.suppress_verbose_help_message = |
1505
|
508 check_preference ("suppress_verbose_help_message"); |
1116
|
509 |
|
510 return 0; |
|
511 } |
|
512 |
|
513 |
661
|
514 // Should things like: |
|
515 // |
|
516 // octave> ones (-1, 5) |
|
517 // |
|
518 // result in an empty matrix or an error? |
|
519 |
1
|
520 int |
|
521 treat_neg_dim_as_zero (void) |
|
522 { |
|
523 user_pref.treat_neg_dim_as_zero = |
1505
|
524 check_preference ("treat_neg_dim_as_zero"); |
1
|
525 |
|
526 return 0; |
|
527 } |
|
528 |
661
|
529 |
|
530 // Generate a warning for the assignment in things like |
|
531 // |
|
532 // octave> if (a = 2 < n) |
|
533 // |
|
534 // but not |
|
535 // |
|
536 // octave> if ((a = 2) < n) |
|
537 |
430
|
538 int |
|
539 warn_assign_as_truth_value (void) |
|
540 { |
|
541 user_pref.warn_assign_as_truth_value = |
1505
|
542 check_preference ("warn_assign_as_truth_value"); |
430
|
543 |
|
544 return 0; |
|
545 } |
|
546 |
661
|
547 |
|
548 // Generate a warning for the comma in things like |
|
549 // |
|
550 // octave> global a, b = 2 |
|
551 |
1
|
552 int |
|
553 warn_comma_in_global_decl (void) |
|
554 { |
|
555 user_pref.warn_comma_in_global_decl = |
1505
|
556 check_preference ("warn_comma_in_global_decl"); |
1
|
557 |
|
558 return 0; |
|
559 } |
|
560 |
661
|
561 |
|
562 // On IEEE machines, allow divide by zero errors to be suppressed. |
|
563 |
1
|
564 int |
|
565 warn_divide_by_zero (void) |
|
566 { |
1505
|
567 user_pref.warn_divide_by_zero = check_preference ("warn_divide_by_zero"); |
1
|
568 |
|
569 return 0; |
|
570 } |
|
571 |
1037
|
572 // Generate warning if declared function name disagrees with the name |
|
573 // of the file in which it is defined. |
|
574 |
|
575 int |
|
576 warn_function_name_clash (void) |
|
577 { |
|
578 user_pref.warn_function_name_clash = |
1505
|
579 check_preference ("warn_function_name_clash"); |
1037
|
580 |
|
581 return 0; |
|
582 } |
|
583 |
1093
|
584 |
1511
|
585 // Generate warning if a statement in a function is not terminated |
|
586 // with a semicolon. Useful for checking functions that should only |
|
587 // produce output using explicit printing statements. |
1509
|
588 |
|
589 int |
|
590 warn_missing_semicolon (void) |
|
591 { |
|
592 user_pref.warn_missing_semicolon = |
|
593 check_preference ("warn_missing_semicolon"); |
|
594 |
|
595 return 0; |
|
596 } |
|
597 |
|
598 |
1093
|
599 // Should whitespace in a literal matrix list be automatically |
|
600 // converted to commas and semicolons? |
|
601 // |
|
602 // user specifies value of pref |
|
603 // -------------- ------------- |
|
604 // "ignore" 2 |
|
605 // "traditional" 1 |
|
606 // anything else 0 |
|
607 // |
|
608 // Octave will never insert a comma in a literal matrix list if the |
|
609 // user specifies "ignore". For example, the statement [1 2] will |
|
610 // result in an error instead of being treated the same as [1, 2], and |
|
611 // the statement |
|
612 // |
|
613 // [ 1, 2, |
|
614 // 3, 4 ] |
|
615 // |
|
616 // will result in the vector [1 2 3 4] instead of a matrix. |
|
617 // |
|
618 // Traditional behavior makes Octave convert spaces to a comma between |
|
619 // identifiers and `('. For example, the statement |
|
620 // |
|
621 // [eye (2)] |
|
622 // |
|
623 // will be parsed as |
|
624 // |
|
625 // [eye, (2)] |
|
626 // |
|
627 // and will result in an error since the `eye' function will be |
|
628 // called with no arguments. To get around this, you would have to |
|
629 // omit the space between `eye' and the `('. |
|
630 // |
|
631 // The default value is 0, which results in behavior that is the same |
|
632 // as traditional, except that Octave does not convert spaces to a |
|
633 // comma between identifiers and `('. For example, the statement |
|
634 // |
|
635 // [eye (2)] |
|
636 // |
|
637 // will result in a call to `eye' with the argument `2'. |
|
638 |
|
639 int |
|
640 whitespace_in_literal_matrix (void) |
|
641 { |
|
642 int pref = 0; |
1755
|
643 string val = builtin_string_variable ("whitespace_in_literal_matrix"); |
|
644 if (! val.empty ()) |
1093
|
645 { |
1755
|
646 if (val.compare ("ignore", 0, 6) == 0) |
1093
|
647 pref = 2; |
1755
|
648 else if (val.compare ("traditional", 0, 11) == 0) |
1093
|
649 pref = 1; |
|
650 } |
|
651 user_pref.whitespace_in_literal_matrix = pref; |
|
652 return 0; |
|
653 } |
|
654 |
|
655 |
1
|
656 int |
|
657 set_output_max_field_width (void) |
|
658 { |
|
659 double val; |
1505
|
660 if (builtin_real_scalar_variable ("output_max_field_width", val) |
1086
|
661 && ! xisnan (val)) |
1
|
662 { |
|
663 int ival = NINT (val); |
|
664 if (ival > 0 && (double) ival == val) |
|
665 { |
1198
|
666 user_pref.output_max_field_width = ival; |
1422
|
667 return 0; |
1
|
668 } |
|
669 } |
1422
|
670 gripe_invalid_value_specified ("output_max_field_width"); |
|
671 return -1; |
1
|
672 } |
|
673 |
|
674 int |
|
675 set_output_precision (void) |
|
676 { |
|
677 double val; |
1505
|
678 if (builtin_real_scalar_variable ("output_precision", val) |
1086
|
679 && ! xisnan (val)) |
1
|
680 { |
|
681 int ival = NINT (val); |
|
682 if (ival >= 0 && (double) ival == val) |
|
683 { |
|
684 user_pref.output_precision = ival; |
1422
|
685 return 0; |
1
|
686 } |
|
687 } |
1422
|
688 gripe_invalid_value_specified ("output_precision"); |
|
689 return -1; |
1
|
690 } |
|
691 |
|
692 int |
275
|
693 set_save_precision (void) |
|
694 { |
|
695 double val; |
1505
|
696 if (builtin_real_scalar_variable ("save_precision", val) |
1086
|
697 && ! xisnan (val)) |
275
|
698 { |
|
699 int ival = NINT (val); |
|
700 if (ival >= 0 && (double) ival == val) |
|
701 { |
|
702 user_pref.save_precision = ival; |
1422
|
703 return 0; |
275
|
704 } |
|
705 } |
1422
|
706 gripe_invalid_value_specified ("save_precision"); |
|
707 return -1; |
275
|
708 } |
|
709 |
|
710 int |
1429
|
711 sv_completion_append_char (void) |
1
|
712 { |
|
713 int status = 0; |
|
714 |
1755
|
715 string s = builtin_string_variable ("completion_append_char"); |
|
716 |
|
717 switch (s.length ()) |
1
|
718 { |
1755
|
719 case 1: |
|
720 user_pref.completion_append_char = s[0]; |
|
721 break; |
|
722 |
|
723 case 0: |
|
724 user_pref.completion_append_char = '\0'; |
|
725 break; |
|
726 |
|
727 default: |
|
728 warning ("completion_append_char must be a single character"); |
430
|
729 status = -1; |
1755
|
730 break; |
430
|
731 } |
|
732 |
|
733 return status; |
|
734 } |
|
735 |
|
736 int |
605
|
737 sv_default_save_format (void) |
|
738 { |
|
739 int status = 0; |
|
740 |
1755
|
741 string s = builtin_string_variable ("default_save_format"); |
|
742 |
|
743 if (s.empty ()) |
605
|
744 { |
1416
|
745 gripe_invalid_value_specified ("default_save_format"); |
605
|
746 status = -1; |
|
747 } |
1755
|
748 else |
|
749 user_pref.default_save_format = s; |
605
|
750 |
|
751 return status; |
|
752 } |
|
753 |
|
754 int |
1429
|
755 sv_editor (void) |
|
756 { |
|
757 int status = 0; |
|
758 |
1755
|
759 string s = builtin_string_variable ("EDITOR"); |
|
760 |
|
761 if (s.empty ()) |
1429
|
762 { |
|
763 gripe_invalid_value_specified ("EDITOR"); |
|
764 status = -1; |
|
765 } |
1755
|
766 else |
|
767 user_pref.editor = s; |
1429
|
768 |
|
769 return status; |
|
770 } |
|
771 |
|
772 int |
1613
|
773 sv_exec_path (void) |
|
774 { |
|
775 int status = 0; |
|
776 |
1755
|
777 string exec_path = builtin_string_variable ("EXEC_PATH"); |
|
778 |
|
779 if (exec_path.empty ()) |
1613
|
780 { |
1755
|
781 gripe_invalid_value_specified ("EXEC_PATH"); |
|
782 status = -1; |
|
783 } |
|
784 else |
|
785 { |
|
786 string arch_dir = octave_arch_lib_dir (); |
|
787 string bin_dir = octave_bin_dir (); |
1613
|
788 |
1755
|
789 int len = arch_dir.length () + bin_dir.length () + strlen (SEPCHAR_STR); |
1613
|
790 |
|
791 static char *putenv_cmd = 0; |
|
792 |
|
793 delete [] putenv_cmd; |
|
794 |
|
795 putenv_cmd = 0; |
|
796 |
1755
|
797 int eplen = exec_path.length (); |
1613
|
798 |
|
799 if (eplen > 0) |
|
800 { |
|
801 int prepend = (exec_path[0] == ':'); |
|
802 int append = (eplen > 1 && exec_path[eplen-1] == ':'); |
|
803 |
|
804 if (prepend) |
|
805 { |
|
806 if (append) |
|
807 { |
|
808 putenv_cmd = new char [2 * len + eplen + 6]; |
|
809 sprintf (putenv_cmd, |
|
810 "PATH=%s" SEPCHAR_STR "%s%s%s" SEPCHAR_STR "%s", |
1755
|
811 arch_dir.c_str (), bin_dir.c_str (), |
|
812 exec_path.c_str (), arch_dir.c_str (), |
|
813 bin_dir.c_str ()); |
1613
|
814 } |
|
815 else |
|
816 { |
|
817 putenv_cmd = new char [len + eplen + 6]; |
|
818 sprintf (putenv_cmd, |
|
819 "PATH=%s" SEPCHAR_STR "%s%s", |
1755
|
820 arch_dir.c_str (), bin_dir.c_str (), |
|
821 exec_path.c_str ()); |
1613
|
822 } |
|
823 } |
|
824 else |
|
825 { |
|
826 if (append) |
|
827 { |
|
828 putenv_cmd = new char [len + eplen + 6]; |
|
829 sprintf (putenv_cmd, |
|
830 "PATH=%s%s" SEPCHAR_STR "%s", |
1755
|
831 exec_path.c_str (), arch_dir.c_str (), |
|
832 bin_dir.c_str ()); |
1613
|
833 } |
|
834 else |
|
835 { |
|
836 putenv_cmd = new char [len + eplen + 6]; |
1755
|
837 sprintf (putenv_cmd, "PATH=%s", exec_path.c_str ()); |
1613
|
838 } |
|
839 } |
|
840 } |
|
841 else |
|
842 { |
|
843 putenv_cmd = new char [len+6]; |
1755
|
844 sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", |
|
845 arch_dir.c_str (), bin_dir.c_str ()); |
1613
|
846 } |
|
847 |
|
848 putenv (putenv_cmd); |
|
849 } |
|
850 |
|
851 return status; |
|
852 } |
|
853 |
|
854 int |
430
|
855 sv_gnuplot_binary (void) |
|
856 { |
|
857 int status = 0; |
|
858 |
1755
|
859 string s = builtin_string_variable ("gnuplot_binary"); |
|
860 |
|
861 if (s.empty ()) |
430
|
862 { |
1416
|
863 gripe_invalid_value_specified ("gnuplot_binary"); |
1
|
864 status = -1; |
|
865 } |
1755
|
866 else |
|
867 user_pref.gnuplot_binary = s; |
1
|
868 |
|
869 return status; |
|
870 } |
|
871 |
|
872 int |
1646
|
873 sv_history_file (void) |
|
874 { |
|
875 int status = 0; |
|
876 |
1755
|
877 string s = builtin_string_variable ("history_file"); |
|
878 |
|
879 if (s.empty ()) |
1646
|
880 { |
|
881 gripe_invalid_value_specified ("history_file"); |
|
882 status = -1; |
|
883 } |
1755
|
884 else |
1799
|
885 { |
|
886 user_pref.history_file = s; |
|
887 octave_command_history.set_file (oct_tilde_expand (s)); |
|
888 } |
1646
|
889 |
|
890 return status; |
|
891 } |
|
892 |
|
893 int |
686
|
894 sv_imagepath (void) |
|
895 { |
|
896 int status = 0; |
|
897 |
1755
|
898 string s = builtin_string_variable ("IMAGEPATH"); |
|
899 |
|
900 if (s.empty ()) |
686
|
901 { |
1416
|
902 gripe_invalid_value_specified ("IMAGEPATH"); |
686
|
903 status = -1; |
|
904 } |
1755
|
905 else |
|
906 user_pref.imagepath = s; |
686
|
907 |
|
908 return status; |
|
909 } |
|
910 |
|
911 int |
186
|
912 sv_info_file (void) |
|
913 { |
|
914 int status = 0; |
|
915 |
1755
|
916 string s = builtin_string_variable ("INFO_FILE"); |
|
917 |
|
918 if (s.empty ()) |
186
|
919 { |
1416
|
920 gripe_invalid_value_specified ("INFO_FILE"); |
186
|
921 status = -1; |
|
922 } |
1755
|
923 else |
|
924 user_pref.info_file = s; |
186
|
925 |
|
926 return status; |
|
927 } |
|
928 |
|
929 int |
1613
|
930 sv_info_prog (void) |
|
931 { |
|
932 int status = 0; |
|
933 |
1755
|
934 string s = builtin_string_variable ("INFO_PROGRAM"); |
|
935 |
|
936 if (s.empty ()) |
1613
|
937 { |
|
938 gripe_invalid_value_specified ("INFO_PROGRAM"); |
|
939 status = -1; |
|
940 } |
1755
|
941 else |
|
942 user_pref.info_prog = s; |
1613
|
943 |
|
944 return status; |
|
945 } |
|
946 |
|
947 int |
430
|
948 sv_loadpath (void) |
195
|
949 { |
|
950 int status = 0; |
|
951 |
1755
|
952 string s = builtin_string_variable ("LOADPATH"); |
|
953 |
|
954 if (s.empty ()) |
195
|
955 { |
1416
|
956 gripe_invalid_value_specified ("LOADPATH"); |
430
|
957 status = -1; |
|
958 } |
1755
|
959 else |
|
960 user_pref.loadpath = maybe_add_default_load_path (s); |
430
|
961 |
|
962 return status; |
|
963 } |
|
964 |
|
965 int |
|
966 sv_pager_binary (void) |
|
967 { |
|
968 int status = 0; |
|
969 |
1755
|
970 string s = builtin_string_variable ("PAGER"); |
|
971 |
|
972 if (s.empty ()) |
430
|
973 { |
1416
|
974 gripe_invalid_value_specified ("PAGER"); |
195
|
975 status = -1; |
|
976 } |
1755
|
977 else |
|
978 user_pref.pager_binary = s; |
195
|
979 |
|
980 return status; |
|
981 } |
|
982 |
|
983 int |
1
|
984 sv_ps1 (void) |
|
985 { |
|
986 int status = 0; |
|
987 |
1755
|
988 string s = builtin_string_variable ("PS1"); |
|
989 |
|
990 if (s.empty ()) |
1
|
991 { |
1416
|
992 gripe_invalid_value_specified ("PS1"); |
1
|
993 status = -1; |
|
994 } |
1755
|
995 else |
|
996 user_pref.ps1 = s; |
1
|
997 |
|
998 return status; |
|
999 } |
|
1000 |
|
1001 int |
|
1002 sv_ps2 (void) |
|
1003 { |
|
1004 int status = 0; |
|
1005 |
1755
|
1006 string s = builtin_string_variable ("PS2"); |
|
1007 |
|
1008 if (s.empty ()) |
1
|
1009 { |
1416
|
1010 gripe_invalid_value_specified ("PS2"); |
1
|
1011 status = -1; |
|
1012 } |
1755
|
1013 else |
|
1014 user_pref.ps2 = s; |
1
|
1015 |
|
1016 return status; |
|
1017 } |
|
1018 |
|
1019 int |
1044
|
1020 sv_ps4 (void) |
|
1021 { |
|
1022 int status = 0; |
|
1023 |
1755
|
1024 string s = builtin_string_variable ("PS4"); |
|
1025 |
|
1026 if (s.empty ()) |
1044
|
1027 { |
1416
|
1028 gripe_invalid_value_specified ("PS4"); |
1044
|
1029 status = -1; |
|
1030 } |
1755
|
1031 else |
|
1032 user_pref.ps4 = s; |
1044
|
1033 |
|
1034 return status; |
|
1035 } |
|
1036 |
|
1037 int |
1
|
1038 sv_pwd (void) |
|
1039 { |
|
1040 int status = 0; |
|
1041 |
1755
|
1042 string s = builtin_string_variable ("PWD"); |
|
1043 |
|
1044 if (s.empty ()) |
1
|
1045 { |
1416
|
1046 gripe_invalid_value_specified ("PWD"); |
1
|
1047 status = -1; |
|
1048 } |
1755
|
1049 else |
|
1050 user_pref.pwd = s; |
1
|
1051 |
|
1052 return status; |
|
1053 } |
|
1054 |
|
1055 /* |
|
1056 ;;; Local Variables: *** |
|
1057 ;;; mode: C++ *** |
|
1058 ;;; End: *** |
|
1059 */ |