Exemplo n.º 1
0
static string *subdir_match(str_list_type subdirs, string * matches)
{
    string *ret = XTALLOC1(string);
    unsigned len = 1;
    unsigned m;

    for (m = 0; matches[m]; m++) {
        size_t loc;
        unsigned e;
        string s = xstrdup(matches[m]);
        for (loc = strlen(s); loc > 0 && !IS_DIR_SEP(s[loc - 1]); loc--);
        while (loc > 0 && IS_DIR_SEP(s[loc - 1])) {
            loc--;
        }
        s[loc] = 0;             /* wipe out basename */

        for (e = 0; e < STR_LIST_LENGTH(subdirs); e++) {
            string subdir = STR_LIST_ELT(subdirs, e);
            size_t subdir_len = strlen(subdir);
            while (subdir_len > 0 && IS_DIR_SEP(subdir[subdir_len - 1])) {
                subdir_len--;
                subdir[subdir_len] = 0; /* remove trailing slashes from subdir spec */
            }
            if (FILESTRCASEEQ(subdir, s + loc - subdir_len)) {
                /* matched, save this one.  */
                XRETALLOC(ret, len + 1, string);
                ret[len - 1] = matches[m];
                len++;
            }
        }
        free(s);
    }
    ret[len - 1] = NULL;
    return ret;
}
Exemplo n.º 2
0
search P3C(kpse_file_format_type, format, char *, file, char *, mode)
{
  FILE *ret;
  string found_name;

#ifdef SECURE
  /* This change suggested by [email protected] to disallow reading of
     arbitrary files.  */
  if (secure && kpse_absolute_p (file)) return NULL;
#endif

  /* Most file looked for through here must exist -- the exception is
     VF's. Bitmap fonts go through pksearch. */
  found_name = kpse_find_file (file, format, format != vfpath);

  if (found_name) {
    unsigned len = strlen (found_name);
#ifndef AMIGA
    if ((format == figpath || format == headerpath)
        && ((len > 2 && FILESTRCASEEQ (found_name + len - 2, ".Z"))
            || (len > 3 && FILESTRCASEEQ (found_name + len - 3, ".gz")))) {
/* FIXME : use zlib instead of gzip ! */
      char *cmd = concat3 (GUNZIP, " -c ", found_name);
      ret = popen (cmd, "r");
      to_close = USE_PCLOSE ;
    } else {
#endif /* not AMIGA */
      ret = fopen (found_name, mode);
      to_close = USE_FCLOSE ;
#ifndef AMIGA
    }
#endif /* not AMIGA */
    if (!ret)
      FATAL_PERROR (found_name);
    /* Free result of previous search.  */
    if (realnameoffile)
      free (realnameoffile);
    /* Save in `name' and `realnameoffile' because other routines
       access those globals.  Sigh.  */
    realnameoffile = found_name;
    strcpy(name, realnameoffile);
  } else
    ret = NULL;

  return ret;
}               /* end search */
Exemplo n.º 3
0
void
kpathsea_maketex_option (kpathsea kpse, const_string fmtname, boolean value)
{
  kpse_file_format_type fmt = kpse_last_format;

  /* Trying to match up with the suffix lists unfortunately doesn't work
     well, since that would require initializing the formats.  */
  if (FILESTRCASEEQ (fmtname, "pk")) {
    fmt = kpse_pk_format;
  } else if (FILESTRCASEEQ (fmtname, "mf")) {
    fmt = kpse_mf_format;
  } else if (FILESTRCASEEQ (fmtname, "tex")) {
    fmt = kpse_tex_format;
  } else if (FILESTRCASEEQ (fmtname, "tfm")) {
    fmt = kpse_tfm_format;
  } else if (FILESTRCASEEQ (fmtname, "fmt")) {
    fmt = kpse_fmt_format;
  } else if (FILESTRCASEEQ (fmtname, "ofm")) {
    fmt = kpse_ofm_format;
  } else if (FILESTRCASEEQ (fmtname, "ocp")) {
    fmt = kpse_ocp_format;
  } else {
    fprintf (stderr, "\nkpathsea: Unknown mktex format: %s\n", fmtname);
  }

  if (fmt != kpse_last_format) {
    kpathsea_set_program_enabled (kpse, fmt, value, kpse_src_cmdline);
  }
}
Exemplo n.º 4
0
void
kpse_maketex_option P2C(const_string, fmtname,  boolean, value)
{
  kpse_file_format_type fmt = kpse_last_format;
  
  /* Trying to match up with the suffix lists unfortunately doesn't work
     well, since that would require initializing the formats.  */
  /* FIXME: Currently the function silently ignores unrecognized arguments.*/
  if (FILESTRCASEEQ (fmtname, "pk")) {
    fmt = kpse_pk_format;
  } else if (FILESTRCASEEQ (fmtname, "mf")) {
    fmt = kpse_mf_format;
  } else if (FILESTRCASEEQ (fmtname, "tex")) {
    fmt = kpse_tex_format;
  } else if (FILESTRCASEEQ (fmtname, "tfm")) {
    fmt = kpse_tfm_format;
  } else if (FILESTRCASEEQ (fmtname, "fmt")) {
    fmt = kpse_fmt_format;
  } else if (FILESTRCASEEQ (fmtname, "ofm")) {
    fmt = kpse_ofm_format;
  } else if (FILESTRCASEEQ (fmtname, "ocp")) {
    fmt = kpse_ocp_format;
  }
  if (fmt != kpse_last_format) {
    kpse_set_program_enabled (fmt, value, kpse_src_cmdline);
  }
}
Exemplo n.º 5
0
cached P1C(const_string, key)
{
  unsigned p;
  
  for (p = 0; p < cache_length; p++)
    {
      if (FILESTRCASEEQ (the_cache[p].key, key))
        return the_cache[p].value;
    }
  
  return NULL;
}
Exemplo n.º 6
0
static void
set_default_pdf_filename(void)
{
  const char *dvi_base;

  dvi_base = xbasename(dvi_filename);
  if (mp_mode &&
      strlen(dvi_base) > 4 &&
      FILESTRCASEEQ(".mps", dvi_base + strlen(dvi_base) - 4)) {
    pdf_filename = NEW(strlen(dvi_base)+1, char);
    strncpy(pdf_filename, dvi_base, strlen(dvi_base) - 4);
    pdf_filename[strlen(dvi_base)-4] = '\0';
  } else if (strlen(dvi_base) > 4 &&
Exemplo n.º 7
0
static str_llist_type *
cached (kpathsea kpse, const_string key)
{
  unsigned p;

  for (p = 0; p < kpse->cache_length; p++)
    {
      if (FILESTRCASEEQ (kpse->the_cache[p].key, key))
        return kpse->the_cache[p].value;
    }

  return NULL;
}
Exemplo n.º 8
0
const_string *
hash_lookup (hash_table_type table,  const_string key)
{
    hash_element_type *p;
    cstr_list_type ret;
    unsigned n = hash (table, key);
    ret = cstr_list_init ();

    /* Look at everything in this bucket.  */
    for (p = table.buckets[n]; p != NULL; p = p->next)
        if (FILESTRCASEEQ (key, p->key))
            cstr_list_add (&ret, p->value);

    /* If we found anything, mark end of list with null.  */
    if (STR_LIST (ret))
        cstr_list_add (&ret, NULL);

#ifdef KPSE_DEBUG
#if defined (KPSE_COMPAT_API)
    {
        kpathsea kpse = kpse_def;
        if (KPATHSEA_DEBUG_P (KPSE_DEBUG_HASH))
        {
            DEBUGF1 ("hash_lookup(%s) =>", key);
            if (!STR_LIST (ret))
                fputs (" (nil)\n", stderr);
            else
            {
                const_string *r;
                for (r = STR_LIST (ret); *r; r++)
                {
                    putc (' ', stderr);
                    if (kpse->debug_hash_lookup_int)
                        fprintf (stderr, "%ld", (long) *r);
                    else
                        fputs (*r, stderr);
                }
                putc ('\n', stderr);
            }
            fflush (stderr);
        }
    }
#endif
#endif

    return STR_LIST (ret);
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
  program_description * program = 0;
  int i, errstatus;
#if defined(WIN32)
  /* if _DEBUG is not defined, these macros will result in nothing. */
   SETUP_CRTDBG;
   /* Set the debug-heap flag so that freed blocks are kept on the
    linked list, to catch any inadvertent use of freed memory */
   SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF );
#endif

   redirect_stdout = -1;
   output_and_cleanup_function = output_and_cleanup;

#if 0
  extern MKTEXDLL string (* var_lookup)(const_string);
  var_lookup = getval;
#endif

  mktexinit(argc, argv);

  for(i = 0; makedesc[i].name; ++i) {
    if (FILESTRCASEEQ(kpse_program_name, makedesc[i].name)) {
      program_number = i;
      progname = makedesc[i].name;
      program = makedesc+i;
      break;
    }
  }
  if (!makedesc[i].name) {
    fprintf(stderr, "This program was incorrectly copied to the name %s\n", 
	    argv[0]);
    return 1;
  }

  /* mktex_opt may modify argc and shift argv */
  argc = mktex_opt(argc, argv, program);

  errstatus = program->prog(argc, argv);

  mt_exit(errstatus);
  return 0;			/* Not reached !!! */
}
Exemplo n.º 10
0
void
hash_remove (hash_table_type *table,  const_string key,
             const_string value)
{
  hash_element_type *p;
  hash_element_type *q;
  unsigned n = hash (*table, key);

  /* Find pair.  */
  for (q = NULL, p = table->buckets[n]; p != NULL; q = p, p = p->next)
    if (FILESTRCASEEQ (key, p->key) && STREQ (value, p->value))
      break;
  if (p) {
    /* We found something, remove it from the chain.  */
    if (q) q->next = p->next; else table->buckets[n] = p->next;
    /* We cannot dispose of the contents.  */
    free (p);
  }
}
Exemplo n.º 11
0
hash_lookup P2C(hash_table_type, table,  const_string, key)
{
  hash_element_type *p;
  str_list_type ret;
  unsigned n = hash (table, key);
  ret = str_list_init ();
  
  /* Look at everything in this bucket.  */
  for (p = table.buckets[n]; p != NULL; p = p->next)
    if (FILESTRCASEEQ (key, p->key))
      /* Cast because the general str_list_type shouldn't force const data.  */
      str_list_add (&ret, (string) p->value);
  
  /* If we found anything, mark end of list with null.  */
  if (STR_LIST (ret))
    str_list_add (&ret, NULL);

#ifdef KPSE_DEBUG
  if (KPSE_DEBUG_P (KPSE_DEBUG_HASH))
    {
      DEBUGF1 ("hash_lookup(%s) =>", key);
      if (!STR_LIST (ret))
        fputs (" (nil)\n", stderr);
      else
        {
          string *r;
          for (r = STR_LIST (ret); *r; r++)
            {
              putc (' ', stderr);
              if (kpse_debug_hash_lookup_int)
                fprintf (stderr, "%ld", (long) *r);
              else
                fputs (*r, stderr);
            }
          putc ('\n', stderr);
        }
      fflush (stderr);
    }
#endif

  return STR_LIST (ret);
}
Exemplo n.º 12
0
static void FontFind(struct font_entry * tfontptr)
{
  kpse_glyph_file_type font_ret;

  /* tfontptr->dpi = kpse_magstep_fix (tfontptr->dpi, resolution, NULL); */
  DEBUG_PRINT(DEBUG_DVI,("\n  FIND FONT:\t%s %d",tfontptr->n,tfontptr->dpi));

  tfontptr->name = kpse_find_vf (tfontptr->n);
  if (tfontptr->name!=NULL)
    InitVF(tfontptr);
#ifdef HAVE_FT2
  else if (option_flags & USE_FREETYPE) {
    tfontptr->psfontmap = FindPSFontMap(tfontptr->n);
    if (tfontptr->psfontmap!=NULL)
      tfontptr->name=kpse_find_t1_or_tt(tfontptr->psfontmap->psfile);
    else
      tfontptr->name=kpse_find_t1_or_tt(tfontptr->n);
    if (tfontptr->name!=NULL) {
      char* tfmname=kpse_find_file(tfontptr->n, kpse_tfm_format, false);
      if (tfmname!=NULL) {
        if (!ReadTFM(tfontptr,tfmname)) {
          Warning("unable to read tfm file %s", tfmname);
          free(tfontptr->name);
          tfontptr->name=NULL;
        } else if ((option_flags & USE_FREETYPE)==0 || !InitFT(tfontptr)) {
          /* if Freetype loading fails for some reason, fall back to PK font */
          free(tfontptr->name);
          tfontptr->name=NULL;
        }
        free(tfmname);
      }
    }
  }
#endif /* HAVE_FT2 */
  if (tfontptr->name==NULL) {
    tfontptr->name=kpse_find_pk (tfontptr->n, tfontptr->dpi, &font_ret);
    if (tfontptr->name!=NULL) {
      if (!FILESTRCASEEQ (tfontptr->n, font_ret.name)) {
        page_flags |= PAGE_GAVE_WARN;
        Warning("font %s not found, using %s at %d dpi instead",
                tfontptr->n, font_ret.name, font_ret.dpi);
        tfontptr->c = 0; /* no checksum warning */
      } else if (!kpse_bitmap_tolerance ((double)font_ret.dpi,
           (double) tfontptr->dpi)) {
        page_flags |= PAGE_GAVE_WARN;
        Warning("font %s at %d dpi not found, using %d dpi instead",
                tfontptr->n, tfontptr->dpi, font_ret.dpi);
      }
      InitPK(tfontptr);
    } else {
      page_flags |= PAGE_GAVE_WARN;
      Warning("font %s at %d dpi not found, characters will be left blank",
        tfontptr->n, tfontptr->dpi);
#ifndef WIN32
      tfontptr->fmmap.fd = 0;
#else  /* WIN32 */
      tfontptr->fmmap.hFile = INVALID_HANDLE_VALUE;
#endif
      tfontptr->magnification = 0;
      tfontptr->designsize = 0;
    }
  }
}
Exemplo n.º 13
0
static kpse_file_format_type
find_format(kpathsea kpse, const_string name, boolean is_filename)
{
    kpse_file_format_type ret;

    if (FILESTRCASEEQ(name, "config.ps")) {
        ret = kpse_dvips_config_format;
    } else if (FILESTRCASEEQ(name, "dvipdfmx.cfg")) {
        ret = kpse_program_text_format;
    } else if (FILESTRCASEEQ(name, "fmtutil.cnf")) {
        ret = kpse_web2c_format;
    } else if (FILESTRCASEEQ(name, "glyphlist.txt")) {
        ret = kpse_fontmap_format;
    } else if (FILESTRCASEEQ(name, "mktex.cnf")) {
        ret = kpse_web2c_format;
    } else if (FILESTRCASEEQ(name, "pdfglyphlist.txt")) {
        ret = kpse_fontmap_format;
    } else if (FILESTRCASEEQ(name, "pdftex.cfg")) {
        ret = kpse_pdftex_config_format;
    } else if (FILESTRCASEEQ(name, "texmf.cnf")) {
        ret = kpse_cnf_format;
    } else if (FILESTRCASEEQ(name, "updmap.cfg")) {
        ret = kpse_web2c_format;
    } else if (FILESTRCASEEQ(name, "XDvi")) {
        ret = kpse_program_text_format;
    } else {
        int f = 0;              /* kpse_file_format_type */
        size_t name_len = strlen(name);

/* Have to rely on `try_len' being declared here, since we can't assume
   GNU C and statement expressions.  */
#define TRY_SUFFIX(ftry) (\
  try_len = (ftry) ? strlen (ftry) : 0, \
  (ftry) && try_len <= name_len \
     && FILESTRCASEEQ (ftry, name + name_len - try_len))

        while (f != kpse_last_format) {
            size_t try_len;
            const_string *ext;
            const_string ftry;
            boolean found = false;

            if (!kpse->format_info[f].type)
                kpathsea_init_format(kpse, (kpse_file_format_type) f);

            if (!is_filename) {
                /* Allow the long name, but only in the -format option.  We don't
                   want a filename confused with a format name.  */
                ftry = kpse->format_info[f].type;
                found = TRY_SUFFIX(ftry);
            }
            for (ext = kpse->format_info[f].suffix; !found && ext && *ext;
                 ext++) {
                found = TRY_SUFFIX(*ext);
            }
            for (ext = kpse->format_info[f].alt_suffix; !found && ext && *ext;
                 ext++) {
                found = TRY_SUFFIX(*ext);
            }

            if (found)
                break;

            /* Some trickery here: the extensions for kpse_fmt_format can
             * clash with other extensions in use, and we prefer for those
             * others to be preferred.  And we don't want to change the
             * integer value of kpse_fmt_format.  So skip it when first
             * enountered, then use it when we've done everything else,
             * and use it as the end-guard.
             */
            if (f == kpse_fmt_format) {
                f = kpse_last_format;
            } else if (++f == kpse_fmt_format) {
                f++;
            } else if (f == kpse_last_format) {
                f = kpse_fmt_format;
            }
        }

        /* If there was a match, f will be one past the correct value.  */
        ret = f;
    }

    return ret;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
  int i;
  int retval = 0;

  kpse_set_progname(argv[0]);
  progname = xstrdup(program_invocation_short_name);

#ifdef _WIN32
  SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
#else
# ifdef SIGHUP
  signal (SIGHUP, sigint_handler);
# endif
# ifdef SIGINT
  signal (SIGINT, sigint_handler);
# endif
# ifdef SIGQUIT
  signal (SIGQUIT, sigint_handler);
# endif
# ifdef SIGEMT
  signal (SIGEMT, sigint_handler);
# endif
# ifdef SIGPIPE
  signal (SIGPIPE, sigint_handler);
# endif
# ifdef SIGTERM
  signal (SIGTERM, sigint_handler);
# endif
#endif

  if (strlen(progname) > 4 && FILESTRNCASEEQ(progname + strlen(progname) - 4, ".exe", 4)) {
    *(progname + strlen(progname) - 4) = '\0';
  }
  is_ht = FILESTRCASEEQ(progname, "ht");

  argv = parse_arguments(&argc, argv);

#if 0
  fprintf(stderr, "%s:\n", progname);
  for (i = 1; i < argc; i++) 
    fprintf(stderr, "\t argv[%d] = %s\n", i, argv[i]);
  fprintf(stderr, "\nconfig(%d,%d) = ", math, dtd);
  for (i = 0; i < 3; i++)
    fprintf(stderr, "%s ", stdcfg[math][dtd][i]);
  fprintf(stderr, "\n");
#endif
  
  texargs = (force ? "--interaction=nonstopmode" : "");

  if (TESTZ(argv[1])) {
    fprintf(stderr, "%s: error, no file specified.\n", progname);
    exit(1);
  }

  texsrc = xstrdup(argv[1]);

#if 0
  /* Rely on latex / kpathsea to find the right source file. */
  if ((strlen(texsrc) < 4)
      || _strnicmp(texsrc + strlen(texsrc) - 4, ".tex", 4) != 0) {
    texsrc = concat(texsrc, ".tex");
  }
#endif

  texfile = xstrdup(texsrc);

  if ((strlen(texfile) >= 4) 
      && _strnicmp(texfile + strlen(texfile) - 4, ".tex", 4) == 0) {
    *(texfile + strlen(texfile) - 4) = '\0';
  }

  if (TESTZ(output_name)) {
    output_name = xstrdup(texfile);
  }
  else {
    if ((strlen(output_name) >= 4) 
	&& _strnicmp(output_name + strlen(output_name) - 4, ".tex", 4) == 0) {
      *(output_name + strlen(output_name) - 4) = '\0';
    }
    texargs = concat3(texargs, " --jobname=", output_name);
  }

#if 0
  // copy the original name to output name if needed
  if (TESTNZ(output_dir)) {
    texfile = concat3(output_dir, "\\", output_name);
  }
  else if (TESTNZ(output_name)) {
    texfile = xstrdup(output_name);
  }
  else 
    texfile = NULL;

  if (texfile) {
    unixtodos_filename(texfile);
    
    if (dry_run) {
      fprintf(stderr, "%s: copying %s to %s\n", progname, texsrc, texfile);
    }
    else {
      if (CopyFile(texsrc, texfile, false) == 0) {
	fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n",
		progname, texsrc, texfile, GetLastError());
      }
    }
    free(texfile);
  }

  texfile = xstrdup(output_name);

  if (TESTNZ(output_dir)) {
    pushd(output_dir);
    xputenv("KPSE_DOT", cwd);
    xputenv("TEXINPUTS", concatn(cwd, "/", output_dir, ";", NULL));
    if (dry_run) {
      fprintf(stderr, "%s: changing directory to %s\n", progname, output_dir);
      fprintf(stderr, "%s: setting KPSE_DOT to %s\n", progname, cwd);
    }
  }
