Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several bugs related with window updates #31

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern off_t LastLoc;
extern int SIZE_CH;
extern bool USE_EBCDIC;
extern char EBCDIC[256];
extern int ASCII_to_EBCDIC[256];
extern bool color_enabled;

/* macros */
Expand All @@ -119,6 +120,7 @@ extern bool color_enabled;
#define MIN_COLS 70 /* screen has to be 70< cols */
#define MIN_LINES 7 /* 8 - 1 */ /* the slk crap minuses 1 line*/
#define KEY_TAB 9 /* value for the tab key */
#define NODEF 0 /* value for not defined characters in ASCII_to_EBCDIC */

#define AlphabetSize (UCHAR_MAX +1) /* for portability */

Expand Down
70 changes: 43 additions & 27 deletions src/acceptch.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ int wacceptch(WINS *win, off_t len)

default: /* if other key... */
/* if key we want... */
if (isprint(key) && ((editHex && isxdigit(key)) || !editHex))
if ( (editHex && isxdigit(key)) ||
( (!editHex && isprint(key)) &&
( (USE_EBCDIC) ? (ASCII_to_EBCDIC[key]!=NODEF) : TRUE )
)
)
{
if ((cl=cursorLoc(currentLine, col, editHex,BASE))< len)
{
Expand Down Expand Up @@ -223,7 +227,8 @@ int wacceptch(WINS *win, off_t len)
val = (val - ((val + 16) % 16) + key);
}
else /* else... */
val = key; /* val is key pressed */
/* val is key pressed */
val = (USE_EBCDIC) ? ASCII_to_EBCDIC[key] : key;

if (editHex) /* update ascii win */
{
Expand Down Expand Up @@ -622,10 +627,17 @@ int wacceptch(WINS *win, off_t len)
/*switch the underline*/
getyx(Winds, row, col); /* current location */
wattrset((editHex) ? win->ascii : win->hex, A_NORMAL);
mvwprintw((editHex) ? win->ascii : win->hex, row,
(editHex) ? col/3 : col*3,
(editHex) ? "%c": "%02X",
(editHex) ? ((isprint(curVal))?curVal : '.'):curVal);

byte_color_on((row * BASE) + col, curVal);

if (editHex)
mvwprintw(win->ascii, row, col/3, "%c",
(USE_EBCDIC) ? EBCDIC[curVal] : (isprint(curVal)) ? curVal : '.');
else
mvwprintw(win->hex, row, col*3, "%02X", curVal);

byte_color_off((row * BASE) + col, curVal);

wnoutrefresh((editHex) ? win->ascii : win->hex);
if (editHex) /* already in hex win */
{
Expand Down Expand Up @@ -705,34 +717,24 @@ int wacceptch(WINS *win, off_t len)
wattron(win->hex, A_BOLD);
wattron(win->ascii, A_BOLD);
}
byte_color_on((row * BASE) + col, val);

if (editHex)
{
wmove(win->ascii, row, (col/3));
wprintw(win->ascii, "%c", (USE_EBCDIC) ? EBCDIC[val] :
(isprint(val) ? val : 46));
wmove(win->hex, row, col);
wrefresh(win->ascii);

wprintw(win->hex, "%02X", val);
wmove(win->hex, row, col);
wrefresh(win->hex);
}
else
{
wmove(win->hex, row, (col*3));
wprintw(win->hex, "%02X", val);
wmove(win->ascii, row, col);
wrefresh(win->hex);

wprintw(win->ascii, "%c", (USE_EBCDIC) ? EBCDIC[val] :
(isprint(val) ? val : 46));
wmove(win->ascii, row, col);
wrefresh(win->ascii);
}
byte_color_off((row * BASE) + col, val);
wattrset(win->hex, A_NORMAL);
wattrset(win->ascii, A_NORMAL);


}
break;

Expand Down Expand Up @@ -767,25 +769,39 @@ int wacceptch(WINS *win, off_t len)
wattron((editHex) ? win->ascii : win->hex,
(inHexList(cursorLoc(lastLine, lastCol, editHex, BASE))) ?
A_BOLD : A_NORMAL);
mvwprintw((editHex) ? win->ascii : win->hex, lastRow,
(editHex) ? lastCol/3 : lastCol*3,
(editHex) ? "%c" : "%02X",
(editHex) ? (isprint(curVal)) ? curVal : '.': curVal);

byte_color_on((lastRow * BASE) + lastCol, curVal);

if (editHex)
mvwprintw(win->ascii, lastRow, lastCol/3, "%c",
(USE_EBCDIC) ? EBCDIC[curVal] : (isprint(curVal)) ? curVal : '.');
else
mvwprintw(win->hex, lastRow, lastCol*3, "%02X", curVal);

byte_color_off((lastRow * BASE) + lastCol, curVal);

wmove(Winds, row, col);
wattrset((editHex) ? win->ascii : win->hex, A_NORMAL);
wnoutrefresh((editHex) ? win->ascii : win->hex);
}

/* highlight new char */
wattron((editHex) ? win->ascii : win->hex, A_UNDERLINE);
if (inHexList(cursorLoc(currentLine, col, editHex, BASE)))
wattron((editHex) ? win->ascii : win->hex, A_BOLD);

curVal = getLocVal(cursorLoc(currentLine, col, editHex, BASE));

mvwprintw((editHex) ? win->ascii : win->hex, row,
(editHex) ? col/3 : col*3,
(editHex) ? "%c" : "%02X",
(editHex) ? (isprint(curVal)) ? curVal : '.' : curVal);
byte_color_on((row * BASE) + col, curVal);

if (editHex)
mvwprintw(win->ascii, row, col/3, "%c",
(USE_EBCDIC) ? EBCDIC[curVal] : (isprint(curVal)) ? curVal : '.');
else
mvwprintw(win->hex, row, col*3, "%02X", curVal);

byte_color_off((row * BASE) + col, curVal);

wattrset((editHex) ? win->ascii : win->hex, A_NORMAL);
wnoutrefresh((editHex) ? win->ascii : win->hex);
}
Expand Down
19 changes: 19 additions & 0 deletions src/hexcurse.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ int hex_win_width,
'.','R','S','T','U','V','W','X','Y','Z','.','.','.','.' ,'.','.', /* E */
'0','1','2','3','4','5','6','7','8','9','.','.','.','.' ,'.','.'};/* F */

int ASCII_to_EBCDIC[] =
{
NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF,
NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF,
NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF, NODEF,

/* 32 */ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, 0x4d, 0x5d,
/* 42 */ 0x5c, 0x4e, 0x6b, 0x60, NODEF, 0x61, 0xf0, 0xf1, 0xf2, 0xf3,
/* 52 */ 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e,
/* 62 */ 0x6e, 0x6f, 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
/* 72 */ 0xc8, 0xc9, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
/* 82 */ 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, NODEF,
/* 92 */ NODEF, NODEF, NODEF, 0x6d, 0xb9, 0x81, 0x82, 0x83, 0x84, 0x85,
/* 102 */ 0x86, 0x87, 0x88, 0x89, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
/* 112 */ 0x98, 0x99, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
/* 122 */ 0xa9, NODEF, 0x4f, NODEF, NODEF /* 126 */
};


int main(int argc, char *argv[]) /* main program */
{

Expand Down