From ed560d6972a1f344df1514277d83fbf7e924c0e1 Mon Sep 17 00:00:00 2001 From: Zev Averbach Date: Tue, 10 Jan 2023 14:30:21 +0100 Subject: [PATCH] progressed, replaced gdb with lldb --- build.sh | 2 +- main.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 52876d5..7adfce5 100755 --- a/build.sh +++ b/build.sh @@ -2,4 +2,4 @@ set -xe -clang -Wall -Wextra -ggdb -o zed main.c +clang -Wall -Wextra -glldb -o zed main.c diff --git a/main.c b/main.c index a5c8f3d..8dbae78 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -31,7 +32,13 @@ int main(int argc, char **argv) // 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"); + fprintf(stderr, "ERROR: could not save the state of the terminal: %s\n", strerror(errno)); + return 1; + } + + term.c_lflag &= ~ECHO; + if (tcsetattr(0, 0, &term)) { + fprintf(stderr, "ERROR: could not update the state of the terminal: %s\n", strerror(errno)); return 1; } @@ -48,11 +55,21 @@ int main(int argc, char **argv) } editor.count = fread(editor.data, 1, ZED_CAPACITY, f); + printf("\ncontents of %s:\n\n", file_path); fwrite(editor.data, 1, editor.count, stdout); - printf("Input file: %s\n", file_path); - fclose(f); + bool quit = false; + while (!quit && !feof(stdin)) { + int x = fgetc(stdin); + if (x == 'q') { + quit = true; + } + } + + term.c_lflag |= ECHO; + tcsetattr(0, 0, &term); + return 0; }