"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/macros.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.

macros.cpp  (bed-3.0.3.src.tar.xz):macros.cpp  (bed-3.1.0.src.tar.xz)
skipping to change at line 25 skipping to change at line 25
/* */ /* */
/* You should have received a copy of the GNU General Public License */ /* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */ /* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Fri Dec 8 22:14:27 2000 */ /* Fri Dec 8 22:14:27 2000 */
#include <stdio.h> #include <stdio.h>
#include "screen.h" #include "screen.h"
#include "myalloc.h" #include "myalloc.h"
#include "macros.h" #include "macros.h"
#include <string.h> #include <string.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#include "system.h" #include "system.h"
extern int writemacroheader(int handle) ; extern int writemacroheader(int handle) ;
#ifdef HAVE_SYS_MMAN_H
static int extendfile(int file, int newmax) { static int extendfile(int file, int newmax) {
unsigned long endstr[]={0xFAFAFAFA}; unsigned long endstr[]={0xFAFAFAFA};
int newpos=newmax-sizeof(endstr); int newpos=newmax-sizeof(endstr);
if(lseek(file,newpos,SEEK_SET)!=newpos) { if(lseek(file,newpos,SEEK_SET)!=newpos) {
return -1; return -1;
} }
if(write(file,endstr,sizeof(endstr))!=sizeof(endstr)) { if(write(file,endstr,sizeof(endstr))!=sizeof(endstr)) {
return -1;}; return -1;};
return 0; return 0;
} }
#endif
void Keystrokes::flush(void) { void Keystrokes::flush(void) {
*inp=out=0; *inp=out=0;
} }
Keystrokes::Keystrokes(char *na):name(na) { Keystrokes::Keystrokes(char *na):name(na) {
inp=&inbuf; inp=&inbuf;
*inp=out=max=0; *inp=out=max=0;
buf=NULL; buf=NULL;
file=-1; file=-1;
mmaptofile(na); mmaptofile(na);
} }
#ifdef HAS_PREAD #ifdef HAS_PREAD
#define poswrite(handle,off,str, len) pwrite(handle,str,len,off) #define poswrite(handle,off,str, len) pwrite(handle,str,len,off)
#else #else
#define poswrite(handle,off,str, len) ((lseek(handle,off,SEEK_SET),write( handle,str,len)) #define poswrite(handle,off,str, len) ((lseek(handle,off,SEEK_SET),write( handle,str,len))
#endif #endif
extern const int startmacrodata; extern const int startmacrodata;
ssize_t getmacroheader(char *macroheader); ssize_t getmacroheader(char *macroheader);
#ifdef HAVE_SYS_MMAN_H
int Keystrokes::mmaptofile(char *name) { int Keystrokes::mmaptofile(char *name) {
if(name) { if(name) {
file=open(name,O_RDWR|O_CREAT BINARY_FLAG,0600); file=open(name,O_RDWR|O_CREAT BINARY_FLAG,0600);
if(file>0) { if(file>0) {
Strokekeytype *tmp; Strokekeytype *tmp;
int in=*inp; int in=*inp;
int newmax=((max*sizeof(Strokekeytype)+4096)/4096 )*4096; int newmax=((max*sizeof(Strokekeytype)+4096)/4096 )*4096;
if(extendfile(file,newmax)<0) { if(extendfile(file,newmax)<0) {
close(file);file=-1;return -1; close(file);file=-1;return -1;
} }
/*
char *macroheader=(char *)alloca(startmacrodata);
getmacroheader(macroheader);
poswrite(file,0,macroheader, startmacrodata);
*/
if((tmp= ( Strokekeytype*)mmap(NULL, newmax, PROT _WRITE|PROT_READ , MAP_SHARED, file,0))==MAP_FAILED) { if((tmp= ( Strokekeytype*)mmap(NULL, newmax, PROT _WRITE|PROT_READ , MAP_SHARED, file,0))==MAP_FAILED) {
close(file); close(file);
file=-1; file=-1;
return file; return file;
} }
getmacroheader(tmp); getmacroheader(tmp);
memcpy(((char *)tmp)+50,buf+out,(in-out)*sizeof(S trokekeytype)); memcpy(((char *)tmp)+50,buf+out,(in-out)*sizeof(S trokekeytype));
in-=out;out=0; in-=out;out=0;
inp=(int *)(((char *)tmp)+46); inp=(int *)(((char *)tmp)+46);
*inp=in; *inp=in;
max=(newmax/sizeof(Strokekeytype))-50; max=(newmax/sizeof(Strokekeytype))-50;
buf=(Strokekeytype *)((char *)tmp+50); buf=(Strokekeytype *)((char *)tmp+50);
} }
return file; return file;
} }
return -1; return -1;
} }
#else
int Keystrokes::mmaptofile(char *name) {
return -1;
}
#endif
int Keystrokes::fill(Strokekeytype *keys,int len) { int Keystrokes::fill(Strokekeytype *keys,int len) {
if(len<=0||!keys) if(len<=0||!keys)
return len; return len;
alloc(len); alloc(len);
memmove(buf+(*inp),keys,len*sizeof(Strokekeytype)); memmove(buf+(*inp),keys,len*sizeof(Strokekeytype));
(*inp)+=len; (*inp)+=len;
return len; return len;
} }
int Keystrokes::fill(Keystrokes &other) { int Keystrokes::fill(Keystrokes &other) {
return fill(other.buf+other.out,*(other.inp)-other.out); return fill(other.buf+other.out,*(other.inp)-other.out);
} }
Keystrokes::~Keystrokes() { Keystrokes::~Keystrokes() {
#ifdef HAVE_SYS_MMAN_H
if(file>0) { if(file>0) {
if(munmap(((char *)buf)-50,(max*sizeof(Strokekeytype))+50 )<0) { if(munmap(((char *)buf)-50,(max*sizeof(Strokekeytype))+50 )<0) {
perror("munmap failed"); perror("munmap failed");
} }
close(file); close(file);
file=-1; file=-1;
} }
else { else
#endif
{
*inp=out=max=0; *inp=out=max=0;
myfree(buf); myfree(buf);
} }
if(name) { if(name) {
// remove(name); // remove(name);
unlink(name); unlink(name);
free(name); free(name);
name=NULL; name=NULL;
} }
} }
/* /*
file format file format
0-49: header 0-49: header
50,..: data 50,..: data
max: dataitems Strokekeytype size max: dataitems Strokekeytype size
*/ */
void Keystrokes::alloc(int len) { void Keystrokes::alloc(int len) {
if(max<(*inp+len)) { if(max<(*inp+len)) {
#ifdef HAVE_SYS_MMAN_H
if(file>0) { if(file>0) {
int newmax=2*((max*sizeof(Strokekeytype))+50),in= *inp; int newmax=2*((max*sizeof(Strokekeytype))+50),in= *inp;
Strokekeytype *ptr; Strokekeytype *ptr;
if(extendfile(file,newmax)<0|| if(extendfile(file,newmax)<0||
#ifdef HAS_MREMAP #ifdef HAS_MREMAP
((ptr=(Strokekeytype *) mremap (((char *)buf)-50,max*sizeof(Strokekeytype)+50, newmax, MREMAP_MAYMOVE))==MAP_FAILED) ((ptr=(Strokekeytype *) mremap (((char *)buf)-50,max*sizeof(Strokekeytype)+50, newmax, MREMAP_MAYMOVE))==MAP_FAILED)
#else #else
((ptr=(Strokekeytype *)mmap(NULL,newmax, PROT_WRITE|PROT_READ , MAP_SHARED, fi le,0))==MAP_FAILED)|| (memcpy(ptr,((char *)buf)-50,max*sizeof(Strokekeytype)+50) ,munmap(((char*)buf)-50,(max*sizeof(Strokekeytype))+50),0) ((ptr=(Strokekeytype *)mmap(NULL,newmax, PROT_WRITE|PROT_READ , MAP_SHARED, fi le,0))==MAP_FAILED)|| (memcpy(ptr,((char *)buf)-50,max*sizeof(Strokekeytype)+50) ,munmap(((char*)buf)-50,(max*sizeof(Strokekeytype))+50),0)
#endif #endif
) { ) {
skipping to change at line 156 skipping to change at line 167
out=0; out=0;
buf=ptr; buf=ptr;
max=newmax/sizeof(Strokekeytype); max=newmax/sizeof(Strokekeytype);
} }
else { else {
inp=(int *)(((char *)ptr)+46); inp=(int *)(((char *)ptr)+46);
buf=(Strokekeytype*)(((char *)ptr)+50); buf=(Strokekeytype*)(((char *)ptr)+50);
max=newmax/sizeof(Strokekeytype)-50; max=newmax/sizeof(Strokekeytype)-50;
} }
} }
else { else
#endif
{
Strokekeytype *tmp=buf; Strokekeytype *tmp=buf;
int newmax=2*((max*sizeof(Strokekeytype))+100+len ); int newmax=2*((max*sizeof(Strokekeytype))+100+len );
buf=myrealloc(Strokekeytype *,tmp,Strokekeytype,n ewmax,max*sizeof(Strokekeytype)) ; buf=myrealloc(Strokekeytype *,tmp,Strokekeytype,n ewmax,max*sizeof(Strokekeytype)) ;
max=newmax/sizeof(Strokekeytype); max=newmax/sizeof(Strokekeytype);
} }
} }
} }
void Keystrokes::add(int key) { void Keystrokes::add(int key) {
if(*inp==out) if(*inp==out)
*inp=out=0; *inp=out=0;
 End of changes. 10 change blocks. 
9 lines changed or deleted 22 lines changed or added

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