Help with reading text file in GFA

GFA BASIC-related articles in here please
Post Reply
User avatar
Kirkman
Captain Atari
Captain Atari
Posts: 197
Joined: Fri Sep 03, 2010 2:29 am
Contact:

Help with reading text file in GFA

Post by Kirkman »

I'm trying to write a simple GFA Basic program using v3.5 in Hatari.

The purpose of the program is to call Larry Mears' new Instant Graphics TTP program, while passing the name of an artwork file as a parameter to the TTP.

I wrote the following code, based on old posts I read here, and it works great when compiled:

Code: Select all

file$="A:\IGNITE.IG"
c$=CHR$(LEN(file$))+file$
~SHEL_WRITE(1,1,0,c$,"A:\IGX1220.TTP")
Now, I want to revise this program so that instead of using a hard-coded artwork filename, the program will instead read the filename from a text file called IGX.INF.

Here's the revised code I wrote:

Code: Select all

file$=""
CLOSE #1
OPEN "I",#1,"A:\IGX.INF"
WHILE EOF(#1)=0
  LINE INPUT #1,buffer$
  file$=file$+buffer$
WEND
CLOSE #1
IF file$<>""
  c$=CHR$(LEN(file$))+file$
  ~SHEL_WRITE(1,1,0,c$,"A:\IGX1220.TTP")
ENDIF
Unfortunately, when I compile it and try to run the .PRG, it gives me an Error 026.

Clearly there's a problem reading the text file. It seems like a really straightforward task. Can anyone tell me what I'm doing wrong? How can I fix this?
I'm the guy behind Break Into Chat, ATASCIItube, and many other projects.
User avatar
DarkLord
Ultimate Atarian
Ultimate Atarian
Posts: 5782
Joined: Mon Aug 16, 2004 12:06 pm
Location: Prestonsburg, KY - USA
Contact:

Re: Help with reading text file in GFA

Post by DarkLord »

I'd contact Lonny (LP). He maintains the GFA stuff and is pretty much expert level
awesomeness when it comes to GFA. :)
Welcome To DarkForce! http://www.darkforce.org "The Fuji Lives.!"
Atari SW/HW based BBS - Telnet:darkforce-bbs.dyndns.org 1040
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3454
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with reading text file in GFA

Post by charles »

eof reached =026

is the file being loaded above 32768 bytes?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3454
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with reading text file in GFA

Post by charles »

im no role model gfa expert
but why is file length only required to be 1 eight bit character?
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
Kirkman
Captain Atari
Captain Atari
Posts: 197
Joined: Fri Sep 03, 2010 2:29 am
Contact:

Re: Help with reading text file in GFA

Post by Kirkman »

charles wrote:eof reached =026

is the file being loaded above 32768 bytes?
No, it's only 12 bytes.
charles wrote:but why is file length only required to be 1 eight bit character?
I wasn't totally sure why the CHR/LEN stuff was necessary, but it *does* work. It came from a reply to an old post written by LP.

After a bit more research, I found this passage in the GFA Basic Compendium which seems to explain it:
... The first character of the command line contains it's length (maximum 127). This is known as a Pascal style string. ...
I'm the guy behind Break Into Chat, ATASCIItube, and many other projects.
czietz
Hardware Guru
Hardware Guru
Posts: 2819
Joined: Tue May 24, 2016 6:47 pm

Re: Help with reading text file in GFA

Post by czietz »

My guess is that you didn't terminate the (last) line in "A:\IGX.INF" with a newline (CR/LF). LINE INPUT reads until it finds a newline and will hit EOF if the line is not terminated.

PS: I wonder why you even read multiple lines from IGX.INF in a WHILE loop.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3413
Joined: Sun Aug 03, 2014 5:54 pm

Re: Help with reading text file in GFA

Post by ThorstenOtto »

The error codes can be looked up in the GFA-Basic compendium, for example here: http://tho-otto.de/hypview/hypview.cgi? ... &index=480

I also wonder why you read lines in a loop when you need only a single filename.

Another problem could be the initial close #1 (don't know how it behaves when the file channel was not opened before)
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3454
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with reading text file in GFA

Post by charles »

heres my working of it all

Code: Select all

'
' CLOSE #1
'
' a$="a:\ignite.ig"
'
' OPEN "o",#1,"d:\igx.inf"
' a%=LEN(a$)
' BPUT #1,V:a$,a%
' CLOSE #1
'
a$=""
'
OPEN "i",#1,"A:\igx.inf"
a%=LOF(#1)
a$=SPACE$(a%)
BGET #1,V:a$,a%
CLOSE #1
'
PRINT a$
'
f$=UPPER$(a$)
c$=CHR$(LEN(f$))+f$
~SHEL_WRITE(1,1,0,c$,UPPER$("a:\igx1220.ttp"))
'
END

The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3454
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with reading text file in GFA

Post by charles »

I see now
yes len of filename
not len of file

: )
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 3454
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Help with reading text file in GFA

Post by charles »

simpler method

Code: Select all

SAVE "d:\igshel.gfa"
LIST "d:\igshel.lst"
'
CLOSE #1
'
a$="A:\igx.inf"
'
OPEN "o",#1,a$
PRINT #1,"a:\ignite.ig"
CLOSE #1
'
IF EXIST(a$)
OPEN "i",#1,a$
INPUT #1,a$
CLOSE #1
'
c$=CHR$(LEN(a$))+a$
~SHEL_WRITE(1,1,0,c$,UPPER$("a:\igx1220.ttp"))
ENDIF
'
END

The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
Kirkman
Captain Atari
Captain Atari
Posts: 197
Joined: Fri Sep 03, 2010 2:29 am
Contact:

Re: Help with reading text file in GFA

Post by Kirkman »

Thanks everyone for your questions and suggestions. You all steered me to something that works!

Here's where I landed. I revised it to allow the .INF file to include multiple filenames, one per line, and the program will pass all the filenames as a space-delimited list to the IGX TTP (which supports display multiple files).

Code: Select all

ttp_file$="A:\IGX1220.TTP"
inf_file$="A:\IGX.INF"
ig_files$=""
'
CLOSE #1
'
IF EXIST(inf_file$)
  OPEN "I",#1,inf_file$
  '
  WHILE EOF(#1)=0
    buffer=INP(#1)
    IF buffer>31 AND buffer<127
      ig_files$=ig_files$+CHR$(buffer)
    ELSE
      IF buffer=10
        ig_files$=ig_files$+" "
      ENDIF
    ENDIF
  WEND
  '
  ' PRINT ig_files$
  CLOSE #1
  '
  ig_files$=TRIM$(ig_files$)
  '
  IF ig_files$<>""
    c$=CHR$(LEN(ig_files$))+ig_files$
    ~SHEL_WRITE(1,1,0,c$,ttp_file$)
  ENDIF
ENDIF
I'm the guy behind Break Into Chat, ATASCIItube, and many other projects.
Post Reply

Return to “GFA BASIC”