summaryrefslogtreecommitdiff
path: root/src/echo.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2024-11-20 21:11:38 -0800
committerKai Stevenson <kai@kaistevenson.com>2024-11-20 21:11:38 -0800
commit711eb1d91832267bdd1fe2bc57eeebba9e637c52 (patch)
tree6cbd10ee276f1cb8119d2528cc1f7a04894228de /src/echo.c
Diffstat (limited to 'src/echo.c')
-rw-r--r--src/echo.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/echo.c b/src/echo.c
new file mode 100644
index 0000000..1efbcda
--- /dev/null
+++ b/src/echo.c
@@ -0,0 +1,29 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "echo.h"
+#include <string.h>
+int main(int argc, char** argv) {
+ char* path;
+ if (argc > 0) {
+ path = argv[1];
+ }
+ else {
+ exit(0);
+ }
+ char* content = read_file(path);
+ parse(content);
+}
+char* read_file(char* path) {
+ FILE* file = fopen(path, "r");
+ if (file == NULL) {
+ printf("file%s does not exist\n", path);
+ }
+ fseek(file, 0, SEEK_END);
+ unsigned long int length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+ char* out = malloc((length + 1) * sizeof(char));
+ fread(out, length, 1, file);
+ fclose(file);
+ out[length] = '\0';
+ return out
+}