From a06db018fa1853dfb3d7347c433d3ac92c57e1cb Mon Sep 17 00:00:00 2001 From: bx Date: Sat, 2 Apr 2022 22:28:47 +0100 Subject: [PATCH] forgot to add clipboard.c last commit --- c_clipboard.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 c_clipboard.c diff --git a/c_clipboard.c b/c_clipboard.c new file mode 100644 index 0000000..99ba56e --- /dev/null +++ b/c_clipboard.c @@ -0,0 +1,24 @@ +void +c_copy(char *c) { + c += 2; + int start = atoi(c); + for(; *c != '\0' && *c != ' '; c++); + int end = atoi(c); + Row *cpy_start = b_getline(buffer, start); + if(cpy_start == NULL || b_getline(buffer, end) == NULL) { + puts("invalid line."); + return; + } + if (clipboard != NULL) { + b_truncate(clipboard); + free(clipboard); + } + clipboard = calloc(1, sizeof(Row)); + Row *dest = clipboard; + for (int i = start; i <= end; i++) { + memcpy(dest->text, cpy_start->text, ROW_SIZE); + cpy_start = cpy_start->n; + dest = b_insert(dest); + } +} +