summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--7ed.h2
-rw-r--r--Makefile9
-rw-r--r--editmode.c28
-rw-r--r--functions.c19
-rw-r--r--test/file.txt26
-rw-r--r--test/file2.txt23
-rw-r--r--test/newlinetest1
-rw-r--r--test/newlinetest210
-rw-r--r--test/text_about_testing.txt27
9 files changed, 114 insertions, 31 deletions
diff --git a/7ed.h b/7ed.h
index 27f0235..65cbaaa 100644
--- a/7ed.h
+++ b/7ed.h
@@ -11,7 +11,7 @@
#ifndef COUNT_LINES_IN_FILE_H
#define COUNT_LINES_IN_FILE_H
-int COUNT_LINES_IN_FILE (char filename[], size_t *lines);
+int COUNT_LINES_IN_FILE (char filename[], uint64_t *lines);
#endif /* COUNT_LINES_IN_FILE_H */
diff --git a/Makefile b/Makefile
index 6746525..01eaee4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,11 @@
all: 7ed
7ed:
gcc -Wfatal-errors -Wall -Werror -Wextra -g 7ed.c functions.c startmode.c editmode.c -o 7ed
- cp 7ed test
- mv test/7ed test/7ed-test
+
clean:
rm -f 7ed
- rm -f test/7ed-test
+ rm -f test/7ed-TESTING
+
+tests:
+ gcc -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address 7ed.c functions.c startmode.c editmode.c -o test/7ed-TESTING
+
diff --git a/editmode.c b/editmode.c
index a021372..24156dd 100644
--- a/editmode.c
+++ b/editmode.c
@@ -77,14 +77,14 @@ return 0;
int NEW_LINE(char filename[]) { // doin this test again
- long new_line_pos;
- long new_line_pos_temp;
+ long new_line_pos; // The "focus" that the newline will be inserted afterwards
+ long new_line_pos_temp; // temp
char buf[1024];
int success;
do {
fprintf(stdout, "Create a new line after: ");
- if (!fgets(buf, 1024, stdin)) {
+ if (!fgets(buf, 1024, stdin)) { // take input from user
fprintf(stderr, "Too many characters\n");
break;
}
@@ -110,25 +110,29 @@ int NEW_LINE(char filename[]) { // doin this test again
} while (!success);
- if (new_line_pos_temp < 1) {
+ if (new_line_pos_temp < 0) {
fprintf(stderr, "The new line can not be under 0!\n");
return 1;
} else {
new_line_pos = new_line_pos_temp;
- char *line;
- size_t start;
- int ret = GET_LINE(filename, new_line_pos, &line, &start);
+ char *line; // line is the line before the newline
+ // line2 is the line right after line
+ size_t start; // start is the position at the start of line
+ // start2 is the position at the start of line2
+ int ret = GET_LINE(filename, new_line_pos+1, &line, &start);
if (ret == 1) {
return 1;
}
size_t len = strlen(line);
- char *newline_and_line = malloc(len+2);
- strcpy(newline_and_line, line);
- strcat(newline_and_line, "\n");
- write_line(filename, new_line_pos, newline_and_line, 1);
- free(newline_and_line);
+ char to_be_written[len+2];
+ to_be_written[0] = '\n';
+ to_be_written[1] = '\0';
+ strcat(to_be_written, line);
+
+ write_line(filename, new_line_pos+1, to_be_written, len+1);
+ free(line);
}
return 0;
diff --git a/functions.c b/functions.c
index 0d7c500..c114efd 100644
--- a/functions.c
+++ b/functions.c
@@ -133,17 +133,6 @@ int GET_LINE(char filename[], long focus, char **line, size_t *start) { // Makin
return 1;
}
- /*
- size_t lines;
- int ret = COUNT_LINES_IN_FILE(filename, &lines);
- if (ret == 1) {
- return EXIT_FAILURE;
- }
-
- if ((long)lines < focus) { // check if focus is bigger than the amount of
- return EXIT_FAILURE; // lines in the actual file and returns exit failure
- }
- */
if (focus == 1) {
int c1_count = 0;
while (1) {
@@ -172,7 +161,8 @@ int GET_LINE(char filename[], long focus, char **line, size_t *start) { // Makin
strcpy(*line, c1buf); // Return line 1
}
- *start = 0;
+ *start = 0; // Is start the start of where line
+
//printf("%s", c1buf); // The purpose of this if statement is that it will only print line 1. Not too elegant of a way to handle this but its the only way i knew how to.
} else {
@@ -219,9 +209,10 @@ int GET_LINE(char filename[], long focus, char **line, size_t *start) { // Makin
if (*line != NULL) {
strcpy(*line, c2buf);
}
- *start = save_i+1;
+ *start = save_i+1; // not sure but i think it saves the start position of the line
+
}
fclose(file);
return 0;
-}
+} \ No newline at end of file
diff --git a/test/file.txt b/test/file.txt
new file mode 100644
index 0000000..6f741aa
--- /dev/null
+++ b/test/file.txt
@@ -0,0 +1,26 @@
+
+
+lksdjflsdjfls209432+093+20943????01+230+2,.,-.,-,-.,-.,.,..,.,.,¨.¨,¨.,¨.´.´,´.,´.,´.´,.´,.´.´,´.????`?`?`?`?`?`?`?`?`???????!!!!!!!!
+öölaölskdöaslkölaksöd
++10230123203293
+())()()()()&&&&&///////////////&%/&/&&%%&/%/// 3
+=)(09820398409709
+zxm,czm.x,cm.zxmc.,....
+This is line 9
+:::
+
+.salksjdlkajs
+las
+
+
+alskdasldkasöld
+
+
+
+.
+
+LINE 22!!!!!!!
+
+ast line!!!
+
+
diff --git a/test/file2.txt b/test/file2.txt
new file mode 100644
index 0000000..73ee54a
--- /dev/null
+++ b/test/file2.txt
@@ -0,0 +1,23 @@
+asldaskdlalksjd
+11111111
+222222
+öölaölskdöaslkölaksöd
++10230123203293
+()))&%#"#¤%&/&%¤
+=)(09820398409709
+zxm,czm.x,cm.zxmc.,....
+:
+:::
+
+.salksjdlkajs
+las
+
+
+alskdasldkasöld
+
+
+
+
+
+
+ölasdlkaösldköalskdöals3925748392
diff --git a/test/newlinetest b/test/newlinetest
index f00c965..051c298 100644
--- a/test/newlinetest
+++ b/test/newlinetest
@@ -1,7 +1,6 @@
1
2
3
-4
5
6
7
diff --git a/test/newlinetest2 b/test/newlinetest2
new file mode 100644
index 0000000..f00c965
--- /dev/null
+++ b/test/newlinetest2
@@ -0,0 +1,10 @@
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
diff --git a/test/text_about_testing.txt b/test/text_about_testing.txt
new file mode 100644
index 0000000..4857dfb
--- /dev/null
+++ b/test/text_about_testing.txt
@@ -0,0 +1,27 @@
+Testing software is crucial for ensuring its functionality, reliability, and overall quality.
+
+
+
+
+
+
+
+
+
+
+It serves as a safety net, catching errors and flaws before they reach end-users, which can ultimately save time, money, and reputation.
+
+
+Firstly, software testing validates that the code functions as intended. It's like a quality control process that verifies if the software meets the specified requirements and performs the expected tasks accurately. By identifying and fixing bugs during testing, developers can prevent issues from surfacing when the software is in use, reducing the potential for disruptions or failures that could impact users.
+
+Secondly, testing helps enhance user experience. When software behaves consistently and predictably, users are more likely to have a positive experience. Comprehensive testing ensures that the software is user-friendly, intuitive, and responsive, which can significantly contribute to user satisfaction and retention.
+
+Moreover, testing aids in maintaining security and protecting sensitive data. Security vulnerabilities can be catastrophic, leading to breaches and compromises. Through rigorous testing, potential vulnerabilities can be identified and addressed, fortifying the software against potential cyber threats.
+
+Testing also supports scalability. It ensures that as the software grows or experiences increased usage, it continues to perform efficiently without compromising speed or functionality. This is particularly crucial in today's tech landscape, where scalability is often a key factor in a software's success.
+
+In essence, software testing isn't just about finding and fixing bugs.
+It's a strategic process that enhances the overall quality, reliability, and security of software, contributing significantly to its success in the market and ensuring a positive user experience.
+
+
+