summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x7edbin0 -> 26344 bytes
-rw-r--r--functions.c10
-rw-r--r--startmode.c12
-rw-r--r--test/testgetline.c44
4 files changed, 66 insertions, 0 deletions
diff --git a/7ed b/7ed
new file mode 100755
index 0000000..3f46e1a
--- /dev/null
+++ b/7ed
Binary files differ
diff --git a/functions.c b/functions.c
index f2ce52e..324dd42 100644
--- a/functions.c
+++ b/functions.c
@@ -123,6 +123,16 @@ void shuffle(char arr[], int n) {
int GET_LINE(char filename[], long focus, char **line) { // Making this function was hell. Hardest thing ive coded in a while.
+ size_t lines;
+ int ret = COUNT_LINES_IN_FILE(filename, &lines);
+ if (ret == 1) {
+ return EXIT_FAILURE;
+ }
+
+ if ((long)lines < focus) {
+ return EXIT_FAILURE;
+ }
+
FILE *file;
file = fopen(filename,"r"); // Open file
diff --git a/startmode.c b/startmode.c
index 866da36..3c5b606 100644
--- a/startmode.c
+++ b/startmode.c
@@ -79,11 +79,23 @@ int startmode(char filename[]) {
}
printf("%s", line);
free(line);
+
break;
case 'E':
case 'e':
printf("EDIT MODE\n");
break;
+ case 'C':
+ case 'c':
+
+ size_t Flines;
+ int returnval = COUNT_LINES_IN_FILE(filename, &Flines);
+ if (returnval == 1) {
+ return EXIT_FAILURE;
+ }
+ fprintf(stdout,"%s %ld lines\n", filename, Flines);
+
+ break;
case 'Q':
case 'q':
return EXIT_SUCCESS;
diff --git a/test/testgetline.c b/test/testgetline.c
new file mode 100644
index 0000000..fb16c54
--- /dev/null
+++ b/test/testgetline.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include "7ed.h"
+
+#define USAGE ""
+#define PROGRAM_NAME "7ed"
+
+int main (int argc, char *argv[]) {
+
+
+int opt;
+int returnval;
+long focus = 100;
+char *line;
+while ((opt = getopt(argc, argv, "i:")) != -1) {
+ switch (opt) {
+
+ case 'i':
+
+ returnval = GET_LINE(optarg, focus, &line);
+ if (returnval == 1) {
+ return EXIT_FAILURE;
+ }
+ printf("%s", line);
+ free(line);
+
+ break;
+
+ default:
+ fprintf(stderr, "%s", USAGE);
+ return EXIT_FAILURE;
+ }
+}
+
+ if (argc == 1) {
+ fprintf(stderr, "%s: Please provide a file.\n%s", argv[0], USAGE);
+ return EXIT_FAILURE;
+ }
+
+return EXIT_SUCCESS;
+
+} \ No newline at end of file