View | Details | Raw Unified
Collapse All | Expand All

(-) texlive-bin-2007.orig/build/source/texk/dviljk/ChangeLog (-4 / +43 lines)
 Lines 1-3    Link Here 
2007-07-02  Joachim Schrod  <jschrod@acm.org>
	* dvi2xx.c (DoSpecial): Security issue: usage of tmpnam() caused
	tempfile race condition. I use mkdtemp() if it's available and
	fall back to tmpnam.
	Special parsing of include files was inconsistent, unify it. The
	current parsing code still allows lots of non-sensical special
	commands, but at least it doesn't access unrelated variables any
	more.
2007-06-28  Joachim Schrod  <jschrod@acm.org>
	* dvi2xx.c: Fixed a whole bunch of buffer overflows: The program
	did not check memory bounds for any string operation. All places
	where strings are copied with strcpy are replaced by dynamically
	allocated strings (with xstrdup from kpathsea) or bounded string
	operations. Fixed also manual string copy operations on special
	strings. Fixed array buffer overflow in defpoint and fill special
	operations.
	(DoSpecial): Call of ghostscript for psfile special had also a
	potential buffer overflow caused by unchecked usage of sprintf.
	Fix core dump: Check if all required parameters of psfile special
	are passed.
	Bumped version number up to 2.6p3.
	* dvi2xx.h: Some fixed sized string arrays are pointers now, they
	get dynamically allocated.
	(GetBytes): Another buffer overflow: Check that the buffer size is
	sufficient to store the read bytes. That relies on the invariant
	that the GetBytes macro is always called with an array as argument
	and not with a pointer.
	* config.h: Throw an error if kpathsea is not used. dvi2xx.c
	had previously already kpathsea dependencies without protecting
	them with #if KPATHSEA. We go that road further since upstream
	does not exist any more.
2006-05-29  Karl Berry  <karl@tug.org>
2006-05-29  Karl Berry  <karl@tug.org>
	* Makefile.in (install-exec): cd $(bindir) in case we are doing
	* Makefile.in (install-exec): cd $(bindir) in case we are doing
 Lines 17-23    Link Here 
	Olaf Weber
	Olaf Weber
Sat Jan 17 15:09:59 1998  Sebastian Rahtz  <s.rahtz@elsevier.co.uk>
Sat Jan 17 15:09:59 1998  Sebastian Rahtz  <s.rahtz@elsevier.co.uk>
	* assorted patches from Peter Breitenlohner, Olaf Weber, 
	* assorted patches from Peter Breitenlohner, Olaf Weber,
 	Eli Zaretskii, Fabrice Popineau etc. Hope it all still works.
 	Eli Zaretskii, Fabrice Popineau etc. Hope it all still works.
 Lines 54-60    Link Here 
Mon Dec  9 00:53:30 1996  Ulrik Vieth  <vieth@thphy.uni-duesseldorf.de>
Mon Dec  9 00:53:30 1996  Ulrik Vieth  <vieth@thphy.uni-duesseldorf.de>
	* dvihp: Use `basename $0` in usage and version messages for
	* dvihp: Use `basename $0` in usage and version messages for
 	consistency with other programs and scripts.  
 	consistency with other programs and scripts.
	Also accept -help, -version in addition to --help, --version.
	Also accept -help, -version in addition to --help, --version.
Sat Dec  7 17:15:54 1996  Karl Berry  <karl@cs.umb.edu>
Sat Dec  7 17:15:54 1996  Karl Berry  <karl@cs.umb.edu>
 Lines 218-224    Link Here 
Fri Dec 30 15:25:54 1994  Karl Berry  <karl@cs.umb.edu>
Fri Dec 30 15:25:54 1994  Karl Berry  <karl@cs.umb.edu>
        * Makefile.in (install-exec): Don't depend on default, so dvilj4
        * Makefile.in (install-exec): Don't depend on default, so dvilj4
        doesn't get made if the user didn't want it. 
        doesn't get made if the user didn't want it.
        (install-data): mkdirchain on texinputdir and fontdir.
        (install-data): mkdirchain on texinputdir and fontdir.
        From Joachim.
        From Joachim.
 Lines 325-331    Link Here 
        * config.h (RESOLUTION, MFMODE) [LJ4L]: Set to 300/cx for this new
        * config.h (RESOLUTION, MFMODE) [LJ4L]: Set to 300/cx for this new
        symbol.
        symbol.
        * dvi2xx.c (DecodeArgs): Always scale pgsiz_dots. 
        * dvi2xx.c (DecodeArgs): Always scale pgsiz_dots.
        (main) [LJ4]: Don't hardwire 600dpi.
        (main) [LJ4]: Don't hardwire 600dpi.
        These fixes from ajp@eng.cam.ac.uk.
        These fixes from ajp@eng.cam.ac.uk.
(-) texlive-bin-2007.orig/build/source/texk/dviljk/c-auto.in (-6 / +20 lines)
 Lines 1-9    Link Here 
/* c-auto.in.  Generated automatically from configure.in by autoheader.  */
/* c-auto.in.  Generated from configure.in by autoheader.  */
/* acconfig.h -- used by autoheader when generating c-auto.in.
/* Define if type char is unsigned and you are not using gcc.  */
   If you're thinking of editing acconfig.h to fix a configuration
#ifndef __CHAR_UNSIGNED__
   problem, don't. Edit the c-auto.h file created by configure,
#undef __CHAR_UNSIGNED__
   instead.  Even better, fix configure to give the right answer.  */
#endif
/* Define to 1 if you have the `mkdtemp' function. */
#undef HAVE_MKDTEMP
/* Define to 1 if you have the `rmdir' function. */
#undef HAVE_RMDIR
/* The number of bytes in a long.  */
/* Define to 1 if you have the `unlink' function. */
#undef HAVE_UNLINK
/* The size of a `long', as computed by sizeof. */
#undef SIZEOF_LONG
#undef SIZEOF_LONG
/* Define to 1 if type `char' is unsigned and you are not using gcc.  */
#ifndef __CHAR_UNSIGNED__
# undef __CHAR_UNSIGNED__
#endif
(-) texlive-bin-2007.orig/build/source/texk/dviljk/config.h (-6 / +22 lines)
 Lines 216-227    Link Here 
#endif
#endif
#ifndef KPATHSEA
#ifndef KPATHSEA
extern bool findfile(
#error "Would need changed findfile, dviljk has changed allocation semantic of name member in tfontptr"
#if NeedFunctionPrototypes
char path[], char n[], long4 fontmag, char name[], 
	      bool tfm, int level
#endif
    );
#endif
#endif
 Lines 444-446    Link Here 
/* If we have neither, should fall back to fprintf with fixed args.  */
/* If we have neither, should fall back to fprintf with fixed args.  */
#endif
#endif
#endif
#endif
/* If unlink and rmdir are not there, we don't delete the temporary files. */
#ifndef HAVE_RMDIR
#define rmdir(dir)
#endif
#ifndef HAVE_UNLINK
#define unlink(file)
#endif
/* If mkdtemp() does not exist, we have to use tmpnam(). */
#ifndef HAVE_MKDTEMP
#define mkdtemp(dir) (tmpnam(dir) ? \
		      ( mkdir(dir, 0700) == -1 ? NULL : dir ) :	\
		      ( errno = EINVAL, NULL ) )
#endif
#ifndef KPATHSEA
/* FIXME: Should provide a strdup function. But currently this tree is
   only used in connection with kpathsea anyhow. */
#error "Need xstrdup and xmalloc function, e.g. from kpathsea"
#endif
(-) texlive-bin-2007.orig/build/source/texk/dviljk/configure (+56 lines)
 Lines 1283-1288    Link Here 
for ac_func in rmdir unlink mkdtemp
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:1290: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
  echo $ac_n "(cached) $ac_c" 1>&6
else
  cat > conftest.$ac_ext <<EOF
#line 1295 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char $ac_func(); below.  */
#include <assert.h>
/* Override any gcc2 internal prototype to avoid an error.  */
/* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */
char $ac_func();
int main() {
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
choke me
#else
$ac_func();
#endif
; return 0; }
EOF
if { (eval echo configure:1318: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
  rm -rf conftest*
  eval "ac_cv_func_$ac_func=yes"
else
  echo "configure: failed program was:" >&5
  cat conftest.$ac_ext >&5
  rm -rf conftest*
  eval "ac_cv_func_$ac_func=no"
fi
rm -f conftest*
fi
if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
  echo "$ac_t""yes" 1>&6
    ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
  cat >> confdefs.h <<EOF
#define $ac_tr_func 1
EOF
 
else
  echo "$ac_t""no" 1>&6
fi
done
ac_config_files="$ac_config_files Makefile"
ac_config_files="$ac_config_files Makefile"
trap '' 1 2 15
trap '' 1 2 15
(-) texlive-bin-2007.orig/build/source/texk/dviljk/configure.in (+2 lines)
 Lines 14-18    Link Here 
AC_C_CHAR_UNSIGNED
AC_C_CHAR_UNSIGNED
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long)
AC_CHECK_FUNCS(rmdir unlink mkdtemp)
KPSE_CONFIG_FILES([Makefile])
KPSE_CONFIG_FILES([Makefile])
AC_OUTPUT
AC_OUTPUT
(-) texlive-bin-2007.orig/build/source/texk/dviljk/dvi2xx.c (-420 / +469 lines)
 Lines 1-5    Link Here 
/* $Id: dvi2xx.c,v 2.5 1997/12/08 20:52:20 neumann Exp $ */
/* $Id: dvi2xx.c,v 2.5 1997/12/08 20:52:20 neumann Exp $ */
#define VERSION "2.6p2 (dviljk)"
#define VERSION "dviljk (version 2.6p3)"
/*
/*
#define DEBUGGS 1
#define DEBUGGS 1
*/
*/
 Lines 165-171    Link Here 
# endif
# endif
#endif
#endif
  /* Initialize pixel_files */   
  /* Initialize pixel_files */
  for (i = 0; i <= MAXOPEN; i++)
  for (i = 0; i <= MAXOPEN; i++)
    pixel_files[i].pixel_file_id = FPNULL;
    pixel_files[i].pixel_file_id = FPNULL;
 Lines 173-179    Link Here 
  y_origin = YDEFAULTOFF; /* y-origin in dots                    */
  y_origin = YDEFAULTOFF; /* y-origin in dots                    */
  setbuf(ERR_STREAM, NULL);
  setbuf(ERR_STREAM, NULL);
  (void) strcpy(G_progname, argv[0]);
  G_progname = argv[0];
#ifdef KPATHSEA
#ifdef KPATHSEA
  kpse_set_progname(argv[0]);
  kpse_set_progname(argv[0]);
  kpse_set_program_enabled (kpse_pk_format, MAKE_TEX_PK_BY_DEFAULT, kpse_src_compile);
  kpse_set_program_enabled (kpse_pk_format, MAKE_TEX_PK_BY_DEFAULT, kpse_src_compile);
 Lines 275-281    Link Here 
  EMIT1("@PJL SET PAGEPROTECT=OFF\012");
  EMIT1("@PJL SET PAGEPROTECT=OFF\012");
  EMIT1("@PJL ENTER LANGUAGE=PCL\012");
  EMIT1("@PJL ENTER LANGUAGE=PCL\012");
  if (econoMode && LJ6)
  if (econoMode && LJ6)
      EMIT1("@PJL SET ECONOMODE=ON\012");  
      EMIT1("@PJL SET ECONOMODE=ON\012");
  EMIT3("\033&u%dD\033*t%dR",RESOLUTION,RESOLUTION);
  EMIT3("\033&u%dD\033*t%dR",RESOLUTION,RESOLUTION);
  if (econoMode && !LJ6)
  if (econoMode && !LJ6)
    EMIT1("\033*v1T");
    EMIT1("\033*v1T");
 Lines 431-438    Link Here 
          /*
          /*
            fprintf(ERR_STREAM,"FirstPart\n count %d, mod %d, pp %d\n",(int)count[0],(int)count[0]%2,PageParity);
            fprintf(ERR_STREAM,"FirstPart\n count %d, mod %d, pp %d\n",(int)count[0],(int)count[0]%2,PageParity);
            */
            */
          SkipMode = 
          SkipMode =
            (bool)(PageParity != (short)((count[0]<0 ? 
            (bool)(PageParity != (short)((count[0]<0 ?
                                          labs(count[0])+1 : count[0])%2));
                                          labs(count[0])+1 : count[0])%2));
          if (count[0] == 0) SkipMode = (bool)!SkipMode;
          if (count[0] == 0) SkipMode = (bool)!SkipMode;
        }
        }
 Lines 641-647    Link Here 
   is not buffered. */
   is not buffered. */
