/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ //TODO manage && || fun deleteOb(inst)= 0;; fun cbIfEqual(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then ( // search for *thing to compare using strfind if ((nth_char value 0) == 42) then set rep = if ((strfind (substr value 1 ((strlen value) - 1)) param 0) != nil) then 1 else 0 else if ((nth_char param 0) == 42) then set rep = if ((strfind (substr param 1 ((strlen param) - 1)) value 0) != nil) then 1 else 0 else set rep = !strcmp value param; ) else if !strcmp stype "Hexa" then set rep = (htoi value) == (htoi param) else if !strcmp stype "Int" then set rep = (atoi value) == (atoi param) else if !strcmp stype "Float" then set rep = (atof value) == (atof param) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbIfSuperior(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then set rep = (strlen param) > (strlen value) else if !strcmp stype "Hexa" then set rep = if param == nil || value == nil then 0 else (htoi param) > (htoi value) else if !strcmp stype "Int" then set rep = if param == nil || value == nil then 0 else (atoi param) > (atoi value) else if !strcmp stype "Float" then set rep = if param == nil || value == nil then 0 else (atof param) >. (atof value) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbIfSuperiorOrEqual(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then set rep = (strlen param) >= (strlen value) else if !strcmp stype "Hexa" then set rep = if param == nil || value == nil then 0 else (htoi param) >= (htoi value) else if !strcmp stype "Int" then set rep = if param == nil || value == nil then 0 else (atoi param) >= (atoi value) else if !strcmp stype "Float" then set rep = if param == nil || value == nil then 0 else (atof param) >=. (atof value) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbIfInferior(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then set rep = (strlen param) < (strlen value) else if !strcmp stype "Hexa" then set rep = if param == nil || value == nil then 0 else (htoi param) < (htoi value) else if !strcmp stype "Int" then set rep = if param == nil || value == nil then 0 else (atoi param) < (atoi value) else if !strcmp stype "Float" then set rep = if param == nil || value == nil then 0 else (atof param) <. (atof value) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbIfInferiorOrEqual(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then set rep = (strlen param) <= (strlen value) else if !strcmp stype "Hexa" then set rep = if param == nil || value == nil then 0 else (htoi param) <= (htoi value) else if !strcmp stype "Int" then set rep = if param == nil || value == nil then 0 else (atoi param) <= (atoi value) else if !strcmp stype "Float" then set rep = if param == nil || value == nil then 0 else (atof param) <=. (atof value) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbIfDifferent(inst, from, action, param, reply, p)= let p -> [value stype] in let if !strcmp value "NIL" then nil else value -> value in let if !strcmp param "NIL" then nil else param -> param in let 0 -> rep in ( if !strcmp stype "String" then ( // search for *thing to compare using strfind if ((nth_char value 0) == 42) then set rep = if ((strfind (substr value 1 ((strlen value) - 1)) param 0) != nil) then 0 else 1 else if ((nth_char param 0) == 42) then set rep = if ((strfind (substr param 1 ((strlen param) - 1)) value 0) != nil) then 0 else 1 else set rep = strcmp value param; ) else if !strcmp stype "Hexa" then set rep = (htoi value) != (htoi param) else if !strcmp stype "Int" then set rep = (atoi value) != (atoi param) else if !strcmp stype "Float" then set rep = (atof value) != (atof param) else nil; if rep then SendPluginEvent inst "True" param nil else SendPluginEvent inst "False" param nil; ); 0;; fun cbSetValue(inst, from, action, param, reply, p)= mutate p <- [param _]; 0;; fun newOb(inst)= let (getPluginInstanceParam inst "value") -> value in let (getPluginInstanceParam inst "type") -> stype in let [value stype] -> p in ( PluginRegisterAction inst "Equal" mkfun6 @cbIfEqual p; PluginRegisterAction inst "Superior" mkfun6 @cbIfSuperior p; PluginRegisterAction inst "SuperiorOrEqual" mkfun6 @cbIfSuperiorOrEqual p; PluginRegisterAction inst "Inferior" mkfun6 @cbIfInferior p; PluginRegisterAction inst "InferiorOrEqual" mkfun6 @cbIfInferiorOrEqual p; PluginRegisterAction inst "Different" mkfun6 @cbIfDifferent p; PluginRegisterAction inst "Set value" mkfun6 @cbSetValue p; setPluginInstanceCbDel inst @deleteOb; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;