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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 ioctl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 ioctl.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */
/* NetHack 3.6 ioctl.c $Date: 2011/06/16 15:10:14 $ $Revision: 1.8 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,63 +10,65 @@
#include "hack.h"
#if defined(BSD_JOB_CONTROL) || defined(_BULL_SOURCE)
# ifdef HPUX
#ifdef HPUX
#include <bsdtty.h>
# else
# if defined(AIX_31) && !defined(_ALL_SOURCE)
# define _ALL_SOURCE /* causes struct winsize to be present */
# ifdef _AIX32
# include <sys/ioctl.h>
# endif
# endif
# if defined(_BULL_SOURCE)
# include <termios.h>
#else
#if defined(AIX_31) && !defined(_ALL_SOURCE)
#define _ALL_SOURCE /* causes struct winsize to be present */
#ifdef _AIX32
#include <sys/ioctl.h>
#endif
#endif
#if defined(_BULL_SOURCE)
#include <termios.h>
struct termios termio;
# undef TIMEOUT /* defined in you.h and sys/tty.h */
# include <sys/tty.h> /* define winsize */
# include <sys/ttold.h> /* define struct ltchars */
# include <sys/bsdioctl.h> /* define TIOGWINSZ */
# else
# ifdef LINUX
# include <bsd/sgtty.h>
# else
# include <sgtty.h>
# endif
# endif
# endif
#undef TIMEOUT /* defined in you.h and sys/tty.h */
#include <sys/tty.h> /* define winsize */
#include <sys/ttold.h> /* define struct ltchars */
#include <sys/bsdioctl.h> /* define TIOGWINSZ */
#else
#ifdef LINUX
#include <bsd/sgtty.h>
#else
#include <sgtty.h>
#endif
#endif
#endif
struct ltchars ltchars;
struct ltchars ltchars0 = { -1, -1, -1, -1, -1, -1 }; /* turn all off */
#else
# ifdef POSIX_TYPES
#ifdef POSIX_TYPES
#include <termios.h>
struct termios termio;
# if defined(BSD) || defined(_AIX32) || defined(__linux__)
# if defined(_AIX32) && !defined(_ALL_SOURCE)
# define _ALL_SOURCE
# endif
#if defined(BSD) || defined(_AIX32) || defined(__linux__)
#if defined(_AIX32) && !defined(_ALL_SOURCE)
#define _ALL_SOURCE
#endif
#include <sys/ioctl.h>
# endif
# else
#include <termio.h> /* also includes part of <sgtty.h> */
# if defined(TCSETS) && !defined(AIX_31)
#endif
#else
#include <termio.h> /* also includes part of <sgtty.h> */
#if defined(TCSETS) && !defined(AIX_31)
struct termios termio;
# else
#else
struct termio termio;
# endif
# endif
# if defined(AMIX) || defined(__APPLE__)
#endif
#endif
#if defined(AMIX) || defined(__APPLE__)
#include <sys/ioctl.h>
# endif /* AMIX */
#endif /* AMIX */
#endif
#ifdef SUSPEND /* BSD isn't alone anymore... */
#include <signal.h>
#ifdef SUSPEND /* BSD isn't alone anymore... */
#include <signal.h>
#endif
#if defined(TIOCGWINSZ) && (defined(BSD) || defined(ULTRIX) || defined(AIX_31) || defined(_BULL_SOURCE) || defined(SVR4))
#if defined(TIOCGWINSZ) \
&& (defined(BSD) || defined(ULTRIX) || defined(AIX_31) \
|| defined(_BULL_SOURCE) || defined(SVR4))
#define USE_WIN_IOCTL
#include "tcap.h" /* for LI and CO */
#include "tcap.h" /* for LI and CO */
#endif
#ifdef _M_UNIX
@@ -97,15 +99,15 @@ getwindowsz()
*/
struct winsize ttsz;
if (ioctl(fileno(stdin), (int)TIOCGWINSZ, (char *)&ttsz) != -1) {
/*
* Use the kernel's values for lines and columns if it has
* any idea.
*/
if (ttsz.ws_row)
LI = ttsz.ws_row;
if (ttsz.ws_col)
CO = ttsz.ws_col;
if (ioctl(fileno(stdin), (int) TIOCGWINSZ, (char *) &ttsz) != -1) {
/*
* Use the kernel's values for lines and columns if it has
* any idea.
*/
if (ttsz.ws_row)
LI = ttsz.ws_row;
if (ttsz.ws_col)
CO = ttsz.ws_col;
}
#endif
}
@@ -114,22 +116,22 @@ void
getioctls()
{
#ifdef BSD_JOB_CONTROL
(void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) &ltchars);
(void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars0);
(void) ioctl(fileno(stdin), (int) TIOCGLTC, (char *) &ltchars);
(void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars0);
#else
# ifdef POSIX_TYPES
(void) tcgetattr(fileno(stdin), &termio);
# else
# if defined(TCSETS) && !defined(AIX_31)
(void) ioctl(fileno(stdin), (int) TCGETS, &termio);
# else
(void) ioctl(fileno(stdin), (int) TCGETA, &termio);
# endif
# endif
#ifdef POSIX_TYPES
(void) tcgetattr(fileno(stdin), &termio);
#else
#if defined(TCSETS) && !defined(AIX_31)
(void) ioctl(fileno(stdin), (int) TCGETS, &termio);
#else
(void) ioctl(fileno(stdin), (int) TCGETA, &termio);
#endif
getwindowsz();
#endif
#endif
getwindowsz();
#ifdef AUX
( void ) signal ( SIGTSTP , catch_stp ) ;
(void) signal(SIGTSTP, catch_stp);
#endif
}
@@ -137,62 +139,60 @@ void
setioctls()
{
#ifdef BSD_JOB_CONTROL
(void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars);
(void) ioctl(fileno(stdin), (int) TIOCSLTC, (char *) &ltchars);
#else
# ifdef POSIX_TYPES
(void) tcsetattr(fileno(stdin), TCSADRAIN, &termio);
# else
# if defined(TCSETS) && !defined(AIX_31)
(void) ioctl(fileno(stdin), (int) TCSETSW, &termio);
# else
(void) ioctl(fileno(stdin), (int) TCSETAW, &termio);
# endif
# endif
#ifdef POSIX_TYPES
(void) tcsetattr(fileno(stdin), TCSADRAIN, &termio);
#else
#if defined(TCSETS) && !defined(AIX_31)
(void) ioctl(fileno(stdin), (int) TCSETSW, &termio);
#else
(void) ioctl(fileno(stdin), (int) TCSETAW, &termio);
#endif
#endif
#endif
}
#ifdef SUSPEND /* No longer implies BSD */
#ifdef SUSPEND /* No longer implies BSD */
int
dosuspend()
{
#ifdef SYSCF
/* NB: check_user_string() is port-specific. */
if( !sysopt.shellers
|| !sysopt.shellers[0]
|| !check_user_string(sysopt.shellers)
){
Norep("Suspend command not available.");
return 0;
}
/* NB: check_user_string() is port-specific. */
if (!sysopt.shellers || !sysopt.shellers[0]
|| !check_user_string(sysopt.shellers)) {
Norep("Suspend command not available.");
return 0;
}
#endif
# if defined(SIGTSTP) && !defined(NO_SIGNAL)
if(signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
suspend_nhwindows((char *)0);
# ifdef _M_UNIX
sco_mapon();
# endif
# ifdef __linux__
linux_mapon();
# endif
(void) signal(SIGTSTP, SIG_DFL);
# ifdef AUX
( void ) kill ( 0 , SIGSTOP ) ;
# else
(void) kill(0, SIGTSTP);
# endif
# ifdef _M_UNIX
sco_mapoff();
# endif
# ifdef __linux__
linux_mapoff();
# endif
resume_nhwindows();
} else {
pline("I don't think your shell has job control.");
}
# else
pline("Sorry, it seems we have no SIGTSTP here. Try ! or S.");
# endif
return(0);
#if defined(SIGTSTP) && !defined(NO_SIGNAL)
if (signal(SIGTSTP, SIG_IGN) == SIG_DFL) {
suspend_nhwindows((char *) 0);
#ifdef _M_UNIX
sco_mapon();
#endif
#ifdef __linux__
linux_mapon();
#endif
(void) signal(SIGTSTP, SIG_DFL);
#ifdef AUX
(void) kill(0, SIGSTOP);
#else
(void) kill(0, SIGTSTP);
#endif
#ifdef _M_UNIX
sco_mapoff();
#endif
#ifdef __linux__
linux_mapoff();
#endif
resume_nhwindows();
} else {
pline("I don't think your shell has job control.");
}
#else
pline("Sorry, it seems we have no SIGTSTP here. Try ! or S.");
#endif
return (0);
}
#endif /* SUSPEND */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 nhlan.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 nhlan.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 nhlan.c $Date: 2009/05/06 10:50:26 $ $Revision: 1.5 $ */
/* SCCS Id: @(#)nhlan.c 3.5 1999/11/21 */
/* Copyright (c) Michael Allison, 1997 */
@@ -19,9 +19,10 @@
#ifdef LAN_FEATURES
void init_lan_features()
void
init_lan_features()
{
lan_username();
lan_username();
}
/*
* The get_lan_username() call is a required call, since some of
@@ -31,14 +32,16 @@ void init_lan_features()
char lusername[MAX_LAN_USERNAME];
int lusername_size = MAX_LAN_USERNAME;
char *lan_username()
char *
lan_username()
{
char *lu;
lu = get_username(&lusername_size);
if (lu) {
Strcpy(lusername, lu);
return lusername;
} else return (char *)0;
char *lu;
lu = get_username(&lusername_size);
if (lu) {
Strcpy(lusername, lu);
return lusername;
} else
return (char *) 0;
}
#endif /*LAN_FEATURES*/
/*nhlan.c*/

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 pcmain.c $NHDT-Date: 1427337317 2015/03/26 02:35:17 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.52 $ */
/* NetHack 3.6 pcmain.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */
/* NetHack 3.6 pcmain.c $Date: 2012/01/20 03:41:31 $ $Revision: 1.48 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -17,45 +17,45 @@
#if !defined(AMIGA) && !defined(GNUDOS)
#include <sys\stat.h>
#else
# ifdef GNUDOS
#ifdef GNUDOS
#include <sys/stat.h>
# endif
#endif
#endif
#ifdef WIN32
#include "win32api.h" /* for GetModuleFileName */
#include "win32api.h" /* for GetModuleFileName */
#endif
#ifdef __DJGPP__
#include <unistd.h> /* for getcwd() prototype */
#include <unistd.h> /* for getcwd() prototype */
#endif
char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */
char orgdir[PATHLEN]; /* also used in pcsys.c, amidos.c */
#ifdef TOS
boolean run_from_desktop = TRUE; /* should we pause before exiting?? */
# ifdef __GNUC__
long _stksize = 16*1024;
# endif
boolean run_from_desktop = TRUE; /* should we pause before exiting?? */
#ifdef __GNUC__
long _stksize = 16 * 1024;
#endif
#endif
#ifdef AMIGA
extern int bigscreen;
void NDECL( preserve_icon );
void NDECL(preserve_icon);
#endif
STATIC_DCL void FDECL(process_options,(int argc,char **argv));
STATIC_DCL void FDECL(process_options, (int argc, char **argv));
STATIC_DCL void NDECL(nhusage);
#if defined(MICRO) || defined(WIN32) || defined(OS2)
extern void FDECL(nethack_exit,(int));
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 boolean getreturn_enabled; /* from sys/share/pcsys.c */
extern int redirect_stdout; /* from sys/share/pcsys.c */
char *NDECL(exename);
char default_window_sys[] = "mswin";
#endif
@@ -65,75 +65,74 @@ extern void NDECL(mswin_destroy_reg);
#endif
#ifdef EXEPATH
STATIC_DCL char *FDECL(exepath,(char *));
STATIC_DCL char *FDECL(exepath, (char *));
#endif
int FDECL(main, (int,char **));
extern boolean FDECL(pcmain, (int,char **));
int FDECL(main, (int, char **));
extern boolean FDECL(pcmain, (int, char **));
#if defined(__BORLANDC__) && !defined(_WIN32)
void NDECL( startup );
void NDECL(startup);
unsigned _stklen = STKSIZ;
#endif
/* If the graphics version is built, we don't need a main; it is skipped
* to help MinGW decide which entry point to choose. If both main and
* to help MinGW decide which entry point to choose. If both main and
* WinMain exist, the resulting executable won't work correctly.
*/
#ifndef __MINGW32__
int
main(argc,argv)
main(argc, argv)
int argc;
char *argv[];
{
boolean resuming;
boolean resuming;
sys_early_init();
sys_early_init();
#ifdef WIN32
Strcpy(default_window_sys, "tty");
Strcpy(default_window_sys, "tty");
#endif
resuming = pcmain(argc,argv);
resuming = pcmain(argc, argv);
#ifdef LAN_FEATURES
init_lan_features();
init_lan_features();
#endif
moveloop(resuming);
nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
moveloop(resuming);
nethack_exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
#endif
boolean
pcmain(argc,argv)
pcmain(argc, argv)
int argc;
char *argv[];
{
register int fd;
register char *dir;
#if defined(WIN32)
char* envp = NULL;
char* sptr = NULL;
char *envp = NULL;
char *sptr = NULL;
char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ];
boolean save_getreturn_status = getreturn_enabled;
#endif
#ifdef NOCWD_ASSUMPTIONS
char failbuf[BUFSZ];
#endif
boolean resuming = FALSE; /* assume new game */
boolean resuming = FALSE; /* assume new game */
#ifdef _MSC_VER
/* set these appropriately for VS debugging */
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); /* | _CRTDBG_MODE_FILE);*/
_CrtSetReportMode(_CRT_ERROR,
_CRTDBG_MODE_DEBUG); /* | _CRTDBG_MODE_FILE);*/
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
/*| _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);*/
/* use STDERR by default
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
/*| _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);*/
/* use STDERR by default
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
#endif
#if defined(__BORLANDC__) && !defined(_WIN32)
@@ -142,12 +141,12 @@ char *argv[];
#ifdef TOS
long clock_time;
if (*argv[0]) { /* only a CLI can give us argv[0] */
if (*argv[0]) { /* only a CLI can give us argv[0] */
hname = argv[0];
run_from_desktop = FALSE;
} else
#endif
hname = "NetHack"; /* used for syntax messages */
hname = "NetHack"; /* used for syntax messages */
#ifndef WIN32
choose_windows(DEFAULT_WINDOW_SYS);
@@ -159,73 +158,79 @@ char *argv[];
/* Save current directory and make sure it gets restored when
* the game is exited.
*/
if (getcwd(orgdir, sizeof orgdir) == (char *)0)
if (getcwd(orgdir, sizeof orgdir) == (char *) 0)
error("NetHack: current directory path too long");
# ifndef NO_SIGNAL
signal(SIGINT, (SIG_RET_TYPE) nethack_exit); /* restore original directory */
# endif
#ifndef NO_SIGNAL
signal(SIGINT,
(SIG_RET_TYPE) nethack_exit); /* restore original directory */
#endif
#endif /* !AMIGA && !GNUDOS */
dir = nh_getenv("NETHACKDIR");
if (dir == (char *)0)
if (dir == (char *) 0)
dir = nh_getenv("HACKDIR");
#ifdef EXEPATH
if (dir == (char *)0)
if (dir == (char *) 0)
dir = exepath(argv[0]);
#endif
if (dir != (char *)0) {
if (dir != (char *) 0) {
(void) strncpy(hackdir, dir, PATHLEN - 1);
hackdir[PATHLEN-1] = '\0';
hackdir[PATHLEN - 1] = '\0';
#ifdef NOCWD_ASSUMPTIONS
{
int prefcnt;
fqn_prefix[0] = (char *)alloc(strlen(hackdir)+2);
fqn_prefix[0] = (char *) alloc(strlen(hackdir) + 2);
Strcpy(fqn_prefix[0], hackdir);
append_slash(fqn_prefix[0]);
for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++)
fqn_prefix[prefcnt] = fqn_prefix[0];
fqn_prefix[prefcnt] = fqn_prefix[0];
# if defined(WIN32) || defined(MSDOS)
#if defined(WIN32) || defined(MSDOS)
/* sysconf should be searched for in this location */
envp = nh_getenv("COMMONPROGRAMFILES");
if (envp) {
if ((sptr = index(envp, ';')) != 0) *sptr = '\0';
if ((sptr = index(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
fqn_prefix[SYSCONFPREFIX] = (char *)alloc(strlen(envp) + 10);
fqn_prefix[SYSCONFPREFIX] =
(char *) alloc(strlen(envp) + 10);
Strcpy(fqn_prefix[SYSCONFPREFIX], envp);
append_slash(fqn_prefix[SYSCONFPREFIX]);
Strcat(fqn_prefix[SYSCONFPREFIX], "NetHack\\");
}
}
/* user's home directory should default to this - unless overridden */
/* user's home directory should default to this - unless
* overridden */
envp = nh_getenv("USERPROFILE");
if (envp) {
if ((sptr = index(envp, ';')) != 0) *sptr = '\0';
if ((sptr = index(envp, ';')) != 0)
*sptr = '\0';
if (strlen(envp) > 0) {
fqn_prefix[CONFIGPREFIX] = (char *)alloc(strlen(envp)+2);
fqn_prefix[CONFIGPREFIX] =
(char *) alloc(strlen(envp) + 2);
Strcpy(fqn_prefix[CONFIGPREFIX], envp);
append_slash(fqn_prefix[CONFIGPREFIX]);
}
}
# endif
#endif
}
#endif
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx (dir, 1);
chdirx(dir, 1);
#endif
}
#ifdef AMIGA
# ifdef CHDIR
#ifdef CHDIR
/*
* If we're dealing with workbench, change the directory. Otherwise
* we could get "Insert disk in drive 0" messages. (Must be done
* before initoptions())....
*/
if(argc == 0)
if (argc == 0)
chdirx(HACKDIR, 1);
# endif
#endif
ami_wininit_data();
#endif
#ifdef WIN32
@@ -238,8 +243,8 @@ char *argv[];
#ifdef NOCWD_ASSUMPTIONS
if (!validate_prefix_locations(failbuf)) {
raw_printf("Some invalid directory locations were specified:\n\t%s\n",
failbuf);
nethack_exit(EXIT_FAILURE);
failbuf);
nethack_exit(EXIT_FAILURE);
}
#endif
@@ -253,114 +258,116 @@ char *argv[];
#else
Strcpy(hackdir, HACKDIR);
#endif
if(argc > 1) {
if (argc > 1) {
if (!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
*/
argc--;
argv++;
dir = argv[0]+2;
if(*dir == '=' || *dir == ':') dir++;
if(!*dir && argc > 1) {
/* avoid matching "-dec" for DECgraphics; since the man page
* says -d directory, hope nobody's using -desomething_else
*/
argc--;
argv++;
dir = argv[0];
}
if(!*dir)
error("Flag -d must be followed by a directory name.");
Strcpy(hackdir, dir);
dir = argv[0] + 2;
if (*dir == '=' || *dir == ':')
dir++;
if (!*dir && argc > 1) {
argc--;
argv++;
dir = argv[0];
}
if (!*dir)
error("Flag -d must be followed by a directory name.");
Strcpy(hackdir, dir);
}
if (argc > 1) {
/*
* Now we know the directory containing 'record' and
* may do a prscore().
*/
if (!strncmp(argv[1], "-s", 2)) {
/*
* Now we know the directory containing 'record' and
* may do a prscore().
*/
if (!strncmp(argv[1], "-s", 2)) {
#if defined(WIN32)
int sfd = (int)_fileno(stdout);
redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0;
int sfd = (int) _fileno(stdout);
redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0;
if (!redirect_stdout) {
raw_printf("-s is not supported for the Graphical Interface\n");
nethack_exit(EXIT_SUCCESS);
}
if (!redirect_stdout) {
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);
chdirx(hackdir, 0);
#endif
#ifdef SYSCF
initoptions();
initoptions();
#endif
prscore(argc, argv);
nethack_exit(EXIT_SUCCESS);
}
prscore(argc, argv);
nethack_exit(EXIT_SUCCESS);
}
#ifdef MSWIN_GRAPHICS
if (!strncmpi(argv[1], "-clearreg", 6)) { /* clear registry */
mswin_destroy_reg();
nethack_exit(EXIT_SUCCESS);
}
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)) {
nhusage();
nethack_exit(EXIT_SUCCESS);
}
/* Don't initialize the window system just to print usage */
if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) {
nhusage();
nethack_exit(EXIT_SUCCESS);
}
}
}
#ifdef WIN32
getreturn_enabled = save_getreturn_status;
#endif
/*
* It seems you really want to play.
*/
/*
* It seems you really want to play.
*/
#ifdef TOS
if (comp_times((long)time(&clock_time)))
if (comp_times((long) time(&clock_time)))
error("Your clock is incorrectly set!");
#endif
if (!dlb_init()) {
pline(
"%s\n%s\n%s\n%s\n\nNetHack was unable to open the required file \"%s\".%s",
copyright_banner_line(1), copyright_banner_line(2),
copyright_banner_line(3), copyright_banner_line(4), DLBFILE,
"%s\n%s\n%s\n%s\n\nNetHack was unable to open the required file "
"\"%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?");
"\nAre you perhaps trying to run NetHack within a zip utility?");
#else
"");
"");
#endif
error("dlb_init failure.");
}
u.uhp = 1; /* prevent RIP on early quits */
u.ux = 0; /* prevent flush_screen() */
u.uhp = 1; /* prevent RIP on early quits */
u.ux = 0; /* prevent flush_screen() */
/* chdir shouldn't be called before this point to keep the
* code parallel to other ports.
*/
/* chdir shouldn't be called before this point to keep the
* code parallel to other ports.
*/
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(hackdir,1);
chdirx(hackdir, 1);
#endif
#if defined(MSDOS) || defined (WIN32)
#if defined(MSDOS) || defined(WIN32)
/* 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 (!strncmpi(windowprocs.name, "mswin", 5))
NHWinMainInit();
else
*/
#ifdef WIN32
/*
if (!strncmpi(windowprocs.name, "mswin", 5))
NHWinMainInit();
else
*/
if (!strncmpi(windowprocs.name, "tty", 3))
nttty_open(1);
# endif
nttty_open(1);
#endif
#endif
#if defined(MSDOS) || defined(WIN32)
@@ -374,27 +381,27 @@ char *argv[];
#endif
#if defined(MSDOS) || defined(WIN32)
init_nhwindows(&argc,argv);
init_nhwindows(&argc, argv);
#else
init_nhwindows(&argc,argv);
init_nhwindows(&argc, argv);
process_options(argc, argv);
#endif
#ifdef WIN32
toggle_mouse_support(); /* must come after process_options */
toggle_mouse_support(); /* must come after process_options */
#endif
#ifdef MFLOPPY
set_lock_and_bones();
# ifndef AMIGA
#ifndef AMIGA
copybones(FROMPERM);
# endif
#endif
#endif
/* strip role,race,&c suffix; calls askname() if plname[] is empty
or holds a generic user name like "player" or "games" */
plnamesuffix();
set_playmode(); /* sets plname to "wizard" for wizard mode */
set_playmode(); /* sets plname to "wizard" for wizard mode */
#if 0
/* unlike Unix where the game might be invoked with a script
which forces a particular character name for each player
@@ -402,57 +409,59 @@ char *argv[];
the character during role/race/&c selection */
iflags.renameallowed = TRUE;
#else
/* until the getlock code is resolved, override askname()'s
setting of renameallowed; when False, player_selection()
won't resent renaming as an option */
iflags.renameallowed = FALSE;
/* until the getlock code is resolved, override askname()'s
setting of renameallowed; when False, player_selection()
won't resent renaming as an option */
iflags.renameallowed = FALSE;
#endif
#if defined(PC_LOCKING)
/* 3.3.0 added this to support detection of multiple games
* under the same plname on the same machine in a windowed
* or multitasking environment.
*
* That allows user confirmation prior to overwriting the
* level files of a game in progress.
*
* Also prevents an aborted game's level files from being
* overwritten without confirmation when a user starts up
* another game with the same player name.
*/
# if defined(WIN32)
/* 3.3.0 added this to support detection of multiple games
* under the same plname on the same machine in a windowed
* or multitasking environment.
*
* That allows user confirmation prior to overwriting the
* level files of a game in progress.
*
* Also prevents an aborted game's level files from being
* 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);
(void) fname_encode(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.", '%',
fnamebuf, encodedfnamebuf, BUFSZ);
Sprintf(lock, "%s", encodedfnamebuf);
/* regularize(lock); */ /* we encode now, rather than substitute */
# else
Strcpy(lock,plname);
#else
Strcpy(lock, plname);
regularize(lock);
# endif
#endif
getlock();
#else /* What follows is !PC_LOCKING */
# ifdef AMIGA /* We'll put the bones & levels in the user specified directory -jhsa */
Strcat(lock,plname);
Strcat(lock,".99");
# else
# ifndef MFLOPPY
#else /* What follows is !PC_LOCKING */
#ifdef AMIGA /* We'll put the bones & levels in the user specified directory \
-jhsa */
Strcat(lock, plname);
Strcat(lock, ".99");
#else
#ifndef MFLOPPY
/* I'm not sure what, if anything, is left here, but MFLOPPY has
* conflicts with set_lock_and_bones() in files.c.
*/
Strcpy(lock,plname);
Strcat(lock,".99");
regularize(lock); /* is this necessary? */
/* not compatible with full path a la AMIGA */
# endif
# endif
#endif /* PC_LOCKING */
Strcpy(lock, plname);
Strcat(lock, ".99");
regularize(lock); /* is this necessary? */
/* not compatible with full path a la AMIGA */
#endif
#endif
#endif /* PC_LOCKING */
/* Set up level 0 file to keep the game state.
*/
fd = create_levelfile(0, (char *)0);
fd = create_levelfile(0, (char *) 0);
if (fd < 0) {
raw_print("Cannot create lock file");
} else {
@@ -462,7 +471,7 @@ char *argv[];
hackpid = 1;
#endif
write(fd, (genericptr_t) &hackpid, sizeof(hackpid));
nhclose(fd);
nhclose(fd);
}
#ifdef MFLOPPY
level_info[0].where = ACTIVE;
@@ -479,34 +488,34 @@ char *argv[];
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.
*/
attempt_restore:
/*
* First, try to find and restore a save file for specified character.
* We'll return here if new game player_selection() renames the hero.
*/
attempt_restore:
if ((fd = restore_saved_game()) >= 0) {
#ifndef NO_SIGNAL
(void) signal(SIGINT, (SIG_RET_TYPE) done1);
#endif
#ifdef NEWS
if(iflags.news){
if (iflags.news) {
display_file(NEWS, FALSE);
iflags.news = FALSE;
}
#endif
pline("Restoring save file...");
mark_synch(); /* flush output */
mark_synch(); /* flush output */
if (dorecover(fd)) {
resuming = TRUE; /* not starting new game */
resuming = TRUE; /* not starting new game */
if (discover)
You("are in non-scoring discovery mode.");
You("are in non-scoring discovery mode.");
if (discover || wizard) {
if(yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
}
if (yn("Do you want to keep the save file?") == 'n')
(void) delete_savefile();
else {
nh_compress(fqname(SAVEF, SAVEPREFIX, 0));
}
}
}
}
@@ -519,14 +528,14 @@ char *argv[];
if (!iflags.renameinprogress) {
player_selection();
if (iflags.renameinprogress) {
/* player has renamed the hero while selecting role;
discard current lock file and create another for
the new character name */
#if 0 /* this needs to be reconciled with the getlock mess above... */
/* player has renamed the hero while selecting role;
discard current lock file and create another for
the new character name */
#if 0 /* this needs to be reconciled with the getlock mess above... */
delete_levelfile(0); /* remove empty lock file */
getlock();
#endif
goto attempt_restore;
goto attempt_restore;
}
}
newgame();
@@ -550,14 +559,13 @@ char *argv[];
{
int i;
/*
* Process options.
*/
while(argc > 1 && argv[1][0] == '-'){
while (argc > 1 && argv[1][0] == '-') {
argv++;
argc--;
switch(argv[0][1]){
switch (argv[0][1]) {
case 'a':
if (argv[0][2]) {
if ((i = str2align(&argv[0][2])) >= 0)
@@ -581,19 +589,19 @@ char *argv[];
break;
#endif
case 'u':
if(argv[0][2])
(void) strncpy(plname, argv[0]+2, sizeof(plname)-1);
else if(argc > 1) {
argc--;
argv++;
(void) strncpy(plname, argv[0], sizeof(plname)-1);
if (argv[0][2])
(void) strncpy(plname, argv[0] + 2, sizeof(plname) - 1);
else if (argc > 1) {
argc--;
argv++;
(void) strncpy(plname, argv[0], sizeof(plname) - 1);
} else
raw_print("Player name expected after -u");
break;
#ifndef AMIGA
case 'I':
case 'i':
if (!strncmpi(argv[0]+1, "IBM", 3)) {
if (!strncmpi(argv[0] + 1, "IBM", 3)) {
load_symset("IBMGraphics", PRIMARY);
load_symset("RogueIBM", ROGUESET);
switch_symbols(TRUE);
@@ -601,7 +609,7 @@ char *argv[];
break;
/* case 'D': */
case 'd':
if (!strncmpi(argv[0]+1, "DEC", 3)) {
if (!strncmpi(argv[0] + 1, "DEC", 3)) {
load_symset("DECGraphics", PRIMARY);
switch_symbols(TRUE);
}
@@ -641,16 +649,16 @@ char *argv[];
}
break;
#ifdef MFLOPPY
# ifndef AMIGA
#ifndef AMIGA
/* Player doesn't want to use a RAM disk
*/
case 'R':
ramdisk = FALSE;
break;
# endif
#endif
#endif
#ifdef AMIGA
/* interlaced and non-interlaced screens */
/* interlaced and non-interlaced screens */
case 'L':
bigscreen = 1;
break;
@@ -660,14 +668,14 @@ char *argv[];
#endif
#ifdef WIN32
case 'w': /* windowtype */
if (strncmpi(&argv[0][2],"tty", 3)) {
if (strncmpi(&argv[0][2], "tty", 3)) {
nttty_open(1);
}
/*
else {
NHWinMainInit();
}
*/
/*
else {
NHWinMainInit();
}
*/
choose_windows(&argv[0][2]);
break;
#endif
@@ -678,8 +686,9 @@ char *argv[];
if ((i = str2role(&argv[0][1])) >= 0) {
flags.initrole = i;
break;
} else raw_printf("\nUnknown switch: %s", argv[0]);
/* FALL THROUGH */
} else
raw_printf("\nUnknown switch: %s", argv[0]);
/* FALL THROUGH */
case '?':
nhusage();
nethack_exit(EXIT_SUCCESS);
@@ -687,7 +696,7 @@ char *argv[];
}
}
STATIC_OVL void
STATIC_OVL void
nhusage()
{
char buf1[BUFSZ], buf2[BUFSZ], *bufptr;
@@ -695,18 +704,20 @@ nhusage()
buf1[0] = '\0';
bufptr = buf1;
#define ADD_USAGE(s) if ((strlen(buf1) + strlen(s)) < (BUFSZ - 1)) Strcat(bufptr, s);
#define ADD_USAGE(s) \
if ((strlen(buf1) + strlen(s)) < (BUFSZ - 1)) \
Strcat(bufptr, s);
/* -role still works for those cases which aren't already taken, but
* is deprecated and will not be listed here.
*/
(void) Sprintf(buf2,
"\nUsage:\n%s [-d dir] -s [-r race] [-p profession] [maxrank] [name]...\n or",
hname);
(void) Sprintf(buf2, "\nUsage:\n%s [-d dir] -s [-r race] [-p profession] "
"[maxrank] [name]...\n or",
hname);
ADD_USAGE(buf2);
(void) Sprintf(buf2,
"\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]",
(void) Sprintf(
buf2, "\n%s [-d dir] [-u name] [-r race] [-p profession] [-[DX]]",
hname);
ADD_USAGE(buf2);
#ifdef NEWS
@@ -716,17 +727,17 @@ nhusage()
ADD_USAGE(" [-I] [-i] [-d]");
#endif
#ifdef MFLOPPY
# ifndef AMIGA
#ifndef AMIGA
ADD_USAGE(" [-R]");
# endif
#endif
#endif
#ifdef AMIGA
ADD_USAGE(" [-[lL]]");
#endif
if (!iflags.window_inited)
raw_printf("%s\n",buf1);
raw_printf("%s\n", buf1);
else
(void) printf("%s\n",buf1);
(void) printf("%s\n", buf1);
#undef ADD_USAGE
}
@@ -736,57 +747,58 @@ chdirx(dir, wr)
char *dir;
boolean wr;
{
# ifdef AMIGA
#ifdef AMIGA
static char thisdir[] = "";
# else
#else
static char thisdir[] = ".";
# endif
if(dir && chdir(dir) < 0) {
#endif
if (dir && chdir(dir) < 0) {
error("Cannot chdir to %s.", dir);
}
# ifndef AMIGA
#ifndef AMIGA
/* Change the default drive as well.
*/
chdrive(dir);
# endif
#endif
/* warn the player if we can't write the record file */
/* perhaps we should also test whether . is writable */
/* unfortunately the access system-call is worthless */
if (wr) check_recordfile(dir ? dir : thisdir);
if (wr)
check_recordfile(dir ? dir : thisdir);
}
#endif /* CHDIR */
#ifdef PORT_HELP
# if defined(MSDOS) || defined(WIN32)
#if defined(MSDOS) || defined(WIN32)
void
port_help()
{
/* display port specific help file */
display_file( PORT_HELP, 1 );
display_file(PORT_HELP, 1);
}
# endif /* MSDOS || WIN32 */
#endif /* MSDOS || WIN32 */
#endif /* PORT_HELP */
/* validate wizard mode if player has requested access to it */
boolean
authorize_wizard_mode()
{
if (!strcmp(plname, WIZARD_NAME)) return TRUE;
if (!strcmp(plname, WIZARD_NAME))
return TRUE;
return FALSE;
}
#ifdef EXEPATH
# ifdef __DJGPP__
#ifdef __DJGPP__
#define PATH_SEPARATOR '/'
# else
#else
#define PATH_SEPARATOR '\\'
# endif
#endif
#ifdef WIN32
static char exenamebuf[PATHLEN];
static char exenamebuf[PATHLEN];
char *
exename()
@@ -794,17 +806,18 @@ exename()
int bsize = PATHLEN;
char *tmp = exenamebuf, *tmp2;
# ifdef UNICODE
#ifdef UNICODE
{
TCHAR wbuf[PATHLEN * 4];
GetModuleFileName((HANDLE)0, 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
#else
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
#endif
tmp2 = strrchr(tmp, PATH_SEPARATOR);
if (tmp2) *tmp2 = '\0';
if (tmp2)
*tmp2 = '\0';
tmp2++;
return tmp2;
}
@@ -813,30 +826,33 @@ exename()
#define EXEPATHBUFSZ 256
char exepathbuf[EXEPATHBUFSZ];
char *exepath(str)
char *
exepath(str)
char *str;
{
char *tmp, *tmp2;
int bsize;
if (!str) return (char *)0;
if (!str)
return (char *) 0;
bsize = EXEPATHBUFSZ;
tmp = exepathbuf;
# ifndef WIN32
Strcpy (tmp, str);
# else
#ifdef UNICODE
#ifndef WIN32
Strcpy(tmp, str);
#else
#ifdef UNICODE
{
TCHAR wbuf[BUFSZ];
GetModuleFileName((HANDLE)0, 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
#else
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
#endif
#endif
tmp2 = strrchr(tmp, PATH_SEPARATOR);
if (tmp2) *tmp2 = '\0';
if (tmp2)
*tmp2 = '\0';
return tmp;
}
#endif /* EXEPATH */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 pcsys.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 pcsys.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.26 $ */
/* NetHack 3.6 pcsys.c $Date: 2012/01/22 06:33:47 $ $Revision: 1.18 $ */
/* SCCS Id: @(#)pcsys.c 3.5 2002/01/22 */
/* NetHack may be freely redistributed. See license for details. */
@@ -13,12 +13,12 @@
#include <ctype.h>
#include <fcntl.h>
#if !defined(MSDOS) && !defined(WIN_CE) /* already done */
#if !defined(MSDOS) && !defined(WIN_CE) /* already done */
#include <process.h>
#endif
#ifdef __GO32__
#define P_WAIT 0
#define P_NOWAIT 1
#define P_WAIT 0
#define P_NOWAIT 1
#endif
#ifdef TOS
#include <osbind.h>
@@ -29,33 +29,31 @@
#define filesize filesize_nh
#endif
#if defined(MICRO) || defined(WIN32) || defined(OS2)
void FDECL(nethack_exit,(int));
void FDECL(nethack_exit, (int));
#else
#define nethack_exit exit
#endif
STATIC_DCL void NDECL(msexit);
#ifdef MOVERLAY
extern void __far __cdecl _movepause( void );
extern void __far __cdecl _moveresume( void );
extern void __far __cdecl _movepause(void);
extern void __far __cdecl _moveresume(void);
extern unsigned short __far __cdecl _movefpause;
extern unsigned short __far __cdecl _movefpaused;
#define __MOVE_PAUSE_DISK 2 /* Represents the executable file */
#define __MOVE_PAUSE_CACHE 4 /* Represents the cache memory */
#endif /* MOVERLAY */
#define __MOVE_PAUSE_DISK 2 /* Represents the executable file */
#define __MOVE_PAUSE_CACHE 4 /* Represents the cache memory */
#endif /* MOVERLAY */
#ifdef MFLOPPY
STATIC_DCL boolean NDECL(record_exists);
# ifndef TOS
#ifndef TOS
STATIC_DCL boolean NDECL(comspec_exists);
# endif
#endif
#endif
#ifdef WIN32
extern int GUILaunched; /* from nttty.c */
extern int GUILaunched; /* from nttty.c */
#endif
#if defined(MICRO) || defined(WIN32)
@@ -63,98 +61,100 @@ extern int GUILaunched; /* from nttty.c */
void
flushout()
{
(void) fflush(stdout);
return;
(void) fflush(stdout);
return;
}
static const char *COMSPEC =
# ifdef TOS
"SHELL";
# else
"COMSPEC";
# endif
#ifdef TOS
"SHELL";
#else
"COMSPEC";
#endif
#define getcomspec() nh_getenv(COMSPEC)
# ifdef SHELL
#ifdef SHELL
int
dosh()
{
extern char orgdir[];
char *comspec;
# ifndef __GO32__
int spawnstat;
# endif
#if defined(MSDOS) && defined(NO_TERMS)
int grmode = iflags.grmode;
extern char orgdir[];
char *comspec;
#ifndef __GO32__
int spawnstat;
#endif
#if defined(MSDOS) && defined(NO_TERMS)
int grmode = iflags.grmode;
#endif
if ((comspec = getcomspec())) {
#ifndef TOS /* TOS has a variety of shells */
suspend_nhwindows(
"To return to NetHack, enter \"exit\" at the system prompt.\n");
#else
#if defined(MSDOS) && defined(NO_TERMS)
grmode = iflags.grmode;
#endif
suspend_nhwindows((char *) 0);
#endif /* TOS */
#ifndef NOCWD_ASSUMPTIONS
chdirx(orgdir, 0);
#endif
#ifdef __GO32__
if (system(comspec) < 0) { /* wsu@eecs.umich.edu */
#else
#ifdef MOVERLAY
/* Free the cache memory used by overlays, close .exe */
_movefpause |= __MOVE_PAUSE_DISK;
_movefpause |= __MOVE_PAUSE_CACHE;
_movepause();
#endif
spawnstat = spawnl(P_WAIT, comspec, comspec, (char *) 0);
#ifdef MOVERLAY
_moveresume();
#endif
if ((comspec = getcomspec())) {
# ifndef TOS /* TOS has a variety of shells */
suspend_nhwindows("To return to NetHack, enter \"exit\" at the system prompt.\n");
# else
# if defined(MSDOS) && defined(NO_TERMS)
grmode = iflags.grmode;
# endif
suspend_nhwindows((char *)0);
# endif /* TOS */
# ifndef NOCWD_ASSUMPTIONS
chdirx(orgdir, 0);
# endif
# ifdef __GO32__
if (system(comspec) < 0) { /* wsu@eecs.umich.edu */
# else
# ifdef MOVERLAY
/* Free the cache memory used by overlays, close .exe */
_movefpause |= __MOVE_PAUSE_DISK;
_movefpause |= __MOVE_PAUSE_CACHE;
_movepause();
# endif
spawnstat = spawnl(P_WAIT, comspec, comspec, (char *)0);
# ifdef MOVERLAY
_moveresume();
# endif
if ( spawnstat < 0) {
# endif
raw_printf("Can't spawn \"%s\"!", comspec);
getreturn("to continue");
}
# ifdef TOS
/* Some shells (e.g. Gulam) turn the cursor off when they exit */
if (iflags.BIOS)
(void)Cursconf(1, -1);
# endif
# ifndef NOCWD_ASSUMPTIONS
chdirx(hackdir, 0);
# endif
get_scr_size(); /* maybe the screen mode changed (TH) */
# if defined(MSDOS) && defined(NO_TERMS)
if (grmode) gr_init();
# endif
resume_nhwindows();
} else
pline("Can't find %s.",COMSPEC);
return 0;
if (spawnstat < 0) {
#endif
raw_printf("Can't spawn \"%s\"!", comspec);
getreturn("to continue");
}
#ifdef TOS
/* Some shells (e.g. Gulam) turn the cursor off when they exit */
if (iflags.BIOS)
(void) Cursconf(1, -1);
#endif
#ifndef NOCWD_ASSUMPTIONS
chdirx(hackdir, 0);
#endif
get_scr_size(); /* maybe the screen mode changed (TH) */
#if defined(MSDOS) && defined(NO_TERMS)
if (grmode)
gr_init();
#endif
resume_nhwindows();
} else
pline("Can't find %s.", COMSPEC);
return 0;
}
# endif /* SHELL */
#endif /* SHELL */
# ifdef MFLOPPY
#ifdef MFLOPPY
void
eraseall(path, files)
const char *path, *files;
{
char buf[PATHLEN];
char *foundfile;
char buf[PATHLEN];
char *foundfile;
foundfile = foundfile_buffer();
Sprintf(buf, "%s%s", path, files);
if (findfirst(buf))
do {
Sprintf(buf, "%s%s", path, foundfile);
(void) unlink(buf);
} while (findnext());
return;
foundfile = foundfile_buffer();
Sprintf(buf, "%s%s", path, files);
if (findfirst(buf))
do {
Sprintf(buf, "%s%s", path, foundfile);
(void) unlink(buf);
} while (findnext());
return;
}
/*
@@ -164,210 +164,212 @@ void
copybones(mode)
int mode;
{
char from[PATHLEN], to[PATHLEN], last[13];
char *frompath, *topath;
char *foundfile;
# ifndef TOS
int status;
char copy[8], *comspec;
# endif
char from[PATHLEN], to[PATHLEN], last[13];
char *frompath, *topath;
char *foundfile;
#ifndef TOS
int status;
char copy[8], *comspec;
#endif
if (!ramdisk)
return;
if (!ramdisk)
return;
/* Find the name of the last file to be transferred
*/
frompath = (mode != TOPERM) ? permbones : levels;
foundfile = foundfile_buffer();
last[0] = '\0';
Sprintf(from, "%s%s", frompath, allbones);
topath = (mode == TOPERM) ? permbones : levels;
# ifdef TOS
eraseall(topath, allbones);
# endif
if (findfirst(from))
do {
# ifdef TOS
Sprintf(from, "%s%s", frompath, foundfile);
Sprintf(to, "%s%s", topath, foundfile);
if (_copyfile(from, to))
goto error_copying;
# endif
Strcpy(last, foundfile);
} while (findnext());
# ifdef TOS
else
return;
# else
if (last[0]) {
Sprintf(copy, "%cC copy",switchar());
/* Find the name of the last file to be transferred
*/
frompath = (mode != TOPERM) ? permbones : levels;
foundfile = foundfile_buffer();
last[0] = '\0';
Sprintf(from, "%s%s", frompath, allbones);
topath = (mode == TOPERM) ? permbones : levels;
#ifdef TOS
eraseall(topath, allbones);
#endif
if (findfirst(from))
do {
#ifdef TOS
Sprintf(from, "%s%s", frompath, foundfile);
Sprintf(to, "%s%s", topath, foundfile);
if (_copyfile(from, to))
goto error_copying;
#endif
Strcpy(last, foundfile);
} while (findnext());
#ifdef TOS
else
return;
#else
if (last[0]) {
Sprintf(copy, "%cC copy", switchar());
/* Remove any bones files in `to' directory.
*/
eraseall(topath, allbones);
/* Remove any bones files in `to' directory.
*/
eraseall(topath, allbones);
/* Copy `from' to `to' */
Sprintf(to, "%s%s", topath, allbones);
comspec = getcomspec();
status =spawnl(P_WAIT, comspec, comspec, copy, from,
to, "> nul", (char *)0);
} else
return;
# endif /* TOS */
/* Copy `from' to `to' */
Sprintf(to, "%s%s", topath, allbones);
comspec = getcomspec();
status = spawnl(P_WAIT, comspec, comspec, copy, from, to, "> nul",
(char *) 0);
} else
return;
#endif /* TOS */
/* See if the last file got there. If so, remove the ramdisk bones
* files.
*/
Sprintf(to, "%s%s", topath, last);
if (findfirst(to)) {
if (mode == TOPERM)
eraseall(frompath, allbones);
return;
}
/* See if the last file got there. If so, remove the ramdisk bones
* files.
*/
Sprintf(to, "%s%s", topath, last);
if (findfirst(to)) {
if (mode == TOPERM)
eraseall(frompath, allbones);
return;
}
# ifdef TOS
#ifdef TOS
error_copying:
# endif
/* Last file didn't get there.
*/
Sprintf(to, "%s%s", topath, allbones);
msmsg("Can't copy \"%s\" to \"%s\" -- ", from, to);
# ifndef TOS
if (status < 0)
msmsg("can't spawn \"%s\"!", comspec);
else
# endif
msmsg((freediskspace(topath) < filesize(from)) ?
"insufficient disk space." : "bad path(s)?");
if (mode == TOPERM) {
msmsg("Bones will be left in \"%s\"\n",
*levels ? levels : hackdir);
} else {
/* Remove all bones files on the RAMdisk */
eraseall(levels, allbones);
playwoRAMdisk();
}
return;
#endif
/* Last file didn't get there.
*/
Sprintf(to, "%s%s", topath, allbones);
msmsg("Can't copy \"%s\" to \"%s\" -- ", from, to);
#ifndef TOS
if (status < 0)
msmsg("can't spawn \"%s\"!", comspec);
else
#endif
msmsg((freediskspace(topath) < filesize(from))
? "insufficient disk space."
: "bad path(s)?");
if (mode == TOPERM) {
msmsg("Bones will be left in \"%s\"\n", *levels ? levels : hackdir);
} else {
/* Remove all bones files on the RAMdisk */
eraseall(levels, allbones);
playwoRAMdisk();
}
return;
}
void
playwoRAMdisk()
{
int c;
int c;
msmsg("Do you wish to play without a RAMdisk? [yn] (n)");
msmsg("Do you wish to play without a RAMdisk? [yn] (n)");
/* Set ramdisk false *before* exit-ing (because msexit calls
* copybones)
*/
ramdisk = FALSE;
c = tgetch(); if (c == 'Y') c = 'y';
if (c != 'y') {
settty("Be seeing you...\n");
nethack_exit(EXIT_SUCCESS);
}
set_lock_and_bones();
return;
/* Set ramdisk false *before* exit-ing (because msexit calls
* copybones)
*/
ramdisk = FALSE;
c = tgetch();
if (c == 'Y')
c = 'y';
if (c != 'y') {
settty("Be seeing you...\n");
nethack_exit(EXIT_SUCCESS);
}
set_lock_and_bones();
return;
}
int
saveDiskPrompt(start)
int start;
{
char buf[BUFSIZ], *bp;
char qbuf[QBUFSZ];
char buf[BUFSIZ], *bp;
char qbuf[QBUFSZ];
int fd;
int fd;
if (sysflags.asksavedisk) {
/* Don't prompt if you can find the save file */
if ((fd = open_savefile()) >= 0) {
(void) nhclose(fd);
return 1;
}
clear_nhwindow(WIN_MESSAGE);
pline("If save file is on a save disk, insert that disk now.");
mark_synch();
Sprintf(qbuf,"File name (default \"%s\"%s) ?", SAVEF,
start ? "" : ", <Esc> cancels save");
getlin(qbuf, buf);
clear_nhwindow(WIN_MESSAGE);
if (!start && *buf == '\033')
return 0;
if (sysflags.asksavedisk) {
/* Don't prompt if you can find the save file */
if ((fd = open_savefile()) >= 0) {
(void) nhclose(fd);
return 1;
}
clear_nhwindow(WIN_MESSAGE);
pline("If save file is on a save disk, insert that disk now.");
mark_synch();
Sprintf(qbuf, "File name (default \"%s\"%s) ?", SAVEF,
start ? "" : ", <Esc> cancels save");
getlin(qbuf, buf);
clear_nhwindow(WIN_MESSAGE);
if (!start && *buf == '\033')
return 0;
/* Strip any whitespace. Also, if nothing was entered except
* whitespace, do not change the value of SAVEF.
*/
for (bp = buf; *bp; bp++)
if (!isspace(*bp)) {
strncpy(SAVEF, bp, PATHLEN);
break;
}
}
return 1;
/* Strip any whitespace. Also, if nothing was entered except
* whitespace, do not change the value of SAVEF.
*/
for (bp = buf; *bp; bp++)
if (!isspace(*bp)) {
strncpy(SAVEF, bp, PATHLEN);
break;
}
}
return 1;
}
/* Return 1 if the record file was found */
STATIC_OVL boolean
record_exists()
{
FILE *fp;
FILE *fp;
fp = fopen_datafile(RECORD, "r", TRUE);
if (fp) {
fclose(fp);
return TRUE;
}
return FALSE;
fp = fopen_datafile(RECORD, "r", TRUE);
if (fp) {
fclose(fp);
return TRUE;
}
return FALSE;
}
#endif /* MFLOPPY */
# ifdef TOS
#ifdef TOS
#define comspec_exists() 1
# else
# ifdef MFLOPPY
#else
#ifdef MFLOPPY
/* Return 1 if the comspec was found */
STATIC_OVL boolean
comspec_exists()
{
int fd;
char *comspec;
int fd;
char *comspec;
if ((comspec = getcomspec()))
if ((fd = open(comspec, O_RDONLY)) >= 0) {
(void) nhclose(fd);
return TRUE;
}
return FALSE;
if ((comspec = getcomspec()))
if ((fd = open(comspec, O_RDONLY)) >= 0) {
(void) nhclose(fd);
return TRUE;
}
return FALSE;
}
# endif /* MFLOPPY */
# endif
#endif /* MFLOPPY */
#endif
# ifdef MFLOPPY
#ifdef MFLOPPY
/* Prompt for game disk, then check for record file.
*/
void
gameDiskPrompt()
{
if (sysflags.asksavedisk) {
if (record_exists() && comspec_exists())
return;
(void) putchar('\n');
getreturn("when the game disk has been inserted");
}
if (comspec_exists() && record_exists())
return;
if (sysflags.asksavedisk) {
if (record_exists() && comspec_exists())
return;
(void) putchar('\n');
getreturn("when the game disk has been inserted");
}
if (comspec_exists() && record_exists())
return;
if (!comspec_exists())
msmsg("\n\nWARNING: can't find command processor \"%s\"!\n", getcomspec());
if (!record_exists())
msmsg("\n\nWARNING: can't find record file \"%s\"!\n", RECORD);
msmsg("If the game disk is not in, insert it now.\n");
getreturn("to continue");
return;
if (!comspec_exists())
msmsg("\n\nWARNING: can't find command processor \"%s\"!\n",
getcomspec());
if (!record_exists())
msmsg("\n\nWARNING: can't find record file \"%s\"!\n", RECORD);
msmsg("If the game disk is not in, insert it now.\n");
getreturn("to continue");
return;
}
# endif /* MFLOPPY */
#endif /* MFLOPPY */
#endif /* MICRO */
/*
@@ -378,16 +380,16 @@ void
append_slash(name)
char *name;
{
char *ptr;
char *ptr;
if (!*name)
return;
ptr = name + (strlen(name) - 1);
if (*ptr != '\\' && *ptr != '/' && *ptr != ':') {
*++ptr = '\\';
*++ptr = '\0';
}
return;
if (!*name)
return;
ptr = name + (strlen(name) - 1);
if (*ptr != '\\' && *ptr != '/' && *ptr != ':') {
*++ptr = '\\';
*++ptr = '\0';
}
return;
}
#ifdef WIN32
@@ -400,30 +402,32 @@ getreturn(str)
const char *str;
{
#ifdef WIN32
if (!getreturn_enabled) return;
if (!getreturn_enabled)
return;
#endif
#ifdef TOS
msmsg("Hit <Return> %s.", str);
msmsg("Hit <Return> %s.", str);
#else
msmsg("Hit <Enter> %s.", str);
msmsg("Hit <Enter> %s.", str);
#endif
while (pgetchar() != '\n') ;
return;
while (pgetchar() != '\n')
;
return;
}
#ifndef WIN32
void
msmsg VA_DECL(const char *, fmt)
VA_START(fmt);
VA_INIT(fmt, const char *);
# if defined(MSDOS) && defined(NO_TERMS)
if (iflags.grmode)
gr_finish();
# endif
Vprintf(fmt, VA_ARGS);
flushout();
VA_END();
return;
void msmsg
VA_DECL(const char *, fmt)
VA_START(fmt);
VA_INIT(fmt, const char *);
#if defined(MSDOS) && defined(NO_TERMS)
if (iflags.grmode)
gr_finish();
#endif
Vprintf(fmt, VA_ARGS);
flushout();
VA_END();
return;
}
#endif
@@ -431,11 +435,11 @@ msmsg VA_DECL(const char *, fmt)
* Follow the PATH, trying to fopen the file.
*/
#ifdef TOS
# ifdef __MINT__
#ifdef __MINT__
#define PATHSEP ':'
# else
#else
#define PATHSEP ','
# endif
#endif
#else
#define PATHSEP ';'
#endif
@@ -444,101 +448,105 @@ FILE *
fopenp(name, mode)
const char *name, *mode;
{
char buf[BUFSIZ], *bp, *pp, lastch = 0;
FILE *fp;
char buf[BUFSIZ], *bp, *pp, lastch = 0;
FILE *fp;
/* Try the default directory first. Then look along PATH.
*/
(void) strncpy(buf, name, BUFSIZ - 1);
buf[BUFSIZ-1] = '\0';
if ((fp = fopen(buf, mode)))
return fp;
else {
int ccnt = 0;
pp = getenv("PATH");
while (pp && *pp) {
bp = buf;
while (*pp && *pp != PATHSEP) {
lastch = *bp++ = *pp++;
ccnt++;
}
if (lastch != '\\' && lastch != '/') {
*bp++ = '\\';
ccnt++;
}
(void) strncpy(bp, name, (BUFSIZ - ccnt) - 2);
bp[BUFSIZ - ccnt - 1] = '\0';
if ((fp = fopen(buf, mode)))
return fp;
if (*pp)
pp++;
}
}
/* Try the default directory first. Then look along PATH.
*/
(void) strncpy(buf, name, BUFSIZ - 1);
buf[BUFSIZ - 1] = '\0';
if ((fp = fopen(buf, mode)))
return fp;
else {
int ccnt = 0;
pp = getenv("PATH");
while (pp && *pp) {
bp = buf;
while (*pp && *pp != PATHSEP) {
lastch = *bp++ = *pp++;
ccnt++;
}
if (lastch != '\\' && lastch != '/') {
*bp++ = '\\';
ccnt++;
}
(void) strncpy(bp, name, (BUFSIZ - ccnt) - 2);
bp[BUFSIZ - ccnt - 1] = '\0';
if ((fp = fopen(buf, mode)))
return fp;
if (*pp)
pp++;
}
}
#ifdef OS2_CODEVIEW /* one more try for hackdir */
(void) strncpy(buf, hackdir, BUFSZ);
buf[BUFSZ-1] = '\0';
if ((strlen(name) + 1 + strlen(buf)) < BUFSZ - 1) {
append_slash(buf);
Strcat(buf,name);
} else
impossible("fopenp() buffer too small for complete filename!");
if(fp = fopen(buf,mode))
return fp;
(void) strncpy(buf, hackdir, BUFSZ);
buf[BUFSZ - 1] = '\0';
if ((strlen(name) + 1 + strlen(buf)) < BUFSZ - 1) {
append_slash(buf);
Strcat(buf, name);
} else
impossible("fopenp() buffer too small for complete filename!");
if (fp = fopen(buf, mode))
return fp;
#endif
return (FILE *)0;
return (FILE *) 0;
}
#if defined(MICRO) || defined(WIN32) || defined(OS2)
void nethack_exit(code)
void
nethack_exit(code)
int code;
{
msexit();
exit(code);
msexit();
exit(code);
}
/* Chdir back to original directory
*/
#ifdef TOS
extern boolean run_from_desktop; /* set in pcmain.c */
extern boolean run_from_desktop; /* set in pcmain.c */
#endif
STATIC_OVL void msexit()
STATIC_OVL void
msexit()
{
#ifdef CHDIR
extern char orgdir[];
extern char orgdir[];
#endif
flushout();
flushout();
#ifndef TOS
# ifndef WIN32
enable_ctrlP(); /* in case this wasn't done */
# endif
#ifndef WIN32
enable_ctrlP(); /* in case this wasn't done */
#endif
#endif
#ifdef MFLOPPY
if (ramdisk) copybones(TOPERM);
if (ramdisk)
copybones(TOPERM);
#endif
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdir(orgdir); /* chdir, not chdirx */
chdrive(orgdir);
chdir(orgdir); /* chdir, not chdirx */
chdrive(orgdir);
#endif
#ifdef TOS
if (run_from_desktop)
getreturn("to continue"); /* so the user can read the score list */
# ifdef TEXTCOLOR
if (colors_changed)
restore_colors();
# endif
if (run_from_desktop)
getreturn("to continue"); /* so the user can read the score list */
#ifdef TEXTCOLOR
if (colors_changed)
restore_colors();
#endif
#endif
#ifdef WIN32
/* Only if we started from the GUI, not the command prompt,
* we need to get one last return, so the score board does
* not vanish instantly after being created.
* GUILaunched is defined and set in nttty.c.
*/
synch_cursor();
if (GUILaunched) getreturn("to end");
synch_cursor();
/* Only if we started from the GUI, not the command prompt,
* we need to get one last return, so the score board does
* not vanish instantly after being created.
* GUILaunched is defined and set in nttty.c.
*/
synch_cursor();
if (GUILaunched)
getreturn("to end");
synch_cursor();
#endif
return;
return;
}
#endif /* MICRO || WIN32 || OS2 */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 pctty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 pctty.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
/* NetHack 3.6 pctty.c $Date: 2009/05/06 10:50:30 $ $Revision: 1.6 $ */
/* SCCS Id: @(#)pctty.c 3.5 1990/22/02
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
@@ -6,7 +6,8 @@
/* tty.c - (PC) version */
#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers */
#define NEED_VARARGS /* Uses ... */ /* comment line for pre-compiled headers \
*/
#include "hack.h"
#include "wintty.h"
@@ -18,15 +19,16 @@ char erase_char, kill_char;
* Called by startup() in termcap.c and after returning from ! or ^Z
*/
void
gettty(){
erase_char = '\b';
kill_char = 21; /* cntl-U */
iflags.cbreak = TRUE;
#if !defined(TOS)
disable_ctrlP(); /* turn off ^P processing */
gettty()
{
erase_char = '\b';
kill_char = 21; /* cntl-U */
iflags.cbreak = TRUE;
#if !defined(TOS)
disable_ctrlP(); /* turn off ^P processing */
#endif
#if defined(MSDOS) && defined(NO_TERMS)
gr_init();
gr_init();
#endif
}
@@ -36,21 +38,21 @@ settty(s)
const char *s;
{
#if defined(MSDOS) && defined(NO_TERMS)
gr_finish();
gr_finish();
#endif
end_screen();
if(s) raw_print(s);
end_screen();
if (s)
raw_print(s);
#if !defined(TOS)
enable_ctrlP(); /* turn on ^P processing */
enable_ctrlP(); /* turn on ^P processing */
#endif
}
/* called by init_nhwindows() and resume_nhwindows() */
void
setftty()
{
start_screen();
start_screen();
}
#if defined(TIMED_DELAY) && defined(_MSC_VER)
@@ -58,30 +60,31 @@ void
msleep(mseconds)
unsigned mseconds;
{
/* now uses clock() which is ANSI C */
clock_t goal;
/* now uses clock() which is ANSI C */
clock_t goal;
goal = mseconds + clock();
while ( goal > clock()) {
/* do nothing */
}
goal = mseconds + clock();
while (goal > clock()) {
/* do nothing */
}
}
#endif
/* fatal error */
/*VARARGS1*/
void
error VA_DECL(const char *,s)
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited) end_screen();
putchar('\n');
Vprintf(s,VA_ARGS);
putchar('\n');
VA_END();
exit(EXIT_FAILURE);
void error
VA_DECL(const char *, s)
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited)
end_screen();
putchar('\n');
Vprintf(s, VA_ARGS);
putchar('\n');
VA_END();
exit(EXIT_FAILURE);
}
/*pctty.c*/

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 pcunix.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 pcunix.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */
/* NetHack 3.6 pcunix.c $Date: 2009/05/06 10:50:30 $ $Revision: 1.27 $ */
/* SCCS Id: @(#)pcunix.c 3.5 1994/11/07 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
@@ -9,16 +9,16 @@
#include "hack.h"
#include "wintty.h"
#include <sys/stat.h>
#include <sys/stat.h>
#if defined(WIN32) || defined(MSDOS)
#include <errno.h>
#include <errno.h>
#endif
#if defined(WIN32) || defined(MSDOS)
extern char orgdir[];
# ifdef WIN32
#ifdef WIN32
extern void NDECL(backsp);
# endif
#endif
extern void NDECL(clear_screen);
#endif
@@ -26,9 +26,9 @@ extern void NDECL(clear_screen);
static struct stat buf;
#endif
# ifdef WANT_GETHDATE
#ifdef WANT_GETHDATE
static struct stat hbuf;
# endif
#endif
#ifdef PC_LOCKING
static int NDECL(eraseoldlocks);
@@ -39,7 +39,7 @@ int
uptodate(fd)
int fd;
{
# ifdef WANT_GETHDATE
#ifdef WANT_GETHDATE
if(fstat(fd, &buf)) {
pline("Cannot get status of saved level? ");
return(0);
@@ -48,8 +48,8 @@ int fd;
pline("Saved level is out of date. ");
return(0);
}
# else
# if (defined(MICRO) || defined(WIN32)) && !defined(NO_FSTAT)
#else
#if (defined(MICRO) || defined(WIN32)) && !defined(NO_FSTAT)
if(fstat(fd, &buf)) {
if(moves > 1) pline("Cannot get status of saved level? ");
else pline("Cannot get status of saved game.");
@@ -61,14 +61,14 @@ int fd;
/* This problem occurs enough times we need to give the player
* some more information about what causes it, and how to fix.
*/
# ifdef MSDOS
#ifdef MSDOS
pline("Make sure that your system's date and time are correct.");
pline("They must be more current than NetHack.EXE's date/time stamp.");
# endif /* MSDOS */
#endif /* MSDOS */
return(0);
}
# endif /* MICRO */
# endif /* WANT_GETHDATE */
#endif /* MICRO */
#endif /* WANT_GETHDATE */
return(1);
}
#endif
@@ -77,193 +77,200 @@ int fd;
static int
eraseoldlocks()
{
register int i;
register int i;
/* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up
*/
for(i = 1; i <= MAXDUNGEON*MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
/* cannot use maxledgerno() here, because we need to find a lock name
* before starting everything (including the dungeon initialization
* that sets astral_level, needed for maxledgerno()) up
*/
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */
set_levelfile_name(lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0));
}
set_levelfile_name(lock, 0);
#ifdef HOLD_LOCKFILE_OPEN
really_close();
really_close();
#endif
if(unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return(1); /* success! */
if (unlink(fqname(lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */
return (1); /* success! */
}
void
getlock()
{
register int fd, c, ci, ct, ern;
int fcmask = FCMASK;
char tbuf[BUFSZ];
const char *fq_lock;
# if defined(MSDOS) && defined(NO_TERMS)
int grmode = iflags.grmode;
# endif
/* we ignore QUIT and INT at this point */
if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
wait_synch();
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("Quitting.");
}
register int fd, c, ci, ct, ern;
int fcmask = FCMASK;
char tbuf[BUFSZ];
const char *fq_lock;
#if defined(MSDOS) && defined(NO_TERMS)
int grmode = iflags.grmode;
#endif
/* we ignore QUIT and INT at this point */
if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
wait_synch();
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("Quitting.");
}
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf,"%s",fqname(lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1);
if((fd = open(fq_lock,0)) == -1) {
if(errno == ENOENT) goto gotlock; /* no such file */
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
# if defined(WIN32) || defined(HOLD_LOCKFILE_OPEN)
# if defined(HOLD_LOCKFILE_OPEN)
if(errno == EACCES) {
/* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1);
if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT)
goto gotlock; /* no such file */
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
#if defined(WIN32) || defined(HOLD_LOCKFILE_OPEN)
#if defined(HOLD_LOCKFILE_OPEN)
if (errno == EACCES) {
#define OOPS_BUFSZ 512
char oops[OOPS_BUFSZ];
Strcpy(oops,
"\nThere are files from a game in progress under your name.");
Strcat(oops, "\nThe files are locked or inaccessible.");
Strcat(oops, " Is the other game still running?\n");
if (strlen(fq_lock) < ((OOPS_BUFSZ -16) - strlen(oops)))
Sprintf(eos(oops), "Cannot open %s", fq_lock);
Strcat(oops, "\n");
unlock_file(HLOCK);
error(oops);
} else
# endif
error("Bad directory or name: %s\n%s\n",
fq_lock, strerror(errno));
# else
perror(fq_lock);
# endif
unlock_file(HLOCK);
error("Cannot open %s", fq_lock);
}
char oops[OOPS_BUFSZ];
Strcpy(
oops,
"\nThere are files from a game in progress under your name.");
Strcat(oops, "\nThe files are locked or inaccessible.");
Strcat(oops, " Is the other game still running?\n");
if (strlen(fq_lock) < ((OOPS_BUFSZ - 16) - strlen(oops)))
Sprintf(eos(oops), "Cannot open %s", fq_lock);
Strcat(oops, "\n");
unlock_file(HLOCK);
error(oops);
} else
#endif
error("Bad directory or name: %s\n%s\n", fq_lock,
strerror(errno));
#else
perror(fq_lock);
#endif
unlock_file(HLOCK);
error("Cannot open %s", fq_lock);
}
(void) nhclose(fd);
(void) nhclose(fd);
if(iflags.window_inited) {
# ifdef SELF_RECOVER
c = yn("There are files from a game in progress under your name. Recover?");
# else
pline("There is already a game in progress under your name.");
pline("You may be able to use \"recover %s\" to get it back.\n",tbuf);
c = yn("Do you want to destroy the old game?");
# endif
} else {
# if defined(MSDOS) && defined(NO_TERMS)
grmode = iflags.grmode;
if (grmode) gr_finish();
# endif
c = 'n';
ct = 0;
# ifdef SELF_RECOVER
msmsg(
"There are files from a game in progress under your name. Recover? [yn]");
# else
msmsg("\nThere is already a game in progress under your name.\n");
msmsg("If this is unexpected, you may be able to use \n");
msmsg("\"recover %s\" to get it back.",tbuf);
msmsg("\nDo you want to destroy the old game? [yn] ");
# endif
while ((ci=nhgetch()) != '\n') {
if (ct > 0) {
msmsg("\b \b");
ct = 0;
c = 'n';
}
if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
ct = 1;
c = ci;
msmsg("%c",c);
}
}
}
if(c == 'y' || c == 'Y')
# ifndef SELF_RECOVER
if(eraseoldlocks()) {
# if defined(WIN32)
if (!strncmpi(windowprocs.name, "tty", 3))
clear_screen(); /* display gets fouled up otherwise */
# endif
goto gotlock;
} else {
unlock_file(HLOCK);
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("Couldn't destroy old game.");
}
# else /*SELF_RECOVER*/
if(recover_savefile()) {
# if defined(WIN32)
if (!strncmpi(windowprocs.name, "tty", 3))
clear_screen(); /* display gets fouled up otherwise */
# endif
goto gotlock;
} else {
unlock_file(HLOCK);
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("Couldn't recover old game.");
}
# endif /*SELF_RECOVER*/
else {
unlock_file(HLOCK);
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("%s", "Cannot start a new game.");
}
if (iflags.window_inited) {
#ifdef SELF_RECOVER
c = yn("There are files from a game in progress under your name. "
"Recover?");
#else
pline("There is already a game in progress under your name.");
pline("You may be able to use \"recover %s\" to get it back.\n",
tbuf);
c = yn("Do you want to destroy the old game?");
#endif
} else {
#if defined(MSDOS) && defined(NO_TERMS)
grmode = iflags.grmode;
if (grmode)
gr_finish();
#endif
c = 'n';
ct = 0;
#ifdef SELF_RECOVER
msmsg("There are files from a game in progress under your name. "
"Recover? [yn]");
#else
msmsg("\nThere is already a game in progress under your name.\n");
msmsg("If this is unexpected, you may be able to use \n");
msmsg("\"recover %s\" to get it back.", tbuf);
msmsg("\nDo you want to destroy the old game? [yn] ");
#endif
while ((ci = nhgetch()) != '\n') {
if (ct > 0) {
msmsg("\b \b");
ct = 0;
c = 'n';
}
if (ci == 'y' || ci == 'n' || ci == 'Y' || ci == 'N') {
ct = 1;
c = ci;
msmsg("%c", c);
}
}
}
if (c == 'y' || c == 'Y')
#ifndef SELF_RECOVER
if (eraseoldlocks()) {
#if defined(WIN32)
if (!strncmpi(windowprocs.name, "tty", 3))
clear_screen(); /* display gets fouled up otherwise */
#endif
goto gotlock;
} else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("Couldn't destroy old game.");
}
#else /*SELF_RECOVER*/
if (recover_savefile()) {
#if defined(WIN32)
if (!strncmpi(windowprocs.name, "tty", 3))
clear_screen(); /* display gets fouled up otherwise */
#endif
goto gotlock;
} else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("Couldn't recover old game.");
}
#endif /*SELF_RECOVER*/
else {
unlock_file(HLOCK);
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("%s", "Cannot start a new game.");
}
gotlock:
fd = creat(fq_lock, fcmask);
if (fd == -1) ern = errno;
unlock_file(HLOCK);
if(fd == -1) {
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
# if defined(WIN32)
error("cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n",
fq_lock, strerror(ern), " Are you sure that the directory",
fqn_prefix[LEVELPREFIX]);
# else
error("cannot creat file (%s.)", fq_lock);
# endif
} else {
if(write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)){
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("cannot write lock (%s)", fq_lock);
}
if(nhclose(fd) == -1) {
# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
# endif
error("cannot close lock (%s)", fq_lock);
}
}
# if defined(MSDOS) && defined(NO_TERMS)
if (grmode) gr_init();
# endif
}
fd = creat(fq_lock, fcmask);
if (fd == -1)
ern = errno;
unlock_file(HLOCK);
if (fd == -1) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
#if defined(WIN32)
error("cannot creat file (%s.)\n%s\n%s\"%s\" exists?\n", fq_lock,
strerror(ern), " Are you sure that the directory",
fqn_prefix[LEVELPREFIX]);
#else
error("cannot creat file (%s.)", fq_lock);
#endif
} else {
if (write(fd, (char *) &hackpid, sizeof(hackpid))
!= sizeof(hackpid)) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("cannot write lock (%s)", fq_lock);
}
if (nhclose(fd) == -1) {
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
chdirx(orgdir, 0);
#endif
error("cannot close lock (%s)", fq_lock);
}
}
#if defined(MSDOS) && defined(NO_TERMS)
if (grmode)
gr_init();
#endif
}
#endif /* PC_LOCKING */
# ifndef WIN32
#ifndef WIN32
void
regularize(s)
/*
@@ -272,19 +279,23 @@ regularize(s)
*/
register char *s;
{
register char *lp;
register char *lp;
for (lp = s; *lp; lp++)
if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',') ||
*lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') ||
# ifdef OS2
*lp == '&' || *lp == '(' || *lp == ')' ||
# endif
*lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']'))
*lp = '_';
for (lp = s; *lp; lp++)
if (*lp <= ' ' || *lp == '"' || (*lp >= '*' && *lp <= ',')
|| *lp == '.' || *lp == '/' || (*lp >= ':' && *lp <= '?') ||
#ifdef OS2
*lp == '&' || *lp == '(' || *lp == ')' ||
#endif
*lp == '|' || *lp >= 127 || (*lp >= '[' && *lp <= ']'))
*lp = '_';
}
# endif /* WIN32 */
#endif /* WIN32 */
#ifdef __EMX__
void seteuid(int i){;}
void
seteuid(int i)
{
;
}
#endif

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 posixregex.c $NHDT-Date: 1428970913 2015/04/14 00:21:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */
/* NetHack 3.6 posixregex.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.2 $ */
/* Copyright (c) Sean Hunt 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -45,49 +45,59 @@
*/
struct nhregex {
regex_t re;
int err;
regex_t re;
int err;
};
struct nhregex *regex_init() {
return (struct nhregex *)alloc(sizeof (struct nhregex));
struct nhregex *
regex_init()
{
return (struct nhregex *) alloc(sizeof(struct nhregex));
}
boolean regex_compile(const char *s, struct nhregex *re) {
if (!re)
return FALSE;
if ((re->err = regcomp(&re->re, s, REG_EXTENDED | REG_NOSUB)))
return FALSE;
return TRUE;
boolean
regex_compile(const char *s, struct nhregex *re)
{
if (!re)
return FALSE;
if ((re->err = regcomp(&re->re, s, REG_EXTENDED | REG_NOSUB)))
return FALSE;
return TRUE;
}
const char *regex_error_desc(struct nhregex *re) {
static char buf[BUFSZ];
const char *
regex_error_desc(struct nhregex *re)
{
static char buf[BUFSZ];
if (!re || !re->err)
return (const char *)0;
if (!re || !re->err)
return (const char *) 0;
/* FIXME: Using a static buffer here is not ideal, but avoids memory
* leaks. Consider the allocation more carefully. */
regerror(re->err, &re->re, buf, BUFSZ);
/* FIXME: Using a static buffer here is not ideal, but avoids memory
* leaks. Consider the allocation more carefully. */
regerror(re->err, &re->re, buf, BUFSZ);
return buf;
return buf;
}
boolean regex_match(const char *s, struct nhregex *re) {
int result;
boolean
regex_match(const char *s, struct nhregex *re)
{
int result;
if (!re)
return FALSE;
if (!re)
return FALSE;
if ((result = regexec(&re->re, s, 0, (genericptr_t)0, 0))) {
if (result != REG_NOMATCH)
re->err = result;
return FALSE;
}
return TRUE;
if ((result = regexec(&re->re, s, 0, (genericptr_t) 0, 0))) {
if (result != REG_NOMATCH)
re->err = result;
return FALSE;
}
return TRUE;
}
void regex_free(struct nhregex *re) {
free(re);
void
regex_free(struct nhregex *re)
{
free(re);
}

View File

@@ -33,16 +33,16 @@
* - cast result of pointer subtraction to long since ptrdiff_t could
* be bigger than that and trigger warnings when assigning to long
*
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
* $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $
* $Date: 2007/12/23 00:59:25 $ $Revision: 1.2 $
*/
#include "hack.h"
#ifdef LIBC_SCCS
# ifndef lint
#ifndef lint
static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
# endif
#endif
#endif /* LIBC_SCCS and not lint */
/*
@@ -50,11 +50,13 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
* An improved random number generation package. In addition to the standard
* rand()/srand() like interface, this package also has a special state info
* interface. The initstate() routine is called with a seed, an array of
* bytes, and a count of how many bytes are being passed in; this array is then
* bytes, and a count of how many bytes are being passed in; this array is
* then
* initialized to contain information for random number generation with that
* much state information. Good sizes for the amount of state information are
* 32, 64, 128, and 256 bytes. The state can be switched by calling the
* setstate() routine with the same array as was initiallized with initstate().
* setstate() routine with the same array as was initiallized with
* initstate().
* By default, the package runs with 128 bytes of state information and
* generates far better random numbers than a linear congruential generator.
* If the amount of state information is less than 32 bytes, a simple linear
@@ -63,7 +65,7 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
* zeroeth element of the array is the type of R.N.G. being used (small
* integer); the remainder of the array is the state information for the
* R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
* state information, which will allow a degree seven polynomial. (Note: the
* state information, which will allow a degree seven polynomial. (Note: the
* zeroeth word of state information also has some other information stored
* in it -- see setstate() for details).
* The random number generation technique is a linear feedback shift register
@@ -82,8 +84,6 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
* predicted by this formula.
*/
/*
* For each of the currently supported random number generators, we have a
* break value on the amount of state information (you need at least this
@@ -92,46 +92,41 @@ static char sccsid[] = "@(#)random.c 5.5 (Berkeley) 7/6/88";
* the separation between the two lower order coefficients of the trinomial.
*/
#define TYPE_0 0 /* linear congruential */
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
#define TYPE_0 0 /* linear congruential */
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
#define TYPE_1 1 /* x**7 + x**3 + 1 */
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
#define TYPE_1 1 /* x**7 + x**3 + 1 */
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
#define TYPE_2 2 /* x**15 + x + 1 */
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
#define TYPE_2 2 /* x**15 + x + 1 */
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
#define TYPE_3 3 /* x**31 + x**3 + 1 */
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
#define TYPE_4 4 /* x**63 + x + 1 */
#define BREAK_4 256
#define DEG_4 63
#define SEP_4 1
#define TYPE_3 3 /* x**31 + x**3 + 1 */
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
#define TYPE_4 4 /* x**63 + x + 1 */
#define BREAK_4 256
#define DEG_4 63
#define SEP_4 1
/*
* Array versions of the above information to make code run faster -- relies
* on fact that TYPE_i == i.
*/
#define MAX_TYPES 5 /* max number of types above */
static int degrees[ MAX_TYPES ] = { DEG_0, DEG_1, DEG_2,
DEG_3, DEG_4 };
static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2,
SEP_3, SEP_4 };
#define MAX_TYPES 5 /* max number of types above */
static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/*
* Initially, everything is set up as if from :
@@ -144,21 +139,23 @@ static int seps[ MAX_TYPES ] = { SEP_0, SEP_1, SEP_2,
* MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3.
*/
static long randtbl[ DEG_3 + 1 ] = { TYPE_3,
0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342,
0xde3b81e0, 0xdf0a6fb5, 0xf103bc02, 0x48f340fb,
0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd,
0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86,
0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7,
0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc,
0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b,
0xf5ad9d0e, 0x8999220b, 0x27fb47b9 };
static long randtbl[DEG_3 + 1] = {
TYPE_3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0,
0xdf0a6fb5, 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918,
0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a,
0x1588ca88, 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96,
0xac94efdc, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e,
0x8999220b, 0x27fb47b9
};
/*
* fptr and rptr are two pointers into the state info, a front and a rear
* pointer. These two pointers are always rand_sep places aparts, as they cycle
* cyclically through the state information. (Yes, this does mean we could get
* away with just one pointer, but the code for random() is more efficient this
* pointer. These two pointers are always rand_sep places aparts, as they
*cycle
* cyclically through the state information. (Yes, this does mean we could
*get
* away with just one pointer, but the code for random() is more efficient
*this
* way). The pointers are left positioned as they would be from the call
* initstate( 1, randtbl, 128 )
* (The position of the rear pointer, rptr, is really 0 (as explained above
@@ -166,10 +163,8 @@ static long randtbl[ DEG_3 + 1 ] = { TYPE_3,
* to point to randtbl[1] (as explained below).
*/
static long *fptr = &randtbl[ SEP_3 + 1 ];
static long *rptr = &randtbl[ 1 ];
static long *fptr = &randtbl[SEP_3 + 1];
static long *rptr = &randtbl[1];
/*
* The following things are the pointer to the state information table,
@@ -183,15 +178,13 @@ static long *rptr = &randtbl[ 1 ];
* the front and rear pointers have wrapped.
*/
static long *state = &randtbl[ 1 ];
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
static long *end_ptr = &randtbl[ DEG_3 + 1 ];
static long *state = &randtbl[1];
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
static long *end_ptr = &randtbl[DEG_3 + 1];
/*
* srandom:
@@ -207,28 +200,26 @@ static long *end_ptr = &randtbl[ DEG_3 + 1 ];
*/
void
srandom( x )
srandom(x)
unsigned x;
unsigned x;
{
register int i;
register int i;
if( rand_type == TYPE_0 ) {
state[ 0 ] = x;
}
else {
state[ 0 ] = x;
for( i = 1; i < rand_deg; i++ ) {
state[i] = 1103515245*state[i - 1] + 12345;
}
fptr = &state[ rand_sep ];
rptr = &state[ 0 ];
for( i = 0; i < 10*rand_deg; i++ ) random();
}
if (rand_type == TYPE_0) {
state[0] = x;
} else {
state[0] = x;
for (i = 1; i < rand_deg; i++) {
state[i] = 1103515245 * state[i - 1] + 12345;
}
fptr = &state[rand_sep];
rptr = &state[0];
for (i = 0; i < 10 * rand_deg; i++)
random();
}
}
/*
* initstate:
* Initialize the state information in the given array of n bytes for
@@ -245,63 +236,62 @@ srandom( x )
* Returns a pointer to the old state.
*/
char *
initstate( seed, arg_state, n )
char *
initstate(seed, arg_state, n)
unsigned seed; /* seed for R. N. G. */
char *arg_state; /* pointer to state array */
int n; /* # bytes of state info */
unsigned seed; /* seed for R. N. G. */
char *arg_state; /* pointer to state array */
int n; /* # bytes of state info */
{
register char *ostate = (char *)( &state[ -1 ] );
register char *ostate = (char *) (&state[-1]);
if( rand_type == TYPE_0 ) state[ -1 ] = rand_type;
else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type);
if( n < BREAK_1 ) {
if( n < BREAK_0 ) {
impossible(
"initstate: not enough state (%d bytes) with which to do jack; ignored.", n);
return (char *)0;
}
rand_type = TYPE_0;
rand_deg = DEG_0;
rand_sep = SEP_0;
}
else {
if( n < BREAK_2 ) {
rand_type = TYPE_1;
rand_deg = DEG_1;
rand_sep = SEP_1;
}
else {
if( n < BREAK_3 ) {
rand_type = TYPE_2;
rand_deg = DEG_2;
rand_sep = SEP_2;
}
else {
if( n < BREAK_4 ) {
rand_type = TYPE_3;
rand_deg = DEG_3;
rand_sep = SEP_3;
}
else {
rand_type = TYPE_4;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
}
}
}
state = &( ( (long *)arg_state )[1] ); /* first location */
end_ptr = &state[ rand_deg ]; /* must set end_ptr before srandom */
srandom( seed );
if( rand_type == TYPE_0 ) state[ -1 ] = rand_type;
else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type);
return( ostate );
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type);
if (n < BREAK_1) {
if (n < BREAK_0) {
impossible("initstate: not enough state (%d bytes) with which to "
"do jack; ignored.",
n);
return (char *) 0;
}
rand_type = TYPE_0;
rand_deg = DEG_0;
rand_sep = SEP_0;
} else {
if (n < BREAK_2) {
rand_type = TYPE_1;
rand_deg = DEG_1;
rand_sep = SEP_1;
} else {
if (n < BREAK_3) {
rand_type = TYPE_2;
rand_deg = DEG_2;
rand_sep = SEP_2;
} else {
if (n < BREAK_4) {
rand_type = TYPE_3;
rand_deg = DEG_3;
rand_sep = SEP_3;
} else {
rand_type = TYPE_4;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
}
}
}
state = &(((long *) arg_state)[1]); /* first location */
end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
srandom(seed);
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type);
return (ostate);
}
/*
* setstate:
* Restore the state from the given state array.
@@ -314,44 +304,45 @@ initstate( seed, arg_state, n )
* Returns a pointer to the old state information.
*/
char *
setstate( arg_state )
char *
setstate(arg_state)
char *arg_state;
char *arg_state;
{
register long *new_state = (long *)arg_state;
register int type = new_state[0]%MAX_TYPES;
register int rear = new_state[0]/MAX_TYPES;
char *ostate = (char *)( &state[ -1 ] );
register long *new_state = (long *) arg_state;
register int type = new_state[0] % MAX_TYPES;
register int rear = new_state[0] / MAX_TYPES;
char *ostate = (char *) (&state[-1]);
if( rand_type == TYPE_0 ) state[ -1 ] = rand_type;
else state[ -1 ] = (long)(MAX_TYPES*(rptr - state) + rand_type);
switch( type ) {
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
rand_type = type;
rand_deg = degrees[ type ];
rand_sep = seps[ type ];
break;
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = (long) (MAX_TYPES * (rptr - state) + rand_type);
switch (type) {
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
rand_type = type;
rand_deg = degrees[type];
rand_sep = seps[type];
break;
default:
impossible("setstate: state info has been munged (%d); not changed.", type);
break;
}
state = &new_state[ 1 ];
if( rand_type != TYPE_0 ) {
rptr = &state[ rear ];
fptr = &state[ (rear + rand_sep)%rand_deg ];
}
end_ptr = &state[ rand_deg ]; /* set end_ptr too */
return( ostate );
default:
impossible("setstate: state info has been munged (%d); not changed.",
type);
break;
}
state = &new_state[1];
if (rand_type != TYPE_0) {
rptr = &state[rear];
fptr = &state[(rear + rand_sep) % rand_deg];
}
end_ptr = &state[rand_deg]; /* set end_ptr too */
return (ostate);
}
/*
* random:
* If we are using the trivial TYPE_0 R.N.G., just do the old linear
@@ -370,22 +361,20 @@ setstate( arg_state )
long
random()
{
long i;
if( rand_type == TYPE_0 ) {
i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff;
}
else {
*fptr += *rptr;
i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */
if( ++fptr >= end_ptr ) {
fptr = state;
++rptr;
}
else {
if( ++rptr >= end_ptr ) rptr = state;
}
}
return( i );
}
long i;
if (rand_type == TYPE_0) {
i = state[0] = (state[0] * 1103515245 + 12345) & 0x7fffffff;
} else {
*fptr += *rptr;
i = (*fptr >> 1) & 0x7fffffff; /* chucking least random bit */
if (++fptr >= end_ptr) {
fptr = state;
++rptr;
} else {
if (++rptr >= end_ptr)
rptr = state;
}
}
return (i);
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 tclib.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 tclib.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 tclib.c $Date: 2009/05/06 10:50:31 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)tclib.c 3.5 1996/02/25 */
/* Copyright (c) Robert Patrick Rankin, 1995 */
@@ -8,28 +8,28 @@
#include "config.h"
#ifndef TERMCAP /* name of default termcap file */
#ifndef TERMCAP /* name of default termcap file */
#define TERMCAP "/etc/termcap"
#endif
#ifndef TCBUFSIZ /* size of tgetent buffer; Unix man page says 1024 */
#ifndef TCBUFSIZ /* size of tgetent buffer; Unix man page says 1024 */
#define TCBUFSIZ 1024
#endif
#define ESC '\033' /* termcap's '\E' */
#define BEL '\007' /* ANSI C's '\a' (we assume ASCII here...) */
#define ESC '\033' /* termcap's '\E' */
#define BEL '\007' /* ANSI C's '\a' (we assume ASCII here...) */
/* exported variables, as per man page */
char PC;
char PC;
char *BC, *UP;
short ospeed;
/* exported routines */
int FDECL(tgetent, (char *,const char *));
int FDECL(tgetflag, (const char *));
int FDECL(tgetnum, (const char *));
char *FDECL(tgetstr, (const char *,char **));
char *FDECL(tgoto, (const char *,int,int));
char *FDECL(tparam, (const char *,char *,int,int,int,int,int));
void FDECL(tputs, (const char *,int,int (*)()));
int FDECL(tgetent, (char *, const char *));
int FDECL(tgetflag, (const char *));
int FDECL(tgetnum, (const char *));
char *FDECL(tgetstr, (const char *, char **));
char *FDECL(tgoto, (const char *, int, int));
char *FDECL(tparam, (const char *, char *, int, int, int, int, int));
void FDECL(tputs, (const char *, int, int (*)()));
/* local support data */
static char *tc_entry;
@@ -37,34 +37,34 @@ static char bc_up_buf[24];
#ifndef NO_DELAY_PADDING
/* `ospeed' to baud rate conversion table, adapted from GNU termcap-1.2 */
static short baud_rates[] = {
0, 50, 75, 110, 135, 150,
# ifdef VMS
300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200,
# else /* assume Unix */
200, 300, 600, 1200, 1800, 2400, 4800,
# endif
9600, -192, -384, /* negative is used as `100 * abs(entry)' */
# ifdef VMS
-576, -768, -1152,
# endif
0, 50, 75, 110, 135, 150,
#ifdef VMS
300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200,
#else /* assume Unix */
200, 300, 600, 1200, 1800, 2400, 4800,
#endif
9600, -192, -384, /* negative is used as `100 * abs(entry)' */
#ifdef VMS
-576, -768, -1152,
#endif
};
#endif /* !NO_DELAY_PADDING */
#endif /* !NO_DELAY_PADDING */
/* local support code */
static int FDECL(tc_store, (const char *,const char *));
static char *FDECL(tc_find, (FILE *,const char *,char *,int));
static char *FDECL(tc_name, (const char *,char *));
static const char *FDECL(tc_field, (const char *,const char **));
static int FDECL(tc_store, (const char *, const char *));
static char *FDECL(tc_find, (FILE *, const char *, char *, int));
static char *FDECL(tc_name, (const char *, char *));
static const char *FDECL(tc_field, (const char *, const char **));
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
/* retrieve the specified terminal entry and return it in `entbuf' */
int
tgetent(entbuf, term)
char *entbuf; /* size must be at least [TCBUFSIZ] */
const char *term;
char *entbuf; /* size must be at least [TCBUFSIZ] */
const char *term;
{
int result;
FILE *fp;
@@ -72,25 +72,26 @@ tgetent(entbuf, term)
tc_entry = entbuf;
if (!entbuf || !term)
return -1;
return -1;
/* if ${TERMCAP} is found as a file, it's not an inline termcap entry */
if ((fp = fopen(tc ? tc : TERMCAP, "r")) != 0)
tc = 0;
/* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP} */
tc = 0;
/* if ${TERMCAP} isn't a file and `term' matches ${TERM}, use ${TERMCAP}
*/
if (tc) {
char *tm = getenv("TERM");
if (tm && strcmp(tm, term) == 0)
return tc_store(term, tc);
fp = fopen(TERMCAP, "r");
char *tm = getenv("TERM");
if (tm && strcmp(tm, term) == 0)
return tc_store(term, tc);
fp = fopen(TERMCAP, "r");
}
/* otherwise, look `term' up in the file */
if (fp) {
char wrkbuf[TCBUFSIZ];
tc = tc_find(fp, term, wrkbuf, (int)(sizeof wrkbuf - strlen(term)));
result = tc_store(term, tc);
(void) fclose(fp);
char wrkbuf[TCBUFSIZ];
tc = tc_find(fp, term, wrkbuf, (int) (sizeof wrkbuf - strlen(term)));
result = tc_store(term, tc);
(void) fclose(fp);
} else {
result = -1;
result = -1;
}
return result;
}
@@ -98,7 +99,7 @@ tgetent(entbuf, term)
/* copy the entry into the output buffer */
static int
tc_store(trm, ent)
const char *trm, *ent;
const char *trm, *ent;
{
const char *bar, *col;
char *s;
@@ -106,31 +107,32 @@ tc_store(trm, ent)
int k;
if (!ent || !*ent || !trm || !*trm || (col = index(ent, ':')) == 0)
return 0;
return 0;
(void) strcpy(tc_entry, trm);
if (((bar = index(ent, '|')) != 0 && bar < col)
|| ((long)(n = strlen(trm)) == (long)(col - ent)
&& strncmp(ent, trm, n) == 0))
(void) strcat(tc_entry, col);
|| ((long) (n = strlen(trm)) == (long) (col - ent)
&& strncmp(ent, trm, n) == 0))
(void) strcat(tc_entry, col);
else if (*ent == ':')
(void) strcat(tc_entry, ent);
(void) strcat(tc_entry, ent);
else
(void) strcat(strcat(tc_entry, ":"), ent);
(void) strcat(strcat(tc_entry, ":"), ent);
/* initialize global variables */
k = tgetnum("pc");
PC = (k == -1) ? '\0' : (char)k;
PC = (k == -1) ? '\0' : (char) k;
BC = s = bc_up_buf;
if (!tgetstr("bc", &s)) (void)strcpy(s, "\b"), s += 2;
if (!tgetstr("bc", &s))
(void) strcpy(s, "\b"), s += 2;
UP = s;
(void)tgetstr("up", &s);
(void) tgetstr("up", &s);
#ifndef NO_DELAY_PADDING
/* caller must set `ospeed' */
if ((int)ospeed >= (int)SIZE(baud_rates))
ospeed = (short)(SIZE(baud_rates) - 1);
if ((int) ospeed >= (int) SIZE(baud_rates))
ospeed = (short) (SIZE(baud_rates) - 1);
else if (ospeed < 0)
ospeed = 0;
#endif /* !NO_DELAY_PADDING */
ospeed = 0;
#endif /* !NO_DELAY_PADDING */
return 1;
}
@@ -138,56 +140,60 @@ tc_store(trm, ent)
/* search for an entry in the termcap file */
static char *
tc_find(fp, term, buffer, bufsiz)
FILE *fp;
const char *term;
char *buffer;
int bufsiz;
FILE *fp;
const char *term;
char *buffer;
int bufsiz;
{
int in, len, first, skip;
char *ip, *op, *tc_fetch, tcbuf[TCBUFSIZ];
buffer[0] = '\0';
do {
ip = tcbuf, in = min(bufsiz,TCBUFSIZ);
first = 1, skip = 0;
/* load entire next entry, including any continuations */
do {
if (!fgets(ip, min(in,BUFSIZ), fp)) break;
if (first) skip = (*ip == '#'), first = 0;
len = (int)strlen(ip);
if (!skip && len > 1
&& *(ip + len - 1) == '\n' && *(ip + len - 2) == '\\')
len -= 2;
ip += len, in -= len;
} while (*(ip - 1) != '\n' && in > 0);
if (ferror(fp) || ip == buffer || *(ip - 1) != '\n')
return (char *)0;
*--ip = '\0'; /* strip newline */
if (!skip) ip = tc_name(term, tcbuf);
ip = tcbuf, in = min(bufsiz, TCBUFSIZ);
first = 1, skip = 0;
/* load entire next entry, including any continuations */
do {
if (!fgets(ip, min(in, BUFSIZ), fp))
break;
if (first)
skip = (*ip == '#'), first = 0;
len = (int) strlen(ip);
if (!skip && len > 1 && *(ip + len - 1) == '\n'
&& *(ip + len - 2) == '\\')
len -= 2;
ip += len, in -= len;
} while (*(ip - 1) != '\n' && in > 0);
if (ferror(fp) || ip == buffer || *(ip - 1) != '\n')
return (char *) 0;
*--ip = '\0'; /* strip newline */
if (!skip)
ip = tc_name(term, tcbuf);
} while (skip || !ip);
/* we have the desired entry; strip cruft and look for :tc=other: */
tc_fetch = 0;
for (op = buffer; *ip; ip++) {
if (op == buffer || *(op - 1) != ':'
|| (*ip != ' ' && *ip != '\t' && *ip != ':'))
*op++ = *ip, bufsiz -= 1;
if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') {
tc_fetch = &ip[4];
if ((ip = index(tc_fetch, ':')) != 0) *ip = '\0';
break;
}
if (op == buffer || *(op - 1) != ':'
|| (*ip != ' ' && *ip != '\t' && *ip != ':'))
*op++ = *ip, bufsiz -= 1;
if (ip[0] == ':' && ip[1] == 't' && ip[2] == 'c' && ip[3] == '=') {
tc_fetch = &ip[4];
if ((ip = index(tc_fetch, ':')) != 0)
*ip = '\0';
break;
}
}
*op = '\0';
if (tc_fetch) {
rewind(fp);
tc_fetch = tc_find(fp, tc_fetch, tcbuf, min(bufsiz,TCBUFSIZ));
if (!tc_fetch)
return (char *)0;
if (op > buffer && *(op - 1) == ':' && *tc_fetch == ':')
++tc_fetch;
strcpy(op, tc_fetch);
rewind(fp);
tc_fetch = tc_find(fp, tc_fetch, tcbuf, min(bufsiz, TCBUFSIZ));
if (!tc_fetch)
return (char *) 0;
if (op > buffer && *(op - 1) == ':' && *tc_fetch == ':')
++tc_fetch;
strcpy(op, tc_fetch);
}
return buffer;
}
@@ -195,37 +201,39 @@ tc_find(fp, term, buffer, bufsiz)
/* check whether `ent' contains `nam'; return start of field entries */
static char *
tc_name(nam, ent)
const char *nam;
char *ent;
const char *nam;
char *ent;
{
char *nxt, *lst, *p = ent;
size_t n = strlen(nam);
if ((lst = index(p, ':')) == 0) lst = p + strlen(p);
if ((lst = index(p, ':')) == 0)
lst = p + strlen(p);
while (p < lst) {
if ((nxt = index(p, '|')) == 0 || nxt > lst) nxt = lst;
if ((long)(nxt - p) == (long)n && strncmp(p, nam, n) == 0)
return lst;
p = nxt + 1;
if ((nxt = index(p, '|')) == 0 || nxt > lst)
nxt = lst;
if ((long) (nxt - p) == (long) n && strncmp(p, nam, n) == 0)
return lst;
p = nxt + 1;
}
return (char *)0;
return (char *) 0;
}
/* look up a numeric entry */
int
tgetnum(which)
const char *which;
const char *which;
{
const char *q, *p = tc_field(which, &q);
char numbuf[32];
size_t n;
if (!p || p[2] != '#')
return -1;
return -1;
p += 3;
if ((n = (size_t)(q - p)) >= sizeof numbuf)
return -1;
return -1;
(void) strncpy(numbuf, p, n);
numbuf[n] = '\0';
return atoi(numbuf);
@@ -234,9 +242,9 @@ tgetnum(which)
/* look up a boolean entry */
int
tgetflag(which)
const char *which;
const char *which;
{
const char *p = tc_field(which, (const char **)0);
const char *p = tc_field(which, (const char **) 0);
return (!p || p[2] != ':') ? 0 : 1;
}
@@ -244,48 +252,74 @@ tgetflag(which)
/* look up a string entry; update `*outptr' */
char *
tgetstr(which, outptr)
const char *which;
char **outptr;
const char *which;
char **outptr;
{
int n;
char c, *r, *result;
const char *q, *p = tc_field(which, &q);
if (!p || p[2] != '=')
return (char *)0;
return (char *) 0;
p += 3;
if ((q = index(p, ':')) == 0) q = p + strlen(p);
if ((q = index(p, ':')) == 0)
q = p + strlen(p);
r = result = *outptr;
while (p < q) {
switch ((*r = *p++)) {
case '\\':
switch ((c = *p++)) {
case 'E': *r = ESC; break;
case 'a': *r = BEL; break;
case 'b': *r = '\b'; break;
case 'f': *r = '\f'; break;
case 'n': *r = '\n'; break;
case 'r': *r = '\r'; break;
case 't': *r = '\t'; break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
n = c - '0';
if (*p >= '0' && *p <= '7') n = 8 * n + (*p++ - '0');
if (*p >= '0' && *p <= '7') n = 8 * n + (*p++ - '0');
*r = (char)n;
break;
/* case '^': case '\\': */
default: *r = c; break;
}
break;
case '^':
*r = (*p++ & 037);
if (!*r) *r = (char)'\200';
break;
default:
break;
}
++r;
switch ((*r = *p++)) {
case '\\':
switch ((c = *p++)) {
case 'E':
*r = ESC;
break;
case 'a':
*r = BEL;
break;
case 'b':
*r = '\b';
break;
case 'f':
*r = '\f';
break;
case 'n':
*r = '\n';
break;
case 'r':
*r = '\r';
break;
case 't':
*r = '\t';
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
n = c - '0';
if (*p >= '0' && *p <= '7')
n = 8 * n + (*p++ - '0');
if (*p >= '0' && *p <= '7')
n = 8 * n + (*p++ - '0');
*r = (char) n;
break;
/* case '^': case '\\': */
default:
*r = c;
break;
}
break;
case '^':
*r = (*p++ & 037);
if (!*r)
*r = (char) '\200';
break;
default:
break;
}
++r;
}
*r++ = '\0';
*outptr = r;
@@ -295,26 +329,27 @@ tgetstr(which, outptr)
/* look for a particular field name */
static const char *
tc_field(field, tc_end)
const char *field;
const char **tc_end;
const char *field;
const char **tc_end;
{
const char *end, *q, *p = tc_entry;
end = p + strlen(p);
while (p < end) {
if ((p = index(p, ':')) == 0)
break;
++p;
if (p[0] == field[0] && p[1] == field[1]
&& (p[2] == ':' || p[2] == '=' || p[2] == '#' || p[2] == '@'))
break;
if ((p = index(p, ':')) == 0)
break;
++p;
if (p[0] == field[0] && p[1] == field[1]
&& (p[2] == ':' || p[2] == '=' || p[2] == '#' || p[2] == '@'))
break;
}
if (tc_end) {
if (p) {
if ((q = index(p + 2, ':')) == 0) q = end;
} else
q = 0;
*tc_end = q;
if (p) {
if ((q = index(p + 2, ':')) == 0)
q = end;
} else
q = 0;
*tc_end = q;
}
return p;
}
@@ -324,19 +359,19 @@ static char cmbuf[64];
/* produce a string which will position the cursor at <row,col> if output */
char *
tgoto(cm, col, row)
const char *cm;
int col, row;
const char *cm;
int col, row;
{
return tparam(cm, cmbuf, (int)(sizeof cmbuf), row, col, 0, 0);
return tparam(cm, cmbuf, (int) (sizeof cmbuf), row, col, 0, 0);
}
/* format a parameterized string, ala sprintf */
char *
tparam(ctl, buf, buflen, row, col, row2, col2)
const char *ctl; /* parameter control string */
char *buf; /* output buffer */
int buflen; /* ought to have been `size_t'... */
int row, col, row2, col2;
const char *ctl; /* parameter control string */
char *buf; /* output buffer */
int buflen; /* ought to have been `size_t'... */
int row, col, row2, col2;
{
int atmp, ac, av[5];
char c, *r, *z, *bufend, numbuf[32];
@@ -345,138 +380,176 @@ tparam(ctl, buf, buflen, row, col, row2, col2)
int bc = 0, up = 0;
#endif
av[0] = row, av[1] = col, av[2] = row2, av[3] = col2, av[4] = 0;
av[0] = row, av[1] = col, av[2] = row2, av[3] = col2, av[4] = 0;
ac = 0;
r = buf, bufend = r + buflen - 1;
r = buf, bufend = r + buflen - 1;
while (*ctl) {
if ((*r = *ctl++) == '%') {
if (ac > 4) ac = 4;
fmt = 0;
switch ((c = *ctl++)) {
case '%': break; /* '%' already copied */
case 'd': fmt = "%d"; break;
case '2': fmt = "%02d"; break;
case '3': fmt = "%03d"; break;
case '+': /*FALLTHRU*/
case '.': *r = (char)av[ac++];
if (c == '+') *r += *ctl++;
if (!*r) {
*r = (char)'\200';
} else {
if ((*r = *ctl++) == '%') {
if (ac > 4)
ac = 4;
fmt = 0;
switch ((c = *ctl++)) {
case '%':
break; /* '%' already copied */
case 'd':
fmt = "%d";
break;
case '2':
fmt = "%02d";
break;
case '3':
fmt = "%03d";
break;
case '+': /*FALLTHRU*/
case '.':
*r = (char) av[ac++];
if (c == '+')
*r += *ctl++;
if (!*r) {
*r = (char) '\200';
} else {
#ifndef NO_SPECIAL_CHARS_FIXUP
/* avoid terminal driver intervention for
various control characters, to prevent
LF from becoming CR+LF, for instance; only
makes sense if this is a cursor positioning
sequence, but we have no way to check that */
while (index("\004\t\n\013\f\r", *r)) {
if (ac & 1) { /* row */
if (!UP || !*UP) break; /* can't fix */
++up; /* incr row now, later move up */
} else { /* column */
if (!BC || !*BC) break; /* can't fix */
++bc; /* incr column, later backspace */
}
(*r)++;
}
#endif /* !NO_SPECIAL_CHARS_FIXUP */
} break;
case '>': if (av[ac] > (*ctl++ & 0377))
av[ac] += *ctl;
++ctl; break;
case 'r': atmp = av[0]; av[0] = av[1]; av[1] = atmp;
atmp = av[2]; av[2] = av[3]; av[3] = atmp;
--r; break;
case 'i': ++av[0]; ++av[1]; ++av[2]; ++av[3];
--r; break;
case 'n': av[0] ^= 0140; av[1] ^= 0140;
av[2] ^= 0140; av[3] ^= 0140;
--r; break;
case 'B': av[0] = ((av[0] / 10) << 4) + (av[0] % 10);
av[1] = ((av[1] / 10) << 4) + (av[1] % 10);
av[2] = ((av[2] / 10) << 4) + (av[2] % 10);
av[3] = ((av[3] / 10) << 4) + (av[3] % 10);
--r; break;
case 'D': av[0] -= (av[0] & 15) << 1;
av[1] -= (av[1] & 15) << 1;
av[2] -= (av[2] & 15) << 1;
av[3] -= (av[3] & 15) << 1;
--r; break;
default: *++r = c; break; /* erroneous entry... */
}
if (fmt) {
(void) sprintf(numbuf, fmt, av[ac++]);
for (z = numbuf; *z && r <= bufend; z++)
*r++ = *z;
--r; /* will be re-incremented below */
}
}
if (++r > bufend)
return (char *)0;
/* avoid terminal driver intervention for
various control characters, to prevent
LF from becoming CR+LF, for instance; only
makes sense if this is a cursor positioning
sequence, but we have no way to check that */
while (index("\004\t\n\013\f\r", *r)) {
if (ac & 1) { /* row */
if (!UP || !*UP)
break; /* can't fix */
++up; /* incr row now, later move up */
} else { /* column */
if (!BC || !*BC)
break; /* can't fix */
++bc; /* incr column, later backspace */
}
(*r)++;
}
#endif /* !NO_SPECIAL_CHARS_FIXUP */
}
break;
case '>':
if (av[ac] > (*ctl++ & 0377))
av[ac] += *ctl;
++ctl;
break;
case 'r':
atmp = av[0];
av[0] = av[1];
av[1] = atmp;
atmp = av[2];
av[2] = av[3];
av[3] = atmp;
--r;
break;
case 'i':
++av[0];
++av[1];
++av[2];
++av[3];
--r;
break;
case 'n':
av[0] ^= 0140;
av[1] ^= 0140;
av[2] ^= 0140;
av[3] ^= 0140;
--r;
break;
case 'B':
av[0] = ((av[0] / 10) << 4) + (av[0] % 10);
av[1] = ((av[1] / 10) << 4) + (av[1] % 10);
av[2] = ((av[2] / 10) << 4) + (av[2] % 10);
av[3] = ((av[3] / 10) << 4) + (av[3] % 10);
--r;
break;
case 'D':
av[0] -= (av[0] & 15) << 1;
av[1] -= (av[1] & 15) << 1;
av[2] -= (av[2] & 15) << 1;
av[3] -= (av[3] & 15) << 1;
--r;
break;
default:
*++r = c;
break; /* erroneous entry... */
}
if (fmt) {
(void) sprintf(numbuf, fmt, av[ac++]);
for (z = numbuf; *z && r <= bufend; z++)
*r++ = *z;
--r; /* will be re-incremented below */
}
}
if (++r > bufend)
return (char *) 0;
}
#ifndef NO_SPECIAL_CHARS_FIXUP
if (bc || up) {
while (--bc >= 0)
for (z = BC; *z && r <= bufend; z++)
*r++ = *z;
while (--up >= 0)
for (z = UP; *z && r <= bufend; z++)
*r++ = *z;
if (r > bufend)
return (char *)0;
while (--bc >= 0)
for (z = BC; *z && r <= bufend; z++)
*r++ = *z;
while (--up >= 0)
for (z = UP; *z && r <= bufend; z++)
*r++ = *z;
if (r > bufend)
return (char *) 0;
}
#endif /* !NO_SPECIAL_CHARS_FIXUP */
#endif /* !NO_SPECIAL_CHARS_FIXUP */
*r = '\0';
return buf;
}
/* send a string to the terminal, possibly padded with trailing NULs */
void
tputs( string, range, output_func )
const char *string; /* characters to output */
int range; /* number of lines affected, used for `*' delays */
int (*output_func)(); /* actual output routine; return value ignored */
tputs(string, range, output_func)
const char *string; /* characters to output */
int range; /* number of lines affected, used for `*' delays */
int (*output_func)(); /* actual output routine; return value ignored */
{
register int c, num = 0;
register const char *p = string;
if (!p || !*p)
return;
return;
/* pick out padding prefix, if any */
if (*p >= '0' && *p <= '9') {
do { /* note: scale `num' by 10 to accommodate fraction */
num += (*p++ - '0'), num *= 10;
} while (*p >= '0' && *p <= '9');
if (*p == '.')
++p, num += (*p >= '0' && *p <= '9') ? (*p++ - '0') : 0;
if (*p == '*')
++p, num *= range;
do { /* note: scale `num' by 10 to accommodate fraction */
num += (*p++ - '0'), num *= 10;
} while (*p >= '0' && *p <= '9');
if (*p == '.')
++p, num += (*p >= '0' && *p <= '9') ? (*p++ - '0') : 0;
if (*p == '*')
++p, num *= range;
}
/* output the string */
while ((c = *p++) != '\0') {
if (c == '\200') c = '\0'; /* undo tgetstr's encoding */
(void) (*output_func)(c);
if (c == '\200')
c = '\0'; /* undo tgetstr's encoding */
(void) (*output_func)(c);
}
#ifndef NO_DELAY_PADDING
/* perform padding */
if (num) {
long pad;
long pad;
/* figure out how many chars needed to produce desired elapsed time */
pad = (long)baud_rates[ospeed];
if (pad < 0) pad *= -100L;
pad *= (long)num;
/* 100000 == 10 bits/char * (1000 millisec/sec scaled by 10) */
num = (int)(pad / 100000L); /* number of characters */
/* figure out how many chars needed to produce desired elapsed time */
pad = (long) baud_rates[ospeed];
if (pad < 0)
pad *= -100L;
pad *= (long) num;
/* 100000 == 10 bits/char * (1000 millisec/sec scaled by 10) */
num = (int) (pad / 100000L); /* number of characters */
c = PC; /* assume output_func isn't allowed to change PC */
while (--num >= 0)
(void) (*output_func)(c);
c = PC; /* assume output_func isn't allowed to change PC */
while (--num >= 0)
(void) (*output_func)(c);
}
#endif /* !NO_DELAY_PADDING */
#endif /* !NO_DELAY_PADDING */
return;
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 unixtty.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 unixtty.c $NHDT-Date: 1431192779 2015/05/09 17:32:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.17 $ */
/* NetHack 3.6 unixtty.c $Date: 2012/01/23 07:11:09 $ $Revision: 1.10 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
@@ -17,124 +17,126 @@
* BSD still has the old sgttyb structure, but SYSV has termio. Thus:
*/
#if (defined(BSD) || defined(ULTRIX)) && !defined(POSIX_TYPES)
# define V7
#define V7
#else
# define USG
#define USG
#endif
#ifdef USG
# ifdef POSIX_TYPES
# include <termios.h>
# include <unistd.h>
# define termstruct termios
# else
# include <termio.h>
# if defined(TCSETS) && !defined(AIX_31)
# define termstruct termios
# else
# define termstruct termio
# endif
# endif /* POSIX_TYPES */
# ifdef LINUX
# include <sys/ioctl.h>
# undef delay_output /* curses redefines this */
# include <curses.h>
# endif
# define kill_sym c_cc[VKILL]
# define erase_sym c_cc[VERASE]
# define intr_sym c_cc[VINTR]
# ifdef TAB3 /* not a POSIX flag, but some have it anyway */
# define EXTABS TAB3
# else
# define EXTABS 0
# endif
# define tabflgs c_oflag
# define echoflgs c_lflag
# define cbrkflgs c_lflag
# define CBRKMASK ICANON
# define CBRKON ! /* reverse condition */
# ifdef POSIX_TYPES
# define OSPEED(x) (speednum(cfgetospeed(&x)))
# else
# ifndef CBAUD
# define CBAUD _CBAUD /* for POSIX nitpickers (like RS/6000 cc) */
# endif
# define OSPEED(x) ((x).c_cflag & CBAUD)
# endif
# define IS_7BIT(x) ((x).c_cflag & CS7)
# define inputflags c_iflag
# define STRIPHI ISTRIP
# ifdef POSIX_TYPES
# define GTTY(x) (tcgetattr(0, x))
# define STTY(x) (tcsetattr(0, TCSADRAIN, x))
# else
# if defined(TCSETS) && !defined(AIX_31)
# define GTTY(x) (ioctl(0, TCGETS, x))
# define STTY(x) (ioctl(0, TCSETSW, x))
# else
# define GTTY(x) (ioctl(0, TCGETA, x))
# define STTY(x) (ioctl(0, TCSETAW, x))
# endif
# endif /* POSIX_TYPES */
# define GTTY2(x) 1
# define STTY2(x) 1
# ifdef POSIX_TYPES
# if defined(BSD) && !defined(__DGUX__)
# define nonesuch _POSIX_VDISABLE
# else
# define nonesuch (fpathconf(0, _PC_VDISABLE))
# endif
# else
# define nonesuch 0
# endif
# define inittyb2 inittyb
# define curttyb2 curttyb
#ifdef POSIX_TYPES
#include <termios.h>
#include <unistd.h>
#define termstruct termios
#else
#include <termio.h>
#if defined(TCSETS) && !defined(AIX_31)
#define termstruct termios
#else
#define termstruct termio
#endif
#endif /* POSIX_TYPES */
#ifdef LINUX
#include <sys/ioctl.h>
#undef delay_output /* curses redefines this */
#include <curses.h>
#endif
#define kill_sym c_cc[VKILL]
#define erase_sym c_cc[VERASE]
#define intr_sym c_cc[VINTR]
#ifdef TAB3 /* not a POSIX flag, but some have it anyway */
#define EXTABS TAB3
#else
#define EXTABS 0
#endif
#define tabflgs c_oflag
#define echoflgs c_lflag
#define cbrkflgs c_lflag
#define CBRKMASK ICANON
#define CBRKON !/* reverse condition */
#ifdef POSIX_TYPES
#define OSPEED(x) (speednum(cfgetospeed(&x)))
#else
#ifndef CBAUD
#define CBAUD _CBAUD /* for POSIX nitpickers (like RS/6000 cc) */
#endif
#define OSPEED(x) ((x).c_cflag & CBAUD)
#endif
#define IS_7BIT(x) ((x).c_cflag & CS7)
#define inputflags c_iflag
#define STRIPHI ISTRIP
#ifdef POSIX_TYPES
#define GTTY(x) (tcgetattr(0, x))
#define STTY(x) (tcsetattr(0, TCSADRAIN, x))
#else
#if defined(TCSETS) && !defined(AIX_31)
#define GTTY(x) (ioctl(0, TCGETS, x))
#define STTY(x) (ioctl(0, TCSETSW, x))
#else
#define GTTY(x) (ioctl(0, TCGETA, x))
#define STTY(x) (ioctl(0, TCSETAW, x))
#endif
#endif /* POSIX_TYPES */
#define GTTY2(x) 1
#define STTY2(x) 1
#ifdef POSIX_TYPES
#if defined(BSD) && !defined(__DGUX__)
#define nonesuch _POSIX_VDISABLE
#else
#define nonesuch (fpathconf(0, _PC_VDISABLE))
#endif
#else
#define nonesuch 0
#endif
#define inittyb2 inittyb
#define curttyb2 curttyb
#else /* V7 */
#else /* V7 */
# include <sgtty.h>
# define termstruct sgttyb
# define kill_sym sg_kill
# define erase_sym sg_erase
# define intr_sym t_intrc
# define EXTABS XTABS
# define tabflgs sg_flags
# define echoflgs sg_flags
# define cbrkflgs sg_flags
# define CBRKMASK CBREAK
# define CBRKON /* empty */
# define inputflags sg_flags /* don't know how enabling meta bits */
# define IS_7BIT(x) (FALSE)
# define STRIPHI 0 /* should actually be done on BSD */
# define OSPEED(x) (x).sg_ospeed
# if defined(bsdi) || defined(__386BSD) || defined(SUNOS4)
# define GTTY(x) (ioctl(0, TIOCGETP, (char *)x))
# define STTY(x) (ioctl(0, TIOCSETP, (char *)x))
# else
# define GTTY(x) (gtty(0, x))
# define STTY(x) (stty(0, x))
# endif
# define GTTY2(x) (ioctl(0, TIOCGETC, (char *)x))
# define STTY2(x) (ioctl(0, TIOCSETC, (char *)x))
# define nonesuch -1
#include <sgtty.h>
#define termstruct sgttyb
#define kill_sym sg_kill
#define erase_sym sg_erase
#define intr_sym t_intrc
#define EXTABS XTABS
#define tabflgs sg_flags
#define echoflgs sg_flags
#define cbrkflgs sg_flags
#define CBRKMASK CBREAK
#define CBRKON /* empty */
#define inputflags sg_flags /* don't know how enabling meta bits */
#define IS_7BIT(x) (FALSE)
#define STRIPHI 0 /* should actually be done on BSD */
#define OSPEED(x) (x).sg_ospeed
#if defined(bsdi) || defined(__386BSD) || defined(SUNOS4)
#define GTTY(x) (ioctl(0, TIOCGETP, (char *) x))
#define STTY(x) (ioctl(0, TIOCSETP, (char *) x))
#else
#define GTTY(x) (gtty(0, x))
#define STTY(x) (stty(0, x))
#endif
#define GTTY2(x) (ioctl(0, TIOCGETC, (char *) x))
#define STTY2(x) (ioctl(0, TIOCSETC, (char *) x))
#define nonesuch -1
struct tchars inittyb2, curttyb2;
#endif /* V7 */
#endif /* V7 */
#if defined(TTY_GRAPHICS) && ((!defined(SYSV) && !defined(HPUX)) || defined(UNIXPC) || defined(SVR4))
# ifndef LINT
extern /* it is defined in libtermlib (libtermcap) */
# endif
short ospeed; /* terminal baudrate; set by gettty */
#if defined(TTY_GRAPHICS) && ((!defined(SYSV) && !defined(HPUX)) \
|| defined(UNIXPC) || defined(SVR4))
#ifndef LINT
extern /* it is defined in libtermlib (libtermcap) */
#endif
short ospeed; /* terminal baudrate; set by gettty */
#else
short ospeed = 0; /* gets around "not defined" error message */
short ospeed = 0; /* gets around "not defined" error message */
#endif
#if defined(POSIX_TYPES) && defined(BSD)
unsigned
#endif
char erase_char, intr_char, kill_char;
char erase_char,
intr_char, kill_char;
static boolean settty_needed = FALSE;
struct termstruct inittyb, curttyb;
@@ -143,34 +145,50 @@ static int
speednum(speed)
speed_t speed;
{
switch (speed) {
case B0: return 0;
case B50: return 1;
case B75: return 2;
case B110: return 3;
case B134: return 4;
case B150: return 5;
case B200: return 6;
case B300: return 7;
case B600: return 8;
case B1200: return 9;
case B1800: return 10;
case B2400: return 11;
case B4800: return 12;
case B9600: return 13;
case B19200: return 14;
case B38400: return 15;
}
switch (speed) {
case B0:
return 0;
case B50:
return 1;
case B75:
return 2;
case B110:
return 3;
case B134:
return 4;
case B150:
return 5;
case B200:
return 6;
case B300:
return 7;
case B600:
return 8;
case B1200:
return 9;
case B1800:
return 10;
case B2400:
return 11;
case B4800:
return 12;
case B9600:
return 13;
case B19200:
return 14;
case B38400:
return 15;
}
return 0;
return 0;
}
#endif
static void
setctty()
{
if(STTY(&curttyb) < 0 || STTY2(&curttyb2) < 0)
perror("NetHack (setctty)");
if (STTY(&curttyb) < 0 || STTY2(&curttyb2) < 0)
perror("NetHack (setctty)");
}
/*
@@ -181,22 +199,22 @@ setctty()
void
gettty()
{
if(GTTY(&inittyb) < 0 || GTTY2(&inittyb2) < 0)
perror("NetHack (gettty)");
curttyb = inittyb;
curttyb2 = inittyb2;
ospeed = OSPEED(inittyb);
erase_char = inittyb.erase_sym;
kill_char = inittyb.kill_sym;
intr_char = inittyb2.intr_sym;
getioctls();
if (GTTY(&inittyb) < 0 || GTTY2(&inittyb2) < 0)
perror("NetHack (gettty)");
curttyb = inittyb;
curttyb2 = inittyb2;
ospeed = OSPEED(inittyb);
erase_char = inittyb.erase_sym;
kill_char = inittyb.kill_sym;
intr_char = inittyb2.intr_sym;
getioctls();
/* do not expand tabs - they might be needed inside a cm sequence */
if(curttyb.tabflgs & EXTABS) {
curttyb.tabflgs &= ~EXTABS;
setctty();
}
settty_needed = TRUE;
/* do not expand tabs - they might be needed inside a cm sequence */
if (curttyb.tabflgs & EXTABS) {
curttyb.tabflgs &= ~EXTABS;
setctty();
}
settty_needed = TRUE;
}
/* reset terminal to original state */
@@ -204,115 +222,115 @@ void
settty(s)
const char *s;
{
end_screen();
if(s) raw_print(s);
if(STTY(&inittyb) < 0 || STTY2(&inittyb2) < 0)
perror("NetHack (settty)");
iflags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF;
iflags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF;
curttyb.inputflags |= STRIPHI;
setioctls();
end_screen();
if (s)
raw_print(s);
if (STTY(&inittyb) < 0 || STTY2(&inittyb2) < 0)
perror("NetHack (settty)");
iflags.echo = (inittyb.echoflgs & ECHO) ? ON : OFF;
iflags.cbreak = (CBRKON(inittyb.cbrkflgs & CBRKMASK)) ? ON : OFF;
curttyb.inputflags |= STRIPHI;
setioctls();
}
void
setftty()
{
unsigned ef, cf;
int change = 0;
unsigned ef, cf;
int change = 0;
ef = 0; /* desired value of flags & ECHO */
cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */
iflags.cbreak = ON;
iflags.echo = OFF;
/* Should use (ECHO|CRMOD) here instead of ECHO */
if ((unsigned)(curttyb.echoflgs & ECHO) != ef) {
curttyb.echoflgs &= ~ECHO;
/* curttyb.echoflgs |= ef; */
change++;
}
if ((unsigned)(curttyb.cbrkflgs & CBRKMASK) != cf) {
curttyb.cbrkflgs &= ~CBRKMASK;
curttyb.cbrkflgs |= cf;
ef = 0; /* desired value of flags & ECHO */
cf = CBRKON(CBRKMASK); /* desired value of flags & CBREAK */
iflags.cbreak = ON;
iflags.echo = OFF;
/* Should use (ECHO|CRMOD) here instead of ECHO */
if ((unsigned) (curttyb.echoflgs & ECHO) != ef) {
curttyb.echoflgs &= ~ECHO;
/* curttyb.echoflgs |= ef; */
change++;
}
if ((unsigned) (curttyb.cbrkflgs & CBRKMASK) != cf) {
curttyb.cbrkflgs &= ~CBRKMASK;
curttyb.cbrkflgs |= cf;
#ifdef USG
/* be satisfied with one character; no timeout */
curttyb.c_cc[VMIN] = 1; /* was VEOF */
curttyb.c_cc[VTIME] = 0; /* was VEOL */
# ifdef POSIX_JOB_CONTROL
/* turn off system suspend character
* due to differences in structure layout, this has to be
* here instead of in ioctl.c:getioctls() with the BSD
* equivalent
*/
# ifdef VSUSP /* real POSIX */
curttyb.c_cc[VSUSP] = nonesuch;
# else /* other later SYSV */
curttyb.c_cc[VSWTCH] = nonesuch;
# endif
# endif
# ifdef VDSUSP /* SunOS Posix extensions */
curttyb.c_cc[VDSUSP] = nonesuch;
# endif
# ifdef VREPRINT
curttyb.c_cc[VREPRINT] = nonesuch;
# endif
# ifdef VDISCARD
curttyb.c_cc[VDISCARD] = nonesuch;
# endif
# ifdef VWERASE
curttyb.c_cc[VWERASE] = nonesuch;
# endif
# ifdef VLNEXT
curttyb.c_cc[VLNEXT] = nonesuch;
# endif
/* be satisfied with one character; no timeout */
curttyb.c_cc[VMIN] = 1; /* was VEOF */
curttyb.c_cc[VTIME] = 0; /* was VEOL */
#ifdef POSIX_JOB_CONTROL
/* turn off system suspend character
* due to differences in structure layout, this has to be
* here instead of in ioctl.c:getioctls() with the BSD
* equivalent
*/
#ifdef VSUSP /* real POSIX */
curttyb.c_cc[VSUSP] = nonesuch;
#else /* other later SYSV */
curttyb.c_cc[VSWTCH] = nonesuch;
#endif
change++;
}
if(!IS_7BIT(inittyb)) curttyb.inputflags &=~ STRIPHI;
/* If an interrupt character is used, it will be overriden and
* set to ^C.
*/
if(intr_char != nonesuch && curttyb2.intr_sym != '\003') {
curttyb2.intr_sym = '\003';
change++;
}
#endif
#ifdef VDSUSP /* SunOS Posix extensions */
curttyb.c_cc[VDSUSP] = nonesuch;
#endif
#ifdef VREPRINT
curttyb.c_cc[VREPRINT] = nonesuch;
#endif
#ifdef VDISCARD
curttyb.c_cc[VDISCARD] = nonesuch;
#endif
#ifdef VWERASE
curttyb.c_cc[VWERASE] = nonesuch;
#endif
#ifdef VLNEXT
curttyb.c_cc[VLNEXT] = nonesuch;
#endif
#endif
change++;
}
if (!IS_7BIT(inittyb))
curttyb.inputflags &= ~STRIPHI;
/* If an interrupt character is used, it will be overriden and
* set to ^C.
*/
if (intr_char != nonesuch && curttyb2.intr_sym != '\003') {
curttyb2.intr_sym = '\003';
change++;
}
if(change) setctty();
start_screen();
if (change)
setctty();
start_screen();
}
void
intron() /* enable kbd interupts if enabled when game started */
void intron() /* enable kbd interupts if enabled when game started */
{
#ifdef TTY_GRAPHICS
/* Ugly hack to keep from changing tty modes for non-tty games -dlc */
if (!strcmp(windowprocs.name, "tty") &&
intr_char != nonesuch && curttyb2.intr_sym != '\003') {
curttyb2.intr_sym = '\003';
setctty();
}
/* Ugly hack to keep from changing tty modes for non-tty games -dlc */
if (!strcmp(windowprocs.name, "tty") && intr_char != nonesuch
&& curttyb2.intr_sym != '\003') {
curttyb2.intr_sym = '\003';
setctty();
}
#endif
}
void
introff() /* disable kbd interrupts if required*/
void introff() /* disable kbd interrupts if required*/
{
#ifdef TTY_GRAPHICS
/* Ugly hack to keep from changing tty modes for non-tty games -dlc */
if (!strcmp(windowprocs.name, "tty") &&
curttyb2.intr_sym != nonesuch) {
curttyb2.intr_sym = nonesuch;
setctty();
}
/* Ugly hack to keep from changing tty modes for non-tty games -dlc */
if (!strcmp(windowprocs.name, "tty") && curttyb2.intr_sym != nonesuch) {
curttyb2.intr_sym = nonesuch;
setctty();
}
#endif
}
#ifdef _M_UNIX /* SCO UNIX (3.2.4), from Andreas Arens */
# include <sys/console.h>
#ifdef _M_UNIX /* SCO UNIX (3.2.4), from Andreas Arens */
#include <sys/console.h>
# define BSIZE (E_TABSZ*2)
# define LDIOC ('D'<<8) /* POSIX prevents definition */
#define BSIZE (E_TABSZ * 2)
#define LDIOC ('D' << 8) /* POSIX prevents definition */
# include <sys/emap.h>
#include <sys/emap.h>
int sco_flag_console = 0;
int sco_map_valid = -1;
@@ -326,60 +344,59 @@ void NDECL(init_sco_cons);
void
sco_mapon()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
if (sco_map_valid != -1) {
ioctl(0,LDSMAP,sco_chanmap_buf);
}
sco_map_valid = -1;
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
if (sco_map_valid != -1) {
ioctl(0, LDSMAP, sco_chanmap_buf);
}
sco_map_valid = -1;
}
#endif
}
void
sco_mapoff()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
sco_map_valid = ioctl(0,LDGMAP,sco_chanmap_buf);
if (sco_map_valid != -1) {
ioctl(0,LDNMAP,(char *)0);
}
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
sco_map_valid = ioctl(0, LDGMAP, sco_chanmap_buf);
if (sco_map_valid != -1) {
ioctl(0, LDNMAP, (char *) 0);
}
}
#endif
}
void
check_sco_console()
{
if (isatty(0) && ioctl(0,CONS_GET,0) != -1) {
sco_flag_console = 1;
}
if (isatty(0) && ioctl(0, CONS_GET, 0) != -1) {
sco_flag_console = 1;
}
}
void
init_sco_cons()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
atexit(sco_mapon);
sco_mapoff();
load_symset("IBMGraphics", PRIMARY);
load_symset("RogueIBM", ROGUESET);
switch_symbols(TRUE);
# ifdef TEXTCOLOR
if (has_colors())
iflags.use_color = TRUE;
# endif
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && sco_flag_console) {
atexit(sco_mapon);
sco_mapoff();
load_symset("IBMGraphics", PRIMARY);
load_symset("RogueIBM", ROGUESET);
switch_symbols(TRUE);
#ifdef TEXTCOLOR
if (has_colors())
iflags.use_color = TRUE;
#endif
}
#endif
}
#endif /* _M_UNIX */
#endif /* _M_UNIX */
#ifdef __linux__ /* via Jesse Thilo and Ben Gertzfield */
# include <sys/vt.h>
# include <sys/ioctl.h>
#ifdef __linux__ /* via Jesse Thilo and Ben Gertzfield */
#include <sys/vt.h>
#include <sys/ioctl.h>
int linux_flag_console = 0;
@@ -391,62 +408,61 @@ void NDECL(init_linux_cons);
void
linux_mapon()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
write(1, "\033(B", 3);
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
write(1, "\033(B", 3);
}
#endif
}
void
linux_mapoff()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
write(1, "\033(U", 3);
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
write(1, "\033(U", 3);
}
#endif
}
void
check_linux_console()
{
struct vt_mode vtm;
struct vt_mode vtm;
if (isatty(0) && ioctl(0,VT_GETMODE,&vtm) >= 0) {
linux_flag_console = 1;
}
if (isatty(0) && ioctl(0, VT_GETMODE, &vtm) >= 0) {
linux_flag_console = 1;
}
}
void
init_linux_cons()
{
# ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
atexit(linux_mapon);
linux_mapoff();
# ifdef TEXTCOLOR
if (has_colors())
iflags.use_color = TRUE;
# endif
}
# endif
#ifdef TTY_GRAPHICS
if (!strcmp(windowprocs.name, "tty") && linux_flag_console) {
atexit(linux_mapon);
linux_mapoff();
#ifdef TEXTCOLOR
if (has_colors())
iflags.use_color = TRUE;
#endif
}
#endif
}
#endif /* __linux__ */
#endif /* __linux__ */
#ifndef __begui__ /* the Be GUI will define its own error proc */
#ifndef __begui__ /* the Be GUI will define its own error proc */
/* fatal error */
/*VARARGS1*/
void
error VA_DECL(const char *,s)
VA_START(s);
VA_INIT(s, const char *);
if(settty_needed)
settty((char *)0);
Vprintf(s,VA_ARGS);
(void) putchar('\n');
VA_END();
exit(EXIT_FAILURE);
void error
VA_DECL(const char *, s)
VA_START(s);
VA_INIT(s, const char *);
if (settty_needed)
settty((char *) 0);
Vprintf(s, VA_ARGS);
(void) putchar('\n');
VA_END();
exit(EXIT_FAILURE);
}
#endif /* !__begui__ */

