Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions

View File

@@ -1,6 +1,6 @@
/* NetHack 3.6 nh340key.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 nh340key.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */
/* NetHack 3.6 nh340key.c $Date: 2009/05/06 10:53:29 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)nh340key.c 3.5 $NHDT-Date$ */
/* SCCS Id: @(#)nh340key.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */
/* SCCS Id: @(#)nh340key.c 3.5 $Date: 2009/05/06 10:53:29 $ */
/* Copyright (c) NetHack PC Development Team 2003 */
/* NetHack may be freely redistributed. See license for details. */
@@ -25,22 +25,23 @@ extern INPUT_RECORD ir;
char dllname[512];
char *shortdllname;
int FDECL(__declspec(dllexport) __stdcall
ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir,
boolean *valid, BOOLEAN_P numberpad, int portdebug));
int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke,
(HANDLE hConIn, INPUT_RECORD *ir, boolean *valid,
BOOLEAN_P numberpad, int portdebug));
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
int WINAPI
DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void)strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
return TRUE;
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void) strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
return TRUE;
}
/*
@@ -48,11 +49,11 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
* (Adopted from the MSDOS port)
*/
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
/*
* Keypad keys are translated to the normal values below.
@@ -61,250 +62,258 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
*/
static const struct pad {
uchar normal, shift, cntrl;
} keypad[PADKEYS] = {
{'y', 'Y', C('y')}, /* 7 */
{'k', 'K', C('k')}, /* 8 */
{'u', 'U', C('u')}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'h', 'H', C('h')}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'l', 'L', C('l')}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'b', 'B', C('b')}, /* 1 */
{'j', 'J', C('j')}, /* 2 */
{'n', 'N', C('n')}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
}, numpad[PADKEYS] = {
{'7', M('7'), '7'}, /* 7 */
{'8', M('8'), '8'}, /* 8 */
{'9', M('9'), '9'}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'4', M('4'), '4'}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'6', M('6'), '6'}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'1', M('1'), '1'}, /* 1 */
{'2', M('2'), '2'}, /* 2 */
{'3', M('3'), '3'}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
};
uchar normal, shift, cntrl;
} keypad[PADKEYS] =
{
{ 'y', 'Y', C('y') }, /* 7 */
{ 'k', 'K', C('k') }, /* 8 */
{ 'u', 'U', C('u') }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ 'h', 'H', C('h') }, /* 4 */
{ 'g', 'G', 'g' }, /* 5 */
{ 'l', 'L', C('l') }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ 'b', 'B', C('b') }, /* 1 */
{ 'j', 'J', C('j') }, /* 2 */
{ 'n', 'N', C('n') }, /* 3 */
{ 'i', 'I', C('i') }, /* Ins */
{ '.', ':', ':' } /* Del */
},
numpad[PADKEYS] = {
{ '7', M('7'), '7' }, /* 7 */
{ '8', M('8'), '8' }, /* 8 */
{ '9', M('9'), '9' }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ '4', M('4'), '4' }, /* 4 */
{ 'g', 'G', 'g' }, /* 5 */
{ '6', M('6'), '6' }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ '1', M('1'), '1' }, /* 1 */
{ '2', M('2'), '2' }, /* 2 */
{ '3', M('3'), '3' }, /* 3 */
{ 'i', 'I', C('i') }, /* Ins */
{ '.', ':', ':' } /* Del */
};
#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
int __declspec(dllexport) __stdcall
ProcessKeystroke(hConIn, ir, valid, numberpad, portdebug)
int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid,
numberpad, portdebug)
HANDLE hConIn;
INPUT_RECORD *ir;
boolean *valid;
boolean numberpad;
int portdebug;
{
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
}
else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
}
else {
ch = kpad[scan - KEYPADLO].normal;
}
if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
} else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
} else {
ch = kpad[scan - KEYPADLO].normal;
}
else if (altseq > 0) { /* ALT sequence */
if (vk == 0xBF) ch = M('?');
else ch = M(tolower(keycode));
}
if (ch == '\r') ch = '\n';
} else if (altseq > 0) { /* ALT sequence */
if (vk == 0xBF)
ch = M('?');
else
ch = M(tolower(keycode));
}
if (ch == '\r')
ch = '\n';
#ifdef PORT_DEBUG
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf,
"PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, sh=0x%X (ESC to end)",
shortdllname, ch, scan, vk, shiftstate);
fprintf(stdout, "\n%s", buf);
}
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf,
"PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, sh=0x%X (ESC to end)",
shortdllname, ch, scan, vk, shiftstate);
fprintf(stdout, "\n%s", buf);
}
#endif
return ch;
return ch;
}
int __declspec(dllexport) __stdcall
NHkbhit(hConIn, ir)
int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir)
HANDLE hConIn;
INPUT_RECORD *ir;
{
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done)
{
count = 0;
PeekConsoleInput(hConIn,ir,1,&count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn,ir,1,&count);
}
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done) {
count = 0;
PeekConsoleInput(hConIn, ir, 1, &count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn, ir, 1, &count);
}
}
else if ((ir->EventType == MOUSE_EVENT &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) {
done = 1;
retval = 1;
}
} else if ((ir->EventType == MOUSE_EVENT
&& (ir->Event.MouseEvent.dwButtonState
& MOUSEMASK))) {
done = 1;
retval = 1;
}
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn,ir,1,&count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn, ir, 1, &count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
}
int __declspec(dllexport) __stdcall
CheckInput(hConIn, ir, count, numpad, mode, mod, cc)
int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad,
mode, mod, cc)
HANDLE hConIn;
INPUT_RECORD *ir;
DWORD *count;
DWORD *count;
boolean numpad;
int mode;
int *mod;
coord *cc;
{
#if defined(SAFERHANGUP)
DWORD dwWait;
DWORD dwWait;
#endif
int ch;
boolean valid = 0, done = 0;
while (!done) {
int ch;
boolean valid = 0, done = 0;
while (!done) {
#if defined(SAFERHANGUP)
dwWait = WaitForSingleObjectEx(
hConIn, // event object to wait for
INFINITE, // waits indefinitely
TRUE); // alertable wait enabled
if (dwWait == WAIT_FAILED) return '\033';
dwWait = WaitForSingleObjectEx(hConIn, // event object to wait for
INFINITE, // waits indefinitely
TRUE); // alertable wait enabled
if (dwWait == WAIT_FAILED)
return '\033';
#endif
ReadConsoleInput(hConIn,ir,1,count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
done = valid;
}
} else {
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
if (valid) return ch;
} else if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0) &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) {
cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1;
ReadConsoleInput(hConIn, ir, 1, count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
done = valid;
}
} else {
if (count > 0) {
if (ir->EventType == KEY_EVENT
&& ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
if (valid)
return ch;
} else if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0)
&& (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) {
cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1;
if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState
& RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON)
*mod = CLICK_3;
#endif
return 0;
}
}
} else
done = 1;
}
}
return mode ? 0 : ch;
#endif
return 0;
}
}
} else
done = 1;
}
}
return mode ? 0 : ch;
}
int __declspec(dllexport) __stdcall
SourceWhere(buf)
int __declspec(dllexport) __stdcall SourceWhere(buf)
char **buf;
{
if (!buf) return 0;
*buf = where_to_get_source;
return 1;
if (!buf)
return 0;
*buf = where_to_get_source;
return 1;
}
int __declspec(dllexport) __stdcall
SourceAuthor(buf)
int __declspec(dllexport) __stdcall SourceAuthor(buf)
char **buf;
{
if (!buf) return 0;
*buf = author;
return 1;
if (!buf)
return 0;
*buf = author;
return 1;
}
int __declspec(dllexport) __stdcall
KeyHandlerName(buf, full)
int __declspec(dllexport) __stdcall KeyHandlerName(buf, full)
char **buf;
int full;
{
if (!buf) return 0;
if (full) *buf = dllname;
else *buf = shortdllname;
return 1;
if (!buf)
return 0;
if (full)
*buf = dllname;
else
*buf = shortdllname;
return 1;
}

