static void rmfiles (char *prefix) { #ifdef _WIN32 /* Win32 doesn't have POSIX dirent functions. */ WIN32_FIND_DATA ffd; HANDLE hnd; int go_on; string temp = concat (prefix, "*"); string directory = xdirname (prefix); pushd (directory); hnd = FindFirstFile(temp, &ffd); go_on = (hnd != INVALID_HANDLE_VALUE); while (go_on) { /* FIXME: can this remove read-only files also, like rm -f does? */ DeleteFile(ffd.cFileName); go_on = (FindNextFile(hnd, &ffd) == TRUE); } FindClose(hnd); free(temp); popd (); #else /* not _WIN32 */ DIR *dp; struct dirent *de; int temp_len = strlen (prefix); string directory = "./"; const_string base = xbasename (prefix); /* Copy the directory part of PREFIX with the trailing slash, if any. */ if (base != prefix) { directory = (string) xmalloc (base - prefix + 1); directory[0] = '\0'; strncat (directory, prefix, base - prefix); } /* Find matching files and delete them. */ if ((dp = opendir (directory)) != 0) { while ((de = readdir (dp)) != 0) { string found = concat (directory, de->d_name); if (FILESTRNCASEEQ (found, prefix, temp_len)) /* On POSIX-compliant systems, including DJGPP, this will also remove read-only files and empty directories, like rm -f does. */ if (remove (found)) perror (found); free (found); } } #endif /* not _WIN32 */ }
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; }