Back to index

texmacs  1.0.7.15
Defines | Functions | Variables
dpxfile.c File Reference
#include <unistd.h>
#include "system.h"
#include "error.h"
#include "mem.h"
#include "dpxutil.h"
#include "mfileio.h"
#include "dpxfile.h"

Go to the source code of this file.

Defines

#define HAVE_SYSTEM   1
#define need(s, l, m, n)

Functions

void dpx_file_set_verbose (void)
static int qcheck_filetype (const char *fqpn, int type)
static char * ensuresuffix (const char *basename, const char *sfx)
static char * dpx_find__app__xyz (const char *filename, const char *suffix, int is_text)
static char * dpx_foolsearch (const char *foolname, const char *filename, int is_text)
static char * dpx_find_fontmap_file (const char *filename)
static char * dpx_find_agl_file (const char *filename)
static char * dpx_find_sfd_file (const char *filename)
static char * dpx_find_cmap_file (const char *filename)
static char * dpx_find_enc_file (const char *filename)
static char * dpx_find_opentype_file (const char *filename)
static char * dpx_find_truetype_file (const char *filename)
static char * dpx_find_type1_file (const char *filename)
static char * dpx_find_iccp_file (const char *filename)
static char * dpx_find_dfont_file (const char *filename)
FILE * dpx_open_file (const char *filename, int type)
char * dpx_create_temp_file (void)
void dpx_delete_temp_file (char *tmp)
int dpx_file_apply_filter (const char *cmdtmpl, const char *input, const char *output, unsigned short version)
static int istruetype (FILE *fp)
static int isopentype (FILE *fp)
static int ist1binary (FILE *fp)
static int ispscmap (FILE *fp)
static int isdfont (FILE *fp)

Variables

static int verbose = 0
static char _sbuf [128]

Define Documentation

#define HAVE_SYSTEM   1

Definition at line 738 of file dpxfile.c.

#define need (   s,
  l,
  m,
  n 
)
Value:
if ((l) + (n) >= (m)) { \
  (m) += (n) + 128; \
  (s)  = RENEW((s), (m), char); \
}

Function Documentation

char* dpx_create_temp_file ( void  )

Definition at line 678 of file dpxfile.c.

{
  char  *tmp = NULL;

#if   defined(MIKTEX)
  {
    tmp = NEW(_MAX_PATH + 1, char);
    miktex_create_temp_file_name(tmp); /* FIXME_FIXME */
  }
#elif defined(HAVE_MKSTEMP)
#  define __TMPDIR     "/tmp"
#  define TEMPLATE     "/dvipdfmx.XXXXXX"
  {
    char *_tmpd;
    int   _fd = -1;
#  ifdef  HAVE_GETENV
    _tmpd = getenv("TMPDIR");
    if (!_tmpd)
      _tmpd = (char *) __TMPDIR;
#  else
    _tmpd = (char *) __TMPDIR;
#  endif /* HAVE_GETENV */
    tmp = NEW(strlen(_tmpd) + strlen(TEMPLATE) + 1, char);
    strcpy(tmp, _tmpd);
    strcat(tmp, TEMPLATE);
    _fd  = mkstemp(tmp);
    if (_fd != -1)
#ifdef WIN32
      _close(_fd);
#else
      close(_fd);
#endif /* WIN32 */
    else {
      RELEASE(tmp);
      tmp = NULL;
    }
  }
#else /* use tmpnam */
  {
    char *_tmpa = NEW(L_tmpnam + 1, char);
    tmp = tmpnam(_tmpa);
    if (!tmp)
      RELEASE(_tmpa);
  }
#endif /* MIKTEX */

  return  tmp;
}

Here is the caller graph for this function:

void dpx_delete_temp_file ( char *  tmp)

Definition at line 728 of file dpxfile.c.

{
  if (!tmp)
    return;
  remove (tmp);
  RELEASE(tmp);

  return;
}

Here is the caller graph for this function:

int dpx_file_apply_filter ( const char *  cmdtmpl,
const char *  input,
const char *  output,
unsigned short  version 
)

Definition at line 748 of file dpxfile.c.

