POV-Ray : Newsgroups : povray.newusers : File handle and macros : Re: File handle and macros Server Time
1 May 2025 17:57:30 EDT (-0400)
  Re: File handle and macros  
From: Leroy
Date: 1 May 2025 13:20:00
Message: <web.6813ac317252bfd738fc462df712fc00@news.povray.org>
kurtz le pirate <kur### [at] freefr> wrote:
>
>
> Of course this code work :
> --------------------------------------------------------------------------
> #fopen FileHandle1 "test1.txt" write
> #fopen FileHandle2 "test2.txt" write
> #fopen FileHandle3 "test3.txt" write
>
> #write (FileHandle1, "writing to test1\n")
> #write (FileHandle2, "writing to test2\n")
> #write (FileHandle3, "writing to test3\n")
>
> #fclose FileHandle3
> #fclose FileHandle2
> #fclose FileHandle1
> --------------------------------------------------------------------------
>
> ...but the advantages of having one and only one macro that writes to
> files are lost :(
>
>
You could put each of those sections in their own macro.
like:
macro OpenW(F,FileName)
 #switch(F)
  #case(1) #fopen Afile FileName write  #break
  #case(2) #fopen Bfile FileName write  #break
  #case(3) #fopen Cfile FileName write  #break
 #end
#macro Write(F,String)
 #switch(F)
  #case(1) #write(Afile,String,"\n") #break
  #case(2) #write(Bfile,String,"\n") #break
  #case(3) #write(Cfile,String,"\n") #break
 #end
#end
#macro Close(F)
 #switch(F)
  #case(1) #fclose Afile #break
  #case(2) #fclose Bfile #break
  #case(3) #fclose Cfile #break
 #end
#end
You'll notice different names here that because I tested the Idea and just
copied the code.
Have Fun


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.