"Fossies" - the Fresh Open Source Software Archive  

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

About: bed is an adjustable data format binary editor.

marken.cpp  (bed-3.0.2.src.tar.xz):marken.cpp  (bed-3.0.3.src.tar.xz)
skipping to change at line 34 skipping to change at line 34
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
#include "screenpart.h" #include "screenpart.h"
#include "system.h" #include "system.h"
#include "marks.h" #include "marks.h"
#include "screen.h" #include "screen.h"
#include "config.h" #include "config.h"
const int MAXOFFTYPE=(sizeof(OFFTYPE)<8?8:sizeof(OFFTYPE)); const int MAXOFFTYPE=(sizeof(OFFTYPE)<8?8:sizeof(OFFTYPE));
extern void mychdir(const char *path); extern void mychdir(const char *path);
extern char *mygetcwd(char *name,int len) ; extern char *mygetcwd(char *name,int len) ;
#define marx (*marksptr) //#define marx (*marksptr)
#ifdef USETHREADS #ifdef USETHREADS
#define startwait sem_wait(&sema); #define startwait sem_wait(&sema);
#define postwait sem_post(&sema); #define postwait sem_post(&sema);
#else #else
#define startwait #define startwait
#define postwait #define postwait
#endif #endif
int Editor::addmark(OFFTYPE pos,int len) { int Editor::addmark(OFFTYPE pos,int len) {
unsigned char r27[]={27,27,27}; unsigned char r27[]={27,27,27};
skipping to change at line 66 skipping to change at line 66
char *des=myallocarp(char *,char,MAXMARKDAT+1); char *des=myallocarp(char *,char,MAXMARKDAT+1);
if((pos+MAXMARKDAT+1)>filesize()) { if((pos+MAXMARKDAT+1)>filesize()) {
int atfile= filesize()-pos; int atfile= filesize()-pos;
getmem(pos,des,atfile); getmem(pos,des,atfile);
memset(des+atfile,0,MAXMARKDAT+1-atfile); memset(des+atfile,0,MAXMARKDAT+1-atfile);
} }
else { else {
getmem(pos,des,MAXMARKDAT); getmem(pos,des,MAXMARKDAT);
des[MAXMARKDAT]='\0'; des[MAXMARKDAT]='\0';
} }
marx.putkeys(keys, nr, pos,des,len) ; marksptr->putkeys(keys, nr, pos,des,len) ;
return 0; return 0;
} }
extern int mywgetch(WINDOW *win) ; extern int mywgetch(WINDOW *win) ;
extern bool mykbhit(void) ; extern bool mykbhit(void) ;
int Editor::keymark(void) { int Editor::keymark(void) {
int i,key; int i,key;
unsigned char keys[100]; unsigned char keys[100];
output("Mark: Type key"); output("Mark: Type key");
wrefresh(editscreen); wrefresh(editscreen);
keys[0]=mywgetch(stdscr); keys[0]=mywgetch(stdscr);
skipping to change at line 136 skipping to change at line 136
int key; int key;
struct keylookup::mark *mark; struct keylookup::mark *mark;
output("Goto mark: type key"); output("Goto mark: type key");
wrefresh(editscreen); wrefresh(editscreen);
while(1) { while(1) {
key=ggetch(stdscr); key=ggetch(stdscr);
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
if((mark=marx.lookup(key))) if((mark=marksptr->lookup(key)))
break; break;
if(marx.isstart()) { if(marksptr->isstart()) {
flushinp(); flushinp();
beep(); beep();
output("Goto mark: Unknown key"); output("Goto mark: Unknown key");
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
return -1; return -1;
}; };
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
skipping to change at line 167 skipping to change at line 167
return mkstandout( mark->pos, mark->len); return mkstandout( mark->pos, mark->len);
}; };
int Editor::nextmark(void) { int Editor::nextmark(void) {
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
struct keylookup::mark *mark; struct keylookup::mark *mark;
do { do {
mark=marx.next(); mark=marksptr->next();
if(!mark) { if(!mark) {
beep(); beep();
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
return -1; return -1;
}; };
} while((editpos+filepos)==(OFFTYPE)mark->pos); } while((editpos+filepos)==(OFFTYPE)mark->pos);
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
skipping to change at line 199 skipping to change at line 199
return toborderpos(pos-off) ; return toborderpos(pos-off) ;
else else
return topos(pos) ; return topos(pos) ;
} }
int Editor::prevmark(void) { int Editor::prevmark(void) {
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
struct keylookup::mark *mark; struct keylookup::mark *mark;
do { do {
mark=marx.prev(); mark=marksptr->prev();
if(!mark) { if(!mark) {
beep(); beep();
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
return -1; return -1;
}; };
} while((editpos+filepos)==(OFFTYPE)mark->pos); } while((editpos+filepos)==(OFFTYPE)mark->pos);
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
return mkstandout( mark->pos, mark->len); return mkstandout( mark->pos, mark->len);
}; };
#define STARTSHOW 10 #define STARTSHOW 10
extern int getindatatype(ScreenPart *thesub) ; extern int getindatatype(ScreenPart *thesub) ;
int Editor::sortmarks(void) { int Editor::sortmarks(void) {
startwait startwait
marx.sort() ; marksptr->sort() ;
postwait postwait
message("Sorted"); message("Sorted");
return 0; return 0;
} }
int Editor::clearmarks(void) { int Editor::clearmarks(void) {
int nr; int nr;
if(marx.head==&marx.begin) { if(marksptr->head==&marksptr->begin) {
message("No marks to clear"); message("No marks to clear");
return -1; return -1;
} }
switch(getkeyinput("Do you really want to clear all marks? (y/n)")) { switch(getkeyinput("Do you really want to clear all marks? (y/n)")) {
case 'y': case 'y':
case 'Y': case 'Y':
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
nr=marx.deleteall() ; nr=marksptr->deleteall() ;
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
message("%d marks deleted",nr); message("%d marks deleted",nr);
break; break;
default: message("Cancelled!"); default: message("Cancelled!");
} }
return 0; return 0;
} }
int Editor::deletemark(void) { int Editor::deletemark(void) {
struct keylookup::mark *mark= markselect<2>("Press return to delete mark" ) ; struct keylookup::mark *mark= markselect<2>("Press return to delete mark" ) ;
if(mark) { if(mark) {
marx.select(mark); marksptr->select(mark);
marx.rmmark(mark); marksptr->rmmark(mark);
marx.prev(); marksptr->prev();
return 0; return 0;
} }
return -1; return -1;
} }
const int MARKFILEGEGSIZE=300; const int MARKFILEGEGSIZE=300;
char marksign[]="\276\320bed marks of "; char marksign[]="\276\320bed marks of ";
char marksend[]="\276\320bed end"; char marksend[]="\276\320bed end";
const int marklen=sizeof(marksign)-1; const int marklen=sizeof(marksign)-1;
const int marksendlen=sizeof(marksend)-1; const int marksendlen=sizeof(marksend)-1;
skipping to change at line 305 skipping to change at line 305
if(!ant) { if(!ant) {
mygetcwd(markdirectory,BEDSMAXPATH); mygetcwd(markdirectory,BEDSMAXPATH);
mychdir(cwdold); mychdir(cwdold);
return -1; return -1;
} }
} while((handle=openfile(ant))==MY_INVALID_HANDLE_VALUE); } while((handle=openfile(ant))==MY_INVALID_HANDLE_VALUE);
mygetcwd(markdirectory,BEDSMAXPATH); mygetcwd(markdirectory,BEDSMAXPATH);
mychdir(cwdold); mychdir(cwdold);
struct keylookup::mark *mark,*first; struct keylookup::mark *mark,*first;
startwait startwait
first=marx.next(); first=marksptr->next();
marx.tobegin(); marksptr->tobegin();
int emptylen= MARKFILEGEGSIZE; int emptylen= MARKFILEGEGSIZE;
char empty[MARKFILEGEGSIZE]; char empty[MARKFILEGEGSIZE];
memset(empty,0xAF,emptylen); memset(empty,0xAF,emptylen);
writetofile(handle,marksign,marklen); writetofile(handle,marksign,marklen);
int flen=mem.filenamelen+1; int flen=mem.filenamelen+1;
writetofile(handle,mem.filename,flen); writetofile(handle,mem.filename,flen);
// writetofile(handle,empty,(BEDS_SIZE_T)MARKFILEGEGSIZE-flen-marklen-28); // writetofile(handle,empty,(BEDS_SIZE_T)MARKFILEGEGSIZE-flen-marklen-28);
// //
skipping to change at line 337 skipping to change at line 337
writetofile(handle,(char *)&tim,8); writetofile(handle,(char *)&tim,8);
writetofile(handle,empty,4); writetofile(handle,empty,4);
/* /*
4: Aantal marks 4: Aantal marks
8: Datum 8: Datum
256: Filename 256: Filename
268 268
32 32
*/ */
for(nrmarks=0;(mark=marx.next());nrmarks++) { for(nrmarks=0;(mark=marksptr->next());nrmarks++) {
/* *((OFFTYPE *)&pos )=mark->pos; /* *((OFFTYPE *)&pos )=mark->pos;
writetofile(handle,pos, MAXOFFTYPE); writetofile(handle,pos, MAXOFFTYPE);
*/ */
writeofftype(handle, mark->pos); writeofftype(handle, mark->pos);
writetofile(handle,mark->des, MAXMARKDAT); writetofile(handle,mark->des, MAXMARKDAT);
writetofile(handle,empty, MAXMARKALL-MAXMARKDAT-4); writetofile(handle,empty, MAXMARKALL-MAXMARKDAT-4);
writetofile(handle,(char *) &(mark->len), 4); /*added length*/ writetofile(handle,(char *) &(mark->len), 4); /*added length*/
writetofile(handle,&mark->nrkeys, 1); writetofile(handle,&mark->nrkeys, 1);
writetofile(handle,(char *)mark->keys, mark->nrkeys); writetofile(handle,(char *)mark->keys, mark->nrkeys);
if(mark->nrkeys<10) if(mark->nrkeys<10)
writetofile(handle,empty,10-mark->nrkeys); writetofile(handle,empty,10-mark->nrkeys);
} }
writetofile(handle,marksend,marksendlen); writetofile(handle,marksend,marksendlen);
setfilepos(handle,(OFFTYPE) (MARKFILEGEGSIZE-4L)); setfilepos(handle,(OFFTYPE) (MARKFILEGEGSIZE-4L));
writetofile(handle,(char *)&nrmarks,4); writetofile(handle,(char *)&nrmarks,4);
closehandle(handle); closehandle(handle);
marx.select(first); marksptr->select(first);
marx.prev(); marksptr->prev();
postwait postwait
editup(); editup();
message("%d marks saved to %s",nrmarks,ant); message("%d marks saved to %s",nrmarks,ant);
return 0; return 0;
} }
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
int Editor::readmarks(void) { int Editor::readmarks(void) {
char cwdold[BEDSMAXPATH]; char cwdold[BEDSMAXPATH];
skipping to change at line 464 skipping to change at line 464
des[MAXMARKDAT]='\0'; des[MAXMARKDAT]='\0';
if(read(handle,keys,nrkeys)<nrkeys) { if(read(handle,keys,nrkeys)<nrkeys) {
message("Error reading keys for pos " OFFPRINT, gegs.pos); message("Error reading keys for pos " OFFPRINT, gegs.pos);
myfree (des); myfree (des);
return -1; return -1;
} }
if(nrkeys<10) { if(nrkeys<10) {
lseek(handle,10-nrkeys,SEEK_CUR); lseek(handle,10-nrkeys,SEEK_CUR);
} }
startwait startwait
marx.putkeys(keys, nrkeys, gegs.pos,des,mlen) ; marksptr->putkeys(keys, nrkeys, gegs.pos,des,mlen) ;
postwait postwait
} }
} }
close(handle); close(handle);
editup(); editup();
if(i!=nrmarks) { if(i!=nrmarks) {
message("Found %d instead of %d marks",i,nrkeys); message("Found %d instead of %d marks",i,nrkeys);
} }
if(errors) if(errors)
message("%d marks: %d added, %d outside limits",nrmarks,nrmarks-e rrors,errors); message("%d marks: %d added, %d outside limits",nrmarks,nrmarks-e rrors,errors);
skipping to change at line 575 skipping to change at line 575
if(rmmarkpos(gegs.pos)>=0) if(rmmarkpos(gegs.pos)>=0)
del++; del++;
else else
notdel++; notdel++;
} }
} }
close(handle); close(handle);
editup(); editup();
if(errors) { if(errors) {
message("%d marks deleted, %d not present, %d outside limits",del ,notdel,errors); message("%d marks deleted, %d not present, %d outside limits",del ,notdel,errors);
assert(nrmarks=(del+notdel+errors)); assert(nrmarks==(del+notdel+errors));
} }
else { else {
message("%d marks deleted, %d not present",del,notdel); message("%d marks deleted, %d not present",del,notdel);
assert(nrmarks=(del+notdel)); assert(nrmarks==(del+notdel));
} }
return 0; return 0;
} }
int Editor::rmmarkpos(OFFTYPE pos) { int Editor::rmmarkpos(OFFTYPE pos) {
struct keylookup::mark *mark,*first; struct keylookup::mark *mark,*first;
startwait startwait
first=marx.next(); first=marksptr->next();
marx.tobegin(); marksptr->tobegin();
while((mark=marx.next())) { while((mark=marksptr->next())) {
if(mark->pos==pos) { if(mark->pos==pos) {
marx.select(mark); marksptr->select(mark);
marx.rmmark(mark); marksptr->rmmark(mark);
marx.prev(); marksptr->prev();
postwait postwait
return 0; return 0;
} }
} }
marx.select(first); marksptr->select(first);
marx.prev(); marksptr->prev();
postwait postwait
return -1; return -1;
} }
template<> struct keylookup::mark *Editor::markselect<1>(const char *prompt) { template<> struct keylookup::mark *Editor::markselect<1>(const char *prompt) {
//struct keylookup::mark * Editor::markselectwhole(const char *prompt) { //struct keylookup::mark * Editor::markselectwhole(const char *prompt) {
static int size=STARTSHOW; static int size=STARTSHOW;
static char **names=myallocarpr(char **,char*,STARTSHOW); static char **names=myallocarpr(char **,char*,STARTSHOW);
struct keylookup::mark *mark,*first; struct keylookup::mark *mark,*first;
int i,take=0,ant,tot; int i,take=0,ant,tot;
ScreenPart *activepart=parts[mode]->getsubpart(); ScreenPart *activepart=parts[mode]->getsubpart();
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
first=marx.iter->next; first=marksptr->iter->next;
mark= &marx.begin; mark= &marksptr->begin;
int aloc=maxnum(((MAXMARKDAT/activepart->bytes)+1)*(activepart->maxres+act ivepart->apart+1),MAXFILES)+1+sizeof(mark); int aloc=maxnum(((MAXMARKDAT/activepart->bytes)+1)*(activepart->maxres+act ivepart->apart+1),MAXFILES)+1+sizeof(mark);
for(i=0;mark!=marx.head;i++) { for(i=0;mark!=marksptr->head;i++) {
mark=mark->next; mark=mark->next;
if(first==mark) if(first==mark)
take=i; take=i;
if(i>=size) { if(i>=size) {
const int oldsize __attribute__ ((unused)) =size; const int oldsize __attribute__ ((unused)) =size;
size*=2; size*=2;
names=myrealloc(char **,names,char*,size,oldsize); names=myrealloc(char **,names,char*,size,oldsize);
} }
names[i]=myallocar(char,aloc); names[i]=myallocar(char,aloc);
int slen=activepart->fromascii((unsigned char*)names[i], (unsigne d char *)mark->des,MAXMARKDAT); int slen=activepart->fromascii((unsigned char*)names[i], (unsigne d char *)mark->des,MAXMARKDAT);
skipping to change at line 663 skipping to change at line 663
for(i=0;i<tot;i++) for(i=0;i<tot;i++)
myrefree(names[i]); myrefree(names[i]);
editup(); editup();
return mark; return mark;
} }
template <int typ> int Editor::showmarks(void) { template <int typ> int Editor::showmarks(void) {
int bufsize=30; int bufsize=30;
char buf[bufsize]; char buf[bufsize];
auto total= marx.gettotal(); auto total= marksptr->gettotal();
struct keylookup::mark *mark= markselect<typ>(total>1?(snprintf(buf,bufsi ze,"%d marks",total),buf):"1 mark") ; struct keylookup::mark *mark= markselect<typ>(total>1?(snprintf(buf,bufsi ze,"%d marks",total),buf):"1 mark") ;
if(mark) { if(mark) {
mkstandout( mark->pos, mark->len); mkstandout( mark->pos, mark->len);
#ifdef USETHREADS #ifdef USETHREADS
sem_wait(&sema); sem_wait(&sema);
#endif #endif
marx.select(mark); marksptr->select(mark);
marx.prev(); marksptr->prev();
#ifdef USETHREADS #ifdef USETHREADS
sem_post(&sema); sem_post(&sema);
#endif #endif
return 0; return 0;
} }
return 1; return 1;
} }
//int Editor::showmarks(void) {return showmarks<0>();}; //int Editor::showmarks(void) {return showmarks<0>();};
//int Editor::showmarkswhole(void) {return showmarks<1>();}; //int Editor::showmarkswhole(void) {return showmarks<1>();};
 End of changes. 23 change blocks. 
34 lines changed or deleted 34 lines changed or added

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