View | Details | Raw Unified
Collapse All | Expand All

(-) work/texk/dviljk/ChangeLog (+39 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
(-) work/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
(-) work/texk/dviljk/config.h (-6 / +22 lines)
 Lines 216-227   typedef SCHAR_TYPE signed_char; 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   typedef FILE *FILEPTR; 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
(-) work/texk/dviljk/configure (+56 lines)
 Lines 1283-1288   EOF 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
(-) work/texk/dviljk/configure.in (+2 lines)
 Lines 14-18   dnl These tests prevent reliable cross-c 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
(-) work/texk/dviljk/dvi2xx.c (-193 / +238 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 173-179   char *argv[]; 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 2968-2975   char *argv[]; 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   char *argv[]; 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 3328-3335   Primary author of Dvi2xx: Gustaf Neumann 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   Primary author of Dvi2xx: Gustaf Neumann 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
        curname = (char *) xmalloc(strlen(tcp)+5);  /* + space for ".dvi" */
        (void) strcpy(curname, tcp);
        (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   Primary author of Dvi2xx: Gustaf Neumann 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   Primary author of Dvi2xx: Gustaf Neumann 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 3698-3703   bool PFlag; Link Here 
#endif
#endif
  }
  }
  CloseFiles();
  CloseFiles();
  if ( tmp_dir[0] != '\0' )
    rmdir (tmp_dir);			/* ignore errors */
  exit(G_errenc);
  exit(G_errenc);
}
}
 Lines 3895-3916   char *str; 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
 Lines 3924-3964   int n; Link Here 
    /* 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 3978-4000   int n; Link Here 
        }
        }
#endif
#endif
        else
        else
#ifdef KPATHSEA
           if (!kpse_tex_hush ("special"))
#endif
          Warning( "Invalid orientation (%d)given; ignored.", k.v.i);
          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 4011-4029   int n; 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
              if (!kpse_tex_hush ("special"))
#endif
          Warning("invalid point definition\n");
          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 4044-4052   int n; Link Here 
          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;
 Lines 4055-4063   int n; Link Here 
          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;
 Lines 4066-4140   int n; 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"))
#endif
        Warning("Can't handle %s=%s command; ignored.", k.Key, k.Val);
        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);
        char *pcl_file = tmpnam(NULL);  
        FILEPTR scalef;
        FILEPTR scalef;
        if ( (scalef = BOUTOPEN(scale_file)) == FPNULL ) {
        if ( urx == 0 || ury == 0 || rwi == 0 ) {
          Warning("Unable to open file %s for writing", scale_file );
  	/* Since dvips' psfile special has a different syntax, this might
          return;
  	   well be one of those specials, i.e., a non-dviljk special. Then
        }
  	   the Warning should be suppressable. */
        fprintf(scalef, "%.2f %.2f scale\n%d %d translate\n",  
  	if ( !kpse_tex_hush ("special") )
                300.0/scale_factor, 300.0/scale_factor,
  	  Warning ("Ignoring psfile special without urx, ury and rwi attributes");
                0, adjusted_height == height ? 0 : ury);
	free (include_file);
        BCLOSE( scalef );
	return;
      }
      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";
        sprintf(cmd,"%s -q -dSIMPLE -dSAFER -dNOPAUSE -sDEVICE=%s -sOutputFile=%s %s %s showpage.ps -c quit",
		gs_path, printer, pcl_file, scale_file, psfile);
#else
#else
        sprintf(cmd,"gs -q -dSIMPLE -dSAFER -dNOPAUSE -sDEVICE=%s -sOutputFile=%s %s %s showpage.ps -c quit",
      gs_cmd = "gs";
                printer, pcl_file, scale_file, psfile);
#endif
#endif
      if ( strlen(cmd_format)-10 + strlen(gs_cmd) + strlen(printer) +
	       strlen(pcl_file) + strlen(scale_file) + strlen(include_file) +1 >
	   sizeof(cmd) ) {
	Warning ("Ghostscript command for %s would be too long, skipping special", include_file);
	free (include_file);
	unlink(scale_file);		/* ignore errors */
	unlink(pcl_file);
	return;
      }
      sprintf(cmd, cmd_format,
	      gs_cmd, printer, pcl_file, scale_file, include_file);
#ifdef DEBUGGS   
#ifdef DEBUGGS   
        fprintf(stderr,
        fprintf(stderr,
          "PS-file '%s' w=%d, h=%d, urx=%d, ury=%d, llx=%d, lly=%d, rwi=%d\n",
          "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);
	      include_file, urx - llx, height, urx,ury,llx,lly, rwi);
        fprintf(stderr,"%s\n",cmd);
        fprintf(stderr,"%s\n",cmd);
#endif
#endif
        if (system(cmd)) {
        if (system(cmd)) {
 Lines 4158-4168   int n; Link Here 
#endif
#endif
          CopyHPFile( pcl_file );
          CopyHPFile( pcl_file );
          /* unlink(pcl_file); */
          /* unlink(scale_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   int n; 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   char *str; 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 4819-4831   struct font_entry *fontptr; 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   struct font_entry *fontptr; 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 5031-5040   printf("[%ld]=%lf * %lf * %lf + 0.5 = %l 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 5047-5055   printf("[%ld]=%lf * %lf * %lf + 0.5 = %l Link Here 
      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   printf("[%ld]=%lf * %lf * %lf + 0.5 = %l 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++;
(-) work/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   char *MFMODE = MFMODE600; 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   int printf(); 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   struct font_entry { /* font entry */ 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   void LoadAChar DVIPROTO((long4, regis 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   bool LastPageSpecified = _FALSE; 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