#endif
  if (is_ht) {
    retval = ht(argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "httex")) {
    retval = ht_engine(runstr_tex, argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "htlatex")) {
    retval = ht_engine(runstr_latex, argc, argv);
  }
  else if (FILESTRCASEEQ(progname, "httexi")) {
    retval = ht_engine(runstr_texi, argc, argv);
  }
  else {
    fprintf(stderr, "%s: %s is unknown, aborting.\n", argv[0], progname);
    retval = 1;
  }

  if (opt_index) {
    /* copy dest_dir/output_name.html to dest_dir/index.html */
    char *destfile = output_name;
    char *indexfile = "index.html";

    if (TESTNZ(output_dir)) {
      destfile = concat3(output_dir, "\\", output_name);
      indexfile = concat(output_dir, "\\index.html");
    }

    if ((strlen(destfile) < 5) 
	|| _strnicmp(destfile + strlen(destfile) - 5, ".html", 5) != 0) {
      destfile = concat(destfile, ".html");
    }
    
    if (CopyFile(destfile, indexfile, false) == 0) {
      fprintf(stderr, "%s: failed to copy %s to %s (Error %d)\n",
	      progname, destfile, indexfile, GetLastError());
    }
  }

  mt_exit(retval);

  /* Not Reached */
  return retval;
}
Exemplo n.º 15
0
void
kpse_set_program_name P2C(const_string, argv0, const_string, progname)
{
  string ext, sdir, sdir_parent, sdir_grandparent;
  string s = getenv ("KPATHSEA_DEBUG");
#ifdef WIN32
  string debug_output = getenv("KPATHSEA_DEBUG_OUTPUT");
  string append_debug_output = getenv("KPATHSEA_DEBUG_APPEND");
  int err, olderr;
#endif
  
  /* Set debugging stuff first, in case we end up doing debuggable stuff
     during this initialization.  */
  if (s) {
    kpathsea_debug |= atoi (s);
  }

#ifndef HAVE_PROGRAM_INVOCATION_NAME
#if defined(WIN32)
  /* Set various info about user. Among many things,
     ensure that HOME is set. If debug_paths is on, 
     turn on some message if $HOME is not found. */
  if (KPSE_DEBUG_P(KPSE_DEBUG_PATHS)) {
    set_home_warning();
  }
  init_user_info();

  /* redirect stderr to debug_output. Easier to send logfiles. */
  if (debug_output) {
    int flags =  _O_CREAT | _O_TRUNC | _O_RDWR;
    err = -1;
    if (_stricmp(debug_output, "con") == 0
       || _stricmp(debug_output, "con:") == 0) {
      err = _fileno(stdout);
    } else {
      if (append_debug_output) {
        flags =  _O_CREAT | _O_APPEND | _O_WRONLY;
      } else {
        flags =  _O_CREAT | _O_TRUNC | _O_WRONLY;
        xputenv("KPATHSEA_DEBUG_APPEND", "yes");
      }
    }

    if ((err < 0)
        && (err = _open(debug_output, flags, _S_IREAD | _S_IWRITE)) == -1)
    {
      WARNING1("Can't open %s for stderr redirection!\n", debug_output);
      perror(debug_output);
    } else if ((olderr = _dup(fileno(stderr))) == -1) {
      WARNING("Can't dup() stderr!\n");
      close(err);
    } else if (_dup2(err, fileno(stderr)) == -1) {
      WARNING1("Can't redirect stderr to %s!\n", debug_output);
      close(olderr);
      close(err);
    } else {
      close(err);
    }
  }
  /* Win95 always gives the short filename for argv0, not the long one.
     There is only this way to catch it. It makes all the selfdir stuff
     useless for win32. */
  {
    char short_path[PATH_MAX], path[PATH_MAX], *fp;
      
    /* SearchPath() always gives back an absolute directory */
    if (SearchPath(NULL, argv0, ".exe", PATH_MAX, short_path, &fp) == 0)
        FATAL1("Can't determine where the executable %s is.\n", argv0);
    if (!win32_get_long_filename(short_path, path, sizeof(path))) {
        FATAL1("This path points to an invalid file : %s\n", short_path);
    }
    /* slashify the dirname */
    for (fp = path; fp && *fp; fp++)
        if (IS_DIR_SEP(*fp)) *fp = DIR_SEP;
    /* sdir will be the directory of the executable, ie: c:/TeX/bin */
    sdir = xdirname(path);
    program_invocation_name = xstrdup(xbasename(path));
  }

#elif defined(__DJGPP__)

  /* DJGPP programs support long filenames on Windows 95, but ARGV0 there
     is always made with the short 8+3 aliases of all the pathname elements.
     If long names are supported, we need to convert that to a long name.

     All we really need is to call `_truename', but most of the code
     below is required to deal with the special case of networked drives.  */
  if (pathconf (argv0, _PC_NAME_MAX) > 12) {
    char long_progname[PATH_MAX];

    if (_truename (argv0, long_progname)) {
      char *fp;

      if (long_progname[1] != ':') {
	/* A complication: `_truename' returns network-specific string at
	   the beginning of `long_progname' when the program resides on a
	   networked drive, and DOS calls cannot grok such pathnames.  We
	   need to convert the filesystem name back to a drive letter.  */
	char rootname[PATH_MAX], rootdir[4];

	if (argv0[0] && argv0[1] == ':')
	  rootdir[0] = argv0[0]; /* explicit drive in `argv0' */
	else
	  rootdir[0] = getdisk () + 'A';
	rootdir[1] = ':';
	rootdir[2] = '\\';
	rootdir[3] = '\0';
	if (_truename (rootdir, rootname)) {
	  /* Find out where `rootname' ends in `long_progname' and replace
	     it with the drive letter.  */
	  int root_len = strlen (rootname);

 	  if (IS_DIR_SEP (rootname[root_len - 1]))
            root_len--;	/* keep the trailing slash */
	  long_progname[0] = rootdir[0];
	  long_progname[1] = ':';
	  memmove (long_progname + 2, long_progname + root_len,
		   strlen (long_progname + root_len) + 1);
	}
      }

      /* Convert everything to canonical form.  */
      if (long_progname[0] >= 'A' && long_progname[0] <= 'Z')
	long_progname[0] += 'a' - 'A'; /* make drive lower case, for beauty */
      for (fp = long_progname; *fp; fp++)
	if (IS_DIR_SEP (*fp))
	  *fp = DIR_SEP;

      program_invocation_name = xstrdup (long_progname);
    }
    else
      /* If `_truename' failed, God help them, because we won't...  */
      program_invocation_name = xstrdup (argv0);
  }
  else
    program_invocation_name = xstrdup (argv0);

#else /* !WIN32 && !__DJGPP__ */

  program_invocation_name = xstrdup (argv0);

#endif
#endif /* not HAVE_PROGRAM_INVOCATION_NAME */

  /* We need to find SELFAUTOLOC *before* removing the ".exe" suffix from
     the program_name, otherwise the PATH search inside selfdir will fail,
     since `prog' doesn't exists as a file, there's `prog.exe' instead.  */
#ifndef WIN32
  sdir = selfdir (program_invocation_name);
#endif
  /* SELFAUTODIR is actually the parent of the invocation directory,
     and SELFAUTOPARENT the grandparent.  This is how teTeX did it.  */
  xputenv ("SELFAUTOLOC", sdir);
  sdir_parent = xdirname (sdir);
  xputenv ("SELFAUTODIR", sdir_parent);
  sdir_grandparent = xdirname (sdir_parent);
  xputenv ("SELFAUTOPARENT", sdir_grandparent);

  free (sdir);
  free (sdir_parent);
  free (sdir_grandparent);

#ifndef HAVE_PROGRAM_INVOCATION_NAME
  program_invocation_short_name = (string)xbasename (program_invocation_name);
#endif

  if (progname) {
    kpse_program_name = xstrdup (progname);
  } else {
    /* If configured --enable-shared and running from the build directory
       with the wrapper scripts (e.g., for make check), the binaries will
       be named foo.exe instead of foo.  Or possibly if we're running on a
       DOSISH system.  */
    ext = find_suffix (program_invocation_short_name);
    if (ext && FILESTRCASEEQ (ext, "exe")) {
      kpse_program_name = remove_suffix (program_invocation_short_name);
    } else {
      kpse_program_name = xstrdup (program_invocation_short_name);
    }
  }
  xputenv("progname", kpse_program_name);
}
Exemplo n.º 16
0
static Boolean
pkopen(register fontdesctype *fd)
{
   register char *d, *n;
   const char *name_ret;
#ifdef KPATHSEA
   int dpi_ret;
#else
   int vdpi;
#endif
   d = fd->area;
   n = fd->name;
#ifndef KPATHSEA
   if (*d==0)
      d = pkpath;
#endif
#ifdef FONTLIB
   if (*(fd->area) == 0) {
      int del;
      for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
        if ((pkfile=flisearch(n, fd->dpi + del)) != (FILE *)NULL )
          return(1);
      }
   }
