/* ----------------------------------------------------------------------------- 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 ObjXmlReaderStr = [ PXR_instance : PInstance, PXR_sRefPath : S, PXR_sPath : S, PXR_lLabels : [[S S] r1], PXR_lValues : [[S S] r1] ]mkObjXmlReaderStr;; fun deleteOb(inst, obstr)= 0;; fun getXmlLabels(obstr, lmarkstr, chain, utf8)= let chain -> cchain in if (lmarkstr == nil) then nil else ( let hd lmarkstr -> markstr in ( set chain = strcatn chain::(if (chain == nil) then "" else ".")::markstr.XMLvalue::nil; let 0 -> sp in let (strlen markstr.XMLdata) - 1 -> ep in let substr markstr.XMLdata sp 1 -> fc in let substr markstr.XMLdata ep 1 -> ec in if ((strcmp "{" fc) || (strcmp "}" ec)) then nil else ( let substr markstr.XMLdata 1 (ep - 1) -> label in let if (utf8) then utf8tostr label else label -> label in ( set obstr.PXR_lLabels = [chain label]::obstr.PXR_lLabels; //addLogMessage strcatn "Label : "::chain::" : "::label::nil; ); ); getXmlLabels obstr markstr.XMLsons chain utf8; ); getXmlLabels obstr tl lmarkstr cchain utf8; 0; );; fun loadXmlRef(obstr)= let XMLloadManual obstr.PXR_sRefPath -> xmlstr in getXmlLabels obstr xmlstr.XMLmarks nil (if (strfindi "utf-8" xmlstr.XMLtype 0) != nil then 1 else 0); set obstr.PXR_lLabels = revertlist obstr.PXR_lLabels; 0;; fun getXmlValues(obstr, lmarkstr, chain, utf8)= let chain -> cchain in if (lmarkstr == nil) then nil else ( let hd lmarkstr -> markstr in ( set chain = strcatn chain::(if (chain == nil) then "" else ".")::markstr.XMLvalue::nil; let switchstri obstr.PXR_lLabels chain -> label in if (label == nil) then nil else let if (utf8) then utf8tostr markstr.XMLdata else markstr.XMLdata -> data in ( set obstr.PXR_lValues = [label data]::obstr.PXR_lValues; SendPluginEvent obstr.PXR_instance chain data nil; //addLogMessage strcatn "Values : "::label::" : "::data::nil; ); getXmlValues obstr markstr.XMLsons chain utf8; ); getXmlValues obstr tl lmarkstr cchain utf8; 0; );; fun cbLoadFile(inst, from, action, param, reply, obstr)= let if ((_checkpack param) == nil) then obstr.PXR_sPath else param -> param in ( set obstr.PXR_sPath = param; let XMLloadManual obstr.PXR_sPath -> xmlstr in getXmlValues obstr xmlstr.XMLmarks nil (if (strfindi "utf-8" xmlstr.XMLtype 0) != nil then 1 else 0); set obstr.PXR_lValues = revertlist obstr.PXR_lValues; SendPluginEvent inst "Loaded" nil nil; ); 0;; fun cbGetFormatedText(inst, from, action, param, reply, obstr)= let let nil -> text in ( let obstr.PXR_lValues -> lval in while (lval != nil) do ( let hd lval -> [label value] in set text = if (text == nil) then strcatn label::": "::value::nil else strcatn text::"\n"::label::": "::value::nil; set lval = tl lval; ); text; ) -> text in if (text == nil) then nil else SendPluginEvent inst "Formated text" text nil; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "refpath") -> refpath in let (getPluginInstanceParam inst "path") -> path in let atoi (getPluginInstanceParam inst "init") -> init in let mkObjXmlReaderStr [inst refpath path nil nil] -> obstr in ( loadXmlRef obstr; if (!init) then nil else cbLoadFile inst nil nil nil nil obstr; PluginRegisterAction inst "Load file" mkfun6 @cbLoadFile obstr; PluginRegisterAction inst "Get formated text" mkfun6 @cbGetFormatedText obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;