Skip to content

Commit

Permalink
Clean up some WIN32 code.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Sep 3, 2018
1 parent ba7c842 commit cb1ced4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile.wng
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MINGW_DEFINES = -DMINGW -DWIN32 -D_CONSOLE -DNDEBUG
# (there are assignments of pointer variables to int variables)
# and so we must force a 32-bit build.
#
CFLAGS_MINGW = -m32 ${MINGW_DEFINES}
CFLAGS_MINGW = ${MINGW_DEFINES}

# MingW may use sh.exe instead of cmd.exe.
# Make sure it does not.
Expand Down
4 changes: 0 additions & 4 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,6 @@ readfd(fd)

#if HAVE_POPEN

#if MSDOS_COMPILER!=WIN32C
FILE *popen();
#endif

/*
* Execute a shell command.
* Return a pointer to a pipe connected to the shell command's standard output.
Expand Down
1 change: 0 additions & 1 deletion lsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ pipe_data(cmd, spos, epos)
{
FILE *f;
int c;
extern FILE *popen();

/*
* This is structured much like lsystem().
Expand Down
2 changes: 1 addition & 1 deletion pattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ compile_pattern2(pattern, search_type, comp_pattern, show_error)
if (show_error)
{
char msg[160];
pcre2_get_error_message(errcode, msg, sizeof(msg));
pcre2_get_error_message(errcode, (PCRE2_UCHAR*)msg, sizeof(msg));
parg.p_string = msg;
error("%s", &parg);
}
Expand Down
15 changes: 8 additions & 7 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ struct keyRecord
static int keyCount = 0;
static WORD curr_attr;
static int pending_scancode = 0;
static WORD *whitescreen;

static HANDLE con_out_save = INVALID_HANDLE_VALUE; /* previous console */
static HANDLE con_out_ours = INVALID_HANDLE_VALUE; /* our own */
Expand Down Expand Up @@ -233,13 +232,17 @@ extern int no_keypad;
extern int sigs;
extern int wscroll;
extern int screen_trashed;
extern int tty;
extern int top_scroll;
extern int quit_if_one_screen;
extern int oldbot;
#if HILITE_SEARCH
extern int hilite_search;
#endif
#if MSDOS_COMPILER==WIN32C
extern HANDLE tty;
#else
extern int tty;
#endif

extern char *tgetstr();
extern char *tgoto();
Expand Down Expand Up @@ -2384,8 +2387,7 @@ putbs()
* Determine whether an input character is waiting to be read.
*/
static int
win32_kbhit(tty)
HANDLE tty;
win32_kbhit()
{
INPUT_RECORD ip;
DWORD read;
Expand Down Expand Up @@ -2458,8 +2460,7 @@ win32_kbhit(tty)
* Read a character from the keyboard.
*/
public char
WIN32getch(tty)
int tty;
WIN32getch()
{
int ascii;

Expand All @@ -2469,7 +2470,7 @@ WIN32getch(tty)
return ((char)(currentKey.scan & 0x00FF));
}

while (win32_kbhit((HANDLE)tty) == FALSE)
while (win32_kbhit() == FALSE)
{
Sleep(20);
if (ABORT_SIGS())
Expand Down
18 changes: 9 additions & 9 deletions ttyin.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#endif
#if MSDOS_COMPILER==WIN32C
#include "windows.h"
extern char WIN32getch();
static DWORD console_mode;
#endif

public HANDLE tty;
#else
public int tty;
#endif
extern int sigs;
extern int utf_mode;

Expand All @@ -32,12 +32,12 @@ open_getchr()
memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
tty = (int) CreateFile("CONIN$", GENERIC_READ,
tty = CreateFile("CONIN$", GENERIC_READ,
FILE_SHARE_READ, &sa,
OPEN_EXISTING, 0L, NULL);
GetConsoleMode((HANDLE)tty, &console_mode);
GetConsoleMode(tty, &console_mode);
/* Make sure we get Ctrl+C events. */
SetConsoleMode((HANDLE)tty, ENABLE_PROCESSED_INPUT);
SetConsoleMode(tty, ENABLE_PROCESSED_INPUT);
#else
#if MSDOS_COMPILER
extern int fd0;
Expand Down Expand Up @@ -81,8 +81,8 @@ open_getchr()
close_getchr()
{
#if MSDOS_COMPILER==WIN32C
SetConsoleMode((HANDLE)tty, console_mode);
CloseHandle((HANDLE)tty);
SetConsoleMode(tty, console_mode);
CloseHandle(tty);
#endif
}

Expand All @@ -105,7 +105,7 @@ getchr()
#if MSDOS_COMPILER==WIN32C
if (ABORT_SIGS())
return (READ_INTR);
c = WIN32getch(tty);
c = WIN32getch();
#else
c = getch();
#endif
Expand Down
3 changes: 2 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ v535 8/16/18 Don't count lines of initial screen if using -X with -F
(thanks to Linus Torvalds).
v536 8/31/18 Use descriptive error messages for PCRE2.
v537 8/31/18 Support mingw build system (thanks to Mike Soyka).
v538 9/3/18 Clean up some WIN32 code.
*/

char version[] = "537";
char version[] = "538";

0 comments on commit cb1ced4

Please sign in to comment.