Kim,
Clint may have been thinking of something vaguely like this (untested) code
that hooks and replaces reads. I haven't considered exactly what happens with
different types of files and if stat ever fails. If the behaviour needs to
change based on open parameters then open/close would need to be hooked to
establish a table of files which would be used by new_reads to figure out if
stat is needed. For instance for messaging, it isn't so it could be skipped.
procedure main()
initialize_new_reads()
# ...
# do stuff
end
procedure initialize_new_reads(f,i)
initial {
reads :=: new_reads() # hook reads for future, we could also use
proc("reads") but it doesn't preserve chain if more are hooked
return
}
end # always fail on subsequent calls
procedure new_reads(f,i)
if /f | type(f) ~== "file"then {
i := f #handle reads(i) - can't recall if this is valid form
like write(), omit if not
f := &input # handle case of omitted file reads(,i)
}
if i = -1 then {
i := stat(f).size |
&null # i will be null on failure - may not be desirable
behaviour
# runerr(500,f) # alternative error may be undesirable as well
}
return new_reads(f,i) # call original reads
end
David
>________________________________
> From: Kim <[email protected]>
>To: [email protected]
>Sent: Tuesday, July 17, 2012 9:56:00 PM
>Subject: Re: [Unicon-group] reads(file, -1) not supported?
>
>
>Clinton Jeffery <jeffery@...> writes:
>> OK, so this divergence of the implementation from the spec is now implemented
>for normal files in svn and will be supported in future binaries builds. In
>the
>meantime, is anyone clever enough to write a library module version of open()
>that implements Jafar's solution at the Unicon level?reads(... -1) was
>originally introduced in the messaging facilities (mode "m" only feature) and
>when the book was being written it was decided to implement for regular files
>as
>well. But no one ever volunteered before now. There are no current plans to
>support reads(... -1) for sockets, windows, etc.Kim, thanks for the
>prod!Cheers,Clint
>
>Thanks Jafar for the workaround.
>
>I wrote in the end:
>
> kf := open(fn, "ru") | stop(ErrorMsg[2])
> line := reads(kf, stat(kf).size)
>
>which works as required.
>
>Clint, do you mean a library module version of reads()? I don’t see a problem
>with open(). (Not that I am clever enough to do either!)
>
>Cheers
>Kim
>
>
>
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and
>threat landscape has changed and how IT managers can respond. Discussions
>will include endpoint security, mobile security and the latest in malware
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>_______________________________________________
>Unicon-group mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/unicon-group
>
>
>------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group