1. buffer flushing

Hi all,

Does anyone know of a way to flush a file buffer on an open file (other than
closing and then re-opening it?)  I have a real time log that I want to be
able to open in notepad, etc. while my program is still running, and be able
to view the file's contents.

Thanks
Brian
bjackson at 2fargon.hypermart.net

new topic     » topic index » view message » categorize

2. Re: buffer flushing

Have you tried opening the file in append mode ?

new topic     » goto parent     » topic index » view message » categorize

3. Re: buffer flushing

Brian Jackson writes:
> Does anyone know of a way to flush a file buffer
> on an open file (other than closing and then re-opening it?)

Closing the file is currently the only way.
In the next major release I'll add a flush() routine.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » goto parent     » topic index » view message » categorize

4. Re: buffer flushing

Rob and Bernie,

Thanks to both!  I tried opening the file in append mode, and it seems to
work just fine.

Brian
bjackson at 2fargon.hypermart.net

new topic     » goto parent     » topic index » view message » categorize

5. Re: buffer flushing

On Tue, 11 May 1999, Robert Craig wrote:

] Brian Jackson writes:
] > Does anyone know of a way to flush a file buffer
] > on an open file (other than closing and then re-opening it?)
]
] Closing the file is currently the only way.
] In the next major release I'll add a flush() routine.
]
] Regards,
]      Rob Craig

Here's an on-the-fly solution that uses the "close-reopen" trick. It's
coded so that it can be put straight into an .E library.

-- Initialise the trick:
sequence open_log
open_log = repeat(0,25) -- Or whatever Eu's MAX_FILES_LIMIT is...

-- redefine the open and close subroutines to use open_log:
function old_open(sequence name, sequence mode)
    return open(name, mode)
end function

procedure old_close(integer handle)
    close(handle)
end procedure

without warning -- me about redefinitions
    global function open(sequence name, sequence mode)
        integer handle
        handle = old_open(name, mode)
        if handle = -1 then return -1 end if

        open_log[handle] = {name, mode}

        return handle
    end function

    global procedure close(integer handle)
        if handle < 3 or handle > 25 or atom(open_log[handle]) then
            return
        end if
        open_log[handle] = 0
        old_close(handle)
    end procedure
with warning -- of other stuff :)

-- and now the new flush procedure:
global procedure flush(integer handle)
    object info
    if handle < 3 or handle > 25 then return end if
    info = open_log[handle]
    if atom(info) then return end if
    old_close(handle) -- use old close for speed, checks already done...
    if info[2][1] = 'r' then return end if -- only flush writeable files
    old_open(info[1], info[2]) -- using the new open isn't necessary.
end procedure

HTH,
Carl

--
Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek
 aka Cyrek   --    No hyphens :)    --       Bigfoot URL Alias

new topic     » goto parent     » topic index » view message » categorize

6. Re: buffer flushing

I think you only want to flush/close files if they are writable.
That means you want to move your close() statement in flush()
below your if "read only" statement.
I also suggest you alter your r to be a find 'r'
"rb" is possible.
even then if you don't close a readable file you will
want to use seek() to return to the beginning of the file.

-- Lucius L. Hilley III

On Thu, 13 May 1999 14:42:16 +0100, Carl R. White
<C.R.White at SCM.BRAD.AC.UK> wrote:

>On Tue, 11 May 1999, Robert Craig wrote:
>
>] Brian Jackson writes:
>] > Does anyone know of a way to flush a file buffer
>] > on an open file (other than closing and then re-opening it?)
>]
>] Closing the file is currently the only way.
>] In the next major release I'll add a flush() routine.
>]
>] Regards,
>]      Rob Craig
>
>Here's an on-the-fly solution that uses the "close-reopen" trick. It's
>coded so that it can be put straight into an .E library.
>
>-- Initialise the trick:
>sequence open_log
>open_log = repeat(0,25) -- Or whatever Eu's MAX_FILES_LIMIT is...
>
>-- redefine the open and close subroutines to use open_log:
>function old_open(sequence name, sequence mode)
>    return open(name, mode)
>end function
>
>procedure old_close(integer handle)
>    close(handle)
>end procedure
>
>without warning -- me about redefinitions
>    global function open(sequence name, sequence mode)
>        integer handle
>        handle = old_open(name, mode)
>        if handle = -1 then return -1 end if
>
>        open_log[handle] = {name, mode}
>
>        return handle
>    end function
>
>    global procedure close(integer handle)
>        if handle < 3 or handle > 25 or atom(open_log[handle]) then
>            return
>        end if
>        open_log[handle] = 0
>        old_close(handle)
>    end procedure
>with warning -- of other stuff :)
>
>-- and now the new flush procedure:
>global procedure flush(integer handle)
>    object info
>    if handle < 3 or handle > 25 then return end if
>    info = open_log[handle]
>    if atom(info) then return end if
>    old_close(handle) -- use old close for speed, checks already done...
>    if info[2][1] = 'r' then return end if -- only flush writeable files
>    old_open(info[1], info[2]) -- using the new open isn't necessary.
>end procedure
>
>HTH,
>Carl
>
>--
>Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek
> aka Cyrek   --    No hyphens :)    --       Bigfoot URL Alias

new topic     » goto parent     » topic index » view message » categorize

7. Re: buffer flushing

On Thu, 13 May 1999, Lucius Hilley III wrote:

] I think you only want to flush/close files if they are writable.
] That means you want to move your close() statement in flush()
] below your if "read only" statement.
] I also suggest you alter your r to be a find 'r'
] "rb" is possible.
] even then if you don't close a readable file you will
] want to use seek() to return to the beginning of the file.
]
] -- Lucius L. Hilley III
]
] On Thu, 13 May 1999 14:42:16 +0100, Carl R. White

1 >global procedure flush(integer handle)
2 >    object info
3 >    if handle < 3 or handle > 25 then return end if
4 >    info = open_log[handle]
5 >    if atom(info) then return end if
6 >    old_close(handle) -- use old close for speed, checks already done...
7 >    if info[2][1] = 'r' then return end if -- only flush writeable files
8 >    old_open(info[1], info[2]) -- using the new open isn't necessary.
9 >end procedure

I did say it was on-the-fly... :)

I can't say that seeking to the beginning of the file is what would be
required of a flush on a read-mode file. I think just ignoring the
request is more correct (MHO).

As for the "only flush writable" 'if', that's correct code. I'm checking
the first element for either "r" or "rb", which would be 'r' in either
case. The first element *has* to be there, so length checking isn't
necessary. old_open() wouldn't have let the new open() put it in
open_log[] if the syntax had been incorrect...

The old_close() call, however, *is* in the wrong place. Well spotted.
<warner_cartoon voice="Sylvester">
Thimply thwap lineth thix and theven for a corrected function.

Lament: Thilly bugth do thilly programth make...
</w_c>
Carl - in a thilly mood.

--
Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek
 aka Cyrek   --    No hyphens :)    --       Bigfoot URL Alias

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu