/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct StringReplaceStr = [ STRRP_sToReplace : S, STRRP_sReplacement : S, STRRP_bCase : I, STRRP_iMode : I, STRRP_iNumber : I, STRRP_iOrder : I ]mkStringReplaceStr;; fun deleteOb(inst)= 0;; fun strFindi2List(s, search)= let nil -> lpos in let 0 -> pos in let strlen search -> searchsize in ( while ((set pos = strfindi search s pos) != nil) do ( set lpos = pos::lpos; set pos = pos + searchsize; ); revertlist lpos; );; fun strReplaceIdx(s, from, to, idx, case, order)= let strlen from -> fsize in if (fsize <= 0) then s else ( let if case then strfind2List s from 0 else strFindi2List s from -> lpos in let sizelist lpos -> lsize in if (idx > lsize) then nil else let nth_list lpos (if order == 0 then (idx - 1) else (lsize - idx)) -> pos in set s = strcatn (substr s 0 pos)::to::(substr s (pos + fsize) ((strlen s) - pos))::nil; s; );; fun cbIn(inst, from, action, param, reply, obstr)= let "" -> out in ( if (obstr.STRRP_iMode == 0 && obstr.STRRP_bCase) then set out = strreplace param obstr.STRRP_sToReplace obstr.STRRP_sReplacement else if (obstr.STRRP_iMode == 0) then set out = strreplacei param obstr.STRRP_sToReplace obstr.STRRP_sReplacement else set out = strReplaceIdx param obstr.STRRP_sToReplace obstr.STRRP_sReplacement obstr.STRRP_iNumber obstr.STRRP_bCase obstr.STRRP_iOrder; SendPluginEvent inst "Out" out nil; ); 0;; fun cbSetTextToReplace(inst, from, action, param, reply, obstr)= set obstr.STRRP_sToReplace = param; 0;; fun cbSetReplacementText(inst, from, action, param, reply, obstr)= set obstr.STRRP_sReplacement = param; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "toreplace") -> toreplace in let if (toreplace == nil) then "" else toreplace -> toreplace in let (getPluginInstanceParam inst "replacement") -> replacement in let if (replacement == nil) then "" else replacement -> replacement in let atoi (getPluginInstanceParam inst "case") -> case in let if (case == nil) then 0 else case -> case in let atoi (getPluginInstanceParam inst "mode") -> mode in let if (mode == nil) then 0 else mode -> mode in let atoi (getPluginInstanceParam inst "number") -> number in let if (number == nil) then 1 else number -> number in let atoi (getPluginInstanceParam inst "order") -> order in let if (order == nil) then 0 else order -> order in let mkStringReplaceStr [toreplace replacement case mode number order] -> obstr in ( PluginRegisterAction inst "In" mkfun6 @cbIn obstr; PluginRegisterAction inst "Set text to replace" mkfun6 @cbSetTextToReplace obstr; PluginRegisterAction inst "Set replacement text" mkfun6 @cbSetReplacementText obstr; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;