"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/undo.cpp" between
bed-3.0.3.src.tar.xz and bed-3.1.0.src.tar.xz

About: bed is an adjustable data format binary editor.

undo.cpp  (bed-3.0.3.src.tar.xz):undo.cpp  (bed-3.1.0.src.tar.xz)
skipping to change at line 69 skipping to change at line 69
if(un->str) { if(un->str) {
myrefree(un->str); myrefree(un->str);
un->str=NULL; un->str=NULL;
} }
un->len=0; un->len=0;
} }
} }
return un; return un;
} }
int Editor::popundo(unsigned char **buf,OFFTYPE *pos) { int Editor::popundo(unsigned char **buf,OFFTYPE *pos,OFFTYPE *diskused) {
int len; int len;
*pos=undobuf[lastundo%MAXUNDO].pos; *pos=undobuf[lastundo%MAXUNDO].pos;
len=undobuf[lastundo%MAXUNDO].len; len=undobuf[lastundo%MAXUNDO].len;
*buf= undobuf[lastundo%MAXUNDO].str; *buf= undobuf[lastundo%MAXUNDO].str;
*diskused=undobuf[lastundo%MAXUNDO].usedondisk;
undobuf[lastundo%MAXUNDO].str=NULL; undobuf[lastundo%MAXUNDO].str=NULL;
lastundo--; lastundo--;
return len; return len;
}; };
/* /*
Use editor procedures: Use editor procedures:
undoone: undoone:
mem.truncatefile(pos); mem.truncatefile(pos);
resetnumbase() ; resetnumbase() ;
mem.extend(pos+ undosize); mem.extend(pos+ undosize);
skipping to change at line 103 skipping to change at line 105
Seperate editor from undo procedures Seperate editor from undo procedures
Editor procedures use general undo procedures Editor procedures use general undo procedures
*/ */
int Editor::undoone(void) { int Editor::undoone(void) {
if(lastundo>=beginundo) { if(lastundo>=beginundo) {
if(searchdontedit()) if(searchdontedit())
return -1; return -1;
unsigned char *bufgegs; unsigned char *bufgegs;
int undosize; int undosize;
OFFTYPE pos; OFFTYPE pos,useddisk;
undosize=popundo(&bufgegs,&pos); undosize=popundo(&bufgegs,&pos,&useddisk);
if(undosize!=0) { if(undosize!=0) {
INCDEST(); INCDEST();
memorize(); memorize();
int oldlastundo=lastundo; int oldlastundo=lastundo;
int oldredos=redos; int oldredos=redos;
if(undosize<0) { /*Truncate undo extend*/ if(undosize<0) { /*Truncate undo extend*/
OFFTYPE thesize=mem.filesize-pos; OFFTYPE thesize=mem.filesize-pos;
strtoundoer(pos,thesize); strtoundoer(pos,thesize);
mem.truncatefile(pos); mem.truncatefile(pos);
resetnumbase() ; resetnumbase() ;
pos--; pos--;
undosize=1; undosize=1;
mem.useddiskfilesize=useddisk;
} }
else { /*size >=0 */ else { /*size >=0 */
if((pos+undosize)>mem.filesize) { /*Extend, undo truncate */ if((pos+undosize)>mem.filesize) { /*Extend, undo truncate */
if(pos!=mem.filesize) { if(pos!=mem.filesize) {
strtoundoer(pos,0); strtoundoer(pos,0);
message("Skipped undo truncate: p os!=mem.filesize"); message("Skipped undo truncate: p os!=mem.filesize");
lastundo=oldlastundo; lastundo=oldlastundo;
redos=oldredos; redos=oldredos;
if(bufgegs) if(bufgegs)
myrefree( bufgegs); myrefree( bufgegs);
DECDEST(); DECDEST();
return 0; return 0;
} }
mem.extend(pos+ undosize); mem.undotruncate(pos+ undosize,useddisk);
resetnumbase() ; resetnumbase() ;
extendtoundoonly(pos); extendtoundoonly(pos);
} }
else { /*Normal undo */ else { /*Normal undo */
strtoundoer(pos,undosize); strtoundoer(pos,undosize);
} }
mem.useddiskfilesize=useddisk;
mem.putpart(pos,undosize,(char *)bufgegs); /*Put undo buffer in filebuffer*/ mem.putpart(pos,undosize,(char *)bufgegs); /*Put undo buffer in filebuffer*/
if(bufgegs) if(bufgegs)
myrefree( bufgegs); myrefree( bufgegs);
} /*end size>=0 */ } /*end size>=0 */
lastundo=oldlastundo; lastundo=oldlastundo;
redos=oldredos; redos=oldredos;
topos(pos); topos(pos);
modified++; modified++;
if(!shouldreinit) if(!shouldreinit)
fromfile(); fromfile();
updated=0; updated=0;
DECDEST(); DECDEST();
return undosize; return undosize;
} }
else { /*undosize==0*/ else { /*undosize==0*/
return 0; return 0;
} }
} }
else // lastundo<beginundo else // lastundo<beginundo
return -1; return -1;
}; };
int Editor::strtoundoer(OFFTYPE pos,int size) { int Editor::strtoundoer(OFFTYPE pos,int size) {
if(pos<0||pos>=filesize()||size<=0) if(pos<0||pos>=filesize()||size<=0)
return -1; return -1;
if((pos+size)>filesize()) { if((pos+size)>filesize()) {
size=(filesize()-pos); size=(filesize()-pos);
} }
struct undo *ptr=getnextundo(); struct undo *ptr=getnextundo();
ptr->len=size; ptr->len=size;
ptr->pos=pos; ptr->pos=pos;
ptr->str=(unsigned char *)expandchunk(ptr->str,size,0); ptr->str=(unsigned char *)expandchunk(ptr->str,size,0);
ptr->usedondisk=mem.useddiskfilesize;
mem.getpart(pos,size,(char *)(ptr->str)); mem.getpart(pos,size,(char *)(ptr->str));
return 0; return 0;
} }
int Editor::appendtoundo(OFFTYPE pos, int size) { int Editor::appendtoundo(OFFTYPE pos, int size) {
if(pos<0||pos>=filesize()||size<=0) if(pos<0||pos>=filesize()||size<=0)
return -1; return -1;
if((pos+size)>filesize()) { if((pos+size)>filesize()) {
size=(filesize()-pos); size=(filesize()-pos);
} }
struct undo *ptr; struct undo *ptr;
freeredos(this); freeredos(this);
if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len>=0&& (p tr->pos+ptr->len)==pos)) if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len>=0&& (p tr->pos+ptr->len)==pos))
{ {
} }
else { else {
ptr=getnextundo(); ptr=getnextundo();
ptr->pos=pos; ptr->pos=pos;
ptr->len=0; ptr->len=0;
ptr->str=NULL; ptr->str=NULL;
ptr->usedondisk=mem.useddiskfilesize;//?
}; };
redos=lastundo; redos=lastundo;
ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+size,ptr->len); ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+size,ptr->len);
mem.getpart(pos,size,(char *)(ptr->str)+ptr->len); mem.getpart(pos,size,(char *)(ptr->str)+ptr->len);
ptr->len+=size; ptr->len+=size;
return 0; return 0;
} }
/* /*
Start Editor interface */ Start Editor interface */
skipping to change at line 212 skipping to change at line 219
struct undo *ptr; struct undo *ptr;
freeredos(this); freeredos(this);
if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len >=0&& (ptr->pos+ptr->len)==pos)) if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len >=0&& (ptr->pos+ptr->len)==pos))
{ {
} }
else { else {
ptr=getnextundo(); ptr=getnextundo();
ptr->pos=pos; ptr->pos=pos;
ptr->len=0; ptr->len=0;
ptr->str=NULL; ptr->str=NULL;
ptr->usedondisk=mem.useddiskfilesize;//?
}; };
redos=lastundo; redos=lastundo;
ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+1,ptr->le n); ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+1,ptr->le n);
ptr->str[ptr->len++]=ch; ptr->str[ptr->len++]=ch;
return 0; return 0;
} }
void Editor::initundo(void) { void Editor::initundo(void) {
MAXUNDO=STARTMAXUNDO; MAXUNDO=STARTMAXUNDO;
undobuf=(struct undo *)calloc(MAXUNDO, sizeof(struct undo)); undobuf=(struct undo *)calloc(MAXUNDO, sizeof(struct undo));
// memset(undobuf,0,sizeof(struct undo)*MAXUNDO); // memset(undobuf,0,sizeof(struct undo)*MAXUNDO);
skipping to change at line 268 skipping to change at line 276
if(pos<0||pos>=filesize()||size<=0) if(pos<0||pos>=filesize()||size<=0)
return -1; return -1;
if((pos+size)>filesize()) { if((pos+size)>filesize()) {
size=(filesize()-pos); size=(filesize()-pos);
} }
freeredos(this); freeredos(this);
struct undo *ptr=getnextundo(); struct undo *ptr=getnextundo();
ptr->len=size; ptr->len=size;
ptr->pos=pos; ptr->pos=pos;
ptr->str=buf; ptr->str=buf;
ptr->usedondisk=mem.useddiskfilesize;//?
redos=lastundo; redos=lastundo;
return 0; return 0;
} }
int Editor::appendstrtoundo(OFFTYPE pos,char *str, int size) { int Editor::appendstrtoundo(OFFTYPE pos,char *str, int size) {
if(pos<0||pos>=filesize()||size<=0) if(pos<0||pos>=filesize()||size<=0)
return -1; return -1;
if((pos+size)>filesize()) { if((pos+size)>filesize()) {
size=(filesize()-pos); size=(filesize()-pos);
} }
struct undo *ptr; struct undo *ptr;
freeredos(this); freeredos(this);
if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len>=0&& (p tr->pos+ptr->len)==pos)) if(lastundo>=beginundo&& (ptr=&undobuf[lastundo%MAXUNDO],ptr->len>=0&& (p tr->pos+ptr->len)==pos))
{ {
} }
else { else {
ptr=getnextundo(); ptr=getnextundo();
ptr->pos=pos; ptr->pos=pos;
ptr->len=0; ptr->len=0;
ptr->usedondisk=mem.useddiskfilesize;//?
ptr->str=NULL; ptr->str=NULL;
}; };
redos=lastundo; redos=lastundo;
ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+size,ptr->len); ptr->str=(unsigned char *)expandchunk(ptr->str,ptr->len+size,ptr->len);
memmove(ptr->str+ptr->len,str,size); memmove(ptr->str+ptr->len,str,size);
ptr->len+=size; ptr->len+=size;
return 0; return 0;
} }
int Editor::extendtoundoonly(OFFTYPE oldsize) { int Editor::extendtoundoonly(OFFTYPE oldsize) {
struct undo *ptr=getnextundo(); struct undo *ptr=getnextundo();
ptr->len=-1; ptr->len=-1;
ptr->pos=oldsize; ptr->pos=oldsize;
ptr->usedondisk=mem.useddiskfilesize;//?
ptr->str=NULL; ptr->str=NULL;
return 0; return 0;
} }
int Editor::extendtoundo(OFFTYPE oldsize) { int Editor::extendtoundo(OFFTYPE oldsize) {
freeredos(this); freeredos(this);
extendtoundoonly(oldsize); extendtoundoonly(oldsize);
redos=lastundo; redos=lastundo;
return 0; return 0;
} }
 End of changes. 13 change blocks. 
4 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)