Back to index

tetex-bin  3.0
Classes | Defines | Typedefs | Enumerations | Functions
dvi-init.h File Reference
#include "xdvi-config.h"
#include "xdvi.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bitmap
struct  glyph
struct  macro
struct  font
struct  tn

Defines

#define NOMAGSTP   (-29999)
#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 */

Typedefs

typedef void(* read_char_proc )(struct font *, wide_ubyte)

Enumerations

enum  dviErrFlagT {
  NO_ERROR = 0, WRONG_DVI_VERSION, DVI_CORRUPTED, NOT_A_DVI_FILE,
  POSTAMBLE_NO_POST, POSTAMBLE_NO_MATCH, POSTAMBLE_NON_FNTDEF, NOT_ALL_PIXEL_FILES_FOUND,
  NO_BOP_AT_PAGEDESC, FILE_HAS_ZERO_SIZE, FILE_DOESNT_EXIST, FILE_IS_DIRECTORY,
  PS_CONVERSION_FAILED, PDF_CONVERSION_FAILED, UNKNOWN_ERROR
}

Functions

const char * get_dvi_error (dviErrFlagT flag)
Boolean internal_open_dvi (const char *path, dviErrFlagT *errmsg, Boolean load_fonts)
char * open_dvi_file_wrapper (const char *filename, Boolean from_command_line, Boolean open_new_instance, Boolean *tried_dvi_ext, Boolean from_file_history)
char * get_tmp_dvi_name (void)
void reset_fonts (void)
void realloc_font (struct font *, wide_ubyte)
void realloc_virtual_font (struct font *, wide_ubyte)
Boolean load_font (struct font *, Boolean use_t1lib)
struct fontdefine_font (Boolean load_font_now, FILE *, wide_ubyte, struct font *, struct font **, unsigned int, struct tn **, Boolean *not_found_flag)
void init_page (void)
void form_dvi_property (void)
 form_dvi_property forms the property used to exhibit the dvi file name used as a window property (used for source specials).
Boolean dvi_file_changed (void)
 Check for changes in dvi file.
void remove_tmp_dvi_file (void)
Boolean load_dvi_file (Boolean load_fonts, dviErrFlagT *errflag)
 Reload the dvi file (unconditionally).
void read_PK_index (struct font *, wide_bool)
void read_GF_index (struct font *, wide_bool)
unsigned long read_VF_index (struct font *, wide_bool)
Boolean set_paper_type (const char *arg)
Boolean find_postamble (FILE *fp, dviErrFlagT *errflag)
Boolean read_postamble (FILE *fp, dviErrFlagT *errflag, Boolean load_fonts)
void close_old_filep (void)
Boolean process_preamble (FILE *fp, dviErrFlagT *errflag)
FILEfile_exists (const char *path, dviErrFlagT *errflag)
char * find_dvi_file (const char *filename, Boolean *tried_dvi_ext, Boolean from_file_history)

Class Documentation

struct bitmap

Definition at line 63 of file dvi-init.h.

Class Members
char * bits
short bytes_wide
unsigned short h
unsigned short w
struct glyph

Definition at line 76 of file dvi-init.h.

Class Members
long addr
long dvi_adv
short x
short x2
short y
short y2
struct macro

Definition at line 97 of file dvi-init.h.

Class Members
long dvi_adv
ubyte * end
Boolean free_me
ubyte * pos
struct font

Definition at line 130 of file dvi-init.h.

Collaboration diagram for font:
Class Members
long checksum
double dimconv
FILE * file
char * filename
struct font * first_font
ubyte flags
char * fontname
float fsize
struct glyph * glyph
struct macro * macro
int magstepval
wide_ubyte maxchar
struct font * next
read_char_proc read_char
long scale
set_char_proc set_char_p
int t1id
unsigned short timestamp
struct tn * vf_chain
struct font ** vf_table
struct tn

Definition at line 156 of file dvi-init.h.

Collaboration diagram for tn:
Class Members
struct font * fontp
struct tn * next
unsigned long TeXnumber

Define Documentation

#define FONT_IN_USE   1 /* used for housekeeping */

Definition at line 120 of file dvi-init.h.

#define FONT_LOADED   2 /* if font file has been read */

Definition at line 121 of file dvi-init.h.

#define FONT_VIRTUAL   4 /* if font is virtual */

Definition at line 122 of file dvi-init.h.

#define NOMAGSTP   (-29999)

Definition at line 118 of file dvi-init.h.


Typedef Documentation

typedef void(* read_char_proc)(struct font *, wide_ubyte)

Definition at line 128 of file dvi-init.h.


Enumeration Type Documentation

Enumerator:
NO_ERROR 
WRONG_DVI_VERSION 
DVI_CORRUPTED 
NOT_A_DVI_FILE 
POSTAMBLE_NO_POST 
POSTAMBLE_NO_MATCH 
POSTAMBLE_NON_FNTDEF 
NOT_ALL_PIXEL_FILES_FOUND 
NO_BOP_AT_PAGEDESC 
FILE_HAS_ZERO_SIZE 
FILE_DOESNT_EXIST 
FILE_IS_DIRECTORY 
PS_CONVERSION_FAILED 
PDF_CONVERSION_FAILED 
UNKNOWN_ERROR 

Definition at line 30 of file dvi-init.h.


Function Documentation

Definition at line 1459 of file dvi-init.c.

{
    if (m_dvi_fp != NULL) {
       fclose(m_dvi_fp);
       m_dvi_fp = NULL;
       if (!resource.use_temp_fp)
           globals.dvi_file.bak_fp = NULL;
    }
}

Here is the caller graph for this function:

struct font* define_font ( Boolean  load_font_now,
FILE ,
wide_ubyte  ,
struct font ,
struct font **  ,
unsigned  int,
struct tn **  ,
Boolean not_found_flag 
) [read]

Definition at line 574 of file dvi-init.c.

