1 #ifndef GLOBALH 2 #define GLOBALH 3 /* 4 * $Id: global.h,v 1.20 2001/02/14 20:54:50 danny Exp $ 5 * 6 * Copyright � 1990, 1992, 1993, 1999, 2000, 2001 Free Software Foundation, Inc. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2, or (at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this software; see the file COPYING. If not, write to 20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 #include <errno.h> 24 #include "sysdef.h" 25 #include "utils.h" 26 27 /* 28 * Constants for graphs 29 */ 30 #define NUM_DATASETS 10 31 32 enum graph_axis 33 { 34 graph_x = 0, 35 graph_y = 1, 36 graph_num_axis = 2 37 }; 38 39 /* 40 * These are named according to the outermost iterator. 41 * Thus graph_rows indicates that cells should be read in 42 * the loop: 43 * 44 * for (r = lr; r <= hr; ++r) 45 * for (c = lc; c <= hc; ++c) 46 * .... 47 */ 48 enum graph_ordering 49 { 50 graph_rows = 0, 51 graph_cols = 1, 52 graph_num_orders = 2 53 }; 54 55 /* These describe supported ways to iterate over a range extracting 56 * pairs of cells. 57 * 58 * There are two degrees of freedom: the 2 cells in each 59 * pair may be oriented horizontally or verically 60 * ______________ 61 * horizontal | 1 | 2 | 62 * -------------- 63 * 64 * 65 * -------- 66 * vertical | 1 | 67 * -------- 68 * | 2 | 69 * -------- 70 * 71 * or the first member of each pair may be implicitly supplied. 72 * In that case, the values used will be 0, 1, 2 ... 73 * 74 * Pairs themselves can be read off either row-wise or column-wise as above. 75 * 76 */ 77 78 enum graph_pair_orientation 79 { 80 graph_hz = 0, 81 graph_vt = 1, 82 graph_implicit = 2, 83 graph_num_pair_orientations = 3 84 }; 85 86 #define PAIR_ORDER(ORDER,ORNT) \ 87 (((ORDER) * graph_num_pair_orientations) + ORNT) 88 89 #define ORDER_OF_PAIRS(GPO) ((GPO) / graph_num_pair_orientations) 90 91 enum graph_pair_ordering 92 { 93 graph_rows_hz = PAIR_ORDER(graph_rows, graph_hz), 94 graph_rows_vt = PAIR_ORDER(graph_rows, graph_vt), 95 graph_rows_implicit = PAIR_ORDER(graph_rows, graph_implicit), 96 graph_cols_hz = PAIR_ORDER(graph_cols, graph_hz), 97 graph_cols_vt = PAIR_ORDER(graph_cols, graph_vt), 98 graph_cols_implicit = PAIR_ORDER(graph_cols, graph_implicit), 99 graph_num_pair_orders = graph_cols_implicit + 1 100 }; 101 102 #include <setjmp.h> 103 104 /* 105 * All kinds of other global stuff 106 */ 107 #define RCFILE ".oleorc" 108 109 /* The most important compile-time constant. How many bits do we want to 110 allocate for cell-references? Useful values are 8 and 16 (at the moment) 111 8 allows luser to access 255*255 cells (probably big enough) 112 16 allows luser to access 65535*65535, which is more than will fit in 113 the avaliable virtual memory on any 32-bit machine. 114 */ 115 116 #ifndef BITS_PER_CELLREF 117 #define BITS_PER_CELLREF 16 118 #endif 119 120 /* The location of a cell that can never be referenced */ 121 #define NON_ROW 0 122 #define NON_COL 0 123 124 #define MIN_ROW 1 125 #define MIN_COL 1 126 127 #if BITS_PER_CELLREF==16 128 typedef unsigned short CELLREF; 129 #define CELLREF_MASK 0xFFFF 130 #define MAX_ROW 65535 131 #define MAX_COL 65535 132 133 /* Do *not* assume that 'name' is aligned! It probably isn't */ 134 #define GET_ROW(name) ((((name)[0])<<8)|(name)[1]) 135 #define GET_COL(name) ((((name)[2])<<8)|(name)[3]) 136 #define PUT_ROW(name,val) ((name)[0]=((val)>>8)),((name)[1]=val) 137 #define PUT_COL(name,val) ((name)[2]=((val)>>8)),((name)[3]=val) 138 #define EXP_ADD sizeof(CELLREF)*2 139 #else 140 #if BITS_PER_CELLREF==8 141 typedef unsigned char CELLREF; 142 #define CELLREF_MASK 0xFF 143 #define MAX_ROW 255 144 #define MAX_COL 255 145 146 #define GET_ROW(name) ((name)[0]) 147 #define GET_COL(name) ((name)[1]) 148 #define PUT_ROW(name,val) ((name)[0]=(val)) 149 #define PUT_COL(name,val) ((name)[1]=(val)) 150 #define EXP_ADD sizeof(CELLREF)*2 151 #else 152 #error "FOO FOO FOO You need to define the obvious macros above" 153 #endif 154 #endif 155 156 /* Struct rng is used to describe a region of cells */ 157 struct rng 158 { 159 CELLREF lr, lc, hr, hc; 160 }; 161 162 #include "oleo_plot.h" 163 164 /* A ref_fm structure contains a list of all cells that reference some 165 * value. The value can be another cell or some global (such as the system 166 * time). 167 * 168 * These structures are hash-consed and shared. The hash-cons procedure 169 * will re-use a particular structure if there is only one reference to it. 170 */ 171 struct ref_fm 172 { 173 struct ref_fm *refs_next; 174 unsigned short refs_refcnt; 175 unsigned short refs_used; 176 struct ref_array 177 { 178 CELLREF ref_row; 179 CELLREF ref_col; 180 } fm_refs[1]; 181 }; 182 183 /* refs_to is a vector of locations in a formula where the 184 * cell references other cells, ranges, or variables 185 */ 186 struct ref_to 187 { 188 unsigned short refs_refcnt; 189 struct ref_to *refs_next; 190 unsigned short refs_used; 191 unsigned char to_refs[1]; 192 }; 193 194 /* These macros are used to extract/store ranges in compiled formulas. */ 195 #define GET_RNG(name,putit) bcopy((VOIDSTAR)(name),(VOIDSTAR)(putit),sizeof(struct rng)) 196 #define PUT_RNG(name,putit) bcopy((VOIDSTAR)(putit),(VOIDSTAR)(name),sizeof(struct rng)) 197 #define EXP_ADD_RNG sizeof(struct rng) 198 199 extern struct obstack tmp_mem; 200 extern VOIDSTAR tmp_mem_start; 201 202 /* Defined in io-utils.c: */ 203 #define ERR_MAX 17 204 extern char *ename[]; 205 extern char tname[]; 206 extern char fname[]; 207 extern char iname[]; 208 extern char mname[]; 209 extern char nname[]; 210 211 extern VOIDSTAR parse_hash; 212 extern double __plinf, __neinf, ___nan; 213 214 /* These have two uses. During parsing, these contain the 215 * base address of all relative references. During evaluation, 216 * these contain the address of the cell that is being updated. 217 * 218 * When MY_CELL is set, these should be the address of that cell. 219 * The address is used to recompute MY_CELL as the sparse array moves 220 * around. 221 * 222 * Whey are all these distinct uses bound up in one pair of GLOBAL 223 * variables? GOOD QUESTION? Why didn't the person who created the mess at 224 * least toss in a COMMENT like the above to explain what was happening? 225 * ANOTHER GOOD QUESTION! 226 */ 227 extern CELLREF cur_row, cur_col; 228 229 extern int default_jst; 230 extern int default_fmt, default_prc; 231 extern int default_lock; 232 233 extern unsigned short current_cycle; 234 extern int ioerror; 235 extern const char oleo_version_string[]; 236 237 extern double astof (char **); 238 extern long astol (char **); 239 extern void panic (const char *, ...); 240 241 extern VOIDSTAR init_stack (void); 242 extern void flush_stack (void *); 243 extern void push_stack (void *, void *); 244 extern VOIDSTAR pop_stack (void *); 245 extern int size_stack (void *); 246 247 extern void add_ref (CELLREF, CELLREF); 248 extern void add_range_ref (struct rng *); 249 extern void add_timer_ref (int); 250 extern void add_ref_to (int); 251 252 struct hash_control; /* in case it hasn't been declared yet */ 253 extern char *hash_insert (struct hash_control *, char *, VOIDSTAR); 254 extern char *flt_to_str (double); 255 extern void push_refs (struct ref_fm *); 256 extern void no_more_cells (void); 257 258 extern char *range_name (struct rng *); 259 extern char *cell_name (CELLREF, CELLREF); 260 261 extern char *new_value (CELLREF, CELLREF, char *); 262 263 extern unsigned char parse_cell_or_range (char **, struct rng *); 264 265 struct var; /* in case it hasn't been declared yet */ 266 extern void for_all_vars (void (*)(char *, struct var *)); 267 268 /* 269 * Forward declarations required to get the global variable to compile 270 */ 271 struct CursesGlobalType; 272 struct MotifGlobalType; 273 struct DatabaseGlobalType; 274 275 /* 276 * This structure is a start at cleaning up global variables that are 277 * around all over. 278 */ 279 struct OleoGlobal { 280 int valid; 281 char *FileName; /* current_file in io-utils.c */ 282 int modified; 283 CELLREF cur_row, cur_col; 284 /* User settable options */ 285 int bkgrnd_recalc, auto_recalc, a0, topclear, sylk_a0; 286 /* This is how frequently the alarm should go off. */ 287 unsigned int alarm_seconds; 288 /* This is whether the alarm should go off at all. */ 289 unsigned int alarm_active; 290 291 /* Jump here on error. This simply restarts the top 292 * level command loop. User state should have been 293 * reset appropriately before the longjmp. 294 */ 295 jmp_buf error_exception; 296 /* From Window.c */ 297 int scr_lines, scr_cols, user_input, user_status, input, 298 status, input_rows, status_rows, label_rows, label_emcols; 299 struct info_buffer *current_info; 300 int info_rows, info_line, info_over; 301 int default_right_border, default_bottom_border; 302 int nwin; 303 struct window *cwin, *wins; 304 int win_id; 305 306 struct MotifGlobalType *MotifGlobal; 307 struct CursesGlobalType *CursesGlobal; 308 struct DatabaseGlobalType *DatabaseGlobal; 309 struct PlotGlobalType *PlotGlobal; 310 311 /* From lists.c */ 312 float user_height_scale, user_width_scale, 313 height_scale, width_scale; 314 315 int cell_font_point_size, block_on_getch; 316 char *io_x11_display_name; 317 int run_load_hooks, sneaky_linec; 318 319 320 struct cf *fp; 321 struct list *the_cols, *wids, *hgts; 322 struct find *w_find, *h_find; 323 324 int display_formula_mode; 325 struct find *finds; 326 327 /* Basic.c */ 328 int auto_motion_direction; 329 330 /* List.c */ 331 char sl_sep; 332 333 int display_opened; 334 335 /* pcl.c */ 336 int need_formfeed; 337 338 /* print.c */ 339 float zoom; 340 struct PrintDriver *CurrentPrintDriver; 341 int interline, TopBorderHeight, BottomBorderHeight, 342 LeftBorderWidth, RightBorderWidth; 343 344 /* window.c */ 345 struct mouse_event *current_mouse, *free_mouse; 346 int mouse_id; 347 348 /* new stuff */ 349 char *encoding; 350 int return_from_error; 351 int had_error; 352 353 char *oldLocale; 354 }; 355 356 extern struct OleoGlobal *Global; 357 358 /* 359 * Determine which flags are set to indicate META-key 360 * OLEO_NUM_KEYS sizes a definition in key.h 361 */ 362 #define BACKSPACE 0x7f 363 364 #if 1 365 /* 366 * Hopefully 8-bit clean version 367 */ 368 #ifndef CTRL_CHAR 369 #define CTRL_CHAR(x) ((x)&037) 370 #endif 371 372 #define META_BIT 0x8000 /* Must be power of 2 */ 373 #define MASK_META_BIT (META_BIT - 1) /* used to be 0x7f */ 374 #define OLEO_NUM_KEYS 0x10000 375 376 #ifndef META 377 #define META(X) ((X)|0200) 378 #endif 379 380 #else 381 /* 8-bit diry version !! */ 382 383 #ifndef CTRL_CHAR 384 #define CTRL_CHAR(x) (x&037) 385 #endif 386 #ifndef META 387 #define META(X) ((X)|0200) 388 #endif 389 #define META_BIT 0x80 /* Must be power of 2 */ 390 #define MASK_META_BIT (META_BIT - 1) /* used to be 0x7f */ 391 392 #define OLEO_NUM_KEYS 256 393 #endif 394 395 #endif /* GLOBALH */ 396