View File

@@ -1,6 +1,6 @@
/* NetHack 3.6 nhdefkey.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 nhdefkey.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.13 $ */
/* NetHack 3.6 nhdefkey.c $Date: 2009/05/06 10:53:29 $ $Revision: 1.10 $ */
/* SCCS Id: @(#)nhdefkey.c 3.5 $NHDT-Date$ */
/* SCCS Id: @(#)nhdefkey.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */
/* SCCS Id: @(#)nhdefkey.c 3.5 $Date: 2009/05/06 10:53:29 $ */
/* Copyright (c) NetHack PC Development Team 2003 */
/* NetHack may be freely redistributed. See license for details. */
@@ -33,22 +33,23 @@ extern struct sinfo program_state;
char dllname[512];
char *shortdllname;
int FDECL(__declspec(dllexport) __stdcall
ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir,
boolean *valid, BOOLEAN_P numberpad, int portdebug));
int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke,
(HANDLE hConIn, INPUT_RECORD *ir, boolean *valid,
BOOLEAN_P numberpad, int portdebug));
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
int WINAPI
DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void)strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
return TRUE;
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void) strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
return TRUE;
}
/*
@@ -56,11 +57,11 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
* (Adopted from the MSDOS port)
*/
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
/*
* Keypad keys are translated to the normal values below.
@@ -69,277 +70,283 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
*/
static const struct pad {
uchar normal, shift, cntrl;
} keypad[PADKEYS] = {
{'y', 'Y', C('y')}, /* 7 */
{'k', 'K', C('k')}, /* 8 */
{'u', 'U', C('u')}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'h', 'H', C('h')}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'l', 'L', C('l')}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'b', 'B', C('b')}, /* 1 */
{'j', 'J', C('j')}, /* 2 */
{'n', 'N', C('n')}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
}, numpad[PADKEYS] = {
{'7', M('7'), '7'}, /* 7 */
{'8', M('8'), '8'}, /* 8 */
{'9', M('9'), '9'}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'4', M('4'), '4'}, /* 4 */
{'5', M('5'), '5'}, /* 5 */
{'6', M('6'), '6'}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'1', M('1'), '1'}, /* 1 */
{'2', M('2'), '2'}, /* 2 */
{'3', M('3'), '3'}, /* 3 */
{'0', M('0'), '0'}, /* Ins */
{'.', ':', ':'} /* Del */
};
uchar normal, shift, cntrl;
} keypad[PADKEYS] =
{
{ 'y', 'Y', C('y') }, /* 7 */
{ 'k', 'K', C('k') }, /* 8 */
{ 'u', 'U', C('u') }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ 'h', 'H', C('h') }, /* 4 */
{ 'g', 'G', 'g' }, /* 5 */
{ 'l', 'L', C('l') }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ 'b', 'B', C('b') }, /* 1 */
{ 'j', 'J', C('j') }, /* 2 */
{ 'n', 'N', C('n') }, /* 3 */
{ 'i', 'I', C('i') }, /* Ins */
{ '.', ':', ':' } /* Del */
},
numpad[PADKEYS] = {
{ '7', M('7'), '7' }, /* 7 */
{ '8', M('8'), '8' }, /* 8 */
{ '9', M('9'), '9' }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ '4', M('4'), '4' }, /* 4 */
{ '5', M('5'), '5' }, /* 5 */
{ '6', M('6'), '6' }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ '1', M('1'), '1' }, /* 1 */
{ '2', M('2'), '2' }, /* 2 */
{ '3', M('3'), '3' }, /* 3 */
{ '0', M('0'), '0' }, /* Ins */
{ '.', ':', ':' } /* Del */
};
#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
static BYTE KeyState[256];
int __declspec(dllexport) __stdcall
ProcessKeystroke(hConIn,ir, valid, numberpad, portdebug)
int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid,
numberpad, portdebug)
HANDLE hConIn;
INPUT_RECORD *ir;
boolean *valid;
boolean numberpad;
int portdebug;
{
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
KeyState[VK_SHIFT] = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0;
KeyState[VK_CONTROL] = (shiftstate & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)) ?
0x81 : 0;
KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0;
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
KeyState[VK_SHIFT] = (shiftstate & SHIFT_PRESSED) ? 0x81 : 0;
KeyState[VK_CONTROL] =
(shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) ? 0x81 : 0;
KeyState[VK_CAPITAL] = (shiftstate & CAPSLOCK_ON) ? 0x81 : 0;
if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
}
else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
}
else {
ch = kpad[scan - KEYPADLO].normal;
}
if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
} else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
} else {
ch = kpad[scan - KEYPADLO].normal;
}
else if (altseq > 0) { /* ALT sequence */
if (vk == 0xBF) ch = M('?');
else ch = M(tolower(keycode));
}
/* Attempt to work better with international keyboards. */
else {
WORD chr[2];
k = ToAscii(vk, scan, KeyState, chr, 0);
if (k <= 2)
switch(k) {
case 2: /* two characters */
ch = (unsigned char)chr[1];
*valid = TRUE;
break;
case 1: /* one character */
ch = (unsigned char)chr[0];
*valid = TRUE;
break;
case 0: /* no translation */
default: /* negative */
*valid = FALSE;
}
}
if (ch == '\r') ch = '\n';
} else if (altseq > 0) { /* ALT sequence */
if (vk == 0xBF)
ch = M('?');
else
ch = M(tolower(keycode));
}
/* Attempt to work better with international keyboards. */
else {
WORD chr[2];
k = ToAscii(vk, scan, KeyState, chr, 0);
if (k <= 2)
switch (k) {
case 2: /* two characters */
ch = (unsigned char) chr[1];
*valid = TRUE;
break;
case 1: /* one character */
ch = (unsigned char) chr[0];
*valid = TRUE;
break;
case 0: /* no translation */
default: /* negative */
*valid = FALSE;
}
}
if (ch == '\r')
ch = '\n';
#ifdef PORT_DEBUG
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf,
"PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, ta=%d (ESC to end)",
shortdllname, ch, scan, vk, pre_ch, shiftstate, k);
fprintf(stdout, "\n%s", buf);
}
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf, "PORTDEBUG (%s): ch=%u, sc=%u, vk=%d, pre=%d, sh=0x%X, "
"ta=%d (ESC to end)",
shortdllname, ch, scan, vk, pre_ch, shiftstate, k);
fprintf(stdout, "\n%s", buf);
}
#endif
return ch;
return ch;
}
int __declspec(dllexport) __stdcall
NHkbhit(hConIn, ir)
int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir)
HANDLE hConIn;
INPUT_RECORD *ir;
{
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done)
{
count = 0;
PeekConsoleInput(hConIn,ir,1,&count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (shiftstate & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn,ir,1,&count);
}
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done) {
count = 0;
PeekConsoleInput(hConIn, ir, 1, &count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (shiftstate & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn, ir, 1, &count);
}
}
else if ((ir->EventType == MOUSE_EVENT &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) {
done = 1;
retval = 1;
}
} else if ((ir->EventType == MOUSE_EVENT
&& (ir->Event.MouseEvent.dwButtonState
& MOUSEMASK))) {
done = 1;
retval = 1;
}
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn,ir,1,&count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn, ir, 1, &count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
}
int __declspec(dllexport) __stdcall
CheckInput(hConIn, ir, count, numpad, mode, mod, cc)
int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad,
mode, mod, cc)
HANDLE hConIn;
INPUT_RECORD *ir;
DWORD *count;
DWORD *count;
boolean numpad;
int mode;
int *mod;
coord *cc;
{
#if defined(SAFERHANGUP)
DWORD dwWait;
DWORD dwWait;
#endif
int ch;
boolean valid = 0, done = 0;
while (!done) {
int ch;
boolean valid = 0, done = 0;
while (!done) {
#if defined(SAFERHANGUP)
dwWait = WaitForSingleObjectEx(
hConIn, // event object to wait for
INFINITE, // waits indefinitely
TRUE); // alertable wait enabled
if (dwWait == WAIT_FAILED) return '\033';
dwWait = WaitForSingleObjectEx(hConIn, // event object to wait for
INFINITE, // waits indefinitely
TRUE); // alertable wait enabled
if (dwWait == WAIT_FAILED)
return '\033';
#endif
ReadConsoleInput(hConIn,ir,1,count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
done = valid;
}
} else {
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
if (valid) return ch;
} else if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0) &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) {
cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1;
ReadConsoleInput(hConIn, ir, 1, count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
done = valid;
}
} else {
if (count > 0) {
if (ir->EventType == KEY_EVENT
&& ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad, 0);
if (valid)
return ch;
} else if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0)
&& (ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) {
cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1;
if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState
& RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON)
*mod = CLICK_3;
#endif
return 0;
}
}
} else
done = 1;
}
}
return mode ? 0 : ch;
#endif
return 0;
}
}
} else
done = 1;
}
}
return mode ? 0 : ch;
}
int __declspec(dllexport) __stdcall
SourceWhere(buf)
int __declspec(dllexport) __stdcall SourceWhere(buf)
char **buf;
{
if (!buf) return 0;
*buf = where_to_get_source;
return 1;
if (!buf)
return 0;
*buf = where_to_get_source;
return 1;
}
int __declspec(dllexport) __stdcall
SourceAuthor(buf)
int __declspec(dllexport) __stdcall SourceAuthor(buf)
char **buf;
{
if (!buf) return 0;
*buf = author;
return 1;
if (!buf)
return 0;
*buf = author;
return 1;
}
int __declspec(dllexport) __stdcall
KeyHandlerName(buf, full)
int __declspec(dllexport) __stdcall KeyHandlerName(buf, full)
char **buf;
int full;
{
if (!buf) return 0;
if (full) *buf = dllname;
else *buf = shortdllname;
return 1;
if (!buf)
return 0;
if (full)
*buf = dllname;
else
*buf = shortdllname;
return 1;
}

