From 0773d4f561f09d25e56719f6d82adc097f9106ce Mon Sep 17 00:00:00 2001 From: bjoernf Date: Sat, 16 Sep 2023 12:39:49 +0200 Subject: [PATCH] removed unused move_lines.c --- src/main.c | 1 - src/move_lines.c | 59 ------------------------------------------------ src/move_lines.h | 20 ---------------- 3 files changed, 80 deletions(-) delete mode 100644 src/move_lines.c delete mode 100644 src/move_lines.h diff --git a/src/main.c b/src/main.c index dcf759a..14ab12a 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,6 @@ #include "cli_arg_parsing.h" #include "date_time_handling.h" #include "string_handling.h" -#include "move_lines.h" #include "read_until_nl.h" #include "read_until_string.h" #include "seek_string_a.h" diff --git a/src/move_lines.c b/src/move_lines.c deleted file mode 100644 index 5d2eb40..0000000 --- a/src/move_lines.c +++ /dev/null @@ -1,59 +0,0 @@ -// functions that can move the file position conveniently -// remember that the last line of a file is usually empty and goes from '\n' to EOF - -#include "move_lines.h" -#include - -// function to move back/up -void go_back_x_lines(int fd, int lines) { - for (int i = 0; i < lines; i++) { - seek_previous_line(fd); - } -} - -void seek_previous_line(int fd) { - seek_line_start(fd); - lseek(fd, -1, SEEK_CUR); - seek_line_start(fd); -} - -// set file position to the beginning of the line -void seek_line_start(int fd) { - char cur_char = '\0'; - - while (cur_char != '\n') { - int ret_lseek = lseek(fd, -1, SEEK_CUR); - if (ret_lseek == -1) - break; - - read(fd, &cur_char, 1); - if (cur_char != '\n') - lseek(fd, -1, SEEK_CUR); - } -} - -// function to move forward/down -void go_forward_x_lines(int fd, int lines) { - for (int i = 0; i < lines; i++) { - seek_next_line(fd); - } -} - -void seek_next_line(int fd) { - seek_line_end(fd); - lseek(fd, 1, SEEK_CUR); -} - -// set file position to the end of the line -void seek_line_end(int fd) { - char cur_char = '\0'; - - while (cur_char != '\n') { - // return code 0 of read indicates EOF - if (read(fd, &cur_char, 1) == 0) - break; - } - - lseek(fd, -1, SEEK_CUR); -} - diff --git a/src/move_lines.h b/src/move_lines.h deleted file mode 100644 index fe9200a..0000000 --- a/src/move_lines.h +++ /dev/null @@ -1,20 +0,0 @@ -// functions that can move the file position conveniently -// remember that the last line of a file is usually empty and goes from '\n' to EOF - -#pragma once - -// function to move back/up -void go_back_x_lines(int fd, int lines); - -void seek_previous_line(int fd); - -// set file position to the beginning of the line -void seek_line_start(int fd); - -// function to move forward/down -void go_forward_x_lines(int fd, int lines); - -void seek_next_line(int fd); - -// set file position to the end of the line -void seek_line_end(int fd);