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