View File

@@ -1,6 +1,6 @@
/* NetHack 3.6 nhraykey.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 nhraykey.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */
/* NetHack 3.6 nhraykey.c $Date: 2009/05/06 10:53:31 $ $Revision: 1.8 $ */
/* SCCS Id: @(#)nhraykey.c 3.5 $NHDT-Date$ */
/* SCCS Id: @(#)nhraykey.c 3.5 $NHDT-Date: 1431192783 2015/05/09 17:33:03 $ */
/* SCCS Id: @(#)nhraykey.c 3.5 $Date: 2009/05/06 10:53:31 $ */
/* Copyright (c) NetHack PC Development Team 2003 */
/* NetHack may be freely redistributed. See license for details. */
@@ -8,156 +8,156 @@
/*
* Keystroke handling contributed by Ray Chason.
* The following text was written by Ray Chason.
*
*
* The problem
* ===========
*
*
* The console-mode Nethack wants both keyboard and mouse input. The
* problem is that the Windows API provides no easy way to get mouse input
* and also keyboard input properly translated according to the user's
* chosen keyboard layout.
*
*
* The ReadConsoleInput function returns a stream of keyboard and mouse
* events. Nethack is interested in those events that represent a key
* pressed, or a click on a mouse button. The keyboard events from
* ReadConsoleInput are not translated according to the keyboard layout,
* and do not take into account the shift, control, or alt keys.
*
*
* The PeekConsoleInput function works similarly to ReadConsoleInput,
* except that it does not remove an event from the queue and it returns
* instead of blocking when the queue is empty.
*
*
* A program can also use ReadConsole to get a properly translated stream
* of characters. Unfortunately, ReadConsole does not return mouse events,
* does not distinguish the keypad from the main keyboard, does not return
* keys shifted with Alt, and does not even return the ESC key when
* pressed.
*
* pressed.
*
* We want both the functionality of ReadConsole and the functionality of
* ReadConsoleInput. But Microsoft didn't seem to think of that.
*
*
*
*
* The solution, in the original code
* ==================================
*
*
* The original 3.4.1 distribution tries to get proper keyboard translation
* by passing keyboard events to the ToAscii function. This works, to some
* extent -- it takes the shift key into account, and it processes dead
* keys properly. But it doesn't take non-US keyboards into account. It
* appears that ToAscii is meant for windowed applications, and does not
* have enough information to do its job properly in a console application.
*
*
*
*
* The Finnish keyboard patch
* ==========================
*
*
* This patch adds the "subkeyvalue" option to the defaults.nh file. The
* user can then add OPTIONS=sukeyvalue:171/92, for instance, to replace
* the 171 character with 92, which is \. This works, once properly
* configured, but places too much burden on the user. It also bars the
* use of the substituted characters in naming objects or monsters.
*
*
*
*
* The solution presented here
* ===========================
*
*
* The best way I could find to combine the functionality of ReadConsole
* with that of ReadConsoleInput is simple in concept. First, call
* PeekConsoleInput to get the first event. If it represents a key press,
* call ReadConsole to retrieve the key. Otherwise, pop it off the queue
* with ReadConsoleInput and, if it's a mouse click, return it as such.
*
*
* But the Devil, as they say, is in the details. The problem is in
* recognizing an event that ReadConsole will return as a key. We don't
* want to call ReadConsole unless we know that it will immediately return:
* if it blocks, the mouse and the Alt sequences will cease to function
* until it returns.
*
*
* Separating process_keystroke into two functions, one for commands and a
* new one, process_keystroke2, for answering prompts, makes the job a lot
* easier. process_keystroke2 doesn't have to worry about mouse events or
* Alt sequences, and so the consequences are minor if ReadConsole blocks.
* Alt sequences, and so the consequences are minor if ReadConsole blocks.
* process_keystroke, OTOH, never needs to return a non-ASCII character
* that was read from ReadConsole; it returns bytes with the high bit set
* only in response to an Alt sequence.
*
*
* So in process_keystroke, before calling ReadConsole, a bogus key event
* is pushed on the queue. This event causes ReadConsole to return, even
* if there was no other character available. Because the bogus key has
* the eighth bit set, it is filtered out. This is not done in
* process_keystroke2, because that would render dead keys unusable.
*
*
* A separate process_keystroke2 can also process the numeric keypad in a
* way that makes sense for prompts: just return the corresponding symbol,
* and pay no mind to number_pad or the num lock key.
*
*
* The recognition of Alt sequences is modified, to support the use of
* characters generated with the AltGr key. A keystroke is an Alt sequence
* if an Alt key is seen that can't be an AltGr (since an AltGr sequence
* could be a character, and in some layouts it could even be an ASCII
* character). This recognition is different on NT-based and 95-based
* Windows:
*
*
* * On NT-based Windows, AltGr signals as right Alt and left Ctrl
* together. So an Alt sequence is recognized if either Alt key is
* pressed and if right Alt and left Ctrl are not both present. This
* is true even if the keyboard in use does not have an AltGr key, and
* uses right Alt for AltGr.
*
*
* * On 95-based Windows, with a keyboard that lacks the AltGr key, the
* right Alt key is used instead. But it still signals as right Alt,
* without left Ctrl. There is no way for the application to know
* whether right Alt is Alt or AltGr, and so it is always assumed
* to be AltGr. This means that Alt sequences must be formed with
* left Alt.
*
*
* So the patch processes keystrokes as follows:
*
*
* * If the scan and virtual key codes are both 0, it's the bogus key,
* and we ignore it.
*
*
* * Keys on the numeric keypad are processed for commands as in the
* unpatched Nethack, and for prompts by returning the ASCII
* character, even if the num lock is off.
*
*
* * Alt sequences are processed for commands as in the unpatched
* Nethack, and ignored for prompts.
*
*
* * Control codes are returned as received, because ReadConsole will
* not return the ESC key.
*
*
* * Other key-down events are passed to ReadConsole. The use of
* ReadConsole is different for commands than for prompts:
*
*
* o For commands, the bogus key is pushed onto the queue before
* ReadConsole is called. On return, non-ASCII characters are
* filtered, so they are not mistaken for Alt sequences; this also
* filters the bogus key.
*
*
* o For prompts, the bogus key is not used, because that would
* interfere with dead keys. Eight bit characters may be returned,
* and are coded in the configured code page.
*
*
*
*
* Possible improvements
* =====================
*
*
* Some possible improvements remain:
*
*
* * Integrate the existing Finnish keyboard patch, for use with non-
* QWERTY layouts such as the German QWERTZ keyboard or Dvorak.
*
*
* * Fix the keyboard glitches in the graphical version. Namely, dead
* keys don't work, and input comes in as ISO-8859-1 but is displayed
* as code page 437 if IBMgraphics is set on startup.
*
*
* * Transform incoming text to ISO-8859-1, for full compatibility with
* the graphical version.
*
*
* * After pushing the bogus key and calling ReadConsole, check to see
* if we got the bogus key; if so, and an Alt is pressed, process the
* event as an Alt sequence.
*
*
*/
static char where_to_get_source[] = "http://www.nethack.org/";
@@ -172,33 +172,34 @@ extern INPUT_RECORD ir;
char dllname[512];
char *shortdllname;
int FDECL(__declspec(dllexport) __stdcall
ProcessKeystroke, (HANDLE hConIn, INPUT_RECORD *ir,
boolean *valid, BOOLEAN_P numberpad, int portdebug));
int FDECL(__declspec(dllexport) __stdcall ProcessKeystroke,
(HANDLE hConIn, INPUT_RECORD *ir, boolean *valid,
BOOLEAN_P numberpad, int portdebug));
static INPUT_RECORD bogus_key;
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
int WINAPI
DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void)strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
/* A bogus key that will be filtered when received, to keep ReadConsole
* from blocking */
bogus_key.EventType = KEY_EVENT;
bogus_key.Event.KeyEvent.bKeyDown = 1;
bogus_key.Event.KeyEvent.wRepeatCount = 1;
bogus_key.Event.KeyEvent.wVirtualKeyCode = 0;
bogus_key.Event.KeyEvent.wVirtualScanCode = 0;
bogus_key.Event.KeyEvent.uChar.AsciiChar = (uchar)0x80;
bogus_key.Event.KeyEvent.dwControlKeyState = 0;
return TRUE;
char dlltmpname[512];
char *tmp = dlltmpname, *tmp2;
*(tmp + GetModuleFileName(hInstance, tmp, 511)) = '\0';
(void) strcpy(dllname, tmp);
tmp2 = strrchr(dllname, '\\');
if (tmp2) {
tmp2++;
shortdllname = tmp2;
}
/* A bogus key that will be filtered when received, to keep ReadConsole
* from blocking */
bogus_key.EventType = KEY_EVENT;
bogus_key.Event.KeyEvent.bKeyDown = 1;
bogus_key.Event.KeyEvent.wRepeatCount = 1;
bogus_key.Event.KeyEvent.wVirtualKeyCode = 0;
bogus_key.Event.KeyEvent.wVirtualScanCode = 0;
bogus_key.Event.KeyEvent.uChar.AsciiChar = (uchar) 0x80;
bogus_key.Event.KeyEvent.dwControlKeyState = 0;
return TRUE;
}
/*
@@ -206,12 +207,13 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
* (Adopted from the MSDOS port)
*/
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define KEYPADLO 0x47
#define KEYPADHI 0x53
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
#define isnumkeypad(x) (KEYPADLO <= (x) && (x) <= 0x51 && (x) != 0x4A && (x) != 0x4E)
#define PADKEYS (KEYPADHI - KEYPADLO + 1)
#define iskeypad(x) (KEYPADLO <= (x) && (x) <= KEYPADHI)
#define isnumkeypad(x) \
(KEYPADLO <= (x) && (x) <= 0x51 && (x) != 0x4A && (x) != 0x4E)
/*
* Keypad keys are translated to the normal values below.
@@ -220,42 +222,45 @@ int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
*/
static const struct pad {
uchar normal, shift, cntrl;
} keypad[PADKEYS] = {
{'y', 'Y', C('y')}, /* 7 */
{'k', 'K', C('k')}, /* 8 */
{'u', 'U', C('u')}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'h', 'H', C('h')}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'l', 'L', C('l')}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'b', 'B', C('b')}, /* 1 */
{'j', 'J', C('j')}, /* 2 */
{'n', 'N', C('n')}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
}, numpad[PADKEYS] = {
{'7', M('7'), '7'}, /* 7 */
{'8', M('8'), '8'}, /* 8 */
{'9', M('9'), '9'}, /* 9 */
{'m', C('p'), C('p')}, /* - */
{'4', M('4'), '4'}, /* 4 */
{'g', 'G', 'g'}, /* 5 */
{'6', M('6'), '6'}, /* 6 */
{'+', 'P', C('p')}, /* + */
{'1', M('1'), '1'}, /* 1 */
{'2', M('2'), '2'}, /* 2 */
{'3', M('3'), '3'}, /* 3 */
{'i', 'I', C('i')}, /* Ins */
{'.', ':', ':'} /* Del */
};
uchar normal, shift, cntrl;
} keypad[PADKEYS] =
{
{ 'y', 'Y', C('y') }, /* 7 */
{ 'k', 'K', C('k') }, /* 8 */
{ 'u', 'U', C('u') }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ 'h', 'H', C('h') }, /* 4 */
{ 'g', 'G', 'g' }, /* 5 */
{ 'l', 'L', C('l') }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ 'b', 'B', C('b') }, /* 1 */
{ 'j', 'J', C('j') }, /* 2 */
{ 'n', 'N', C('n') }, /* 3 */
{ 'i', 'I', C('i') }, /* Ins */
{ '.', ':', ':' } /* Del */
},
numpad[PADKEYS] = {
{ '7', M('7'), '7' }, /* 7 */
{ '8', M('8'), '8' }, /* 8 */
{ '9', M('9'), '9' }, /* 9 */
{ 'm', C('p'), C('p') }, /* - */
{ '4', M('4'), '4' }, /* 4 */
{ 'g', 'G', 'g' }, /* 5 */
{ '6', M('6'), '6' }, /* 6 */
{ '+', 'P', C('p') }, /* + */
{ '1', M('1'), '1' }, /* 1 */
{ '2', M('2'), '2' }, /* 2 */
{ '3', M('3'), '3' }, /* 3 */
{ 'i', 'I', C('i') }, /* Ins */
{ '.', ':', ':' } /* Del */
};
#define inmap(x,vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
#define inmap(x, vk) (((x) > 'A' && (x) < 'Z') || (vk) == 0xBF || (x) == '2')
/* Use process_keystroke for key commands, process_keystroke2 for prompts */
/* int FDECL(process_keystroke, (INPUT_RECORD *ir, boolean *valid, int portdebug)); */
int FDECL(process_keystroke2, (HANDLE,INPUT_RECORD *ir, boolean *valid));
/* int FDECL(process_keystroke, (INPUT_RECORD *ir, boolean *valid, int
* portdebug)); */
int FDECL(process_keystroke2, (HANDLE, INPUT_RECORD *ir, boolean *valid));
static int FDECL(is_altseq, (unsigned long shiftstate));
static int
@@ -267,190 +272,195 @@ unsigned long shiftstate;
* on 95-based Windows, AltGr signals as right Alt only.
* So on NT, we signal Alt if either Alt is pressed and left Ctrl is not,
* and on 95, we signal Alt for left Alt only. */
switch (shiftstate & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) {
case LEFT_ALT_PRESSED:
case LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED:
return 1;
switch (shiftstate
& (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) {
case LEFT_ALT_PRESSED:
case LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED:
return 1;
case RIGHT_ALT_PRESSED:
case RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED:
return (GetVersion() & 0x80000000) == 0;
case RIGHT_ALT_PRESSED:
case RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED:
return (GetVersion() & 0x80000000) == 0;
default:
return 0;
default:
return 0;
}
}
int __declspec(dllexport) __stdcall
ProcessKeystroke(hConIn, ir, valid, numberpad, portdebug)
int __declspec(dllexport) __stdcall ProcessKeystroke(hConIn, ir, valid,
numberpad, portdebug)
HANDLE hConIn;
INPUT_RECORD *ir;
boolean *valid;
boolean numberpad;
int portdebug;
{
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
DWORD count;
int metaflags = 0, k = 0;
int keycode, vk;
unsigned char ch, pre_ch, mk = 0;
unsigned short int scan;
unsigned long shiftstate;
int altseq = 0;
const struct pad *kpad;
DWORD count;
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
if (scan == 0 && vk == 0) {
/* It's the bogus_key */
ReadConsoleInput(hConIn,ir,1,&count);
*valid = FALSE;
return 0;
}
shiftstate = 0L;
ch = pre_ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
if (scan == 0 && vk == 0) {
/* It's the bogus_key */
ReadConsoleInput(hConIn, ir, 1, &count);
*valid = FALSE;
return 0;
}
if (is_altseq(shiftstate)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
ReadConsoleInput(hConIn,ir,1,&count);
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
}
else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
}
else {
ch = kpad[scan - KEYPADLO].normal;
}
if (is_altseq(shiftstate)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || (iskeypad(scan)) || (altseq > 0))
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan)) {
ReadConsoleInput(hConIn, ir, 1, &count);
kpad = numberpad ? numpad : keypad;
if (shiftstate & SHIFT_PRESSED) {
ch = kpad[scan - KEYPADLO].shift;
} else if (shiftstate & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) {
ch = kpad[scan - KEYPADLO].cntrl;
} else {
ch = kpad[scan - KEYPADLO].normal;
}
else if (altseq > 0) { /* ALT sequence */
ReadConsoleInput(hConIn,ir,1,&count);
if (vk == 0xBF) ch = M('?');
else ch = M(tolower(keycode));
}
else if (ch < 32 && !isnumkeypad(scan)) {
/* Control code; ReadConsole seems to filter some of these,
* including ESC */
ReadConsoleInput(hConIn,ir,1,&count);
}
/* Attempt to work better with international keyboards. */
else {
CHAR ch2;
DWORD written;
/* The bogus_key guarantees that ReadConsole will return,
* and does not itself do anything */
WriteConsoleInput(hConIn, &bogus_key, 1, &written);
ReadConsole(hConIn,&ch2,1,&count,NULL);
/* Prevent high characters from being interpreted as alt
* sequences; also filter the bogus_key */
if (ch2 & 0x80)
*valid = FALSE;
else
ch = ch2;
if (ch == 0) *valid = FALSE;
}
if (ch == '\r') ch = '\n';
} else if (altseq > 0) { /* ALT sequence */
ReadConsoleInput(hConIn, ir, 1, &count);
if (vk == 0xBF)
ch = M('?');
else
ch = M(tolower(keycode));
} else if (ch < 32 && !isnumkeypad(scan)) {
/* Control code; ReadConsole seems to filter some of these,
* including ESC */
ReadConsoleInput(hConIn, ir, 1, &count);
}
/* Attempt to work better with international keyboards. */
else {
CHAR ch2;
DWORD written;
/* The bogus_key guarantees that ReadConsole will return,
* and does not itself do anything */
WriteConsoleInput(hConIn, &bogus_key, 1, &written);
ReadConsole(hConIn, &ch2, 1, &count, NULL);
/* Prevent high characters from being interpreted as alt
* sequences; also filter the bogus_key */
if (ch2 & 0x80)
*valid = FALSE;
else
ch = ch2;
if (ch == 0)
*valid = FALSE;
}
if (ch == '\r')
ch = '\n';
#ifdef PORT_DEBUG
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf,
"PORTDEBUG: ch=%u, scan=%u, vk=%d, pre=%d, shiftstate=0x%X (ESC to end)\n",
ch, scan, vk, pre_ch, shiftstate);
fprintf(stdout, "\n%s", buf);
}
if (portdebug) {
char buf[BUFSZ];
Sprintf(buf, "PORTDEBUG: ch=%u, scan=%u, vk=%d, pre=%d, "
"shiftstate=0x%X (ESC to end)\n",
ch, scan, vk, pre_ch, shiftstate);
fprintf(stdout, "\n%s", buf);
}
#endif
return ch;
return ch;
}
int process_keystroke2(hConIn, ir, valid)
int
process_keystroke2(hConIn, ir, valid)
HANDLE hConIn;
INPUT_RECORD *ir;
boolean *valid;
{
/* Use these values for the numeric keypad */
static const char keypad_nums[] = "789-456+1230.";
/* Use these values for the numeric keypad */
static const char keypad_nums[] = "789-456+1230.";
unsigned char ch;
int vk;
unsigned short int scan;
unsigned long shiftstate;
int altseq;
DWORD count;
unsigned char ch;
int vk;
unsigned short int scan;
unsigned long shiftstate;
int altseq;
DWORD count;
ch = ir->Event.KeyEvent.uChar.AsciiChar;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
ch = ir->Event.KeyEvent.uChar.AsciiChar;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
if (scan == 0 && vk == 0) {
/* It's the bogus_key */
ReadConsoleInput(hConIn,ir,1,&count);
*valid = FALSE;
return 0;
}
if (scan == 0 && vk == 0) {
/* It's the bogus_key */
ReadConsoleInput(hConIn, ir, 1, &count);
*valid = FALSE;
return 0;
}
altseq = is_altseq(shiftstate);
if (ch || (iskeypad(scan)) || altseq)
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan) && !altseq) {
ReadConsoleInput(hConIn,ir,1,&count);
ch = keypad_nums[scan - KEYPADLO];
}
else if (ch < 32 && !isnumkeypad(scan)) {
/* Control code; ReadConsole seems to filter some of these,
* including ESC */
ReadConsoleInput(hConIn,ir,1,&count);
}
/* Attempt to work better with international keyboards. */
else {
CHAR ch2;
ReadConsole(hConIn,&ch2,1,&count,NULL);
ch = ch2 & 0xFF;
if (ch == 0) *valid = FALSE;
}
if (ch == '\r') ch = '\n';
return ch;
altseq = is_altseq(shiftstate);
if (ch || (iskeypad(scan)) || altseq)
*valid = TRUE;
/* if (!valid) return 0; */
/*
* shiftstate can be checked to see if various special
* keys were pressed at the same time as the key.
* Currently we are using the ALT & SHIFT & CONTROLS.
*
* RIGHT_ALT_PRESSED, LEFT_ALT_PRESSED,
* RIGHT_CTRL_PRESSED, LEFT_CTRL_PRESSED,
* SHIFT_PRESSED,NUMLOCK_ON, SCROLLLOCK_ON,
* CAPSLOCK_ON, ENHANCED_KEY
*
* are all valid bit masks to use on shiftstate.
* eg. (shiftstate & LEFT_CTRL_PRESSED) is true if the
* left control key was pressed with the keystroke.
*/
if (iskeypad(scan) && !altseq) {
ReadConsoleInput(hConIn, ir, 1, &count);
ch = keypad_nums[scan - KEYPADLO];
} else if (ch < 32 && !isnumkeypad(scan)) {
/* Control code; ReadConsole seems to filter some of these,
* including ESC */
ReadConsoleInput(hConIn, ir, 1, &count);
}
/* Attempt to work better with international keyboards. */
else {
CHAR ch2;
ReadConsole(hConIn, &ch2, 1, &count, NULL);
ch = ch2 & 0xFF;
if (ch == 0)
*valid = FALSE;
}
if (ch == '\r')
ch = '\n';
return ch;
}
int __declspec(dllexport) __stdcall
CheckInput(hConIn, ir, count, numpad, mode, mod, cc)
int __declspec(dllexport) __stdcall CheckInput(hConIn, ir, count, numpad,
mode, mod, cc)
HANDLE hConIn;
INPUT_RECORD *ir;
DWORD *count;
@@ -459,53 +469,61 @@ boolean numpad;
coord *cc;
{
#if defined(SAFERHANGUP)
DWORD dwWait;
DWORD dwWait;
#endif
int ch;
boolean valid = 0, done = 0;
while (!done) {
*count = 0;
dwWait = WaitForSingleObject(hConIn, INFINITE);
int ch;
boolean valid = 0, done = 0;
while (!done) {
*count = 0;
dwWait = WaitForSingleObject(hConIn, INFINITE);
#if defined(SAFERHANGUP)
if (dwWait == WAIT_FAILED) return '\033';
if (dwWait == WAIT_FAILED)
return '\033';
#endif
PeekConsoleInput(hConIn,ir,1,count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = process_keystroke2(hConIn, ir, &valid);
done = valid;
} else
ReadConsoleInput(hConIn,ir,1,count);
} else {
ch = 0;
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad,
PeekConsoleInput(hConIn, ir, 1, count);
if (mode == 0) {
if ((ir->EventType == KEY_EVENT) && ir->Event.KeyEvent.bKeyDown) {
ch = process_keystroke2(hConIn, ir, &valid);
done = valid;
} else
ReadConsoleInput(hConIn, ir, 1, count);
} else {
ch = 0;
if (count > 0) {
if (ir->EventType == KEY_EVENT
&& ir->Event.KeyEvent.bKeyDown) {
ch = ProcessKeystroke(hConIn, ir, &valid, numpad,
#ifdef PORTDEBUG
1);
1);
#else
0);
0);
#endif
if (valid) return ch;
} else {
ReadConsoleInput(hConIn,ir,1,count);
if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0) &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK)) {
cc->x = ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y = ir->Event.MouseEvent.dwMousePosition.Y - 1;
if (valid)
return ch;
} else {
ReadConsoleInput(hConIn, ir, 1, count);
if (ir->EventType == MOUSE_EVENT) {
if ((ir->Event.MouseEvent.dwEventFlags == 0)
&& (ir->Event.MouseEvent.dwButtonState
& MOUSEMASK)) {
cc->x =
ir->Event.MouseEvent.dwMousePosition.X + 1;
cc->y =
ir->Event.MouseEvent.dwMousePosition.Y - 1;
if (ir->Event.MouseEvent.dwButtonState & LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState & RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
if (ir->Event.MouseEvent.dwButtonState
& LEFTBUTTON)
*mod = CLICK_1;
else if (ir->Event.MouseEvent.dwButtonState
& RIGHTBUTTON)
*mod = CLICK_2;
#if 0 /* middle button */
else if (ir->Event.MouseEvent.dwButtonState & MIDBUTTON)
*mod = CLICK_3;
#endif
return 0;
}
}
#endif
return 0;
}
}
#if 0
/* We ignore these types of console events */
else if (ir->EventType == FOCUS_EVENT) {
@@ -513,96 +531,96 @@ coord *cc;
else if (ir->EventType == MENU_EVENT) {
}
#endif
}
} else
done = 1;
}
}
*mod = 0;
return ch;
}
} else
done = 1;
}
}
*mod = 0;
return ch;
}
int __declspec(dllexport) __stdcall
NHkbhit(hConIn, ir)
int __declspec(dllexport) __stdcall NHkbhit(hConIn, ir)
HANDLE hConIn;
INPUT_RECORD *ir;
{
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done)
{
count = 0;
PeekConsoleInput(hConIn,ir,1,&count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (is_altseq(shiftstate)) {
if (ch || inmap(keycode,vk)) altseq = 1;
else altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn,ir,1,&count);
}
int done = 0; /* true = "stop searching" */
int retval; /* true = "we had a match" */
DWORD count;
unsigned short int scan;
unsigned char ch;
unsigned long shiftstate;
int altseq = 0, keycode, vk;
done = 0;
retval = 0;
while (!done) {
count = 0;
PeekConsoleInput(hConIn, ir, 1, &count);
if (count > 0) {
if (ir->EventType == KEY_EVENT && ir->Event.KeyEvent.bKeyDown) {
ch = ir->Event.KeyEvent.uChar.AsciiChar;
scan = ir->Event.KeyEvent.wVirtualScanCode;
shiftstate = ir->Event.KeyEvent.dwControlKeyState;
vk = ir->Event.KeyEvent.wVirtualKeyCode;
keycode = MapVirtualKey(vk, 2);
if (is_altseq(shiftstate)) {
if (ch || inmap(keycode, vk))
altseq = 1;
else
altseq = -1; /* invalid altseq */
}
if (ch || iskeypad(scan) || altseq) {
done = 1; /* Stop looking */
retval = 1; /* Found what we sought */
} else {
/* Strange Key event; let's purge it to avoid trouble */
ReadConsoleInput(hConIn, ir, 1, &count);
}
}
else if ((ir->EventType == MOUSE_EVENT &&
(ir->Event.MouseEvent.dwButtonState & MOUSEMASK))) {
done = 1;
retval = 1;
}
} else if ((ir->EventType == MOUSE_EVENT
&& (ir->Event.MouseEvent.dwButtonState
& MOUSEMASK))) {
done = 1;
retval = 1;
}
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn,ir,1,&count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
else /* Discard it, it's an insignificant event */
ReadConsoleInput(hConIn, ir, 1, &count);
} else /* There are no events in console event queue */ {
done = 1; /* Stop looking */
retval = 0;
}
}
return retval;
}
int __declspec(dllexport) __stdcall
SourceWhere(buf)
int __declspec(dllexport) __stdcall SourceWhere(buf)
char **buf;
{
if (!buf) return 0;
*buf = where_to_get_source;
return 1;
if (!buf)
return 0;
*buf = where_to_get_source;
return 1;
}
int __declspec(dllexport) __stdcall
SourceAuthor(buf)
int __declspec(dllexport) __stdcall SourceAuthor(buf)
char **buf;
{
if (!buf) return 0;
*buf = author;
return 1;
if (!buf)
return 0;
*buf = author;
return 1;
}
int __declspec(dllexport) __stdcall
KeyHandlerName(buf, full)
int __declspec(dllexport) __stdcall KeyHandlerName(buf, full)
char **buf;
int full;
{
if (!buf) return 0;
if (full) *buf = dllname;
else *buf = shortdllname;
return 1;
if (!buf)
return 0;
if (full)
*buf = dllname;
else
*buf = shortdllname;
return 1;
}

