summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-25 10:36:51 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-25 10:36:51 +0000
commit7b365448b54cde46c08ffe17cc4d596a3932b282 (patch)
treed2578540b4722b135b0df2e2c9db4ca762f57c82 /Build
parente8bfdd907996c5c4ad9475c4dd87cab97336e1b4 (diff)
dvipdfmx: Patch from Tsuchimura Nobuyuki to speed up inclusion of eps figures
git-svn-id: svn://tug.org/texlive/trunk@29495 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/dvipdfmx/ChangeLog9
-rw-r--r--Build/source/texk/dvipdfmx/data/dvipdfmx.cfg5
-rw-r--r--Build/source/texk/dvipdfmx/src/dpxfile.c145
-rw-r--r--Build/source/texk/dvipdfmx/src/dpxfile.h5
-rw-r--r--Build/source/texk/dvipdfmx/src/dvi.c5
-rw-r--r--Build/source/texk/dvipdfmx/src/dvicodes.h2
-rw-r--r--Build/source/texk/dvipdfmx/src/dvipdfmx.c14
-rw-r--r--Build/source/texk/dvipdfmx/src/pdfximage.c26
-rw-r--r--Build/source/texk/dvipdfmx/src/vf.c2
9 files changed, 175 insertions, 38 deletions
diff --git a/Build/source/texk/dvipdfmx/ChangeLog b/Build/source/texk/dvipdfmx/ChangeLog
index 7868f303b4b..8331141a508 100644
--- a/Build/source/texk/dvipdfmx/ChangeLog
+++ b/Build/source/texk/dvipdfmx/ChangeLog
@@ -1,3 +1,12 @@
+2013-03-25 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Patch from Tsuchimura Nobuyuki <tutimura@nn.iij4u.or.jp> to
+ speed up inclusion of eps figures.
+ * data/dvipdfmx.cfg, src/dpxfile.[ch], src/dvi.c,
+ src/dvicodes.h, src/dvipdfmx.c, src/pdfximage.c, src/vf.c:
+ Applied with small modifications to avoid compiler warnings,
+ adapted for WIN32 by Akira Kakuto.
+
2013-03-24 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* src/dpxfile.c: Change dpx_create_temp_file() because tmpnam()
diff --git a/Build/source/texk/dvipdfmx/data/dvipdfmx.cfg b/Build/source/texk/dvipdfmx/data/dvipdfmx.cfg
index 53c96b8e3cc..fed46401d5a 100644
--- a/Build/source/texk/dvipdfmx/data/dvipdfmx.cfg
+++ b/Build/source/texk/dvipdfmx/data/dvipdfmx.cfg
@@ -184,6 +184,11 @@ D "rungs -q -dNOPAUSE -dBATCH -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityL
%d 5
+%% Image cache life in hours
+%% 0 means erase all old images and leave new images
+%% -1 means erase all old images and also erase new images
+%I 48
+
%% Font Map Files
%%
%% teTeX 2.x and TeX Live using updmap (pdfTeX format)
diff --git a/Build/source/texk/dvipdfmx/src/dpxfile.c b/Build/source/texk/dvipdfmx/src/dpxfile.c
index bb827489649..dcb520577d2 100644
--- a/Build/source/texk/dvipdfmx/src/dpxfile.c
+++ b/Build/source/texk/dvipdfmx/src/dpxfile.c
@@ -26,6 +26,12 @@
#include "config.h"
#endif
+#ifdef _MSC_VER
+#include <kpathsea/dirent.h>
+#endif
+
+#include <time.h>
+
#include "system.h"
#include "error.h"
#include "mem.h"
@@ -34,6 +40,8 @@
#include "mfileio.h"
#include "dpxfile.h"
+#include "dpxcrypt.h"
+#define MAX_KEY_LEN 16
#include <kpathsea/lib.h>
#include <string.h>
@@ -53,6 +61,7 @@
#endif
static int verbose = 0;
+int keep_cache = false;
void
dpx_file_set_verbose (void)
@@ -717,11 +726,37 @@ dpx_find_dfont_file (const char *filename)
return fqpn;
}
+static const char *
+dpx_get_tmpdir (void)
+{
+# ifdef WIN32
+# define __TMPDIR "."
+# else /* WIN32 */
+# define __TMPDIR "/tmp"
+#endif /* WIN32 */
+ const char *_tmpd;
+
+# ifdef HAVE_GETENV
+ _tmpd = getenv("TMPDIR");
+# ifdef WIN32
+ if (!_tmpd)
+ _tmpd = getenv("TMP");
+ if (!_tmpd)
+ _tmpd = getenv("TEMP");
+# endif /* WIN32 */
+ if (!_tmpd)
+ _tmpd = __TMPDIR;
+# else /* HAVE_GETENV */
+ _tmpd = __TMPDIR;
+# endif /* HAVE_GETENV */
+ return _tmpd;
+}
#ifdef HAVE_MKSTEMP
# include <stdlib.h>
#endif
+#if 0 /* Not used */
char *
dpx_create_temp_file (void)
{
@@ -733,18 +768,11 @@ dpx_create_temp_file (void)
miktex_create_temp_file_name(tmp); /* FIXME_FIXME */
}
#elif defined(HAVE_MKSTEMP)
-# define __TMPDIR "/tmp"
# define TEMPLATE "/dvipdfmx.XXXXXX"
{
const char *_tmpd;
int _fd = -1;
-# ifdef HAVE_GETENV
- _tmpd = getenv("TMPDIR");
- if (!_tmpd)
- _tmpd = __TMPDIR;
-# else
- _tmpd = __TMPDIR;
-# endif /* HAVE_GETENV */
+ _tmpd = dpx_get_tmpdir();
tmp = NEW(strlen(_tmpd) + strlen(TEMPLATE) + 1, char);
strcpy(tmp, _tmpd);
strcat(tmp, TEMPLATE);
@@ -763,21 +791,10 @@ dpx_create_temp_file (void)
#else /* use _tempnam or tmpnam */
{
# ifdef WIN32
-# define __TMPDIR "."
const char *_tmpd;
char *p;
-# ifdef HAVE_GETENV
- _tmpd = getenv ("TMPDIR");
- if (!_tmpd)
- _tmpd = getenv ("TMP");
- if (!_tmpd)
- _tmpd = getenv ("TEMP");
- if (!_tmpd)
- _tmpd = __TMPDIR;
-# else /* HAVE_GETENV */
- _tmpd = __TMPDIR;
-# endif /* HAVE_GETENV */
- tmp = _tempnam (_tmpd, "dpxtmp.");
+ _tmpd = dpx_get_tmpdir();
+ tmp = _tempnam (_tmpd, "dvipdfmx.");
for (p = tmp; *p; p++) {
if (IS_KANJI (p))
p++;
@@ -795,13 +812,95 @@ dpx_create_temp_file (void)
return tmp;
}
+#endif /* 0 */
+
+char *
+dpx_create_fix_temp_file (char *filename)
+{
+#define PREFIX "dvipdfmx."
+ static const char *dir = NULL;
+ static char *cwd = NULL;
+ char *ret, *s;
+ int i;
+ MD5_CONTEXT state;
+ unsigned char digest[MAX_KEY_LEN];
+#ifdef WIN32
+ char *p;
+#endif
+
+ if (!dir) {
+ dir = dpx_get_tmpdir();
+ cwd = xgetcwd();
+ }
+
+ MD5_init(&state);
+ MD5_write(&state, (unsigned char *)cwd, strlen(cwd));
+ MD5_write(&state, (unsigned char *)filename, strlen(filename));
+ MD5_final(digest, &state);
+
+ ret = NEW(strlen(dir)+1+strlen(PREFIX)+MAX_KEY_LEN*2 + 1, char);
+ sprintf(ret, "%s/%s", dir, PREFIX);
+ s = ret + strlen(ret);
+ for (i=0; i<MAX_KEY_LEN; i++) {
+ sprintf(s, "%02x", digest[i]);
+ s += 2;
+ }
+#ifdef WIN32
+ for (p = ret; *p; p++) {
+ if (IS_KANJI (p))
+ p++;
+ else if (*p == '\\')
+ *p = '/';
+ }
+#endif
+ /* printf("dpx_create_fix_temp_file: %s\n", ret); */
+ return ret;
+}
+
+static int
+dpx_clear_cache_filter (const struct dirent *ent) {
+ int plen = strlen(PREFIX);
+ if (strlen(ent->d_name) != plen + MAX_KEY_LEN * 2) return 0;
+#ifdef WIN32
+ return strncasecmp(ent->d_name, PREFIX, plen) == 0;
+#else
+ return strncmp(ent->d_name, PREFIX, plen) == 0;
+#endif
+}
+
+void
+dpx_delete_old_cache (int life)
+{
+ const char *dir = dpx_get_tmpdir();
+ char *pathname = NEW(strlen(dir)+1+strlen(PREFIX)+MAX_KEY_LEN*2 + 1, char);
+ DIR *dp;
+ struct dirent *de;
+ time_t limit = time(NULL) - life * 60 * 60;
+
+ if (life >= 0) keep_cache = true;
+ if ((dp = opendir(dir)) != NULL) {
+ while((de = readdir(dp)) != NULL) {
+ if (dpx_clear_cache_filter(de)) {
+ struct stat sb;
+ sprintf(pathname, "%s/%s", dir, de->d_name);
+ stat(pathname, &sb);
+ if (sb.st_mtime < limit) {
+ remove(pathname);
+ /* printf("remove: %s\n", pathname); */
+ }
+ }
+ }
+ closedir(dp);
+ }
+ RELEASE(pathname);
+}
void
-dpx_delete_temp_file (char *tmp)
+dpx_delete_temp_file (char *tmp, int force)
{
if (!tmp)
return;
- remove (tmp);
+ if (force || !keep_cache) remove (tmp);
RELEASE(tmp);
return;
diff --git a/Build/source/texk/dvipdfmx/src/dpxfile.h b/Build/source/texk/dvipdfmx/src/dpxfile.h
index b7e24d16f92..53b9fc7855e 100644
--- a/Build/source/texk/dvipdfmx/src/dpxfile.h
+++ b/Build/source/texk/dvipdfmx/src/dpxfile.h
@@ -57,6 +57,9 @@ extern int dpx_file_apply_filter (const char *cmdtmpl,
const char *input, const char *output,
unsigned char version);
extern char *dpx_create_temp_file (void);
-extern void dpx_delete_temp_file (char *tmp); /* tmp freed here */
+extern char *dpx_create_fix_temp_file (char *filename);
+extern void dpx_delete_old_cache (int life);
+extern void dpx_delete_temp_file (char *tmp, int force); /* tmp freed here */
+extern int keep_cache;
#endif /* _DPXFILE_H_ */
diff --git a/Build/source/texk/dvipdfmx/src/dvi.c b/Build/source/texk/dvipdfmx/src/dvi.c
index 38f48dccd42..894430284a0 100644
--- a/Build/source/texk/dvipdfmx/src/dvi.c
+++ b/Build/source/texk/dvipdfmx/src/dvi.c
@@ -1563,7 +1563,7 @@ dvi_do_page (unsigned n,
case FNT_DEF4: do_fntdef4(); break;
/* pTeX extension */
- case DIR:
+ case PTEXDIR:
do_dir();
break;
@@ -1868,7 +1868,6 @@ scan_special (double *wd, double *ht, double *xo, double *yo, char *lm,
skip_white(&p, endptr);
}
}
- RELEASE(q);
}
return error;
@@ -1952,7 +1951,7 @@ dvi_scan_specials (unsigned page_no,
case FNT_DEF3: do_fntdef3(); break;
case FNT_DEF4: do_fntdef4(); break;
- case DIR:
+ case PTEXDIR:
get_unsigned_byte(fp);
break;
diff --git a/Build/source/texk/dvipdfmx/src/dvicodes.h b/Build/source/texk/dvipdfmx/src/dvicodes.h
index 4de92c5bd0c..964da579b15 100644
--- a/Build/source/texk/dvipdfmx/src/dvicodes.h
+++ b/Build/source/texk/dvipdfmx/src/dvicodes.h
@@ -119,7 +119,7 @@
Version byte (same as preamble)
Padded by four or more 223's to the end of the file. */
#define PADDING 223
-#define DIR 255 /* Ascii pTeX DIR command */
+#define PTEXDIR 255 /* Ascii pTeX DIR command */
#ifdef XETEX
#define XDV_PIC_FILE 251 /* include graphic or PDF file */
diff --git a/Build/source/texk/dvipdfmx/src/dvipdfmx.c b/Build/source/texk/dvipdfmx/src/dvipdfmx.c
index 128ffd1b5b9..7dbd7de9769 100644
--- a/Build/source/texk/dvipdfmx/src/dvipdfmx.c
+++ b/Build/source/texk/dvipdfmx/src/dvipdfmx.c
@@ -86,6 +86,11 @@ static int really_quiet = 0;
*/
static int pdfdecimaldigits = 2;
+/* Image cache life in hours */
+/* 0 means erase all old images and leave new images */
+/* -1 means erase all old images and also erase new images */
+static int image_cache_life = 48;
+
/* Encryption */
static int do_encryption = 0;
static unsigned key_bits = 40;
@@ -181,6 +186,9 @@ show_usage (void)
fprintf(stdout, "\t\tAnd negative values replace old values.\n");
fprintf(stdout, "-D template\tPS->PDF conversion command line template [none]\n");
fprintf(stdout, "-E \t\tEnable DVIPDFM emulation mode\n");
+ fprintf(stdout, "-I number\tImage cache life in hours [48]\n");
+ fprintf(stdout, " \t 0: erase all old images and leave new images\n");
+ fprintf(stdout, " \t-1: erase all old images and also erase new images\n");
fprintf(stdout, "-K number\tEncryption key length [40]\n");
fprintf(stdout, "-O number\tSet maximum depth of open bookmark items [0]\n");
fprintf(stdout, "-P number\tSet permission flags for PDF encryption [0x003C]\n");
@@ -529,6 +537,11 @@ do_args (int argc, char *argv[])
POP_ARG();
}
break;
+ case 'I':
+ CHECK_ARG(1, "image cache life in hours");
+ image_cache_life = (unsigned) atoi(argv[1]);
+ POP_ARG();
+ break;
case 'S':
do_encryption = 1;
break;
@@ -898,6 +911,7 @@ main (int argc, char *argv[])
kpse_set_program_enabled(kpse_pk_format, true, kpse_src_texmf_cnf);
#endif
pdf_font_set_dpi(font_dpi);
+ dpx_delete_old_cache(image_cache_life);
if (!dvi_filename) {
WARN("No dvi filename specified.");
diff --git a/Build/source/texk/dvipdfmx/src/pdfximage.c b/Build/source/texk/dvipdfmx/src/pdfximage.c
index 779942839d9..1c18ea2ff9c 100644
--- a/Build/source/texk/dvipdfmx/src/pdfximage.c
+++ b/Build/source/texk/dvipdfmx/src/pdfximage.c
@@ -193,9 +193,9 @@ pdf_close_images (void)
* We also use this to convert a PS file only once if multiple
* pages are imported from that file.
*/
- if (_opts.verbose > 1)
+ if (_opts.verbose > 1 && !keep_cache)
MESG("pdf_image>> deleting temporary file \"%s\"\n", I->filename);
- dpx_delete_temp_file(I->filename); /* temporary filename freed here */
+ dpx_delete_temp_file(I->filename, false); /* temporary filename freed here */
I->filename = NULL;
}
pdf_clean_ximage_struct(I);
@@ -869,6 +869,7 @@ ps_include_page (pdf_ximage *ximage)
char *temp;
FILE *fp;
int error = 0;
+ struct stat stat_o, stat_t;
if (!distiller_template) {
WARN("No image converter available for converting file \"%s\" to PDF format.", filename);
@@ -876,7 +877,7 @@ ps_include_page (pdf_ximage *ximage)
return -1;
}
- temp = dpx_create_temp_file();
+ temp = dpx_create_fix_temp_file(filename);
if (!temp) {
WARN("Failed to create temporary file for image conversion: %s", filename);
return -1;
@@ -889,18 +890,25 @@ ps_include_page (pdf_ximage *ximage)
MESG("pdf_image>> ...");
}
- error = dpx_file_apply_filter(distiller_template, filename, temp,
+ if (stat(temp, &stat_t)==0 && stat(filename, &stat_o)==0
+ && stat_t.st_mtime > stat_o.st_mtime) {
+ /* cache exist */
+ /*printf("\nLast file modification: %s", ctime(&stat_o.st_mtime));
+ printf("Last file modification: %s", ctime(&stat_t.st_mtime));*/
+ } else {
+ error = dpx_file_apply_filter(distiller_template, filename, temp,
(unsigned char) pdf_get_version());
- if (error) {
- WARN("Image format conversion for \"%s\" failed...", filename);
- dpx_delete_temp_file(temp);
- return error;
+ if (error) {
+ WARN("Image format conversion for \"%s\" failed...", filename);
+ dpx_delete_temp_file(temp, true);
+ return error;
+ }
}
fp = MFOPEN(temp, FOPEN_RBIN_MODE);
if (!fp) {
WARN("Could not open conversion result \"%s\" for image \"%s\". Why?", temp, filename);
- dpx_delete_temp_file(temp);
+ dpx_delete_temp_file(temp, true);
return -1;
}
pdf_set_ximage_tempfile(ximage, temp);
diff --git a/Build/source/texk/dvipdfmx/src/vf.c b/Build/source/texk/dvipdfmx/src/vf.c
index cbb53683ce7..1d7f9e753f4 100644
--- a/Build/source/texk/dvipdfmx/src/vf.c
+++ b/Build/source/texk/dvipdfmx/src/vf.c
@@ -1002,7 +1002,7 @@ void vf_set_char(SIGNED_QUAD ch, int vf_font)
case XXX4:
vf_xxx4(&start, end);
break;
- case DIR:
+ case PTEXDIR:
vf_dir(&start, end);
break;
default: