[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apple II text files (again)



In article <93102.093250F0O@psuvm.psu.edu> <F0O@psuvm.psu.edu> writes:
>   Thanks everyone for your help, but unfortunately my routine still isn't
>working.  I'm using an apple IIe with Dos 3.3.  Below is a listing of
>the relevant parts of my program:
>
>10 ONERR GOTO 282
>20 D$ = CHR$(4)
>30 RT$ = CHR$(13)
>32 T$ = CHR#(1)
>87 LN$ = ""
>90 HOME
>100 INPUT "ENTER PRETEST DATE ";DT$
>110 INPUT "ENTER NAME OF OUTPUT FILE ";OF$
>130 PRINT D$;"OPEN ";FL$;",D1"
>132 PRINT D$;"APPEND ";OF$;",D2"
>140 PRINT D$;"READ ";FL$
>160 GET CH$
     ^^^^^^^
     Aha!  This is the culprit right here.  See below.

>170 LN$ = LN$ + CH$
>180 IF CH$ <> RT$ THEN GOTO 160
>210 PRINT D$;"WRITE ";OF$
>220 PRINT LN$
>222 GOTO 140
>250 END
>270 REM ERROR HANDLING ROUTINE
>282 PRINT D$;"CLOSE ";OF$
>284 PRINT D$;"CLOSE ";FL$
>286 POKE 216,0
>290 GOTO 87
>
>   Ok, what happens is the print statements go out to the screen, instead
>of the disk file.  So does the write statement in line 210.
>So what I see is:
>   WRITE filename
>   Print statement output
>   Print statement output
>
>   If anyone has any idea what is wrong, please let me know.  This is
>driving me up the wall!

The problem is that GET command.  The DOS 3.3 I/O state routines assume
that you're using INPUT to get stuff from the file.  GET works, but it fails
to properly reinitialize the state after the character is gotten.  The
result is that DOS in effect forgets about the last carriage return you
printed.  Since DOS commands in DOS 3.3 have to be preceeded by a carriage
return, your WRITE command is never recognized as a DOS command.

Suggested fix:

210 PRINT RT$;D$;"WRITE ";OF$

This fix only works in DOS 3.3.  I don't think it's even necessary in
ProDOS.

I also suggest liberal use of X=FRE(0).  Each pass through your GET loop
adds two new strings to the string table (a new CH$ and a new LN$)...if you
use this routine to copy a large file, you could find yourself hanging for
a LONG time while BASIC cleans up old strings...better to clean them up by
hand while the string table is still small.

               - Neil Parker
--
Neil Parker                 No cute ASCII art...no cute quote...no cute
nparker@cie.uoregon.edu     disclaimer...no deposit, no return...
parker@corona.uoregon.edu   (This space intentionally left blank:           )