/* read a buffered byte */
/* read a buffered byte */
char 
char
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
b_read(FILEPTR spfp)
b_read(FILEPTR spfp)
#else
#else
 Lines 661-667    Link Here 
}
}
#ifdef RISC_BUFFER
#ifdef RISC_BUFFER
void 
void
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
b_write(FILEPTR spfp, char c) /* write a buffered byte */
b_write(FILEPTR spfp, char c) /* write a buffered byte */
#else
#else
 Lines 677-683    Link Here 
  buffout[boact++] = c;
  buffout[boact++] = c;
}
}
void 
void
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
b_wrtmult(FILEPTR spfp, char *buf, int len) /* write a sequence of bytes to the output buffer */
b_wrtmult(FILEPTR spfp, char *buf, int len) /* write a sequence of bytes to the output buffer */
#else
#else
 Lines 693-714    Link Here 
    write_multi(buffout,1,boact,spfp);
    write_multi(buffout,1,boact,spfp);
    /* Copy only small blocks; large ones are written directly */
    /* Copy only small blocks; large ones are written directly */
    if (len < (BUFFSIZE/4)) {
    if (len < (BUFFSIZE/4)) {
      for (i = 0; i<len; i++) 
      for (i = 0; i<len; i++)
        buffout[i] = buf[i];
        buffout[i] = buf[i];
      boact = len;
      boact = len;
    } else {
    } else {
      write_multi(buf,1,len,spfp); 
      write_multi(buf,1,len,spfp);
      boact = 0;
      boact = 0;
    }
    }
  }
  }
  else {
  else {
    for (i = 0; i<len; i++) 
    for (i = 0; i<len; i++)
      buffout[boact++] = buf[i];
      buffout[boact++] = buf[i];
  }
  }
}
}
/* flush the output buffer */
/* flush the output buffer */
void 
void
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
b_oflush(FILEPTR spfp)
b_oflush(FILEPTR spfp)
#else
#else
 Lines 762-770    Link Here 
