Creating a library

Discussions related to database technologies, file handling, directories and storage
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Creating a library

Post by Ric »

Evening All,
I am trying to write a program to convert a raw list of openGL constants in to a library file for bbcsdl/bb4w. The following program successfully converts the text file into a structure(d) list but when i save it to file i can not read it with bb4w. The error "line too long" occurs. Pleasde can someone tell me how to modify line 440 and onwards to solve my problem. Thanks in advance Ric.

Code: Select all

   10 DIM const{(2750) name$,value$}
   40 
   50 c% = OPENIN("constants.txt")
   60 d% = OPENOUT("myConstants.bbc")
   70 f$ = ""
   80 g$ = ""
   90 l% = 0
  100 
  110 REPEAT
  120   
  130   f$ = ""
  140   REPEAT
  150     e% = BGET#c%
  160     f$+=CHR$(e%)
  170   UNTIL e% = 32
  180   IF LEN(f$) < 55 THEN f$ += STRING$(55-LEN(f$), " ")
  190   REPEAT
  200     e% = BGET#c%
  210   UNTIL e% = 120
  220   
  230   g$ = ""
  240   REPEAT
  250     e% = BGET#c%
  260     g$ += CHR$(e%)
  270   UNTIL e% = 41
  280   
  290   g$ = LEFT$(g$,LEN(g$)-1)
  300   g$ = "= &" + g$
  310   
  320   REM PRINT f$,g$
  330   
  340   const{(l%)}.name$ = f$
  350   const{(l%)}.value$ = g$
  360   
  370   l% += 1
  380   e% = BGET#c%
  390   
  400 UNTIL e% = 46
  410 
  420 PRINT l%
  430 
  440 PTR#d% = 0
  450 FOR f% = 0 TO l%
  460   
  470   const{(f%)}.name$ = STR$(f%) + " " + const{(f%)}.name$ + const{(f%)}.value$ + CHR$(13)
  480   PRINT#d%, const{(f%)}.name$
  
  500 NEXT
  510 
  520 CLOSE#0
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
User avatar
JeremyNicoll
Posts: 73
Joined: Sun 26 Jul 2020, 22:22
Location: Edinburgh

Re: Creating a library

Post by JeremyNicoll »

You don't say how you're trying to read the file later. I expect the "line too long" is because the function reading it expects (say) to see CR LF at the end of each line, but your PRINT# only follows each string it writes out with a CR.

Look at doc for PRINT# and BPUT# and REaD# /INPUT'# and GET$ etc.
nvingo
Posts: 42
Joined: Sat 28 May 2022, 22:40

Re: Creating a library

Post by nvingo »

Ric wrote: Sat 06 Apr 2024, 18:48 Evening All,
I am trying to write a program to convert a raw list of openGL constants in to a library file for bbcsdl/bb4w. The following program successfully converts the text file into a structure(d) list but when i save it to file i can not read it with bb4w. The error "line too long" occurs. Pleasde can someone tell me how to modify line 440 and onwards to solve my problem. Thanks in advance Ric.

Code: Select all

   10 DIM const{(2750) name$,value$}
   40 
   50 c% = OPENIN("constants.txt")
   60 d% = OPENOUT("myConstants.bbc")
   70 f$ = ""
   80 g$ = ""
   90 l% = 0
  100 
  110 REPEAT
  120   
  130   f$ = ""
  140   REPEAT
  150     e% = BGET#c%
  160     f$+=CHR$(e%)
  170   UNTIL e% = 32
  180   IF LEN(f$) < 55 THEN f$ += STRING$(55-LEN(f$), " ")
  190   REPEAT
  200     e% = BGET#c%
  210   UNTIL e% = 120
  220   
  230   g$ = ""
  240   REPEAT
  250     e% = BGET#c%
  260     g$ += CHR$(e%)
  270   UNTIL e% = 41
  280   
  290   g$ = LEFT$(g$,LEN(g$)-1)
  300   g$ = "= &" + g$
  310   
  320   REM PRINT f$,g$
  330   
  340   const{(l%)}.name$ = f$
  350   const{(l%)}.value$ = g$
  360   
  370   l% += 1
  380   e% = BGET#c%
  390   
  400 UNTIL e% = 46
  410 
  420 PRINT l%
  430 
  440 PTR#d% = 0
  450 FOR f% = 0 TO l%
  460   
  470   const{(f%)}.name$ = STR$(f%) + " " + const{(f%)}.name$ + const{(f%)}.value$ + CHR$(13)
  480   PRINT#d%, const{(f%)}.name$
  
  500 NEXT
  510 
  520 CLOSE#0
Is there any possibility your source data file contains non-displayable characters (eg chr$13 CR)?
It strikes me that the only processing done between input and output is to first pad the data to LEN55 with spaces, then concatenate the index to the start of each entry.
Two things there:
The length if the index (number of digits) varies, from 1 to 4? Does this cause the line length exceeded?
You declare an array to store the whole file in memory (yet each entry is processed individually) this seems wasteful. You should be able to read each entry from the source, add the index and padding, then write it to the output file in the one loop, without any array.
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.
jgharston
Posts: 39
Joined: Thu 05 Apr 2018, 14:08

Re: Creating a library

Post by jgharston »

"line too long" doesn't appear to be a program error. I've only ever got that when pasting code into the editor, not when running a program. There's an odd gap in your posted code between line 480 and line 500. Have you accidently appended line 490 to the end of line 480?
Line too long
An attempt to concatenate two program lines, by typing backspace when the cursor is at the beginning of the line, would cause the maximum line length to be exceeded.
Ric
Posts: 208
Joined: Tue 17 Apr 2018, 21:03

Re: Creating a library

Post by Ric »

Thanks for the replies.
I am trying to create a library in bb4w so the gui reading the file is bb4w. I will try adding a LF character on the end of each line as well.
Kind regards Ric



Many Thanks,
I was using CHR$(13) instead of CHR$(10), now works fine.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023