Scripting Additions Guide

CHAPTER 2
Scripting Addition Commands
Using Read/Write Commands 79
set postBuffer to read fileRefNum from 1
(* before writing new record, file mark must be reset to
beginning of file; to do this, write an empty string to the
beginning of file *)
write "" to fileRefNum starting at 0
WriteNewRecord(recordToAdd, fieldDelimiter, ¬
recordDelimiter, fileRefNum)
--now add back the rest of the record
write postBuffer to fileRefNum
return
end if
(* if the record is to be added somewhere other than at the
beginning of the file, the rest of the AddRecord handler is
executed *)
repeat with idx from 1 to addWhere - 1
repeat (readxTimes) times
set q to read fileRefNum until fieldDelimiter
set accumulatedSize to accumulatedSize + (length of q)
end repeat
if readxTimes is not numberOfFields then
set q to read fileRefNum until recordDelimiter
set accumulatedSize to accumulatedSize + (length of q)
end if
end repeat
(* read from beginning of file to the byte at which the new
record is to be added *)
set postBuffer to read fileRefNum from accumulatedSize + 1
(* before writing new record, set file mark to byte at which
new record is to be added; to do this, write an empty
string to that byte *)
write "" to fileRefNum starting at accumulatedSize + 1
WriteNewRecord(recordToAdd, fieldDelimiter, recordDelimiter, ¬
fileRefNum)