73 lines
1.5 KiB
Text
73 lines
1.5 KiB
Text
include 'std/args.fa'
|
|
include 'std/lstd.fa'
|
|
include 'std/mem/gmem.fa'
|
|
|
|
|
|
macro MAX_BUFFER 2048 end
|
|
|
|
|
|
fun main [ str str int ] int eo
|
|
2 argc lst if
|
|
label print_input
|
|
%MAX_BUFFER #malloc as input_buffer
|
|
|
|
%MAX_BUFFER
|
|
@input_buffer deref
|
|
%STDIN
|
|
%SYS_read sys 4
|
|
|
|
copy 0 eql if
|
|
pop
|
|
%EXIT_SUCCESS ret
|
|
end
|
|
|
|
@input_buffer deref %STDOUT #fputs
|
|
|
|
%MAX_BUFFER @input_buffer deref
|
|
#mfree pop
|
|
|
|
goto print_input
|
|
end
|
|
|
|
1 argc sub as print_files_idx_max
|
|
1 as print_files_idx
|
|
|
|
@print_files_idx deref
|
|
|
|
label print_files
|
|
@print_files_idx deref #get_arg as file
|
|
0 @file deref %SYS_open sys 3 as fd
|
|
|
|
0 @fd deref lst if
|
|
"Invalid input file (I was too lazy to calculate the len): " %STDERR #fputs
|
|
10 @file deref %STDERR #fputs
|
|
10 #putc
|
|
%EXIT_FAILURE ret
|
|
end
|
|
|
|
%MAX_BUFFER #malloc as file_buffer
|
|
|
|
%MAX_BUFFER
|
|
@file_buffer deref
|
|
@fd deref
|
|
%SYS_read sys 4
|
|
|
|
@file_buffer deref %STDOUT #fputs
|
|
|
|
%MAX_BUFFER @file_buffer deref
|
|
#mfree pop
|
|
|
|
@fd deref %SYS_close sys 2
|
|
|
|
@print_files_idx deref
|
|
@print_files_idx_max deref grt if
|
|
@print_files_idx 1 @print_files_idx deref add point
|
|
goto print_files
|
|
end
|
|
|
|
10 #putc
|
|
|
|
%EXIT_SUCCESS
|
|
end
|
|
|
|
#main #exit
|