|
 |
"Warp" <war### [at] tag povray org> wrote...
> I thought that perhaps a macro could be done to automatize the ignoring
> of repeated. This macro could be used like:
>
> import("myinclude.inc")
>
> which would #include "myinclude.inc" only if it wasn't included before.
>
> It's not easy to implement this macro with the current povray script.
It's not that hard. Here it is with comments. I don't think it would be
too slow, either. You've got to do the string comparisons somewhere, either
when you do token comparisons to find the identifier in the identifiers
table or when you search through the array like in this macro.
-Nathan
================
#macro Import(File)
// uncomment this to be case insensitive
//#local File=strupr(File)
// set up some variables
#ifndef(ImportFileList)
// we only keep track of a limited number of includes
#declare MaxImportFiles=50;
#declare ImportFileList=array[MaxImportFiles]
#declare NumImportsUsed=0;
#end
// look through the list to see if we've already
// included it
#local I=0;
#local Found=0;
#while(I<NumImportsUsed & Found=0)
#if(strcmp(ImportFileList[I],File)=0)
#local Found=1;
#else
#local I=I+1;
#end
#end
// if we didn't find it, let's include it
#if(Found=0)
// but first let's make a note that we are including
// it so we won't import it again
// if we've gone over the max, just don't bother
// (it will get re-included)
#if(NumImportsUsed<MaxImportFiles)
#declare ImportFileList[NumImportsUsed]=File
#declare NumImportsUsed=NumImportsUsed+1;
#end
// now do the include
#include File
#end
#end
Post a reply to this message
|
 |