+/* $NetBSD: machdep.c,v 1.5 1995/04/28 23:49:22 mycroft Exp $ */
+
/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
*/
#ifndef lint
-static char sccsid[] = "@(#)machdep.c 5.7 (Berkeley) 2/28/91";
+#if 0
+static char sccsid[] = "@(#)machdep.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: machdep.c,v 1.5 1995/04/28 23:49:22 mycroft Exp $";
+#endif
#endif /* not lint */
/*
#ifdef UNIX_BSD4_2
#include <sys/time.h>
-#include <sgtty.h>
#endif
#ifdef UNIX_SYSV
#include <time.h>
-#include <termio.h>
#endif
#include <signal.h>
+#include <termios.h>
#include "rogue.h"
#include "pathnames.h"
(void)fpurge(stdin);
}
-/* md_control_keyboard():
- *
- * This routine is much like md_cbreak_no_echo_nonl() below. It sets up the
- * keyboard for appropriate input. Specifically, it prevents the tty driver
- * from stealing characters. For example, ^Y is needed as a command
- * character, but the tty driver intercepts it for another purpose. Any
- * such behavior should be stopped. This routine could be avoided if
- * we used RAW mode instead of CBREAK. But RAW mode does not allow the
- * generation of keyboard signals, which the program uses.
- *
- * The parameter 'mode' when true, indicates that the keyboard should
- * be set up to play rogue. When false, it should be restored if
- * necessary.
- *
- * This routine is not strictly necessary and may be stubbed. This may
- * cause certain command characters to be unavailable.
- */
-
-md_control_keybord(mode)
-boolean mode;
-{
- static boolean called_before = 0;
-#ifdef UNIX_BSD4_2
- static struct ltchars ltc_orig;
- static struct tchars tc_orig;
- struct ltchars ltc_temp;
- struct tchars tc_temp;
-#endif
-#ifdef UNIX_SYSV
- static struct termio _oldtty;
- struct termio _tty;
-#endif
-
- if (!called_before) {
- called_before = 1;
-#ifdef UNIX_BSD4_2
- ioctl(0, TIOCGETC, &tc_orig);
- ioctl(0, TIOCGLTC, <c_orig);
-#endif
-#ifdef UNIX_SYSV
- ioctl(0, TCGETA, &_oldtty);
-#endif
- }
-#ifdef UNIX_BSD4_2
- ltc_temp = ltc_orig;
- tc_temp = tc_orig;
-#endif
-#ifdef UNIX_SYSV
- _tty = _oldtty;
-#endif
-
- if (!mode) {
-#ifdef UNIX_BSD4_2
- ltc_temp.t_suspc = ltc_temp.t_dsuspc = -1;
- ltc_temp.t_rprntc = ltc_temp.t_flushc = -1;
- ltc_temp.t_werasc = ltc_temp.t_lnextc = -1;
- tc_temp.t_startc = tc_temp.t_stopc = -1;
-#endif
-#ifdef UNIX_SYSV
- _tty.c_cc[VSWTCH] = CNSWTCH;
-#endif
- }
-#ifdef UNIX_BSD4_2
- ioctl(0, TIOCSETC, &tc_temp);
- ioctl(0, TIOCSLTC, <c_temp);
-#endif
-#ifdef UNIX_SYSV
- ioctl(0, TCSETA, &_tty);
-#endif
-}
-
/* md_heed_signals():
*
* This routine tells the program to call particular routines when
struct rogue_time *rt_buf;
{
struct tm *t, *localtime();
- long seconds;
+ time_t seconds;
time(&seconds);
t = localtime(&seconds);
struct rogue_time *rt_buf;
{
struct stat sbuf;
- long seconds;
+ time_t seconds;
struct tm *t;
stat(fname, &sbuf);
/* md_lock():
*
* This function is intended to give the user exclusive access to the score
- * file. It does so by "creat"ing a lock file, which can only be created
- * if it does not already exist. The file is deleted when score file
- * processing is finished. The lock file should be located in the same
- * directory as the score file. These full path names should be defined for
- * any particular site in rogue.h. The constants _PATH_SCOREFILE and
- * _PATH_LOCKFILE define these file names.
+ * file. It does so by flock'ing the score file. The full path name of the
+ * score file should be defined for any particular site in rogue.h. The
+ * constants _PATH_SCOREFILE defines this file name.
*
* When the parameter 'l' is non-zero (true), a lock is requested. Otherwise
- * the lock is released by removing the lock file.
+ * the lock is released.
*/
md_lock(l)
boolean l;
{
+ static int fd;
short tries;
- char *lock_file = _PATH_LOCKFILE;
if (l) {
- for (tries = 0; tries < 5; tries++) {
- if (md_get_file_id(lock_file) == -1) {
- if (creat(lock_file, 0444) != -1) {
- break;
- } else {
- message("cannot lock score file", 0);
- }
- } else {
- message("waiting to lock score file", 0);
- }
- sleep(2);
+ if ((fd = open(_PATH_SCOREFILE, O_RDONLY)) < 1) {
+ message("cannot lock score file", 0);
+ return;
}
+ for (tries = 0; tries < 5; tries++)
+ if (!flock(fd, LOCK_EX|LOCK_NB))
+ return;
} else {
- (void) unlink(lock_file);
+ (void)flock(fd, LOCK_NB);
+ (void)close(fd);
}
}
md_cbreak_no_echo_nonl(on)
boolean on;
{
-#ifdef UNIX_BSD4_2
- static struct sgttyb tty_buf;
- static int tsave_flags;
-
- if (on) {
- ioctl(0, TIOCGETP, &tty_buf);
- tsave_flags = tty_buf.sg_flags;
- tty_buf.sg_flags |= CBREAK;
- tty_buf.sg_flags &= ~(ECHO | CRMOD); /* CRMOD: see note 3 above */
- ioctl(0, TIOCSETP, &tty_buf);
- } else {
- tty_buf.sg_flags = tsave_flags;
- ioctl(0, TIOCSETP, &tty_buf);
- }
-#endif
-#ifdef UNIX_SYSV
- struct termio tty_buf;
- static struct termio tty_save;
+ struct termios tty_buf;
+ static struct termios tty_save;
if (on) {
- ioctl(0, TCGETA, &tty_buf);
+ tcgetattr(0, &tty_buf);
tty_save = tty_buf;
tty_buf.c_lflag &= ~(ICANON | ECHO);
tty_buf.c_oflag &= ~ONLCR;
- tty_buf.c_cc[4] = 1; /* MIN */
- tty_buf.c_cc[5] = 2; /* TIME */
- ioctl(0, TCSETAF, &tty_buf);
+ tty_buf.c_cc[VMIN] = 1;
+ tty_buf.c_cc[VTIME] = 2;
+ tcsetattr(0, TCSADRAIN, &tty_buf);
} else {
- ioctl(0, TCSETAF, &tty_save);
+ tcsetattr(0, TCSADRAIN, &tty_save);
}
-#endif
}
/* md_gdtcf(): (Get Default Termcap File)