POV-Ray : Newsgroups : povray.general : #ifdef fails? Server Time
25 Nov 2024 23:39:39 EST (-0500)
  #ifdef fails? (Message 1 to 5 of 5)  
From: Ger
Subject: #ifdef fails?
Date: 17 Nov 2012 14:22:20
Message: <50a7e3ec$1@news.povray.org>
Consider then following code;

    #fopen FN FileName read
    #ifdef (FN)
      #while (defined(FN))
	#read ( FN , Vector)
	action( Vector )
      #end
    #end

After processing Filename001 - FileName100, the next file doesn't exist 
(FileName101). Afaik #ifdef (FN) should catch that and not allow the #while 
loop to continue.

Or am I missing something?
-- 
Ger

Using Pov 3.7 on Linux


Post a reply to this message

From: Christian Froeschlin
Subject: Re: #ifdef fails?
Date: 17 Nov 2012 16:42:15
Message: <50a804b7$1@news.povray.org>
Ger wrote:

>     #fopen FN FileName read
>     #ifdef (FN)
>       #while (defined(FN))
> 	#read ( FN , Vector)
> 	action( Vector )
>       #end
>     #end

the documentation of #fopen states that IDENTIFIER should be
an undefined identifier. So it might be that the #ifdef test
only works if FN was not alreaday defined prior to #fopen.


Post a reply to this message

From: Ger
Subject: Re: #ifdef fails?
Date: 17 Nov 2012 17:44:04
Message: <50a81334$1@news.povray.org>
Christian Froeschlin wrote:

> Ger wrote:
> 
>>     #fopen FN FileName read
>>     #ifdef (FN)
>>       #while (defined(FN))
>> #read ( FN , Vector)
>> action( Vector )
>>       #end
>>     #end
> 
> the documentation of #fopen states that IDENTIFIER should be
> an undefined identifier. So it might be that the #ifdef test
> only works if FN was not alreaday defined prior to #fopen.

From the manual
<
You may use #ifdef FILE_HANDLE_IDENTIFIER to see if a file is open.
>
-- 
Ger


Post a reply to this message

From: Thomas de Groot
Subject: Re: #ifdef fails?
Date: 18 Nov 2012 03:16:30
Message: <50a8995e$1@news.povray.org>
On 17-11-2012 20:22, Ger wrote:
> Consider then following code;
>
>      #fopen FN FileName read
>      #ifdef (FN)
>        #while (defined(FN))
> 	#read ( FN , Vector)
> 	action( Vector )
>        #end
>      #end
>
> After processing Filename001 - FileName100, the next file doesn't exist
> (FileName101). Afaik #ifdef (FN) should catch that and not allow the #while
> loop to continue.
>
> Or am I missing something?
>

I wonder: shouldn't #fopen not give a parse error message when trying to 
open a non-existing file? Before even #ifdef()?

I remember having misquoted a filename and having the parser abort.

[quote]You may use #ifdef FILE_HANDLE_IDENTIFIER to see if a file is 
open[unquote] only tests if the file is /open/ not if it /exists/. That 
might be a subtle difference...

Thomas


Post a reply to this message

From: clipka
Subject: Re: #ifdef fails?
Date: 19 Nov 2012 02:34:46
Message: <50a9e116@news.povray.org>
Am 17.11.2012 20:22, schrieb Ger:
> Consider then following code;
>
>      #fopen FN FileName read
>      #ifdef (FN)
>        #while (defined(FN))
>          #read ( FN , Vector)
>          action( Vector )
>        #end
>      #end
>
> After processing Filename001 - FileName100, the next file doesn't exist
> (FileName101). Afaik #ifdef (FN) should catch that and not allow the #while
> loop to continue.

Well, if FN is undefined, the #while loop itself should refuse to run 
even a single time, so the #ifdef is redundant.

But if the file doesn't exist, #fopen doesn't fail with an undefined FN, 
but rather with an error message.

You might want to use the following code:

#if (file_exists(FileName))
   #fopen ...
   #while ...
     ...
   #end
#end


Post a reply to this message

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