diff srogue/main.c @ 119:458df24e973d

srogue: use functions from mdport.c. Shell escape, passwd entries, terminal settings, and most signal handling is now done with the more portable md_* functions.
author John "Elwin" Edwards
date Wed, 30 Apr 2014 14:46:30 -0700
parents ee250e3646fd
children d6b7c3fb37ea
line wrap: on
line diff
--- a/srogue/main.c	Sun Apr 27 08:29:14 2014 -0700
+++ b/srogue/main.c	Wed Apr 30 14:46:30 2014 -0700
@@ -18,11 +18,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include <termios.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <signal.h>
-#include <pwd.h>
 #include <limits.h>
 #include <sys/stat.h>
 #include "rogue.h"
@@ -39,8 +36,6 @@
 
 #include "rogue.ext"
 
-struct termios terminal;
-
 main(argc, argv, envp)
 char **argv;
 char **envp;
@@ -48,8 +43,6 @@
 	register char *env;
 	register struct linked_list *item;
 	register struct object *obj;
-	struct passwd *pw;
-	struct passwd *getpwuid();
 	char alldone, wpt;
 	char *getpass(), *xcrypt(), *strrchr();
 	int lowtime;
@@ -132,10 +125,11 @@
 
 	if ((env = getenv("HOME")) != NULL)
 		strcpy(home, env);
-	else if ((pw = getpwuid(playuid)) != NULL)
-		strcpy(home, pw->pw_dir);
-	else
-		home[0] = '\0';
+	else {
+		strncpy(home, md_gethomedir(), LINLEN);
+		if (home[LINLEN-1] != '\0')
+			home[0] = '\0';
+	}
 
         if (strcmp(home,"/") == 0)
 		home[0] = '\0';
@@ -153,13 +147,7 @@
 
 	if (!use_savedir && (env == NULL || whoami[0] == '\0'))
 	{
-		if((pw = getpwuid(playuid)) == NULL)
-		{
-			printf("Say, who are you?\n");
-			exit(1);
-		}
-		else
-			strucpy(whoami, pw->pw_name, strlen(pw->pw_name));
+		strucpy(whoami, md_getusername(), strlen(md_getusername()));
 	}
 
 	if (env == NULL || fruit[0] == '\0')
@@ -191,8 +179,7 @@
 	seed = dnum;
 	srand48(seed);			/* init rnd number gen */
 
-	signal(SIGINT, byebye);		/* just in case */
-	signal(SIGQUIT ,byebye);
+	md_onsignal_exit();		/* just in case */
 
 	init_everything();
 
@@ -397,27 +384,7 @@
 */
 setup()
 {
-	signal(SIGHUP, auto_save);
-	signal(SIGINT, auto_save);
-	signal(SIGQUIT,  byebye);
-	signal(SIGILL, game_err);
-	signal(SIGTRAP, game_err);
-#ifdef SIGIOT
-	signal(SIGIOT, game_err);
-#endif
-#ifdef SIGEMT
-	signal(SIGEMT, game_err);
-#endif
-	signal(SIGFPE, game_err);
-#ifdef SIGBUS
-	signal(SIGBUS, game_err);
-#endif
-	signal(SIGSEGV, game_err);
-#ifdef SIGSYS
-	signal(SIGSYS, game_err);
-#endif
-	signal(SIGPIPE, game_err);
-	signal(SIGTERM, game_err);
+	md_onsignal_autosave();
 
 	nonl();
 	cbreak();
@@ -433,9 +400,6 @@
 {
 	reg char *opts;
 
-	tcgetattr(0,&terminal);
-
-
 	/* parse environment declaration of options */
 
 	if ((opts = getenv("ROGUEOPTS")) != NULL)