summaryrefslogtreecommitdiff
path: root/buff.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-05-30 16:42:16 +0100
committerKatolaZ <katolaz@freaknet.org>2018-05-30 16:42:16 +0100
commit00d893c8f8e742acc15e6675dec20c946dfb6fd7 (patch)
tree06325441928ab711afb550339c7aa837dd2ac223 /buff.c
parent169cd80426f3a5e1462913f24b47e3f3ac39dbce (diff)
implemented 'm' and 't'
Diffstat (limited to 'buff.c')
-rw-r--r--buff.c71
1 files changed, 29 insertions, 42 deletions
diff --git a/buff.c b/buff.c
index 6b3af61..c9d6800 100644
--- a/buff.c
+++ b/buff.c
@@ -95,8 +95,26 @@ void __append_lines(int addr, int n, line_t *first, line_t *last){
}
-void __copy_lines(line_t **first, line_t **last){
-
+int __copy_lines(line_t **first, line_t **last){
+
+ line_t *new, *l, *p;
+ int n = addr2;
+
+ move_to_line(addr2,0);
+ l = malloc(sizeof(line_t));
+ l-> c = malloc((strlen(cur->c) + 1) * sizeof(char));
+ strcpy(l->c, cur->c);
+ p = *first = l;
+ while(++n <= addr1){
+ cur = cur -> next, pos++;
+ l = malloc(sizeof(line_t));
+ l->c = malloc((strlen(cur->c) + 1) * sizeof(char));
+ strcpy(l->c, cur->c);
+ p->next = l;
+ p = l;
+ }
+ *last = p;
+ return n - addr2;
}
@@ -178,32 +196,6 @@ void print_lineno(){
printf("%d\n", addr1);
}
-int move_forward(int n){
-
- if (pos + n > num){
- E;
- return -1;
- }
- while(n-- > 0){
- cur = cur->next;
- }
- pos += n;
- return 0;
-}
-
-int move_backward(int n){
-
- if (pos - n < 1){
- E;
- return -1;
- }
- while(n-- >0){
- cur = cur->prev;
- }
- pos -= n;
- return 0;
-}
-
/* add lines after pos */
@@ -248,8 +240,7 @@ void delete_lines(){
if (addr2 > 1){
handle = cur -> prev;
}
- while(pos <= addr1){
- pos ++;
+ while(pos++ <= addr1){
next = cur -> next;
prev = cur -> prev;
free(cur -> c);
@@ -259,7 +250,6 @@ void delete_lines(){
else
break;
}
-
if (!handle){
/* first line deleted */
b_start = cur;
@@ -274,7 +264,6 @@ void delete_lines(){
pos = addr2 - 1;
cur = prev;
}
-
num -= addr1 - addr2 + 1;
}
@@ -372,26 +361,24 @@ int mark(char *c){
}
-int transfer_lines(int addr, char move){
+void transfer_lines(int addr, char move){
line_t *first, *last;
-
+ int n;
+
if (addr2 < addr && addr < addr1){
E;
- return -1;
+ return;
}
first = last = NULL;
-
- __copy_lines(&first, &last);
-
+ n = __copy_lines(&first, &last);
+ fprintf(stderr, " >>>> transfer_lines -- addr: %d n: %d\n", addr, n);
if (move){
if (addr1 < addr)
addr -= (addr1 - addr2 + 1);
delete_lines();
}
- /* make a generic function to append lines after an addr */
-
- return 0;
-
+ __append_lines(addr, n, first, last);
+ move_to_line(addr+n,0);
}