From a565043e685d25a2140de1efe3be0cc6b6eba4ba Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 31 May 2003 09:24:46 +0000 Subject: [PATCH] Modify LibScriptSearch to replace "$$s/" with an appropriate path. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7070 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 6 ++++++ src/support/filetools.C | 37 +++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 72e33c3073..89cca0a0ea 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,9 @@ +2003-05-30 Angus Leeming + + * filetools.C (LibScriptSearch): make it search for "$$s/" and replace + this with the path to the script. If the script is not found, the "$$s/" + string is removed. + 2003-05-22 Lars Gullik Bjønnes * lstrings.[Ch] (prefixIs,suffixIs,subst): remove variants taking diff --git a/src/support/filetools.C b/src/support/filetools.C index a9102ce69a..4cff72828d 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -333,18 +333,35 @@ i18nLibFileSearch(string const & dir, string const & name, } -string const LibScriptSearch(string const & command) +string const LibScriptSearch(string const & command_in) { - string script; - string args = command; - args = split(args, script, ' '); - script = LibFileSearch("scripts", script); - if (script.empty()) + string const token_scriptpath("$$s/"); + + string command = command_in; + // Find the starting position of "$$s/" + string::size_type const pos1 = command.find(token_scriptpath); + if (pos1 == string::npos) return command; - else if (args.empty()) - return script; - else - return script + ' ' + args; + // Find the end of the "$$s/some_script" word within command + string::size_type const start_script = pos1 + 4; + string::size_type const pos2 = command.find(' ', start_script); + string::size_type const size_script = pos2 == string::npos? + (command.size() - start_script) : pos2 - start_script; + + // Does this script file exist? + string const script = + LibFileSearch("scripts", command.substr(start_script, size_script)); + + if (script.empty()) { + // Replace "$$s/" with "" + command.erase(pos1, 4); + } else { + // Replace "$$s/some_script" with "$LYX_SCRIPT_PATH/some_script" + string::size_type const size_replace = size_script + 4; + command.replace(pos1, size_replace, script); + } + + return command; } -- 2.39.2