Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
PAUL VOJTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NOTE:
xdvi is based on prior work, as noted in the modification history
in xdvi.c.
\*========================================================================*/
/* helbig changed this file to make it work on Mac OS X */
/* it defined XOPEN_SOURCE, which causes NSIG to be not defined,
which breaks signal.h included by event.c */
/*
* Written by Eric C. Cooper, CMU
*/
#ifndef XDVI_H
#define XDVI_H
/********************************
* The C environment *
*******************************/
#ifdef __hpux
/* On HP-UX 10.10 B and 20.10, compiling with _XOPEN_SOURCE + ..._EXTENDED
* leads to poll() not realizing that a file descriptor is writable in psgs.c.
*/
#define _HPUX_SOURCE 1
#else
#undef _XOPEN_SOURCE /* needed because of imake */
#define _XOPEN_SOURCE_EXTENDED 1
#define __EXTENSIONS__ 1 /* needed to get struct timeval on SunOS 5.5 */
#define _SVID_SOURCE 1 /* needed to get S_IFLNK in glibc */
#define _BSD_SOURCE 1 /* needed to get F_SETOWN in glibc-2.1.3 */
#endif
/* If xmkmf is broken and there's a symlink from /usr/include/X11 to the right
* place, then there will be no -I... argument on the cc command line for the
* X include files. Since gcc version 3 and higher sets __STDC__ to 0 when
* including system header files on some platforms, we may end up with
* NeedFunctionPrototypes set to 0 when it should be 1. So, let's force the
* issue.
*/
#if STDC_HEADERS
# include <stddef.h>
# include <stdlib.h>
/* the following works around the wchar_t problem */
# include <X11/X.h>
# if HAVE_X11_XOSDEFS_H
# include <X11/Xosdefs.h>
# endif
# ifdef X_NOT_STDC_ENV
# undef X_NOT_STDC_ENV
# undef X_WCHAR
# include <X11/Xlib.h>
# define X_NOT_STDC_ENV
# endif
#endif
#include <X11/Xlib.h> /* include Xfuncs.h, if available */
#include <X11/Xutil.h> /* needed for XDestroyImage */
#include <X11/Xos.h>
#if NeedFunctionPrototypes
#define ARGS(x) x
#else
#define ARGS(x) ()
#endif
#ifndef KPATHSEA
/* These macros munge function declarations to make them work in both
cases. The P?H macros are used for declarations, the P?C for
definitions. See <ansidecl.h> from the GNU C library. P1H(void)
also works for definitions of routines which take no args. */
#if NeedFunctionPrototypes /* Don't use __STDC__ here (gcc + SunOS 4) */
/*
* pixel_conv is currently used only for converting absolute positions
* to pixel values; although normally it should be
* ((int) ((x) / shrink_factor + (1 << 15) >> 16)),
* the rounding is achieved instead by moving the constant 1 << 15 to
* PAGE_OFFSET in dvi-draw.c.
*/
#define pixel_conv(x) ((int) ((x) / shrink_factor >> 16))
#define pixel_round(x) ((int) ROUNDUP(x, shrink_factor << 16))
#define spell_conv0(n, f) ((long) (n * f))
#define spell_conv(n) spell_conv0(n, dimconv)
struct drawinf { /* this information is saved when using virtual fonts */
struct framedata data;
struct font *fontp;
set_char_proc set_char_p;
int tn_table_len;
struct font **tn_table;
struct tn *tn_head;
ubyte *pos, *end;
struct font *virtual;
#ifdef TEXXET
int dir;
#endif
};
EXTERN struct drawinf currinf;
/* entries below with the characters 'dvi' in them are actually stored in
scaled pixel units */
EXTERN int current_page;
EXTERN int total_pages;
EXTERN int pageno_correct INIT(1);
EXTERN long magnification;
EXTERN double dimconv;
EXTERN double tpic_conv;
EXTERN int n_files_left INIT(32767); /* for LRU closing of fonts */
EXTERN unsigned int page_w, page_h;
EXTERN int scanned_page; /* last page prescanned */
#if PS
EXTERN int scanned_page_ps; /* last page scanned for PS specials */
EXTERN int scanned_page_ps_bak; /* save the above if PS is turned off */
#endif
#if COLOR
EXTERN int scanned_page_color; /* last page scanned for color spcls */
#endif
EXTERN int scanned_page_reset; /* number to reset the above to */
/*
* The following is set when we're prescanning before opening up the windows,
* and we hit a PostScript header file. We can't start up gs until we get
* a window to associate the process to, so we have to prescan twice.
*/
#if PS_GS
EXTERN Boolean gs_postpone_prescan INIT(False);
#endif
/*
* Per-page data in DVI file, indexed by page number - 1.
* Offset is initialized in prepare_pages().
* Page size is initialized while prescanning.
*/
struct per_page {
long offset;
unsigned int pw, ph; /* page size */
unsigned int ww, wh; /* window size */
};
EXTERN struct per_page *page_info;
/*
* Set if the -paper option overrides papersize specials.
*/
EXTERN Boolean ignore_papersize_specials INIT(False);
/*
* Mechanism for reducing repeated warning about specials, lost characters, etc.
*/
EXTERN Boolean warn_spec_now;
/*
* If we're in the middle of a PSFIG special.
*/
EXTERN Boolean psfig_begun INIT(False);
/*
* Page on which to draw box from forward source special searching.
*/
EXTERN int source_fwd_box_page INIT(-1); /* -1 means no box */
/*
* Information on deferred source operation. See do_pages() for meaning.
*/
EXTERN _Xconst char *source_forward_string INIT(NULL);
EXTERN int source_reverse_x, source_reverse_y;
EXTERN int source_show_all;
/*
* Bitmap structure for raster ops.
*/
struct bitmap {
unsigned short w, h; /* width and height in pixels */
short bytes_wide; /* scan-line width in bytes */
char *bits; /* pointer to the bits */
};
/*
* Per-character information.
* There is one of these for each character in a font (raster fonts only).
* All fields are filled in at font definition time,
* except for the bitmap, which is "faulted in"
* when the character is first referenced.
*/
struct glyph {
long addr; /* address of bitmap in font file */
long dvi_adv; /* DVI units to move reference point */
short x, y; /* x and y offset in pixels */
struct bitmap bitmap; /* bitmap for character */
short x2, y2; /* x and y offset in pixels (shrunken bitmap) */
#if GREY
# if COLOR
struct fgrec *fg; /* fgrec for which these pixmaps are valid */
# endif
XImage *image2;
char *pixmap2;
char *pixmap2_t;
#endif /* GREY */
struct bitmap bitmap2; /* shrunken bitmap for character */
};
/*
* Per-character information for virtual fonts
*/
struct macro {
ubyte *pos; /* address of first byte of macro */
ubyte *end; /* address of last+1 byte */
long dvi_adv; /* DVI units to move reference point */
Boolean free_me; /* if free(pos) should be called when */
/* freeing space */
};
/*
* The layout of a font information block.
* There is one of these for every loaded font or magnification thereof.
* Duplicates are eliminated: this is necessary because of possible recursion
* in virtual fonts.
*
* Also note the strange units. The design size is in 1/2^20 point
* units (also called micro-points), and the individual character widths
* are in the TFM file in 1/2^20 ems units, i.e., relative to the design size.
*
* We then change the sizes to SPELL units (unshrunk pixel / 2^16).
*/
#define NOMAGSTP (-29999)
typedef void (*read_char_proc) ARGS((struct font *, wide_ubyte));
struct font {
struct font *next; /* link to next font info block */
char *fontname; /* name of font */
float fsize; /* size information (dots per inch) */
int magstepval; /* magstep number * two, or NOMAGSTP */
FILE *file; /* open font file or NULL */
char *filename; /* name of font file */
long checksum; /* checksum */
unsigned short timestamp; /* for LRU management of fonts */
ubyte flags; /* flags byte (see values below) */
ubyte maxchar; /* largest character code */
double dimconv; /* size conversion factor */
set_char_proc set_char_p; /* proc used to set char */
/* these fields are used by (loaded) raster fonts */
read_char_proc read_char; /* function to read bitmap */
struct glyph *glyph;
/* these fields are used by (loaded) virtual fonts */
struct font **vf_table; /* list of fonts used by this vf */
struct tn *vf_chain; /* ditto, if TeXnumber >= VFTABLELEN */
struct font *first_font; /* first font defined */
struct macro *macro;
/* I suppose the above could be put into a union, but we */
/* wouldn't save all that much space. */
};
#define FONT_IN_USE 1 /* used for housekeeping */
#define FONT_LOADED 2 /* if font file has been read */
#define FONT_VIRTUAL 4 /* if font is virtual */
struct tn {
struct tn *next; /* link to next TeXnumber info block */
int TeXnumber; /* font number (in DVI file) */
struct font *fontp; /* pointer to the rest of the info */
};
EXTERN struct font *tn_table[TNTABLELEN];
EXTERN struct font *font_head INIT(NULL);
EXTERN struct tn *tn_head INIT(NULL);
EXTERN ubyte maxchar;
EXTERN unsigned short current_timestamp INIT(0);
/*
* Command line flags.
*/
extern struct _resource {
#if TOOLKIT && CFGFILE
_Xconst char *progname;
#endif
#if TOOLKIT
int shrinkfactor;
_Xconst char *main_translations;
_Xconst char *wheel_translations;
int dvips_hang;
int dvips_fail_hang;
#endif
int wheel_unit;
int _density;
#ifdef GREY
float _gamma;
#endif
int _pixels_per_inch;
_Xconst char *sidemargin;
_Xconst char *topmargin;
_Xconst char *xoffset;
_Xconst char *yoffset;
_Xconst char *paper;
_Xconst char *_alt_font;
#ifdef MKTEXPK
Boolean makepk;
#endif
_Xconst char *mfmode;
_Xconst char *editor;
_Xconst char *src_pos;
Boolean src_fork;
Boolean _list_fonts;
Boolean reverse;
Boolean _warn_spec;
Boolean _hush_chars;
Boolean _hush_chk;
Boolean safer;
#if defined(VMS) || !defined(TOOLKIT)
_Xconst char *fore_color;
_Xconst char *back_color;
#endif
Pixel _fore_Pixel;
Pixel _back_Pixel;
#ifdef TOOLKIT
Pixel _brdr_Pixel;
Pixel _hl_Pixel;
Pixel _cr_Pixel;
#endif
_Xconst char *icon_geometry;
Boolean keep_flag;
Boolean copy;
Boolean thorough;
#if PS
/* default is to use DPS, then NEWS, then GhostScript;
* we will figure out later on which one we will use */
Boolean _postscript;
Boolean allow_shell;
#ifdef PS_DPS
Boolean useDPS;
#endif
#ifdef PS_NEWS
Boolean useNeWS;
#endif
#ifdef PS_GS
Boolean useGS;
Boolean gs_safer;
Boolean gs_alpha;
_Xconst char *gs_path;
_Xconst char *gs_palette;
#endif
#endif /* PS */
Boolean prescan;
_Xconst char *debug_arg;
Boolean version_flag;
#if BUTTONS
Boolean expert;
_Xconst char *button_translations;
int shrinkbutton[9];
Dimension btn_side_spacing;
Dimension btn_top_spacing;
Dimension btn_between_spacing;
Dimension btn_between_extra;
Dimension btn_border_width;
#endif
_Xconst char *mg_arg[5];
#if COLOR
Boolean _use_color;
#endif
#ifdef GREY
Boolean _use_grey;
Bool3 install;
#endif
#if TOOLKIT
_Xconst char *dvips_path;
#endif
} resource;
/* As a convenience, we define the field names without leading underscores
* to point to the field of the above record. Here are the global ones;
* the local ones are defined in each module. */
/* Information on background color and initial color stack for each page. */
EXTERN struct pagecolor *page_colors INIT(NULL);
/* The initial color stack is gotten from the pagecolor record for a page. */
EXTERN _Xconst struct rgb *color_bottom;
EXTERN unsigned int color_bot_size; /* number of entries */
/* Additions to the runtime color stack on a given page are stored in a linked
list. "struct colorframe" is defined in special.c. */
EXTERN struct colorframe *rcs_top;
/*
* For each (foreground, background) color pair, we keep information (depending
* on the color model). It is organized as a linked list of linked lists,
* with background color more significant.
*/
struct bgrec {
struct bgrec *next;
struct rgb color;
struct fgrec *fg_head;
Boolean pixel_good; /* if the pixel entry is valid */
Pixel pixel;
};
struct fgrec {
struct fgrec *next;
struct rgb color;
Boolean pixel_good; /* if the pixel entry is valid */
Pixel pixel;
#if GREY
Boolean palette_good; /* if the palette entry is valid */
Pixel palette[16]; /* non-TrueColor only */
#endif
};
EXTERN struct bgrec *bg_head INIT(NULL); /* head of list */
EXTERN struct bgrec *bg_current INIT(NULL); /* current bg value */
EXTERN struct fgrec *fg_current; /* current fg value */
EXTERN struct fgrec *fg_active INIT(NULL); /* where the GCs are */
/* List of allocated colors (to be deallocated upon document change) */
EXTERN Pixel *color_list; /* list of colors */
EXTERN unsigned int color_list_len INIT(0); /* current len of list*/
EXTERN unsigned int color_list_max INIT(0); /* allocated size */
/* Whether the color situation has been warned about. */
EXTERN Boolean color_warned INIT(False);
/* Cursor color (for XRecolorCursor). */
extern XColor cr_Color;
#endif /* COLOR */
extern struct mg_size_rec {
int w;
int h;
}
mg_size[5];
EXTERN unsigned int ev_flags INIT(EV_IDLE);
EXTERN VOLATILE int event_counter INIT(0);
EXTERN jmp_buf canit_env;
struct xchild {
struct xchild *next; /* link to next in list */
pid_t pid; /* pid of process, or 0 */
Boolean killable; /* if can be killed with SIGKILL */
void (*proc) ARGS((int)); /* procedure to call */
};
struct xio {
struct xio *next; /* link to next in list */
int fd; /* file descriptor */
int xio_events; /* same as in struct pollfd (can't call
it events because poll.h on AIX
defines events to something else) */
#if HAVE_POLL
struct pollfd *pfd;
#endif
void (*read_proc) ARGS((void)); /* call to read */
void (*write_proc) ARGS((void)); /* call to write */
};
struct xtimer {
struct xtimer *next; /* link to next in chain */
struct timeval when; /* when to call the routine */
void (*proc) ARGS((struct xtimer *)); /* procedure to call */
#if MOTIF_TIMERS
XtTimerCallbackProc xt_proc; /* additional data for Xm */
XtPointer closure;
#endif
};
/*
* If a popup is popped up before the main window, then the main window is
* likely to cover it. So we have to postpone popping them up until after
* realizing the main window. It is not workable to pop them up immediately
* and then raise them later, due to unpredictable window manager behavior.
*/
EXTERN char *ffline INIT(NULL); /* an array used by filefind to store */
/* the file name being formed. */
/* It expands as needed. */
/* Also used elsewhere. */
EXTERN size_t ffline_len INIT(0); /* current length of ffline[] */
/*
* Used by the geometry-scanning routines.
* It passes pointers to routines to be called at certain
* points in the dvi file, and other information.
*/