View File

@@ -32,7 +32,7 @@
* but other programs such as zoo or arc may or may not require the file
* to be "BILFed" (or "unBILFed" or whatever). Also, unlike the other
* flavors, VMS files don't get overwritten (a higher version is created).
*
*
* Modified 13 April 1991 by Gary Mussar to be forgiving of systems that
* appear to be stripping trailing blanks.
*
@@ -41,7 +41,7 @@
* Modified 08 July 2006 to cast strlen() result to int to suppress a
* warning on platforms where size_t > sizeof(int).
*
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
* $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $
* $Date: 2006/07/09 16:42:21 $ $Revision: 1.4 $
*/
@@ -49,7 +49,7 @@
static char sccsid[] = "@(#)uudecode.c 5.5 (Berkeley) 7/6/88";
#endif /* not lint */
#ifdef __MSDOS__ /* For Turbo C */
#ifdef __MSDOS__ /* For Turbo C */
#define MSDOS 1
#endif
@@ -70,108 +70,110 @@ static char sccsid[] = "@(#)uudecode.c 5.5 (Berkeley) 7/6/88";
#include <stdio.h>
#ifdef VMS
# include <types.h>
# include <stat.h>
#include <types.h>
#include <stat.h>
#else
# if !defined(MSDOS) && !defined(WIN32)
# include <pwd.h>
# endif
# include <sys/types.h> /* MSDOS, WIN32, or UNIX */
# include <sys/stat.h>
# include <string.h>
# include <stdlib.h>
#if !defined(MSDOS) && !defined(WIN32)
#include <pwd.h>
#endif
#include <sys/types.h> /* MSDOS, WIN32, or UNIX */
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#endif
static void decode(FILE *, FILE *);
static void outdec(char *, FILE *, int);
/* single-character decode */
#define DEC(c) (((c) - ' ') & 077)
#define DEC(c) (((c) - ' ') & 077)
int main(argc, argv)
int
main(argc, argv)
int argc;
char **argv;
{
FILE *in, *out;
int mode;
char dest[128];
char buf[80];
FILE *in, *out;
int mode;
char dest[128];
char buf[80];
/* optional input arg */
if (argc > 1) {
if ((in = fopen(argv[1], "r")) == NULL) {
perror(argv[1]);
exit(1);
}
argv++; argc--;
} else
in = stdin;
/* optional input arg */
if (argc > 1) {
if ((in = fopen(argv[1], "r")) == NULL) {
perror(argv[1]);
exit(1);
}
argv++;
argc--;
} else
in = stdin;
if (argc != 1) {
printf("Usage: uudecode [infile]\n");
exit(2);
}
if (argc != 1) {
printf("Usage: uudecode [infile]\n");
exit(2);
}
/* search for header line */
for (;;) {
if (fgets(buf, sizeof buf, in) == NULL) {
fprintf(stderr, "No begin line\n");
exit(3);
}
if (strncmp(buf, "begin ", 6) == 0)
break;
}
(void)sscanf(buf, "begin %o %s", &mode, dest);
/* search for header line */
for (;;) {
if (fgets(buf, sizeof buf, in) == NULL) {
fprintf(stderr, "No begin line\n");
exit(3);
}
if (strncmp(buf, "begin ", 6) == 0)
break;
}
(void) sscanf(buf, "begin %o %s", &mode, dest);
#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
/* handle ~user/file format */
if (dest[0] == '~') {
char *sl;
struct passwd *getpwnam();
struct passwd *user;
char dnbuf[100], *index(), *strcat(), *strcpy();
/* handle ~user/file format */
if (dest[0] == '~') {
char *sl;
struct passwd *getpwnam();
struct passwd *user;
char dnbuf[100], *index(), *strcat(), *strcpy();
sl = index(dest, '/');
if (sl == NULL) {
fprintf(stderr, "Illegal ~user\n");
exit(3);
}
*sl++ = 0;
user = getpwnam(dest+1);
if (user == NULL) {
fprintf(stderr, "No such user as %s\n", dest);
exit(4);
}
strcpy(dnbuf, user->pw_dir);
strcat(dnbuf, "/");
strcat(dnbuf, sl);
strcpy(dest, dnbuf);
}
#endif /* !defined(MSDOS) && !defined(VMS) */
sl = index(dest, '/');
if (sl == NULL) {
fprintf(stderr, "Illegal ~user\n");
exit(3);
}
*sl++ = 0;
user = getpwnam(dest + 1);
if (user == NULL) {
fprintf(stderr, "No such user as %s\n", dest);
exit(4);
}
strcpy(dnbuf, user->pw_dir);
strcat(dnbuf, "/");
strcat(dnbuf, sl);
strcpy(dest, dnbuf);
}
#endif /* !defined(MSDOS) && !defined(VMS) */
/* create output file */
/* create output file */
#if defined(MSDOS) || defined(WIN32)
out = fopen(dest, "wb"); /* Binary file */
out = fopen(dest, "wb"); /* Binary file */
#else
out = fopen(dest, "w");
out = fopen(dest, "w");
#endif
if (out == NULL) {
perror(dest);
exit(4);
}
#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) /* i.e., UNIX */
chmod(dest, mode);
if (out == NULL) {
perror(dest);
exit(4);
}
#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) /* i.e., UNIX */
chmod(dest, mode);
#endif
decode(in, out);
decode(in, out);
if (fgets(buf, sizeof buf, in) == NULL || strcmp(buf, "end\n")) {
fprintf(stderr, "No end line\n");
exit(5);
}
exit(0);
/*NOTREACHED*/
return 0;
if (fgets(buf, sizeof buf, in) == NULL || strcmp(buf, "end\n")) {
fprintf(stderr, "No end line\n");
exit(5);
}
exit(0);
/*NOTREACHED*/
return 0;
}
/*
@@ -182,31 +184,32 @@ decode(in, out)
FILE *in;
FILE *out;
{
char buf[80];
char *bp;
int n, i, expected;
char buf[80];
char *bp;
int n, i, expected;
for (;;) {
/* for each input line */
if (fgets(buf, sizeof buf, in) == NULL) {
printf("Short file\n");
exit(10);
}
n = DEC(buf[0]);
if ((n <= 0) || (buf[0] == '\n'))
break;
for (;;) {
/* for each input line */
if (fgets(buf, sizeof buf, in) == NULL) {
printf("Short file\n");
exit(10);
}
n = DEC(buf[0]);
if ((n <= 0) || (buf[0] == '\n'))
break;
/* Calculate expected # of chars and pad if necessary */
expected = ((n+2)/3)<<2;
for (i = (int)strlen(buf)-1; i <= expected; i++) buf[i] = ' ';
/* Calculate expected # of chars and pad if necessary */
expected = ((n + 2) / 3) << 2;
for (i = (int) strlen(buf) - 1; i <= expected; i++)
buf[i] = ' ';
bp = &buf[1];
while (n > 0) {
outdec(bp, out, n);
bp += 4;
n -= 3;
}
}
bp = &buf[1];
while (n > 0) {
outdec(bp, out, n);
bp += 4;
n -= 3;
}
}
}
/*
@@ -221,17 +224,17 @@ char *p;
FILE *f;
int n;
{
int c1, c2, c3;
int c1, c2, c3;
c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
c3 = DEC(p[2]) << 6 | DEC(p[3]);
if (n >= 1)
putc(c1, f);
if (n >= 2)
putc(c2, f);
if (n >= 3)
putc(c3, f);
c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
c3 = DEC(p[2]) << 6 | DEC(p[3]);
if (n >= 1)
putc(c1, f);
if (n >= 2)
putc(c2, f);
if (n >= 3)
putc(c3, f);
}
#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
@@ -241,18 +244,17 @@ int n;
*/
#ifndef NULL
#define NULL 0
#define NULL 0
#endif
char *
index(sp, c)
register char *sp, c;
{
do {
if (*sp == c)
return(sp);
} while (*sp++);
return(NULL);
do {
if (*sp == c)
return (sp);
} while (*sp++);
return (NULL);
}
#endif