Skip to content

Commit

Permalink
Patches (golded-plus#81)
Browse files Browse the repository at this point in the history
Patches by Nil Alexandrov, 2:5015/46.
  • Loading branch information
vitaliy-aksyonov authored Feb 28, 2024
2 parents c7b6101 + 86c6ba5 commit 9082258
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 75 deletions.
4 changes: 2 additions & 2 deletions golded3/gckeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,10 @@ int ReadKeysCfg()
if(*ptr == '\"') // Start of literal string
{
ptr++;
while((*ptr != '\"') and (n < (sizeof(tmp2.buf)/sizeof(gkey))))
while(*ptr and *ptr != '\"' and n < (sizeof(tmp2.buf)/sizeof(gkey)))
{
// allow '\"' and '\\' in config
if((ptr[0] == '\\') and ((ptr[1] == '\"') or (ptr[1] == '\\')))
if(*ptr and ptr[0] == '\\' and ((ptr[1] == '\"') or (ptr[1] == '\\')))
ptr++;
ch = *ptr++;
tmp2.buf[n++] = (gkey)(ch | (scancode(ch) << 8));
Expand Down
10 changes: 4 additions & 6 deletions golded3/geedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@

#include <golded.h>
#include <geedit.h>

gkey kbxget_raw(int mode);

#include <gkbdbase.h>

// ------------------------------------------------------------------
// Globals
Expand Down Expand Up @@ -3369,9 +3367,9 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg)
do
{
_ch = getxchtick();
// TO_PORT_TAG: kbxget_raw(3)
// TO_PORT_TAG: kbxget_raw(KeyMode_Control)
#if defined(__WIN32__)
keystatus = kbxget_raw(3);
keystatus = kbxget_raw(KeyMode_Control);
#endif

if(EDIT->AutoSave())
Expand Down Expand Up @@ -3400,7 +3398,7 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg)
{
_ch = _kk;

// TO_PORT_TAG: kbxget_raw(3)
// TO_PORT_TAG: kbxget_raw(KeyMode_Shift)
#if defined(__WIN32__)
if (keystatus & SHIFT_PRESSED)
#else
Expand Down
16 changes: 1 addition & 15 deletions golded3/geutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,7 @@ void update_statuslinef(const char *format, const char *token, ...)
char winfobuf[350];
va_list argptr;
va_start(argptr, token);

try
{
vsprintf(winfobuf, format, argptr);
}
catch(...)
{
if (*token)
sprintf(winfobuf, "ERROR: Update %s in your GOLDLANG.CFG or report to author.", token);
else
sprintf(winfobuf, "ERROR: \"%s\". Report to author.", format);

error = true;
}

vsprintf(winfobuf, format, argptr);
va_end(argptr);
update_statusline(winfobuf);

Expand Down
2 changes: 1 addition & 1 deletion goldlib/gall/gcharset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const char *get_dos_charset(const char *cpfrom)
}
#if defined(__unix__)
char* lang = getenv("LANG");
if( lang && strncmp(lang,"ru_RU",5) )
if( lang && !strncmp(lang,"ru_RU",5) )
{
return "CP866";
}
Expand Down
92 changes: 43 additions & 49 deletions goldlib/gcui/gkbdbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

#if defined(__linux__)
#include <sys/ioctl.h>
#include <linux/tiocl.h>
#include <stdio.h>
#endif

Expand Down Expand Up @@ -1069,14 +1070,14 @@ void gkbd_setfnkeys()
#endif
}

int gkbd_cursgetch(int mode)
int gkbd_cursgetch(eKeyModes mode)
{

int key;
#ifndef BUGGY_NCURSES
nodelay(stdscr, mode);
#else
wtimeout(stdscr, mode ? 0 : -1);
wtimeout(stdscr, (mode != KeyMode_Wait) ? 0 : -1);
#endif
key = getch();
#ifndef BUGGY_NCURSES
Expand Down Expand Up @@ -1456,22 +1457,18 @@ gkey gkbd_alt_secondary_keyboard(int key)
// ------------------------------------------------------------------
// Get key stroke

gkey kbxget_raw(int mode)
gkey kbxget_raw(eKeyModes mode)
{
// mode - =0 - wait for key is pressed (returns code)
// =1 - test if keystroke is available (returns code if YES,
// otherwise returns 0)
// =2 - return Shifts key status
gkey k;

// TO_PORT_TAG: kbxget_raw(3)
// TO_PORT_TAG: kbxget_raw(KeyMode_Control)
#if defined(__USE_NCURSES__)

int key;
if(mode == 2)
if(mode == KeyMode_Shift)
{
// We can't do much but we can at least this :-)
k = kbxget_raw(1);
k = kbxget_raw(KeyMode_Test);
key = 0;
switch(k)
{
Expand Down Expand Up @@ -1511,7 +1508,7 @@ gkey kbxget_raw(int mode)
// Prefix for Meta-key or Alt-key sequences
if(key == 27)
{
int key2 = gkbd_cursgetch(TRUE);
int key2 = gkbd_cursgetch(KeyMode_Test);
// If no key follows, it is no Meta- or Alt- seq, but a single Esc
if(key2 == ERR)
k = Key_Esc;
Expand All @@ -1533,12 +1530,12 @@ gkey kbxget_raw(int mode)
else if(0 == (k = gkbd_alt_secondary_keyboard(key2)))
{
// No correct Alt-sequence; ungetch last key and return Esc
if (mode != 1)
if (mode != KeyMode_Test)
ungetch(key2);
k = Key_Esc;
}

if((key2 != ERR) and (mode == 1))
if((key2 != ERR) and (mode == KeyMode_Test))
ungetch(key2);
}
// Curses sequence; lookup in nice table above
Expand All @@ -1557,27 +1554,27 @@ gkey kbxget_raw(int mode)
else
return 0; // Incorrect or unsupported key don't ungetch()

if(mode == 1)
if(mode == KeyMode_Test)
ungetch(key);

#elif defined(__MSDOS__)

int dos_mode = (int)mode;
if(gkbd.extkbd)
mode |= 0x10;
dos_mode |= 0x10;

i86 cpu;
cpu.ah((byte)mode);
cpu.ah((byte)dos_mode);
cpu.genint(0x16);
if(mode & 0x01)
if(dos_mode & 0x01)
if(cpu.flags() & 0x40) // if ZF is set, no key is available
return 0;
k = (gkey)cpu.ax();

if((mode & ~0x10) == 0)
if((dos_mode & ~0x10) == 0)
{
if((KCodAsc(k) == 0xE0) and (KCodScn(k) != 0))
{
if(kbxget_raw(2) & (LSHIFT | RSHIFT))
if(kbxget_raw(KeyMode_Shift) & (LSHIFT | RSHIFT))
{
KCodAsc(k) = 0;
KCodScn(k) |= 0x80;
Expand All @@ -1597,7 +1594,7 @@ gkey kbxget_raw(int mode)
case 0x52:
case 0x53:
{
int shifts = kbxget_raw(2);
int shifts = kbxget_raw(KeyMode_Shift);
if(shifts & (LSHIFT | RSHIFT))
{
if(shifts & NUMLOCK)
Expand All @@ -1620,16 +1617,15 @@ gkey kbxget_raw(int mode)
// for testing for keys. This can be done with by bioskey (1) or
// bioskey (0x11). Failing to do so can cause trouble in multitasking
// environments like DESQview/X. (Taken from DJGPP documentation)
if((mode & 0x02) == 1)
kbxget_raw(1);
if((dos_mode & 0x02) == 1)
kbxget_raw(KeyMode_Test);

#elif defined(__OS2__)

KBDKEYINFO kb;
mode &= 0xF;
if(mode == 0)
if(mode == KeyMode_Wait)
KbdCharIn(&kb, IO_WAIT, 0);
else if(mode == 2)
else if(mode == KeyMode_Shift)
{
KbdPeek(&kb, 0);
if(kb.fbStatus)
Expand Down Expand Up @@ -1699,15 +1695,15 @@ gkey kbxget_raw(int mode)
DWORD nread;
static gkey KeyCtrlState = 0;

if (mode == 3)
if (mode == KeyMode_Control)
{
return KeyCtrlState;
}
else if(mode == 2)
else if(mode == KeyMode_Shift)
{
return 0;
}
else if(mode & 0x01)
else if(mode == KeyMode_Test)
{

// Peek at next key
Expand All @@ -1732,7 +1728,7 @@ gkey kbxget_raw(int mode)
}
}
}
else
else // KeyMode_Wait
{

DWORD &CKS = inp.Event.KeyEvent.dwControlKeyState;
Expand Down Expand Up @@ -1845,41 +1841,42 @@ gkey kbxget_raw(int mode)

#elif defined(__UNIX__)

if(mode == 2)
if(mode == KeyMode_Shift)
{
int key;
#if defined(__linux__)
// Under Linux we could use TIOCLINUX fn. 6 to read shift states on console
// Under Linux we could use TIOCLINUX ioctl_console with
// TIOCL_GETSHIFTSTATE subcode to read the shift state variable.
// Of course it is very unportable but should produce good results :-)
key = 6;
// Note: valgrind complains with "Syscall param ioctl(TIOCLINUX) points
// to uninitialised byte(s)". This is expected. valgrind does not
// understand how the ioctl works. Try to run with a
// --sim-hints=lax-ioctls option.
char key = TIOCL_GETSHIFTSTATE;
if(ioctl(fileno(stdin), TIOCLINUX, &key) == -1)
#else
int key = 0;
#endif
key = 0;
#ifdef __BEOS__
key = BeOSShiftState();
#endif
return key;
return (int)key;
}
else if(mode & 0x01)
else if(mode == KeyMode_Test)
{

// Peek at next key
return gkbd_input_pending() ? 0xFFFF : 0;
}
else
{

k = gkbd_getmappedkey();
}

#endif

#ifdef __linux__
char shifts = TIOCL_GETSHIFTSTATE;
if(linux_cui_key(k))
{
// Under Linux we could use TIOCLINUX fn. 6 to read shift states on console
// Of course it is very unportable but should produce good results :-)
int shifts = 6;
if(ioctl(fileno(stdin), TIOCLINUX, &shifts) == -1)
shifts = 0;
if(shifts & (LSHIFT | RSHIFT))
Expand Down Expand Up @@ -1923,9 +1920,6 @@ gkey kbxget_raw(int mode)
}
else if(k == Key_BS)
{
// Under Linux we could use TIOCLINUX fn. 6 to read shift states on console
// Of course it is very unportable but should produce good results :-)
int shifts = 6;
if(ioctl(fileno(stdin), TIOCLINUX, &shifts) == -1)
shifts = 0;
if(shifts & ALT)
Expand Down Expand Up @@ -2247,7 +2241,7 @@ gkey kbxget_raw(int mode)
}
#endif

// TO_PORT_TAG: kbxget_raw(3)
// TO_PORT_TAG: kbxget_raw(KeyMode_Control)
#if defined(__WIN32__)
KeyCtrlState = (gkey)(inp.Event.KeyEvent.dwControlKeyState & 0xFFFF);
#endif
Expand All @@ -2258,7 +2252,7 @@ gkey kbxget_raw(int mode)
// ------------------------------------------------------------------
// Get key stroke

gkey kbxget(int mode)
gkey kbxget(eKeyModes mode)
{

return keyscanxlat(kbxget_raw(mode));
Expand All @@ -2271,7 +2265,7 @@ gkey kbxget(int mode)
gkey kbxhit()
{

return kbxget(0x01);
return kbxget(KeyMode_Test);
}


Expand All @@ -2298,7 +2292,7 @@ void clearkeys()
{

while(kbxhit())
kbxget(0x00);
kbxget(KeyMode_Wait);
}


Expand Down
17 changes: 16 additions & 1 deletion goldlib/gcui/gkbdbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@

typedef word gkey;

// Operation modes for reading keystrokes, using in the following functions
// kbxget, kbxget_raw and gkbd_cursgetch.
enum eKeyModes
{
// Waits for a pressed key and returns a code
KeyMode_Wait = 0,
// Returns a keystroke if available, otherwise 0
KeyMode_Test,
// Returns Shifts key status
KeyMode_Shift,
// Returns Control key status
KeyMode_Control
};


// ------------------------------------------------------------------
// Keycode object
Expand Down Expand Up @@ -134,14 +148,15 @@ extern bool right_alt_same_as_left;
// ------------------------------------------------------------------
// Function prototypes

gkey kbxget_raw(eKeyModes mode);
KBnd* chgonkey (KBnd* kblist);
void clearkeys ();
void freonkey ();
int setonkey (gkey keycode, VfvCP func, gkey pass);
gkey getxch (int __tick=false);
void kbclear ();
gkey kbmhit ();
gkey kbxget (int mode=0);
gkey kbxget (eKeyModes mode=KeyMode_Wait);
gkey kbxhit ();
int kbput (gkey xch);
word kbput_ (gkey xch);
Expand Down
2 changes: 1 addition & 1 deletion goldlib/gcui/gkbdgetm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ gkey getxch(int __tick)
{
gkbd.source = GEVT_KEYBOARD;
k = kbxget();
gkey s = kbxget(2); // Read shift status
gkey s = kbxget(KeyMode_Shift); // Read shift status
if(not gkbd.extkbd)
{
if(s & (LSHIFT|RSHIFT|GCTRL|ALT))
Expand Down

0 comments on commit 9082258

Please sign in to comment.