summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-02-10 23:17:40 +0100
committerOskar <[email protected]>2024-02-10 23:17:40 +0100
commit6d15b3fc79e01fea1db05a6906596798fee4beaa (patch)
treeaac5a3d7d6bc248fce7e07904fb7ba0e63ac3b2d
parent03f53f231f0708b9f9f74302554a5d7d982aaa21 (diff)
Makefile changes and slight change to variable in startmode.c
-rw-r--r--Makefile14
-rw-r--r--editmode.c7
-rw-r--r--startmode.c15
3 files changed, 22 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 95e8d9a..aa9ed13 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,17 @@
+CC=clang
+CFLAGS=-Wfatal-errors -Wall -Werror -Wextra -g -O2
+CFLAGS_TESTBIN=-Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address
+TARGET=7ed
+TESTTARGET=7ed-TESTING
+
all: 7ed
7ed:
- gcc -Wfatal-errors -Wall -Werror -Wextra -g -O3 7ed.c functions.c startmode.c editmode.c -o 7ed
+ $(CC) $(CFLAGS) 7ed.c functions.c startmode.c editmode.c -o $(TARGET)
clean:
- rm -f 7ed
- rm -f test/7ed-TESTING
+ rm -f $(TARGET)
+ rm -f test/$(TESTTARGET)
tests:
- gcc -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address 7ed.c functions.c startmode.c editmode.c -o test/7ed-TESTING
+ $(CC) $(CFLAGS_TESTBIN) 7ed.c functions.c startmode.c editmode.c -o test/$(TESTTARGET)
diff --git a/editmode.c b/editmode.c
index 2fb40b2..938bb5a 100644
--- a/editmode.c
+++ b/editmode.c
@@ -242,7 +242,10 @@ int editmode(char filename[], long focus) { // the editing interface
char editbuffer[BUF_SZ_2];
fprintf(stdout, "(%ld EDIT): ", focus);
- fgets(editbuffer, BUF_SZ_2, stdin);
+ char *fgs = fgets(editbuffer, BUF_SZ_2, stdin);
+ if (fgs == NULL) {
+ return 0;
+ }
if (editbuffer[0] == '\n') {
fprintf(stdout, "No changes\n");
@@ -265,4 +268,4 @@ int editmode(char filename[], long focus) { // the editing interface
return EXIT_SUCCESS;
-} \ No newline at end of file
+}
diff --git a/startmode.c b/startmode.c
index 7bd5049..f65a8c6 100644
--- a/startmode.c
+++ b/startmode.c
@@ -28,22 +28,21 @@ int ncat(char filename[]) {
int startmode(char filename[]) {
uint64_t Flines;
- int returnval = count_lines_in_file(filename, &Flines);
+ int returnval = count_lines_in_file(filename, &Flines);
if (returnval == 1) {
return EXIT_FAILURE;
}
fprintf(stdout,"%s %lu lines\n", filename, Flines);
uint64_t focus = 1;
-
+ // This stuff before the while loop is to display the amount of lines upon starting the editor and also setting focus
while(1) {
firstwhile:
- int ret = count_lines_in_file(filename, &Flines); // update Flines every time
- if (ret == 1) {
- return EXIT_FAILURE;
- }
-
+ count_lines_in_file(filename, &Flines); // I do not know WHY i can not have this return to a variable??
+ // For some reason whenever i do int x = count_lines_in_file(.....) it will NOT compile
+ // I can not for the life of me figure out what the compiler is trying to say about the"expected expression" error
+ // I HAVE DONE THE SAME THING EVERYWHERE ELSE WHY WOULD IT INEXPLICABLY NOT WORK SPECIFICALLY HERE?
fprintf(stdout, "(%lu): ", focus);
char command = getchar();
if (command == '\n') {
@@ -215,4 +214,4 @@ int startmode(char filename[]) {
}
return EXIT_SUCCESS;
-} \ No newline at end of file
+}