From 22df868ef80976f03f87704d26bd5b5e51d4cbd7 Mon Sep 17 00:00:00 2001 From: Zev Averbach Date: Thu, 29 Dec 2022 21:47:38 -0400 Subject: [PATCH] added some terminal things, added debugging to buildfile --- .gitignore | 1 + README.md | 1 + build.sh | 2 +- main.c | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 6c24c44..4d59550 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ zed +*.dSYM/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc1af64 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This is me coding along with Mr. [Tsoding](https://www.twitch.tv/tsoding)'s stream about creating a text editor from scratch using C. diff --git a/build.sh b/build.sh index cd87d44..52876d5 100755 --- a/build.sh +++ b/build.sh @@ -2,4 +2,4 @@ set -xe -clang -Wall -Wextra -o zed main.c +clang -Wall -Wextra -ggdb -o zed main.c diff --git a/main.c b/main.c index 78984b7..a5c8f3d 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,10 @@ #include #include +#include + +#include + #define ZED_CAPACITY 1024 typedef struct { @@ -13,12 +17,24 @@ static Editor editor = {0}; int main(int argc, char **argv) { + if (!isatty(0)) { + fprintf(stderr, "Please run in the terminal!\n"); + return 1; + } + if (argc < 2) { fprintf(stderr, "Usage: zed \n"); fprintf(stderr, "ERROR: no input file was provided\n"); return 1; } + // stores the state of the terminal + struct termios term; + if (tcgetattr(0, &term)) { + fprintf(stderr, "ERROR: could not save the state of the terminal\n"); + return 1; + } + const char *file_path = argv[1]; FILE *f = fopen(file_path, "rb"); if (f == NULL) {