MPMSTATICFUNC(void) RememberFileNameInfo(const string& prefixedFileName, const string& packageId) { shared_ptr<Session> session = Session::Get(); string fileName; // ignore non-texmf files if (!PackageManager::StripTeXMFPrefix(prefixedFileName, fileName)) { return; } PathNameParser pathtok(fileName); if (!pathtok) { return; } // initialize root path: "//MiKTeX/[MPM]" PathName path = session->GetMpmRootPath(); // path += CURRENT_DIRECTORY; // s1: current path name component string s1 = *pathtok; ++pathtok; // name: file name component string name = s1; while (pathtok) { string s2 = *pathtok; ++pathtok; directoryInfoTable[path.ToString()].subDirectoryNames.insert(s1); name = s2; #if defined(MIKTEX_WINDOWS) // make sure the the rest of the path contains slashes (not // backslashes) path.AppendAltDirectoryDelimiter(); #else path.AppendDirectoryDelimiter(); #endif path /= s1; s1 = s2; } DirectoryInfo& directoryInfo = directoryInfoTable[path.ToString()]; directoryInfo.fileNames.push_back(name); directoryInfo.packageNames.push_back(packageId); }
void WebAppInputLine::SetAuxDirectory(const PathName& path) { if (pimpl->auxDirectory == path) { return; } LogInfo("setting aux directory: " + path.ToString()); pimpl->auxDirectory = path; }
bool PackageManagerImpl::ReadDirectory(const PathName& path, vector<string>& subDirNames, vector<string>& fileNames, vector<string>& fileNameInfos) { const DirectoryInfo& directoryInfo = directoryInfoTable[path.ToString()]; for (const string& name : directoryInfo.subDirectoryNames) { subDirNames.push_back(name); } fileNames = directoryInfo.fileNames; fileNameInfos = directoryInfo.packageNames; return true; }
bool SessionImpl::ConvertToBitmapFile(const PathName& sourceFileName, PathName& destFileName, IRunProcessCallback* callback) { string ext = sourceFileName.GetExtension(); if (ext.empty()) { MIKTEX_FATAL_ERROR_2(T_("No file name extension in graphics rule."), "path", ext); } string rule; if (!FindGraphicsRule(ext, ".bmp", rule)) { MIKTEX_FATAL_ERROR_2(T_("No conversion rule found."), "path", sourceFileName.ToString()); } destFileName.SetToTempFile(); #if defined(MIKTEX_WINDOWS) Utils::RemoveBlanksFromPathName(destFileName); #endif string commandLine; for (const char* lpsz = rule.c_str(); *lpsz != 0; ++lpsz) { if (*lpsz == '%') { ++lpsz; switch (*lpsz) { case 'i': commandLine += sourceFileName.GetData(); break; case 'o': commandLine += destFileName.GetData(); break; } } else { commandLine += *lpsz; } } bool done = Process::ExecuteSystemCommand(commandLine, nullptr, callback, nullptr); if (!done) { File::Delete(destFileName, { FileDeleteOption::TryHard }); } return done; }
void PipeStream::Open(const PathName& fileName, const vector<string>& arguments) { childStartInfo.FileName = fileName.ToString(); childStartInfo.Arguments = arguments; childStartInfo.RedirectStandardInput = true; childStartInfo.RedirectStandardError = true; childStartInfo.RedirectStandardOutput = true; childProcess = Process::Start(childStartInfo); Application::GetApplication()->LogInfo("started PipeStream child process " + std::to_string(childProcess->GetSystemId()) + ": " + StringUtil::Flatten(arguments, ' ')); childStdinFile = childProcess->get_StandardInput(); setvbuf(childStdinFile, nullptr, _IONBF, 0); StartThreads(); }
void Utils::CanonicalizePathName(PathName& path) { wchar_t szFullPath[BufferSizes::MaxPath]; DWORD n = GetFullPathNameW(path.ToWideCharString().c_str(), BufferSizes::MaxPath, szFullPath, nullptr); if (n == 0) { MIKTEX_FATAL_WINDOWS_ERROR_2("GetFullPathNameW", "path", path.ToString()); } if (n >= BufferSizes::MaxPath) { BUF_TOO_SMALL(); } path = szFullPath; }
bool Utils::SupportsHardLinks(const PathName& path) { DWORD fileSystemFlags; wchar_t fileSystemName[_MAX_PATH]; PathName root = path.GetMountPoint(); if (GetVolumeInformationW(root.ToWideCharString().c_str(), nullptr, 0, nullptr, nullptr, &fileSystemFlags, fileSystemName, _MAX_PATH) == 0) { MIKTEX_FATAL_WINDOWS_ERROR_2("GetVolumeInformationW", "root", root.ToString()); } if (WindowsVersion::IsWindows7OrGreater()) { return (fileSystemFlags & FILE_SUPPORTS_HARD_LINKS) != 0; } else { return _wcsicmp(fileSystemName, L"NTFS") == 0; } }
void CommandLineBuilder::AppendRedirection(const PathName& path_, string direction) { #if defined(MIKTEX_WINDOWS) string path = PathName(path_).ToDos().ToString(); #else string path = path_.ToString(); #endif pimpl->str += direction; bool needsQuoting = path.find_first_of(pimpl->needsQuoting) != string::npos; if (needsQuoting) { pimpl->str += '"'; } pimpl->str += path; if (needsQuoting) { pimpl->str += '"'; } }
void TpmParser::GetFiles (/*[in]*/ const XML_Char * lpszFiles, /*[out]*/ vector<string> & files) { MIKTEX_ASSERT (Utils::IsAscii(lpszFiles)); for (Tokenizer tok (lpszFiles, X_(";\n\r \t")); tok.GetCurrent() != 0; ++ tok) { PathName path (tok.GetCurrent()); #if defined(MIKTEX_UNIX) path.ToUnix (); #endif if (texMFPrefix.length() == 0 || (PathName::Compare(texMFPrefix, path, texMFPrefix.length()) == 0)) { files.push_back (path.ToString()); } } }
void Tfm::Read () { if (! dviChars.empty() || dviInfo.notLoadable) { return; } trace_tfm->WriteFormattedLine ("libdvi", T_("going to load TFM file %s"), dviInfo.name.c_str()); PathName fileName; bool tfmFileExists = SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(), fileName, false); if (! tfmFileExists) { if (Make(dviInfo.name)) { tfmFileExists = SessionWrapper(true)->FindTfmFile(dviInfo.name.c_str(), fileName, false); if (! tfmFileExists) { // this shouldn't happen; but it does (#521481) } } if (! tfmFileExists) { dviInfo.transcript += "\r\n"; dviInfo.transcript += T_("Loading 'cmr10' instead.\r\n"); trace_error->WriteFormattedLine ("libdvi", T_("'%s' not loadable - loading 'cmr10' instead!"), dviInfo.name.c_str()); if (! (SessionWrapper(true)->FindTfmFile("cmr10", fileName, false) || (Make("cmr10") && SessionWrapper(true)->FindTfmFile("cmr10", fileName, false)))) { dviInfo.transcript += T_("'cmr10' not loadable either!"); trace_error->WriteLine ("libdvi", T_("'cmr10' not loadable - will display blank chars!")); return; } } } dviInfo.fileName = fileName.ToString(); trace_tfm->WriteFormattedLine ("libdvi", T_("opening TFM file %s"), fileName.Get()); InputStream inputStream (fileName.Get()); long lf = inputStream.ReadSignedPair(); if (lf == 0) { FATAL_DVI_ERROR ("Tfm::Read", T_("Invalid TFM file."), 0); } long lh = inputStream.ReadSignedPair(); long bc = inputStream.ReadSignedPair(); long ec = inputStream.ReadSignedPair(); long nw = inputStream.ReadSignedPair(); long nh = inputStream.ReadSignedPair(); long nd = inputStream.ReadSignedPair(); long ni = inputStream.ReadSignedPair(); long nl = inputStream.ReadSignedPair(); long nk = inputStream.ReadSignedPair(); long ne = inputStream.ReadSignedPair(); long np = inputStream.ReadSignedPair(); trace_tfm->WriteFormattedLine ("libdvi", T_("header size: %ld"), lh); trace_tfm->WriteFormattedLine ("libdvi", T_("smallest character code: %ld"), bc); trace_tfm->WriteFormattedLine ("libdvi", T_("largest character code: %ld"), ec); trace_tfm->WriteFormattedLine ("libdvi", T_("width table size: %ld"), nw); trace_tfm->WriteFormattedLine ("libdvi", T_("height table size: %ld"), nh); trace_tfm->WriteFormattedLine ("libdvi", T_("depth table size: %ld"), nd); trace_tfm->WriteFormattedLine ("libdvi", T_("italic correction table size: %ld"), ni); trace_tfm->WriteFormattedLine ("libdvi", T_("lig/kern table size: %ld"), nl); trace_tfm->WriteFormattedLine ("libdvi", T_("kern table size: %ld"), nk); trace_tfm->WriteFormattedLine ("libdvi", T_("extensible character table size: %ld"), ne); trace_tfm->WriteFormattedLine ("libdvi", T_("font parameter size: %ld"), np); int my_checkSum = inputStream.ReadSignedQuad(); trace_tfm->WriteFormattedLine ("libdvi", "checkSum: 0%lo", my_checkSum); int my_designSize = inputStream.ReadSignedQuad(); trace_tfm->WriteFormattedLine ("libdvi", "designSize: %ld", my_designSize); if (my_checkSum != checkSum) { trace_error->WriteFormattedLine ("libdvi", T_("%s: checkSum mismatch"), dviInfo.name.c_str()); } if (my_designSize * tfmConv != designSize) { trace_error->WriteFormattedLine ("libdvi", T_("%s: designSize mismatch"), dviInfo.name.c_str()); } inputStream.SkipBytes ((lh - 2) * 4); struct TfmIndex { int widthIndex; int heightIndex; int depthIndex; }; vector<TfmIndex> infoTable (ec); for (int charCode = bc; charCode < ec; ++ charCode) { DviChar * pDviChar = new DviChar (this); dviChars[charCode] = pDviChar; pDviChar->SetCharacterCode (charCode); TfmIndex tfmIndex; tfmIndex.widthIndex = inputStream.ReadSignedByte(); int heightDepth = inputStream.ReadSignedByte(); tfmIndex.heightIndex = ((heightDepth >> 4) & 15); tfmIndex.depthIndex = (heightDepth & 15); inputStream.SkipBytes (2); infoTable[charCode] = tfmIndex; } vector<int> widths (nw); for (int idx = 0; idx < nw; ++ idx) { widths[idx] = inputStream.ReadSignedQuad(); } vector<int> heights (nh); for (int idx = 0; idx < nh; ++ idx) { heights[idx] = inputStream.ReadSignedQuad(); } vector<int> depths (nd); for (int idx = 0; idx < nd; ++ idx) { depths[idx] = inputStream.ReadSignedQuad(); } // inputStream.Close (); for (int charCode = bc; charCode < ec; ++ charCode) { int tfmWidth = ScaleFix(widths[infoTable[charCode].widthIndex], GetScaledAt()); dviChars[charCode]->SetDviWidth (tfmWidth); int pixelWidth; if (tfmWidth >= 0) { pixelWidth = static_cast<int>(conv * tfmWidth + 0.5); } else { pixelWidth = - static_cast<int>(conv * -tfmWidth + 0.5); } dviChars[charCode]->SetWidth (pixelWidth); } }
int MAIN(int argc, MAINCHAR** argv) { try { // build new argv vector<string> utf8args; for (int idx = 0; idx < argc; ++idx) { utf8args.push_back(TU_(argv[idx])); } vector<char*> newargv; newargv.reserve(utf8args.size() + 1); for (const string& arg : utf8args) { newargv.push_back((char*)arg.c_str()); } newargv.push_back(nullptr); app.Init(newargv); // determine script name PathName programName = PathName(newargv[0]).GetFileNameWithoutExtension(); std::string scriptName; #if defined(MTXRUN) bool isLuatools = (PathName::Compare(programName, "luatools") == 0); bool isMtxrun = (PathName::Compare(programName, "mtxrun") == 0); bool isTexmfstart = (PathName::Compare(programName, "texmfstart") == 0); if (isLuatools) { scriptName = "luatools"; } else { scriptName = "mtxrun"; } #else scriptName = programName.ToString(); #endif // get relative script path PathName scriptsIni; if (!app.GetSession()->FindFile(MIKTEX_PATH_SCRIPTS_INI, MIKTEX_PATH_TEXMF_PLACEHOLDER, scriptsIni)) { MIKTEX_FATAL_ERROR(MIKTEXTEXT("The script configuration file cannot be found.")); } unique_ptr<Cfg> scriptConfig(Cfg::Create()); scriptConfig->Read(scriptsIni, true); std::string relScriptPath; if (!scriptConfig->TryGetValueAsString(CFGKEY, scriptName, relScriptPath)) { MIKTEX_FATAL_ERROR_2(MIKTEXTEXT("The Lua script is not registered."), "programName", programName.ToString()); } scriptConfig = nullptr; // find script PathName scriptPath; if (!app.GetSession()->FindFile(relScriptPath, MIKTEX_PATH_TEXMF_PLACEHOLDER, scriptPath)) { MIKTEX_FATAL_ERROR_2(MIKTEXTEXT("The Lua script could not be found."), "path", relScriptPath); } // inject arguments vector<char*> extraArgs; extraArgs.push_back("--luaonly"); extraArgs.push_back(scriptPath.GetData()); #if defined(MTXRUN) if (!(isLuatools || isMtxrun || isTexmfstart)) { extraArgs.push_back("--script"); extraArgs.push_back(programName); } #endif newargv.insert(newargv.begin() + 1, extraArgs.begin(), extraArgs.end()); // run texlua int exitCode = Main(newargv.size() - 1, &newargv[0]); app.Finalize2(exitCode); return exitCode; } catch (const MiKTeXException& e) { Utils::PrintException(e); app.Finalize2(1); return 1; } catch (const std::exception& e) { Utils::PrintException(e); app.Finalize2(1); return 1; } catch (int exitCode) { app.Finalize2(exitCode); return exitCode; } }
void PackageManager::SetMiKTeXDirectRoot(const PathName& path) { shared_ptr<Session> session = Session::Get(); session->SetConfigValue(MIKTEX_REGKEY_PACKAGE_MANAGER, MIKTEX_REGVAL_MIKTEXDIRECT_ROOT, path.ToString()); }
void PackageManager::SetLocalPackageRepository(const PathName& path) { Session::Get()->SetConfigValue(MIKTEX_REGKEY_PACKAGE_MANAGER, MIKTEX_REGVAL_LOCAL_REPOSITORY, path.ToString()); }
void miktex_set_aux_directory(const char* path) { auxDirectory = path; auxDirectory.MakeAbsolute(); shared_ptr<Session> session = Session::Get(); if (!Directory::Exists(auxDirectory)) { if (session->GetConfigValue(MIKTEX_CONFIG_SECTION_TEXANDFRIENDS, MIKTEX_CONFIG_VALUE_CREATEAUXDIRECTORY).GetString() == "t") { Directory::Create(auxDirectory); } else { MIKTEX_FATAL_ERROR_2(T_("The specified auxiliary directory does not exist."), "directory", auxDirectory.ToString()); } } session->AddInputDirectory(auxDirectory, true); }