04-30-2021, 10:12 PM
I needed a program to split a CSV file at each line feed character after loading the file into the Emu48. The CSV file contains local coordinates and descriptions of a fictitious piece of land. The point file is a list of strings containing that information. The integer in the first position of the list represents the number of available positions.
CSV @ Comma-Separated Values file
"1,5000,5000,SW COR■
2,5300,5000,NW COR■
3,5300,5400,NE COR■
4,5000,5400,SE COR"
File @ Point file
{ 4 "" "" "" "" }
FIN @ 240.5 bytes, # 6054h checksum
\<< FILE 1 GET CSV
DUP SIZE 10 CHR 1 \->
@ numpoints - local variable for size of list.
@ csv - local variable for CSV file.
@ size - local variable for size of CSV file. Represents end of file.
@ char - local variable for line feed character.
@ start - local variable for start of substring.
numpoints csv size
char start
\<< MEM DROP 1 @ MEM performs garbage collection.
numpoints
START csv start
size SUB DUP char
@ Remove substring if line feed character is in string.
POS DUP 0 >
\<< DUP 'start'
STO+ 2 - 1 SWAP SUB @ 'start' is moved ahead after each iteration.
\>> IFT
NEXT DROP
numpoints \->LIST
\>>
\>>
Any suggestions to improve the code would be greatly appreciated!
CSV @ Comma-Separated Values file
"1,5000,5000,SW COR■
2,5300,5000,NW COR■
3,5300,5400,NE COR■
4,5000,5400,SE COR"
File @ Point file
{ 4 "" "" "" "" }
FIN @ 240.5 bytes, # 6054h checksum
\<< FILE 1 GET CSV
DUP SIZE 10 CHR 1 \->
@ numpoints - local variable for size of list.
@ csv - local variable for CSV file.
@ size - local variable for size of CSV file. Represents end of file.
@ char - local variable for line feed character.
@ start - local variable for start of substring.
numpoints csv size
char start
\<< MEM DROP 1 @ MEM performs garbage collection.
numpoints
START csv start
size SUB DUP char
@ Remove substring if line feed character is in string.
POS DUP 0 >
\<< DUP 'start'
STO+ 2 - 1 SWAP SUB @ 'start' is moved ahead after each iteration.
\>> IFT
NEXT DROP
numpoints \->LIST
\>>
\>>
Any suggestions to improve the code would be greatly appreciated!