Hugh,

I had one last thought while reading this that might be a clever approach. Read a little bit off the front of the currently running stack (since you KNOW that's a valid stack) and compare it to the file in question. The advantages are that you only have to read a tiny bit of the file, and that the script should continue to work even if/when Rev formats change. It's not foolproof - there's always the chance that another type of file would have the same first bytes, but it's probably very unlikely in practice and could always be balanced with some sort of fatal error if the file did indeed end up being bogus when you actually try to load it.

Reading from a file should be perfectly safe even if it is in use - writing is the dangerous one. The only caveat I can think of is that the current stack that you are using to compare against must exist on disk and not *only* in memory.

function isAStack tFilePath
   ## the file path to the current stack
   put value(word 2 of the long name of this stack) into tStackPath

   ## nibble off the first 8 bytes
   open file tStackPath for binary read
   read from file tStackPath for 8
   put it into myFirst8Bytes
   close file tStackPath

   ## check the first 8 bytes of the file in question
   open file tFilePath for binary read
   read from file tFilePath for 8
   put it into testFirst8Bytes
   close file tFilePath

   ## are they the same?
   return (myFirst8Bytes = testFirst8Bytes)
end isAStack

Hi Klaus, Brian, David:

Good catches. I don't think I dare use open/read/close in case the file (and
it could be any file) is in use, and  testing the suffix is not always
reliable (I am allowing data stacks to be suffix-less). Since I've never used a shell script, I'm not sure what differentiates them from a 'normal' stack in terms of initial stackfile characters. I don't think there are any differences, so a bit hard to be 100% foolproof it this case. Finally, since this is for ssBk and it is purposefully always saved in 2.4 format (as several people have requested for project compatibility purposes), I think I shall run with my
original.

BUT your comments have been most instructive, and I thank you  all.

/H




_______________________________________________
metacard mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/metacard

_______________________________________________
metacard mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/metacard

Reply via email to