/* * \file lyx_path_prefix.C * This file is part of LyX, the document processor. * http://www.lyx.org/ * Licence details can be found in the file COPYING or copy at * http://www.lyx.org/about/license.php3 * \author Angus Leeming * Full author contact details are available in file CREDITS or copy at * http://www.lyx.org/about/credits.php * * This little piece of code is used to insert some code into LyX's * Resources/lyx/configure script so that it will cause lyxrc.defaults to * contain * * \path_prefix ";;..." * * Compile the code with * * g++ -I/c/Program\ Files/NSIS/Contrib -Wall -shared \ * lyx_path_prefix.c -o lyx_path_prefix.dll * * Move resulting .dll to /c/Program\ Files/NSIS/Plugins */ #include #include "ExDLL/exdll.h" #include #include #include #include #include namespace { std::string const subst(std::string const & a, std::string const & oldstr, std::string const & newstr) { std::string lstr = a; std::string::size_type i = 0; std::string::size_type const olen = oldstr.length(); while ((i = lstr.find(oldstr, i)) != std::string::npos) { lstr.replace(i, olen, newstr); i += newstr.length(); // We need to be sure that we dont // use the same i over and over again. } return lstr; } } // namespace anon BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { return TRUE; } extern "C" void __declspec(dllexport) set(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { char configure_file[MAX_PATH]; char path_prefix[MAX_PATH]; EXDLL_INIT(); popstring(configure_file); popstring(path_prefix); std::fstream fs(configure_file); if (!fs) { pushstring("-1"); return; } std::istreambuf_iterator const begin(fs); std::istreambuf_iterator const end; std::string configure_data(begin, end); std::string::size_type const xfonts_pos = configure_data.find("X FONTS"); if (xfonts_pos == std::string::npos) { pushstring("-1"); return; } std::string::size_type const xfonts_start = configure_data.find_last_of('\n', xfonts_pos); if (xfonts_start == std::string::npos) { pushstring("-1"); return; } fs.seekg(0); fs << configure_data.substr(0, xfonts_start) << "\n" "cat >>$outfile <