added some terminal things, added debugging to buildfile

This commit is contained in:
2022-12-29 21:47:38 -04:00
parent a6c2cc7f61
commit 22df868ef8
4 changed files with 19 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
zed
*.dSYM/

1
README.md Normal file
View File

@@ -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.

View File

@@ -2,4 +2,4 @@
set -xe
clang -Wall -Wextra -o zed main.c
clang -Wall -Wextra -ggdb -o zed main.c

16
main.c
View File

@@ -2,6 +2,10 @@
#include <string.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
#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 <input.txt>\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) {