summaryrefslogtreecommitdiff
path: root/tnslc/read_file_test.tnsl
diff options
context:
space:
mode:
Diffstat (limited to 'tnslc/read_file_test.tnsl')
-rw-r--r--tnslc/read_file_test.tnsl40
1 files changed, 40 insertions, 0 deletions
diff --git a/tnslc/read_file_test.tnsl b/tnslc/read_file_test.tnsl
new file mode 100644
index 0000000..60c4c5b
--- /dev/null
+++ b/tnslc/read_file_test.tnsl
@@ -0,0 +1,40 @@
+:include "c_wrap.tnsl"
+
+{}uint8 usage_msg = "Usage: read_file.exe [file to read] [file to write]\n\0"
+{}uint8 print_one = "\0\0"
+{}uint8 nl = "\n\0"
+
+/; main (int argc, ~~uint8 argv) [int]
+
+ # On windows, the first two arguments are passed in RCX and RDX, so we need to
+ # update their positions here or else tnsl will have garbage values in r8 and r9
+ asm "mov r8, rcx"
+ asm "mov r9, rdx"
+
+ # If on linux, you would use rdi and rsi instead of rcx and rdx, respectively
+ # simply comment out the bove asm, and uncomment the below lines
+ # asm "mov r8, rdi"
+ # asm "mov r9, rsi"
+
+ /; if (argc < 2)
+ _printf(~usage_msg{0})
+ return 1
+ ;/
+
+ _printf(argv{1})
+ _printf(~nl{0})
+
+ ~void write_handle = _create_file(argv{1})
+
+ _print_num(~_dec{0}, write_handle)
+
+ int ln = cstr_len(argv{1})
+
+ /; loop (int i = 0; i < ln) [i++]
+ _write_byte(write_handle, ~argv{1}{i})
+ ;/
+
+ _close_file(write_handle)
+
+ return 0
+;/ \ No newline at end of file