#endif
   {
#ifdef KPATHSEA
     char *this_name = concat (d, n);

     pkfile = pksearch(this_name, READBIN, fd->dpi, &name_ret, &dpi_ret);

     if (!pkfile || !FILESTRCASEEQ (this_name, name_ret)) {
       char *msg = concatn ("Font ", fd->area, n, " not found; ", NULL);
       /* wasting some memory */
       if (!pkfile)
         msg = concat (msg, "characters will be left blank.");
       else
         msg = concat3 (msg, "using ", name_ret);
       dontmakefont = 1;
       error (msg);

     } else if (!kpse_bitmap_tolerance ((double) dpi_ret, (double) fd->dpi))
       {
           fd->loadeddpi = dpi_ret;
           fd->alreadyscaled = 0;
           sprintf(errbuf,
                   "Font %s at %d not found; scaling %d instead.",
                                     n, fd->dpi, dpi_ret);
           error(errbuf);
           lectureuser();
       }

     if (this_name != name_ret)
       free (this_name);

     return pkfile != NULL;
   }
#else
      int del;
      for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
         if (actualdpi == vactualdpi) {
            vdpi = 0;
         } else {
            vdpi = (2 * ((long)vactualdpi) * (fd->dpi + del) + actualdpi)
                                                       / (2 * actualdpi);
         }
#ifdef MVSXA
         sprintf(name, "pk%d(%s)", fd->dpi + del, n);
#else
         sprintf(name, "%s.%dpk", n, fd->dpi + del);
#endif
         if (0 != (pkfile=pksearch(d, name, READBIN, n, fd->dpi + del, vdpi)))
            return(1);
      }
   }