askhad-apishev / corewar

0 stars 0 forks source link

Asm task 04 #23

Closed akaruitori closed 4 years ago

akaruitori commented 4 years ago

Added asm-file reading and saving

The main intention was to just save the whole useful data from file into linked list (t_line struct). But I needed to decide what exactly I would do next with data to know how and what I need to read and save. I had a few ideas about on-the-go parsing, but that seem to turn into way too complicated code. So I decided to save lines (segments for binary file -- this will be the next task) before doing any parsing or translation.

The tricky part would be to determine whether the last code line ends with \nor not if that line is actually the last one in the file. In both cases codeline\nEOF (valid) and codelineEOF (not valid) get_next_line() would return 1 and the next time 0, and write into buffer codeline\0. I will use lseek() to 1 byte on the parsing stage to find out if \n was present. And there is a case then the last line in file is a comment or just spaces. As I'm skipping such lines for non-last lines, I'm still saving the last one no matter if it is code or not. So later I could see that the last line is code (so I need lseek()) or not (so no further checks needed, the last code line obviously ended with \n).

Also I added structs to save parsed data, but that is more of a draft to guide the next steps. So some fields may be added/removed later.