Back to index

tetex-bin  3.0
xdvi.h
Go to the documentation of this file.
00001 /*========================================================================*\
00002 
00003 Copyright (c) 1990-2004  Paul Vojta
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to
00007 deal in the Software without restriction, including without limitation the
00008 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00009 sell copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00016 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE
00019 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00020 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00021 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 NOTE:
00024 xdvi is based on prior work, as noted in the modification history
00025 in xdvi.c.
00026 
00027 \*========================================================================*/
00028 
00029 /*
00030  *     Original version by Eric C. Cooper, CMU
00031  */
00032 
00033 #ifndef       XDVI_H_
00034 #define       XDVI_H_
00035 
00036 #include "xdvi-config.h"
00037 
00038 /* headers used by all modules */
00039 #include "xdvi-debug.h"
00040 #include "c-auto.h"
00041 
00042 #include "kpathsea/c-auto.h" /* kpathsea definitions */
00043 #include "kpathsea/config.h"
00044 
00045 /********************************
00046  *     The C environment    *
00047  *******************************/
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <limits.h>
00052 
00053 /* in case stdlib.h doesn't define these ... */
00054 #ifndef EXIT_SUCCESS
00055 #define EXIT_SUCCESS 0
00056 #endif
00057 #ifndef EXIT_FAILURE
00058 #define EXIT_FAILURE 1
00059 #endif
00060 
00061 #ifdef HAVE_WORKING_NL_LANGINFO_CODESET
00062 # define USE_LANGINFO 1
00063 #else
00064 # define USE_LANGINFO 0
00065 #endif
00066 
00067 #if HAVE_SYS_WAIT_H
00068 # include <sys/wait.h>
00069 #endif
00070 #ifndef WIFEXITED
00071 # define WIFEXITED(status)  (((status) & 255) == 0)
00072 #endif
00073 #ifndef WEXITSTATUS
00074 # define WEXITSTATUS(status)       ((unsigned)(status) >> 8)
00075 #endif
00076 #ifndef WIFSIGNALED
00077 # ifndef WIFSTOPPED
00078 #  define WIFSTOPPED(status)       (((status) & 0xff) == 0x7f)
00079 # endif
00080 # define WIFSIGNALED(status)       (!WIFSTOPPED(status) && !WIFEXITED(status))
00081 #endif
00082 #ifndef WTERMSIG
00083 # define WTERMSIG(status)   ((status) & 0x7f)
00084 #endif
00085 
00086 /*
00087  * If this is set to 1, xdvi will explicitly clear the internal GS
00088  * buffer after every page that contained a PS special (figure etc.)
00089  * to avoid artifacts with later PS specials (overlapping lines etc.);
00090  * see also bug #633420. This workaround will slow down the drawing of
00091  * the next page considerably. Currently xdvi also sometimes dies with
00092  * `Internal error in beginheader_gs()'
00093  * when paging quickly through a file with this hack enabled.
00094  * Set to 0 to disable the hack.
00095  */
00096 #define GS_PIXMAP_CLEARING_HACK 1
00097 
00098 #ifdef __hpux
00099 /* On HP-UX 10.10 B and 20.10, compiling with _XOPEN_SOURCE + ..._EXTENDED
00100  * leads to poll() not realizing that a file descriptor is writable in psgs.c.
00101  */
00102 # define _HPUX_SOURCE       1
00103 #else
00104 # ifndef _XOPEN_SOURCE
00105 # define _XOPEN_SOURCE      600
00106 # endif
00107 # define _XOPEN_SOURCE_EXTENDED    1
00108 # define __EXTENSIONS__     1      /* needed to get struct timeval on SunOS 5.5 */
00109 # define _SVID_SOURCE       1      /* needed to get S_IFLNK in glibc */
00110 # define _BSD_SOURCE 1      /* needed to get F_SETOWN in glibc-2.1.3 */
00111 #endif
00112 
00113 /* Some O/S dependent kludges. */
00114 #ifdef _AIX
00115 # define _ALL_SOURCE 1
00116 #endif
00117 
00118 /* just a kludge, no real portability here ... */
00119 #define DIR_SEPARATOR '/'
00120 
00121 #if STDC_HEADERS
00122 # include <stddef.h>
00123 # include <stdlib.h>
00124 /* the following works around the wchar_t problem */
00125 # include <X11/X.h>
00126 # if HAVE_X11_XOSDEFS_H
00127 #  include <X11/Xosdefs.h>
00128 # endif
00129 # ifdef X_NOT_STDC_ENV
00130 #  undef X_NOT_STDC_ENV
00131 #  undef X_WCHAR
00132 #  include <X11/Xlib.h>
00133 #  define X_NOT_STDC_ENV
00134 # endif
00135 #endif /* STDC_HEADERS */
00136 
00137 /* For wchar_t et al., that the X files might want. */
00138 #include "kpathsea/systypes.h"
00139 #include "kpathsea/c-memstr.h"
00140 
00141 #ifdef HAVE_SYS_PARAM_H
00142 #include <sys/param.h> /* this should define MAXPATHLEN */
00143 #endif
00144 #include "kpathsea/c-pathmx.h" /* get fallback for PATH_MAX if all else fails */
00145 
00146 #include <X11/Xlib.h>       /* include Xfuncs.h, if available */
00147 #include <X11/Xutil.h>      /* needed for XDestroyImage */
00148 #include <X11/Xos.h>
00149 
00150 #include <X11/Xfuncs.h>
00151 #include <X11/Intrinsic.h>
00152 
00153 #ifndef MAXPATHLEN
00154 # ifdef PATH_MAX
00155 #  define MAXPATHLEN PATH_MAX
00156 # else
00157 #  define MAXPATHLEN 1024
00158 # endif
00159 #endif
00160 
00161 #if defined(CFG2RES) && !defined(SELFAUTO)
00162 # define SELFAUTO 1
00163 #endif
00164 
00165 #if defined(SELFAUTO) && !defined(DEFAULT_CONFIG_PATH)
00166 # define DEFAULT_CONFIG_PATH "$SELFAUTODIR:$SELFAUTOPARENT"
00167 #endif
00168 
00169 /* NOTE: we don't use CFGFILE */
00170 
00171 typedef       char          Bool3;        /* Yes/No/Maybe */
00172 
00173 #define       True   1
00174 #define       False  0
00175 #define       Maybe  2
00176 
00177 
00178 #ifdef DEBUG
00179 #include<asm/msr.h>
00180 extern unsigned long time_start, time_end;
00181 #endif
00182 
00183 #include <X11/Xmd.h> /* get WORD64 and LONG64 */
00184 
00185 #ifndef WORD64
00186 # ifdef LONG64
00187 typedef unsigned int xuint32;
00188 # else
00189 typedef unsigned long xuint32;
00190 # endif
00191 #endif
00192 
00193 /* for unused parameters */
00194 #ifndef UNUSED
00195 #define UNUSED(x) ((void)(x))
00196 #endif
00197 
00198 #include <string.h>
00199 
00200 #ifdef VMS
00201 #define       index  strchr
00202 #define       rindex strrchr
00203 #define       bzero(a, b)   (void) memset ((void *) (a), 0, (size_t) (b))
00204 #define bcopy(a, b, c)  (void) memmove ((void *) (b), (void *) (a), (size_t) (c))
00205 #endif
00206 
00207 #include <stdio.h>
00208 #include <setjmp.h>
00209 
00210 #if HAVE_UNISTD_H
00211 # include <unistd.h>
00212 #endif
00213 
00214 /* all of these are POSIX and should have been defined by unistd.h: */
00215 #ifndef STDIN_FILENO
00216 #define STDIN_FILENO 0
00217 #endif
00218 #ifndef STDOUT_FILENO
00219 #define STDOUT_FILENO 1
00220 #endif
00221 #ifndef STDERR_FILENO
00222 #define STDERR_FILENO 2
00223 #endif
00224 
00225 /* see C FAQ; additional +1 for '\0' */
00226 #define LENGTH_OF_INT ((sizeof(int) * CHAR_BIT + 2) / 3 + 1 + 1)
00227 #define LENGTH_OF_LONG ((sizeof(long) * CHAR_BIT + 2) / 3 + 1 + 1)
00228 #define LENGTH_OF_ULONG ((sizeof(unsigned long) * CHAR_BIT + 2) / 3 + 1 + 1)
00229 
00230 #include "kpathsea/c-dir.h" /* dirent.h, NAMLEN */
00231 
00232 extern KPSEDLL char *kpathsea_version_string;
00233 
00234 #ifndef       NeedFunctionPrototypes
00235 # if   __STDC__
00236 #  define   NeedFunctionPrototypes 1
00237 # else
00238 #  define   NeedFunctionPrototypes 0
00239 # endif
00240 #endif
00241 
00242 #ifndef       NeedWidePrototypes
00243 # define NeedWidePrototypes NeedFunctionPrototypes
00244 #endif
00245 
00246 #ifndef       NeedVarargsPrototypes
00247 # define NeedVarargsPrototypes     NeedFunctionPrototypes
00248 #endif
00249 
00250 #include "kpathsea/c-vararg.h"
00251 
00252 #ifndef       _XFUNCPROTOBEGIN
00253 # define _XFUNCPROTOBEGIN
00254 # define _XFUNCPROTOEND
00255 #endif
00256 
00257 
00258 /* If xmkmf is broken and there's a symlink from /usr/include/X11 to the right
00259  * place, then there will be no -I... argument on the cc command line for the
00260  * X include files.  Since gcc version 3 and higher sets __STDC__ to 0 when
00261  * including system header files on some platforms, we may end up with
00262  * NeedFunctionPrototypes set to 0 when it should be 1.  So, let's force the
00263  * issue.
00264  */
00265 #if __STDC__ && !defined(FUNCPROTO)
00266 /* FUNCPROTO is a bitmask specifying ANSI conformance (see Xfuncproto.h).
00267    The single bits specify varargs, const availability, prototypes etc.;
00268    we enable everything here. */
00269 # define FUNCPROTO (-1)
00270 #endif
00271 
00272 #ifndef       VOLATILE
00273 # if __STDC__ || (defined(__stdc__) && defined(__convex__))
00274 #  define VOLATILE   volatile
00275 # else
00276 #  define VOLATILE   /* as nothing */
00277 # endif
00278 #endif
00279 
00280 #ifndef       NORETURN
00281 # ifdef       __GNUC__
00282 #  ifndef __STRICT_ANSI__
00283 #   define    NORETURN      volatile
00284 #  else
00285 #   define    NORETURN      /* as nothing */
00286 #  endif
00287 # else
00288 #  define     NORETURN      /* as nothing */
00289 # endif
00290 #endif
00291 
00292 #ifndef       OPEN_MODE
00293 /*
00294  * SU, 2001/01/07: xdvi defines OPEN_MODE as "r" or as "r", "ctx=stm" (for VMS),
00295  * but we use the definition of FOPEN_R_MODE from kpathsea/c-fopen.h instead:
00296  */
00297 # define OPEN_MODE FOPEN_R_MODE
00298 #endif /* OPEN_MODE */
00299 
00300 #ifndef       VMS
00301 # define OPEN_MODE_ARGS     const char *
00302 #else
00303 # define OPEN_MODE_ARGS     const char *, const char *
00304 #endif
00305 
00306 #ifndef __LINE__
00307 # define __LINE__ 0
00308 #endif
00309 
00310 #ifndef __FILE__
00311 # define __FILE__ "?"
00312 #endif
00313 
00314 #define       MAXDIM 32767
00315 
00316 typedef       unsigned char ubyte;
00317 
00318 #if NeedWidePrototypes
00319 typedef       unsigned int  wide_ubyte;
00320 typedef       int           wide_bool;
00321 #else
00322 typedef       ubyte         wide_ubyte;
00323 typedef       Boolean              wide_bool;
00324 #endif
00325 
00326 #if defined(MAKEPK) && !defined(MKTEXPK)
00327 # define MKTEXPK 1
00328 #endif
00329 
00330 #define       spell_conv0(n, f)   ((long) (n * f))
00331 #define       spell_conv(n)     spell_conv0(n, dimconv)
00332 
00333 typedef BMTYPE bmTypeT;
00334 typedef unsigned BMTYPE bmUnitT;
00335 /* #define    BMUNIT            unsigned BMTYPE */
00336 #define       BMBITS            (8 * BMBYTES) /* number of bits in a bmTypeT */
00337 
00338 #define       ADD(a, b)     ((bmUnitT *) (((char *) a) + b))
00339 #define       SUB(a, b)     ((bmUnitT *) (((char *) a) - b))
00340 
00341 extern bmUnitT bit_masks[BMBITS + 1];
00342 
00343 /* for safely printing char *s that might be NULL */
00344 #define STRING_OR_NULL(x) ((x == NULL ? "<NULL>" : x))
00345 
00346 #define INSIDE_MANE_WIN ((currwin.win == mane.win))
00347 #define MAGNIFIER_ACTIVE ((magnifier.win != 0))
00348 
00349 #define       mane_base_x 0
00350 #define       mane_base_y 0
00351 
00352 
00353 struct frame {
00354     /* dvi_h and dvi_v is the horizontal and vertical baseline position;
00355        it is the responsability of the set_char procedure to update
00356        them. */
00357     struct framedata {
00358        long dvi_h, dvi_v, w, x, y, z;
00359        int pxl_v;
00360     } data;
00361     struct frame *next, *prev;
00362 };
00363 
00364 #ifdef TEXXET
00365 typedef void setcharRetvalT;
00366 #else
00367 typedef long setcharRetvalT;
00368 #endif
00369 
00370 typedef       setcharRetvalT (*set_char_proc) (
00371 #ifdef TEXXET
00372                                     wide_ubyte cmd,
00373 #endif
00374                                     wide_ubyte ch);
00375 
00376 #define ROUNDUP(x,y) (((x)+(y)-1)/(y))
00377 
00378 #ifndef       BDPI
00379 #define       BDPI   600
00380 #endif
00381 
00382 #if defined(GS_PATH) && !defined(PS_GS)
00383 # define PS_GS       1
00384 #endif
00385 
00386 #if defined(PS_DPS) || defined(PS_NEWS) || defined(PS_GS)
00387 # define PS   1
00388 #else
00389 # define PS   0
00390 #endif
00391 
00392 typedef enum {
00393     XPRT_SHOW_NONE = 0U,
00394     XPRT_SHOW_STATUSLINE = 1,
00395     XPRT_SHOW_SCROLLBARS = 2,
00396 #ifdef MOTIF
00397     XPRT_SHOW_PAGELIST = 4,
00398     XPRT_SHOW_TOOLBAR = 8,
00399     XPRT_SHOW_MENUBAR = 16,
00400     XPRT_SHOW_ALL = 31
00401 #else
00402     XPRT_SHOW_BUTTONS = 4,
00403     XPRT_SHOW_ALL = 7
00404 #endif
00405 } expertFlagT;
00406 
00407 typedef enum {
00408     MOUSE_MAGNIFIER_MODE,
00409     MOUSE_TEXT_MODE,
00410     MOUSE_RULER_MODE,
00411     MOUSE_MAX_MODE
00412 } mouseModeT;
00413 
00414 /* SUBPIXEL_NONE for no subpixel rendering, otherwise order of subpixels
00415    (from option/resource subPixels) */
00416 typedef enum { SUBPIXEL_NONE, SUBPIXEL_RGB, SUBPIXEL_BGR } subpixelOrderT;
00417 
00418 /*
00419  *     X resources.
00420  */
00421 extern struct x_resources {
00422     /* NOTE: we don't use CFGFILE */
00423     Boolean   no_init_file;
00424     Boolean   regression;
00425     const char *geometry;
00426     const char *windowsize;
00427     Boolean   remember_windowsize;
00428     int              app_defaults_fileversion;
00429     int              mouse_mode;
00430     Boolean   use_tex_pages;
00431     int              shrinkfactor;
00432     const char *main_translations;
00433     const char *wheel_translations;
00434     int              wheel_unit;
00435     int              density;
00436     Boolean     omega;
00437 #ifdef GREY
00438     float     gamma;
00439 /*     float      inverted_factor; */
00440 #endif
00441     int              pixels_per_inch;
00442     Boolean   delay_rulers;
00443     int              tick_length;
00444     char       *tick_units;
00445     const char *sidemargin;
00446     int              sidemargin_int;
00447     const char *topmargin;
00448     int              topmargin_int;
00449     const char *xoffset;
00450     int              xoffset_int;
00451     const char *yoffset;
00452     int              yoffset_int;
00453     Boolean   use_current_offset; /* only used internally */
00454     const char *paper;
00455     Boolean     paper_landscape; /* only used internally */
00456     const char *alt_font;
00457 #ifdef MKTEXPK
00458     Boolean   makepk;
00459 #endif
00460     const char *mfmode;
00461     const char *editor;
00462 #ifdef MOTIF
00463     char       *prefs_editor_list;
00464 #endif
00465     Boolean   t1lib;
00466     const char *src_pos;
00467     const char *find_string;
00468     const char *text_encoding;
00469     Boolean   src_fork;
00470     const char *sub_pixels;
00471     const char *file_history;
00472     int              file_history_size;
00473     Boolean   no_file_arg_use_history;
00474     subpixelOrderT subpixel_order;
00475     float     subpixel_energy[3];
00476     Boolean   unique;
00477     Boolean   list_fonts;
00478     Boolean   reverse;
00479     Boolean   warn_spec;
00480     Boolean   hush_chars;
00481     Boolean   hush_chk;
00482     Boolean   hush_stdout;
00483     Boolean   safer;
00484 #ifdef VMS
00485     const char *fore_color;
00486     const char *back_color;
00487 #endif
00488     Pixel     fore_Pixel;
00489     Pixel     back_Pixel;
00490     /*     Pixel     brdr_Pixel; */
00491     Pixel     hl_Pixel;
00492     Pixel     cr_Pixel;
00493     const char *icon_geometry;
00494     Boolean   keep_flag;
00495     Boolean   copy;
00496     Boolean   thorough;
00497     Boolean   pause;
00498     const char *pause_special;
00499     Boolean   fullscreen;
00500 #ifdef PS
00501     int              postscript;
00502     Boolean   allow_shell;
00503 # ifdef       PS_DPS
00504     Boolean   useDPS;
00505 # endif
00506 # ifdef       PS_NEWS
00507     Boolean   useNeWS;
00508 # endif
00509 # ifdef       PS_GS
00510     Boolean   useGS;
00511     Boolean   gs_safer;
00512     Boolean   gs_alpha;
00513     const char *gs_path;
00514     const char *gs_palette;
00515     int              gs_timeout;
00516 # endif
00517 # ifdef       MAGICK
00518     Boolean   useMAGICK;
00519     const char *magick_cache;
00520 # endif
00521 #endif /* PS */
00522     Boolean     prescan;
00523     Boolean     use_temp_fp;
00524     const char *debug_arg;
00525     const char *menu_translations;
00526     Boolean   expert;
00527     float     watch_file; /* check DVI file every so often, in seconds */
00528     int         expert_mode;
00529 #ifndef MOTIF
00530     Dimension btn_side_spacing;
00531     Dimension btn_top_spacing;
00532     Dimension btn_between_spacing;
00533     /* ignored, only for backwards compatibility */
00534     Dimension btn_between_extra;
00535     Dimension btn_border_width;
00536 #else /* MOTIF */
00537     const char *toolbar_translations;
00538 #endif /* MOTIF */
00539     Boolean   statusline;
00540 #ifdef MOTIF
00541     /* not a user-level resource; indicates a problem with the toolbar, in
00542        which case the toolbar is disabled. */
00543     Boolean   toolbar_unusable;
00544     const char *toolbar_pixmap_file;
00545     Boolean   toolbar_buttons_raised;
00546     Boolean   tooltips_in_statusline;
00547     int              tooltips_wait_period; /* used for communication with Tip.c */
00548     int              tooltips_wait_period_bak; /* uncustomized value */
00549     Boolean   show_tooltips;
00550 #endif
00551     Boolean   pagelist_highlight_current;
00552     Dimension pagelist_width;
00553     const char *mg_arg[5];
00554 #if COLOR
00555     Boolean     use_color;
00556 #endif
00557 #ifdef GREY
00558     Boolean   use_grey;
00559     Bool3     install;
00560 #endif
00561     Boolean   match_highlight_inverted;
00562     const char *dvips_path;
00563     const char *ps2pdf_path;
00564     int              dvips_hang;
00565     int              dvips_fail_hang;
00566     const char *dvips_printer_str;
00567     const char *dvips_options_str;
00568     int              default_saving_format;
00569     int              default_printing_target;
00570     char       *rule_color;
00571     Pixel     rule_pixel;
00572     int              link_style;
00573     char       *link_color;
00574     char       *visited_link_color;
00575     char       *browser;
00576 #ifdef MOTIF
00577     char       *prefs_browser_list;
00578 #endif
00579     char       *unknown_mime_suffix;
00580     char       *no_mime_suffix;
00581     char       *anchor_pos;
00582     /* bitmask of current search window settings */
00583     unsigned int    search_window_defaults;
00584     /*     char *    _scroll_pages; */
00585     char       *help_general;
00586     char       *help_hypertex;
00587     char       *help_othercommands;
00588     char       *help_pagemotion;
00589     char       *help_marking;
00590     char       *help_modes;
00591     char       *help_search;
00592     char       *help_mousebuttons;
00593     char       *help_sourcespecials;
00594     int         page_history_size;
00595 } resource;
00596 
00597 extern void reload_app_resources(void);
00598 
00599 
00600 struct WindowRec {
00601     Window win;
00602     int       shrinkfactor;
00603     int       base_x;
00604     int       base_y;
00605     unsigned int width;
00606     unsigned int height;
00607     /* for pending expose events */
00608     int       min_x;
00609     int max_x;
00610     int min_y;
00611     int max_y;
00612 };
00613 
00614 struct event_info {
00615     int flags;
00616     VOLATILE int ctr;
00617     jmp_buf canit;
00618     jmp_buf next;    /* to skip next event */
00619 };
00620 
00621 struct pause_info {
00622     int num;
00623     int *num_save;
00624     Boolean flag;
00625 };
00626 
00627 struct gc_info {
00628     GC rule;
00629     GC fore;
00630     GC inverted;
00631     GC high;
00632     GC linkcolor;
00633     GC visited_linkcolor;
00634     GC fore2;
00635     GC fore2_bak;
00636     GC fore2_bak1;
00637     GC copy;
00638     GC ruler;
00639     Boolean do_copy;
00640 };
00641 
00642 /* values of cursor flags */
00643 #define CURSOR_LINK 1
00644 #define CURSOR_MAG 2
00645 /* flags for drag cursors */
00646 #define CURSOR_DRAG_V 4
00647 #define CURSOR_DRAG_H 8
00648 #define CURSOR_DRAG_A 16
00649 #define CURSOR_CORRUPTED 32 /* if file is corrupted */
00650 #define CURSOR_TEXT 64
00651 
00652 struct cursor_info {
00653     Cursor wait;
00654     Cursor ready;
00655     Cursor corrupted;
00656     Cursor link;
00657     Cursor rule;
00658     Cursor mag;
00659     /* horizontal/vertical/all directions drag */
00660     Cursor drag_h;
00661     Cursor drag_v;
00662     Cursor drag_a;
00663     /* support for `pause' feature */
00664     Cursor pause;
00665     /* text selection */
00666     Cursor text;
00667     
00668     /* one of the flags defined above */
00669     unsigned long flags;
00670 };
00671 
00672 struct window_expose_info {
00673     int min_x, max_x, min_y, max_y;
00674 };
00675 
00676 /* for communication with forward search in dvi-draw.c */
00677 struct src_info {
00678     int fwd_box_page;
00679     const char *fwd_string;
00680 };
00681 
00682 struct widget_info {
00683     Widget top_level;
00684     Widget draw_widget, draw_background, clip_widget;
00685     Widget x_bar, y_bar;
00686 #ifdef MOTIF
00687     Widget main_window, main_row, tool_bar, top_row, menu_bar;
00688 #else
00689     Widget vport_widget, form_widget, paned;
00690 #endif
00691 };
00692 
00693 struct page_info {
00694     unsigned int w, h;
00695     unsigned int unshrunk_w, unshrunk_h;
00696 };
00697 
00698 struct dvi_file_info {
00699     char *dirname;
00700     size_t dirlen;
00701     FILE *bak_fp;
00702     time_t time;     /* last file modification time */
00703 };
00704 
00705 /* struct to hold global settings that can't go into the resources,
00706  * as a replacement for global variables:
00707  */
00708 extern struct program_globals {
00709     const char *program_name;      /* argv[0] without the directory part */
00710     const char *xdvi_dir;   /* directory where xdvi is running in (for childs who need to change back to it) */
00711     char *dvi_name;         /* dvi file name, fully expanded with REALPATH */
00712     Boolean load_init_file; /* whether to read/save ~/.xdvirc */
00713     char *orig_locale;             /* original locale we are running in */
00714     unsigned long debug;    /* debugging option */
00715 
00716     /* for older Motif versions or LessTif, which have broken
00717        handling of Act_motion() / Act_release() events */
00718     Boolean broken_motif_event_handling;
00719     
00720     /* offset from c-style (0 based) numbers to real pagenumbers;
00721        also contains the offset that user has set via Act_declare_page_number() */
00722     int pageno_correct;
00723 
00724     /* whether we warn about unrecognized specials. Copy of resource.warn_spec value,
00725        set to False in the drawing routine to reduce the amount of warnings given.
00726        Better maybe replace with hash lookup similar to fonts warnings? */
00727     Boolean warn_spec_now;
00728 
00729     /* used to save X resource values */
00730     char *curr_paper;
00731     char *curr_editor;
00732     char *curr_browser;
00733     float curr_gamma;
00734     Boolean curr_use_color;
00735 
00736     
00737     /* forward search info */
00738     struct src_info src;
00739     
00740     /* event information */
00741     struct event_info ev;
00742 
00743     /* support for `-pause' feature */
00744     struct pause_info pausing;
00745     
00746     /* window expose information */
00747     struct window_expose_info win_expose;
00748 
00749     struct gc_info gc;
00750     
00751     /* cursor information */
00752     struct cursor_info cursor;
00753 
00754     /* widget information */
00755     struct widget_info widgets;
00756 
00757     /* page size info */
00758     struct page_info page;
00759 
00760     /* DVI file and modification time info */
00761     struct dvi_file_info dvi_file;
00762     
00763 } globals;
00764 
00765 
00766 /* TODO: put these into globals as well */
00767 extern struct WindowRec mane;
00768 extern struct WindowRec currwin;
00769 extern struct WindowRec magnifier;
00770 
00771 #ifdef MOTIF
00772 #include <Xm/Xm.h>
00773 extern  XmStringCharSet G_charset;
00774 #endif
00775 
00776 extern XtAppContext app;
00777 extern char          *dvi_property;              /* for setting in window */
00778 extern size_t        dvi_property_length;
00779 extern XImage        *G_image;
00780 extern int G_backing_store;
00781 /* extern     int           home_x, home_y; */
00782 
00783 extern Display              *DISP;
00784 extern Screen        *SCRN;
00785 
00786 extern XtAccelerators       G_accels_cr;
00787 #ifdef GREY
00788 extern Visual        *G_visual;
00789 extern unsigned int  G_depth;
00790 extern Colormap      G_colormap;
00791 #else
00792 # define G_depth     (unsigned int) DefaultDepthOfScreen(SCRN)
00793 # define G_visual    DefaultVisualOfScreen(SCRN)
00794 # define G_colormap  DefaultColormapOfScreen(SCRN)
00795 #endif
00796 
00797 
00798 #define       TNTABLELEN    30     /* length of TeXnumber array (dvi file) */
00799 #define       VFTABLELEN    5      /* length of TeXnumber array (virtual fonts) */
00800 
00801 extern struct font *tn_table[TNTABLELEN];
00802 extern struct font *font_head;
00803 extern struct tn *tn_head;
00804 extern wide_ubyte maxchar;
00805 extern unsigned short current_timestamp;
00806 
00807 extern int current_page;
00808 extern int total_pages;
00809 
00810 extern unsigned long magnification;
00811 extern double dimconv;
00812 extern double tpic_conv;
00813 
00814 /* whether this file contains source specials, so that we need to
00815    update the `windows' property for forward search on expose events:
00816 */
00817 extern Boolean have_src_specials;
00818 
00819 extern Boolean dragcurs;    /* whether drag cursor is active; needed by hypertex.c */
00820 extern int drag_flags;      /* 1 = vert, 2 = horiz; also needed by hypertex.c */
00821 
00822 typedef void (*mouse_proc) (XEvent *);
00823 extern mouse_proc mouse_motion;
00824 extern mouse_proc mouse_release;
00825 
00826 #if GREY
00827 extern Pixel plane_masks[4];
00828 #endif
00829 
00830 #if GREY || COLOR
00831 extern XColor color_data[2];
00832 #endif
00833 
00834 #if COLOR
00835 struct rgb {
00836     unsigned short r, g, b;
00837 };
00838 
00839 struct pagecolor {
00840     struct rgb bg;
00841     unsigned int stacksize;
00842     struct rgb *colorstack;
00843 };
00844 struct pagecolor_info {
00845   /* different from non-k xdvi, we also need the allocated stack size,
00846      since it might differ from the number of pages (e.g. when loading
00847      a new file). */
00848     size_t size;
00849     /* this is const in non-k xdvi, but some instances of it may ultimately
00850        get free()d in full_reset_colors(), so it's not *really* const ...
00851     */
00852     struct pagecolor *stack;
00853 };
00854 
00855 /* Information on background color and initial color stack for each page.  */
00856 extern struct pagecolor_info page_colors;
00857 
00858 /* The initial color stack is obtained from the pagecolor record for a page.  */
00859 extern struct rgb *color_bottom;
00860 extern unsigned int color_bot_size;       /* number of entries */
00861 
00862 /* Additions to the runtime color stack on a given page are stored in a linked
00863    list.  "struct colorframe" is defined in special.c.  */
00864 extern struct colorframe *rcs_top;
00865 
00866 /* Color states.  */
00867 
00868 /*
00869  * For each (foreground, background) color pair, we keep information (depending
00870  * on the color model).  It is organized as a linked list of linked lists,
00871  * with background color more significant.
00872  */
00873 
00874 struct bgrec {
00875     struct bgrec *next;
00876     struct rgb color;
00877     struct fgrec *fg_head;
00878     Boolean pixel_good;     /* if the pixel entry is valid */
00879     Pixel pixel;
00880 };
00881 
00882 struct fgrec {
00883     struct fgrec *next;
00884     struct rgb color;
00885     Boolean pixel_good;            /* if the pixel entry is valid */
00886     Pixel pixel;
00887 #if GREY
00888     Boolean palette_good;   /* if the palette entry is valid */
00889     Pixel palette[16];             /* non-TrueColor only */
00890 #endif
00891 };
00892 
00893 extern struct rgb fg_initial;      /* Initial fg (from command line) */
00894 extern struct rgb bg_initial;      /* Initial bg */
00895 extern struct bgrec *bg_head;             /* head of list */
00896 extern struct bgrec *bg_current;   /* current bg value */
00897 extern struct fgrec *fg_current;   /* current fg value */
00898 extern struct fgrec *fg_active;           /* where the GCs are */
00899 
00900 /* List of allocated colors (to be deallocated upon document change) */
00901 extern Pixel *color_list;          /* list of colors */
00902 extern unsigned int color_list_len;       /* current len of list */
00903 extern unsigned int color_list_max;       /* allocated size */
00904 
00905 /* Whether the color situation has been warned about.  */
00906 extern Boolean color_warned;
00907 #endif /* COLOR */
00908 
00909 extern Boolean dvi_file_corrupted;
00910 
00911 extern short magnifier_stat;       /* 1 = wait for expose, -1 = destroy upon expose */
00912 
00913 /*
00914   ================================================================================
00915   globals from dvi-draw.c
00916   ================================================================================
00917 */
00918 
00919 /*
00920  * The following is set when we're prescanning before opening up the windows,
00921  * and we hit a PostScript header file.  We can't start up gs until we get
00922  * a window to associate the process to, so we have to prescan twice.
00923  */
00924 #if PS_GS
00925 extern Boolean gs_postpone_prescan;
00926 #endif
00927 
00928 #if PS
00929 extern int scanned_page_ps; /* last page scanned for PS specials */
00930 extern int scanned_page_ps_bak;    /* save the above if PS is turned off */
00931 #endif
00932 
00933 #if COLOR
00934 extern int scanned_page_color;     /* last page scanned for color spcls */
00935 #endif /* COLOR */
00936 
00937 extern int scanned_page; /* last page prescanned */
00938 extern int scanned_page_reset;     /* number to reset the above to */
00939 extern ubyte *G_dvi_buf_ptr;
00940 extern struct drawinf currinf;
00941 extern Boolean drawing_mag;
00942 extern Boolean htex_inside_href;
00943 
00944 /* globals from hypertex.h */
00945 /* current anchor to search for, either from command-line or from clicking mouse */
00946 extern char *g_anchor_pos;
00947 extern size_t g_anchor_len;
00948 
00949 extern char *g_link_color_rgb;
00950 extern char *g_visited_link_color_rgb;
00951 
00952 /* globals from special.h */
00953 /*
00954  * If we're in the middle of a PSFIG special.
00955  */
00956 extern Boolean psfig_begun;
00957 /*
00958  * Set if the -paper option overrides papersize specials.
00959  */
00960 extern Boolean ignore_papersize_specials;
00961 extern Boolean have_raw_postscript;
00962 #if PS
00963 extern struct psprocs psp, no_ps_procs;
00964 #ifdef PS_GS
00965 extern Boolean had_ps_specials;
00966 #endif
00967 #endif
00968 
00969 #ifdef MAGICK
00970 /* TODO: put access functions for these in special.c */
00971 extern int bbox_angle;
00972 extern Boolean bbox_valid;
00973 extern unsigned int bbox_width;
00974 extern unsigned int bbox_height;
00975 extern int bbox_voffset;
00976 #endif
00977 
00978 /* globals from statusline.h */
00979 extern int global_statusline_h; /* height of statusline, or 0 */
00980 extern Widget statusline;
00981 
00982 
00983 /*
00984  * The cursor shape in the magnifying glass is determined by which
00985  * window received the button press event.  Under Motif, it's mane.win,
00986  * under XAW, it's the parent of mane.win.
00987  */
00988 #ifdef MOTIF
00989 # define CURSORWIN   mane.win
00990 #else
00991 /* # define CURSORWIN       XtWindow(globals.widgets.form_widget) */
00992 # define CURSORWIN   mane.win
00993 #endif
00994 
00995 
00996 /*
00997  * This was MOTIF_TIMERS in the non-k xdvi version, but since xdvik
00998  * also uses XtAppAddTimeOut() for Xaw, we always need to define it.
00999  * See the comment in events.c for further explanations.
01000  */
01001 #if LD_ALLOWS_MULTIPLE_DEFINITIONS
01002 # define XDVI_XT_TIMER_HACK 1
01003 #else
01004 # define XDVI_XT_TIMER_HACK 0
01005 #endif
01006 
01007 /* globally used GUI stuff */
01008 #ifdef MOTIF
01009 #include <Xm/Xm.h>
01010 /* Note: non-k xdvi has MOTIF_TIMERS here, we use XDVI_XT_TIMER_HACK instead (see above) */
01011 
01012 # ifndef DDIST
01013 #  define DDIST 4
01014 # endif
01015 # ifndef DDIST_MAJOR
01016 #  define DDIST_MAJOR 10
01017 # endif
01018 # ifndef DDIST_MINOR
01019 #  define DDIST_MINOR 5
01020 # endif
01021 #endif
01022 
01023 extern const char **get_paper_types(void);
01024 extern size_t get_paper_types_size(void);
01025 
01026 extern size_t get_magglass_items(void);
01027 extern int get_magglass_width(int idx);
01028 extern int get_magglass_height(int idx);
01029 
01030 
01031 #ifdef STATUSLINE
01032 /* this is only for the initialization; the statusline will reset it to a more adequate value: */
01033 # define XTRA_H      17
01034 #endif
01035 
01036 /*
01037  * Generic structure for DVI scans; contains a buffer for longjmp()ing
01038  * out of the scanning process if it's interrupted by the user (ugh ...)
01039  * and a generic `void *' to scan-specific info.
01040  */
01041 struct scan_info {
01042     jmp_buf done_env;
01043     void (*geom_special)(struct scan_info *info, const char *str, int str_len);
01044     void *data;
01045 };
01046 
01047 /*
01048  * Used by the geometry-scanning routines.
01049  * It passes pointers to routines to be called at certain
01050  * points in the dvi file, and other information.
01051  */
01052 struct geom_info {
01053     void (*geom_box)(struct scan_info *, long, long, long, long);
01054     void *geom_data;
01055 };
01056 
01057 #ifdef CFG2RES
01058 struct cfg2res {
01059     const char *cfgname;    /* name in config file */
01060     const char *resname;    /* name of resource */
01061     Boolean numeric; /* if numeric */
01062 };
01063 #endif
01064 
01065 #define get_byte(fp) ((unsigned char)getc(fp))
01066 #define get_lbyte(fp)       ((long)get_byte(fp))
01067 
01068 extern void get_icon_and_title(const char *filename, char **icon_name, char **title_name);
01069 extern void set_icon_and_title(const char *icon_name, const char *title_name);
01070 extern void reconfigure_window(Boolean fullsize, Dimension w, Dimension h,
01071                             Boolean save_position);
01072 extern void set_windowsize(Dimension *ret_w, Dimension *ret_h, int add_w, int add_h, Boolean override);
01073 
01074 #ifdef MOTIF
01075 extern void motif_translations_hack(void);
01076 #endif
01077 
01078 #ifndef       MAX
01079 # define MAX(i, j)  ((i) > (j) ? (i) : (j))
01080 #endif
01081 
01082 #ifndef       MIN
01083 # define MIN(i, j)       ((i) < (j) ? (i) : (j))
01084 #endif
01085 
01086 #ifndef ABS
01087 # define ABS(x)  (((x) < 0) ? (-(x)) : (x))
01088 #endif
01089 
01090 #define REPORT_XDVI_BUG_TEMPLATE "Please report this as a bug to:\n\
01091    http://sourceforge.net/tracker/?group_id=23164&atid=377580\n"
01092 
01093 #if HAVE_ICONV && HAVE_ICONV_H
01094 #undef HAVE_ICONV_H
01095 #define HAVE_ICONV_H 1
01096 #else
01097 #undef HAVE_ICONV_H
01098 #define HAVE_ICONV_H 0
01099 #endif
01100 
01101 
01102 #if HAVE_GOOD_SETSID_VFORK
01103 # if HAVE_VFORK_H
01104 #  include <vfork.h>
01105 # endif
01106 #else /* HAVE_GOOD_SETSID_VFORK */
01107 /* Mac OS X 10.3 (Panther) (11/2003) doesn't allow setsid() within vfork() */
01108 # undef vfork
01109 # define vfork fork
01110 #endif /* HAVE_GOOD_SETSID_VFORK */
01111 
01112 /* enable following if you get unresolved messages about `iconv_open' etc.: */
01113 #if 0
01114 #define LIBICONV_PLUG
01115 #define iconv_open libiconv_open
01116 #define iconv_close libiconv_close
01117 #define iconv libiconv
01118 #endif /* 0 */
01119 
01120 typedef ICONV_CHAR_PPTR_TYPE iconv_char_pptrT;
01121 
01122 #define DEVEL_MODE 0
01123 
01124 #endif /* XDVI_H_ */