From c5b58534dc41ec36e041717918de5727e0200b28 Mon Sep 17 00:00:00 2001 From: Oskar Date: Sun, 31 Mar 2024 22:28:31 +0200 Subject: Singles done --- 7ed.h | 2 +- editmode.c | 2 +- input.c | 3 +++ input.h | 1 + process_multiples.c | 10 ++++++++++ startmode.c | 31 +++++++++++++++++++++++++++---- 6 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 process_multiples.c diff --git a/7ed.h b/7ed.h index ab6a239..a65e3fe 100644 --- a/7ed.h +++ b/7ed.h @@ -26,7 +26,7 @@ int startmode(char filename[]); int get_line(char filename[], long focus, char **line, size_t *start); -int editmode(char filename[], long focus); +int editmode(char filename[], uint64_t focus); int new_line(char filename[], long new_line_pos_temp); diff --git a/editmode.c b/editmode.c index 938bb5a..7080c84 100644 --- a/editmode.c +++ b/editmode.c @@ -226,7 +226,7 @@ int remove_line_contents(char filename[], long focus) { // removes contents of a } -int editmode(char filename[], long focus) { // the editing interface +int editmode(char filename[], uint64_t focus) { // the editing interface char *line; size_t start; diff --git a/input.c b/input.c index 6895573..db1fef7 100644 --- a/input.c +++ b/input.c @@ -106,6 +106,9 @@ int smode_input(char *single, char **multiple, uint64_t focus) { // This functio *single = smode_buf[0]; return _SINGLE; break; + case '\n': + return _RETURN; + break; } diff --git a/input.h b/input.h index e509ee7..cd4ef19 100644 --- a/input.h +++ b/input.h @@ -9,6 +9,7 @@ #define SMODE_MAX_SIZE 33 #define SMODE_MAX_INPUT_SIZE 32 +#define _RETURN 3 #define _ONE 1 #define _SINGLE 1 #define _MULTIPLE 2 diff --git a/process_multiples.c b/process_multiples.c new file mode 100644 index 0000000..839573a --- /dev/null +++ b/process_multiples.c @@ -0,0 +1,10 @@ +#include +#include +#include +#include +#include +#include "7ed.h" +#include "input.h" +#include "i_validation.h" +#include + diff --git a/startmode.c b/startmode.c index a52e4d2..3b4179b 100644 --- a/startmode.c +++ b/startmode.c @@ -39,30 +39,52 @@ int display_name_linecount(char *filename) { return 0; } -int call_singles(char single) { +int call_singles(char single, uint64_t focus, char *filename) { switch(single) { case 'p': case 'P': - + + char *line; + size_t start; + int ret = get_line(filename, focus, &line, &start); + if (ret == 1) { + return EXIT_FAILURE; + } + fprintf(stdout, "%s", line); + free(line); + break; case 'e': case 'E': + editmode(filename, focus); + break; case 'c': case 'C': + int dnl = display_name_linecount(filename); + if (dnl == 1) { + return EXIT_FAILURE; + } + break; case 'q': case 'Q': + exit(EXIT_SUCCESS); + break; case 'a': case 'A': + ncat(filename); + break; } + + return 0; } int startmode(char filename[]) { @@ -81,8 +103,7 @@ int startmode(char filename[]) { switch (smode_input_ret) { case _SINGLE: - fprintf(stdout, "single\n"); - fprintf(stdout, "%c\n", single); + call_singles(single, focus, filename); break; case _MULTIPLE: fprintf(stdout, "multiple\n"); @@ -92,6 +113,8 @@ int startmode(char filename[]) { case _FAIL: fprintf(stdout, "?\n"); break; + case _RETURN: // if user just preses 'return' button + break; } -- cgit v1.2.3