[net.micro.apple] Help with DOS 3.3 write end of file

dr@ski.UUCP (David Robins) (02/02/86)

2 Feb 86 00:12:57 GMT
Distribution: usa
Organization: Smith-Kettlewell Institute, S.F., CA.
Lines: 41

> 				 Ted
> 				 milnet address "medin@nosc-shark"
Although you didn't specify, I assume you are dealing with a
SEQUENTIAL text file.

If you look in the Apple DOS Programmer's Manual, page 66, the answer
is right there.  

"This section gives you a new use for OPEN.  Suppose your program
routinely replaces an old text file with a new one with the same name.
When the new one is shorter than the old one, the new one will have
part of the old file hanging on the the end unless the program first
deletes the old one.  If you don't want this extra text at the end of
the file, delete the old file before writing to the new one.  The next 
program shows you how to delete a file and open it for new data,
whether or not the file already exists."
	....................................
	40  PRINT D$;"OPEN ";FILE$
	50  PRINT D$;"DELETE ";FILE$
	60  PRINT D$;"OPEN ";FILE$


		WRITE

	160 PRINT D$;"CLOSE ";FILE$

I believe the EOF marker is a 00, (see Beneath Apple DOS) which I THINK
is placed there by the CLOSEing of a file. 
I don't know why overwriting a sequential text
file and ending it in a 00 won't stop the extra text from getting in
the way.  In any case, most users follow the OPEN, DELETE, OPEN
business to keep things straight.
-- 
====================================================================
David Robins, M.D. 
Smith-Kettlewell Institute of Visual Sciences
2232 Webster St; San Francisco CA 94115
415/561-1705
			{ihnp4,qantel,dual}!ptsfa!ski!dr

The opinions expressed herein do not reflect the opinion of the Institute!

kamath@reed.UUCP (Sean Kamath) (02/06/86)

Here's an interesting tidbit.  If anyone has dossource (Complete
disassembly of dos 3.3) or is in the mood, take a look at where dos
tries to read or write a file.  I forget exactly where it is, but notice
that it checks to see if the file is open.  If it isn't then it opens
it.  Therefore, there is no real need to open a file before reading or
writing it. try it sometime.  Also, you may have noticed that
Applewriter won't create a new file if you try to read one that isn't
there.  But when you try to open one that doesn't exist from your own
programs, you're left with a one sectore file by that name.  How does
Applewriter do it?  Take a look at Beneath Apple Dos.  You'll notice
that there is a marker in dos that tells it if a command can creat a new
file.  They are "open" "save" etc.  Ones that cannot are "load" "delete"
etc.  In the case of open, if you stick a hex 22 in the right spot, no
nasty on sector files.  On the other hand, if you try to open a new file
to write to, you must replace that 22 with a 23.  If anyone's going
crazy because they can't live with out the exact location(s), write me.

Sean Kamath


-- 
________________________________________________________________________________

UUCP {ihnp4,decvax,ucbcad}!tektronix!reed!kamath

And I looked again
And the monster was me...