View File

@@ -1,13 +1,13 @@
/* NetHack 3.6 ntsound.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 ntsound.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 ntsound.c $Date: 2009/05/06 10:53:33 $ $Revision: 1.7 $ */
/* SCCS Id: @(#)ntsound.c 3.5 $NHDT-Date$ */
/* SCCS Id: @(#)ntsound.c 3.5 $Date: 2009/05/06 10:53:33 $ */
/* SCCS Id: @(#)ntsound.c 3.5 $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ */
/* SCCS Id: @(#)ntsound.c 3.5 $Date: 2009/05/06 10:53:33 $ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
/* */
/*
* ntsound.c - Windows NT NetHack sound support
*
*
*Edit History:
* Initial Creation 93/12/11
*
@@ -19,12 +19,13 @@
#ifdef USER_SOUNDS
void play_usersound(filename, volume)
const char* filename;
void
play_usersound(filename, volume)
const char *filename;
int volume;
{
/* pline("play_usersound: %s (%d).", filename, volume); */
(void)sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT);
/* pline("play_usersound: %s (%d).", filename, volume); */
(void) sndPlaySound(filename, SND_ASYNC | SND_NODEFAULT);
}
#endif /*USER_SOUNDS*/

File diff suppressed because it is too large Load Diff

View File

@@ -1,41 +1,41 @@
#include "hack.h"
#ifdef GUISTUB
# ifdef TTYSTUB
# error You can't compile this with both GUISTUB and TTYSTUB defined.
# endif
#ifdef TTYSTUB
#error You can't compile this with both GUISTUB and TTYSTUB defined.
#endif
int GUILaunched;
struct window_procs mswin_procs = {"guistubs"};
struct window_procs mswin_procs = { "guistubs" };
void
mswin_destroy_reg()
{
return;
return;
}
/* MINGW32 has trouble with both a main() and WinMain()
* so we move main for the MINGW tty version into this stub
* so that it is out of sight for the gui linkage.
*/
# ifdef __MINGW32__
#ifdef __MINGW32__
extern char default_window_sys[];
int
main(argc,argv)
main(argc, argv)
int argc;
char *argv[];
{
boolean resuming;
boolean resuming;
sys_early_init();
Strcpy(default_window_sys, "tty");
resuming = pcmain(argc,argv);
moveloop(resuming);
nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
sys_early_init();
Strcpy(default_window_sys, "tty");
resuming = pcmain(argc, argv);
moveloop(resuming);
nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
# endif
#endif
#endif /* GUISTUB */
/* =============================================== */
@@ -45,7 +45,7 @@ char *argv[];
#include "hack.h"
int GUILaunched;
struct window_procs tty_procs = {"ttystubs"};
struct window_procs tty_procs = { "ttystubs" };
void
win_tty_init(dir)
@@ -58,45 +58,44 @@ void
nttty_open(mode)
int mode;
{
return;
return;
}
void
xputc(ch)
char ch;
{
return;
return;
}
void
xputs(s)
const char *s;
{
return;
return;
}
void
raw_clear_screen()
{
return;
return;
}
void
clear_screen()
{
return;
return;
}
void
backsp()
{
return;
return;
}
int
has_color(int color)
{
return 1;
}
@@ -104,7 +103,7 @@ has_color(int color)
void
toggle_mouse_support()
{
return;
return;
}
#endif
@@ -112,12 +111,12 @@ toggle_mouse_support()
void
win32con_debug_keystrokes()
{
return;
return;
}
void
win32con_handler_info()
{
return;
return;
}
#endif
@@ -125,45 +124,45 @@ void
map_subkeyvalue(op)
register char *op;
{
return;
return;
}
void
load_keyboard_handler()
{
return;
return;
}
/* this is used as a printf() replacement when the window
* system isn't initialized yet
*/
void
msmsg VA_DECL(const char *, fmt)
VA_START(fmt);
VA_INIT(fmt, const char *);
VA_END();
return;
void msmsg
VA_DECL(const char *, fmt)
VA_START(fmt);
VA_INIT(fmt, const char *);
VA_END();
return;
}
/*VARARGS1*/
void
nttty_error VA_DECL(const char *,s)
VA_START(s);
VA_INIT(s, const char *);
VA_END();
return;
void nttty_error
VA_DECL(const char *, s)
VA_START(s);
VA_INIT(s, const char *);
VA_END();
return;
}
void
synch_cursor()
{
return;
return;
}
void more()
void
more()
{
return;
return;
}
#endif /* TTYSTUBS */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winnt.c $NHDT-Date: 1430988900 2015/05/07 08:55:00 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.24 $ */
/* NetHack 3.6 winnt.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */
/* Copyright (c) NetHack PC Development Team 1993, 1994 */
/* NetHack may be freely redistributed. See license for details. */
@@ -20,7 +20,6 @@
#include "wintty.h"
#ifdef WIN32
/*
* The following WIN32 API routines are used in this file.
*
@@ -33,9 +32,8 @@
*
*/
/* globals required within here */
HANDLE ffhandle = (HANDLE)0;
HANDLE ffhandle = (HANDLE) 0;
WIN32_FIND_DATA ffd;
/* The function pointer nt_kbhit contains a kbhit() equivalent
@@ -51,30 +49,27 @@ int (*nt_kbhit)() = def_kbhit;
char
switchar()
{
/* Could not locate a WIN32 API call for this- MJA */
return '-';
/* Could not locate a WIN32 API call for this- MJA */
return '-';
}
long
freediskspace(path)
char *path;
{
char tmppath[4];
DWORD SectorsPerCluster = 0;
DWORD BytesPerSector = 0;
DWORD FreeClusters = 0;
DWORD TotalClusters = 0;
char tmppath[4];
DWORD SectorsPerCluster = 0;
DWORD BytesPerSector = 0;
DWORD FreeClusters = 0;
DWORD TotalClusters = 0;
tmppath[0] = *path;
tmppath[1] = ':';
tmppath[2] = '\\';
tmppath[3] = '\0';
GetDiskFreeSpace(tmppath, &SectorsPerCluster,
&BytesPerSector,
&FreeClusters,
&TotalClusters);
return (long)(SectorsPerCluster * BytesPerSector *
FreeClusters);
tmppath[0] = *path;
tmppath[1] = ':';
tmppath[2] = '\\';
tmppath[3] = '\0';
GetDiskFreeSpace(tmppath, &SectorsPerCluster, &BytesPerSector,
&FreeClusters, &TotalClusters);
return (long) (SectorsPerCluster * BytesPerSector * FreeClusters);
}
/*
@@ -84,35 +79,34 @@ int
findfirst(path)
char *path;
{
if (ffhandle){
FindClose(ffhandle);
ffhandle = (HANDLE)0;
}
ffhandle = FindFirstFile(path,&ffd);
return
(ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1;
if (ffhandle) {
FindClose(ffhandle);
ffhandle = (HANDLE) 0;
}
ffhandle = FindFirstFile(path, &ffd);
return (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1;
}
int
findnext()
findnext()
{
return FindNextFile(ffhandle,&ffd) ? 1 : 0;
return FindNextFile(ffhandle, &ffd) ? 1 : 0;
}
char *
foundfile_buffer()
{
return &ffd.cFileName[0];
return &ffd.cFileName[0];
}
long
filesize(file)
char *file;
{
if (findfirst(file)) {
return ((long)ffd.nFileSizeLow);
} else
return -1L;
if (findfirst(file)) {
return ((long) ffd.nFileSizeLow);
} else
return -1L;
}
/*
@@ -122,69 +116,73 @@ void
chdrive(str)
char *str;
{
char *ptr;
char drive;
if ((ptr = index(str, ':')) != (char *)0)
{
drive = toupper(*(ptr - 1));
_chdrive((drive - 'A') + 1);
}
char *ptr;
char drive;
if ((ptr = index(str, ':')) != (char *) 0) {
drive = toupper(*(ptr - 1));
_chdrive((drive - 'A') + 1);
}
}
static int
max_filename()
{
DWORD maxflen;
int status=0;
status = GetVolumeInformation((LPTSTR)0,(LPTSTR)0, 0
,(LPDWORD)0,&maxflen,(LPDWORD)0,(LPTSTR)0,0);
if (status) return maxflen;
else return 0;
DWORD maxflen;
int status = 0;
status = GetVolumeInformation((LPTSTR) 0, (LPTSTR) 0, 0, (LPDWORD) 0,
&maxflen, (LPDWORD) 0, (LPTSTR) 0, 0);
if (status)
return maxflen;
else
return 0;
}
int
def_kbhit()
{
return 0;
return 0;
}
/*
/*
* Strip out troublesome file system characters.
*/
void
nt_regularize(s) /* normalize file name */
void nt_regularize(s) /* normalize file name */
register char *s;
{
register unsigned char *lp;
register unsigned char *lp;
for (lp = s; *lp; lp++)
if ( *lp == '?' || *lp == '"' || *lp == '\\' ||
*lp == '/' || *lp == '>' || *lp == '<' ||
*lp == '*' || *lp == '|' || *lp == ':' || (*lp > 127))
*lp = '_';
for (lp = s; *lp; lp++)
if (*lp == '?' || *lp == '"' || *lp == '\\' || *lp == '/'
|| *lp == '>' || *lp == '<' || *lp == '*' || *lp == '|'
|| *lp == ':' || (*lp > 127))
*lp = '_';
}
/*
* This is used in nhlan.c to implement some of the LAN_FEATURES.
*/
char *get_username(lan_username_size)
char *
get_username(lan_username_size)
int *lan_username_size;
{
static TCHAR username_buffer[BUFSZ];
unsigned int status;
DWORD i = BUFSZ - 1;
static TCHAR username_buffer[BUFSZ];
unsigned int status;
DWORD i = BUFSZ - 1;
/* i gets updated with actual size */
status = GetUserName(username_buffer, &i);
if (status) username_buffer[i] = '\0';
else Strcpy(username_buffer, "NetHack");
if (lan_username_size) *lan_username_size = strlen(username_buffer);
return username_buffer;
/* i gets updated with actual size */
status = GetUserName(username_buffer, &i);
if (status)
username_buffer[i] = '\0';
else
Strcpy(username_buffer, "NetHack");
if (lan_username_size)
*lan_username_size = strlen(username_buffer);
return username_buffer;
}
# if 0
#if 0
char *getxxx()
{
char szFullPath[MAX_PATH] = "";
@@ -193,66 +191,68 @@ HMODULE hInst = NULL; /* NULL gets the filename of this module */
GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
return &szFullPath[0];
}
# endif
#endif
/* fatal error */
/*VARARGS1*/
void
error VA_DECL(const char *,s)
char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited) end_screen();
if (!strncmpi(windowprocs.name, "tty", 3)) {
buf[0] = '\n';
(void) vsprintf(&buf[1], s, VA_ARGS);
Strcat(buf, "\n");
msmsg(buf);
} else {
(void) vsprintf(buf, s, VA_ARGS);
Strcat(buf, "\n");
raw_printf(buf);
}
VA_END();
exit(EXIT_FAILURE);
void error
VA_DECL(const char *, s)
char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited)
end_screen();
if (!strncmpi(windowprocs.name, "tty", 3)) {
buf[0] = '\n';
(void) vsprintf(&buf[1], s, VA_ARGS);
Strcat(buf, "\n");
msmsg(buf);
} else {
(void) vsprintf(buf, s, VA_ARGS);
Strcat(buf, "\n");
raw_printf(buf);
}
VA_END();
exit(EXIT_FAILURE);
}
void Delay(int ms)
void
Delay(int ms)
{
(void)Sleep(ms);
(void) Sleep(ms);
}
extern void NDECL(backsp);
void win32_abort()
void
win32_abort()
{
if (wizard) {
int c, ci, ct;
if (wizard) {
int c, ci, ct;
if (!iflags.window_inited)
c = 'n';
ct = 0;
msmsg("Execute debug breakpoint wizard?");
while ((ci=nhgetch()) != '\n') {
if (ct > 0) {
backsp(); /* \b is visible on NT */
(void) putchar(' ');
backsp();
ct = 0;
c = 'n';
}
if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
ct = 1;
c = ci;
msmsg("%c",c);
}
}
if (c == 'y')
DebugBreak();
}
abort();
if (!iflags.window_inited)
c = 'n';
ct = 0;
msmsg("Execute debug breakpoint wizard?");
while ((ci = nhgetch()) != '\n') {
if (ct > 0) {
backsp(); /* \b is visible on NT */
(void) putchar(' ');
backsp();
ct = 0;
c = 'n';
}
if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
ct = 1;
c = ci;
msmsg("%c", c);
}
}
if (c == 'y')
DebugBreak();
}
abort();
}
static char interjection_buf[INTERJECTION_TYPES][1024];
@@ -265,81 +265,85 @@ int interjection_type;
genericptr_t ptr1;
genericptr_t ptr2;
{
switch(num) {
case 1: {
char *panicmsg = (char *)ptr1;
char *datadir = (char *)ptr2;
char *tempdir = nh_getenv("TEMP");
interjection_type = INTERJECT_PANIC;
interjection[INTERJECT_PANIC] = 1;
/*
* ptr1 = the panic message about to be delivered.
* ptr2 = the directory prefix of the dungeon file
* that failed to open.
* Check to see if datadir matches tempdir or a
* common windows temp location. If it does, inform
* the user that they are probably trying to run the
* game from within their unzip utility, so the required
* files really don't exist at the location. Instruct
* them to unpack them first.
*/
if (panicmsg && datadir) {
if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15) ||
strstri(datadir, "TEMP") ||
(tempdir && strstri(datadir, tempdir))) {
(void)strncpy(interjection_buf[INTERJECT_PANIC],
"\nOne common cause of this error is attempting to execute\n"
"the game by double-clicking on it while it is displayed\n"
"inside an unzip utility.\n\n"
"You have to unzip the contents of the zip file into a\n"
"folder on your system, and then run \"NetHack.exe\" or \n"
"\"NetHackW.exe\" from there.\n\n"
"If that is not the situation, you are encouraged to\n"
"report the error as shown above.\n\n", 1023);
}
}
}
break;
}
switch (num) {
case 1: {
char *panicmsg = (char *) ptr1;
char *datadir = (char *) ptr2;
char *tempdir = nh_getenv("TEMP");
interjection_type = INTERJECT_PANIC;
interjection[INTERJECT_PANIC] = 1;
/*
* ptr1 = the panic message about to be delivered.
* ptr2 = the directory prefix of the dungeon file
* that failed to open.
* Check to see if datadir matches tempdir or a
* common windows temp location. If it does, inform
* the user that they are probably trying to run the
* game from within their unzip utility, so the required
* files really don't exist at the location. Instruct
* them to unpack them first.
*/
if (panicmsg && datadir) {
if (!strncmpi(datadir, "C:\\WINDOWS\\TEMP", 15)
|| strstri(datadir, "TEMP")
|| (tempdir && strstri(datadir, tempdir))) {
(void) strncpy(
interjection_buf[INTERJECT_PANIC],
"\nOne common cause of this error is attempting to "
"execute\n"
"the game by double-clicking on it while it is "
"displayed\n"
"inside an unzip utility.\n\n"
"You have to unzip the contents of the zip file into a\n"
"folder on your system, and then run \"NetHack.exe\" or "
"\n"
"\"NetHackW.exe\" from there.\n\n"
"If that is not the situation, you are encouraged to\n"
"report the error as shown above.\n\n",
1023);
}
}
} break;
}
}
void
interject(interjection_type)
int interjection_type;
{
if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
msmsg(interjection_buf[interjection_type]);
if (interjection_type >= 0 && interjection_type < INTERJECTION_TYPES)
msmsg(interjection_buf[interjection_type]);
}
# ifdef RUNTIME_PORT_ID
#ifdef RUNTIME_PORT_ID
/*
* _M_IX86 is Defined for x86 processors. This is not defined for x64 processors.
* _M_IX86 is Defined for x86 processors. This is not defined for x64
* processors.
* _M_X64 is Defined for x64 processors.
* _M_IA64 is Defined for Itanium Processor Family 64-bit processors.
* _WIN64 is Defined for applications for Win64.
*/
# ifndef _M_IX86
# ifdef _M_X64
# define TARGET_PORT "(x64) "
# endif
# ifdef _M_IA64
# define TARGET_PORT "(IA64) "
# endif
# endif
#ifndef _M_IX86
#ifdef _M_X64
#define TARGET_PORT "(x64) "
#endif
#ifdef _M_IA64
#define TARGET_PORT "(IA64) "
#endif
#endif
# ifndef TARGET_PORT
# define TARGET_PORT "(x86) "
# endif
#ifndef TARGET_PORT
#define TARGET_PORT "(x86) "
#endif
void
append_port_id(buf)
char *buf;
{
char *portstr = TARGET_PORT;
Sprintf(eos(buf), " %s", portstr);
char *portstr = TARGET_PORT;
Sprintf(eos(buf), " %s", portstr);
}
# endif /* RUNTIME_PORT_ID */
#endif /* RUNTIME_PORT_ID */
#endif /* WIN32 */