Exemplo n.º 1
0
/* Get long name for file, if possible (assumed to be absolute).  */
BOOL
win32_get_long_filename (char * name, char * buf, int size)
{
  char * o = buf;
  char * p;
  char * q;
  char full[ MAX_PATH ];
  int len;

  len = strlen (name);
  if (len >= MAX_PATH)
    return FALSE;

  /* Use local copy for destructive modification.  */
  memcpy (full, name, len+1);
  unixtodos_filename (full);

  /* Copy root part verbatim.  */
  len = _parse_root (full, &p);
  memcpy (o, full, len);
  o += len;
  size -= len;

  do
    {
      q = p;
      p = strchr (q, '\\');
      if (p) *p = '\0';
      len = get_long_basename (full, o, size);
      if (len > 0)
        {
          o += len;
          size -= len;
          if (p != NULL)
            {
              *p++ = '\\';
              if (size < 2)
                return FALSE;
              *o++ = '\\';
              size--;
              *o = '\0';
            }
        }
      else
        return FALSE;
    }
  while (p != NULL && *p);

  return TRUE;
}
Exemplo n.º 2
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;
}