Skip to content

Commit

Permalink
extend size of address when file is larger than 4GB (#72)
Browse files Browse the repository at this point in the history
* extend size of address when file is larger than 4GB

* changes requested in review (#72)
  • Loading branch information
farindk authored Jul 31, 2024
1 parent 3f0d6ad commit bc5c65b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
14 changes: 11 additions & 3 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int computeLineSize(void) { return computeCursorXPos(lineLength - 1, 0) + 1; }
int computeCursorXCurrentPos(void) { return computeCursorXPos(cursor, hexOrAscii); }
int computeCursorXPos(int cursor, int hexOrAscii)
{
int r = 11;
int r = nAddrDigits + 3;
int x = cursor % lineLength;
int h = (hexOrAscii ? x : lineLength - 1);

Expand Down Expand Up @@ -162,6 +162,13 @@ void exitCurses(void)
endwin();
}

static void printaddr(uint64_t addr)
{
char templ[7]; // maximum string is "%016lX", which is 6 chars + 1 null byte
sprintf(templ,"%%0%dlX", nAddrDigits);
PRINTW((templ, addr));
}

void display(void)
{
long long fsize;
Expand All @@ -176,7 +183,7 @@ void display(void)
move(i / lineLength, 0);
for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */
move(i / lineLength, 0);
PRINTW(("%08lX", (int) (base + i)));
printaddr(base+i);
}

attrset(NORMAL);
Expand All @@ -201,7 +208,8 @@ void displayLine(int offset, int max)
#ifdef HAVE_COLORS
mark_color = COLOR_PAIR(4) | A_BOLD;
#endif
PRINTW(("%08lX ", (int) (base + offset)));
printaddr(base + offset);
PRINTW((" "));
for (i = offset; i < offset + lineLength; i++) {
if (i > offset) MAXATTRPRINTW(bufferAttr[i] & MARKED, (((i - offset) % blocSize) ? " " : " "));
if (i < max) {
Expand Down
27 changes: 27 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/
#include "hexedit.h"


// Compute number of hex-digits needed to display an address.
// We only increase this by full bytes (2 digits).
// Because the input is uint64_t, the maximum result is 16 (64bit = 16*4bit).
int compute_nDigits(uint64_t maxAddr)
{
int digits = 0;
while (maxAddr) {
digits+=2;
maxAddr >>= 8;
}

if (digits==0) {
return 2;
}

return digits;
}


void openFile(void)
{
struct stat st;
Expand Down Expand Up @@ -53,6 +73,13 @@ void openFile(void)
fileSize = 0;
}
biggestLoc = fileSize;

nAddrDigits = compute_nDigits(biggestLoc);

// use at least 8 digits (4 byte addresses)
if (nAddrDigits < 8) {
nAddrDigits = 8;
}
}

void readFile(void)
Expand Down
1 change: 1 addition & 0 deletions hexedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ INT base, oldbase;
int normalSpaces, cursor, cursorOffset, hexOrAscii;
int cursor, blocSize, lineLength, colsUsed, page;
int fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
int nAddrDigits;
int sizeCopyBuffer, *bufferAttr;
char *progName, *fileName, *baseName;
unsigned char *buffer, *copyBuffer;
Expand Down
1 change: 1 addition & 0 deletions hexedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ extern INT base, oldbase;
extern int normalSpaces, cursor, cursorOffset, hexOrAscii;
extern int cursor, blocSize, lineLength, colsUsed, page;
extern int isReadOnly, fd, nbBytes, oldcursor, oldattr, oldcursorOffset;
extern int nAddrDigits;
extern int sizeCopyBuffer, *bufferAttr;
extern char *progName, *fileName, *baseName;
extern unsigned char *buffer, *copyBuffer;
Expand Down

0 comments on commit bc5c65b

Please sign in to comment.