1 /* 2 This file is part of GNU APL, a free implementation of the 3 ISO/IEC Standard 13751, "Programming Language APL, Extended" 4 5 Copyright (C) 2008-2015 Dr. Jürgen Sauermann 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __USER_PREFERENCES_HH_DEFINED__ 22 #define __USER_PREFERENCES_HH_DEFINED__ 23 24 #include <sys/time.h> 25 #include <string> 26 27 #include "Parallel.hh" 28 #include "UTF8_string.hh" 29 30 class Function; 31 32 /** a structure that contains user preferences from different sources 33 (command line arguments, config files, environment variables ...) 34 */ 35 /// Various preferences of the user 36 struct UserPreferences 37 { UserPreferencesUserPreferences38 UserPreferences() 39 : silent(false), 40 emacs_mode(false), 41 emacs_arg(0), 42 do_not_echo(false), 43 echo_CIN(false), 44 safe_mode(false), 45 user_do_svars(true), 46 system_do_svars(true), 47 do_CONT(true), 48 do_Color(true), 49 requested_id(0), 50 requested_par(0), 51 requested_cc(CCNT_UNKNOWN), 52 daemon(false), 53 append_summary(false), 54 wait_ms(0), 55 randomize_testfiles(false), 56 user_profile(0), 57 backup_before_save(false), 58 script_argc(0), 59 line_history_path(".apl.history"), 60 line_history_len(500), 61 nabla_to_history(1), // if function was modified 62 control_Ds_to_exit(0), 63 raw_cin(false), 64 initial_pw(DEFAULT_Quad_PW), 65 #define sec_def(X) X(false), 66 #include "Security.def" 67 multi_line_strings(true), 68 multi_line_strings_3(true), 69 WINCH_sets_pw(false), 70 auto_OFF(false), 71 CPU_limit_secs(0) 72 { gettimeofday(&session_start, 0); } 73 74 /// read a \b preference file and update parameters set there 75 void read_config_file(bool sys, bool log_startup); 76 77 /// read a \b parallel_thresholds file and update parameters set there 78 void read_threshold_file(bool sys, bool log_startup); 79 80 /// print possible command line options and exit 81 static void usage(const char * prog); 82 83 /// return " (default)" if yes is true is_defaultUserPreferences84 static const char * is_default(bool yes) 85 { return yes ? " (default)" : ""; } 86 87 /// print how the interpreter was configured (via ./configure) and exit 88 static void show_configure_options(); 89 90 /// print the GPL 91 static void show_GPL(ostream & out); 92 93 /// show version information 94 static void show_version(ostream & out); 95 96 /// parse command line parameters (before reading preference files) 97 bool parse_argv_1(); 98 99 /// parse command line parameters (after reading preference files) 100 void parse_argv_2(bool logit); 101 102 /// expand lumped arguments 103 void expand_argv(int argc, const char ** argv); 104 105 /// argv/argc at startup 106 std::vector<const char *> original_argv; 107 108 /// argv/argc after expand_argv 109 std::vector<const char *> expanded_argv; 110 111 /// when apl was started 112 timeval session_start; 113 114 /// true if no banner/Goodbye is wanted. 115 bool silent; 116 117 /// true if emacs mode is wanted 118 bool emacs_mode; 119 120 /// an argument for emacs mode 121 const char * emacs_arg; 122 123 /// true if no input echo is wanted. 124 bool do_not_echo; 125 126 /// true to echo input (after editing) 127 bool echo_CIN; 128 129 /// true if --safe command line option was given 130 bool safe_mode; 131 132 /// true if shared variables are wanted by the user 133 bool user_do_svars; 134 135 /// true if shared variables are enabled by the system. This is initially 136 /// the same as user_do_svars, but can become false if something goes wrong 137 bool system_do_svars; 138 139 /// load workspace CONTINUE on start-up 140 bool do_CONT; 141 142 /// output coloring enabled 143 bool do_Color; 144 145 /// desired --id (⎕AI[1] and shared variable functions) 146 int requested_id; 147 148 /// desired --par (⎕AI[1] and shared variable functions) 149 int requested_par; 150 151 /// desired core count 152 CoreCount requested_cc; 153 154 /// run as deamon 155 bool daemon; 156 157 /// append test results to summary.log rather than overriding it 158 bool append_summary; 159 160 /// wait at start-up 161 int wait_ms; 162 163 /// randomize the order of testfiles 164 bool randomize_testfiles; 165 166 /// the profile to be used (in the preferences file) 167 int user_profile; 168 169 /// something to be executed at startup (--LX) 170 UTF8_string latent_expression; 171 172 /// a workspace to be loaded at startup 173 UTF8_string initial_workspace; 174 175 /// backup on )SAVE 176 bool backup_before_save; 177 178 /// the argument number of the APL script name (if run from a script) 179 /// in expanded_argv, or 0 if apl is started directly. 180 size_t script_argc; 181 182 /// location of the input line history 183 UTF8_string line_history_path; 184 185 /// number of lines in the input line history 186 int line_history_len; 187 188 /// when function body shall go into the history 189 int nabla_to_history; 190 191 /// name of a user-provided keyboard layout file 192 UTF8_string keyboard_layout_file; 193 194 /// number of control-Ds to exit (0 = never) 195 int control_Ds_to_exit; 196 197 /// send no ESC sequences on stderr 198 bool raw_cin; 199 200 /// initial value of ⎕PW 201 int initial_pw; 202 203 #define sec_def(X) \ 204 bool X; ///< true if X is disabled dor security reasons 205 #include "Security.def" 206 207 /// true if old-style multi-line strings are allowed (in ∇-defined functions) 208 bool multi_line_strings; 209 210 /// true if new-style multi-line strings are allowed 211 bool multi_line_strings_3; 212 213 /// true if the WINCH signal shall modify ⎕PW 214 bool WINCH_sets_pw; 215 216 /// true if the interpreter shall )OFF on EOF of the last input file 217 bool auto_OFF; 218 219 /// limit (seconds) on the CPU time 220 int CPU_limit_secs; 221 protected: 222 /// open a user-supplied config file (in $HOME or gnu-apl.d) 223 FILE * open_user_file(const char * fname, char * opened_filename, 224 bool sys, bool log_startup); 225 226 /// set the parallel threshold of function \b fun to \b threshold 227 static void set_threshold(Function * fun, int padic, int macn, 228 ShapeItem threshold); 229 230 /// return true if file \b filename is an APL script (has execute permission 231 /// and starts with #! 232 static bool is_APL_script(const char * filename); 233 234 /// decode a byte in a preferences file. The byte can be given as ASCII name 235 /// (currently only ESC is understood), a single char (that stands for 236 /// itself), or 2 2-character hex value 237 /// 238 static int decode_ASCII(const char * strg); 239 }; 240 241 extern UserPreferences uprefs; 242 243 #endif // __USER_PREFERENCES_HH_DEFINED__ 244