bool LocateNTEmacs (/*[out]*/ PathName & ntEmacs, /*[in]*/ const char * lpszName) { PathName path; if (! ReadPath(HKEY_LOCAL_MACHINE, L"SOFTWARE\\GNU\\Emacs", L"emacs_dir", path)) { return (false); } path += "bin"; path += lpszName; path.SetExtension (".exe"); if (! File::Exists(path)) { return (false); } ntEmacs = path; return (true); }
void dvipdft (/*[in]*/ int argc, /*[in]*/ const char ** argv) { // must have at least one argument: the DVI file name if (argc == 1) { BadUsage (); } char szGSExePath[BufferSizes::MaxPath]; SessionWrapper(true)->GetGhostscript (szGSExePath, 0); PathName dvipdfmExe; if (! SessionWrapper(true)->FindFile("dvipdfm", FileType::EXE, dvipdfmExe)) { FatalError (MIKTEXTEXT("The Dvipdfm executable could not be found.")); } // create a temporary directory TempDirectory tempDir; CommandLineBuilder arguments; PathName fileNoExt; // loop over all arguments except the last one for (int i = 1; i < argc - 1; ++ i) { arguments.AppendArgument (argv[i]); if (strcmp(argv[i], "-o") == 0 && i + 1 < argc - 1) { ++ i; arguments.AppendArgument (argv[i]); fileNoExt = argv[i]; fileNoExt.SetExtension (0); } } const char * lpszUserFilename = argv[argc - 1]; if (fileNoExt.GetLength() == 0) { fileNoExt = lpszUserFilename; fileNoExt.SetExtension (0); } // run dvipdfm with the fastest options for the first pass arguments.AppendOption ("-e"); arguments.AppendOption ("-z", "0"); arguments.AppendArgument (lpszUserFilename); int exitCode = 0; if (! Process::Run(dvipdfmExe.Get(), arguments.Get(), 0, &exitCode, 0)) { FatalError (MIKTEXTEXT("%s could not be started."), dvipdfmExe.Get()); } if (exitCode != 0) { throw (exitCode); } // run GhostScript to create thumbnails PathName outFileTemplate (tempDir.Get(), fileNoExt.Get(), "%d"); arguments.Clear (); arguments.AppendOption ("-r", "10"); arguments.AppendOption ("-dNOPAUSE"); arguments.AppendOption ("-dBATCH"); arguments.AppendOption ("-sDEVICE:", "png256"); arguments.AppendOption ("-sOutputFile:", outFileTemplate.Get()); arguments.AppendArgument (PathName(0, fileNoExt.Get(), ".pdf").Get()); if (! Process::Run(szGSExePath, arguments.Get(), 0, &exitCode, 0)) { FatalError (MIKTEXTEXT("%s could not be started."), szGSExePath); } if (exitCode != 0) { throw (exitCode); } // run dvipdfm with the users specified options for the last pass arguments.Clear (); arguments.AppendOption ("-dt"); arguments.AppendArguments (argc - 1, &argv[1]); printf ("dvipdfm %s\n", arguments.Get()); Utils::SetEnvironmentString ("MIKTEX_TEMP", tempDir.Get()); if (! Process::Run(dvipdfmExe.Get(), arguments.Get(), 0, &exitCode, 0)) { FatalError (MIKTEXTEXT("%s could not be started."), dvipdfmExe.Get()); } if (exitCode != 0) { throw (exitCode); } tempDir.Delete (); }