Debian Codegraph @

texk/xdvik/xdvi.h

raw
1 /*========================================================================*\
2
3 Copyright (c) 1990-2019 Paul Vojta
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to
7 deal in the Software without restriction, including without limitation the
8 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 sell copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE
19 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 NOTE:
24 xdvi is based on prior work, as noted in the modification history
25 in xdvi.c.
26
27 \*========================================================================*/
28
29 /*
30 * Original version by Eric C. Cooper, CMU
31 */
32
33 #ifndef XDVI_H_
34 #define XDVI_H_
35
36 /* headers used by all modules */
37 #include "xdvi-debug.h"
38
39 #include "kpathsea/config.h" /* kpathsea definitions */
40
41 /********************************
42 * The C environment *
43 *******************************/
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <limits.h>
48
49 /* in case stdlib.h doesn't define these ... */
50 #ifndef EXIT_SUCCESS
51 # define EXIT_SUCCESS 0
52 #endif
53
54 #ifndef EXIT_FAILURE
55 # define EXIT_FAILURE 1
56 #endif
57
58 #ifdef HAVE_WORKING_NL_LANGINFO_CODESET
59 # define USE_LANGINFO 1
60 #else
61 # define USE_LANGINFO 0
62 #endif
63
64 #if HAVE_SYS_WAIT_H
65 # include <sys/wait.h>
66 #endif
67
68 #ifndef WIFEXITED
69 # define WIFEXITED(status) (((status) & 255) == 0)
70 #endif
71
72 #ifndef WEXITSTATUS
73 # define WEXITSTATUS(status) ((unsigned)(status) >> 8)
74 #endif
75
76 #ifndef WIFSIGNALED
77 # ifndef WIFSTOPPED
78 # define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
79 # endif
80 # define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status))
81 #endif
82
83 #ifndef WTERMSIG
84 # define WTERMSIG(status) ((status) & 0x7f)
85 #endif
86
87 #if A4
88 # define DEFAULT_PAPER "a4"
89 #else
90 # define DEFAULT_PAPER "us"
91 #endif
92
93 /*
94 * Define to 1 if you want to use the experimental font creation code
95 */
96 #define DELAYED_MKTEXPK 0
97
98 #ifdef __hpux
99 /* On HP-UX 10.10 B and 20.10, compiling with _XOPEN_SOURCE + ..._EXTENDED
100 * leads to poll() not realizing that a file descriptor is writable in psgs.c.
101 */
102 # define _HPUX_SOURCE 1
103 #else
104 # ifndef _XOPEN_SOURCE
105 # define _XOPEN_SOURCE 600
106 # endif
107 # define _XOPEN_SOURCE_EXTENDED 1
108 # define __EXTENSIONS__ 1 /* needed to get struct timeval on SunOS 5.5 */
109 # define _SVID_SOURCE 1 /* needed to get S_IFLNK in glibc */
110 # define _BSD_SOURCE 1 /* needed to get F_SETOWN in glibc-2.1.3 */
111 #endif
112
113 /* Some O/S dependent kludges. */
114 #ifdef _AIX
115 # define _ALL_SOURCE 1
116 #endif
117
118 /* just a kludge, no real portability here ... */
119 #define DIR_SEPARATOR '/'
120
121 #if STDC_HEADERS
122 # include <stddef.h>
123 # include <stdlib.h>
124 /* the following works around the wchar_t problem */
125 # include <X11/X.h>
126 # if HAVE_X11_XOSDEFS_H
127 # include <X11/Xosdefs.h>
128 # endif
129 # ifdef X_NOT_STDC_ENV
130 # undef X_NOT_STDC_ENV
131 # undef X_WCHAR
132 # include <X11/Xlib.h>
133 # define X_NOT_STDC_ENV
134 # endif
135 #endif /* STDC_HEADERS */
136
137 /* For wchar_t et al., that the X files might want. */
138 #include "kpathsea/systypes.h"
139 #include "kpathsea/c-memstr.h"
140
141 #ifdef HAVE_SYS_PARAM_H
142 # include <sys/param.h> /* this should define MAXPATHLEN */
143 #endif
144
145 #include "kpathsea/c-pathmx.h" /* get fallback for PATH_MAX if all else fails */
146
147 #include <X11/Xlib.h> /* include Xfuncs.h, if available */
148 #include <X11/Xutil.h> /* needed for XDestroyImage */
149 #include <X11/Xos.h>
150
151 #include <X11/Xfuncs.h>
152 #include <X11/Intrinsic.h>
153
154 #if HAVE_XI21
155 # include <X11/extensions/XInput2.h> /* for hi-res (smooth) scrolling */
156 #endif
157
158 #ifndef MAXPATHLEN
159 # ifdef PATH_MAX
160 # define MAXPATHLEN PATH_MAX
161 # else
162 # define MAXPATHLEN 1024
163 # endif
164 #endif
165
166 typedef char Bool3; /* Yes/No/Maybe */
167 #define True 1
168 #define False 0
169 #define Maybe 2
170
171
172 #ifdef DEBUG
173 # include<asm/msr.h>
174 extern unsigned long time_start, time_end;
175 #endif
176
177 #include <X11/Xmd.h> /* get WORD64 and LONG64 */
178
179 #if defined(HAVE_STDINT_H)
180 #include <stdint.h>
181 #elif defined(HAVE_INTTYPES_H)
182 #include <inttypes.h>
183 #endif
184
185 /* for unused parameters */
186 #ifndef UNUSED
187 # define UNUSED(x) ((void)(x))
188 #endif
189
190 #include <string.h>
191
192 #include <stdio.h>
193 #include <setjmp.h>
194
195 #if HAVE_UNISTD_H
196 # include <unistd.h>
197 #endif
198
199 /* all of these are POSIX and should have been defined by unistd.h: */
200 #ifndef STDIN_FILENO
201 # define STDIN_FILENO 0
202 #endif
203
204 #ifndef STDOUT_FILENO
205 # define STDOUT_FILENO 1
206 #endif
207
208 #ifndef STDERR_FILENO
209 # define STDERR_FILENO 2
210 #endif
211
212 /* see C FAQ; additional +1 for '\0' */
213 #define LENGTH_OF_INT ((sizeof(int) * CHAR_BIT + 2) / 3 + 1 + 1)
214 #define LENGTH_OF_LONG ((sizeof(long) * CHAR_BIT + 2) / 3 + 1 + 1)
215 #define LENGTH_OF_ULONG ((sizeof(unsigned long) * CHAR_BIT + 2) / 3 + 1 + 1)
216
217 #include "kpathsea/c-dir.h" /* dirent.h, NAMLEN */
218
219 #include <stdarg.h>
220 #include "kpathsea/c-fopen.h"
221 #include "kpathsea/version.h"
222
223 #ifndef _XFUNCPROTOBEGIN
224 # define _XFUNCPROTOBEGIN
225 # define _XFUNCPROTOEND
226 #endif
227
228
229 /* If xmkmf is broken and there's a symlink from /usr/include/X11 to the right
230 * place, then there will be no -I... argument on the cc command line for the
231 * X include files. Since gcc version 3 and higher sets __STDC__ to 0 when
232 * including system header files on some platforms, we may end up with
233 * NeedFunctionPrototypes set to 0 when it should be 1. So, let's force the
234 * issue.
235 */
236 #if __STDC__ && !defined(FUNCPROTO)
237 /* FUNCPROTO is a bitmask specifying ANSI conformance (see Xfuncproto.h).
238 The single bits specify varargs, const availability, prototypes etc.;
239 we enable everything here. */
240 # define FUNCPROTO (-1)
241 #endif
242
243 #ifndef VOLATILE
244 # if __STDC__ || (defined(__stdc__) && defined(__convex__))
245 # define VOLATILE volatile
246 # else
247 # define VOLATILE /* as nothing */
248 # endif
249 #endif
250
251 #ifndef OPEN_MODE
252 /*
253 * SU, 2001/01/07: xdvi defines OPEN_MODE as "r" or as "r", "ctx=stm" (for VMS),
254 * but we use the definition of FOPEN_R_MODE from kpathsea/c-fopen.h instead:
255 */
256 # define OPEN_MODE FOPEN_R_MODE
257 #endif /* OPEN_MODE */
258
259 #ifndef VMS
260 # define OPEN_MODE_ARGS const char *
261 #else
262 # define OPEN_MODE_ARGS const char *, const char *
263 #endif
264
265 #ifndef __LINE__
266 # define __LINE__ 0
267 #endif
268
269 #ifndef __FILE__
270 # define __FILE__ "?"
271 #endif
272
273 #define MAXDIM 32767
274
275 typedef unsigned char ubyte;
276
277 typedef unsigned int wide_ubyte;
278 typedef int wide_bool;
279
280 #if defined(MAKEPK) && !defined(MKTEXPK)
281 # define MKTEXPK 1
282 #endif
283
284 #define spell_conv0(n, f) ((long) (n * f))
285 #define spell_conv(n) spell_conv0(n, dimconv)
286
287 typedef BMTYPE bmTypeT;
288 typedef unsigned BMTYPE bmUnitT;
289 /* #define BMUNIT unsigned BMTYPE */
290 #define BMBITS (8 * BMBYTES) /* number of bits in a bmTypeT */
291
292 #define ADD(a, b) ((bmUnitT *) (((char *) a) + b))
293 #define SUB(a, b) ((bmUnitT *) (((char *) a) - b))
294
295 extern bmUnitT bit_masks[BMBITS + 1];
296
297 /* for safely printing char *s that might be NULL */
298 #define STRING_OR_NULL(x) ((x == NULL ? "<NULL>" : x))
299
300 #define INSIDE_MANE_WIN ((currwin.win == mane.win))
301 #define MAGNIFIER_ACTIVE ((magnifier.win != 0))
302 /* #define MAGNIFIER_ACTIVE ((globals.cursor.flags & CURSOR_MAG)) */
303
304 #define mane_base_x 0
305 #define mane_base_y 0
306
307
308 struct frame {
309 /* dvi_h and dvi_v is the horizontal and vertical baseline position;
310 it is the responsability of the set_char procedure to update
311 them. */
312 struct framedata {
313 long dvi_h, dvi_v, w, x, y, z;
314 int pxl_v;
315 } data;
316 struct frame *next, *prev;
317 };
318
319 #ifdef TEXXET
320 typedef void setcharRetvalT;
321 #else
322 typedef long setcharRetvalT;
323 #endif
324
325 typedef setcharRetvalT (*set_char_proc) (
326 #ifdef TEXXET
327 wide_ubyte cmd,
328 #endif
329 wide_ubyte ch);
330
331 #define ROUNDUP(x,y) (((x)+(y)-1)/(y))
332
333 #ifndef BDPI
334 # define BDPI 600
335 #endif
336
337 #if defined(GS_PATH) && !defined(PS_GS)
338 # define PS_GS 1
339 #endif
340
341 #if defined(PS_DPS) || defined(PS_NEWS) || defined(PS_GS)
342 # define PS 1
343 #else
344 # define PS 0
345 #endif
346
347 #ifdef MOTIF
348 # include <Xm/Xm.h>
349
350 /* Note: non-k xdvi has MOTIF_TIMERS here, we use XDVI_XT_TIMER_HACK instead (see above) */
351
352 # ifndef DDIST
353 # define DDIST 4
354 # endif
355 # ifndef DDIST_MAJOR
356 # define DDIST_MAJOR 10
357 # endif
358 # ifndef DDIST_MINOR
359 # define DDIST_MINOR 5
360 # endif
361
362 extern XmStringCharSet G_charset;
363
364 /*
365 * Whether to use some widgets which are only available with Motif 2.0.
366 * In these cases, the LessTif versions are either buggy or visually
367 * inferior (as of lesstif-0.93.18), in which case suitable replacements
368 * should be used; e.g. cascade button or a textfield plus button for
369 * a combobox, or a textfield plus button for a spinbox.
370 */
371 # if XmVersion >= 2000 && !defined(LESSTIF_VERSION)
372 # define USE_COMBOBOX 1
373 # define Xdvi_COMBO_BOX_ARROW_SIZE 15 /* the default arrows are *way* too big */
374 # define USE_SPINBOX 1
375 # else
376 # define USE_COMBOBOX 0
377 # define USE_SPINBOX 0
378 # endif
379
380 #endif /* MOTIF */
381
382 typedef enum {
383 XPRT_SHOW_NONE = 0U,
384 XPRT_SHOW_STATUSLINE = 1,
385 XPRT_SHOW_SCROLLBARS = 2,
386 #ifdef MOTIF
387 XPRT_SHOW_PAGELIST = 4,
388 XPRT_SHOW_TOOLBAR = 8,
389 XPRT_SHOW_MENUBAR = 16,
390 XPRT_SHOW_ALL = 31
391 #else
392 XPRT_SHOW_BUTTONS = 4,
393 XPRT_SHOW_ALL = 7
394 #endif /* MOTIF */
395 } expertFlagT;
396
397 typedef enum {
398 MOUSE_MODE1,
399 MOUSE_MODE2,
400 MOUSE_MODE3,
401 MOUSE_MODE_MAX
402 } mouseModeT;
403
404 typedef enum {
405 NO_MODE_ACTIVE,
406 RULER_MODE_ACTIVE,
407 TEXT_MODE_ACTIVE
408 } modeFlagT;
409
410 /* SUBPIXEL_NONE for no subpixel rendering, otherwise order of subpixels
411 (from option/resource subPixels) */
412 typedef enum { SUBPIXEL_NONE, SUBPIXEL_RGB, SUBPIXEL_BGR } subpixelOrderT;
413
414 /*
415 * X resources.
416 */
417 extern struct x_resources {
418 /* NOTE: we don't use CFGFILE */
419 Boolean no_init_file;
420 Boolean regression;
421 const char *geometry;
422 const char *windowsize;
423 Boolean remember_windowsize;
424 int app_defaults_fileversion;
425 mouseModeT mouse_mode;
426 Boolean use_tex_pages;
427 int shrinkfactor;
428 const char *main_translations;
429 const char *mouse_translations;
430 /* const char *wheel_translations; */
431 int wheel_unit;
432 int density;
433 Boolean omega;
434 const char *mouse_mode1_name;
435 const char *mouse_mode1_description;
436 int mouse_mode1_cursor;
437 const char *mouse_mode2_name;
438 const char *mouse_mode2_description;
439 int mouse_mode2_cursor;
440 const char *mouse_mode3_name;
441 const char *mouse_mode3_description;
442 int mouse_mode3_cursor;
443 #ifdef GREY
444 float gamma;
445 /* float inverted_factor; */
446 #endif
447 int pixels_per_inch;
448 Boolean delay_rulers;
449 int tick_length;
450 char *tick_units;
451 const char *sidemargin;
452 int sidemargin_int;
453 const char *topmargin;
454 int topmargin_int;
455 const char *xoffset;
456 int xoffset_int;
457 const char *yoffset;
458 int yoffset_int;
459 Boolean use_current_offset; /* only used internally */
460 const char *paper;
461 Boolean paper_landscape; /* only used internally */
462 const char *alt_font;
463 #ifdef MKTEXPK
464 Boolean makepk;
465 #endif
466 const char *mfmode;
467 const char *editor;
468 #ifdef MOTIF
469 char *prefs_editor_list;
470 #endif
471 Boolean freetype;
472 #if HAVE_XI21
473 Boolean xi2scrolling;
474 #endif
475 const char *src_pos;
476 const char *find_string;
477 const char *text_encoding;
478 Boolean src_fork;
479 const char *sub_pixels;
480 const char *file_history;
481 int file_history_size;
482 Boolean no_file_arg_use_history;
483 #if RGB_ANTI_ALIASING
484 subpixelOrderT subpixel_order;
485 float subpixel_energy[3];
486 #endif
487 Boolean unique;
488 Boolean list_fonts;
489 Boolean reverse;
490 Boolean warn_spec;
491 Boolean hush;
492 Boolean hush_chars;
493 Boolean hush_chk;
494 Boolean hush_stdout;
495 Boolean hush_bell;
496 Boolean safer;
497 #ifdef VMS
498 const char *fore_color;
499 const char *back_color;
500 #endif
501 Pixel fore_Pixel;
502 Pixel back_Pixel;
503 /* Pixel brdr_Pixel; */
504 Pixel hl_Pixel;
505 Pixel cr_Pixel;
506 const char *icon_geometry;
507 Boolean keep_flag;
508 Boolean copy;
509 Boolean thorough;
510 Boolean pause;
511 const char *pause_special;
512 Boolean fullscreen;
513 #ifdef PS
514 int postscript;
515 Boolean allow_shell;
516 # ifdef PS_DPS
517 Boolean useDPS;
518 # endif
519 # ifdef PS_NEWS
520 Boolean useNeWS;
521 # endif
522 # ifdef PS_GS
523 Boolean useGS;
524 Boolean gs_safer;
525 Boolean gs_alpha;
526 const char *gs_path;
527 const char *gs_palette;
528 int gs_timeout;
529 # endif
530 # ifdef MAGICK
531 Boolean useMAGICK;
532 const char *magick_cache;
533 # endif
534 #endif /* PS */
535 Boolean prescan;
536 Boolean use_temp_fp;
537 const char *debug_arg;
538 const char *menu_translations;
539 Boolean expert;
540 float watch_file; /* check DVI file every so often, in seconds */
541 int expert_mode;
542 #ifndef MOTIF
543 Dimension btn_side_spacing;
544 Dimension btn_top_spacing;
545 Dimension btn_between_spacing;
546 /* ignored, only for backwards compatibility */
547 Dimension btn_between_extra;
548 Dimension btn_border_width;
549 #else /* MOTIF */
550 const char *toolbar_translations;
551 #endif /* MOTIF */
552 Boolean statusline;
553 #ifdef MOTIF
554 /* not a user-level resource; indicates a problem with the toolbar, in
555 which case the toolbar is disabled. */
556 Boolean toolbar_unusable;
557 const char *toolbar_pixmap_file;
558 Boolean toolbar_buttons_raised;
559 Boolean tooltips_in_statusline;
560 int tooltips_wait_period; /* used for communication with Tip.c */
561 int tooltips_wait_period_bak; /* uncustomized value */
562 Boolean show_tooltips;
563 #endif /* MOTIF */
564 Boolean pagelist_highlight_current;
565 Dimension pagelist_width;
566 const char *mg_arg[5];
567 #if COLOR
568 Boolean use_color;
569 #endif
570 #ifdef GREY
571 Boolean use_grey;
572 Bool3 install;
573 #endif
574 Boolean match_highlight_inverted;
575 const char *dvips_path;
576 const char *ps2pdf_path;
577 int dvips_hang;
578 int dvips_fail_hang;
579 const char *dvips_printer_str;
580 const char *dvips_options_str;
581 int default_saving_format;
582 int default_printing_target;
583 int grid_mode;
584 char *rule_color;
585 Pixel rule_pixel;
586 int link_style;
587 char *link_color;
588 char *visited_link_color;
589 char *browser;
590 #ifdef MOTIF
591 char *prefs_browser_list;
592 # if USE_COMBOBOX
593 char *search_history;
594 int search_history_size;
595 # endif
596 #endif /* MOTIF */
597 char *unknown_mime_suffix;
598 char *no_mime_suffix;
599 char *anchor_pos;
600 /* whether to open file in new window from file selector (only for DVI files) */
601 Boolean filesel_open_new_window;
602 /* bitmask of current search window settings */
603 unsigned int search_window_defaults;
604 /* char * _scroll_pages; */
605 char *help_general;
606 char *help_hypertex;
607 char *help_othercommands;
608 char *help_pagemotion;
609 char *help_marking;
610 char *help_modes;
611 char *help_search;
612 char *help_mousebuttons;
613 char *help_sourcespecials;
614 int page_history_size;
615 } resource;
616
617 extern void load_app_resources(Boolean also_pixels);
618
619
620 struct WindowRec {
621 Window win;
622 int shrinkfactor;
623 int base_x;
624 int base_y;
625 unsigned int width;
626 unsigned int height;
627 /* for pending expose events */
628 int min_x;
629 int max_x;
630 int min_y;
631 int max_y;
632 };
633
634 struct event_info {
635 int flags;
636 VOLATILE int ctr;
637 jmp_buf canit;
638 jmp_buf next; /* to skip next event */
639 };
640
641 struct pause_info {
642 int num;
643 int *num_save;
644 Boolean flag;
645 };
646
647 struct gc_info {
648 GC rule;
649 GC fore;
650 GC inverted;
651 GC high;
652 GC linkcolor;
653 GC visited_linkcolor;
654 GC fore2;
655 GC fore2_bak;
656 GC fore2_bak1;
657 GC copy;
658 GC ruler;
659 Boolean do_copy;
660 };
661
662 /* flags for special cursor states */
663 #define CURSOR_LINK 1 /* hyperlink */
664 #define CURSOR_MAG 2 /* magnifier is mapped */
665 #define CURSOR_DRAG_V 4 /* vertical dragging */
666 #define CURSOR_DRAG_H 8 /* horizontal dragging */
667 #define CURSOR_DRAG_A 16 /* dragging in any direction */
668 #define CURSOR_CORRUPTED 32 /* DVI file corrupted */
669 #define CURSOR_TEXT 64 /* DVI file corrupted */
670 #define CURSOR_RULER 128 /* DVI file corrupted */
671
672 /* cursors for all states */
673 struct cursor_info {
674 Cursor mode1;
675 Cursor mode2;
676 Cursor mode3;
677
678 Cursor wait;
679 Cursor corrupted;
680 /* hyperlink */
681 Cursor link;
682 /* horizontal/vertical/all directions drag */
683 Cursor drag_h;
684 Cursor drag_v;
685 Cursor drag_a;
686 /* support for `pause' feature */
687 Cursor pause;
688 /* empty cursor */
689 Cursor empty;
690
691 /* one of the flags defined above */
692 unsigned long flags;
693 };
694
695 struct window_expose_info {
696 int min_x, max_x, min_y, max_y;
697 };
698
699 /* for communication with forward search in dvi-draw.c */
700 struct src_info {
701 int fwd_box_page;
702 const char *fwd_string;
703 };
704
705 struct widget_info {
706 Widget top_level;
707 Widget draw_widget, draw_background, clip_widget;
708 Widget x_bar, y_bar;
709 #ifdef MOTIF
710 Widget main_window, main_row, tool_bar, top_row, menu_bar;
711 #else
712 Widget vport_widget, form_widget, paned;
713 #endif
714 };
715
716 struct page_info {
717 unsigned int w, h;
718 unsigned int unshrunk_w, unshrunk_h;
719 };
720
721 struct dvi_file_info {
722 char *dirname;
723 size_t dirlen;
724 FILE *bak_fp;
725 time_t time; /* last file modification time */
726 };
727
728 /* struct to hold global settings that can't go into the resources,
729 * as a replacement for global variables:
730 */
731 extern struct program_globals {
732 XtAppContext app;
733 const char *program_name; /* argv[0] without the directory part */
734 const char *cwd; /* directory where xdvi is running in (for childs who need to change back to it) */
735 char *dvi_name; /* dvi file name, fully expanded with REALPATH */
736 Boolean load_init_file; /* whether to read/save ~/.xdvirc */
737 char *orig_locale; /* original locale we are running in */
738 unsigned long debug; /* debugging option */
739
740 /* for older Motif versions or LessTif, which have broken
741 handling of Act_motion() / Act_release() events */
742 Boolean broken_motif_event_handling;
743
744 /* offset from c-style (0 based) numbers to real pagenumbers;
745 also contains the offset that user has set via Act_declare_page_number() */
746 int pageno_correct;
747
748 /* paper unit used for grid mode */
749 unsigned int grid_paper_unit;
750
751 /* whether we warn about unrecognized specials. Copy of resource.warn_spec value,
752 set to False in the drawing routine to reduce the amount of warnings given.
753 Better maybe replace with hash lookup similar to fonts warnings? */
754 Boolean warn_spec_now;
755
756 /* used to save X resource values */
757 char *curr_paper;
758 char *curr_editor;
759 char *curr_browser;
760 float curr_gamma;
761 Boolean curr_use_color;
762
763 modeFlagT curr_mode;
764
765 /* forward search info */
766 struct src_info src;
767
768 /* event information */
769 struct event_info ev;
770
771 /* support for `-pause' feature */
772 struct pause_info pausing;
773
774 /* window expose information */
775 struct window_expose_info win_expose;
776
777 struct gc_info gc;
778
779 /* cursor information */
780 struct cursor_info cursor;
781
782 /* widget information */
783 struct widget_info widgets;
784
785 /* page size info */
786 struct page_info page;
787
788 /* DVI file and modification time info */
789 struct dvi_file_info dvi_file;
790
791 } globals;
792
793
794 /* TODO: put these into globals as well */
795 extern struct WindowRec mane;
796 extern struct WindowRec currwin;
797 extern struct WindowRec magnifier;
798
799
800 extern XtAppContext app;
801 extern char *dvi_property; /* for setting in window */
802 extern size_t dvi_property_length;
803 extern XImage *G_image;
804 extern int G_backing_store;
805 /* extern int home_x, home_y; */
806
807 extern Display *DISP;
808 extern Screen *SCRN;
809
810 extern XtAccelerators G_accels_cr;
811 #ifdef GREY
812 extern Visual *G_visual;
813 extern unsigned int G_depth;
814 extern Colormap G_colormap;
815 #else
816 # define G_depth (unsigned int) DefaultDepthOfScreen(SCRN)
817 # define G_visual DefaultVisualOfScreen(SCRN)
818 # define G_colormap DefaultColormapOfScreen(SCRN)
819 #endif
820
821
822 #define TNTABLELEN 30 /* length of TeXnumber array (dvi file) */
823 #define VFTABLELEN 5 /* length of TeXnumber array (virtual fonts) */
824
825 extern struct font *tn_table[TNTABLELEN];
826 extern struct font *font_head;
827 extern struct tn *tn_head;
828 extern wide_ubyte maxchar;
829 extern unsigned short current_timestamp;
830
831 extern int current_page;
832 extern int total_pages;
833
834 extern unsigned long magnification;
835 extern double dimconv;
836 extern double tpic_conv;
837
838 /* whether this file contains source specials, so that we need to
839 update the `windows' property for forward search on expose events:
840 */
841 extern Boolean have_src_specials;
842
843 extern Boolean dragcurs; /* whether drag cursor is active; needed by hypertex.c */
844 extern int drag_flags; /* 1 = vert, 2 = horiz; also needed by hypertex.c */
845
846 typedef void (*mouse_proc) (XEvent *);
847 extern mouse_proc mouse_motion;
848 extern mouse_proc mouse_release;
849
850 struct mouse_acts {
851 Modifiers mask;
852 Modifiers value;
853 struct _LateBindings *late_bindings;
854 unsigned int button;
855 struct xdvi_action *action;
856 struct mouse_acts *next;
857 };
858
859 extern struct mouse_acts *mouse_actions;
860
861 #if GREY
862 extern Pixel plane_masks[4];
863 #endif
864
865 #if GREY || COLOR
866 extern XColor color_data[2];
867 #endif
868
869 #if COLOR
870 struct rgb {
871 unsigned short r, g, b;
872 };
873
874 struct pagecolor {
875 struct rgb bg;
876 unsigned int stacksize;
877 struct rgb *colorstack;
878 };
879 struct pagecolor_info {
880 /* different from non-k xdvi, we also need the allocated stack size,
881 since it might differ from the number of pages (e.g. when loading
882 a new file). */
883 size_t size;
884 /* this is const in non-k xdvi, but some instances of it may ultimately
885 get free()d in full_reset_colors(), so it's not *really* const ...
886 */
887 struct pagecolor *stack;
888 };
889
890 /* Information on background color and initial color stack for each page. */
891 extern struct pagecolor_info page_colors;
892
893 /* The initial color stack is obtained from the pagecolor record for a page. */
894 extern struct rgb *color_bottom;
895 extern unsigned int color_bot_size; /* number of entries */
896
897 /* Additions to the runtime color stack on a given page are stored in a linked
898 list. "struct colorframe" is defined in special.c. */
899 extern struct colorframe *rcs_top;
900
901 /* Color states. */
902
903 /*
904 * For each (foreground, background) color pair, we keep information (depending
905 * on the color model). It is organized as a linked list of linked lists,
906 * with background color more significant.
907 */
908
909 struct bgrec {
910 struct bgrec *next;
911 struct rgb color;
912 struct fgrec *fg_head;
913 Boolean pixel_good; /* if the pixel entry is valid */
914 Pixel pixel;
915 };
916
917 struct fgrec {
918 struct fgrec *next;
919 struct rgb color;
920 Boolean pixel_good; /* if the pixel entry is valid */
921 Pixel pixel;
922 # if GREY
923 Boolean palette_good; /* if the palette entry is valid */
924 Pixel palette[16]; /* non-TrueColor only */
925 # endif
926 };
927
928 extern struct rgb fg_initial; /* Initial fg (from command line) */
929 extern struct rgb bg_initial; /* Initial bg */
930 extern struct bgrec *bg_head; /* head of list */
931 extern struct bgrec *bg_current; /* current bg value */
932 extern struct fgrec *fg_current; /* current fg value */
933 extern struct fgrec *fg_active; /* where the GCs are */
934
935 /* List of allocated colors (to be deallocated upon document change) */
936 extern Pixel *color_list; /* list of colors */
937 extern unsigned int color_list_len; /* current len of list */
938 extern unsigned int color_list_max; /* allocated size */
939
940 /* Whether the color situation has been warned about. */
941 extern Boolean color_warned;
942 #endif /* COLOR */
943
944
945 #if HAVE_XI21
946 struct xi2_valinfo {
947 int number;
948 double increment;
949 double lastval;
950 double lastexact;
951 double factor;
952 unsigned long serial;
953 };
954
955 struct xi2_slave {
956 int id; /* slave device id */
957 unsigned int flags;
958 unsigned char enabled;
959 unsigned char btn_mask; /* buttons corresponding to valuators */
960 struct xi2_valinfo vert, horiz;
961 struct xi2_slave *next;
962 };
963
964 /* flag bits */
965 # define XI2_SLAVE_VERT (1<<0) /* if vert. valuator present */
966 # define XI2_SLAVE_HORIZ (1<<1) /* if horiz. valuator present */
967
968 struct xi2_master {
969 int id; /* master device id */
970 struct xi2_slave *slave; /* currently active slave dev */
971 struct xi2_master *next;
972 };
973
974
975 extern int xi2_opcode;
976 extern Boolean xi2_active;
977 extern struct xi2_master *xi2_masters; /* linked list of master devs */
978 extern struct xi2_master *xi2_current; /* current master device */
979 extern struct xi2_slave *xi2_slaves; /* linked list of slave devs */
980
981 extern struct xi2_slave xi2_no_slave; /* if no slave assigned yet */
982
983 extern void xi2_init_valuators(struct xi2_slave *, XIAnyClassInfo **, int);
984 extern void xi2_activate(void);
985
986 #endif /* HAVE_XI21 */
987
988
989 extern Boolean dvi_file_corrupted;
990
991 extern short magnifier_stat; /* 1 = wait for expose, -1 = destroy upon expose */
992
993 extern void run_dvi_file(const char *filename, void *data);
994
995 /*
996 ================================================================================
997 globals from dvi-draw.c
998 ================================================================================
999 */
1000
1001 /*
1002 * The following is set when we're prescanning before opening up the windows,
1003 * and we hit a PostScript header file. We can't start up gs until we get
1004 * a window to associate the process to, so we have to prescan twice.
1005 */
1006 #if PS_GS
1007 extern Boolean gs_postpone_prescan;
1008 #endif
1009
1010 #if PS
1011 extern int scanned_page_ps; /* last page scanned for PS specials */
1012 extern int scanned_page_ps_bak; /* save the above if PS is turned off */
1013 #endif
1014
1015 #if COLOR
1016 extern int scanned_page_color; /* last page scanned for color spcls */
1017 #endif /* COLOR */
1018
1019 extern int scanned_page; /* last page prescanned */
1020 extern int scanned_page_reset; /* number to reset the above to */
1021 extern ubyte *G_dvi_buf_ptr;
1022 extern struct drawinf currinf;
1023 extern Boolean drawing_mag;
1024 extern Boolean htex_inside_href;
1025
1026 /* globals from hypertex.h */
1027 /* current anchor to search for, either from command-line or from clicking mouse */
1028 extern char *g_anchor_pos;
1029 extern size_t g_anchor_len;
1030
1031 extern char *g_link_color_rgb;
1032 extern char *g_visited_link_color_rgb;
1033
1034 /* globals from special.h */
1035 /*
1036 * If we're in the middle of a PSFIG special.
1037 */
1038 extern Boolean psfig_begun;
1039 /*
1040 * Set if the -paper option overrides papersize specials.
1041 */
1042 extern Boolean ignore_papersize_specials;
1043 extern Boolean have_raw_postscript;
1044 #if PS
1045 extern struct psprocs psp, no_ps_procs;
1046 #endif
1047
1048 #ifdef MAGICK
1049 /* TODO: put access functions for these in special.c */
1050 extern int bbox_angle;
1051 extern Boolean bbox_valid;
1052 extern unsigned int bbox_width;
1053 extern unsigned int bbox_height;
1054 extern int bbox_voffset;
1055 #endif
1056
1057 /* globals from statusline.h */
1058 extern Widget statusline;
1059
1060
1061 /*
1062 * The cursor shape in the magnifying glass is determined by which
1063 * window received the button press event. Under Motif, it's mane.win,
1064 * under XAW, it's the parent of mane.win.
1065 */
1066 #ifdef MOTIF
1067 # define CURSORWIN mane.win
1068 #else
1069 /* # define CURSORWIN XtWindow(globals.widgets.form_widget) */
1070 # define CURSORWIN mane.win
1071 #endif
1072
1073
1074 /*
1075 * This was MOTIF_TIMERS in the non-k xdvi version, but since xdvik
1076 * also uses XtAppAddTimeOut() for Xaw, we always need to define it.
1077 * See the comment in events.c for further explanations.
1078 */
1079 #if LD_ALLOWS_MULTIPLE_DEFINITIONS
1080 # define XDVI_XT_TIMER_HACK 1
1081 #else
1082 # define XDVI_XT_TIMER_HACK 0
1083 #endif
1084
1085 extern const char **get_paper_types(void);
1086 extern size_t get_paper_types_size(void);
1087
1088 extern void register_font_popup(void);
1089 extern void unregister_font_popup(void);
1090
1091 struct startup_info {
1092 int file_idx;
1093 char *page_arg;
1094 };
1095
1096 #ifdef STATUSLINE
1097 /* this is only for the initialization; the statusline will reset it to a more adequate value: */
1098 # define XTRA_H 17
1099 #endif
1100
1101 /*
1102 * Generic structure for DVI scans; contains a buffer for longjmp()ing
1103 * out of the scanning process if it's interrupted by the user (ugh ...)
1104 * and a generic `void *' to scan-specific info.
1105 */
1106 struct scan_info {
1107 jmp_buf done_env;
1108 void (*geom_special)(struct scan_info *info, const char *str, int str_len);
1109 void *data;
1110 };
1111
1112 /*
1113 * Used by the geometry-scanning routines.
1114 * It passes pointers to routines to be called at certain
1115 * points in the dvi file, and other information.
1116 */
1117 struct geom_info {
1118 void (*geom_box)(struct scan_info *, long, long, long, long);
1119 void *geom_data;
1120 };
1121
1122 #define get_byte(fp) ((unsigned char)getc(fp))
1123 #define get_lbyte(fp) ((long)get_byte(fp))
1124
1125 extern void get_icon_and_title(const char *filename, char **icon_name, char **title_name);
1126 extern void set_icon_and_title(const char *icon_name, const char *title_name);
1127 extern void reconfigure_window(Boolean fullsize, Dimension w, Dimension h,
1128 Boolean save_position);
1129 extern void set_windowsize(Dimension *ret_w, Dimension *ret_h, int add_w, int add_h, Boolean override);
1130
1131 #ifdef MOTIF
1132 extern void motif_translations_hack(void);
1133 #endif
1134
1135 #ifndef MAX
1136 # define MAX(i, j) ((i) > (j) ? (i) : (j))
1137 #endif
1138
1139 #ifndef MIN
1140 # define MIN(i, j) ((i) < (j) ? (i) : (j))
1141 #endif
1142
1143 #ifndef ABS
1144 # define ABS(x) (((x) < 0) ? (-(x)) : (x))
1145 #endif
1146
1147 #define REPORT_XDVI_BUG_TEMPLATE "Please report this as a bug to:\n\
1148 http://sourceforge.net/tracker/?group_id=23164&atid=377580\n"
1149
1150 #if HAVE_ICONV && HAVE_ICONV_H
1151 # undef HAVE_ICONV_H
1152 # define HAVE_ICONV_H 1
1153 #else
1154 # undef HAVE_ICONV_H
1155 # define HAVE_ICONV_H 0
1156 #endif
1157
1158
1159 #if HAVE_GOOD_SETSID_VFORK
1160 # if HAVE_VFORK_H
1161 # include <vfork.h>
1162 # endif
1163 #else /* HAVE_GOOD_SETSID_VFORK */
1164 /* Mac OS X 10.3 (Panther) (11/2003) doesn't allow setsid() within vfork() */
1165 # undef vfork
1166 # define vfork fork
1167 #endif /* HAVE_GOOD_SETSID_VFORK */
1168
1169
1170 /* XawtextScrollWhenNeeded has been ditched in Xaw7
1171 (e.g. Xfree >= 4.x); from the man page:
1172
1173 The value XawtextScrollWhenNeeded (and whenNeeded, recognized by
1174 the converter), is accepted for backwards compatibilty with
1175 resource specifications written for the Xaw6 Text widget, but
1176 ignored (effectively treated as XawtextScrollNever).
1177
1178 So we're forced to use `scrollAlways' here.
1179 */
1180 #define XAW_SCROLL_ALWAYS XawtextScrollAlways
1181
1182 /* the reconfig stuff has been fixed in XFree 4.1.0, vendor release 6510 (Slackware 8.0) */
1183 #define BROKEN_RECONFIG (( \
1184 (strstr(ServerVendor(DISP), "XFree") != NULL) \
1185 && VendorRelease(DISP) >= 4000 \
1186 && VendorRelease(DISP) < 4002 \
1187 ))
1188
1189 /* enable the following if you're getting unresolved messages about `iconv_open' etc.: */
1190 #if 0
1191 #define LIBICONV_PLUG
1192 #define iconv_open libiconv_open
1193 #define iconv_close libiconv_close
1194 #define iconv libiconv
1195 #endif /* 0 */
1196
1197 #if HAVE_ICONV_H
1198 typedef ICONV_CHAR_PPTR_TYPE iconv_char_pptrT;
1199 #endif /* HAVE_ICONV_H */
1200
1201 #define DEVEL_MODE 0
1202
1203 #endif /* XDVI_H_ */