commit a54107338818766882b3060b61116ea2861f103f Author: Zev Averbach Date: Thu Dec 29 20:59:22 2022 -0400 first iteration diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..cd87d44 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +set -xe + +clang -Wall -Wextra -o zed main.c diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..06a0b41 --- /dev/null +++ b/input.txt @@ -0,0 +1 @@ +Hello, Zed! diff --git a/main.c b/main.c new file mode 100644 index 0000000..78984b7 --- /dev/null +++ b/main.c @@ -0,0 +1,42 @@ +#include +#include +#include + +#define ZED_CAPACITY 1024 + +typedef struct { + char data[ZED_CAPACITY]; + size_t count; +} Editor; + +static Editor editor = {0}; + +int main(int argc, char **argv) +{ + if (argc < 2) { + fprintf(stderr, "Usage: zed \n"); + fprintf(stderr, "ERROR: no input file was provided\n"); + return 1; + } + + const char *file_path = argv[1]; + FILE *f = fopen(file_path, "rb"); + if (f == NULL) { + fprintf( + stderr, + "ERROR: could not open file %s: %s\n", + file_path, + strerror(errno) + ); + return 1; + } + + editor.count = fread(editor.data, 1, ZED_CAPACITY, f); + fwrite(editor.data, 1, editor.count, stdout); + + printf("Input file: %s\n", file_path); + + fclose(f); + + return 0; +} diff --git a/zed b/zed new file mode 100755 index 0000000..1f9c5fa Binary files /dev/null and b/zed differ