efn/c_clipboard.c

37 lines
871 B
C
Raw Normal View History

2022-04-02 21:28:47 +00:00
void
c_copy(char *c, char **argv) {
2022-04-02 21:28:47 +00:00
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);
}
}
2022-04-02 21:36:17 +00:00
void
c_paste(char *c, char **argv) {
2022-04-02 21:36:17 +00:00
Row *line = b_getline(buffer, atoi(c + 2));
if (line == NULL) {puts("invalid line."); return; }
if (clipboard == NULL) {puts("empty clipboard"); return; }
for (Row *cb = clipboard; cb->n != NULL; cb = cb->n) {
line = b_insert(line);
memcpy(line->text, cb->text, ROW_SIZE);
}
}