From 829af5fa425a8d9762bb297f37b5574db7419fde Mon Sep 17 00:00:00 2001 From: Timo Engel Date: Sat, 14 Mar 2026 09:34:37 +0100 Subject: [PATCH] new option to output fixed number of bytes per line --- main.c | 27 +++++++++++++++++++-------- output.c | 12 ++++++------ output.h | 6 +++--- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index a271723..8d068b0 100644 --- a/main.c +++ b/main.c @@ -54,6 +54,7 @@ void helpscreen(char* argv0,int exitval) fprintf(stderr," -g, -G show the license\n"); fprintf(stderr," -f, -F [configfile] read the config from [configfile]\n"); fprintf(stderr," -m, -M [markerfile] read the bookmarks from [markerfile]\n"); + fprintf(stderr," -b, -B [bytes] output [bytes] bytes per output line\n"); fprintf(stderr,"\n"); fprintf(stderr,"%s [Parameters] [Filename]: Edit a single file\n",argv0); fprintf(stderr," -ab, -AB [x] set the base address to [x] (binary)\n"); @@ -130,7 +131,7 @@ int parsecursorpos(tInt64* cursorpos1,tInt64* cursorpos2,char* lastopt,char* arg return RETOK; } -int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr) +int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* baseaddr2,tInt64* cursorpos1,tInt64* cursorpos2,tBool* diffmode,int* filename1,int* filename2,tBool* keyboardsetupreq,char* markerfilename,char* configfile,tSearch* search1,tBool* gosearch1,tSearch* search2,tBool* gosearch2,tCorrelation* correlation,tBool* gocorr,int* dispWidth) { int filenamecnt=0; int i; @@ -341,6 +342,15 @@ int parsecommandlineoptions(int argc,char** argv,tInt64* baseaddr1,tInt64* basea case 'M': if (markerfilename) memcpy(markerfilename,argv[i],64); break; + case 'b': + case 'B': + *dispWidth = atoi(argv[i]); + if (*dispWidth < 1) + { + fprintf(stderr,"invalid bytes per output line\n"); + retval=RETNOK; + } + break; default: retval=RETNOK; break; @@ -374,6 +384,7 @@ int main(int argc,char** argv) tOutput* output=NULL; tInt64 baseaddr1=0; tInt64 cursorpos1; + int dispWidth=0; tInt64 firstpos1; tInt64 baseaddr2=0; tInt64 cursorpos2; @@ -416,7 +427,7 @@ int main(int argc,char** argv) clearsearch(&search1); clearsearch(&search2); clear_correlation(&correlation); - if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr)!=RETOK) + if (parsecommandlineoptions(argc,argv,&baseaddr1,&baseaddr2,&cursorpos1,&cursorpos2,&diffmode,&filename1,&filename2,&keyboardsetupreq,markerfilename,configfile,&search1,&gosearch1,&search2,&gosearch2,&correlation,&gocorr,&dispWidth)!=RETOK) { if (output) { @@ -535,9 +546,9 @@ int main(int argc,char** argv) { printmainmenu(output,diffmode); if (diffmode) - printbufferdiff(output,buf1,buf2,cursorpos1,cursorpos2); + printbufferdiff(output,buf1,buf2,cursorpos1,cursorpos2,dispWidth); else - printbuffersingle(output,buf1,cursorpos1,firstpos1,windowfield); + printbuffersingle(output,buf1,cursorpos1,firstpos1,windowfield,dispWidth); ch=getkey((tKeyTab*)output->pKeyTab,1); #define MOVEMENTDEFINE(KEY,VIKEY,mvchar,mvline,mvpage) \ @@ -549,11 +560,11 @@ int main(int argc,char** argv) oldfirstpos2=firstpos2; \ oldcursorpos2=cursorpos2; \ \ - err=movepositions(&cursorpos1,&firstpos1,buf1->bufsize,mvchar,mvline,mvpage,diffmode); \ + err=movepositions(&cursorpos1,&firstpos1,buf1->bufsize,mvchar,mvline,mvpage,diffmode,dispWidth); \ \ if (diffmode) \ { \ - movepositions(&cursorpos2,&firstpos2,buf2->bufsize,mvchar,mvline,mvpage,diffmode); \ + movepositions(&cursorpos2,&firstpos2,buf2->bufsize,mvchar,mvline,mvpage,diffmode,dispWidth); \ err=((cursorpos1<0 && cursorpos2<0) || (cursorpos1>buf1->bufsize && cursorpos2>buf2->bufsize)); \ } \ if (err) \ @@ -718,7 +729,7 @@ int main(int argc,char** argv) buf1->changes[buf1->changesnum].pos=cursorpos1; buf1->changes[buf1->changesnum].after=buf1->nexthex; buf1->changesnum++; - movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode); + movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode,dispWidth); } buf1->nibble=!buf1->nibble; buf1->changepos=cursorpos1; @@ -729,7 +740,7 @@ int main(int argc,char** argv) buf1->changes[buf1->changesnum].pos=cursorpos1; buf1->changes[buf1->changesnum].after=ch; buf1->changesnum++; - movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode); + movepositions(&cursorpos1,&firstpos1,buf1->bufsize,1,0,0,diffmode,dispWidth); } } if (ch==KEYF10) diff --git a/output.c b/output.c index 327fd61..241bd36 100644 --- a/output.c +++ b/output.c @@ -79,7 +79,7 @@ void drawcenterframe(tOutput* output,tInt8 h,tInt8 w,char* header) { drawframe(output,LINES/2-h/2,COLS/2-w/2,h,w,header); } -void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield) +void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield,int dispWidth) { int i; int j; @@ -92,7 +92,7 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 addrwidth=((hBuf1->bufsize+hBuf1->baseaddr)>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. setcolor(output,COLOR_HEADLINE); wmove(output->win,0,0); @@ -196,7 +196,7 @@ void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 } } } -void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2) +void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2,int dispWidth) { int i; int j; @@ -211,7 +211,7 @@ void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursor addrwidth=((hBuf1->bufsize+hBuf1->baseaddr)>0xffffffffull || (hBuf2->bufsize+hBuf2->baseaddr)>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. setcolor(output,COLOR_HEADLINE); wmove(output->win,0,0); @@ -452,7 +452,7 @@ void printmainmenu(tOutput* output,tBool diffmode) } } -tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode) +tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode,int dispWidth) { tInt32 bytesperline; tInt32 bytesperhalfpage; @@ -464,7 +464,7 @@ tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 addrwidth=(maxbufsize>0xffffffffull)?16:8; - bytesperline=(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. + bytesperline=dispWidth?dispWidth:(COLS-(addrwidth+3+3))*8/(8*3+8+1); // this many bytes can be printed in one line. every 8 bytes there is an extra space in the hex field. bytesperhalfpage=bytesperline*(LINES/2-2); bytesperpage=bytesperline*(LINES-2); diff --git a/output.h b/output.h index cef29e9..52694c4 100644 --- a/output.h +++ b/output.h @@ -11,11 +11,11 @@ void initcolors(); void colorpair(tOutput* output,uicolors uicol,short fg,short bg,int attr); void pairsinit(tOutput* output); void setcolor(tOutput* output,uicolors col); -void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield); -void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2); +void printbuffersingle(tOutput* output,tBuffer* hBuf1,tInt64 cursorpos1,tUInt64 firstpos1,tUInt8 windowfield,int dispWidth); +void printbufferdiff(tOutput* output,tBuffer* hBuf1,tBuffer* hBuf2,tInt64 cursorpos1,tInt64 cursorpos2,int dispWidth); void printmainmenu(tOutput* output,tBool diffmode); void drawframe(tOutput* output,tInt16 y,tInt16 x,tInt8 h,tInt8 w,char* header); void drawcenterframe(tOutput* output,tInt8 h,tInt8 w,char* header); -tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode); +tInt32 movepositions(tInt64* cursorpos,tInt64* firstpos,tInt64 maxbufsize,tInt32 chars,tInt32 lines,tInt32 pages,tBool diffmode,int dispWidth); #endif