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:
344
sys/os2/os2.c
344
sys/os2/os2.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 os2.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 os2.c $NHDT-Date: 1431192782 2015/05/09 17:33:02 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
|
||||
/* NetHack 3.6 os2.c $Date: 2009/05/06 10:50:12 $ $Revision: 1.5 $ */
|
||||
/* SCCS Id: @(#)os2.c 3.5 1996/02/29 */
|
||||
/* Copyright (c) Timo Hakulinen, 1990, 1991, 1992, 1993, 1996. */
|
||||
@@ -38,24 +38,24 @@ static char NDECL(BIOSgetch);
|
||||
int
|
||||
tgetch()
|
||||
{
|
||||
char ch;
|
||||
char ch;
|
||||
|
||||
/* BIOSgetch can use the numeric key pad on IBM compatibles. */
|
||||
if (iflags.BIOS)
|
||||
ch = BIOSgetch();
|
||||
else
|
||||
ch = DOSgetch();
|
||||
return ((ch == '\r') ? '\n' : ch);
|
||||
/* BIOSgetch can use the numeric key pad on IBM compatibles. */
|
||||
if (iflags.BIOS)
|
||||
ch = BIOSgetch();
|
||||
else
|
||||
ch = DOSgetch();
|
||||
return ((ch == '\r') ? '\n' : ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* Keyboard translation tables.
|
||||
*/
|
||||
#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.
|
||||
@@ -63,36 +63,38 @@ tgetch()
|
||||
* shift values below.
|
||||
*/
|
||||
static const struct pad {
|
||||
char 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', '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', 'P', C('p')}, /* + */
|
||||
{'1', M('1'), '1'}, /* 1 */
|
||||
{'2', M('2'), '2'}, /* 2 */
|
||||
{'3', M('3'), '3'}, /* 3 */
|
||||
{'i', 'I', C('i')}, /* Ins */
|
||||
{'.', ':', ':'} /* Del */
|
||||
};
|
||||
char 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', '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', 'P', C('p') }, /* + */
|
||||
{ '1', M('1'), '1' }, /* 1 */
|
||||
{ '2', M('2'), '2' }, /* 2 */
|
||||
{ '3', M('3'), '3' }, /* 3 */
|
||||
{ 'i', 'I', C('i') }, /* Ins */
|
||||
{ '.', ':', ':' } /* Del */
|
||||
};
|
||||
|
||||
/*
|
||||
* Unlike Ctrl-letter, the Alt-letter keystrokes have no specific ASCII
|
||||
@@ -102,116 +104,119 @@ static const struct pad {
|
||||
* scan code table to translate the scan code into a letter, then set the
|
||||
* "meta" bit for it. -3.
|
||||
*/
|
||||
#define SCANLO 0x10
|
||||
#define SCANHI 0x32
|
||||
#define SCANKEYS (SCANHI - SCANLO + 1)
|
||||
#define inmap(x) (SCANLO <= (x) && (x) <= SCANHI)
|
||||
#define SCANLO 0x10
|
||||
#define SCANHI 0x32
|
||||
#define SCANKEYS (SCANHI - SCANLO + 1)
|
||||
#define inmap(x) (SCANLO <= (x) && (x) <= SCANHI)
|
||||
|
||||
static const char scanmap[SCANKEYS] = { /* ... */
|
||||
'q','w','e','r','t','y','u','i','o','p','[',']', '\n',
|
||||
0, 'a','s','d','f','g','h','j','k','l',';','\'', '`',
|
||||
0, '\\', 'z','x','c','v','b','N','m' /* ... */
|
||||
static const char scanmap[SCANKEYS] = {
|
||||
/* ... */
|
||||
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a',
|
||||
's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x',
|
||||
'c', 'v', 'b', 'N', 'm' /* ... */
|
||||
};
|
||||
|
||||
/*
|
||||
* BIOSgetch emulates the MSDOS way of getting keys directly with a BIOS call.
|
||||
*/
|
||||
#define SHIFT_KEY (0x1 | 0x2)
|
||||
#define CTRL_KEY 0x4
|
||||
#define ALT_KEY 0x8
|
||||
#define SHIFT_KEY (0x1 | 0x2)
|
||||
#define CTRL_KEY 0x4
|
||||
#define ALT_KEY 0x8
|
||||
|
||||
static char
|
||||
BIOSgetch()
|
||||
{
|
||||
unsigned char scan, shift, ch;
|
||||
const struct pad *kpad;
|
||||
unsigned char scan, shift, ch;
|
||||
const struct pad *kpad;
|
||||
|
||||
KBDKEYINFO CharData;
|
||||
USHORT IOWait = 0;
|
||||
HKBD KbdHandle = 0;
|
||||
KBDKEYINFO CharData;
|
||||
USHORT IOWait = 0;
|
||||
HKBD KbdHandle = 0;
|
||||
|
||||
KbdCharIn(&CharData,IOWait,KbdHandle);
|
||||
ch = CharData.chChar;
|
||||
scan = CharData.chScan;
|
||||
shift = CharData.fsState;
|
||||
KbdCharIn(&CharData, IOWait, KbdHandle);
|
||||
ch = CharData.chChar;
|
||||
scan = CharData.chScan;
|
||||
shift = CharData.fsState;
|
||||
|
||||
/* Translate keypad keys */
|
||||
if (iskeypad(scan)) {
|
||||
kpad = iflags.num_pad ? numpad : keypad;
|
||||
if (shift & SHIFT_KEY)
|
||||
ch = kpad[scan - KEYPADLO].shift;
|
||||
else if (shift & CTRL_KEY)
|
||||
ch = kpad[scan - KEYPADLO].cntrl;
|
||||
else
|
||||
ch = kpad[scan - KEYPADLO].normal;
|
||||
}
|
||||
/* Translate unassigned Alt-letters */
|
||||
if ((shift & ALT_KEY) && !ch) {
|
||||
if (inmap(scan))
|
||||
ch = scanmap[scan - SCANLO];
|
||||
return (isprint(ch) ? M(ch) : ch);
|
||||
}
|
||||
return ch;
|
||||
/* Translate keypad keys */
|
||||
if (iskeypad(scan)) {
|
||||
kpad = iflags.num_pad ? numpad : keypad;
|
||||
if (shift & SHIFT_KEY)
|
||||
ch = kpad[scan - KEYPADLO].shift;
|
||||
else if (shift & CTRL_KEY)
|
||||
ch = kpad[scan - KEYPADLO].cntrl;
|
||||
else
|
||||
ch = kpad[scan - KEYPADLO].normal;
|
||||
}
|
||||
/* Translate unassigned Alt-letters */
|
||||
if ((shift & ALT_KEY) && !ch) {
|
||||
if (inmap(scan))
|
||||
ch = scanmap[scan - SCANLO];
|
||||
return (isprint(ch) ? M(ch) : ch);
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
static char
|
||||
DOSgetch()
|
||||
{
|
||||
KBDKEYINFO CharData;
|
||||
USHORT IOWait = 0;
|
||||
HKBD KbdHandle = 0;
|
||||
KBDKEYINFO CharData;
|
||||
USHORT IOWait = 0;
|
||||
HKBD KbdHandle = 0;
|
||||
|
||||
KbdCharIn(&CharData,IOWait,KbdHandle);
|
||||
if (CharData.chChar == 0) { /* an extended code -- not yet supported */
|
||||
KbdCharIn(&CharData,IOWait,KbdHandle); /* eat the next character */
|
||||
CharData.chChar = 0; /* and return a 0 */
|
||||
}
|
||||
return (CharData.chChar);
|
||||
KbdCharIn(&CharData, IOWait, KbdHandle);
|
||||
if (CharData.chChar == 0) { /* an extended code -- not yet supported */
|
||||
KbdCharIn(&CharData, IOWait, KbdHandle); /* eat the next character */
|
||||
CharData.chChar = 0; /* and return a 0 */
|
||||
}
|
||||
return (CharData.chChar);
|
||||
}
|
||||
|
||||
char
|
||||
switchar()
|
||||
{
|
||||
return '/';
|
||||
return '/';
|
||||
}
|
||||
|
||||
int
|
||||
kbhit()
|
||||
{
|
||||
KBDKEYINFO CharData;
|
||||
HKBD KbdHandle = 0;
|
||||
KBDKEYINFO CharData;
|
||||
HKBD KbdHandle = 0;
|
||||
|
||||
KbdPeek(&CharData,KbdHandle);
|
||||
return (CharData.fbStatus & (1 << 6));
|
||||
KbdPeek(&CharData, KbdHandle);
|
||||
return (CharData.fbStatus & (1 << 6));
|
||||
}
|
||||
|
||||
long
|
||||
freediskspace(path)
|
||||
char *path;
|
||||
{
|
||||
FSALLOCATE FSInfoBuf;
|
||||
FSALLOCATE FSInfoBuf;
|
||||
#ifdef OS2_32BITAPI
|
||||
ULONG
|
||||
ULONG
|
||||
#else
|
||||
USHORT
|
||||
USHORT
|
||||
#endif
|
||||
DriveNumber, FSInfoLevel = 1, res;
|
||||
DriveNumber, FSInfoLevel = 1, res;
|
||||
|
||||
if (path[0] && path[1] == ':')
|
||||
DriveNumber = (toupper(path[0]) - 'A') + 1;
|
||||
else
|
||||
DriveNumber = 0;
|
||||
res =
|
||||
if (path[0] && path[1] == ':')
|
||||
DriveNumber = (toupper(path[0]) - 'A') + 1;
|
||||
else
|
||||
DriveNumber = 0;
|
||||
res =
|
||||
#ifdef OS2_32BITAPI
|
||||
DosQueryFSInfo(DriveNumber,FSInfoLevel,(PVOID)&FSInfoBuf,(ULONG)sizeof(FSInfoBuf));
|
||||
DosQueryFSInfo(DriveNumber, FSInfoLevel, (PVOID) &FSInfoBuf,
|
||||
(ULONG) sizeof(FSInfoBuf));
|
||||
#else
|
||||
DosQFSInfo(DriveNumber,FSInfoLevel,(PBYTE)&FSInfoBuf,(USHORT)sizeof(FSInfoBuf));
|
||||
DosQFSInfo(DriveNumber, FSInfoLevel, (PBYTE) &FSInfoBuf,
|
||||
(USHORT) sizeof(FSInfoBuf));
|
||||
#endif
|
||||
if (res)
|
||||
return -1L; /* error */
|
||||
else
|
||||
return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail *
|
||||
FSInfoBuf.cbSector);
|
||||
if (res)
|
||||
return -1L; /* error */
|
||||
else
|
||||
return ((long) FSInfoBuf.cSectorUnit * FSInfoBuf.cUnitAvail
|
||||
* FSInfoBuf.cbSector);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -230,55 +235,59 @@ findfirst(path)
|
||||
char *path;
|
||||
{
|
||||
#ifdef OS2_32BITAPI
|
||||
ULONG
|
||||
ULONG
|
||||
#else
|
||||
USHORT
|
||||
USHORT
|
||||
#endif
|
||||
res, SearchCount = 1;
|
||||
res, SearchCount = 1;
|
||||
|
||||
DirHandle = 1;
|
||||
res =
|
||||
DirHandle = 1;
|
||||
res =
|
||||
#ifdef OS2_32BITAPI
|
||||
DosFindFirst((PSZ)path,&DirHandle,0L,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount,1L);
|
||||
DosFindFirst((PSZ) path, &DirHandle, 0L, (PVOID) &ResultBuf,
|
||||
(ULONG) sizeof(ResultBuf), &SearchCount, 1L);
|
||||
#else
|
||||
DosFindFirst((PSZ)path,&DirHandle,0,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount,0L);
|
||||
DosFindFirst((PSZ) path, &DirHandle, 0, &ResultBuf,
|
||||
(USHORT) sizeof(ResultBuf), &SearchCount, 0L);
|
||||
#endif
|
||||
return(!res);
|
||||
return (!res);
|
||||
}
|
||||
|
||||
int
|
||||
findnext()
|
||||
{
|
||||
#ifdef OS2_32BITAPI
|
||||
ULONG
|
||||
ULONG
|
||||
#else
|
||||
USHORT
|
||||
USHORT
|
||||
#endif
|
||||
res, SearchCount = 1;
|
||||
res, SearchCount = 1;
|
||||
|
||||
res =
|
||||
res =
|
||||
#ifdef OS2_32BITAPI
|
||||
DosFindNext(DirHandle,(PVOID)&ResultBuf,(ULONG)sizeof(ResultBuf),&SearchCount);
|
||||
DosFindNext(DirHandle, (PVOID) &ResultBuf, (ULONG) sizeof(ResultBuf),
|
||||
&SearchCount);
|
||||
#else
|
||||
DosFindNext(DirHandle,&ResultBuf,(USHORT)sizeof(ResultBuf),&SearchCount);
|
||||
DosFindNext(DirHandle, &ResultBuf, (USHORT) sizeof(ResultBuf),
|
||||
&SearchCount);
|
||||
#endif
|
||||
return(!res);
|
||||
return (!res);
|
||||
}
|
||||
|
||||
char *
|
||||
foundfile_buffer()
|
||||
{
|
||||
return(ResultBuf.achName);
|
||||
return (ResultBuf.achName);
|
||||
}
|
||||
|
||||
long
|
||||
filesize(file)
|
||||
char *file;
|
||||
{
|
||||
if (findfirst(file)) {
|
||||
return (* (long *) (ResultBuf.cbFileAlloc));
|
||||
} else
|
||||
return -1L;
|
||||
if (findfirst(file)) {
|
||||
return (*(long *) (ResultBuf.cbFileAlloc));
|
||||
} else
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -288,77 +297,80 @@ void
|
||||
chdrive(str)
|
||||
char *str;
|
||||
{
|
||||
char *ptr;
|
||||
char drive;
|
||||
char *ptr;
|
||||
char drive;
|
||||
|
||||
if ((ptr = index(str, ':')) != (char *)0) {
|
||||
drive = toupper(*(ptr - 1));
|
||||
if ((ptr = index(str, ':')) != (char *) 0) {
|
||||
drive = toupper(*(ptr - 1));
|
||||
#ifdef OS2_32BITAPI
|
||||
DosSetDefaultDisk((ULONG)(drive - 'A' + 1));
|
||||
DosSetDefaultDisk((ULONG)(drive - 'A' + 1));
|
||||
#else
|
||||
DosSelectDisk((USHORT)(drive - 'A' + 1));
|
||||
DosSelectDisk((USHORT)(drive - 'A' + 1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
disable_ctrlP()
|
||||
{
|
||||
KBDINFO KbdInfo;
|
||||
HKBD KbdHandle = 0;
|
||||
KBDINFO KbdInfo;
|
||||
HKBD KbdHandle = 0;
|
||||
|
||||
if (!iflags.rawio) return;
|
||||
KbdInfo.cb = sizeof(KbdInfo);
|
||||
KbdGetStatus(&KbdInfo,KbdHandle);
|
||||
KbdInfo.fsMask &= 0xFFF7; /* ASCII off */
|
||||
KbdInfo.fsMask |= 0x0004; /* BINARY on */
|
||||
KbdSetStatus(&KbdInfo,KbdHandle);
|
||||
if (!iflags.rawio)
|
||||
return;
|
||||
KbdInfo.cb = sizeof(KbdInfo);
|
||||
KbdGetStatus(&KbdInfo, KbdHandle);
|
||||
KbdInfo.fsMask &= 0xFFF7; /* ASCII off */
|
||||
KbdInfo.fsMask |= 0x0004; /* BINARY on */
|
||||
KbdSetStatus(&KbdInfo, KbdHandle);
|
||||
}
|
||||
|
||||
void
|
||||
enable_ctrlP()
|
||||
{
|
||||
KBDINFO KbdInfo;
|
||||
HKBD KbdHandle = 0;
|
||||
KBDINFO KbdInfo;
|
||||
HKBD KbdHandle = 0;
|
||||
|
||||
if (!iflags.rawio) return;
|
||||
KbdInfo.cb = sizeof(KbdInfo);
|
||||
KbdGetStatus(&KbdInfo,KbdHandle);
|
||||
KbdInfo.fsMask &= 0xFFFB; /* BINARY off */
|
||||
KbdInfo.fsMask |= 0x0008; /* ASCII on */
|
||||
KbdSetStatus(&KbdInfo,KbdHandle);
|
||||
if (!iflags.rawio)
|
||||
return;
|
||||
KbdInfo.cb = sizeof(KbdInfo);
|
||||
KbdGetStatus(&KbdInfo, KbdHandle);
|
||||
KbdInfo.fsMask &= 0xFFFB; /* BINARY off */
|
||||
KbdInfo.fsMask |= 0x0008; /* ASCII on */
|
||||
KbdSetStatus(&KbdInfo, KbdHandle);
|
||||
}
|
||||
|
||||
void
|
||||
get_scr_size()
|
||||
{
|
||||
VIOMODEINFO ModeInfo;
|
||||
HVIO VideoHandle = 0;
|
||||
VIOMODEINFO ModeInfo;
|
||||
HVIO VideoHandle = 0;
|
||||
|
||||
ModeInfo.cb = sizeof(ModeInfo);
|
||||
ModeInfo.cb = sizeof(ModeInfo);
|
||||
|
||||
(void) VioGetMode(&ModeInfo,VideoHandle);
|
||||
(void) VioGetMode(&ModeInfo, VideoHandle);
|
||||
|
||||
CO = ModeInfo.col;
|
||||
LI = ModeInfo.row;
|
||||
CO = ModeInfo.col;
|
||||
LI = ModeInfo.row;
|
||||
}
|
||||
|
||||
void
|
||||
gotoxy(x,y)
|
||||
int x,y;
|
||||
gotoxy(x, y)
|
||||
int x, y;
|
||||
{
|
||||
HVIO VideoHandle = 0;
|
||||
HVIO VideoHandle = 0;
|
||||
|
||||
x--; y--; /* (0,0) is upper right corner */
|
||||
x--;
|
||||
y--; /* (0,0) is upper right corner */
|
||||
|
||||
(void) VioSetCurPos(x, y, VideoHandle);
|
||||
(void) VioSetCurPos(x, y, VideoHandle);
|
||||
}
|
||||
|
||||
|
||||
char* get_username(lan_username_size)
|
||||
char *
|
||||
get_username(lan_username_size)
|
||||
int *lan_username_size;
|
||||
{
|
||||
return (char*)0;
|
||||
return (char *) 0;
|
||||
}
|
||||
#ifdef X11_GRAPHICS
|
||||
int errno;
|
||||
|
||||
Reference in New Issue
Block a user