[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [StrongED] Time stamps
In message <da221be656.gavin@xxxxxxxxxxxxxxx>
Gavin Wraith <gavin@xxxxxxxxxxxxxxx> wrote:
> In message <e92c0ae656.fjgraute@xxxxxxxxx>
> Fred Graute <fjgraute@xxxxxxxxx> wrote:
>
> > I've done something similar (in Lua) to update my local copy of the
> > StrongED website. As far as I can see it's working fine. How are you
> > comparing the time stamps?
>
> I am using RO 5.23 on a Raspberry Pi3. So 'disk' is an SD card.
> My timestamp-compare code is slightly Byzantine. Function ok
> should return true if either fout (the target) does not exist or if its
> time stamp is earlier than that of fin (the source):
>
> local funny = " has a funny type"
> local ok = \ (fin, fout)
> local r0,r1,r2,r3 = sys (8,23,fout..'\0') -- OS_File
> if r0 == 0 then => true end -- if (fout non-existent)
> assert (r0 == 1, fout..funny)
> local s0,s1,s2,s3 = sys (8,23, fin..'\0')
> assert (s0 == 1, fin..funny)
> r3 & = 0xff
> s3 & = 0xff
> if s3 > r3 then => true end -- if (5-th byte compared)
> if s3 < r3 then => end -- if
> local r2h = (r2 & 0xff000000) >> 6
> local s2h = (s2 & 0xff000000) >> 6
> if s2h > r2h then => true end -- if (4-th byte compared)
> if s2h < r2h then => end -- if
> r2 & = 0x00ffffff
> s2 & = 0x00ffffff
> => (s2 > r2) -- (bottom three bytes compared)
> end -- function
>
> It is probably not optimal, and I may be being excessively cautious
> about avoiding signed comparisons.
No, being careful with signed comparisons is good. Below is the code I
use to check if a rebuild is required, which is equally cautious.
function getfileinfo(file)
riscos.$[wimpblk] = file.."\x00"
local r0,r1,r2,r3 = riscos.sys("OS_File",23,wimpblk)
-- make sure 32 bit values are returned, RiscLua 6 sign extends to 64 bit
return r0,r2 & 0x000000FF,r3 & 0xFFFFFFFF
end -- function
function comparedatestamps(sourcefile,targetfile)
local sourcetype,sourcedatehi,sourcedatelo = getfileinfo(sourcefile)
local targettype,targetdatehi,targetdatelo = getfileinfo(targetfile)
-- times are unsigned but lua treats integers as signed
sourcedatehi = ((sourcedatehi << 8) | (sourcedatelo >> 24))
targetdatehi = ((targetdatehi << 8) | (targetdatelo >> 24))
sourcedatelo = (sourcedatelo & 0x00FFFFFF)
targetdatelo = (targetdatelo & 0x00FFFFFF)
local rebuild = (targettype == 0)
--rebuild = true
if not rebuild then
if (sourcedatehi) == (targetdatehi) then
rebuild = (sourcedatelo) > (targetdatelo)
else
rebuild = (sourcedatehi) > (targetdatehi)
end -- if
end -- if
if rebuild then
print(sourcetype,sourcedatehi,sourcedatelo,sourcefile)
print(targettype,targetdatehi,targetdatelo,targetfile)
print()
end -- if
return rebuild
end -- function
Cheers,
Fred.
--
StrongED Developer
http://www.stronged.iconbar.com/
--
To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxx
List archives and instructions at
http://diy.Torrens.org/RO/StrongED/index.html