Windows startup modifications
Changes to be committed: modified: include/winprocs.h modified: src/options.c modified: sys/share/pcmain.c new file: sys/share/safeproc.c modified: sys/winnt/Makefile.msc modified: sys/winnt/stubs.c new file: sys/winnt/windmain.c modified: sys/winnt/winnt.c modified: win/win32/vs2017/NetHack.vcxproj modified: win/win32/vs2017/NetHackW.vcxproj modified: win/win32/winhack.c Because multiple window ports are supported on Windows now, even in the same executable and selectable via config file in some cases, some adjustments became necessary. There will likely be some further refining of this over the next day or two. List of changes: Move Windows startup from sys/share/pcmain.c and into its own sys/winnt/windmain.c so that it can be modified to fix some current breakage, and allow altering the order of some things. There is startup processing code that is common to all of the Windows WindowPorts, but that startup processing code needs to have no dependency on any one of those WindowPorts. Yet, during startup processing, some of the initialization routines can end up calling NetHack functions that expect an active Window port underneath, and if there isn't one, routines like pline, impossible, panic can end up invoking null function pointers. Place a new file sys/share/safeproc.c, in which a complete window port is available for early startup processing purposes. It's WindowPort name field is set to "safe-startup" just for reference. The prototypes in include/winprocs.h require that SAFEPROCS be Usage: windowprocs = get_safe_procs(0); initializes a set of winprocs function pointers that ensure none of the function pointers are left null, but that's all it does. windowprocs = get_safe_procs(1); initializes a set of winprocs functions pointers that ensure none of the function pointers are left null, but also provides some basic output and input functionality using nothing other than C stdio routines (no platform or OS specific code). The conditional code related to WIN32 has been removed from sys/share/pcmain.c The code common to all of the Windows WindowPorts calls get_safe_procs() almost immediately to ensure that there is a set of WindowPort winprocs available.
This commit is contained in:
@@ -3,11 +3,7 @@
|
||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
/* main.c - MSDOS, OS/2, ST, Amiga, and Windows NetHack */
|
||||
|
||||
#ifdef WIN32
|
||||
#include "win32api.h" /* for GetModuleFileName */
|
||||
#endif
|
||||
/* main.c - MSDOS, OS/2, ST, Amiga NetHack */
|
||||
|
||||
#include "hack.h"
|
||||
#include "dlb.h"
|
||||
@@ -47,29 +43,12 @@ void NDECL(preserve_icon);
|
||||
STATIC_DCL void FDECL(process_options, (int argc, char **argv));
|
||||
STATIC_DCL void NDECL(nhusage);
|
||||
|
||||
#if defined(MICRO) || defined(WIN32) || defined(OS2)
|
||||
#if defined(MICRO) || defined(OS2)
|
||||
extern void FDECL(nethack_exit, (int));
|
||||
#else
|
||||
#define nethack_exit exit
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
|
||||
extern int redirect_stdout; /* from sys/share/pcsys.c */
|
||||
extern int GUILaunched;
|
||||
char *NDECL(exename);
|
||||
char default_window_sys[] = "mswin";
|
||||
#ifndef WIN32CON
|
||||
HANDLE hStdOut;
|
||||
boolean NDECL(fakeconsole);
|
||||
void NDECL(freefakeconsole);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MSWIN_GRAPHICS)
|
||||
extern void NDECL(mswin_destroy_reg);
|
||||
#endif
|
||||
|
||||
#ifdef EXEPATH
|
||||
STATIC_DCL char *FDECL(exepath, (char *));
|
||||
#endif
|
||||
@@ -78,7 +57,7 @@ int FDECL(main, (int, char **));
|
||||
|
||||
extern boolean FDECL(pcmain, (int, char **));
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(_WIN32)
|
||||
#if defined(__BORLANDC__)
|
||||
void NDECL(startup);
|
||||
unsigned _stklen = STKSIZ;
|
||||
#endif
|
||||
@@ -98,21 +77,8 @@ char *argv[];
|
||||
{
|
||||
boolean resuming;
|
||||
|
||||
nethack_enter(argc, argv);
|
||||
|
||||
sys_early_init();
|
||||
#if defined(WIN32) && defined(TTY_GRAPHICS)
|
||||
Strcpy(default_window_sys, "tty");
|
||||
#else
|
||||
#if defined(CURSES_GRAPHICS)
|
||||
Strcpy(default_window_sys, "curses");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
resuming = pcmain(argc, argv);
|
||||
#ifdef LAN_FEATURES
|
||||
init_lan_features();
|
||||
#endif
|
||||
moveloop(resuming);
|
||||
nethack_exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
@@ -126,14 +92,10 @@ char *argv[];
|
||||
{
|
||||
register int fd;
|
||||
register char *dir;
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
#if defined(MSDOS)
|
||||
char *envp = NULL;
|
||||
char *sptr = NULL;
|
||||
#endif
|
||||
#if defined(WIN32)
|
||||
char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ];
|
||||
boolean save_getreturn_status = getreturn_enabled;
|
||||
#endif
|
||||
#ifdef NOCWD_ASSUMPTIONS
|
||||
char failbuf[BUFSZ];
|
||||
#endif
|
||||
@@ -162,7 +124,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(_WIN32)
|
||||
#if defined(__BORLANDC__)
|
||||
startup();
|
||||
#endif
|
||||
|
||||
@@ -175,15 +137,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
#endif
|
||||
hname = "NetHack"; /* used for syntax messages */
|
||||
|
||||
#ifndef WIN32
|
||||
choose_windows(DEFAULT_WINDOW_SYS);
|
||||
#else
|
||||
choose_windows(default_window_sys);
|
||||
if (argc >= 1
|
||||
&& !strcmpi(default_window_sys, "mswin")
|
||||
&& strstri(argv[0], "nethackw.exe"))
|
||||
iflags.windowtype_locked = TRUE;
|
||||
#endif
|
||||
|
||||
#if !defined(AMIGA) && !defined(GNUDOS)
|
||||
/* Save current directory and make sure it gets restored when
|
||||
@@ -243,7 +197,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++)
|
||||
fqn_prefix[prefcnt] = fqn_prefix[0];
|
||||
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
#if defined(MSDOS)
|
||||
/* sysconf should be searched for in this location */
|
||||
envp = nh_getenv("COMMONPROGRAMFILES");
|
||||
if (envp) {
|
||||
@@ -317,14 +271,6 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
chdirx(HACKDIR, 1);
|
||||
#endif
|
||||
ami_wininit_data();
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
save_getreturn_status = getreturn_enabled;
|
||||
#ifdef TTY_GRAPHICS
|
||||
raw_clear_screen();
|
||||
#endif
|
||||
getreturn_enabled = TRUE;
|
||||
check_recordfile((char *) 0);
|
||||
#endif
|
||||
initoptions();
|
||||
|
||||
@@ -355,13 +301,6 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
argv++;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (argcheck(argc, argv, ARG_WINDOWS) == 1) {
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argc > 1 && !strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') {
|
||||
/* avoid matching "-dec" for DECgraphics; since the man page
|
||||
* says -d directory, hope nobody's using -desomething_else
|
||||
@@ -381,36 +320,11 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
Strcpy(hackdir, dir);
|
||||
}
|
||||
if (argc > 1) {
|
||||
#if defined(WIN32) && !defined(WIN32CON)
|
||||
int sfd = 0;
|
||||
boolean tmpconsole = FALSE;
|
||||
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
#endif
|
||||
/*
|
||||
* Now we know the directory containing 'record' and
|
||||
* may do a prscore().
|
||||
*/
|
||||
if (!strncmp(argv[1], "-s", 2)) {
|
||||
#if defined(WIN32) && !defined(WIN32CON)
|
||||
|
||||
#if 0
|
||||
if (!hStdOut) {
|
||||
tmpconsole = fakeconsole();
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Check to see if we're redirecting to a file.
|
||||
*/
|
||||
sfd = (int) _fileno(stdout);
|
||||
redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0;
|
||||
|
||||
if (!redirect_stdout && !hStdOut) {
|
||||
raw_printf(
|
||||
"-s is not supported for the Graphical Interface\n");
|
||||
nethack_exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
|
||||
chdirx(hackdir, 0);
|
||||
#endif
|
||||
@@ -418,47 +332,16 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
initoptions();
|
||||
#endif
|
||||
prscore(argc, argv);
|
||||
#if defined(WIN32) && !defined(WIN32CON)
|
||||
if (tmpconsole) {
|
||||
getreturn("to exit");
|
||||
freefakeconsole();
|
||||
tmpconsole = FALSE;
|
||||
}
|
||||
#endif
|
||||
nethack_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef MSWIN_GRAPHICS
|
||||
if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */
|
||||
mswin_destroy_reg();
|
||||
nethack_exit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
/* Don't initialize the window system just to print usage */
|
||||
if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) {
|
||||
#if 0
|
||||
if (!hStdOut) {
|
||||
GUILaunched = 0;
|
||||
tmpconsole = fakeconsole();
|
||||
}
|
||||
#endif
|
||||
nhusage();
|
||||
|
||||
#if defined(WIN32) && !defined(WIN32CON)
|
||||
if (tmpconsole) {
|
||||
getreturn("to exit");
|
||||
freefakeconsole();
|
||||
tmpconsole = FALSE;
|
||||
}
|
||||
#endif
|
||||
nethack_exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
getreturn_enabled = save_getreturn_status;
|
||||
#endif
|
||||
/*
|
||||
* It seems you really want to play.
|
||||
*/
|
||||
@@ -472,11 +355,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
"\"%s\".%s",
|
||||
copyright_banner_line(1), copyright_banner_line(2),
|
||||
copyright_banner_line(3), copyright_banner_line(4), DLBFILE,
|
||||
#ifdef WIN32
|
||||
"\nAre you perhaps trying to run NetHack within a zip utility?");
|
||||
#else
|
||||
"");
|
||||
#endif
|
||||
error("dlb_init failure.");
|
||||
}
|
||||
|
||||
@@ -490,41 +369,22 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
chdirx(hackdir, 1);
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#if defined(MSDOS)
|
||||
/* In 3.6.0, several ports process options before they init
|
||||
* the window port. This allows settings that impact window
|
||||
* ports to be specified or read from the sys or user config files.
|
||||
*/
|
||||
process_options(argc, argv);
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
if (WINDOWPORT("mswin"))
|
||||
NHWinMainInit();
|
||||
else
|
||||
*/
|
||||
#ifdef TTY_GRAPHICS
|
||||
if (WINDOWPORT("tty")) {
|
||||
iflags.use_background_glyph = FALSE;
|
||||
nttty_open(1);
|
||||
} else {
|
||||
iflags.use_background_glyph = TRUE;
|
||||
}
|
||||
#endif /* TTY_GRAPHICS */
|
||||
#endif /* WIN32 */
|
||||
#endif /* MSDOS || WIN32 */
|
||||
#endif /* MSDOS */
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#if defined(MSDOS)
|
||||
init_nhwindows(&argc, argv);
|
||||
#else
|
||||
init_nhwindows(&argc, argv);
|
||||
process_options(argc, argv);
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && defined(TTY_GRAPHICS)
|
||||
toggle_mouse_support(); /* must come after process_options */
|
||||
#endif
|
||||
|
||||
#ifdef MFLOPPY
|
||||
set_lock_and_bones();
|
||||
#ifndef AMIGA
|
||||
@@ -561,19 +421,8 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
* overwritten without confirmation when a user starts up
|
||||
* another game with the same player name.
|
||||
*/
|
||||
#if defined(WIN32)
|
||||
/* Obtain the name of the logged on user and incorporate
|
||||
* it into the name. */
|
||||
Sprintf(fnamebuf, "%s-%s", get_username(0), plname);
|
||||
(void) fname_encode(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
|
||||
fnamebuf, encodedfnamebuf, BUFSZ);
|
||||
Sprintf(lock, "%s", encodedfnamebuf);
|
||||
/* regularize(lock); */ /* we encode now, rather than substitute */
|
||||
#else
|
||||
Strcpy(lock, plname);
|
||||
regularize(lock);
|
||||
#endif
|
||||
getlock();
|
||||
#else /* What follows is !PC_LOCKING */
|
||||
#ifdef AMIGA /* We'll put the bones & levels in the user specified directory \
|
||||
@@ -599,11 +448,7 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
if (fd < 0) {
|
||||
raw_print("Cannot create lock file");
|
||||
} else {
|
||||
#ifdef WIN32
|
||||
hackpid = GetCurrentProcessId();
|
||||
#else
|
||||
hackpid = 1;
|
||||
#endif
|
||||
write(fd, (genericptr_t) &hackpid, sizeof(hackpid));
|
||||
nhclose(fd);
|
||||
}
|
||||
@@ -618,10 +463,6 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
|
||||
vision_init();
|
||||
|
||||
display_gamewindows();
|
||||
#ifdef WIN32
|
||||
getreturn_enabled = TRUE;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* First, try to find and restore a save file for specified character.
|
||||
* We'll return here if new game player_selection() renames the hero.
|
||||
@@ -799,18 +640,6 @@ char *argv[];
|
||||
case 'l':
|
||||
bigscreen = -1;
|
||||
break;
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case 'w': /* windowtype */
|
||||
#ifdef TTY_GRAPHICS
|
||||
if (strncmpi(&argv[0][2], "tty", 3)) {
|
||||
nttty_open(1);
|
||||
}
|
||||
#endif
|
||||
config_error_init(FALSE, "command line", FALSE);
|
||||
choose_windows(&argv[0][2]);
|
||||
config_error_done();
|
||||
break;
|
||||
#endif
|
||||
case '@':
|
||||
flags.randomall = 1;
|
||||
@@ -904,14 +733,14 @@ boolean wr;
|
||||
#endif /* CHDIR */
|
||||
|
||||
#ifdef PORT_HELP
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#if defined(MSDOS)
|
||||
void
|
||||
port_help()
|
||||
{
|
||||
/* display port specific help file */
|
||||
display_file(PORT_HELP, 1);
|
||||
}
|
||||
#endif /* MSDOS || WIN32 */
|
||||
#endif /* MSDOS */
|
||||
#endif /* PORT_HELP */
|
||||
|
||||
/* validate wizard mode if player has requested access to it */
|
||||
@@ -930,71 +759,6 @@ authorize_wizard_mode()
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(WIN32CON)
|
||||
static char exenamebuf[PATHLEN];
|
||||
extern HANDLE hConIn;
|
||||
extern HANDLE hConOut;
|
||||
boolean has_fakeconsole;
|
||||
|
||||
char *
|
||||
exename()
|
||||
{
|
||||
int bsize = PATHLEN;
|
||||
char *tmp = exenamebuf, *tmp2;
|
||||
|
||||
#ifdef UNICODE
|
||||
{
|
||||
TCHAR wbuf[PATHLEN * 4];
|
||||
GetModuleFileName((HANDLE) 0, wbuf, PATHLEN * 4);
|
||||
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, tmp, bsize, NULL, NULL);
|
||||
}
|
||||
#else
|
||||
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
|
||||
#endif
|
||||
tmp2 = strrchr(tmp, PATH_SEPARATOR);
|
||||
if (tmp2)
|
||||
*tmp2 = '\0';
|
||||
tmp2++;
|
||||
return tmp2;
|
||||
}
|
||||
|
||||
boolean
|
||||
fakeconsole(void)
|
||||
{
|
||||
if (!hStdOut) {
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
if (!hStdOut && !hStdIn) {
|
||||
/* Bool rval; */
|
||||
AllocConsole();
|
||||
AttachConsole(GetCurrentProcessId());
|
||||
/* rval = SetStdHandle(STD_OUTPUT_HANDLE, hWrite); */
|
||||
freopen("CON", "w", stdout);
|
||||
freopen("CON", "r", stdin);
|
||||
}
|
||||
has_fakeconsole = TRUE;
|
||||
}
|
||||
|
||||
/* Obtain handles for the standard Console I/O devices */
|
||||
hConIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
#if 0
|
||||
if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
|
||||
/* Unable to set control handler */
|
||||
cmode = 0; /* just to have a statement to break on for debugger */
|
||||
}
|
||||
#endif
|
||||
return has_fakeconsole;
|
||||
}
|
||||
void freefakeconsole()
|
||||
{
|
||||
if (has_fakeconsole) {
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define EXEPATHBUFSZ 256
|
||||
char exepathbuf[EXEPATHBUFSZ];
|
||||
|
||||
@@ -1009,19 +773,7 @@ char *str;
|
||||
return (char *) 0;
|
||||
bsize = EXEPATHBUFSZ;
|
||||
tmp = exepathbuf;
|
||||
#ifndef WIN32
|
||||
Strcpy(tmp, str);
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
{
|
||||
TCHAR wbuf[BUFSZ];
|
||||
GetModuleFileName((HANDLE) 0, wbuf, BUFSZ);
|
||||
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, tmp, bsize, NULL, NULL);
|
||||
}
|
||||
#else
|
||||
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
|
||||
#endif
|
||||
#endif
|
||||
tmp2 = strrchr(tmp, PATH_SEPARATOR);
|
||||
if (tmp2)
|
||||
*tmp2 = '\0';
|
||||
|
||||
550
sys/share/safeproc.c
Normal file
550
sys/share/safeproc.c
Normal file
@@ -0,0 +1,550 @@
|
||||
/* NetHack 3.6 safeproc.c */
|
||||
/* Copyright (c) Michael Allison, 2018 */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
#include "hack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* ***********************************************************
|
||||
* This is a complete WindowPort implementation that can be
|
||||
* assigned to the windowproc function pointers very early
|
||||
* in the startup initialization, perhaps immediately even.
|
||||
* It requires only the following call:
|
||||
* windowprocs = get_safe_procs(0);
|
||||
*
|
||||
* The game startup can trigger functions in other modules
|
||||
* that make assumptions on a WindowPort being available
|
||||
* and bad things can happen if any function pointers are
|
||||
* null at that time.
|
||||
*
|
||||
* Some ports prior to 3.6.2 made attempts to early init
|
||||
* various pieces of one of their WindowPorts, but that
|
||||
* caused conflicts if that particular WindowPort wasn't
|
||||
* the one that the user ended up selecting in their
|
||||
* config file later. The WindowPort interfaced was designed
|
||||
* to allow multiple WindowPorts to be linked into the same
|
||||
* game binary.
|
||||
*
|
||||
* The base functions established by a call to get_safe_procs()
|
||||
* accomplish the goal of preventing crashes, but not much
|
||||
* else.
|
||||
*
|
||||
* There are also a few additional functions provided in here
|
||||
* that can be selected optionally to provide some startup
|
||||
* functionality for getting messages out to the user about
|
||||
* issues that are being experienced during startup in
|
||||
* general or during options parsing. The ones in here are
|
||||
* deliberately free from any platforms or OS specific code.
|
||||
* Please leave them using stdio C routines as much as
|
||||
* possible. That isn't to say you can't do fancier functions
|
||||
* prior to initialization of the primary WindowPort, but you
|
||||
* can provide those platform-specific functions elsewhere,
|
||||
* and assign them the same way that these more generic versions
|
||||
* are assigned.
|
||||
*
|
||||
* The additional platform-independent, but more functional
|
||||
* routines provided in here should be assigned after the
|
||||
* windowprocs = get_safe_procs()
|
||||
* call. Here's a list of them:
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* ***********************************************************
|
||||
*/
|
||||
|
||||
struct window_procs safe_procs = {
|
||||
"safe-startup", 0L, 0L,
|
||||
safe_init_nhwindows, safe_player_selection, safe_askname, safe_get_nh_event,
|
||||
safe_exit_nhwindows, safe_suspend_nhwindows, safe_resume_nhwindows,
|
||||
safe_create_nhwindow, safe_clear_nhwindow, safe_display_nhwindow,
|
||||
safe_destroy_nhwindow, safe_curs, safe_putstr, genl_putmixed,
|
||||
safe_display_file, safe_start_menu, safe_add_menu, safe_end_menu,
|
||||
safe_select_menu, safe_message_menu, safe_update_inventory, safe_mark_synch,
|
||||
safe_wait_synch,
|
||||
#ifdef CLIPPING
|
||||
safe_cliparound,
|
||||
#endif
|
||||
#ifdef POSITIONBAR
|
||||
safe_update_positionbar,
|
||||
#endif
|
||||
safe_print_glyph, safe_raw_print, safe_raw_print_bold, safe_nhgetch,
|
||||
safe_nh_poskey, safe_nhbell, safe_doprev_message, safe_yn_function,
|
||||
safe_getlin, safe_get_ext_cmd, safe_number_pad, safe_delay_output,
|
||||
#ifdef CHANGE_COLOR /* the Mac uses a palette device */
|
||||
safe_change_color,
|
||||
#ifdef MAC
|
||||
safe_change_background, set_safe_font_name,
|
||||
#endif
|
||||
safe_get_color_string,
|
||||
#endif
|
||||
safe_start_screen, safe_end_screen, genl_outrip,
|
||||
safe_preference_update,
|
||||
safe_getmsghistory, safe_putmsghistory,
|
||||
safe_status_init,
|
||||
safe_status_finish, safe_status_enablefield,
|
||||
#ifdef STATUS_HILITES
|
||||
safe_status_update,
|
||||
#else
|
||||
safe_status_update,
|
||||
#endif
|
||||
safe_can_suspend,
|
||||
};
|
||||
|
||||
struct window_procs *
|
||||
get_safe_procs(optn)
|
||||
int optn;
|
||||
{
|
||||
if (optn) {
|
||||
/* include the slightly more functional stdc versions */
|
||||
safe_procs.win_raw_print = stdio_raw_print;
|
||||
safe_procs.win_raw_print_bold = stdio_raw_print_bold;
|
||||
safe_procs.win_nhgetch = stdio_nhgetch;
|
||||
safe_procs.win_wait_synch = stdio_wait_synch;
|
||||
}
|
||||
return &safe_procs;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
safe_init_nhwindows(argcp, argv)
|
||||
int *argcp UNUSED;
|
||||
char **argv UNUSED;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_player_selection()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_askname()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_get_nh_event()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_suspend_nhwindows(str)
|
||||
const char *str;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_resume_nhwindows()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_exit_nhwindows(str)
|
||||
const char *str;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
winid
|
||||
safe_create_nhwindow(type)
|
||||
int type;
|
||||
{
|
||||
return WIN_ERR;
|
||||
}
|
||||
|
||||
void
|
||||
safe_clear_nhwindow(window)
|
||||
winid window;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
safe_display_nhwindow(window, blocking)
|
||||
winid window;
|
||||
boolean blocking;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_dismiss_nhwindow(window)
|
||||
winid window;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_destroy_nhwindow(window)
|
||||
winid window;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_curs(window, x, y)
|
||||
winid window;
|
||||
int x, y;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_putstr(window, attr, str)
|
||||
winid window;
|
||||
int attr;
|
||||
const char *str;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_display_file(fname, complain)
|
||||
const char *fname;
|
||||
boolean complain;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_start_menu(window)
|
||||
winid window;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
/*
|
||||
* Add a menu item to the beginning of the menu list. This list is reversed
|
||||
* later.
|
||||
*/
|
||||
void
|
||||
safe_add_menu(window, glyph, identifier, ch, gch, attr, str, preselected)
|
||||
winid window; /* window to use, must be of type NHW_MENU */
|
||||
int glyph UNUSED; /* glyph to display with item (not used) */
|
||||
const anything *identifier; /* what to return if selected */
|
||||
char ch; /* keyboard accelerator (0 = pick our own) */
|
||||
char gch; /* group accelerator (0 = no group) */
|
||||
int attr; /* attribute for string (like safe_putstr()) */
|
||||
const char *str; /* menu string */
|
||||
boolean preselected; /* item is marked as selected */
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* End a menu in this window, window must a type NHW_MENU.
|
||||
*/
|
||||
void
|
||||
safe_end_menu(window, prompt)
|
||||
winid window; /* menu to use */
|
||||
const char *prompt; /* prompt to for menu */
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
safe_select_menu(window, how, menu_list)
|
||||
winid window;
|
||||
int how;
|
||||
menu_item **menu_list;
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* special hack for treating top line --More-- as a one item menu */
|
||||
char
|
||||
safe_message_menu(let, how, mesg)
|
||||
char let;
|
||||
int how;
|
||||
const char *mesg;
|
||||
{
|
||||
return '\033';
|
||||
}
|
||||
|
||||
void
|
||||
safe_update_inventory()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_mark_synch()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
safe_wait_synch()
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef CLIPPING
|
||||
void
|
||||
safe_cliparound(x, y)
|
||||
int x, y;
|
||||
{
|
||||
}
|
||||
#endif /* CLIPPING */
|
||||
|
||||
/*
|
||||
* safe_print_glyph
|
||||
*
|
||||
* Print the glyph to the output device. Don't flush the output device.
|
||||
*/
|
||||
void
|
||||
safe_print_glyph(window, x, y, glyph, bkglyph)
|
||||
winid window;
|
||||
xchar x, y;
|
||||
int glyph;
|
||||
int bkglyph UNUSED;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_raw_print(str)
|
||||
const char *str;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_raw_print_bold(str)
|
||||
const char *str;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
safe_nhgetch()
|
||||
{
|
||||
return '\033';
|
||||
}
|
||||
|
||||
/*
|
||||
* return a key, or 0, in which case a mouse button was pressed
|
||||
* mouse events should be returned as character postitions in the map window.
|
||||
* Since normal tty's don't have mice, just return a key.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
safe_nh_poskey(x, y, mod)
|
||||
int *x, *y, *mod;
|
||||
{
|
||||
return '\033';
|
||||
}
|
||||
|
||||
void
|
||||
win_safe_init(dir)
|
||||
int dir;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef POSITIONBAR
|
||||
void
|
||||
safe_update_positionbar(posbar)
|
||||
char *posbar;
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif /* POSITIONBAR */
|
||||
|
||||
/*
|
||||
* safe_status_init()
|
||||
* -- initialize the port-specific data structures.
|
||||
*/
|
||||
void
|
||||
safe_status_init()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_can_suspend()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_nhbell()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
safe_doprev_message()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char
|
||||
safe_yn_function(query, resp, def)
|
||||
const char *query;
|
||||
const char *resp;
|
||||
char def;
|
||||
{
|
||||
return '\033';
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
safe_getlin(prompt, outbuf)
|
||||
const char *prompt UNUSED;
|
||||
char *outbuf;
|
||||
{
|
||||
Strcpy(outbuf, "\033");
|
||||
}
|
||||
|
||||
int
|
||||
safe_get_ext_cmd()
|
||||
{
|
||||
return '\033';
|
||||
}
|
||||
|
||||
void
|
||||
safe_number_pad(mode)
|
||||
int mode;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_delay_output()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_start_screen()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_end_screen()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
safe_outrip(tmpwin, how, when)
|
||||
winid tmpwin;
|
||||
int how;
|
||||
time_t when;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
safe_preference_update(pref)
|
||||
const char *pref UNUSED;
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char *
|
||||
safe_getmsghistory(init)
|
||||
boolean init UNUSED;
|
||||
{
|
||||
return (char *) 0;
|
||||
}
|
||||
|
||||
void
|
||||
safe_putmsghistory(msg, is_restoring)
|
||||
const char *msg;
|
||||
boolean is_restoring;
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
safe_status_finish()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
safe_status_enablefield(fieldidx, nm, fmt, enable)
|
||||
int fieldidx;
|
||||
const char *nm;
|
||||
const char *fmt;
|
||||
boolean enable;
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef STATUS_HILITES
|
||||
/* call once for each field, then call with BL_FLUSH to output the result */
|
||||
void
|
||||
safe_status_update(idx, ptr, chg, percent, color, colormasks)
|
||||
int idx;
|
||||
genericptr_t ptr;
|
||||
int chg UNUSED, percent UNUSED, color UNUSED;
|
||||
unsigned long *colormasks UNUSED;
|
||||
{
|
||||
}
|
||||
#endif /* STATUS_HILITES */
|
||||
|
||||
/**************************************************************
|
||||
* These are some optionally selectable routines that add
|
||||
* some base functionality over the safe_* versions above.
|
||||
* The safe_* versions are primarily designed to ensure that
|
||||
* there are no null function pointers remaining at early
|
||||
* game startup/initialization time.
|
||||
*
|
||||
* The slightly more functional versions in here should be kept
|
||||
* free of platform-specific code or OS-specific code. If you
|
||||
* want to use versions that involve platform-specific or
|
||||
* OS-specific code, go right ahead but use your own replacement
|
||||
* version of the functions in a platform-specific or
|
||||
* OS-specific source file, not in here.
|
||||
***************************************************************/
|
||||
|
||||
/* Add to your code: windowprocs.win_raw_print = stdio_wait_synch; */
|
||||
void
|
||||
stdio_wait_synch()
|
||||
{
|
||||
char valid[] = {' ', '\n', '\r', '\033', '\0'};
|
||||
|
||||
fprintf(stdout, "--More--");
|
||||
(void) fflush(stdout);
|
||||
while (!index(valid, stdio_nhgetch()))
|
||||
;
|
||||
}
|
||||
|
||||
/* Add to your code: windowprocs.win_raw_print = stdio_raw_print; */
|
||||
void
|
||||
stdio_raw_print(str)
|
||||
const char *str;
|
||||
{
|
||||
if (str)
|
||||
fprintf(stdout, "%s\n", str);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add to your code: windowprocs.win_raw_print_bold = stdio_raw_print_bold; */
|
||||
void
|
||||
stdio_raw_print_bold(str)
|
||||
const char *str;
|
||||
{
|
||||
stdio_raw_print(str);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Add to your code: windowprocs.win_nhgetch = stdio_nhgetch; */
|
||||
int
|
||||
stdio_nhgetch()
|
||||
{
|
||||
return getchar();
|
||||
}
|
||||
|
||||
|
||||
/* safeprocs.c */
|
||||
Reference in New Issue
Block a user