1 /* 2 * Mathomatic global variables and arrays. 3 * Most global variables for Mathomatic are defined here and duplicated in "externs.h". 4 * 5 * C initializes global variables and arrays to zero by default. 6 * This is required for proper operation. 7 * 8 * Copyright (C) 1987-2012 George Gesslein II. 9 10 This library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 This library is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this library; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 24 The chief copyright holder can be contacted at gesslein@mathomatic.org, or 25 George Gesslein II, P.O. Box 224, Lansing, NY 14882-0224 USA. 26 27 */ 28 29 #include "includes.h" 30 31 int n_tokens = DEFAULT_N_TOKENS; /* maximum size of expressions, must only be set during startup */ 32 33 int n_equations, /* number of equation spaces allocated */ 34 cur_equation; /* current equation space number (origin 0) */ 35 36 /* expression storage pointers and current length variables (they go together) */ 37 token_type *lhs[N_EQUATIONS], /* The Left Hand Sides of equation spaces */ 38 *rhs[N_EQUATIONS]; /* The Right Hand Sides of equation spaces */ 39 40 int n_lhs[N_EQUATIONS], /* number of tokens in each lhs[], 0 means equation space is empty */ 41 n_rhs[N_EQUATIONS]; /* number of tokens in each rhs[], 0 means not an equation */ 42 43 token_type *tlhs, /* LHS during solve and temporary storage for expressions, quotient for poly_div() and smart_div(). */ 44 *trhs, /* RHS during solve and temporary storage for expressions, remainder for poly_div() and smart_div(). */ 45 *tes, /* Temporary Equation Side, used in commands, simpa_repeat_side(), simple_frac_repeat_side(), etc. */ 46 *scratch; /* Very temporary storage for expressions, used only in low level routines for expression manipulation. */ 47 /* Do not run any functions on scratch[], except for blt() (which is memmove(3)). */ 48 49 int n_tlhs, /* number of tokens in tlhs */ 50 n_trhs, /* number of tokens in trhs */ 51 n_tes; /* number of tokens in tes */ 52 53 token_type zero_token, /* the universal constant 0.0 as an expression */ 54 one_token; /* the universal constant 1.0 as an expression */ 55 56 /* Set options with their initial values. */ 57 int precision = 14; /* the display precision for doubles (number of digits) */ 58 int case_sensitive_flag = true; /* "set case_sensitive" flag */ 59 int factor_int_flag; /* factor integers when displaying expressions */ 60 #if LIBRARY && !ROBOT_COMMAND 61 int display2d = false; /* "set no display2d" to allow feeding the output to the input */ 62 #else 63 int display2d = true; /* "set display2d" flag for 2D display */ 64 #endif 65 int fractions_display = 1; /* "set fraction" mode */ 66 int preserve_surds = true; /* set option to preserve roots like (2^.5) */ 67 int rationalize_denominators = true; /* try to rationalize denominators if true */ 68 int modulus_mode = 2; /* true for mathematically correct modulus */ 69 volatile int screen_columns = STANDARD_SCREEN_COLUMNS; /* screen width of the terminal; 0 = infinite */ 70 volatile int screen_rows = STANDARD_SCREEN_ROWS; /* screen height of the terminal; 0 = infinite */ 71 int finance_option = -1; /* for displaying dollars and cents */ 72 int autosolve = true; /* Allows solving by typing the variable name at the main prompt */ 73 int autocalc = true; /* Allows automatically calculating a numerical expression */ 74 int autodelete = false; /* Automatically deletes the previous calculated numerical expression when a new one is entered */ 75 int autoselect = true; /* Allows selecting equation spaces by typing the number */ 76 #if LIBRARY 77 char special_variable_characters[256] = "\\[]"; /* allow backslash in variable names for Latex compatibility */ 78 #else 79 char special_variable_characters[256] = "'\\[]"; /* user defined characters for variable names, '\0' terminated */ 80 #endif 81 #if MINGW 82 char plot_prefix[256] = "set grid; set xlabel 'X'; set ylabel 'Y';"; /* prefix fed into gnuplot before the plot command */ 83 #else 84 char plot_prefix[256] = "set grid; set xlabel \"X\"; set ylabel \"Y\";"; /* prefix fed into gnuplot before the plot command */ 85 #endif 86 int factor_out_all_numeric_gcds = false; /* if true, factor out the GCD of rational coefficients */ 87 int right_associative_power; /* if true, evaluate power operators right to left */ 88 int power_starstar; /* if true, display power operator as "**", otherwise "^" */ 89 #if !SILENT 90 int debug_level; /* current debug level */ 91 #endif 92 93 /* variables having to do with color output mode */ 94 #if LIBRARY || NO_COLOR 95 int color_flag = 0; /* library shouldn't default to color mode */ 96 #else 97 int color_flag = 1; /* "set color" flag; 0 for no color, 1 for color, 2 for alternative color output mode */ 98 #endif 99 #if BOLD_COLOR 100 int bold_colors = 1; /* "set bold color" flag for brighter colors */ 101 #else 102 int bold_colors = 0; /* bold_colors must be 0 or 1; 0 is dim */ 103 #endif 104 int text_color = -1; /* Current normal text color, -1 for no color */ 105 int cur_color = -1; /* memory of current color on the terminal */ 106 int html_flag; /* 1 for HTML mode on all standard output; 2 for HTML mode on all output, even redirected output */ 107 108 /* double precision floating point epsilon constants for number comparisons for equivalency */ 109 double small_epsilon = 0.000000000000005; /* for ignoring small, floating point round-off errors */ 110 double epsilon = 0.00000000000005; /* for ignoring larger, accumulated round-off errors */ 111 112 /* string variables */ 113 char *prog_name = "mathomatic"; /* name of this program */ 114 char *var_names[MAX_VAR_NAMES]; /* index for storage of variable name strings */ 115 char var_str[MAX_VAR_LEN+80]; /* temp storage for listing a variable name */ 116 char prompt_str[MAX_PROMPT_LEN]; /* temp storage for the prompt string */ 117 #if !SECURE 118 char rc_file[MAX_CMD_LEN]; /* pathname for the set options startup file */ 119 #endif 120 121 #if CYGWIN || MINGW 122 char *dir_path; /* directory path to the executable */ 123 #endif 124 #if READLINE || EDITLINE 125 char *last_history_string; /* To prevent repeated, identical entries. Must not point to temporary string. */ 126 #endif 127 #if READLINE 128 char *history_filename; 129 char history_filename_storage[MAX_CMD_LEN]; 130 #endif 131 132 /* The following are for integer factoring (filled by factor_one()): */ 133 double unique[64]; /* storage for the unique prime factors */ 134 int ucnt[64]; /* number of times the factor occurs */ 135 int uno; /* number of unique factors stored in unique[] */ 136 137 /* misc. variables */ 138 int previous_return_value = 1; /* Return value of last command entered. */ 139 sign_array_type sign_array; /* for keeping track of unique "sign" variables */ 140 FILE *default_out; /* file pointer where all gfp output goes by default */ 141 FILE *gfp; /* global output file pointer, for dynamically redirecting Mathomatic output */ 142 char *gfp_filename; /* filename associated with gfp if redirection is happening */ 143 int gfp_append_flag; /* true if appending to gfp, false if overwriting */ 144 jmp_buf jmp_save; /* for setjmp(3) to longjmp(3) to when an error happens deep within this code */ 145 int eoption; /* -e option flag */ 146 int test_mode; /* test mode flag (-t) */ 147 int demo_mode; /* demo mode flag (-d), don't load rc file or pause commands when true */ 148 int quiet_mode; /* quiet mode (-q, don't display prompts) */ 149 int echo_input; /* if true, echo input */ 150 int readline_enabled = true; /* set to false (-r) to disable readline */ 151 int partial_flag; /* normally true for partial unfactoring, false for "unfactor fraction" */ 152 int symb_flag; /* true during "simplify symbolic", which is not 100% mathematically correct */ 153 int symblify = true; /* if true, set symb_flag when helpful during solving, etc. */ 154 int high_prec; /* flag to output constants in higher precision (used when saving equations) */ 155 int input_column; /* current column number on the screen at the beginning of a parse */ 156 int sign_cmp_flag; /* true when all "sign" variables are to compare equal */ 157 int domain_check; /* flag to track domain errors in the pow() function */ 158 int approximate_roots; /* true if in calculate command (force approximation of roots like (2^.5)) */ 159 volatile int abort_flag; /* if true, abort current operation; set by control-C interrupt */ 160 int pull_number; /* equation space number to pull when using the library */ 161 int security_level; /* current enforced security level for session, -1 for m4 Mathomatic */ 162 int repeat_flag; /* true if the command is to repeat its function or simplification, set by repeat command */ 163 int show_usage; /* show command usage info if a command fails and this flag is true */ 164 int point_flag; /* point to location of parse error if true */ 165 166 /* library variables go here */ 167 char *result_str; /* returned result text string when using as library */ 168 int result_en = -1; /* equation number of the returned result, if stored in an equation space */ 169 const char *error_str; /* last error string */ 170 const char *warning_str; /* last warning string */ 171 172 /* Screen character array, for buffering page-at-a-time 2D string output: */ 173 char *vscreen[TEXT_ROWS]; 174 int current_columns; 175