... | ... |
@@ -39,6 +39,7 @@ static char *genname(char *filename,char *prefix, char *postfix, char *buf, int |
39 | 39 |
static char *ptr_getlong(char *ptr,char *endptr,long *data); |
40 | 40 |
static char *ptr_getchar(char *ptr,char *endptr,char *data); |
41 | 41 |
static char *ptr_searchendchar(char *ptr, char *endptr, char endchar, char **endcharpos); |
42 |
+static char sep_select(char *buf, int bufsize, char **pos); |
|
42 | 43 |
|
43 | 44 |
redata_t * |
44 | 45 |
redata_init(void) |
... | ... |
@@ -618,6 +619,7 @@ redata_unsaved_loadappend(redata_t *redata) |
618 | 619 |
int |
619 | 620 |
redata_unsaved_add(redata_t *redata, undo_t *undo) |
620 | 621 |
{ |
622 |
+ |
|
621 | 623 |
/* separator is '$' , '@' or '%' (whatever makes the longest string) */ |
622 | 624 |
/* if len is omitted, then it goes inmediatly after the last op (probably there separator character was used in the string) */ |
623 | 625 |
#warning TODO |
... | ... |
@@ -631,6 +633,14 @@ redata_unsaved_unadd(redata_t *redata, undo_t *undo) |
631 | 633 |
return(-1); |
632 | 634 |
} |
633 | 635 |
|
636 |
+int |
|
637 |
+redata_unsaved_commit(redata_t *redata) |
|
638 |
+{ |
|
639 |
+#warning TODO |
|
640 |
+ return(-1); |
|
641 |
+} |
|
642 |
+ |
|
643 |
+ |
|
634 | 644 |
int |
635 | 645 |
redata_load(redata_t *redata, char *filename, int use_unsaved) |
636 | 646 |
{ |
... | ... |
@@ -751,11 +761,11 @@ redata_undobuf_reserve(redata_t *redata, undostack_t *stack, int minavail) |
751 | 761 |
} |
752 | 762 |
|
753 | 763 |
undo_t * |
754 |
-redata_undo_new(redata_t *redata, undostack_t *stack, char *type) |
|
764 |
+redata_undo_new(redata_t *redata, undostack_t *stack, char type) |
|
755 | 765 |
{ |
756 | 766 |
int newsize; |
757 | 767 |
undo_t *newptr,*undo; |
758 |
- if(redata==NULL || type==NULL |
|
768 |
+ if(redata==NULL |
|
759 | 769 |
|| (stack!=&(redata->undostack) && stack!=&(redata->redostack))) |
760 | 770 |
return(NULL); /* sanity check failed */ |
761 | 771 |
if(stack->sizeundo==stack->usedundo) { |
... | ... |
@@ -769,15 +779,14 @@ redata_undo_new(redata_t *redata, undostack_t *stack, char *type) |
769 | 779 |
} |
770 | 780 |
undo=stack->undo+stack->usedundo; |
771 | 781 |
stack->usedundo++; |
772 |
- strncpy(undo->type,type,sizeof(undo->type)); |
|
773 |
- undo->type[sizeof(undo->type)-1]='\0'; |
|
782 |
+ undo->type=type; |
|
774 | 783 |
undo->off=stack->usedbuf; |
775 | 784 |
undo->len=0; |
776 | 785 |
return(undo); |
777 | 786 |
} |
778 | 787 |
|
779 | 788 |
undo_t * |
780 |
-redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char *type, int pos1, int len) |
|
789 |
+redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char type, int pos1, int len) |
|
781 | 790 |
{ |
782 | 791 |
int startpos,endpos; |
783 | 792 |
long startoff,endoff; |
... | ... |
@@ -785,7 +794,7 @@ redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char *type, int |
785 | 794 |
int k; |
786 | 795 |
long used; |
787 | 796 |
long copyfrom,copysize; |
788 |
- if(redata==NULL || type==NULL || len<=0 |
|
797 |
+ if(redata==NULL || len<=0 |
|
789 | 798 |
|| (stack!=&(redata->undostack) && stack!=&(redata->redostack))) |
790 | 799 |
return(NULL); /* sanity check failed */ |
791 | 800 |
if(redata_getposptr(redata,pos1,&startpos,&startoff)==-1 || |
... | ... |
@@ -821,10 +830,10 @@ redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char *type, int |
821 | 830 |
} |
822 | 831 |
|
823 | 832 |
undo_t * |
824 |
-redata_undo_newfrombuf(redata_t *redata, undostack_t *stack, char *type, char *buf, int buflen) |
|
833 |
+redata_undo_newfrombuf(redata_t *redata, undostack_t *stack, char type, char *buf, int buflen) |
|
825 | 834 |
{ |
826 | 835 |
undo_t *undo; |
827 |
- if(redata==NULL || type==NULL || buflen<=0 |
|
836 |
+ if(redata==NULL || buflen<=0 |
|
828 | 837 |
|| (stack!=&(redata->undostack) && stack!=&(redata->redostack))) |
829 | 838 |
return(NULL); /* sanity check failed */ |
830 | 839 |
if(redata_undobuf_reserve(redata,stack, buflen)!=0) |
... | ... |
@@ -905,7 +914,7 @@ redata_op_add(redata_t *redata, long insertpos, char *buf, long buflen, undostac |
905 | 914 |
if(redata_getposptr(redata,insertpos,&chunkno,&pos)==-1) |
906 | 915 |
return(-1); /* invalid pos */ |
907 | 916 |
if(fromhere!=&(redata->undostack)) { |
908 |
- if((undo=redata_undo_newfrombuf(redata,&(redata->undostack),"ADD",buf,buflen))==NULL) |
|
917 |
+ if((undo=redata_undo_newfrombuf(redata,&(redata->undostack),'A',buf,buflen))==NULL) |
|
909 | 918 |
return(-1); /* couldn't create undo struct */ |
910 | 919 |
redata_hash(redata,undo->prehash); |
911 | 920 |
} else { |
... | ... |
@@ -993,7 +1002,7 @@ redata_op_del(redata_t *redata, long delpos, long size, undostack_t *fromhere) |
993 | 1002 |
if(redata_getposptr(redata,delpos,&chunkno,&pos)==-1) |
994 | 1003 |
return(-1); /* invalid pos */ |
995 | 1004 |
if(fromhere!=&(redata->undostack)) { |
996 |
- if((undo=redata_undo_newfromchunks(redata,&(redata->undostack),"DEL",delpos,size))==NULL) |
|
1005 |
+ if((undo=redata_undo_newfromchunks(redata,&(redata->undostack),'D',delpos,size))==NULL) |
|
997 | 1006 |
return(-1); /* couldn't create undo struct */ |
998 | 1007 |
redata_hash(redata,undo->prehash); |
999 | 1008 |
} else { |
... | ... |
@@ -1046,11 +1055,11 @@ redata_op_undo(redata_t *redata) |
1046 | 1055 |
|| redata->undostack.usedundo<1) |
1047 | 1056 |
return(-1); /* sanity check failed */ |
1048 | 1057 |
undo=redata->undostack.undo+redata->undostack.usedundo-1; |
1049 |
- if(strcmp(undo->type,"ADD")==0) { |
|
1058 |
+ if(undo->type=='A') { /* ADD */ |
|
1050 | 1059 |
redata_op_del(redata,undo->posorig,undo->len,&(redata->undostack)); |
1051 |
- } else if(strcmp(undo->type,"DEL")==0) { |
|
1060 |
+ } else if(undo->type=='D') { /* DEL */ |
|
1052 | 1061 |
redata_op_add(redata,undo->posorig,redata->undostack.buf+undo->off,undo->len,&(redata->undostack)); |
1053 |
- } else if(strcmp(undo->type,"MOV")==0) { |
|
1062 |
+ } else if(undo->type=='M') { /* MOVE */ |
|
1054 | 1063 |
if(undo->posorig<undo->posdest) |
1055 | 1064 |
redata_op_move(redata,undo->posdest-undo->len, undo->len, undo->posorig,&(redata->undostack)); |
1056 | 1065 |
else |
... | ... |
@@ -1068,11 +1077,11 @@ redata_op_redo(redata_t *redata) |
1068 | 1077 |
|| redata->redostack.usedundo<1) |
1069 | 1078 |
return(-1); /* sanity check failed */ |
1070 | 1079 |
undo=redata->redostack.undo+redata->redostack.usedundo-1; |
1071 |
- if(strcmp(undo->type,"ADD")==0) { |
|
1080 |
+ if(undo->type=='A') { /* ADD */ |
|
1072 | 1081 |
redata_op_add(redata,undo->posorig,redata->redostack.buf+undo->off,undo->len,&(redata->redostack)); |
1073 |
- } else if(strcmp(undo->type,"DEL")==0) { |
|
1082 |
+ } else if(undo->type=='D') { /* DEL */ |
|
1074 | 1083 |
redata_op_del(redata,undo->posorig,undo->len,&(redata->redostack)); |
1075 |
- } else if(strcmp(undo->type,"MOV")==0) { |
|
1084 |
+ } else if(undo->type=='M') { /* MOVE */ |
|
1076 | 1085 |
redata_op_move(redata,undo->posorig, undo->len, undo->posdest,&(redata->redostack)); |
1077 | 1086 |
} else |
1078 | 1087 |
return(-1); /* unknown operation */ |
... | ... |
@@ -1284,3 +1293,25 @@ ptr_searchendchar(char *ptr, char *endptr, char endchar, char **endcharpos) |
1284 | 1293 |
return(aux+1); |
1285 | 1294 |
} |
1286 | 1295 |
|
1296 |
+static char |
|
1297 |
+sep_select(char *buf, int bufsize, char **pos) |
|
1298 |
+{ |
|
1299 |
+ static char seps[]={"$%@!|&/='\"^*;:,-_"}; |
|
1300 |
+ char *ptr,*bestptr; |
|
1301 |
+ int i,besti; |
|
1302 |
+ bestptr=buf; |
|
1303 |
+ if(pos!=NULL) |
|
1304 |
+ *pos=NULL; |
|
1305 |
+ for(i=0,besti=0;i<sizeof(seps);i++) { |
|
1306 |
+ if((ptr=memchr(buf,seps[i],bufsize))==NULL) |
|
1307 |
+ return(seps[i]); |
|
1308 |
+ if(ptr>bestptr) { |
|
1309 |
+ besti=0; |
|
1310 |
+ bestptr=ptr; |
|
1311 |
+ } |
|
1312 |
+ } |
|
1313 |
+ if(pos!=NULL) |
|
1314 |
+ *pos=bestptr; |
|
1315 |
+ return(seps[besti]); |
|
1316 |
+} |
|
1317 |
+ |
... | ... |
@@ -25,7 +25,7 @@ typedef struct rechunk_t { |
25 | 25 |
} rechunk_t; |
26 | 26 |
|
27 | 27 |
typedef struct undo_t { |
28 |
- char type[4]; |
|
28 |
+ char type; |
|
29 | 29 |
long off; |
30 | 30 |
long len; |
31 | 31 |
long posorig; |
... | ... |
@@ -88,9 +88,9 @@ int redata_chunk_deletedata(redata_t *redata, int chunkno, long pos, long n); |
88 | 88 |
int redata_whatin_refresh(redata_t *redata, int chunkno); |
89 | 89 |
int redata_fix_nl(redata_t *redata, int chunkno); |
90 | 90 |
int redata_undobuf_reserve(redata_t *redata, undostack_t *stack, int minavail); |
91 |
-undo_t *redata_undo_new(redata_t *redata, undostack_t *stack, char *type); |
|
92 |
-undo_t *redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char *type, int pos1, int len); |
|
93 |
-undo_t *redata_undo_newfrombuf(redata_t *redata, undostack_t *stack, char *type, char *buf, int buflen); |
|
91 |
+undo_t *redata_undo_new(redata_t *redata, undostack_t *stack, char type); |
|
92 |
+undo_t *redata_undo_newfromchunks(redata_t *redata, undostack_t *stack, char type, int pos1, int len); |
|
93 |
+undo_t *redata_undo_newfrombuf(redata_t *redata, undostack_t *stack, char type, char *buf, int buflen); |
|
94 | 94 |
int redata_undo_movelast(redata_t *redata, undostack_t *from, undostack_t *to); |
95 | 95 |
int redata_undo_removelast(redata_t *redata, undostack_t *stack); |
96 | 96 |
int redata_undo_wipe(redata_t *redata, undostack_t *stack); |
... | ... |
@@ -171,7 +171,7 @@ fprintf(stderr,"\ntest_edit(%s%s%s,%s%s%s,%i,%i);\nResult: ",(filename!=NULL)?"\ |
171 | 171 |
progress[l]=(l<(sizeof(progress)-2))?*ptr:'+'; |
172 | 172 |
progress[l+1]='\0'; |
173 | 173 |
} |
174 |
-if(k!=0) redata_save(redata,"test.pre"); |
|
174 |
+/*if(k!=0) redata_save(redata,"test.pre");*/ |
|
175 | 175 |
if(*ptr=='A') { |
176 | 176 |
/* A<insertpos><endchar><text><endchar> */ |
177 | 177 |
ptr++; |
... | ... |
@@ -205,7 +205,7 @@ if(k!=0) redata_save(redata,"test.pre"); |
205 | 205 |
return(errorbuf); |
206 | 206 |
} |
207 | 207 |
if(k!=0) { |
208 |
-if(k!=0) redata_save(redata,"test.post"); |
|
208 |
+/*if(k!=0) redata_save(redata,"test.post");*/ |
|
209 | 209 |
redata_hash(redata,hash129_redata); |
210 | 210 |
redata_memhash(redata,mem,cursize,hash129_mem); |
211 | 211 |
if(strcmp(hash129_redata,hash129_mem)!=0) { |
... | ... |
@@ -217,7 +217,7 @@ if(k!=0) redata_save(redata,"test.post"); |
217 | 217 |
return(errorbuf); |
218 | 218 |
} |
219 | 219 |
redata_op_undo(redata); |
220 |
-redata_save(redata,"test.undo"); |
|
220 |
+/*redata_save(redata,"test.undo");*/ |
|
221 | 221 |
redata_hash(redata,hash129_redata); |
222 | 222 |
if(strcmp(hash129_redata,hash129_memold)!=0) { |
223 | 223 |
if(mem!=NULL) |
... | ... |
@@ -228,7 +228,7 @@ redata_save(redata,"test.undo"); |
228 | 228 |
return(errorbuf); |
229 | 229 |
} |
230 | 230 |
redata_op_redo(redata); |
231 |
-redata_save(redata,"test.redo"); |
|
231 |
+/*redata_save(redata,"test.redo");*/ |
|
232 | 232 |
redata_hash(redata,hash129_redata); |
233 | 233 |
if(strcmp(hash129_redata,hash129_mem)!=0) { |
234 | 234 |
if(mem!=NULL) |