/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ /************************************************** Ogre Material parser library Version: 1.0 Author: Bastien BOURINEAU / I-maginer Last update: 23.12.2008 **************************************************/ fun OGMATlcat (p, q)= if p==nil then q else let p -> [h nxt] in h::OGMATlcat nxt q;; fun OGMATfindResourcePath(file, lpaths)= if file == nil then nil else if (_checkpack file) != nil then file else let getPathFile file "" -> [_ file] in let sizelist lpaths -> size in let nil -> goodpath in let 0 -> i in ( while i < size && goodpath == nil do ( let nth_list lpaths i -> path in ( let if (!strcmp "/" (substr path ((strlen path) - 1) 1)) then path else (strcat path "/") -> path in if (_checkpack strcat path file) == nil then nil else set goodpath = strcat path file; ); set i = i + 1; ); goodpath; );; fun strcatLine(l)= let sizelist l -> size in let "" -> line in let 0 -> i in ( while i < size do ( let nth_list l i -> word in if i == 0 then set line = word else set line = strcatn line::" "::word::nil; set i = i + 1; ); line; );; fun strBuildWithTabs(l)= let sizelist l -> size in let "" -> string in let 0 -> i in ( while i < size do ( let nth_list l i -> line in if i == 0 then set string = strcatLine line else set string = strcatn string::(ctoa 13)::(ctoa 10)::(strcatLine line)::nil; set i = i + 1; ); string; );; fun OGMATsetResourcesPath(file, lpaths)= let _checkpack file -> pfile in if pfile == nil then ( _fooS strcat "OGRE MATERIAL PARSER ERROR : file not found > " file; nil; ) else ( let nil -> baddata in let strextr _getpack pfile -> lcont in let sizelist lcont -> size in let lcont -> lcontcp in ( let 0 -> i in while (i < size) do ( let nth_list lcont i -> line in let strtrim (hd line) -> fword in ( if (!strcmpi "texture" fword) || (!strcmpi "cubic_texture" fword) || (!strcmpi "source" fword) || (!strcmpi "anim_texture" fword) || (!strcmpi "image" fword) then ( if (isLastWordfromString "cubic_texture" fword) || (isLastWordfromString "anim_texture" fword) then ( let sizelist (tl line) -> size2 in let 1 -> i2 in while i2 < size2 do ( let endlist line i2 -> cubelist in let strtrim (hd cubelist) -> cubefile in if (atoi cubefile) > 0 then nil else if ((_checkpack cubefile) != nil) || ((getFileExt cubefile) == nil) then nil else ( let OGMATfindResourcePath cubefile lpaths -> goodcubepath in if goodcubepath == nil then ( set baddata = [i cubefile]::baddata; 0; ) else ( mutate cubelist <- [goodcubepath _]; 0; ); ); set i2 = i2 + 1; ); ) else if ((_checkpack (strtrim (hd tl line))) != nil) || ((getFileExt (strtrim (hd tl line))) == nil) then nil else ( let tl line -> chtup in let OGMATfindResourcePath (strtrim (hd chtup)) lpaths -> goodpath in if goodpath == nil then ( set baddata = [i strtrim (hd chtup)]::baddata; 0; ) else ( mutate chtup <- [goodpath _]; 0; ); 0; ); ) else nil; ); set i = i + 1; ); _storepack (strBuildWithTabs lcont) file; baddata; ); );; fun OGMATgetResources(file)= let _checkpack file -> pfile in if pfile == nil then ( _fooS strcat "OGRE MATERIAL PARSER ERROR : file not found > " file; nil; ) else ( let strextr _getpack pfile -> lcont in let 1 -> ret in let nil -> ndata in let nil -> baddata in let 0 -> i in ( while (lcont != nil) do ( let hd lcont -> line in let strtrim (hd line) -> fword in ( if (!strcmpi "texture" fword) || (!strcmpi "cubic_texture" fword) || (!strcmpi "source" fword) || (!strcmpi "anim_texture" fword) || (!strcmpi "image" fword) then ( if (isLastWordfromString "cubic_texture" fword) || (isLastWordfromString "anim_texture" fword) then ( let sizelist (tl line) -> size2 in let 1 -> i2 in while i2 < size2 do ( let strtrim (nth_list line i2) -> cubefile in ( if ((_checkpack cubefile) != nil) || ((atoi cubefile) > 0) then ( set ndata = [1 cubefile]::ndata; 0; ) else if (getFileExt cubefile) == nil then nil else ( set baddata = [i cubefile]::baddata; set ret = 0; 0; ); ); set i2 = i2 + 1; ); ) else if (_checkpack strtrim(hd tl line)) != nil then ( set ndata = [(if (!strcmpi "source" fword) || (!strcmpi "image" fword) then 0 else 1) strtrim((hd tl line))]::ndata; 0; ) else if (getFileExt strtrim(hd tl line)) == nil then nil else ( set baddata = [i strtrim(hd tl line)]::baddata; set ret = 0; 0; ); ) else nil; ); set i = i + 1; set lcont = tl lcont; ); [ret ndata baddata]; ); );;