{
    unsigned int TeXnumber;
    struct font *fontp;
    float fsize;
    double scale_dimconv;
    long checksum;
    int scale, orig_scale;
    int design;
    int magstepval;
    int len;
    char *fontname;
    int size;

    TeXnumber = get_bytes(file, (int)cmnd - FNTDEF1 + 1);
    checksum = get_bytes(file, 4);
    scale = orig_scale = get_bytes(file, 4);
    design = get_bytes(file, 4);
    len = get_byte(file);
    len += get_byte(file);  /* sequence point in the middle */

    if (!load_font_now)
       return NULL;
    
    fontname = xmalloc((unsigned)len + 1);
    fread(fontname, sizeof(char), len, file);
    fontname[len] = '\0';
    if (globals.debug & DBG_PK)
       printf("xdvi: Define font \"%s\" scale=%d design=%d number=%d\n",
              fontname, scale, design, TeXnumber);
    if (vfparent == NULL) {
       fsize = 0.001 * scale / design * magnification * resource.pixels_per_inch;
       scale_dimconv = dimconv;
    }
    else {
       /*
        * The scaled size is given in units of vfparent->scale * 2 ** -20
        *      SPELL units, so we convert it into SPELL units by multiplying by
        *              vfparent->dimconv.
        *      The design size is given in units of 2 ** -20 pt, so we convert
        *      into SPELL units by multiplying by
        *              (resource.pixels_per_inch * 2**16) / (72.27 * 2**20).
        */
       fsize = (72.27 * (1 << 4)) * vfparent->dimconv * scale / design;
       scale_dimconv = vfparent->dimconv;
       /* Inherit the scale from the virtual parent */
       scale = vfparent->scale * ((orig_scale * scale_dimconv / (1 << 20)) / vfparent->dimconv);
    }
    magstepval = magstepvalue(&fsize);
    size = fsize + 0.5;
    /*
     * reuse font if possible
     */
    for (fontp = font_head;; fontp = fontp->next) {
       if (fontp == NULL) { /* if font doesn't exist yet */
           if (resource.list_fonts)
              printf("xdvi: %s at %d dpi\n", fontname, (int)(fsize + 0.5));
           fontp = xmalloc((unsigned)sizeof(struct font));
           fontp->fontname = fontname;
           fontp->fsize = fsize;
           fontp->magstepval = magstepval;
           fontp->file = NULL;     /* needed if it's a virtual font */
           fontp->checksum = checksum;
           fontp->flags = FONT_IN_USE;
           fontp->dimconv =  orig_scale * scale_dimconv / (1 << 20);
           fontp->set_char_p = load_n_set_char;
           fontp->scale = scale;
           if (vfparent == NULL)
              if (!load_font(fontp, resource.t1lib)) {
                  if (globals.ev.flags & EV_GE_NEWDOC) {       /* if aborting */
                     free(fontname);
                     free(fontp);
                     return NULL;
                  }
                  *not_found_flag = True;
              }
           fontp->next = font_head;
           font_head = fontp;
           break;
       }
       if (strcmp(fontname, fontp->fontname) == 0
           && size == (int)(fontp->fsize + 0.5)) {
           /* if font already in use */
           reuse_font(fontp);
           free(fontname);
           break;
       }
    }
    if (TeXnumber < tn_table_len)
       tntable[TeXnumber] = fontp;
    else {
       struct tn *tnp;
       tnp = xmalloc((unsigned)sizeof(struct tn));
       tnp->next = *tn_headpp;
       *tn_headpp = tnp;
       tnp->TeXnumber = TeXnumber;
       tnp->fontp = fontp;
    }
    return fontp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Check for changes in dvi file.

Return True if file has changed, False else.

Definition at line 1477 of file dvi-init.c.

{
    TRACE_FILES((stderr, "dvi_file_changed: fp = %p?", (void *)m_dvi_fp));

/*     fprintf(stderr, "m_dvi_fp3: %p (%s)\n", m_dvi_fp, globals.dvi_name); */
    if (m_dvi_fp == NULL) {
       TRACE_FILES((stderr, "m_dvi_fp == NULL"));
       if (stat(globals.dvi_name, &fstatbuf) == 0 && fstatbuf.st_mtime != globals.dvi_file.time) {
           TRACE_FILES((stderr, "file changed"));
           if (resource.use_temp_fp) {
              dviErrFlagT errflag = NO_ERROR;

              if (resource.watch_file == 0.0)
                  statusline_print(STATUS_MEDIUM, "File changed ...");
              TRACE_FILES((stderr, "returning FALSE"));

              if (file_exists_p(globals.dvi_name, &errflag)
                  && process_preamble(m_dvi_fp, &errflag)
                  && find_postamble(m_dvi_fp, &errflag)
                  && read_postamble(m_dvi_fp, &errflag, False)) {
                  TRACE_FILES((stderr, "File OK, reloading ..."));
                  
                  globals.ev.flags |= EV_RELOAD;
                  return True;
              }
              else {
                  return False;
              }
           }
           /* Bug alert: Don't set EV_RELOAD again here, else xdvi
              can go into a stretch of time where it again and again
              tries to reload a file even if the user doesn't click
              on the canvas.
           */
           /*
           else {
              globals.ev.flags |= EV_RELOAD;
           }
           */
           TRACE_FILES((stderr, "returning TRUE"));
           return True;
       }
       else {
           TRACE_FILES((stderr, "file not changed"));
       }
    }
    /* BUG ALERT: Don't use fstat(fileno(m_dvi_fp) here; if file hase
       disappeared, this won't report an error! */
    else if (stat(globals.dvi_name, &fstatbuf) != 0 /* stat failed ... */
            || fstatbuf.st_mtime != globals.dvi_file.time /* ... or different timestamp, reload: */) {
       dviErrFlagT errflag = NO_ERROR;

       TRACE_FILES((stderr, "Stat failed, or different timestamp ..."));
       globals.dvi_file.time = 0; /* force reload next time also if stat failed */
       
       if (resource.use_temp_fp) { /* in this case, reload only if file has been written completely */
           if (resource.watch_file == 0.0) {
              statusline_print(STATUS_MEDIUM, "File corrupted (click on window to reload) ...");
              globals.cursor.flags |= CURSOR_CORRUPTED;
              globals.ev.flags |= EV_CURSOR;
           }
           else {
              statusline_print(STATUS_MEDIUM, "File corrupted (will try to reload) ...");
           }
           close_old_filep();
           if (file_exists_p(globals.dvi_name, &errflag)
              && process_preamble(m_dvi_fp, &errflag)
              && find_postamble(m_dvi_fp, &errflag)
              && read_postamble(m_dvi_fp, &errflag, False)) {
              TRACE_FILES((stderr, "File OK, reloading ..."));
              
              globals.ev.flags |= EV_RELOAD;
              return True;
           }
           else {
              TRACE_FILES((stderr, "NO successful load: %s", get_dvi_error(errflag)));
/*            fprintf(stderr, "=========== NO successful load: %s\n", get_dvi_error(errflag)); */
              return False;
           }
       }
       else {
           TRACE_FILES((stderr, "Not using temp fp, reloading..."));
           globals.ev.flags |= EV_RELOAD;
           return True;
       }
    }
    return False;
}

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* file_exists ( const char *  path,
dviErrFlagT errflag 
)
char* find_dvi_file ( const char *  filename,
Boolean tried_dvi_ext,
Boolean  from_file_history 
)

Definition at line 1268 of file dvi-init.c.

{
    char *new_filename;
    size_t len;
    dviErrFlagT errflag;

    ASSERT(filename != NULL, "Filename argument in find_dvi_file() musn't be NULL");
    len = strlen(filename);

    if (len < sizeof(".dvi") || strcmp(filename + len - sizeof(".dvi") + 1, ".dvi") != 0) {
       /* doesn't already have .dvi extension */
       TRACE_HTEX((stderr, "|%s| doesn't have .dvi extension, appending ...", filename));
       new_filename = xstrdup(filename);
       new_filename = xstrcat(new_filename, ".dvi");
       *tried_dvi_ext = True;
       
       if (file_exists_p(new_filename, &errflag)) { /* file exists */
           char *expanded_filename = expand_filename(new_filename, USE_CWD_PATH);
           free(new_filename);
           return expanded_filename;
       }
       else { /* don't report an error; will try verbatim filename next */
           free(new_filename);
       }
    }

    /* try verbatim filename (might be strange things like `foo.wdvi') */
    if (file_exists_p(filename, &errflag)) {
       char *expanded_filename = expand_filename(filename, USE_CWD_PATH);
       return expanded_filename;
    }
    else {
       if (*tried_dvi_ext) {
           if (!from_file_history) {
              XDVI_FATAL((stderr, "%s: %s, and %s.dvi doesn't exist either.",
                         filename, get_dvi_error(errflag), filename));
           }
           else {
              popup_message(globals.widgets.top_level,
                           MSG_ERR,
                           NULL,
                           "Could not open \"%s\": %s.\n", filename, get_dvi_error(errflag));
           }
       }
       else {
           if (!from_file_history) {
              XDVI_FATAL((stderr, "%s: %s.", filename, get_dvi_error(errflag)));
           }
           /* else: file is from history; this is at startup, where we may
              loop through the history until we find a usable file. Don't report
              an error in this case. */
       }
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean find_postamble ( FILE fp,
dviErrFlagT errflag 
)

Definition at line 728 of file dvi-init.c.

{
    long pos;
    ubyte temp[TMPSIZ];
    ubyte *p;
    ubyte *p1;
    ubyte byte;

    TRACE_FILES((stderr, "find_postamble on fp: %p", (void *)fp));
    
    fseek(fp, 0L, SEEK_END);
    pos = ftell(fp) - TMPSIZ;
    if (pos < 0)
       pos = 0;
    fseek(fp, pos, SEEK_SET);
    p = temp + fread((char *)temp, sizeof(char), TMPSIZ, fp);
    for (;;) {
       p1 = p;
       while (p1 > temp && *(--p1) != TRAILER);
       p = p1;
       while (p > temp && *(--p) == TRAILER);
       if (p <= p1 - 4)
           break;    /* found 4 TRAILER bytes */
       if (p <= temp) {
           *errflag = DVI_CORRUPTED;
           TRACE_FILES((stderr, "find_postamble: returning FALSE"));
           return False;
       }
    }
    pos += p - temp;
    byte = *p;
    while (byte == TRAILER) {
       fseek(fp, --pos, SEEK_SET);
       byte = get_byte(fp);
    }
    if (byte != 2) {
       *errflag = WRONG_DVI_VERSION;
       TRACE_FILES((stderr, "find_postamble: returning FALSE"));
       return False;
    }
    fseek(fp, pos - 4, SEEK_SET);
    fseek(fp, get_lbytes(fp, 4), SEEK_SET);
    TRACE_FILES((stderr, "find_postamble: returning TRUE"));
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

form_dvi_property forms the property used to exhibit the dvi file name used as a window property (used for source specials).

Definition at line 1434 of file dvi-init.c.

{
#if 0
    size_t len;
    unsigned long ino;
    int i;
#endif

    if (m_dvi_fp == NULL)
       return;

    if (dvi_property != NULL)
       free(dvi_property);

    dvi_property_length = strlen(globals.dvi_name) + 1; /* also copy the terminating 0 */
    dvi_property = xmalloc(dvi_property_length);

    /* NOTE: we don't use dvi_inode like non-k xdvi, since dvi_name is
       always fully expanded with xdvik. */
    strcpy(dvi_property, globals.dvi_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* get_dvi_error ( dviErrFlagT  flag)

Definition at line 131 of file dvi-init.c.

                                {
    ASSERT(flag < XtNumber(dvi_err_list), "Flag out of range");
    return dvi_err_list[flag];
}

Here is the caller graph for this function:

char* get_tmp_dvi_name ( void  )

Definition at line 966 of file dvi-init.c.

                         {
    return tmp_dvi_name;
}

Here is the caller graph for this function:

Definition at line 948 of file dvi-init.c.

{
    if (globals.dvi_file.bak_fp == NULL)
       return;
    globals.page.unshrunk_w = pageinfo_get_page_width(current_page);
    globals.page.unshrunk_h = pageinfo_get_page_height(current_page);
    globals.page.w = ROUNDUP(globals.page.unshrunk_w, mane.shrinkfactor) + 2;
    globals.page.h = ROUNDUP(globals.page.unshrunk_h, mane.shrinkfactor) + 2;
    TRACE_FILES((stderr, "init_page: setting globals.page.w = %d, globals.page.h = %d", globals.page.w, globals.page.h));
}

Here is the call graph for this function:

Boolean internal_open_dvi ( const char *  path,
dviErrFlagT errmsg,
Boolean  load_fonts 
)

Definition at line 1144 of file dvi-init.c.

{
/*     FILE *tmp_fp = NULL; */
/*     static FILE *bak_fp = NULL; /\* re-use the temporary backup fp *\/ */
/*      fprintf(stderr, "------------ opening: |%s|\n", path); */

    TRACE_FILES((stderr, "internal_open_dvi for |%s|", path));
    close_old_filep();

    if (!file_exists_p(path, errflag)) { /* this should set fstatbuf.st_mtime */
       return False;
    }

    if (!resource.use_temp_fp || (globals.dvi_file.bak_fp = make_backup_fp(m_dvi_fp, globals.dvi_file.bak_fp)) == NULL) {
       globals.dvi_file.bak_fp = m_dvi_fp;
    }
    globals.dvi_file.time = fstatbuf.st_mtime;
    
    if (!internal_init_dvi(errflag, load_fonts)) {
       return False;
    }
    
#if COLOR
    full_reset_colors();
#endif /* COLOR */
    reset_papersize_special();
    
    TRACE_FILES((stderr, "internal_open_dvi: SUCCESS!"));

    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean load_dvi_file ( Boolean  load_fonts,
dviErrFlagT errflag 
)

Reload the dvi file (unconditionally).

Return True on success, False else.

Definition at line 1571 of file dvi-init.c.

{
    unsigned int old_page_w, old_page_h;
    static ino_t dvi_inode = 0;

    TRACE_FILES((stderr, "load_dvi_file: going to read %p", (void *)m_dvi_fp));
    
    if (resource.use_temp_fp && m_dvi_fp != NULL) {
       /* in this case, reload only if file has been written completely */
       *errflag = NO_ERROR;
       fseek(m_dvi_fp, 0L, SEEK_SET);
       if (!process_preamble(m_dvi_fp, errflag)
           || !find_postamble(m_dvi_fp, errflag)
           || !read_postamble(m_dvi_fp, errflag, True)) {
           TRACE_FILES((stderr, "reading of %p failed: %s!",
                      (void *)m_dvi_fp,
                      get_dvi_error(*errflag)));
           return False;
       }
    }

    old_page_w = globals.page.w;
    old_page_h = globals.page.h;

    *errflag = NO_ERROR;
    if (!internal_open_dvi(globals.dvi_name, errflag, load_fonts)) {
/*     || !internal_init_dvi(errflag, load_fonts)) { */
       XClearWindow(DISP, mane.win);
       XBell(DISP, 0);
       statusline_print(STATUS_MEDIUM, "%s: %s%s", globals.dvi_name, get_dvi_error(*errflag),
                      resource.watch_file > 0.0 ? "; will try to reload ..." : " (click on window to reload)");
       close_old_filep();

       return False;
    }
    else { /* success */
       if (fstatbuf.st_ino != dvi_inode) {
           dvi_inode = fstatbuf.st_ino;
           form_dvi_property();
           set_dvi_property();
       }
       if (globals.page.w != old_page_w || globals.page.h != old_page_h)
           reconfig();

       htex_reinit();

       globals.cursor.flags &= ~CURSOR_CORRUPTED;
       return True;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean load_font ( struct font ,
Boolean  use_t1lib 
)

Definition at line 362 of file dvi-init.c.

{
    double fsize = fontp->fsize;
    int dpi = fsize + 0.5;
    char *font_found;
    int size_found;
    int magic;
    Boolean hushcs = resource.hush_chk;

    fontp->file = NULL;

    /* BUG ALERT: This used to be:
     *
     * if (--globals.ev.ctr == 0) {
     *     read_events(EV_GE_IDLE);
     * }
     * force_statusline_update();
     * XSync(DISP, False);
     *
     * The idea was to update the `loading fonts ...' popup. However,
     * calling read_events() here may call dvi_file_changed() if the
     * user clicks on the window, which calls file_exists_p(), and
     * that changes m_dvi_fp while it's still being used to read the
     * postamble (where load_font() is called from), which will cause
     * xdvi to crash! (bug #968127).
     *
     * Sadly, without this update, the `loading fonts' popup doesn't
     * appear before the main window comes up ...
     */

#ifdef T1LIB
    fontp->file = font_open(fontp->fontname, &font_found,
                         fsize, &size_found,
                         &fontp->filename, &fontp->t1id);
#else
    fontp->file = font_open(fontp->fontname, &font_found,
                         fsize, &size_found,
                         &fontp->filename);
#endif /* T1LIB */

#ifdef T1LIB
    if (fontp->t1id >= 0 && use_t1lib) {
       /* It's a type1 font */
       fontp->fsize = fsize;       /* It comes in all sizes */
       fontp->timestamp = ++current_timestamp;
       fontp->maxchar = maxchar = 255;
       fontp->set_char_p = set_t1_char;
       /* read_T1_char is a dummy */
       fontp->read_char = read_T1_char;
       fontp->glyph = xmalloc (256 * sizeof (struct glyph));
       memset((char *) fontp->glyph, 0, 256 * sizeof (struct glyph));
       fontp->flags |= FONT_LOADED;
       if (font_found != NULL) {
           statusline_print(STATUS_MEDIUM,
                          "Error: Can't find font %s; using %s instead. Expect ugly output.",
                          fontp->fontname, font_found);
           force_statusline_update();
           free(fontp->fontname);
           fontp->fontname = font_found; /* this has been allocated by font_open */
       }
       return True;
    }
#endif /* T1LIB */
    /* when not using T1lib, fontp->file == NULL means total failure */
    if (fontp->file == NULL) {
       if (globals.ev.flags & EV_GE_NEWDOC)
           return False;
       fontp->flags |= FONT_LOADED;       /* as loaded as it'll get */
       XDVI_ERROR((stderr, "Can't find font %s.%dpk", fontp->fontname, dpi));
       return False;
    }
    fontp->flags |= FONT_LOADED;

    if (font_found != NULL  && strcmp(fontp->fontname, font_found) != 0) {
       /* some other font used - FIXME: is there a more efficient way than strcmp() for checking this? */
       statusline_print(STATUS_MEDIUM,
                      "Can't find pixel font %s; using %s instead at %d dpi.",
                      fontp->fontname, font_found, dpi);
       force_statusline_update();
       free(fontp->fontname);
       fontp->fontname = font_found; /* this has been allocated by font_open */
       hushcs = True;
    }
    else if (!kpse_bitmap_tolerance((double)size_found, fsize)) { /* a different size used */
       statusline_print(STATUS_MEDIUM,
                      "Can't find pixel font %s at %d dpi; using %d dpi instead.",
                      fontp->fontname, dpi, size_found);
       force_statusline_update();
    }

    /* PK version of some font found */
    fontp->fsize = size_found;
    fontp->timestamp = ++current_timestamp;
    fontp->maxchar = maxchar = 255;
    fontp->set_char_p = set_char;
    magic = get_bytes(fontp->file, 2);

    switch(magic) {
    case PK_MAGIC:
       read_PK_index(fontp, (wide_bool)hushcs);
       break;
#ifdef USE_GF
    case GF_MAGIC:
       read_GF_index(fontp, (wide_bool)hushcs);
       break;
#endif
    case VF_MAGIC:
       if (resource.omega)
           maxchar = read_VF_index(fontp, (wide_bool)hushcs);
       else
           (void)read_VF_index(fontp, (wide_bool)hushcs);
       break;
    default:
       XDVI_FATAL((stderr, "Cannot recognize format for font file %s", fontp->filename));
       break;
    }
    
    if (fontp->flags & FONT_VIRTUAL) {
       if (!resource.omega) {
           while (maxchar > 0 && fontp->macro[maxchar].pos == NULL) {
              --maxchar;
           }
           if (maxchar < 255) {
              realloc_virtual_font(fontp, (wide_ubyte)maxchar);
           }
       }
    }
    else {
       while (maxchar > 0 && fontp->glyph[maxchar].addr == 0)
           --maxchar;
       if (maxchar < 255)
           realloc_font(fontp, (wide_ubyte)maxchar);
    }
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* open_dvi_file_wrapper ( const char *  filename,
Boolean  from_command_line,
Boolean  open_new_instance,
Boolean tried_dvi_ext,
Boolean  from_file_history 
)

Definition at line 1331 of file dvi-init.c.

{
    char *real_filename = NULL;
    char *new_dvi_name = NULL;
    char canonical_path[MAXPATHLEN + 1];
    
    if (from_command_line) {
       TRACE_HTEX((stderr, "filename IS from commandline"));
       /*
         if filename is from command-line, we want to treat the file as a DVI file
         always (and NOT launch the browser or other programs; that'd just confuse
         people, who meant to launch *xdvi*). `find_dvi_file' tries to locate the
         file and does all error handling; on success, it returns a fully expanded
         filename.
        */
       real_filename = find_dvi_file(filename, tried_dvi_ext, from_file_history); /* this allocates real_filename */
       if (real_filename == NULL)
           return False;
       
       TRACE_HTEX((stderr, "filename |%s| %p from commandline;\ndvi_name: |%s|,\nfilename: |%s|%p",
                  real_filename, real_filename, globals.dvi_name, filename, (void *)filename));
       new_dvi_name = xstrdup(REALPATH(real_filename, canonical_path));
       free(real_filename);
       TRACE_FILES((stderr, "new_dvi_name: |%s|", new_dvi_name));
       return new_dvi_name;
    }
    else {
       /*
         if it's not from the command line (e.g. result of clicking Mouse-1 on a link);
         in this case we might fall back to using the browser.
         Check whether it's a local file:
        */
       const char *filename_no_prefix;
       char *expanded_filename;
       TRACE_HTEX((stderr, "filename NOT from commandline"));
       if ((filename_no_prefix = is_local_file(filename)) != NULL) {
           /* if it's a local file, check whether it's a DVI file: */
           if ((expanded_filename = is_dvi_file(filename_no_prefix)) != NULL) {
              /* yes, open it */
              if (open_dvi_file(expanded_filename, open_new_instance)) {
                  TRACE_FILES((stderr, "success: %p |%s|", expanded_filename, expanded_filename));
                  if (!open_new_instance) {
                     new_dvi_name = expand_filename_append_dvi(expanded_filename, USE_DVI_PATH, True);
                     TRACE_FILES((stderr, "new_dvi_name: %p |%s|", (void*)new_dvi_name, new_dvi_name));
                  }
              }
              free(expanded_filename);
              return new_dvi_name;
           }
           else {
              /*
                local file, but not a DVI file;
                try other viewers for this MIME type:
              */
              TRACE_HTEX((stderr, "%s is NOT a DVI file", filename_no_prefix));
              launch_program(filename);
              return NULL;
           }
       }
       else {
           /* not a local file, retrieve it with the browser: */
           launch_browser(filename);
           return NULL;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean process_preamble ( FILE fp,
dviErrFlagT errflag 
)

Definition at line 689 of file dvi-init.c.

{
    ubyte k;
    static char job_id[300];

    TRACE_FILES((stderr, "process_preamble: fp = %p, errflag = %d", (void *)fp, *errflag));
    
    if (get_byte(fp) != PRE) {
       *errflag = NOT_A_DVI_FILE;
       TRACE_FILES((stderr, "process_preamble: fp = %p, errflag = %d, returning False", (void *)fp, *errflag));
       return False;
    }
    if (get_byte(fp) != 2) {
       *errflag = WRONG_DVI_VERSION;
       TRACE_FILES((stderr, "process_preamble: fp = %p, errflag = %d, returning False", (void *)fp, *errflag));
       return False;
    }
    numerator = get_bytes(fp, 4);
    denominator = get_bytes(fp, 4);
    magnification = get_bytes(fp, 4);
    dimconv = (((double)numerator * magnification)
              / ((double)denominator * 1000.));
    dimconv = dimconv * (((long)resource.pixels_per_inch) << 16) / 254000;
    tpic_conv = resource.pixels_per_inch * magnification / 1000000.0;
    k = get_byte(fp);
    fread(job_id, sizeof(char), (int)k, fp);
    job_id[k] = '\0';

    TRACE_FILES((stderr, "process_preamble: fp = %p, errflag = %d, returning True", (void *)fp, *errflag));
    
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void read_GF_index ( struct font ,
wide_bool   
)

Definition at line 243 of file gf.c.

{
    int hppp, vppp;
    ubyte ch, cmnd;
    struct glyph *g;
    long checksum;

    fontp->read_char = read_GF_char;
    GF_file = fontp->file;
    if (globals.debug & DBG_PK)
       printf("Reading GF pixel file %s\n", fontp->filename);
    /*
     * Find postamble.
     */
    fseek(GF_file, (long)-4, SEEK_END);
    while (get_bytes(GF_file, 4) != ((unsigned long)TRAILER << 24 | TRAILER << 16
                          | TRAILER << 8 | TRAILER))
       fseek(GF_file, (long)-5, SEEK_CUR);
    fseek(GF_file, (long)-5, SEEK_CUR);
    for (;;) {
       ch = get_byte(GF_file);
       if (ch != TRAILER)
           break;
       fseek(GF_file, (long)-2, SEEK_CUR);
    }
    if (ch != GF_ID_BYTE)
       XDVI_FATAL((stderr, "Bad end of font file %s", fontp->fontname));
    fseek(GF_file, (long)-6, SEEK_CUR);
    expect(POST_POST);
    fseek(GF_file, get_lbytes(GF_file, 4), SEEK_SET);   /* move to postamble */
    /*
     * Read postamble.
     */
    expect(POST);
    (void)get_bytes(GF_file, 4);   /* pointer to last eoc + 1 */
    (void)get_bytes(GF_file, 4);   /* skip design size */
    checksum = get_bytes(GF_file, 4);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
       && !hushcs)
       XDVI_WARNING((stderr, "Checksum mismatch (dvi = %lu, gf = %lu) in font file %s",
                    fontp->checksum, checksum, fontp->filename));
    hppp = get_lbytes(GF_file, 4);
    vppp = get_lbytes(GF_file, 4);
    if (hppp != vppp && (globals.debug & DBG_PK))
       printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
    (void)get_bytes(GF_file, 4);   /* skip min_m */
    (void)get_bytes(GF_file, 4);   /* skip max_m */
    (void)get_bytes(GF_file, 4);   /* skip min_n */
    (void)get_bytes(GF_file, 4);   /* skip max_n */
    /*
     * Prepare glyph array.
     */
    fontp->glyph = xmalloc(256 * sizeof(struct glyph));
    memset((char *)fontp->glyph, 0, 256 * sizeof(struct glyph));
    /*
     * Read glyph directory.
     */
    while ((cmnd = get_byte(GF_file)) != POST_POST) {
       int addr;

       ch = get_byte(GF_file);     /* character code */
       g = &fontp->glyph[ch];
       switch (cmnd) {
       case CHAR_LOC:
           /* g->pxl_adv = get_lbytes(GF_file, 4); */
           (void)get_bytes(GF_file, 4);
           (void)get_bytes(GF_file, 4);   /* skip dy */
           break;
       case CHAR_LOC0:
           /* g->pxl_adv = get_byte(GF_file) << 16; */
           (void)get_byte(GF_file);
           break;
       default:
           XDVI_FATAL((stderr, "Non-char_loc command found in GF preamble:  %d", cmnd));
       }
       g->dvi_adv = fontp->dimconv * get_lbytes(GF_file, 4);
       addr = get_bytes(GF_file, 4);
       if (addr != -1)
           g->addr = addr;
       if (globals.debug & DBG_PK)
           printf("Read GF glyph for character %d; dy = %ld, addr = %x\n",
                 ch, g->dvi_adv, addr);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void read_PK_index ( struct font ,
wide_bool   
)

Definition at line 318 of file pk.c.

{
    int hppp, vppp;
    long checksum;

    fontp->read_char = read_PK_char;
    if (globals.debug & DBG_PK)
       printf("Reading PK pixel file %s\n", fontp->filename);

    fseek(fontp->file, (long)get_byte(fontp->file), SEEK_CUR); /* skip comment */

    (void)get_bytes(fontp->file, 4);      /* skip design size */
    checksum = get_bytes(fontp->file, 4);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
       && !hushcs)
       XDVI_WARNING((stderr, "Checksum mismatch (dvi = %lu, pk = %lu) in font file %s",
                    fontp->checksum, checksum, fontp->filename));
    hppp = get_lbytes(fontp->file, 4);
    vppp = get_lbytes(fontp->file, 4);
    if (hppp != vppp && (globals.debug & DBG_PK))
       printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
    /*
     * Prepare glyph array.
     */
    fontp->glyph = xmalloc(256 * sizeof(struct glyph));
    memset((char *)fontp->glyph, 0, 256 * sizeof(struct glyph));
    /*
     * Read glyph directory (really a whole pass over the file).
     */
    for (;;) {
       int bytes_left, flag_low_bits;
       unsigned int ch;

       PK_skip_specials(fontp);
       if (PK_flag_byte == PK_POST)
           break;
       flag_low_bits = PK_flag_byte & 0x7;
       if (flag_low_bits == 7) {
           bytes_left = get_bytes(fontp->file, 4);
           ch = get_bytes(fontp->file, 4);
       }
       else if (flag_low_bits > 3) {
           bytes_left = ((flag_low_bits - 4) << 16) + get_bytes(fontp->file, 2);
           ch = get_byte(fontp->file);
       }
       else {
           bytes_left = (flag_low_bits << 8) + get_byte(fontp->file);
           ch = get_byte(fontp->file);
       }
       fontp->glyph[ch].addr = ftell(fontp->file);
       fontp->glyph[ch].x2 = PK_flag_byte;
#ifdef linux
# ifndef SHORTSEEK
#  define SHORTSEEK 2048
# endif
       /* A bug in Linux libc (as of 18oct94) makes a short read faster
          than a short forward seek. Totally non-intuitive.  */
       if (bytes_left > 0 && bytes_left < SHORTSEEK) {
           char *dummy = xmalloc(bytes_left);
           fread(dummy, 1, bytes_left, fontp->file);
           free(dummy);
       }
       else
           /* seek backward, or long forward */
#endif /* linux */
           fseek(fontp->file, (long)bytes_left, SEEK_CUR);
       if (globals.debug & DBG_PK)
           printf("Scanning pk char %u, at %ld.\n", ch, fontp->glyph[ch].addr);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean read_postamble ( FILE fp,
dviErrFlagT errflag,
Boolean  load_fonts 
)

Definition at line 828 of file dvi-init.c.

{
    ubyte cmnd;
    Boolean font_not_found = False;
    struct font      *fontp;

    TRACE_FILES((stderr, "read_postamble: reading %p (%d)", (void *)fp, load_fonts));

    /* clear existing font table */
    memset((char *)tn_table, 0, (int)sizeof tn_table);
    free_vf_chain(tn_head);
    tn_head = NULL;
    for (fontp = font_head; fontp != NULL; fontp = fontp->next)
       fontp->flags &= ~FONT_IN_USE;

    
    if (get_byte(fp) != POST) {
       *errflag = POSTAMBLE_NO_POST;
       TRACE_FILES((stderr, "read_postamble: returning FALSE"));
       return False;
    }
    m_last_page_offset = get_bytes(fp, 4);
    if (numerator != get_bytes(fp, 4)
       || denominator != get_bytes(fp, 4)
       || magnification != get_bytes(fp, 4)) {
       *errflag = POSTAMBLE_NO_MATCH;
       TRACE_FILES((stderr, "read_postamble: returning FALSE"));
       return False;
    }

    /* read largest box height and width */
    dvi_unshrunk_page_h = (spell_conv(get_lbytes(fp, 4)) >> 16) + resource.yoffset_int;
    if (dvi_unshrunk_page_h < m_paper_unshrunk_h)
       dvi_unshrunk_page_h = m_paper_unshrunk_h;
    dvi_unshrunk_page_w = (spell_conv(get_lbytes(fp, 4)) >> 16) + resource.xoffset_int;
    if (dvi_unshrunk_page_w < m_paper_unshrunk_w)
       dvi_unshrunk_page_w = m_paper_unshrunk_w;
    (void)get_bytes(fp, 2); /* max stack size */
    total_pages = get_bytes(fp, 2);

    /* read font definitions */
    while ((cmnd = get_byte(fp)) >= FNTDEF1 && cmnd <= FNTDEF4) {
       struct font *f = define_font(load_fonts, fp, cmnd, (struct font *)NULL, tn_table,
                                 TNTABLELEN, &tn_head, &font_not_found);
       if (load_fonts && f == NULL) {
           TRACE_FILES((stderr, "read_postamble: returning FALSE"));
           return False;
       }
       else if (!load_fonts) { /* return early */
           TRACE_FILES((stderr, "read_postamble: returning TRUE"));
           return True;
       }
    }
    if (cmnd != POSTPOST) {
       *errflag = POSTAMBLE_NON_FNTDEF;
       TRACE_FILES((stderr, "read_postamble: returning FALSE"));
       return False;
    }
    if (font_not_found) {
       *errflag = NOT_ALL_PIXEL_FILES_FOUND;
       TRACE_FILES((stderr, "read_postamble: returning FALSE"));
       return False;
    }
    free_unused_fonts();

    TRACE_FILES((stderr, "read_postamble: returning TRUE"));
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned long read_VF_index ( struct font ,
wide_bool   
)

Definition at line 59 of file vf.c.

{
    FILE *VF_file = fontp->file;
    ubyte cmnd;
    ubyte *avail, *availend;       /* available space for macros */
    long checksum;
    struct macro *newmacro;
    unsigned long maxcc = 0;
    Boolean dummy = False;
    
    fontp->read_char = NULL;
    fontp->flags |= FONT_VIRTUAL;
    fontp->set_char_p = set_vf_char;
    if (globals.debug & DBG_PK)
       printf("Reading VF file %s\n", fontp->filename);
    /*
     * Read preamble.
     */
    fseek(VF_file, (long)get_byte(VF_file), SEEK_CUR);  /* skip comment */
    checksum = get_bytes(VF_file, 4);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
       && !hushcs)
       XDVI_WARNING((stderr, "Checksum mismatch (dvi = %lu, vf = %lu) in font file %s",
                    fontp->checksum, checksum, fontp->filename));
    (void)get_bytes(VF_file, 4);   /* skip design size */
    /*
     * Read the fonts.
     */
    fontp->vf_table = xmalloc(VFTABLELEN * sizeof(struct font *));
    memset((char *)fontp->vf_table, 0, VFTABLELEN * sizeof(struct font *));
    fontp->vf_chain = NULL;
    fontp->first_font = NULL;
    while ((cmnd = get_byte(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
       struct font *newfontp = define_font(True,
                                       VF_file, cmnd, fontp,
                                       fontp->vf_table, VFTABLELEN,
                                       &fontp->vf_chain,
                                       &dummy);
       if (fontp->first_font == NULL)
           fontp->first_font = newfontp;
    }
    /*
     * Prepare macro array.
     */
    if (resource.omega) {
       fontp->maxchar = 65535;
       fontp->macro = xmalloc(65536 * sizeof(struct macro));
       memset((char *)fontp->macro, 0, 65536 * sizeof(struct macro));
    }
    else {
       fontp->macro = xmalloc(256 * sizeof(struct macro));
       memset((char *)fontp->macro, 0, 256 * sizeof(struct macro));
    }
    /*
     * Read macros.
     */
    avail = availend = NULL;
    for (; cmnd <= LONG_CHAR; cmnd = get_byte(VF_file)) {
       struct macro *m;
       int len;
       unsigned long cc;
       long width;

       if (cmnd == LONG_CHAR) {    /* long form packet */
           len = get_bytes(VF_file, 4);
           cc = get_bytes(VF_file, 4);
           width = get_bytes(VF_file, 4);
           if ((resource.omega && cc >= 65536)
              || (!resource.omega && cc >= 256)) {
              XDVI_WARNING((stderr, "Virtual character %lu in font %s ignored.",
                           cc, fontp->fontname));
              fseek(VF_file, (long)len, SEEK_CUR);
              continue;
           }
       }
       else { /* short form packet */
           len = cmnd;
           cc = get_byte(VF_file);
           width = get_bytes(VF_file, 3);
       }
       if (resource.omega) {
           maxcc = (cc > maxcc) ? cc : maxcc;
       }
       m = &fontp->macro[cc];
       m->dvi_adv = width * fontp->dimconv;
       if (len > 0) {
           if (len <= availend - avail) {
              m->pos = avail;
              avail += len;
           }
           else {
              m->free_me = True;
              if (len <= VF_PARM_1) {
                  m->pos = avail = xmalloc(VF_PARM_2);
                  availend = avail + VF_PARM_2;
                  avail += len;
              }
              else
                  m->pos = xmalloc((unsigned)len);
           }
           fread((char *)m->pos, 1, len, VF_file);
           m->end = m->pos + len;
       }
       if (globals.debug & DBG_PK)
            printf("Read VF macro for character %lu; dy = %ld, length = %d\n",
                  cc, m->dvi_adv, len);
    }
    if (cmnd != POST)
       XDVI_FATAL((stderr, "Wrong command byte found in VF macro list:  %d", cmnd));

    fclose(VF_file);
    fontp->file = NULL;
    if (resource.omega) {
       size_t i;
       newmacro = xmalloc((maxcc + 1) * sizeof(struct macro));
       for (i = 0; i <= maxcc; i++) {
           newmacro[i] = fontp->macro[i];
       }
       free(fontp->macro);
       fontp->macro = newmacro;
       fontp->maxchar = maxcc;
       return maxcc;
    }
    else
       return 0; /* dummy */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void realloc_font ( struct font ,
wide_ubyte   
)

Definition at line 322 of file dvi-init.c.

{
    struct glyph *glyph;

    glyph = fontp->glyph = xrealloc(fontp->glyph,
                                (unsigned int)(newsize + 1) * sizeof(struct glyph));
    if (newsize > fontp->maxchar)
       memset((char *)(glyph + fontp->maxchar + 1), 0,
             (int)(newsize - fontp->maxchar) * sizeof(struct glyph));
    maxchar = fontp->maxchar = newsize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void realloc_virtual_font ( struct font ,
wide_ubyte   
)

Definition at line 340 of file dvi-init.c.

{
    struct macro *macro;

    macro = fontp->macro = xrealloc(fontp->macro,
                                (unsigned int)(newsize + 1) * sizeof(struct macro));
    if (newsize > fontp->maxchar)
       memset((char *)(macro + fontp->maxchar + 1), 0,
             (int)(newsize - fontp->maxchar) * sizeof(struct macro));
    maxchar = fontp->maxchar = newsize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 971 of file dvi-init.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 185 of file dvi-init.c.

{
    struct font *f;

    for (f = font_head; f != NULL; f = f->next) {
       if ((f->flags & FONT_LOADED) && !(f->flags & FONT_VIRTUAL)) {
           delete_glyphs(f);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Boolean set_paper_type ( const char *  arg)

Definition at line 777 of file dvi-init.c.

{
    const char *arg1;
    char temp[21];
    const char **p;
    char *q;
    const char **paper_types = get_paper_types();
    size_t paper_types_size = get_paper_types_size();
    
    if (*arg == '+') {
       ++arg;
       ignore_papersize_specials = True;
    }
    if (strlen(arg) > sizeof(temp) - 1)
       return False;
    q = temp;
    for (;;) {       /* convert to lower case */
       char c = *arg++;
       if (c >= 'A' && c <= 'Z')
           c ^= ('a' ^ 'A');
       *q++ = c;
       if (c == '\0')
           break;
    }
    arg = temp;
    /* perform substitutions */
    for (p = paper_types; p < paper_types + paper_types_size; p += 2) {
       if (strcmp(temp, *p) == 0) {
           arg = p[1];
           break;
       }
    }
    arg1 = strchr(arg, 'x');
    if (arg1 == NULL)
       return False;
    m_paper_unshrunk_w = atopix(arg, False);
    m_paper_unshrunk_h = atopix(arg1 + 1, False);

    return (m_paper_unshrunk_w != 0 && m_paper_unshrunk_h != 0);
}

Here is the call graph for this function:

Here is the caller graph for this function: