⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 machdep.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
 * after restoring games from them. * * Again, this function is not strictly necessary, and can be stubbed * by simply returning 1.  In this case, saved-game files will not be * deleted and can be replayed. */booleanmd_df(fname)char *fname;{	if (unlink(fname)) {		return(0);	}	return(1);}/* md_gln: (Get login name) * * This routine returns the login name of the user.  This string is * used mainly for identifying users in score files. * * A dummy string may be returned if you are unable to implement this * function, but then the score file would only have one name in it. */char *md_gln(){	struct passwd *p, *getpwuid();	if (!(p = getpwuid(getuid())))		return((char *)NULL);	return(p->pw_name);}/* md_sleep: * * This routine causes the game to pause for the specified number of * seconds. * * This routine is not particularly necessary at all.  It is used for * delaying execution, which is useful to this program at some times. */md_sleep(nsecs)int nsecs;{	(void) sleep(nsecs);}/* md_getenv() * * This routine gets certain values from the user's environment.  These * values are strings, and each string is identified by a name.  The names * of the values needed, and their use, is as follows: * *   TERMCAP *     The name of the users's termcap file, NOT the termcap entries *     themselves.  This is used ONLY if the program is compiled with *     CURSES defined (-DCURSES).  Even in this case, the program need *     not find a string for TERMCAP.  If it does not, it will use the *     default termcap file as returned by md_gdtcf(); *   TERM *     The name of the users's terminal.  This is used ONLY if the program *     is compiled with CURSES defined (-DCURSES).  In this case, the string *     value for TERM must be found, or the routines in curses.c cannot *     function, and the program will quit. *   ROGUEOPTS *     A string containing the various game options.  This need not be *     defined. *   HOME *     The user's home directory.  This is only used when the user specifies *     '~' as the first character of a saved-game file.  This string need *     not be defined. *   SHELL *     The user's favorite shell.  If not found, "/bin/sh" is assumed. * * If your system does not provide a means of searching for these values, * you will have to do it yourself.  None of the values above really need * to be defined except TERM when the program is compiled with CURSES * defined.  In this case, as a bare minimum, you can check the 'name' * parameter, and if it is "TERM" find the terminal name and return that, * else return zero.  If the program is not compiled with CURSES, you can * get by with simply always returning zero.  Returning zero indicates * that their is no defined value for the given string. */char *md_getenv(name)char *name;{	char *value;	char *getenv();	value = getenv(name);	return(value);}/* md_malloc() * * This routine allocates, and returns a pointer to, the specified number * of bytes.  This routines absolutely MUST be implemented for your * particular system or the program will not run at all.  Return zero * when no more memory can be allocated. */char *md_malloc(n)int n;{	char *malloc();	char *t;	t = malloc(n);	return(t);}/* md_gseed() (Get Seed) * * This function returns a seed for the random number generator (RNG).  This * seed causes the RNG to begin generating numbers at some point in it's * sequence.  Without a random seed, the RNG will generate the same set * of numbers, and every game will start out exactly the same way.  A good * number to use is the process id, given by getpid() on most UNIX systems. * * You need to find some single random integer, such as: *   process id. *   current time (minutes + seconds) returned from md_gct(), if implemented. *    * It will not help to return "get_rand()" or "rand()" or the return value of * any pseudo-RNG.  If you don't have a random number, you can just return 1, * but this means your games will ALWAYS start the same way, and will play * exactly the same way given the same input. */md_gseed(){	return(getpid());}/* md_exit(): * * This function causes the program to discontinue execution and exit. * This function must be implemented or the program will continue to * hang when it should quit. */md_exit(status)int status;{	exit(status);}/* 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 SCORE_FILE * and LOCK_FILE define these file names. * * When the parameter 'l' is non-zero (true), a lock is requested.  Otherwise * the lock is released by removing the lock file. */md_lock(l)boolean l;{	short tries;	char *lock_file = LOCK_FILE;	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);		}	} else {		(void) unlink(lock_file);	}}/* md_shell(): * * This function spawns a shell for the user to use.  When this shell is * terminated, the game continues.  Since this program may often be run * setuid to gain access to privileged files, care is taken that the shell * is run with the user's REAL user id, and not the effective user id. * The effective user id is restored after the shell completes. */md_shell(shell)char *shell;{	long w[2];	if (!fork()) {		int uid;		uid = getuid();		setuid(uid);		execl(shell, shell, 0);	}	wait(w);}/* If you have a viable curses/termlib library, then use it and don't bother * implementing the routines below.  And don't compile with -DCURSES. */#ifdef CURSES/* md_cbreak_no_echo_nonl: * * This routine sets up some terminal characteristics.  The tty-driver * must be told to: *   1.)  Not echo input. *   2.)  Transmit input characters immediately upon typing. (cbreak mode) *   3.)  Move the cursor down one line, without changing column, and *        without generating a carriage-return, when it *        sees a line-feed.  This is only necessary if line-feed is ever *        used in the termcap 'do' (cursor down) entry, in which case, *        your system should must have a way of accomplishing this. * * When the parameter 'on' is true, the terminal is set up as specified * above.  When this parameter is false, the terminal is restored to the * original state. * * Raw mode should not to be used.  Keyboard signals/events/interrupts should * be sent, although they are not strictly necessary.  See notes in * md_heed_signals(). * * This function must be implemented for rogue to run properly if the * program is compiled with CURSES defined to use the enclosed curses * emulation package.  If you are not using this, then this routine is * totally unnecessary. *  * Notice that information is saved between calls.  This is used to * restore the terminal to an initial saved state. * */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;	if (on) {		ioctl(0, TCGETA, &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);	} else {		ioctl(0, TCSETAF, &tty_save);	}#endif}/* md_gdtcf(): (Get Default Termcap File) * * This function is called ONLY when the program is compiled with CURSES * defined.  If you use your system's curses/termlib library, this function * won't be called.  On most UNIX systems, "/etc/termcap" suffices. * * If their is no such termcap file, then return 0, but in that case, you * must have a TERMCAP file returned from md_getenv("TERMCAP").  The latter * will override the value returned from md_gdtcf().  If the program is * compiled with CURSES defined, and md_gdtcf() returns 0, and * md_getenv("TERMCAP") returns 0, the program will have no terminal * capability information and will quit. */char *md_gdtcf(){	return("/etc/termcap");}/* md_tstp(): * * This function puts the game to sleep and returns to the shell.  This * only applies to UNIX 4.2 and 4.3.  For other systems, the routine should * be provided as a do-nothing routine.  md_tstp() will only be referenced * in the code when compiled with CURSES defined. * */md_tstp(){#ifdef UNIX_BSD4_2	kill(0, SIGTSTP);#endif}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -