summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--7ed.c1
-rw-r--r--7ed.h1
-rw-r--r--Makefile2
-rw-r--r--README8
-rw-r--r--editmode.c3
-rw-r--r--functions.c7
-rw-r--r--startmode.c19
7 files changed, 25 insertions, 16 deletions
diff --git a/7ed.c b/7ed.c
index 26b803e..a2dd4e1 100644
--- a/7ed.c
+++ b/7ed.c
@@ -3,6 +3,7 @@
#include <unistd.h>
#include <string.h>
#include "7ed.h"
+#include <stdint.h>
#define USAGE ""
#define PROGRAM_NAME "7ed"
diff --git a/7ed.h b/7ed.h
index 83495bf..27f0235 100644
--- a/7ed.h
+++ b/7ed.h
@@ -1,4 +1,5 @@
#include <stddef.h>
+#include <stdint.h>
#define BUF_SZ_256 256
#define BUF_SZ_512 512
diff --git a/Makefile b/Makefile
index 07442d1..6746525 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
all: 7ed
7ed:
- gcc -Wfatal-errors -Wall -Werror -Wextra -g -fsanitize=address 7ed.c functions.c startmode.c editmode.c -o 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:
diff --git a/README b/README
index 5f4e6fe..6f0a4b5 100644
--- a/README
+++ b/README
@@ -5,5 +5,9 @@ TODO:
- Create a function to retrieve a line from file (DONE) It's called: GET_LINE(char filename[], long focus, char **line)
- Create edit mode to actually make edits to the file (DONE)
- Find and fix bugs. Fixed one bug in write_line() function. (btw this was written with 7ed!!!)
-- Fix weird quirks that i did not think about
-- clean up code
+- Create functionality to actually add new lines. You cant actually add a line on the end of the file. You also cant just add a line and move everything under it one line down. I will get to fixing that though.
+
+
+
+
+
diff --git a/editmode.c b/editmode.c
index 97afbe8..a021372 100644
--- a/editmode.c
+++ b/editmode.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <errno.h>
#include "7ed.h"
+#include <stdint.h>
int write_line(char filename[], long focus, char editbuffer[], size_t editbuffer_size) {
@@ -74,7 +75,7 @@ return 0;
}
-int NEW_LINE(char filename[]) { // testing this now with -fsanitize=address !! Please work!
+int NEW_LINE(char filename[]) { // doin this test again
long new_line_pos;
long new_line_pos_temp;
diff --git a/functions.c b/functions.c
index edba69b..0d7c500 100644
--- a/functions.c
+++ b/functions.c
@@ -4,6 +4,7 @@
#include "7ed.h"
#include <time.h>
#include <string.h>
+#include <stdint.h>
void CONFIRM() {
struct termios old,new;
@@ -20,7 +21,7 @@ void CONFIRM() {
}
int CHOICE() {
- int choice;
+ char choice;
do {
@@ -46,11 +47,11 @@ int CHOICE() {
return EXIT_FAILURE;
}
-int COUNT_LINES_IN_FILE (char filename[], size_t *lines) {
+int COUNT_LINES_IN_FILE (char filename[], uint64_t *lines) {
// Does not follow posix because this function accounts for if the last line does not end with a newline.
- size_t line_count = 0; // Counter starting at 0
+ uint64_t line_count = 0; // Counter starting at 0
FILE *file;
file = fopen(filename,"rb"); // Open file
diff --git a/startmode.c b/startmode.c
index 988b6fd..1ecaa94 100644
--- a/startmode.c
+++ b/startmode.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <errno.h>
#include "7ed.h"
+#include <stdint.h>
int NCAT(char filename[]) {
@@ -26,18 +27,18 @@ int NCAT(char filename[]) {
int startmode(char filename[]) {
- size_t Flines;
+ uint64_t Flines;
int returnval = COUNT_LINES_IN_FILE(filename, &Flines);
if (returnval == 1) {
return EXIT_FAILURE;
}
- fprintf(stdout,"%s %ld lines\n", filename, Flines);
+ fprintf(stdout,"%s %lu lines\n", filename, Flines);
- long focus = 1;
+ uint64_t focus = 1;
while(1) {
- fprintf(stdout, "(%ld): ", focus);
+ fprintf(stdout, "(%lu): ", focus);
char command = getchar();
if (command == '\n') {
continue;
@@ -47,7 +48,7 @@ int startmode(char filename[]) {
switch (command) {
case 'L':
case 'l':
- long Lfocus;
+ uint64_t Lfocus;
char buf[1024];
int success;
@@ -81,8 +82,8 @@ int startmode(char filename[]) {
} while (!success);
- if (Lfocus < 1 || Lfocus > (long)Flines) {
- fprintf(stderr, "L is either less than 1 or more than %ld\n", Flines);
+ if (Lfocus < 1 || Lfocus > Flines) {
+ fprintf(stderr, "L is either less than 1 or more than %lu\n", Flines);
} else {
focus = Lfocus;
}
@@ -111,12 +112,12 @@ int startmode(char filename[]) {
case 'C':
case 'c':
- size_t CFlines;
+ uint64_t CFlines;
int returnval = COUNT_LINES_IN_FILE(filename, &CFlines);
if (returnval == 1) {
return EXIT_FAILURE;
}
- fprintf(stdout,"%s %ld lines\n", filename, CFlines);
+ fprintf(stdout,"%s %zu lines\n", filename, CFlines);
break;
case 'Q':