commit 5162804270318e46adc45e52c11c2f040d4af96f Author: Garritt McCune Date: Tue Dec 28 20:09:33 2021 +0000 Initial commit, can read from a list of files passed. diff --git a/assm b/assm new file mode 100755 index 0000000..3f39161 Binary files /dev/null and b/assm differ diff --git a/misc/test.asm b/misc/test.asm new file mode 100644 index 0000000..3f6f3f9 --- /dev/null +++ b/misc/test.asm @@ -0,0 +1,6 @@ +; comments are ignored +; This is a very simple test file for an assemblier. +mov r1, 5 ; move the immediate value 5 into r1 +add r1, 5 ; add 5 into r1 +int 21 ; maybe that will call some string drawing BIOS-like routine +ret ; return from 'call' if there were such a thing \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..02176cc --- /dev/null +++ b/src/main.c @@ -0,0 +1,44 @@ +#include +#include + +void print_file(char*); + +int main(int argc, char* args[]) { + const char *input_files[argc - 1]; + + if (argc == 1) { + printf("Input files required.\n"); + return -1; + } + + // for (int i = 1; i < argc; i++) { + // input_files[i - 1] = args[i]; + // print_file(args[i]); + // } + + print_file(args[1]); +} + +void print_file(char* file_path) { + FILE *file; + char* line = NULL; + size_t len = 0; + ssize_t bytes_read; + + file = fopen(file_path, "r"); + + if (!file) { + printf("Failed to open '%s' for reading.\n", file_path); + return; + } + + while((bytes_read = getline(&line, &len, file)) != -1) { + printf("%s", line); + } + + printf("\n"); + + fclose(file); + + if (line) free(line); +} \ No newline at end of file