/***************************** CopyHPFile ******************************/
/***************************** CopyHPFile ******************************/
/*********************************************************************/
/*********************************************************************/
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
int getnum(FILEPTR spfp, char *t, char *numstr) 
int getnum(FILEPTR spfp, char *t, char *numstr)
#else
#else
int getnum(spfp, t, numstr) 
int getnum(spfp, t, numstr)
FILEPTR spfp;
FILEPTR spfp;
char *t, *numstr;
char *t, *numstr;
#endif
#endif
 Lines 777-806    Link Here 
}
}
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
void setOffset(char dir, char sign, int pos) 
void setOffset(char dir, char sign, int pos)
#else
#else
void setOffset(dir, sign, pos, first) 
void setOffset(dir, sign, pos, first)
char dir, sign;
char dir, sign;
int pos;
int pos;
#endif
#endif
{
{
  if ((sign == '+' || sign == '-') && pos > 0 ) {
  if ((sign == '+' || sign == '-') && pos > 0 ) {
    EMIT4("\033*p%c%d%c",sign,pos,dir);
    EMIT4("\033*p%c%d%c",sign,pos,dir);
#ifdef DEBUGGS   
#ifdef DEBUGGS
    fprintf(stderr, "relative: *p%c%d%c\n", sign, pos, dir);
    fprintf(stderr, "relative: *p%c%d%c\n", sign, pos, dir);
#endif
#endif
  } else if (pos>0) {
  } else if (pos>0) {
    EMIT3("\033*p%d%c",pos,dir);
    EMIT3("\033*p%d%c",pos,dir);
#ifdef DEBUGGS   
#ifdef DEBUGGS
    fprintf(stderr, "absolute: *p%d%c\n", pos, dir);
    fprintf(stderr, "absolute: *p%d%c\n", pos, dir);
#endif
#endif
    if (dir == 'X') 
    if (dir == 'X')
      last_rx = pos;
      last_rx = pos;
    else 
    else
      last_ry = pos;
      last_ry = pos;
  } else {
  } else {
    /*EMIT3("\033*p%d%c",pos,dir);*/
    /*EMIT3("\033*p%d%c",pos,dir);*/
#ifdef DEBUGGS   
#ifdef DEBUGGS
    fprintf(stderr, "Relative: *p%d%c\n", pos, dir);
    fprintf(stderr, "Relative: *p%d%c\n", pos, dir);
#endif
#endif
  }
  }
 Lines 832-838    Link Here 
     unwanted commands from the input file and outputs the rest */
     unwanted commands from the input file and outputs the rest */
  /* reset the input buffer */
  /* reset the input buffer */
  binumber = 0; 
  binumber = 0;
  biact = 0;
  biact = 0;
  qfprintf(ERR_STREAM," [%s", str);
  qfprintf(ERR_STREAM," [%s", str);
 Lines 853-868    Link Here 
          /* of the commands (x first, y first) */
          /* of the commands (x first, y first) */
          if (t=='Y' || t=='y') {
          if (t=='Y' || t=='y') {
            if (numstr[0]!='+' && numstr[0]!='-' && num<miny) 
            if (numstr[0]!='+' && numstr[0]!='-' && num<miny)
              miny = num;
              miny = num;
            if (t=='y') {
            if (t=='y') {
              num = getnum(spfp, &t, numstr);
              num = getnum(spfp, &t, numstr);
              if (numstr[0]!='+' && numstr[0]!='-' && num<minx) 
              if (numstr[0]!='+' && numstr[0]!='-' && num<minx)
                minx = num;
                minx = num;
            }
            }
          }
          }
          if (t=='X' || t=='x') {
          if (t=='X' || t=='x') {
            if (numstr[0]!='+' && numstr[0]!='-' && num<minx) 
            if (numstr[0]!='+' && numstr[0]!='-' && num<minx)
              minx = num;
              minx = num;
            if (t=='x') {
            if (t=='x') {
 Lines 920-935    Link Here 
  }
  }
  qfprintf(ERR_STREAM," [%s", str);
  qfprintf(ERR_STREAM," [%s", str);
  /* reset input buffer again */
  /* reset input buffer again */
  binumber = 0; 
  binumber = 0;
  biact = 0;
  biact = 0;
  /* Pass through the input file again but this time output the */
  /* Pass through the input file again but this time output the */
  /* retained PCL commands */
  /* retained PCL commands */
#ifdef DEBUGGS   
#ifdef DEBUGGS
  fprintf(stderr,"\nminx=%d, miny=%d, xg=%d, yg=%d\n", 
  fprintf(stderr,"\nminx=%d, miny=%d, xg=%d, yg=%d\n",
          minx, miny, x_goffset, y_goffset);
          minx, miny, x_goffset, y_goffset);
#endif  
#endif
  do {
  do {
    t = (char)b_read(spfp);
    t = (char)b_read(spfp);
    if (t==0x1B) {
    if (t==0x1B) {
 Lines 948-954    Link Here 
            } else {
            } else {
              setOffset('Y',numstr[0], num);
              setOffset('Y',numstr[0], num);
            }
            }
            
            if (t == 'y') {
            if (t == 'y') {
              num = getnum(spfp, &t,numstr);
              num = getnum(spfp, &t,numstr);
              if (numstr[0]!='+' && numstr[0]!='-') {
              if (numstr[0]!='+' && numstr[0]!='-') {
 Lines 960-975    Link Here 
              }
              }
            }
            }
          }
          }
            
          if (t=='X' || t=='x') {
          if (t=='X' || t=='x') {
            if (numstr[0]!='+' && numstr[0]!='-') {
            if (numstr[0]!='+' && numstr[0]!='-') {
              /*Add in the correct horizontal offset*/
              /*Add in the correct horizontal offset*/
              setOffset('X',numstr[0],
              setOffset('X',numstr[0],
                        num - minx + (int)PIXROUND(h,hconv) + x_goffset);
                        num - minx + (int)PIXROUND(h,hconv) + x_goffset);
            } else { 
            } else {
              setOffset('X',numstr[0], num);
              setOffset('X',numstr[0], num);
            }
            }
            
            if (t=='x') {
            if (t=='x') {
              num = getnum(spfp, &t,numstr);
              num = getnum(spfp, &t,numstr);
              if (numstr[0]!='+' && numstr[0]!='-') {
              if (numstr[0]!='+' && numstr[0]!='-') {
 Lines 1027-1033    Link Here 
        case(0x63):
        case(0x63):
          /* Rectangular draw commands */
          /* Rectangular draw commands */
          EMIT1("\033*c");
          EMIT1("\033*c");
          for (t = (char)b_read(spfp); t<0x40 || t>0x60; 
          for (t = (char)b_read(spfp); t<0x40 || t>0x60;
               t = (char)b_read(spfp))
               t = (char)b_read(spfp))
            EMITC(t);
            EMITC(t);
          EMITC(t);
          EMITC(t);
 Lines 1110-1116    Link Here 
  long4 x = 0;      /* number being constructed */
  long4 x = 0;      /* number being constructed */
  unsigned char h;
  unsigned char h;
  while (n--) {
  while (n--) {
    x <<= 8; 
    x <<= 8;
    read_byte(fp,h);
    read_byte(fp,h);
    x |= h;
    x |= h;
  }
  }
 Lines 1143-1149    Link Here 
#ifdef SIGN_DEBUG
#ifdef SIGN_DEBUG
  long4    x0;      /* copy of x  */
  long4    x0;      /* copy of x  */
#endif
#endif
  read_byte(fp,h); 
  read_byte(fp,h);
  x = h; /* get first (high-order) byte */
  x = h; /* get first (high-order) byte */
  n1 = n--;
  n1 = n--;
  while (n--) {
  while (n--) {
 Lines 1296-1302    Link Here 
                                        /* ---> result in DX       */
                                        /* ---> result in DX       */
  if (  (regs.h.dl & 0x80)              /* file handle points to a device */
  if (  (regs.h.dl & 0x80)              /* file handle points to a device */
        && !(regs.h.dl & 0x07) ) {      /* neither console i/o or null    */ 
        && !(regs.h.dl & 0x07) ) {      /* neither console i/o or null    */
    regs.h.dl  |= 0x20;                 /* set BINARY bit in device info  */
    regs.h.dl  |= 0x20;                 /* set BINARY bit in device info  */
    regs.h.ah = (unsigned char) 0x44;   /* IOCTL                  */
    regs.h.ah = (unsigned char) 0x44;   /* IOCTL                  */
 Lines 1501-1520    Link Here 
    /* For COMPRESSED CHARS */
    /* For COMPRESSED CHARS */
    if (PrevSize < nbpl) {
    if (PrevSize < nbpl) {
      PrevSize = nbpl;
      PrevSize = nbpl;
      if (PrevLine != NULL) 
      if (PrevLine != NULL)
        free(PrevLine);
        free(PrevLine);
      if ((PrevLine = (unsigned char*)malloc(PrevSize*sizeof(char))) 
      if ((PrevLine = (unsigned char*)malloc(PrevSize*sizeof(char)))
          == NULL) {
          == NULL) {
        PrevSize = 0; 
        PrevSize = 0;
        Fatal("EmitChar: Out of memory error!\n");
        Fatal("EmitChar: Out of memory error!\n");
      }
      }
    }
    }
    /* Clear seed line */
    /* Clear seed line */
    for (i = 0; i<nbpl; i++) 
    for (i = 0; i<nbpl; i++)
      PrevLine[i] = 0;
      PrevLine[i] = 0;
    CChar_Off = 0; 
    CChar_Off = 0;
    CChar_Last = -1;
    CChar_Last = -1;
    
    /* This bit copied from below... */
    /* This bit copied from below... */
#  ifdef USEPXL
#  ifdef USEPXL
    if (fontptr->id == pk89)
    if (fontptr->id == pk89)
 Lines 1530-1540    Link Here 
        CompressedCharLine(ce,nbpl,sl);
        CompressedCharLine(ce,nbpl,sl);
      }
      }
#  else
#  else
    for (i = num_rows; i > 0; i--) 
    for (i = num_rows; i > 0; i--)
      CompressedCharLine(ce,nbpl,(bits + (i-1)*nbpl));
      CompressedCharLine(ce,nbpl,(bits + (i-1)*nbpl));
#  endif /* USEPXL */
#  endif /* USEPXL */
  }
  }
  else 
  else
    CChar_Off = -1;
    CChar_Off = -1;
# endif /* LJ4 */
# endif /* LJ4 */
 Lines 1544-1553    Link Here 
# ifdef LJ4
# ifdef LJ4
  /* printf("raw: %d (%d * %d), comp: %d\n",
  /* printf("raw: %d (%d * %d), comp: %d\n",
     total,ce->width,ce->height,CChar_Off); */
     total,ce->width,ce->height,CChar_Off); */
  /* Characters that don't compress well are usually rather small so 
  /* Characters that don't compress well are usually rather small so
     reading them again and writing them uncompressed won't take 
     reading them again and writing them uncompressed won't take
     much time anyway. */
     much time anyway. */
  if (CChar_Off > total) 
  if (CChar_Off > total)
    CChar_Off = -1;
    CChar_Off = -1;
  if (CChar_Off >= 0) {
  if (CChar_Off >= 0) {
    EMIT4("\033*c%sd%dE\033(s%ldW", cnv_buffer,
    EMIT4("\033*c%sd%dE\033(s%ldW", cnv_buffer,
 Lines 1606-1612    Link Here 
      }
      }
#endif
#endif
    }
    }
    
#ifdef IBM3812
#ifdef IBM3812
#ifdef USEPXL
#ifdef USEPXL
  used_fontstorage += (long4)ce->height * ((ce->width + 15) >> 4) * 2 + 14;
  used_fontstorage += (long4)ce->height * ((ce->width + 15) >> 4) * 2 + 14;
 Lines 1652-1658    Link Here 
int     repeatcount;
int     repeatcount;
void             /* <Read and translate raster description@>*/
void             /* <Read and translate raster description@>*/
#if NeedFunctionPrototypes 
#if NeedFunctionPrototypes
PkRaster(struct char_entry *ce, int raster)
PkRaster(struct char_entry *ce, int raster)
#else
#else
PkRaster(ce, raster)
PkRaster(ce, raster)
 Lines 1735-1741    Link Here 
      if (wordweight < 31) {
      if (wordweight < 31) {
#ifdef COMMENT
#ifdef COMMENT
# ifdef DRAWGLYPH
# ifdef DRAWGLYPH
        { 
        {
          int k;
          int k;
          for (k = 15; k>=0; k--) {
          for (k = 15; k>=0; k--) {
            if ((power[k] & word)!=0) printf("Z");
            if ((power[k] & word)!=0) printf("Z");
 Lines 1749-1755    Link Here 
        for (j = 3; j >= (wordwidth * 4 - (long4)nbpl); j--) {
        for (j = 3; j >= (wordwidth * 4 - (long4)nbpl); j--) {
          OUTCHAR(((word >> (j << 3)) & 0xff));
          OUTCHAR(((word >> (j << 3)) & 0xff));
#ifdef DRAWGLYPH
#ifdef DRAWGLYPH
          { 
          {
            int k;
            int k;
            for (k = 7; k>=0; k--) {
            for (k = 7; k>=0; k--) {
              if ((power[k] & ((word >> (j << 3)) & 0xff))!=0) printf("M");
              if ((power[k] & ((word >> (j << 3)) & 0xff))!=0) printf("M");
 Lines 1760-1768    Link Here 
        }
        }
      }
      }
        
      switch (raster) {
      switch (raster) {
      case 1: 
      case 1:
        RasterLine(ce, nbpl, current_line, raster_line_buf);
        RasterLine(ce, nbpl, current_line, raster_line_buf);
        current_line++;
        current_line++;
        break;
        break;
 Lines 1826-1832    Link Here 
            OUTCHAR((tl       & 0xFF));
            OUTCHAR((tl       & 0xFF));
#ifdef DRAWGLYPH
#ifdef DRAWGLYPH
            { 
            {
              int k;
              int k;
              for (k = 31; k>=0; k--) {
              for (k = 31; k>=0; k--) {
                if ((power[k] & row[ii])!=0) printf("M");
                if ((power[k] & row[ii])!=0) printf("M");
 Lines 1839-1845    Link Here 
          for (j = 3; j >= (wordwidth *4 - (long4)nbpl); j--) {
          for (j = 3; j >= (wordwidth *4 - (long4)nbpl); j--) {
            OUTCHAR(((tl >> (j << 3)) & 0xff));
            OUTCHAR(((tl >> (j << 3)) & 0xff));
#ifdef DRAWGLYPH
#ifdef DRAWGLYPH
            { 
            {
              int k;
              int k;
              for (k = 7; k>=0; k--) {
              for (k = 7; k>=0; k--) {
                if ((power[k] & ((tl >> (j << 3)) & 0xff))!=0) printf("M");
                if ((power[k] & ((tl >> (j << 3)) & 0xff))!=0) printf("M");
 Lines 1850-1856    Link Here 
          }
          }
          switch (raster) {
          switch (raster) {
          case 1: 
          case 1:
            RasterLine(ce, (unsigned int)nbpl, current_line, raster_line_buf);
            RasterLine(ce, (unsigned int)nbpl, current_line, raster_line_buf);
            current_line++;
            current_line++;
            break;
            break;
 Lines 1969-1975    Link Here 
#ifdef LJ4
#ifdef LJ4
/* Compress a raster line in compression mode 2 */
/* Compress a raster line in compression mode 2 */
int 
int
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
CompressLine2(unsigned char *buffer, unsigned char *buffout, int emitbytes)
CompressLine2(unsigned char *buffer, unsigned char *buffout, int emitbytes)
#else
#else
 Lines 1984-1996    Link Here 
  char last,c;
  char last,c;
  /* trap empty lines (otherwise problems with Packbits) */
  /* trap empty lines (otherwise problems with Packbits) */
  if (emitbytes == 0) 
  if (emitbytes == 0)
    return(0);
    return(0);
  /* Use Packbits compression (mode 2) on raster line */
  /* Use Packbits compression (mode 2) on raster line */
  pos = buffer; 
  pos = buffer;
  litpos = buffer; 
  litpos = buffer;
  pack = 1; 
  pack = 1;
  ppos = buffout; 
  ppos = buffout;
  last = *pos++;
  last = *pos++;
  upper = buffer + emitbytes;
  upper = buffer + emitbytes;
  while (pos < upper) {
  while (pos < upper) {
 Lines 2000-2013    Link Here 
      /* At least three equal bytes ==> write out preceding literal sequence */
      /* At least three equal bytes ==> write out preceding literal sequence */
      if ((pack == 3) && ((lit = (int)(pos - litpos - 3)) != 0)) {
      if ((pack == 3) && ((lit = (int)(pos - litpos - 3)) != 0)) {
        while (lit >= 128) {
        while (lit >= 128) {
          *ppos++ = 127; 
          *ppos++ = 127;
          for (i = 1; i<=128; i++) 
          for (i = 1; i<=128; i++)
            *ppos++ = *litpos++;
            *ppos++ = *litpos++;
          lit -= 128;
          lit -= 128;
        }
        }
        if (lit != 0) {
        if (lit != 0) {
          *ppos++ = lit-1; 
          *ppos++ = lit-1;
          while ((lit--) > 0) 
          while ((lit--) > 0)
            *ppos++ = *litpos++;
            *ppos++ = *litpos++;
          /* litpos is now pos-3 (i.e. first of the sequence) */
          /* litpos is now pos-3 (i.e. first of the sequence) */
        }
        }
 Lines 2015-2033    Link Here 
    }
    }
    else {
    else {
      while (pack >= 128) {
      while (pack >= 128) {
        *ppos++ = 129; 
        *ppos++ = 129;
        *ppos++ = last; 
        *ppos++ = last;
        litpos += 128; 
        litpos += 128;
        pack -= 128;
        pack -= 128;
      }
      }
      /* At least 3 equal bytes or 2 that don't break a literal sequence
      /* At least 3 equal bytes or 2 that don't break a literal sequence
         ==> write out packed sequence */
         ==> write out packed sequence */
      if ((pack >= 3) || ((pack == 2) && (litpos == pos-3))) {
      if ((pack >= 3) || ((pack == 2) && (litpos == pos-3))) {
        *ppos++ = 257 - pack; 
        *ppos++ = 257 - pack;
        *ppos++ = last; 
        *ppos++ = last;
        litpos += pack;
        litpos += pack;
      }
      }
      pack = 1; 
      pack = 1;
      last = c;
      last = c;
    }
    }
    if (ppos > (buffout + BUFFSIZE/2 - 129)) {
    if (ppos > (buffout + BUFFSIZE/2 - 129)) {
 Lines 2036-2063    Link Here 
      return(0);
      return(0);
    }
    }
  }
  }
  
  while (pack >= 128) {
  while (pack >= 128) {
    *ppos++ = 129; 
    *ppos++ = 129;
    *ppos++ = last; 
    *ppos++ = last;
    litpos += 128; 
    litpos += 128;
    pack -= 128;
    pack -= 128;
  }
  }
  if ((pack >= 3) || ((pack == 2) && (litpos == pos-3))) {
  if ((pack >= 3) || ((pack == 2) && (litpos == pos-3))) {
    *ppos++ = 257 - pack; 
    *ppos++ = 257 - pack;
    *ppos++ = last; 
    *ppos++ = last;
    litpos += pack;
    litpos += pack;
  }
  }
  else if ((lit = (int)(pos - litpos)) != 0) {
  else if ((lit = (int)(pos - litpos)) != 0) {
    while (lit >= 128) {
    while (lit >= 128) {
      *ppos++ = 127; 
      *ppos++ = 127;
      for (i = 1; i<=128; i++) 
      for (i = 1; i<=128; i++)
        *ppos++ = *litpos++;
        *ppos++ = *litpos++;
      lit -= 128;
      lit -= 128;
    }
    }
    if (lit != 0) {
    if (lit != 0) {
      *ppos++ = lit-1; 
      *ppos++ = lit-1;
      while ((lit--) > 0) 
      while ((lit--) > 0)
        *ppos++ = *litpos++;
        *ppos++ = *litpos++;
    }
    }
  }
  }
 Lines 2079-2102    Link Here 
  int lit,i,pack;
  int lit,i,pack;
  /* Use compression mode 3 */
  /* Use compression mode 3 */
  pos = buffer; 
  pos = buffer;
  ppos = buffout; 
  ppos = buffout;
  upper = buffer + emitbytes; 
  upper = buffer + emitbytes;
  prev = PrevLine;
  prev = PrevLine;
  while(pos < upper) {
  while(pos < upper) {
    litpos = pos;
    litpos = pos;
    while ((*prev == *pos) && (pos < upper)) {
    while ((*prev == *pos) && (pos < upper)) {
      prev++; 
      prev++;
      pos++;
      pos++;
    }
    }
    if (pos < upper) {
    if (pos < upper) {
      pack = (int)(pos - litpos); 
      pack = (int)(pos - litpos);
      litpos = pos;
      litpos = pos;
      i = upper - pos; 
      i = upper - pos;
      if (i > 8) 
      if (i > 8)
        i = 8;
        i = 8;
      while ((*pos != *prev) && (i > 0)) {
      while ((*pos != *prev) && (i > 0)) {
        *prev++ = *pos++; 
        *prev++ = *pos++;
        i--;
        i--;
      }
      }
      i = (int)(pos - litpos - 1);
      i = (int)(pos - litpos - 1);
 Lines 2105-2120    Link Here 
        *ppos++ = lit + pack;
        *ppos++ = lit + pack;
      }
      }
      else {
      else {
        *ppos++ = lit + 31; 
        *ppos++ = lit + 31;
        pack -= 31;
        pack -= 31;
        while (pack >= 255) {
        while (pack >= 255) {
          *ppos++ = 255; 
          *ppos++ = 255;
          pack -= 255;
          pack -= 255;
        }
        }
        *ppos++ = pack;
        *ppos++ = pack;
      }
      }
      while (i >= 0) {
      while (i >= 0) {
        *ppos++ = *litpos++; 
        *ppos++ = *litpos++;
        i--;
        i--;
      }
      }
    }
    }
 Lines 2134-2140    Link Here 
/**********************************************************************/
/**********************************************************************/
void
void
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
RasterLine(struct char_entry *ce, unsigned int nbpl, 
RasterLine(struct char_entry *ce, unsigned int nbpl,
           unsigned int current_line, unsigned char *buffer)
           unsigned int current_line, unsigned char *buffer)
#else
#else
RasterLine(ce, nbpl, current_line, buffer)
RasterLine(ce, nbpl, current_line, buffer)
 Lines 2208-2228    Link Here 
    EMIT2("\033*b%dW", emitbytes);
    EMIT2("\033*b%dW", emitbytes);
    EMITL(emitbytes, buffer);
    EMITL(emitbytes, buffer);
    break;
    break;
 
  case 2:
  case 2:
    i = CompressLine2(buffer,buffin,emitbytes);
    i = CompressLine2(buffer,buffin,emitbytes);
    EMIT2("\033*b%dW", i);
    EMIT2("\033*b%dW", i);
    EMITL(i,buffin);
    EMITL(i,buffin);
    break;
    break;
 
  case 3:
  case 3:
    i = CompressLine3(buffer,buffin + BUFFSIZE/2,(int)nbpl);
    i = CompressLine3(buffer,buffin + BUFFSIZE/2,(int)nbpl);
    EMIT2("\033*b%dW", i);
    EMIT2("\033*b%dW", i);
    EMITL(i,buffin + BUFFSIZE/2);
    EMITL(i,buffin + BUFFSIZE/2);
    break;
    break;
 
  default: 
  default:
    fprintf(ERR_STREAM,"Unsupported compression mode!\n"); 
    fprintf(ERR_STREAM,"Unsupported compression mode!\n");
  }
  }
# else
# else
  EMIT2("\033*b%dW", emitbytes);
  EMIT2("\033*b%dW", emitbytes);
 Lines 2280-2289    Link Here 
  if (CompressCharMode == 3) {
  if (CompressCharMode == 3) {
    /* Check if PrevLine big enough; claim more space if not */
    /* Check if PrevLine big enough; claim more space if not */
    if (((int)nbpl) > PrevSize) {
    if (((int)nbpl) > PrevSize) {
      if (PrevLine != NULL) 
      if (PrevLine != NULL)
        free(PrevLine);
        free(PrevLine);
      if ((PrevLine = (unsigned char *)malloc(nbpl*sizeof(char))) == NULL) {
      if ((PrevLine = (unsigned char *)malloc(nbpl*sizeof(char))) == NULL) {
        PrevSize = 0; 
        PrevSize = 0;
        Fatal("RasterChar: out of memory!\n");
        Fatal("RasterChar: out of memory!\n");
      }
      }
      PrevSize = (int)nbpl;
      PrevSize = (int)nbpl;
 Lines 2419-2425    Link Here 
  if (bytes > 0) {
  if (bytes > 0) {
    /* do NOT load Huge characters */
    /* do NOT load Huge characters */
    if ((bytes > HUGE_CHAR_PATTERN) && (fontptr->id != pk89)) {
    if ((bytes > HUGE_CHAR_PATTERN) && (fontptr->id != pk89)) {
      qfprintf(ERR_STREAM,"Huge Character <%c> (%ld Bytes)\n", 
      qfprintf(ERR_STREAM,"Huge Character <%c> (%ld Bytes)\n",
               (char)c, bytes);
               (char)c, bytes);
      ptr->charsize = HUGE_SIZE;
      ptr->charsize = HUGE_SIZE;
      ptr->where.isloaded = _FALSE;
      ptr->where.isloaded = _FALSE;
 Lines 2505-2511    Link Here 
    SetPosn(h, v);
    SetPosn(h, v);
  }
  }
  /*  
  /*
    fprintf(ERR_STREAM,
    fprintf(ERR_STREAM,
            "(%d) hh=%ld (+%ld/+%ld), h=%ld, xh=%ld,xhh=%ld, [%ld|%ld] ->%d\n",
            "(%d) hh=%ld (+%ld/+%ld), h=%ld, xh=%ld,xhh=%ld, [%ld|%ld] ->%d\n",
            (int)do_posn,hh,(long4)ptr->cw,(long4)ptr->cw*(long4)hconv,h,
            (int)do_posn,hh,(long4)ptr->cw,(long4)ptr->cw*(long4)hconv,h,
 Lines 2553-2559    Link Here 
      int     tmp;
      int     tmp;
      char    sign;
      char    sign;
      if (!do_posn) 
      if (!do_posn)
        SetPosn(h, v);
        SetPosn(h, v);
#ifdef USEPXL
#ifdef USEPXL
 Lines 2563-2569    Link Here 
#endif
#endif
      if (tmp != 0) {
      if (tmp != 0) {
        if (tmp < 0) {
        if (tmp < 0) {
          sign = '-'; 
          sign = '-';
          tmp = -tmp;
          tmp = -tmp;
        } else
        } else
          sign = '+';
          sign = '+';
 Lines 2576-2582    Link Here 
#endif
#endif
      if (tmp != 0) {
      if (tmp != 0) {
        if (tmp < 0) {
        if (tmp < 0) {
          sign = '-'; 
          sign = '-';
          tmp = -tmp;
          tmp = -tmp;
        } else
        } else
          sign = '+';
          sign = '+';
 Lines 2644-2650    Link Here 
    fprintf(stderr,"--> hh(%ld) += cw(%ld) * hconv(%ld)",
    fprintf(stderr,"--> hh(%ld) += cw(%ld) * hconv(%ld)",
            (long)hh, (long)ptr->cw, (long) hconv);
            (long)hh, (long)ptr->cw, (long) hconv);
            */
            */
#ifdef LJ    
#ifdef LJ
    /* the guessed position must be a multiple of pixels */
    /* the guessed position must be a multiple of pixels */
    if (RESOLUTION == 300)
    if (RESOLUTION == 300)
      hh += (long4) ((ptr->cw)/4)*4*hconv;
      hh += (long4) ((ptr->cw)/4)*4*hconv;
 Lines 2661-2667    Link Here 
  if (command <= SET4)
  if (command <= SET4)
    h += ptr->tfmw;
    h += ptr->tfmw;
  if (pos_after) 
  if (pos_after)
    SetPosn(h, v);
    SetPosn(h, v);
  else
  else
    last_rx = (int)PIXROUND(h, hconv) + x_goffset;
    last_rx = (int)PIXROUND(h, hconv) + x_goffset;
 Lines 2682-2688    Link Here 
  }
  }
  fonts_used_on_this_page = 0;
  fonts_used_on_this_page = 0;
#endif
#endif
  for (p = hfontptr; p; p = p->next) 
  for (p = hfontptr; p; p = p->next)
    p->used_on_this_page = _FALSE;
    p->used_on_this_page = _FALSE;
}
}
 Lines 2740-2746    Link Here 
  rx = (int)PIXROUND(x, hconv) + x_goffset;
  rx = (int)PIXROUND(x, hconv) + x_goffset;
  ry = (int)PIXROUND(y, vconv) + y_goffset;
  ry = (int)PIXROUND(y, vconv) + y_goffset;
  /*  
  /*
  fprintf(ERR_STREAM,
  fprintf(ERR_STREAM,
	  "setposn to %ld/%ld, %d/%d, last: %d/%d\n",
	  "setposn to %ld/%ld, %d/%d, last: %d/%d\n",
	  (long)x,(long)y,
	  (long)x,(long)y,
 Lines 2804-2816    Link Here 
   offset in the buffer, CChar_Last is the first byte of the last
   offset in the buffer, CChar_Last is the first byte of the last
   compacted row (line repeat count).  Updates the previous line
   compacted row (line repeat count).  Updates the previous line
   (PrevLine) if necessary. */
   (PrevLine) if necessary. */
void 
void
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
CompressedCharLine(struct char_entry *ce, int nbpl, unsigned char *buffer)
CompressedCharLine(struct char_entry *ce, int nbpl, unsigned char *buffer)
#else
#else
CompressedCharLine(ce, nbpl, buffer)
CompressedCharLine(ce, nbpl, buffer)
struct char_entry *ce;
struct char_entry *ce;
int nbpl; 
int nbpl;
unsigned char *buffer;
unsigned char *buffer;
#endif
#endif
{
{
 Lines 2821-2851    Link Here 
    int t,mode,max;
    int t,mode,max;
    register int x,y,i;
    register int x,y,i;
    prev = PrevLine; 
    prev = PrevLine;
    obuf = buffer; 
    obuf = buffer;
    end = buffer + nbpl; 
    end = buffer + nbpl;
    x = 0;
    x = 0;
    while (obuf < end) {
    while (obuf < end) {
      if (*obuf != *prev) {
      if (*obuf != *prev) {
        *prev = *obuf; 
        *prev = *obuf;
        x = 1;
        x = 1;
      }
      }
      obuf++; 
      obuf++;
      prev++;
      prev++;
    }
    }
    if (x == 0 && CChar_Last >= 0) {
    if (x == 0 && CChar_Last >= 0) {
      (buffin[CChar_Last])++; 
      (buffin[CChar_Last])++;
      return; /* line repeat count +1 */
      return; /* line repeat count +1 */
    }
    }
    end = buffin + BUFFSIZE - 16; 
    end = buffin + BUFFSIZE - 16;
    obuf = buffin + CChar_Off; 
    obuf = buffin + CChar_Off;
    buff = buffer;
    buff = buffer;
    *obuf++ = 0; /* Line repeat count = 0 */
    *obuf++ = 0; /* Line repeat count = 0 */
    t = 0;
    t = 0;
    CChar_Last = CChar_Off; /* Next line */
    CChar_Last = CChar_Off; /* Next line */
    mode = 0; 
    mode = 0;
    y = *buff++; 
    y = *buff++;
    i = 7; /* i = current bit */
    i = 7; /* i = current bit */
    while ((t < ce->width) && (obuf < end)) {
    while ((t < ce->width) && (obuf < end)) {
      max = ce->width - t; /* maximum pixels left to do */
      max = ce->width - t; /* maximum pixels left to do */
 Lines 2853-2865    Link Here 
      if (mode == 0) {
      if (mode == 0) {
        /* white run */
        /* white run */
        while ((y & (1<<i)) == 0 && x < max) {
        while ((y & (1<<i)) == 0 && x < max) {
          x++; 
          x++;
          i--; 
          i--;
          if (i < 0) {
          if (i < 0) {
            i = 7; 
            i = 7;
            y = *buff++; 
            y = *buff++;
            while (y == 0 && x < max) {
            while (y == 0 && x < max) {
              x += 8; 
              x += 8;
              y = *buff++;
              y = *buff++;
            }
            }
          }
          }
 Lines 2869-2894    Link Here 
      else {
      else {
        /* black run */
        /* black run */
        while ((y & (1<<i)) != 0 && x < max) {
        while ((y & (1<<i)) != 0 && x < max) {
          x++; 
          x++;
          i--; 
          i--;
          if (i < 0) {
          if (i < 0) {
            i = 7; 
            i = 7;
            y = *buff++; 
            y = *buff++;
            while (y == 0xff && x < max) {
            while (y == 0xff && x < max) {
              x += 8; 
              x += 8;
              y = *buff++;
              y = *buff++;
            }
            }
          }
          }
        }
        }
        mode = 0;
        mode = 0;
      }
      }
      if (x > max) 
      if (x > max)
        x = max;
        x = max;
      t += x;
      t += x;
      /* make precautions for very long runs */
      /* make precautions for very long runs */
      while (x > 0xff) {
      while (x > 0xff) {
        *obuf++ = 0xff; 
        *obuf++ = 0xff;
        *obuf++ = 0; 
        *obuf++ = 0;
        x -= 0xff;
        x -= 0xff;
      }
      }
      *obuf++ = x;
      *obuf++ = x;
 Lines 2968-2975    Link Here 
#endif
#endif
{
{
  int     argind;            /* argument index for flags      */
  int     argind;            /* argument index for flags      */
  char    curarea[STRSIZE];  /* current file area             */
  char    *curarea;	     /* current file area             */
  char    curname[STRSIZE];  /* current file name             */
  char    *curname;   	     /* current file name             */
  char    *tcp, *tcp1;       /* temporary character pointers  */
  char    *tcp, *tcp1;       /* temporary character pointers  */
  char    *this_arg;
  char    *this_arg;
  double  x_offset = 0.0, y_offset = 0.0;
  double  x_offset = 0.0, y_offset = 0.0;
 Lines 2988-2996    Link Here 
#endif
#endif
#endif
#endif
  if (argc == 2 && (strcmp (argv[1], "--version") == 0)) {
  if (argc == 2 && EQ(argv[1], "--version")) {
    extern KPSEDLL char *kpathsea_version_string;
    extern KPSEDLL char *kpathsea_version_string;
    puts ("dvilj(k) 2.6");
    puts (VERSION);
    puts (kpathsea_version_string);
    puts (kpathsea_version_string);
    puts ("Copyright (C) 1997 Gustaf Neumann.\n\
    puts ("Copyright (C) 1997 Gustaf Neumann.\n\
There is NO warranty.  You may redistribute this software\n\
There is NO warranty.  You may redistribute this software\n\
 Lines 2998-3004    Link Here 
For more information about these matters, see the files\n\
For more information about these matters, see the files\n\
named COPYING and dvi2xx.c.\n\
named COPYING and dvi2xx.c.\n\
Primary author of Dvi2xx: Gustaf Neumann; -k maintainer: K. Berry.");
Primary author of Dvi2xx: Gustaf Neumann; -k maintainer: K. Berry.");
    exit (0); 
    exit (0);
  }
  }
#ifdef LJ4
#ifdef LJ4
 Lines 3048-3056    Link Here 
#ifdef LJ2P
#ifdef LJ2P
      case 'd':       /* d selects DUPLEX mode  */
      case 'd':       /* d selects DUPLEX mode  */
        tcp++;
        tcp++;
        if (*tcp == '1' ) 
        if (*tcp == '1' )
          DuplexMode = 1;
          DuplexMode = 1;
        else if (*tcp == '2') 
        else if (*tcp == '2')
          DuplexMode = 2;
          DuplexMode = 2;
        else {
        else {
          Warning("Invalid DUPLEX mode, assuming DUPLEX=1, Long-Edge Binding");
          Warning("Invalid DUPLEX mode, assuming DUPLEX=1, Long-Edge Binding");
 Lines 3062-3074    Link Here 
        DoublePage = _TRUE;
        DoublePage = _TRUE;
        tcp++;
        tcp++;
        if (*tcp == '1' || *tcp == '2') {
        if (*tcp == '1' || *tcp == '2') {
          if (*tcp == '2') 
          if (*tcp == '2')
            PrintFirstPart = _FALSE;
            PrintFirstPart = _FALSE;
          else             
          else
            PrintSecondPart = _FALSE;
            PrintSecondPart = _FALSE;
          tcp++;
          tcp++;
        }
        }
        if (*tcp == '-') 
        if (*tcp == '-')
          PrintEmptyPages = _FALSE;
          PrintEmptyPages = _FALSE;
        break;
        break;
#ifdef LJ4
#ifdef LJ4
 Lines 3256-3269    Link Here 
#ifdef LJ
#ifdef LJ
      case 'V':   /* bugfixes for various vendor's PCL emulations */
      case 'V':   /* bugfixes for various vendor's PCL emulations */
        tcp++;
        tcp++;
        if (*tcp == 'K' || *tcp == 'k') 
        if (*tcp == 'K' || *tcp == 'k')
          kyocera_mode = _TRUE;
          kyocera_mode = _TRUE;
        else
        else
          if (*tcp == 'B' || *tcp == 'b') 
          if (*tcp == 'B' || *tcp == 'b')
            brother_mode = _TRUE;
            brother_mode = _TRUE;
# ifdef LJ4
# ifdef LJ4
	else
	else
        if (*tcp == '6' || *tcp == '6') 
        if (*tcp == '6' || *tcp == '6')
	    LJ6 = _TRUE;
	    LJ6 = _TRUE;
# endif
# endif
        break;
        break;
 Lines 3306-3312    Link Here 
#endif
#endif
#ifdef __riscos
#ifdef __riscos
      case 'i': /* name of directory to store diagrams in */
      case 'i': /* name of directory to store diagrams in */
        tcp++; 
        tcp++;
        ddi = 0;
        ddi = 0;
        while (*tcp != ' ' && *tcp != '\0' && ddi < DIAGDIRSIZE-1) {
        while (*tcp != ' ' && *tcp != '\0' && ddi < DIAGDIRSIZE-1) {
          diagdir[ddi++] = *tcp++;
          diagdir[ddi++] = *tcp++;
 Lines 3328-3335    Link Here 
      }
      }
    } else {
    } else {
      (void) strcpy(filename, tcp);
      filename = tcp;
      if (!strcmp(filename, "-")) {
      if (EQ(filename, "-")) {
        EmitFileName = "-";
        EmitFileName = "-";
#ifdef RISC_USE_OSL
#ifdef RISC_USE_OSL
        dvifp = BINOPEN("Kbd:");
        dvifp = BINOPEN("Kbd:");
 Lines 3339-3395    Link Here 
	  AssureBinary(fileno(dvifp));
	  AssureBinary(fileno(dvifp));
#endif
#endif
      } else {
      } else {
	/* Since this code is used only once during startup, we don't care
	   about free()ing the allocated strings that represent filenames.
	   It will be more work to realize proper deallocation handling than
	   it's worth in terms of saving a few bytes. We consider these
	   bytes actually static memory where we don't know the size in
	   advance and don't add them to the allocated_storage count.
	   [27 Jun 07 -js] */
#ifdef KPATHSEA
#ifdef KPATHSEA
        /* split into directory + file name */
        /* split into directory + file name */
	int tcplen, argvlen;
	int tcplen, argvlen;
	tcp = (char *)xbasename(argv[argind]);/* this knows about any kind of slashes */
	tcp = (char *)xbasename(argv[argind]);/* this knows about any kind of slashes */
	tcplen = strlen(tcp);
	tcplen = strlen(tcp);
	if ( tcplen == 0 ) {
	  /* This happens when the DVI file name has a trailing slash; this
	     is not a valid name. Then we terminate the argument parsing
	     loop, a usage message will be output below. */
	  break;
	}
	argvlen = strlen(argv[argind]);
	argvlen = strlen(argv[argind]);
	if (tcplen == argvlen)
	if (tcplen == argvlen)
	  curarea[0] = '\0';
	  curarea = "";
	else {
	else {
	  (void) strcpy(curarea, argv[argind]);
	  curarea = xstrdup(argv[argind]);
	  curarea[argvlen-tcplen] = '\0';
	  curarea[argvlen-tcplen] = '\0';
	}
	}
#else
#else
        tcp = strrchr(argv[argind], '/');
        tcp = strrchr(argv[argind], '/');
        /* split into directory + file name */
        /* split into directory + file name */
        if (tcp == NULL) {
        if (tcp == NULL) {
          curarea[0] = '\0';
          curarea[0] = "";
          tcp = argv[argind];
          tcp = argv[argind];
        } else {
        } else {
          (void) strcpy(curarea, argv[argind]);
	  curarea = xstrdup(argv[argind]);
          curarea[tcp-argv[argind]+1] = '\0';
          curarea[tcp-argv[argind]+1] = '\0';
          tcp += 1;
          tcp += 1;
        }
        }
#endif
#endif
        (void) strcpy(curname, tcp);
        curname = (char *) xmalloc(strlen(tcp)+5);  /* + space for ".dvi" */
	(void) strcpy(curname, tcp);
        /* split into file name + extension */
        /* split into file name + extension */
        tcp1 = strrchr(tcp, '.');
        tcp1 = strrchr(curname, '.');
        if (tcp1 == NULL) {
        if (tcp1 == NULL) {
          (void) strcpy(rootname, curname);
          rootname = xstrdup(curname);
          strcat(curname, ".dvi");
          strcat(curname, ".dvi");
        } else {
        } else {
          *tcp1 = '\0';
          *tcp1 = '\0';
          (void) strcpy(rootname, curname);
          rootname = xstrdup(curname);
          *tcp1 = '.';
          *tcp1 = '.';
        }
        }
	filename = (char *) xmalloc(strlen(curarea)+strlen(curname)+1);
        (void) strcpy(filename, curarea);
        (void) strcpy(filename, curarea);
        (void) strcat(filename, curname);
        (void) strcat(filename, curname);
        if ((dvifp = BINOPEN(filename)) == FPNULL) {
        if ((dvifp = BINOPEN(filename)) == FPNULL) {
          /* do not insist on .dvi */
          /* do not insist on .dvi */
          if (tcp1 == NULL) {
          if (tcp1 == NULL) {
            int l = strlen(curname);
	    filename[strlen(filename) - 4] = '\0';
            if (l > 4)
	    dvifp = BINOPEN(filename);
              curname[l - 4] = '\0';
            l = strlen(filename);
            if (l > 4)
              filename[l - 4] = '\0';
          }
          }
          if (tcp1 != NULL || (dvifp = BINOPEN(filename)) == FPNULL) {
          if (dvifp == FPNULL) {
#ifdef MSC5
#ifdef MSC5
            Fatal("%s: can't find DVI file \"%s\"\n\n",
            Fatal("%s: can't find DVI file \"%s\"\n\n",
                  G_progname, filename);
                  G_progname, filename);
 Lines 3411-3417    Link Here 
  y_goffset = (short) MM_TO_PXL(y_offset) + y_origin;
  y_goffset = (short) MM_TO_PXL(y_offset) + y_origin;
  if (dvifp == FPNULL) {
  if (dvifp == FPNULL) {
    fprintf(ERR_STREAM,"\nThis is the DVI to %s converter version %s",
    fprintf(ERR_STREAM,"\nThis is the DVI to %s converter %s",
            PRINTER, VERSION);
            PRINTER, VERSION);
#ifdef SEVENBIT
#ifdef SEVENBIT
    fprintf(ERR_STREAM,", 7bit");
    fprintf(ERR_STREAM,", 7bit");
 Lines 3507-3519    Link Here 
    exit(1);
    exit(1);
  }
  }
  if (EQ(EmitFileName, "")) {
  if (EQ(EmitFileName, "")) {
    if ((EmitFileName = (char *)malloc( STRSIZE )) != NULL)
    EmitFileName = (char *) xmalloc(strlen(rootname)+sizeof(EMITFILE_EXTENSION));
      allocated_storage += STRSIZE;
    (void) strcpy(EmitFileName, rootname);
    else
      Fatal("Can't allocate storage of %d bytes\n",STRSIZE);
    (void) strcpy(EmitFileName, curname);
    if ((tcp1 = strrchr(EmitFileName, '.')))
      *tcp1 = '\0';
    strcat(EmitFileName, EMITFILE_EXTENSION);
    strcat(EmitFileName, EMITFILE_EXTENSION);
  }
  }
  if (G_quiet)
  if (G_quiet)
 Lines 3668-3674    Link Here 
  if (PrintTestPage) EMIT1("\033z");
  if (PrintTestPage) EMIT1("\033z");
#ifdef vms
#ifdef vms
  /* last record is not flushed to file, unless it is completely filled */
  /* last record is not flushed to file, unless it is completely filled */
  for (kk = (int)((*outfp)->_cnt); kk > 0; --kk) 
  for (kk = (int)((*outfp)->_cnt); kk > 0; --kk)
    putc('\0',outfp);
    putc('\0',outfp);
  fflush(outfp);
  fflush(outfp);
#endif
#endif
 Lines 3698-3703    Link Here 
#endif
#endif
  }
  }
  CloseFiles();
  CloseFiles();
  if ( tmp_dir[0] != '\0' )
    rmdir (tmp_dir);			/* ignore errors */
  exit(G_errenc);
  exit(G_errenc);
}
}
 Lines 3764-3778    Link Here 
#endif
#endif
{
{
  char *a,*b;
  char *a,*b;
  
  a = s1; 
  a = s1;
  b = s2;
  b = s2;
  while (*a != '\0') {
  while (*a != '\0') {
    if (tolower(*a) != tolower(*b)) return(_FALSE);
    if (tolower(*a) != tolower(*b)) return(_FALSE);
    a++; 
    a++;
    b++;
    b++;
  }
  }
  *end = b; 
  *end = b;
  return(_TRUE);
  return(_TRUE);
}
}
 Lines 3791-3808    Link Here 
{
{
  char *s;
  char *s;
  int count = 0;
  int count = 0;
  
  s = str;
  s = str;
  while ((*s != '\0') && (count < number)) {
  while ((*s != '\0') && (count < number)) {
    while ((*s == ' ') || (*s == ',') || (*s == '=')) 
    while ((*s == ' ') || (*s == ',') || (*s == '='))
      s++;
      s++;
    if (*s != '\0') {
    if (*s != '\0') {
      result[count++] = strtod(s,&s);
      result[count++] = strtod(s,&s);
    }
    }
  }
  }
  while ((*s == ' ') || (*s == ',') || (*s == '=')) 
  while ((*s == ' ') || (*s == ',') || (*s == '='))
    s++;
    s++;
  *end = s; 
  *end = s;
  return(count);
  return(count);
}
}
 Lines 3822-3843    Link Here 
  int results[4],no;
  int results[4],no;
  s = str;
  s = str;
  while (*s == ' ') 
  while (*s == ' ')
    s++;
    s++;
  if ((StrCompare("drawfile",s,&s)) || (StrCompare("DVIview_diagram",s,&s))) {
  if ((StrCompare("drawfile",s,&s)) || (StrCompare("DVIview_diagram",s,&s))) {
    if (printdiag == _FALSE) 
    if (printdiag == _FALSE)
      return(_TRUE); /* it's a diagram, but don't print */
      return(_TRUE); /* it's a diagram, but don't print */
    while ((*s == ' ') || (*s == '=')) 
    while ((*s == ' ') || (*s == '='))
      s++; /* space or '=' separates keyword/keyval */
      s++; /* space or '=' separates keyword/keyval */
    if (*s == '\0') {
    if (*s == '\0') {
      fprintf(ERR_STREAM,"No filename given for \\special-diagram!\n"); 
      fprintf(ERR_STREAM,"No filename given for \\special-diagram!\n");
      return(_TRUE);
      return(_TRUE);
    }
    }
    sh = diagname;
    sh = diagname;
    while ((*s != ' ') && (*s != ',') && (*s != '\0')) 
    while ((*s != ' ') && (*s != ',') && (*s != '\0'))
      *sh++ = *s++;
      *sh++ = *s++;
    *sh = '\0';
    *sh = '\0';
 Lines 3845-3851    Link Here 
    dt.scalex = dt.scaley = 100;
    dt.scalex = dt.scaley = 100;
    dt.cropl = dt.cropb = dt.cropr = dt.cropt = 0;
    dt.cropl = dt.cropb = dt.cropr = dt.cropt = 0;
    while (*s != '\0') {
    while (*s != '\0') {
      while ((*s == ' ') || (*s == ',')) 
      while ((*s == ' ') || (*s == ','))
        s++;
        s++;
      if (*s != '\0') {
      if (*s != '\0') {
        if (StrCompare("scale",s,&s)) {
        if (StrCompare("scale",s,&s)) {
 Lines 3853-3859    Link Here 
            fprintf(ERR_STREAM,
            fprintf(ERR_STREAM,
                   "Too few arguments (%d) given for <scale> - ignored.\n",no);
                   "Too few arguments (%d) given for <scale> - ignored.\n",no);
          }
          }
          dt.scalex = results[0]; 
          dt.scalex = results[0];
          dt.scaley = results[1];
          dt.scaley = results[1];
        }
        }
        else if (StrCompare("crop",s,&s)) {
        else if (StrCompare("crop",s,&s)) {
 Lines 3861-3875    Link Here 
            fprintf(ERR_STREAM,
            fprintf(ERR_STREAM,
                   "Too few arguments (%d) given for <crop> - ignored.\n",no);
                   "Too few arguments (%d) given for <crop> - ignored.\n",no);
          }
          }
          dt.cropl = results[0]; 
          dt.cropl = results[0];
          dt.cropr = results[1];
          dt.cropr = results[1];
          dt.cropt = results[2]; 
          dt.cropt = results[2];
          dt.cropb = results[3];
          dt.cropb = results[3];
        }
        }
        else {
        else {
          fprintf(ERR_STREAM,"Bad \\special keyword - <%s> ignored\n",s);
          fprintf(ERR_STREAM,"Bad \\special keyword - <%s> ignored\n",s);
          /* skip over this word */
          /* skip over this word */
          while ((*s != ' ') && (*s != ',') && (*s != '=') && (*s != '\0')) 
          while ((*s != ' ') && (*s != ',') && (*s != '=') && (*s != '\0'))
            s++;
            s++;
        }
        }
      }
      }
 Lines 3879-3885    Link Here 
    diagram(diagname,&dt);
    diagram(diagname,&dt);
    return(_TRUE);
    return(_TRUE);
  }
  }
  else 
  else
    return(_FALSE);
    return(_FALSE);
}
}
# endif /* LJ */
# endif /* LJ */
 Lines 3895-3964    Link Here 
int  n;
int  n;
#endif
#endif
{
{
  char    spbuf[STRSIZE], xs[STRSIZE], ys[STRSIZE];
  char    xs[STRSIZE], ys[STRSIZE];
  char    *sf = NULL, *psfile = NULL;
  char    *include_file = NULL;
  enum    { VerbFile, HPFile, PSFile } file_type;
  float   x,y;
  float   x,y;
  long4   x_pos, y_pos;
  long4   x_pos, y_pos;
  KeyWord k;
  KeyWord k;
  int     i, j, j1;
  int     i, j, j1;
  static  int   GrayScale = 10, Pattern = 1;
  static  int   GrayScale = 10, Pattern = 1;
  static  bool  GrayFill = _TRUE;
  static  bool  GrayFill = _TRUE;
  static  long4 p_x[80], p_y[80];
  static  long4 p_x[MAX_SPECIAL_DEFPOINTS], p_y[MAX_SPECIAL_DEFPOINTS];
  int llx=0, lly=0, urx=0, ury=0, rwi=0, rhi=0;
  int llx=0, lly=0, urx=0, ury=0, rwi=0;
#ifdef WIN32
  char    *gs_path;
#endif
  str[n] = '\0';
  str[n] = '\0';
  spbuf[0] = '\0';
  for ( i=0 ; i<MAX_SPECIAL_DEFPOINTS ; i++ )
    p_x[i] = p_y[i] = -1;
  SetPosn(h, v);
  SetPosn(h, v);
#ifdef __riscos
#ifdef __riscos
#ifdef LJ
#ifdef LJ
  if (ParseDiagram(str)) 
  if (ParseDiagram(str))
    return;
    return;
#endif
#endif
#endif
#endif
 
  while ( (str = GetKeyStr(str, &k)) != NULL ) {
  while ( (str = GetKeyStr(str, &k)) != NULL ) {
    /* get all keyword-value pairs */
    /* get all keyword-value pairs */
    /* for compatibility, single words are taken as file names */
    /* for compatibility, single words are taken as file names */
    if ( k.vt == None && access(k.Key, 0) == 0) {
    if ( k.vt == None && access(k.Key, 0) == 0) {
      if ( sf
      if ( include_file && !kpse_tex_hush ("special") ) {
#ifdef KPATHSEA
        Warning("More than one \\special file name given. %s ignored", include_file);
           && !kpse_tex_hush ("special")
	free (include_file);
#endif
      }
         )
      include_file = xstrdup(k.Key);
        Warning("More than one \\special file name given. %s ignored", sf);
      file_type = VerbFile;
      (void) strcpy(spbuf, k.Key);
    } else if ( GetKeyVal( &k, KeyTab, NKEYS, &i ) && i != -1 ) {
      sf = spbuf;
      /*
        for (j = 1; ((sf[j]=='/' ? sf[j]='\\':sf[j]) != '\0'); j++);
        */
    } else if ( GetKeyVal( &k, KeyTab, NKEYS, &i ) && i != -1 )
      switch (i) {
      switch (i) {
      case PSFILE:
      case PSFILE:
        if (sf
        if ( include_file ) {
#ifdef KPATHSEA
	  Warning("More than one \\special file name given. %s ignored", include_file);
            && !kpse_tex_hush ("special")
	  free(include_file);
#endif
	}
            )
        include_file = xstrdup(k.Val);
            Warning("More than one \\special file name given. %s ignored", sf);
	file_type = PSFile;
        (void) strcpy(spbuf, k.Val);
        psfile = spbuf;
        /*
          for (j=1; ((sf[j]=='/' ? sf[j]='\\':sf[j]) != '\0'); j++);
          */
        break;
        break;
        
      case HPFILE:
      case HPFILE:
        if (sf)
        if ( include_file && !kpse_tex_hush ("special") ) {
            Warning("More than one \\special file name given. %s ignored", sf);
	  Warning("More than one \\special file name given. %s ignored", include_file);
        (void) strcpy(spbuf, k.Val);
	  free(include_file);
        sf = spbuf;
	}
        /*
        include_file = xstrdup(k.Val);
          for (j=1; ((sf[j]=='/' ? sf[j]='\\':sf[j]) != '\0'); j++);
	file_type = HPFile;
          */
        break;
        break;
      case ORIENTATION:
      case ORIENTATION:
 Lines 3977-4000    Link Here 
          EMIT2("\033&l%dO\033*rF", (unsigned char)k.v.i);
          EMIT2("\033&l%dO\033*rF", (unsigned char)k.v.i);
        }
        }
#endif
#endif
        else
        else {
#ifdef KPATHSEA
	  Warning( "Invalid orientation (%d) given; ignored.", k.v.i);
           if (!kpse_tex_hush ("special"))
	}
#endif
          Warning( "Invalid orientation (%d)given; ignored.", k.v.i);
        break;
        break;
      case RESETPOINTS:
      case RESETPOINTS:
        (void) strcpy(spbuf, k.Val);
	for ( i=0 ; i<MAX_SPECIAL_DEFPOINTS ; i++ )
	  p_x[i] = p_y[i] = -1;
        sf = NULL;
        break;
        break;
      case DEFPOINT:
      case DEFPOINT:
        (void) strcpy(spbuf, k.Val);
	/* 254 is STRSIZE-1. cpp should be used to construct that number. */
        i = sscanf(spbuf,"%d(%[^,],%s)",&j,xs,ys);
        i = sscanf(k.Val,"%d(%254[^,],%254s)",&j,xs,ys);
        if (i>0) {
        if (i>0) {
          x_pos = h; 
	  if ( j < 0  ||  j >= MAX_SPECIAL_DEFPOINTS ) {
	    Warning ("defpoint %d ignored, must be between 0 and %d",
		     j, MAX_SPECIAL_DEFPOINTS);
	    break;
	  }
          x_pos = h;
          y_pos = v;
          y_pos = v;
          if (i>1) {
          if (i>1) {
            if (sscanf(xs,"%fpt",&x)>0) {
            if (sscanf(xs,"%fpt",&x)>0) {
 Lines 4010-4029    Link Here 
          }
          }
          p_x[j]=x_pos;
          p_x[j]=x_pos;
          p_y[j]=y_pos;
          p_y[j]=y_pos;
        } else
        } else {
#ifdef KPATHSEA
	  Warning("invalid point definition");
              if (!kpse_tex_hush ("special"))
	}
#endif
          Warning("invalid point definition\n");
        sf = NULL;
        break;
        break;
      case FILL:
      case FILL:
        (void) strcpy(spbuf, k.Val);
	/* 254 is STRSIZE-1. cpp should be used to construct that number. */
        i = sscanf(spbuf,"%d/%d %s",&j,&j1,xs);
        i = sscanf(k.Val,"%d/%d %254s",&j,&j1,xs);
        if (i>1) {
        if (i>1) {
#ifdef LJ
#ifdef LJ
	  if ( j < 0 || j >= MAX_SPECIAL_DEFPOINTS ) {
	    Warning ("fill ignored, point %d must be between 0 and %d",
		     j, MAX_SPECIAL_DEFPOINTS);
	    break;
	  }
	  if ( p_x[j] == -1 ) {
	    Warning ("fill ignored, point %d is undefined\n", j);
	    break;
	  }
	  if ( j1 < 0 || j1 >= MAX_SPECIAL_DEFPOINTS ) {
	    Warning ("fill ignored, point %d must be between 0 and %d",
		     j1, MAX_SPECIAL_DEFPOINTS);
	    break;
	  }
	  if ( p_x[j1] == -1 ) {
	    Warning ("fill ignored, point %d is undefined\n", j1);
	    break;
	  }
          SetPosn(p_x[j], p_y[j]);
          SetPosn(p_x[j], p_y[j]);
          x_pos = (long4)PIXROUND(p_x[j1]-p_x[j], hconv);
          x_pos = (long4)PIXROUND(p_x[j1]-p_x[j], hconv);
          y_pos = (long4)PIXROUND(p_y[j1]-p_y[j], vconv);
          y_pos = (long4)PIXROUND(p_y[j1]-p_y[j], vconv);
 Lines 4043-4064    Link Here 
        if ((k.v.i >= 0) && (k.v.i < 101)) {
        if ((k.v.i >= 0) && (k.v.i < 101)) {
          GrayScale = k.v.i;
          GrayScale = k.v.i;
          GrayFill = _TRUE;
          GrayFill = _TRUE;
        } else
        } else {
#ifdef KPATHSEA
           if (!kpse_tex_hush ("special"))
#endif
          Warning( "Invalid gray scale (%d) given; ignored.", k.v.i);
          Warning( "Invalid gray scale (%d) given; ignored.", k.v.i);
	}
        break;
        break;
      case PATTERN:
      case PATTERN:
        if ((k.v.i >= 0) && (k.v.i < 7)) {
        if ((k.v.i >= 0) && (k.v.i < 7)) {
          Pattern = k.v.i;
          Pattern = k.v.i;
          GrayFill = _FALSE;
          GrayFill = _FALSE;
        } else
        } else {
#ifdef KPATHSEA
           if (!kpse_tex_hush ("special"))
#endif
          Warning( "Invalid pattern (%d) given; ignored.", k.v.i);
          Warning( "Invalid pattern (%d) given; ignored.", k.v.i);
	}
        break;
        break;
      case LLX: llx = k.v.i; break;
      case LLX: llx = k.v.i; break;
 Lines 4066-4168    Link Here 
      case URX: urx = k.v.i; break;
      case URX: urx = k.v.i; break;
      case URY: ury = k.v.i; break;
      case URY: ury = k.v.i; break;
      case RWI: rwi = k.v.i; break;
      case RWI: rwi = k.v.i; break;
      case RHI: rhi = k.v.i; break;
      case RHI:
	if (!kpse_tex_hush ("special"))
	  Warning("Whatever rhi was good for once, it is ignored now.");
	break;
      default:
      default:
#ifdef KPATHSEA
	if ( !kpse_tex_hush ("special") )
           if (!kpse_tex_hush ("special"))
	  Warning("Can't handle %s=%s command; ignored.", k.Key, k.Val);
#endif
        Warning("Can't handle %s=%s command; ignored.", k.Key, k.Val);
        break;
        break;
      }
      }
      
    else
    } else if (!kpse_tex_hush ("special")) {
#ifdef KPATHSEA
           if (!kpse_tex_hush ("special"))
#endif
      Warning("Invalid keyword or value in \\special - <%s> ignored", k.Key);
      Warning("Invalid keyword or value in \\special - <%s> ignored", k.Key);
    }
    free (k.Key);
    if ( k.Val != NULL )  free(k.Val);
  }
  }
  if ( sf || psfile ) {
  if ( include_file ) {
    last_rx = last_ry = UNKNOWN;
    last_rx = last_ry = UNKNOWN;
#ifdef IBM3812
#ifdef IBM3812
    PMPflush;
    PMPflush;
#endif
#endif
    if (sf) {
      if (i == HPFILE) 
        CopyHPFile( sf );
      else 
        CopyFile( sf );
    }
    else
#ifdef LJ
#ifdef LJ
      if (psfile) {
    if ( file_type == PSFile) {
        /* int height = rwi * (urx - llx) / (ury - lly);*/
      /* int height = rwi * (urx - llx) / (ury - lly);*/
        int width  = urx - llx;
      int width  = urx - llx;
        int height = ury - lly;
      int height = ury - lly;
        char cmd[255];
      char cmd[255];
        int scale_factor    = 3000 * width / rwi;
      char *cmd_format = "%s -q -dSIMPLE -dSAFER -dNOPAUSE -sDEVICE=%s -sOutputFile=%s %s %s showpage.ps -c quit";
        int adjusted_height = height * 300/scale_factor;
      char *gs_cmd;
        int adjusted_llx    = llx    * 300/scale_factor;
      int scale_factor, adjusted_height, adjusted_llx;
        char *printer = "ljetplus"; /* use the most stupid one */
      char *printer = "ljetplus"; /* use the most stupid one */
      char pcl_file[STRSIZE];
        char scale_file_name[255];
      char scale_file[STRSIZE];
        char *scale_file = tmpnam(scale_file_name);
      FILEPTR scalef;
        char *pcl_file = tmpnam(NULL);  
        FILEPTR scalef;
      if ( urx == 0 || ury == 0 || rwi == 0 ) {
	/* Since dvips' psfile special has a different syntax, this might
        if ( (scalef = BOUTOPEN(scale_file)) == FPNULL ) {
	   well be one of those specials, i.e., a non-dviljk special. Then
          Warning("Unable to open file %s for writing", scale_file );
	   the Warning should be suppressable. */
          return;
	if ( !kpse_tex_hush ("special") )
        }
	  Warning ("Ignoring psfile special without urx, ury and rwi attributes");
        fprintf(scalef, "%.2f %.2f scale\n%d %d translate\n",  
	free (include_file);
                300.0/scale_factor, 300.0/scale_factor,
	return;
                0, adjusted_height == height ? 0 : ury);
      }
        BCLOSE( scalef );
      scale_factor    = 3000 * width / rwi;
      adjusted_height = height * 300/scale_factor;
      adjusted_llx    = llx    * 300/scale_factor;
      /* We cannot use mkstemp, as we cannot pass two open file descriptors
	 portably to Ghostscript. We don't want to use tmpnam() or tempnam()
	 either, as they have tempfile creation race conditions. Instead we
	 create a temporary directory with mkdtemp() -- if that's available.
	 If not, we are thrown back to tempnam(), to get our functionality
	 at all. We need to create the temporary directory only once per
	 run; it will be deleted in AllDone(). */
      if ( tmp_dir[0] == '\0' ) {
	char * base_dir;
	if ( (base_dir = getenv("TMPDIR")) == NULL ) {
	  base_dir = "/tmp";
	} else if ( strlen(base_dir) > STRSIZE - sizeof("/dviljkXXXXXX/include.pcl") ) {
	  Warning ("TMPDIR %s is too long, using /tmp instead", base_dir);
	  base_dir = "/tmp";
	}
	if ( base_dir[0] == '/'  && base_dir[1] == '\0' ) {
	  Warning ("Feeling naughty, do we? / is no temporary directory, dude");
	  base_dir = "/tmp";
	}
	strcpy (tmp_dir, base_dir);
	strcat (tmp_dir, "/dviljkXXXXXX");
	if ( mkdtemp(tmp_dir) == NULL ) {
	  Warning ("Could not create temporary directory %s, errno = %d; ignoring include file special",
		   tmp_dir, errno);
	  return;
	}
      }
      strcpy(pcl_file, tmp_dir);
      strcat(pcl_file, "/include.pcl");
      strcpy(scale_file, tmp_dir);
      strcat(scale_file, "/scale.ps");
      if ( (scalef = BOUTOPEN(scale_file)) == FPNULL ) {
	Warning("Unable to open file %s for writing", scale_file );
	free (include_file);
	unlink(scale_file);		/* ignore error */
	return;
      }
      fprintf(scalef, "%.2f %.2f scale\n%d %d translate\n",
	      300.0/scale_factor, 300.0/scale_factor,
	      0, adjusted_height == height ? 0 : ury);
      BCLOSE( scalef );
#ifdef WIN32
#ifdef WIN32
	gs_path = getenv("GS_PATH");
      if ( (gs_cmd = getenv("GS_PATH")) == NULL )
	if (!gs_path)
	gs_cmd = "gswin32c.exe";
	  gs_path = "gswin32c.exe";
#else
        sprintf(cmd,"%s -q -dSIMPLE -dSAFER -dNOPAUSE -sDEVICE=%s -sOutputFile=%s %s %s showpage.ps -c quit",
      gs_cmd = "gs";
		gs_path, printer, pcl_file, scale_file, psfile);
#else
        sprintf(cmd,"gs -q -dSIMPLE -dSAFER -dNOPAUSE -sDEVICE=%s -sOutputFile=%s %s %s showpage.ps -c quit",
                printer, pcl_file, scale_file, psfile);
#endif
#ifdef DEBUGGS   
        fprintf(stderr,
          "PS-file '%s' w=%d, h=%d, urx=%d, ury=%d, llx=%d, lly=%d, rwi=%d\n",
                psfile, urx - llx, height, urx,ury,llx,lly, rwi);
        fprintf(stderr,"%s\n",cmd);
#endif
#endif
        if (system(cmd)) {
      if ( strlen(cmd_format)-10 + strlen(gs_cmd) + strlen(printer) +
          Warning("execution of '%s' returned an error", cmd);
	       strlen(pcl_file) + strlen(scale_file) + strlen(include_file) +1 >
        } else {
	   sizeof(cmd) ) {
#ifdef DEBUGGS   
	Warning ("Ghostscript command for %s would be too long, skipping special", include_file);
          fprintf(stderr, "o=%d, h=%d, so=%d, sh=%d\n", 
	free (include_file);
                  llx, height, adjusted_llx, adjusted_height);
	unlink(scale_file);		/* ignore errors */
          
	unlink(pcl_file);
          fprintf(stderr, "OLD x=%d, y=%d\n", 
	return;
                  (int)PIXROUND(h, hconv) + x_goffset,
      }
                  (int)PIXROUND(v, vconv) + y_goffset);
      sprintf(cmd, cmd_format,
#endif  
	      gs_cmd, printer, pcl_file, scale_file, include_file);
          v -= 65536l*adjusted_height; /**300/scale_factor;*/
#ifdef DEBUGGS
          h -= 65536l*adjusted_llx; /* *300/scale_factor;*/
      fprintf(stderr,
          SetPosn(h, v);
	"PS-file '%s' w=%d, h=%d, urx=%d, ury=%d, llx=%d, lly=%d, rwi=%d\n",
#ifdef DEBUGGS   
	      include_file, urx - llx, height, urx,ury,llx,lly, rwi);
          fprintf(stderr, "NEW x=%d, y=%d\n", 
      fprintf(stderr,"%s\n",cmd);
                  (int)PIXROUND(h, hconv) + x_goffset,
#endif
                  (int)PIXROUND(v, vconv) + y_goffset);
      if (system(cmd)) {
#endif
	Warning("execution of '%s' returned an error", cmd);
      } else {
          CopyHPFile( pcl_file );
#ifdef DEBUGGS
          /* unlink(pcl_file); */
	fprintf(stderr, "o=%d, h=%d, so=%d, sh=%d\n",
          /* unlink(scale_file); */
		llx, height, adjusted_llx, adjusted_height);
        }
	fprintf(stderr, "OLD x=%d, y=%d\n",
		(int)PIXROUND(h, hconv) + x_goffset,
		(int)PIXROUND(v, vconv) + y_goffset);
#endif
	v -= 65536l*adjusted_height; /**300/scale_factor;*/
	h -= 65536l*adjusted_llx; /* *300/scale_factor;*/
	SetPosn(h, v);
#ifdef DEBUGGS
	fprintf(stderr, "NEW x=%d, y=%d\n",
		(int)PIXROUND(h, hconv) + x_goffset,
		(int)PIXROUND(v, vconv) + y_goffset);
#endif
	CopyHPFile( pcl_file );
      }
      }
      unlink(scale_file);		/* ignore errors */
      unlink(pcl_file);
    }
    else
#endif /* LJ */
#endif /* LJ */
    if ( file_type == HPFile )
      CopyHPFile( include_file );
    else if ( file_type == VerbFile )
      CopyFile( include_file );
    else
      Warning ("This can't happen: unknown file_type value %d", file_type);
    if ( include_file != NULL )  free(include_file);
  }
  }
}
}
 Lines 4173-4184    Link Here 
/**********************************************************************/
/**********************************************************************/
/*****************************  GetKeyStr  ****************************/
/*****************************  GetKeyStr  ****************************/
/**********************************************************************/
/**********************************************************************/
/* extract first keyword-value pair from string (value part may be null)
/* Extract first keyword-value pair from string (value part may be null),
 * return pointer to remainder of string
 * keyword and value are allocated and must be free by caller.
 * return NULL if none found
 * Return pointer to remainder of string,
 * return NULL if none found.
 */
 */
char    KeyStr[STRSIZE];
char    ValStr[STRSIZE];
#if NeedFunctionPrototypes
#if NeedFunctionPrototypes
char *GetKeyStr(char *str, KeyWord *kw )
char *GetKeyStr(char *str, KeyWord *kw )
#else
#else
 Lines 4187-4225    Link Here 
KeyWord *kw;
KeyWord *kw;
#endif
#endif
{
{
  char    *s, *k, *v, t;
  char *s, *start;
  char save_char, quote_char;
  if ( !str )
  if ( !str )
    return( NULL );
    return( NULL );
  for (s = str; *s == ' '; s++)
  for (s = str; *s == ' '; s++)
    ;          /* skip over blanks */
    ;          /* skip over blanks */
  if (*s == '\0')
  if (*s == '\0')
    return( NULL );
    return( NULL );
  for (k = KeyStr; /* extract keyword portion */
  start = s++;				/* start of keyword */
       *s != ' ' && *s != '\0' && *s != '=';
  while ( *s != ' ' && *s != '\0' && *s != '=' )  /* locate end */
       *k++ = *s++)
    s++;
    ;
  save_char = *s;
  *k = '\0';
  *s = '\0';
  kw->Key = KeyStr;
  kw->Key = xstrdup(start);
  kw->Val = v = NULL;
  kw->Val = NULL;
  kw->vt = None;
  kw->vt = None;
  for ( ; *s == ' '; s++)
  if ( save_char == '\0' )		/* shortcut when we're at the end */
    ;            /* skip over blanks */
    return (s);
  if ( *s != '=' )         /* look for "=" */
  *s = save_char;			/* restore keyword end char */
  while ( *s == ' ' ) s++ ;		/* skip over blanks */
  if ( *s != '=' )			/* no "=" means no value */
    return( s );
    return( s );
  for (s++; *s == ' '; s++);      /* skip over blanks */
  for (s++; *s == ' '; s++)
  if ( *s == '\'' || *s == '\"' )  /* get string delimiter */
    ;					/* skip over blanks */
    t = *s++;
  if ( *s == '\'' || *s == '\"' )	/* get string delimiter */
    quote_char = *s++;
  else
  else
    t = ' ';
    quote_char = ' ';
  for (v = ValStr; /* copy value portion up to delim */
  start = s;				/* no increment, might be "" as value */
       *s != t && *s != '\0';
  while ( *s != quote_char && *s != '\0' )
       *v++ = *s++)
    s++;			  /* locate end of value portion */
    ;
  save_char = *s;
  if ( t != ' ' && *s == t )
  *s = '\0';
    s++;
  kw->Val = xstrdup(start);
  *v = '\0';
  kw->Val = ValStr;
  kw->vt = String;
  kw->vt = String;
  if ( save_char != '\0' ) {		/* save_char is now quote_char */
    *s = save_char;
    if ( quote_char != ' ' )		/* we had real quote chars */
      s++;
  }
  return( s );
  return( s );
}
}
 Lines 4281-4287    Link Here 
#endif
#endif
{
{
  char *x, *y;
  char *x, *y;
  
  for (x = a, y = b; *a; a++, b++)
  for (x = a, y = b; *a; a++, b++)
    if ( tolower(*a) != tolower(*b) )
    if ( tolower(*a) != tolower(*b) )
      return( _FALSE );
      return( _FALSE );
 Lines 4469-4478    Link Here 
       *   process for simplicity always horizontally
       *   process for simplicity always horizontally
       */
       */
      /* 
      /*
         fprintf(ERR_STREAM,"large box: w=%d,x=%d,y=%d\n",(int)yy,(int)xx,0);
         fprintf(ERR_STREAM,"large box: w=%d,x=%d,y=%d\n",(int)yy,(int)xx,0);
         */
         */
      
      hor_offset  = HOR_HALF(30);
      hor_offset  = HOR_HALF(30);
      MoveHor(hor_offset);
      MoveHor(hor_offset);
      vert_offset = VERT_HALF(30);
      vert_offset = VERT_HALF(30);
 Lines 4547-4553    Link Here 
      yy += (long4)pgsiz_dots - (long4)last_ry;
      yy += (long4)pgsiz_dots - (long4)last_ry;
    if ((yy>0) && (xx>0))
    if ((yy>0) && (xx>0))
      EMIT4("\033*p-%ldY\033*c%lda%ldbP", 
      EMIT4("\033*p-%ldY\033*c%lda%ldbP",
            (long)yy - 1, (long)xx, (long)yy);
            (long)yy - 1, (long)xx, (long)yy);
#endif
#endif
    last_rx = last_ry = UNKNOWN;       /* next time full positioning */
    last_rx = last_ry = UNKNOWN;       /* next time full positioning */
 Lines 4708-4714    Link Here 
      if ((fid = pixel_files[least_used].pixel_file_id) != NO_FILE) {
      if ((fid = pixel_files[least_used].pixel_file_id) != NO_FILE) {
        /* mark file as being closed in the entry */
        /* mark file as being closed in the entry */
        fp = hfontptr;
        fp = hfontptr;
        while (fp != NULL && fp->font_file_id != fid) 
        while (fp != NULL && fp->font_file_id != fid)
          fp = fp->next;
          fp = fp->next;
        if (fp == NULL)
        if (fp == NULL)
          Fatal("Open file %x not found in font entry list.\n", fid);
          Fatal("Open file %x not found in font entry list.\n", fid);
 Lines 4763-4771    Link Here 
      while ((fp != NULL) && (fp->font_file_id != f))
      while ((fp != NULL) && (fp->font_file_id != f))
        fp = fp->next;
        fp = fp->next;
      if (fp == NULL) 
      if (fp == NULL)
        Fatal("Open file %x not found in font entry list.\n",f);
        Fatal("Open file %x not found in font entry list.\n",f);
      else 
      else
        fp->font_file_id = FPNULL;
        fp->font_file_id = FPNULL;
    }
    }
    BCLOSE(f);
    BCLOSE(f);
 Lines 4819-4831    Link Here 
     the resident fonts.  */
     the resident fonts.  */
  if (tfm_read_info(fontptr->n, &tfm_info)
  if (tfm_read_info(fontptr->n, &tfm_info)
      && tfm_info.family[0]
      && tfm_info.family[0]
      && strcmp((char *)tfm_info.family, "HPAUTOTFM") == 0) {
      && EQ((char *)tfm_info.family, "HPAUTOTFM")) {
    unsigned i;
    unsigned i;
    double factor = fontptr->s / (double)0x100000;
    double factor = fontptr->s / (double)0x100000;
    resident_count++;
    resident_count++;
    fontptr->resident_p = _TRUE;
    fontptr->resident_p = _TRUE;
    strcpy(fontptr->symbol_set, (char *)tfm_info.coding_scheme);
    strncpy(fontptr->symbol_set, (char *)tfm_info.coding_scheme, 39);
    fontptr->symbol_set[39] = '\0';
    fontptr->resid = tfm_info.typeface_id;
    fontptr->resid = tfm_info.typeface_id;
    fontptr->spacing = tfm_info.spacing;
    fontptr->spacing = tfm_info.spacing;
    fontptr->style = tfm_info.style;
    fontptr->style = tfm_info.style;
 Lines 4878-4884    Link Here 
    fontptr->resident_p = _FALSE;
    fontptr->resident_p = _FALSE;
    if (tfm_info.family[0]
    if (tfm_info.family[0]
        && strcmp((char *)tfm_info.family, "UNSPECIFIED") == 0) {
        && EQ((char *)tfm_info.family, "UNSPECIFIED")) {
      Warning("font family for %s is UNSPECIFIED; need to run dvicopy?",
      Warning("font family for %s is UNSPECIFIED; need to run dvicopy?",
              fontptr->n);
              fontptr->n);
      fontptr->font_file_id = NO_FILE;
      fontptr->font_file_id = NO_FILE;
 Lines 5005-5011    Link Here 
  GetBytes(dvifp, tfontptr->n, tfontptr->a + tfontptr->l);
  GetBytes(dvifp, tfontptr->n, tfontptr->a + tfontptr->l);
  tfontptr->n[tfontptr->a+tfontptr->l] = '\0';
  tfontptr->n[tfontptr->a+tfontptr->l] = '\0';
  tfontptr->font_mag = 
  tfontptr->font_mag =
    (long4)((ActualFactor((long4)(1000.0*tfontptr->s/(double)tfontptr->d+0.5))
    (long4)((ActualFactor((long4)(1000.0*tfontptr->s/(double)tfontptr->d+0.5))
             * ActualFactor(mag)
             * ActualFactor(mag)
#ifdef USEPXL
#ifdef USEPXL
 Lines 5031-5040    Link Here 
  if (tfontptr->resident_p)
  if (tfontptr->resident_p)
    return;
    return;
  if (!(resident_font_located)) {
  if (!(resident_font_located))
#endif
#endif
#ifdef KPATHSEA
    {
    {
      kpse_glyph_file_type font_ret;
      kpse_glyph_file_type font_ret;
      char *name;
      char *name;
 Lines 5042-5055    Link Here 
        = kpse_magstep_fix ((unsigned) (tfontptr->font_mag / 5.0 + .5),
        = kpse_magstep_fix ((unsigned) (tfontptr->font_mag / 5.0 + .5),
                            RESOLUTION, NULL);
                            RESOLUTION, NULL);
      tfontptr->font_mag = dpi * 5; /* save correct dpi */
      tfontptr->font_mag = dpi * 5; /* save correct dpi */
      
      name = kpse_find_pk (tfontptr->n, dpi, &font_ret);
      name = kpse_find_pk (tfontptr->n, dpi, &font_ret);
      if (name)
      if (name)
        {
        {
          font_found = _TRUE;
          font_found = _TRUE;
          strcpy (tfontptr->name, name);
          tfontptr->name = name;
          free (name);
          allocated_storage += strlen(name)+1;
          
          if (!FILESTRCASEEQ (tfontptr->n, font_ret.name)) {
          if (!FILESTRCASEEQ (tfontptr->n, font_ret.name)) {
              fprintf (stderr,
              fprintf (stderr,
                       "dvilj: Font %s not found, using %s at %d instead.\n",
                       "dvilj: Font %s not found, using %s at %d instead.\n",
 Lines 5071-5099    Link Here 
            tfontptr->n, dpi);
            tfontptr->n, dpi);
        }
        }
    }
    }
#else /* not KPATHSEA */
    if (!(findfile(PXLpath,
                   tfontptr->n,
                   tfontptr->font_mag,
                   tfontptr->name,
                   _FALSE,
                   0))) {
      Warning(tfontptr->name); /* contains error messsage */
      tfontptr->font_file_id = NO_FILE;
#ifdef __riscos
      MakeMetafontFile(PXLpath, tfontptr->n, tfontptr->font_mag);
#endif
    }
    else {
      font_found = _TRUE;
      if (G_verbose)
        fprintf(ERR_STREAM,"%d: using font <%s>\n", plusid, tfontptr->name);
    }
#endif /* not KPATHSEA */
#ifdef LJ_RESIDENT_FONTS
  }
#endif
  tfontptr->plusid = plusid;
  tfontptr->plusid = plusid;
  plusid++;
  plusid++;
 Lines 5107-5113    Link Here 
          HANDLE_MAX_FONTS);
          HANDLE_MAX_FONTS);
#endif
#endif
  if (tfontptr != pfontptr) {
  if (tfontptr != pfontptr) {
    if (font_found) 
    if (font_found)
      OpenFontFile();
      OpenFontFile();
    else
    else
      pxlfp = NO_FILE;
      pxlfp = NO_FILE;
 Lines 5146-5152    Link Here 
    if (t == PK_PRE) {
    if (t == PK_PRE) {
      unsigned char   temp_byte;
      unsigned char   temp_byte;
      temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
      temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
      if (temp_byte != PK_ID) 
      if (temp_byte != PK_ID)
        Fatal( "Wrong Version of pk file!  (%d should be 89)\n",
        Fatal( "Wrong Version of pk file!  (%d should be 89)\n",
               (int)temp_byte);
               (int)temp_byte);
      else
      else
 Lines 5163-5169    Link Here 
    tfontptr->magnification = NoSignExtend(pxlfp, 4);
    tfontptr->magnification = NoSignExtend(pxlfp, 4);
    tfontptr->designsize    = NoSignExtend(pxlfp, 4);
    tfontptr->designsize    = NoSignExtend(pxlfp, 4);
        
    if (tfontptr->id == id1001)
    if (tfontptr->id == id1001)
      FSEEK(pxlfp, (long)(NoSignExtend(pxlfp, 4) * 4), SEEK_SET);
      FSEEK(pxlfp, (long)(NoSignExtend(pxlfp, 4) * 4), SEEK_SET);
    else
    else
 Lines 5232-5238    Link Here 
    hppp = NoSignExtend(pxlfp, 4);
    hppp = NoSignExtend(pxlfp, 4);
    vppp = NoSignExtend(pxlfp, 4);
    vppp = NoSignExtend(pxlfp, 4);
    if (hppp != vppp)
    if (hppp != vppp)
      Warning("aspect ratio is %ld:%ld (should be 1:1)!", 
      Warning("aspect ratio is %ld:%ld (should be 1:1)!",
              (long)hppp, (long)vppp);
              (long)hppp, (long)vppp);
    tfontptr->magnification = (long4)(hppp * 72.27 * 5 / 65536l + 0.5);
    tfontptr->magnification = (long4)(hppp * 72.27 * 5 / 65536l + 0.5);
 Lines 5515-5521    Link Here 
{
{
  int     a, l;
  int     a, l;
  char    n[STRSIZE];
  char    n[STRSIZE];
  
  (void) NoSignExtend(dvifp, 4);
  (void) NoSignExtend(dvifp, 4);
  (void) NoSignExtend(dvifp, 4);
  (void) NoSignExtend(dvifp, 4);
  (void) NoSignExtend(dvifp, 4);
  (void) NoSignExtend(dvifp, 4);
 Lines 5524-5530    Link Here 
  GetBytes(dvifp, n, a + l);
  GetBytes(dvifp, n, a + l);
}
}
    
/*------------------------ end dvifont.c -------------------------------*/
/*------------------------ end dvifont.c -------------------------------*/
 Lines 5598-5604    Link Here 
#endif
#endif
  if ( G_nowarn || G_quiet )
  if ( G_nowarn || G_quiet )
    return;
    return;
  
  fprintf(ERR_STREAM, "%s: warning: ", G_progname);
  fprintf(ERR_STREAM, "%s: warning: ", G_progname);
  vfprintf(ERR_STREAM, fmt, args);
  vfprintf(ERR_STREAM, fmt, args);
  fprintf(ERR_STREAM, "\n");
  fprintf(ERR_STREAM, "\n");
(-) texlive-bin-2007.orig/build/source/texk/dviljk/dvi2xx.h (-11 / +19 lines)
 Lines 10-17    Link Here 
#ifdef KPATHSEA
#ifdef KPATHSEA
#include <kpathsea/config.h>
#include <kpathsea/config.h>
#include <kpathsea/c-std.h>
#include <kpathsea/c-limits.h>
#include <kpathsea/c-limits.h>
#include <kpathsea/c-memstr.h>
#include <kpathsea/magstep.h>
#include <kpathsea/magstep.h>
#include <kpathsea/proginit.h>
#include <kpathsea/proginit.h>
#include <kpathsea/progname.h>
#include <kpathsea/progname.h>
 Lines 24-29    Link Here 
#include <string.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef  unix
#ifdef  unix
#include <limits.h>
#include <limits.h>
#endif
#endif
 Lines 41-49    Link Here 
#ifdef MSC5
#ifdef MSC5
#include <dos.h>     /* only for binaryopen on device  */
#include <dos.h>     /* only for binaryopen on device  */
#endif
#endif
#if defined (unix) && !defined (KPATHSEA)
#include <limits.h>
#endif
#include "config.h"
#include "config.h"
 Lines 116-121    Link Here 
#define  HUGE_SIZE  (unsigned char) 2
#define  HUGE_SIZE  (unsigned char) 2
#define  HUGE_CHAR_PATTERN 32767l
#define  HUGE_CHAR_PATTERN 32767l
#define  BYTES_PER_PIXEL_LINE 500    /* max number of bytes per pixel line */
#define  BYTES_PER_PIXEL_LINE 500    /* max number of bytes per pixel line */
#define  MAX_SPECIAL_DEFPOINTS 80    /* max number of defpoint specials */
#define PK_POST 245
#define PK_POST 245
 Lines 281-287    Link Here 
#define VisChar(c) (unsigned char)(c)
#define VisChar(c) (unsigned char)(c)
#endif
#endif
#define GetBytes(fp,buf,n) read_multi(buf,1,n,fp) /* used to be a function */
/* Used to be a function. buf is always an array, never a pointer.
   Without that invariant, we would have to introduce full dynamic
   memory management in this driver -- probably it would be easier to
   write a new one. [27 Jun 07 -js] */
#define GetBytes(fp,buf,n) \
    ( sizeof(buf) != sizeof(void *) && sizeof(buf) > n ? \
        read_multi(buf, 1, n, fp) \
      : Fatal("Try to read %d bytes in an array of size %d", n, sizeof(buf)) )
/**********************************************************************/
/**********************************************************************/
 Lines 307-312    Link Here 
int     sscanf();
int     sscanf();
int     strcmp();
int     strcmp();
char   *strcpy();
char   *strcpy();
char   *strncpy();
#   ifdef MSC5
#   ifdef MSC5
unsigned int strlen();
unsigned int strlen();
#   endif
#   endif
 Lines 393-399    Link Here 
    char n[STRSIZE];          /* FNT_DEF command parameters                */
    char n[STRSIZE];          /* FNT_DEF command parameters                */
    long4    font_mag;         /* computed from FNT_DEF s and d parameters  */
    long4    font_mag;         /* computed from FNT_DEF s and d parameters  */
    /*char psname[STRSIZE];*/ /* PostScript name of the font               */
    /*char psname[STRSIZE];*/ /* PostScript name of the font               */
    char    name[STRSIZE];    /* full name of PXL file                     */
    char    *name;	       /* full name of PXL file                     */
    FILEPTR font_file_id;      /* file identifier (NO_FILE if none)         */
    FILEPTR font_file_id;      /* file identifier (NO_FILE if none)         */
#ifdef USEPXL
#ifdef USEPXL
    long4    magnification;    /* magnification read from PXL file          */
    long4    magnification;    /* magnification read from PXL file          */
 Lines 487-494    Link Here 
long4   NoSignExtend DVIPROTO((FILEPTR, int));
long4   NoSignExtend DVIPROTO((FILEPTR, int));
void    OpenFontFile DVIPROTO((void));
void    OpenFontFile DVIPROTO((void));
long4   PixRound DVIPROTO((long4, long4));
long4   PixRound DVIPROTO((long4, long4));
void    PkRaster DVIPROTO((struct char_entry *, int)); 
void    PkRaster DVIPROTO((struct char_entry *, int));
void    RasterLine DVIPROTO((struct char_entry *, unsigned int, 
void    RasterLine DVIPROTO((struct char_entry *, unsigned int,
			     unsigned int, unsigned char *));
			     unsigned int, unsigned char *));
void    RasterChar DVIPROTO((struct char_entry *));
void    RasterChar DVIPROTO((struct char_entry *));
void    ReadFontDef DVIPROTO((long4));
void    ReadFontDef DVIPROTO((long4));
 Lines 534-544    Link Here 
#ifndef KPATHSEA
#ifndef KPATHSEA
char   *PXLpath = FONTAREA;
char   *PXLpath = FONTAREA;
#endif
#endif
char    G_progname[STRSIZE];     /* program name                        */
char   *G_progname;		 /* program name                        */
char    filename[STRSIZE];       /* DVI file name                       */
char   *filename;	         /* DVI file name                       */
char    rootname[STRSIZE];       /* DVI filename without extension      */
char   *rootname;		 /* DVI filename without extension      */
char   *HeaderFileName = "";     /* file name & path of Headerfile      */
char   *HeaderFileName = "";     /* file name & path of Headerfile      */
char   *EmitFileName = "";       /* file name & path for output         */
char   *EmitFileName = "";       /* file name & path for output         */
char    tmp_dir[STRSIZE] = "";	 /* temporary directory for auxilliary files */
#ifdef IBM3812
#ifdef IBM3812
bool    FirstAlternate = _FALSE; /* first page from alternate casette ?   */
bool    FirstAlternate = _FALSE; /* first page from alternate casette ?   */
#endif
#endif