added some terminal things, added debugging to buildfile
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
zed
|
||||
*.dSYM/
|
||||
|
||||
1
README.md
Normal file
1
README.md
Normal 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.
|
||||
2
build.sh
2
build.sh
@@ -2,4 +2,4 @@
|
||||
|
||||
set -xe
|
||||
|
||||
clang -Wall -Wextra -o zed main.c
|
||||
clang -Wall -Wextra -ggdb -o zed main.c
|
||||
|
||||
16
main.c
16
main.c
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user