1 ; sped - the stupidly pointless editor
21 banner_str db `SPED - the stupidly pointless editor\n`, 0x00
22 readfile_str db `reading file %s\n`, 0x00
23 nofile_str db `no file provided\n`, 0x00
24 argcount_str db `there are %d args\n`, 0x00
25 wrongfile_str db `unable to open file, error code: %i\n`, 0x00
26 char_str db `read this char: %i\n`, 0x00
27 printfint_str db `int: %i\n`, 0x00
37 ; read command line args
42 ; display error msg if no file
49 mov ebx, DWORD [ebp+_ARGV]
69 ; reads file line by line
72 ; eax - pointer to mem
79 %define BUF_PTR 16 ; malloced array of strings
86 mov DWORD [ebp-FILE_HANDLE], 0x00
87 mov DWORD [ebp-IS_EOF], 0x00
88 mov DWORD [ebp-LINES_READ], 0x00
92 mov [ebp-BUF_PTR], eax
96 mov ebx, [ebp+_FILE_NAME]
100 mov [ebp-FILE_HANDLE], eax
102 ; check if file was open successfully
112 ; check if eof was reached
113 cmp DWORD [ebp-IS_EOF], 1
116 push DWORD [ebp-FILE_HANDLE]
120 mov [ebp-IS_EOF], ebx
125 ; make string buffer bigger
126 mov eax, DWORD [ebp-LINES_READ]
131 push DWORD [ebp-BUF_PTR]
133 mov DWORD [ebp-BUF_PTR], eax
135 ; write string to buffer
136 mov eax, DWORD [ebp-BUF_PTR]
141 add DWORD [ebp-LINES_READ], 1
148 mov ebx, [ebp-FILE_HANDLE]
162 ; reads a line until newline character is reached
165 ; eax: location to buffer
168 %define _FILE_HANDLE 8
169 %define CHAR_COUNT 4 ; count number of characters read
170 %define BLOCK_COUNT 8 ; number of 64 blocks we've read
171 %define STR_PTR 12 ; malloced buffer to store read string
178 mov DWORD [ebp-CHAR_COUNT], 0x00
179 mov DWORD [ebp-BLOCK_COUNT], 0x00
183 mov [ebp-STR_PTR], eax
185 push DWORD [ebp-STR_PTR]
191 cmp BYTE [ebp-CHAR_COUNT], 63 ; leave one byte for null byte
192 jne _readLine_notfull
196 ; read a single character
198 mov ebx, [ebp+_FILE_HANDLE]
199 mov ecx, [ebp-STR_PTR]
200 add ecx, [ebp-CHAR_COUNT]
206 ; mov ecx, [ebp-STR_PTR]
207 ; add ecx, [ebp-CHAR_COUNT]
212 cmp eax, 0 ; eax has zero on eof
213 jne _readLine_not_eof
219 mov eax, [ebp-STR_PTR]
220 add eax, [ebp-CHAR_COUNT]
221 cmp DWORD [eax], 0x0a
222 jne _readLine_not_newline
225 _readLine_not_newline:
227 add DWORD [ebp-CHAR_COUNT], 1
232 mov eax, DWORD [ebp-STR_PTR]