{
  char   *cmd = NULL;
  char   *p, *q;
  size_t  n, size;
  int     error = 0;

  if (!cmdtmpl)
    return -1;
  else if (!input || !output)
    return -1;

  size = strlen(cmdtmpl) + strlen(input) + strlen(output) + 3;
  cmd  = NEW(size, char);
  memset(cmd, 0, size);
  for (n = 0, p = (char *) cmdtmpl; *p != 0; p++) {
#define need(s,l,m,n) \
if ((l) + (n) >= (m)) { \
  (m) += (n) + 128; \
  (s)  = RENEW((s), (m), char); \
}
    if (p[0] == '%') {
      p++;
      switch (p[0]) {
      case 'o': /* Output file name */
        need(cmd, n, size, strlen(output));
        strcpy(cmd + n, output); n += strlen(output);
        break;
      case 'i': /* Input filename */
        need(cmd, n, size, strlen(input));
        strcpy(cmd + n, input);  n += strlen(input);
        break;
      case 'b':
        need(cmd, n, size, strlen(input));
        q = strrchr(input, '.'); /* wrong */
        if (q) {
          memcpy(cmd + n, input, (int) (q - input));
          n += (int) (q - input);
        } else {
          strcpy(cmd + n, input); n += strlen(input);
        }
      case  'v': /* Version number, e.g. 1.4 */ {
       char buf[16];
       sprintf(buf, "1.%hu", version);
       need(cmd, n, size, strlen(buf));
       strcpy(cmd + n, buf);  n += strlen(buf);
       break;
      }
      case  0:
        break;
      case '%':
        need(cmd, n, size, 1);
        cmd[n] = '%'; n++;
        break;
      }
    } else {
      need(cmd, n, size, 1);
      cmd[n] = p[0]; n++;
    }
  }
  need(cmd, n, size, 1);
  cmd[n] = '\0';
  if (strlen(cmd) == 0) {
    RELEASE(cmd);
    return -1;
  }

  error = system(cmd);
  if (error)
    WARN("Filtering file via command -->%s<-- failed.", cmd);
  RELEASE(cmd);

  return  error;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dpx_file_set_verbose ( void  )

Definition at line 43 of file dpxfile.c.

{
  verbose++;
}
static char* dpx_find__app__xyz ( const char *  filename,
const char *  suffix,
int  is_text 
) [static]

Definition at line 222 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;
  char  *q;

  q    = ensuresuffix(filename, suffix);
  fqpn = kpse_find_file(q,
                         (is_text ?
                            kpse_program_text_format : kpse_program_binary_format), 0);
  if (!fqpn && strcmp(q, filename))
    fqpn = kpse_find_file(filename,
                           (is_text ?
                              kpse_program_text_format : kpse_program_binary_format), 0);   
  RELEASE(q);

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_agl_file ( const char *  filename) [static]

Definition at line 391 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;
  char  *q;

  q = ensuresuffix(filename, ".txt");
#ifdef  MIKTEX
  fqpn = dpx_find__app__xyz(q, ".txt", 1);
#else /* !MIKTEX */
  fqpn = kpse_find_file(q, kpse_fontmap_format, 0);
  if (!fqpn) {
    fqpn = dpx_find__app__xyz(q, ".txt", 1);
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
    if (fqpn)
      insistupdate(q, fqpn, PACKAGE,
                   kpse_program_text_format, kpse_fontmap_format); 
#endif
  }
#endif /* MIKETEX */
  RELEASE(q);

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_cmap_file ( const char *  filename) [static]

Definition at line 422 of file dpxfile.c.

{
  char  *fqpn = NULL;
  static const char *fools[] = {
    "cmap", "tex", NULL
  };
  int    i;

#if  defined(MIKTEX)
  /* Find in Acrobat's Resource/CMap dir */
  {
    char  _acrodir[_MAX_PATH+1];
    char  *q;
    int    r;

    memset(_acrodir, 0, _MAX_PATH+1);
    r = miktex_get_acrobat_font_dir(_acrodir);
    if (r &&
        strlen(_acrodir) > strlen("Font")) {
      /* ....\Font\ */
      q = strrchr(_acrodir, PATH_SEP_CHR);
      if (q && q[1] == '\0')
        q[0] = '\0';
      q = strrchr(_acrodir, PATH_SEP_CHR);
      if (q && !strcmp(q + 1, "Font")) {
        sprintf(q, "%cCMap%c", PATH_SEP_CHR, PATH_SEP_CHR);
        r = miktex_find_file(filename, _acrodir, _tmpbuf);
        if (r) {
          fqpn = NEW(strlen(_tmpbuf) + 1, char);
          strcpy(fqpn, _tmpbuf);
        }
      }
    }
    memset(_tmpbuf, 0, _MAX_PATH+1);
  }
#else
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L  
  fqpn = kpse_find_file(filename, kpse_cmap_format, 0); 
#endif  
#endif

  /* Files found above are assumed to be CMap,
   * if it's not really CMap it will cause an error.
   */
  for (i = 0; !fqpn && fools[i]; i++) { 
    fqpn = dpx_foolsearch(fools[i], filename, 1);
    if (fqpn) {
#ifndef  MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
      insistupdate(filename, fqpn, fools[i],
                   kpse_program_text_format, kpse_cmap_format); 
#endif
#endif
      if (!qcheck_filetype(fqpn, DPX_RES_TYPE_CMAP)) {
        WARN("Found file \"%s\" for PostScript CMap but it doesn't look like a CMap...", fqpn);
        RELEASE(fqpn);
        fqpn = NULL;
      }
    }
  }

  return  fqpn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_dfont_file ( const char *  filename) [static]

Definition at line 644 of file dpxfile.c.

{
#ifdef NOKPSE
  char *fqpn = NULL;

  fqpn = kpse_find_file(filename, kpse_truetype_format, 0);
  if (fqpn) {
    int len = strlen(fqpn);
    if (len > 6 && strncmp(fqpn+len-6, ".dfont", 6)) {
      fqpn = RENEW(fqpn, len+6, char);
      strcat(fqpn, "/rsrc");
    }
  }
  if (!qcheck_filetype(fqpn, DPX_RES_TYPE_DFONT)) {
    RELEASE(fqpn);
    fqpn = NULL;
  }
  return fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_enc_file ( const char *  filename) [static]

Definition at line 527 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;
  char  *q;
  static const char *fools[] = {
    "dvips", NULL
  };
  int    i;

  q = ensuresuffix(filename, ".enc");
#ifdef  MIKTEX
  if (miktex_find_psheader_file(q, _tmpbuf)) {
    fqpn = NEW(strlen(_tmpbuf) + 1, char);
    strcpy(fqpn, _tmpbuf);
  }
#else
# if defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
  fqpn = kpse_find_file(q, kpse_enc_format, 0);
# else
  fqpn = kpse_find_file(q, kpse_tex_ps_header_format, 0);
# endif
#endif /* MIKTEX */

  for (i = 0; !fqpn && fools[i]; i++) { 
    fqpn = dpx_foolsearch(fools[i], q, 1);
#ifndef  MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
    if (fqpn)
      insistupdate(filename, fqpn, fools[i],
                   kpse_program_text_format, kpse_enc_format); 
#endif
#endif
  }
  RELEASE(q);

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_fontmap_file ( const char *  filename) [static]

Definition at line 361 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;
  char  *q;

  q = ensuresuffix(filename, ".map");
#ifdef  MIKTEX
  fqpn = dpx_find__app__xyz(q, ".map", 1);
#else /* !MIKTEX */
  fqpn = kpse_find_file(q, kpse_fontmap_format, 0);
  if (!fqpn) {
    fqpn = dpx_find__app__xyz(q, ".map", 1);
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
    if (fqpn)
      insistupdate(q, fqpn, PACKAGE,
                   kpse_program_text_format, kpse_fontmap_format); 
#endif
  }
#endif /* MIKETEX */
  RELEASE(q);

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_iccp_file ( const char *  filename) [static]

Definition at line 342 of file dpxfile.c.

{
  char  *fqpn = NULL;

  fqpn = dpx_find__app__xyz(filename, "", 0);
  if (fqpn || strrchr(filename, '.'))
    return  fqpn;

  fqpn = dpx_find__app__xyz(filename, ".icc", 0);
  if (fqpn)
    return  fqpn;

  fqpn = dpx_find__app__xyz(filename, ".icm", 0);

  return  fqpn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_opentype_file ( const char *  filename) [static]

Definition at line 610 of file dpxfile.c.

{
  char  *fqpn = NULL;
  char  *q;

  q = ensuresuffix(filename, ".otf");
#ifndef MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
  fqpn = kpse_find_file(q, kpse_opentype_format, 0);
  if (!fqpn) {
#endif
#endif
    fqpn = dpx_foolsearch(PACKAGE, q, 0);
#ifndef  MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
    if (fqpn)
      insistupdate(filename, fqpn, PACKAGE,
                   kpse_program_binary_format, kpse_opentype_format); 
  }
#endif
#endif
  RELEASE(q);

  /* *We* use "opentype" for ".otf" (CFF). */
  if (fqpn && !qcheck_filetype(fqpn, DPX_RES_TYPE_OTFONT)) {
    RELEASE(fqpn);
    fqpn = NULL;
  }

  return  fqpn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_sfd_file ( const char *  filename) [static]

Definition at line 494 of file dpxfile.c.

{
  char  *fqpn = NULL;
  char  *q;
  static const char *fools[] = {
    "ttf2pk", "ttf2tfm", NULL
  };
  int    i;

  q    = ensuresuffix(filename, ".sfd");
#ifndef  MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
  fqpn = kpse_find_file(q, kpse_sfd_format, 0);
#endif
#endif /* !MIKTEX */

  for (i = 0; !fqpn && fools[i]; i++) { 
    fqpn = dpx_foolsearch(fools[i], q, 1);
#ifndef  MIKTEX
#if  defined(__TDS_VERSION__) && __TDS_VERSION__ >= 0x200406L
    if (fqpn)
      insistupdate(filename, fqpn, fools[i],
                   kpse_program_text_format, kpse_sfd_format); 
#endif
#endif
  }
  RELEASE(q);

  return  fqpn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_truetype_file ( const char *  filename) [static]

Definition at line 591 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;

  fqpn = kpse_find_file(filename, kpse_truetype_format, 0);
  if (fqpn && !qcheck_filetype(fqpn, DPX_RES_TYPE_TTFONT)) {
    RELEASE(fqpn);
    fqpn = NULL;
  }

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * dpx_find_type1_file ( const char *  filename) [static]

Definition at line 572 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;

  fqpn = kpse_find_file(filename, kpse_type1_format, 0);
  if (fqpn && !qcheck_filetype(fqpn, DPX_RES_TYPE_T1FONT)) {
    RELEASE(fqpn);
    fqpn = NULL;
  }

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* dpx_foolsearch ( const char *  foolname,
const char *  filename,
int  is_text 
) [static]

Definition at line 246 of file dpxfile.c.

{
#ifdef NOKPSE
  char  *fqpn = NULL;

  kpse_reset_program_name(foolname);
  fqpn = kpse_find_file  (filename,
                          (is_text ?
                              kpse_program_text_format :
                              kpse_program_binary_format),
                          false);
  kpse_reset_program_name(PACKAGE);

  return  fqpn;
#else
  return NULL;
#endif
}

Here is the caller graph for this function:

FILE* dpx_open_file ( const char *  filename,
int  type 
)

Definition at line 280 of file dpxfile.c.

{
#ifdef NOKPSE
  FILE  *fp   = NULL;
  char  *fqpn = NULL;

  switch (type) {
  case DPX_RES_TYPE_FONTMAP:
    fqpn = dpx_find_fontmap_file(filename);
    break;
  case DPX_RES_TYPE_T1FONT:
    fqpn = dpx_find_type1_file(filename);
    break;
  case DPX_RES_TYPE_TTFONT:
    fqpn = dpx_find_truetype_file(filename);
    break;
  case DPX_RES_TYPE_OTFONT:
    fqpn = dpx_find_opentype_file(filename);
    break;
  case DPX_RES_TYPE_PKFONT:
    break;
  case DPX_RES_TYPE_CMAP:
    fqpn = dpx_find_cmap_file(filename);
    break;
  case DPX_RES_TYPE_ENC:
    fqpn = dpx_find_enc_file(filename);
    break;
  case DPX_RES_TYPE_SFD:
    fqpn = dpx_find_sfd_file(filename);
    break;
  case DPX_RES_TYPE_AGL:
    fqpn = dpx_find_agl_file(filename);
    break;
  case DPX_RES_TYPE_ICCPROFILE:
    fqpn = dpx_find_iccp_file(filename);
    break;
  case DPX_RES_TYPE_DFONT:
    fqpn = dpx_find_dfont_file(filename);
    break;
  case DPX_RES_TYPE_BINARY:
    fqpn = dpx_find__app__xyz(filename, "", 0);
    break;
  case DPX_RES_TYPE_TEXT:
    fqpn = dpx_find__app__xyz(filename, "", 1);
    break;
  default:
    ERROR("Unknown resource type: %d", type);
    break;
  }
  if (fqpn) {
    fp = MFOPEN(fqpn, FOPEN_RBIN_MODE);
    RELEASE(fqpn);
  }

  return  fp;
#else
  return NULL;
#endif
}

Here is the call graph for this function:

static char* ensuresuffix ( const char *  basename,
const char *  sfx 
) [static]

Definition at line 141 of file dpxfile.c.

{
  char  *q, *p;

  p = NEW(strlen(basename) + strlen(sfx) + 1, char);
  strcpy(p, basename);
  q = strrchr(p, '.');
  if (!q && sfx[0])
    strcat(p, sfx);

  return  p;
}

Here is the caller graph for this function:

static int isdfont ( FILE *  fp) [static]

Definition at line 928 of file dpxfile.c.

{
  int i, n;
  unsigned long pos;

  rewind(fp);

  get_unsigned_quad(fp);
  seek_absolute(fp, (pos = get_unsigned_quad(fp)) + 0x18);
  seek_absolute(fp, pos + get_unsigned_pair(fp));
  n = get_unsigned_pair(fp);
  for (i = 0; i <= n; i++) {
    if (get_unsigned_quad(fp) == 0x73666e74UL) /* "sfnt" */
      return 1;
    get_unsigned_quad(fp);
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int isopentype ( FILE *  fp) [static]

Definition at line 864 of file dpxfile.c.

{
  int   n;

  rewind(fp);
  n = fread(_sbuf, 1, 4, fp);
  rewind(fp);

  if (n != 4)
    return  0;
  else if (!memcmp(_sbuf, "OTTO", 4))
    return  1;
  else
    return  0;
}

Here is the caller graph for this function:

static int ispscmap ( FILE *  fp) [static]

Definition at line 911 of file dpxfile.c.

{
  char  *p;
  p = mfgets(_sbuf, 128, fp); p[127] = '\0';
  if (!p || strlen(p) < 4 || memcmp(p, "%!PS", 4))
    return 0;
  for (p += 4; *p && !isspace(*p); p++);
  for ( ; *p && (*p == ' ' || *p == '\t'); p++);
  if (*p == '\0' || strlen(p) < strlen("Resource-CMap"))
    return  0;
  else if (!memcmp(p, "Resource-CMap", strlen("Resource-CMap")))
    return  1;
  /* Otherwise ambiguious */
  return  0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int ist1binary ( FILE *  fp) [static]

Definition at line 881 of file dpxfile.c.

{
  char *p;
  int   n;

  rewind(fp);
  n = fread(_sbuf, 1, 21, fp);
  rewind(fp);

  p = _sbuf;
  if (n != 21)
    return  0;
  else if (p[0] != (char) 0x80 || p[1] < 0 || p[1] > 3)
    return  0;
  else if (!memcmp(p + 6, "%!PS-AdobeFont", 14) ||
           !memcmp(p + 6, "%!FontType1", 11))
    return  1;
  else if (!memcmp(p + 6, "%!PS", 4)) {
#if  0
    p[20] = '\0'; p += 6;
    WARN("Ambiguous PostScript resource type: %s", (char *) p);
#endif
    return  1;
  }
  /* Otherwise ambiguious */
  return  0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int istruetype ( FILE *  fp) [static]

Definition at line 843 of file dpxfile.c.

{
  int   n;

  rewind(fp);
  n = fread(_sbuf, 1, 4, fp);
  rewind(fp);

  if (n != 4)
    return  0;
  else if (!memcmp(_sbuf, "true", 4) ||
           !memcmp(_sbuf, "\0\1\0\0", 4)) /* This doesn't help... */
    return  1;
  else if (!memcmp(_sbuf, "ttcf", 4))
    return  1;

  return  0;
}

Here is the caller graph for this function:

static int qcheck_filetype ( const char *  fqpn,
int  type 
) [static]

Definition at line 949 of file dpxfile.c.

{
  int    r = 1;
  FILE  *fp;

  if (!fqpn)
    return  0;

  fp = MFOPEN(fqpn, FOPEN_RBIN_MODE);
  if (!fp) {
    WARN("File \"%s\" found but I could not open that...", fqpn);
    return  0;
  }
  switch (type) {
  case DPX_RES_TYPE_T1FONT:
    r = ist1binary(fp);
    break;
  case DPX_RES_TYPE_TTFONT:
    r = istruetype(fp);
    break;
  case DPX_RES_TYPE_OTFONT:
    r = isopentype(fp);
    break;
  case DPX_RES_TYPE_CMAP:
    r = ispscmap(fp);
    break;
  case DPX_RES_TYPE_DFONT:
    r = isdfont(fp);
    break;
  }
  MFCLOSE(fp);

  return  r;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char _sbuf[128] [static]

Definition at line 833 of file dpxfile.c.

int verbose = 0 [static]

Definition at line 40 of file dpxfile.c.