"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "plugins/examples/searchclip.cc" 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.

searchclip.cc  (bed-3.0.3.src.tar.xz):searchclip.cc  (bed-3.1.0.src.tar.xz)
#include "global.h" #include "global.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include "config.h" #include "config.h"
#include "varmacro.h" #include "varmacro.h"
#include CURSES_HEADER #include CURSES_HEADER
//#define DEBUGGING(...) fprintf(stderr,__VA_ARGS__)
#ifndef DEBUGGING
#ifdef OLDGCCVARMACRO #ifdef OLDGCCVARMACRO
#define DEBUGGING(var...) #define DEBUGGING(var...)
#else #else
#define DEBUGGING(...) #define DEBUGGING(...)
#endif #endif
#endif
#define MAXLEN 50 #define MAXLEN 50
BEDPLUGIN BEDPLUGIN
#define minnum(x,y) ((x)<(y)?(x):(y)) #define minnum(x,y) ((x)<(y)?(x):(y))
extern Editor *getselectioneditor(void); extern Editor *getselectioneditor(void);
#ifdef _WIN32 #ifdef _WIN32
#define alignedalloc(bs,size) (char *)::aligned_alloc(bs, size) #define ALIGNMEMORY
#else
#define alignedalloc(bs,size) (char *)::malloc(size)
#endif #endif
#include "../../src/alignmem.h"
class Editor { class Editor {
#include "faked.h" #include "faked.h"
public: public:
int searchclip(void) { int searchclip(void) {
char *ptr; char *ptr;
int len=getselbuf( &ptr); int len=getselbuf( &ptr);
// int uit=creat("selectie.dat",0777); write(uit,ptr,len); close(uit);
const OFFTYPE startpos=getfilepos()+geteditpos(); const OFFTYPE startpos=getfilepos()+geteditpos();
const OFFTYPE fsize=filesize(); const OFFTYPE fsize=filesize();
if(len<=0) { if(len<=0) {
message("Nothing in copy buffer"); message("Nothing in copy buffer");
beep(); beep();
return -1; return -1;
} }
BLOCKTYPE BLOCKSIZE=blocksize(); BLOCKTYPE BLOCKSIZE=blocksize();
int takelen=minnum(len,BLOCKSIZE); int takelen=minnum(len,BLOCKSIZE);
char *buf=(char *)alignedalloc(BLOCKSIZE,BLOCKSIZE); char *buf=(char *)alignedalloc(BLOCKSIZE,BLOCKSIZE);
OFFTYPE res=startpos; OFFTYPE res=startpos;
for(;;){ for(;;){
FURTHER: FURTHER:
res=dosearch(res,ptr,takelen); res=dosearch(res,ptr,takelen);
if(res==OFFTYPEINVALID) { if(res==OFFTYPEINVALID) {
DEBUGGING("Not found"); DEBUGGING("Not found");
topos(startpos); topos(startpos);
message("Content copy buffer not found"); message("Content copy buffer not found");
beep(); beep();
::free(buf); alignedfree(buf);
return -1; return -1;
} }
DEBUGGING("Found start " OFFPRINT,res); DEBUGGING("Found start " OFFPRINT,res);
OFFTYPE compstart=res+takelen; OFFTYPE compstart=res+takelen;
int inblock=compstart%BLOCKSIZE; int inblock=compstart%BLOCKSIZE;
BLOCKTYPE bl=compstart/BLOCKSIZE; BLOCKTYPE bl=compstart/BLOCKSIZE;
int max=minnum(len,fsize-res); int max=minnum(len,fsize-res);
for(int pos=takelen;pos<max;pos+=(BLOCKSIZE-inblock),inblock=0) { for(int pos=takelen;pos<max;pos+=(BLOCKSIZE-inblock),inblock=0) {
int size=minnum(BLOCKSIZE-inblock,max-pos); int size=minnum(BLOCKSIZE-inblock,max-pos);
int take=getblock(bl++,buf); int take=getblock(bl++,buf);
// getmem(res+pos,buf,size); // getmem(res+pos,buf,size);
if(take<size||memcmp(buf+inblock,ptr+pos,size)) { if(take<size||memcmp(buf+inblock,ptr+pos,size)) {
DEBUGGING("partial match " OFFPRINT" to " OFFPRIN T,res,pos ); DEBUGGING("partial match " OFFPRINT" to %d" ,res, pos );
if(res>=startpos) if(res>=startpos)
res++; res++;
else else
res--; res--;
goto FURTHER; goto FURTHER;
} }
} }
::free(buf); alignedfree(buf);
if(max<len) { if(max<len) {
message("Reached end of file matched for %ld bytes at " O FFPRINT,max,res); message("Reached end of file matched for %ld bytes at " O FFPRINT,max,res);
beep(); beep();
return -1; return -1;
} }
else else
message("Found content copy buffer at " OFFPRINT " (#%ld) ",res,len); message("Found content copy buffer at " OFFPRINT " (#%ld) ",res,len);
topos(res); topos(res);
return 0; return 0;
} }
} }
int compare(void) { int compare(void) {
Editor *ed; Editor *ed;
message("Compare selection to current file from cursor position ...");
if((ed=getselectioneditor())) { if((ed=getselectioneditor())) {
OFFTYPE len,start; OFFTYPE len,start;
if((len=ed->getselregion(&start))) { if((len=ed->getselregion(&start))) {
BLOCKTYPE BLOCKSIZE=blocksize(); BLOCKTYPE BLOCKSIZE=blocksize();
OFFTYPE curpos=getfilepos()+geteditpos(); OFFTYPE curpos=getfilepos()+geteditpos();
OFFTYPE fsize=filesize(),left=fsize-curpos; OFFTYPE fsize=filesize(),left=fsize-curpos;
OFFTYPE end=minnum(len,left); OFFTYPE end=minnum(len,left);
for(OFFTYPE pos=0;pos<end;pos+=BLOCKSIZE) { for(OFFTYPE pos=0;pos<end;pos+=BLOCKSIZE) {
char bufhere[BLOCKSIZE],bufthere[BLOCKSIZE]; char bufhere[BLOCKSIZE],bufthere[BLOCKSIZE];
int size=minnum(BLOCKSIZE,end-pos); int size=minnum(BLOCKSIZE,end-pos);
 End of changes. 9 change blocks. 
7 lines changed or deleted 10 lines changed or added

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