Re: Adding to binary files



In article
<Pine.GSO.3.95.iB1.0.1060710005256.23369A-100000@xxxxxxxxxxxxxxxxxxxxxx>
,
"Simon D. Williams" <bb065@xxxxxxxxxxxxxx> wrote:

On Mon, 10 Jul 2006, John B. Matthews wrote:

In article
<Pine.GSO.3.95.iB1.0.1060709140223.10565A-100000@xxxxxxxxxxxxxxxxxxxxxx>
,
"Simon D. Williams" <bb065@xxxxxxxxxxxxxx> wrote:

I have an idea for a program that would output files larger than memory
will allow. Is it possible in ProDOS to either combine file segments on
disk, or append data to an existing file?
-s
_____
|[LD8]! :::::::: RetroChallenge 2006 Endurance Blog :::::::::
| o. | ::::::::::: " 8-bit to the Bitter End! " ::::::::::::
!__!__! ::::::::: http://www.chebucto.ns.ca/~bb065/ :::::::::

From assembly, you should be able to append to a file by doing OPEN
($C8), GET_EOF ($D1), SET_MARK ($CE), WRITE ($CB) and CLOSE ($CC).

From Basic, the APPEND command works with sequential text files.

John
[...]

Is there a way to do this with _binary_ files?

[...]
You don't mention whether you're working from assembly or Basic, so I'll
address both.

The assembly approach should work with either text or binary. If you
SET_EOF ($D0) past the current EOF and do a SET_MARK between the old EOF
and the new, you'll create a sparse file. Instead, get the EOF, set the
mark to it and write. The "ProDOS 8 Technical Reference Manual" is your
friend.

Basic APPEND under ProDOS accepts a T (type) and L (record length)
parameter, so you can try something like

10 d$=chr$(4)
20 print d$;"APPEND myfile,Tbin,L1"
30 print "Hello"
40 print d$;"CLOSE"

Because the type is specified, the file must already exist. Binary
output may be awkward. Also, print without a trailing semicolon will
output a carriage return. AFAIK, you don't need to know the file length
_a_priori_, as APPEND sets the mark to EOF.

If you're from moria:-), here's a pre-release version of the ProDOS
Basic programming documentation:

http://www.apple2.org.za/gswv/a2zine/Docs/ProDOS.txt

--
John Matthews
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/
.



Relevant Pages

  • Re: fscanf
    ... It just says append is a possible mode with a+ also which is append-read mode. ... The value EOF is returned if the end of input is reached before either the first ... means checking the values returned by things like fscanf. ... Wouldn't you be curious, whether fscanf converted zero, one, or two items? ...
    (comp.lang.c)
  • Re: how to write to a file without race condition
    ... >>No, each of them will atomically seek to the current EOF, append their ... then the next one will write at the new EOF. ... (James Antill *agreed* with it, ... to set O_APPEND rather than using lseek(). ...
    (comp.unix.programmer)
  • Re: Adding to binary files
    ... On Mon, 10 Jul 2006, John B. Matthews wrote: ... you should be able to append to a file by doing OPEN ... John Matthews ... jmatthews at wright dot edu ...
    (comp.sys.apple2.programmer)
  • Simple RMS question
    ... I want to open a sequential file using RMS, append a single line and close it. ... When calling SYS$PUT I get the error %RMS-F-NEF which is not positioned to EOF on $PUT if the file is nonblank. ...
    (comp.os.vms)
  • Re: leading null characters produced in script...
    ... :> When a file is opened in append mode, there is an implied seek to EOF ... when your log rotation truncates the ... :> continuing at its current offset. ...
    (comp.os.linux.misc)