# HG changeset patch # User John "Elwin" Edwards # Date 1398894390 25200 # Node ID 458df24e973d61c4f2baf28b2cbcbee665101f96 # Parent 8d1dfc5a912c83e539a42d7df64f89c3f7ecef89 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. diff -r 8d1dfc5a912c -r 458df24e973d srogue/command.c --- a/srogue/command.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/command.c Wed Apr 30 14:46:30 2014 -0700 @@ -369,8 +369,10 @@ /* * Reset the signal in case we got here via an interrupt */ +#ifdef SIGINT if (signal(SIGINT, quit) != quit) mpos = 0; +#endif msg("Really quit? [y/n/s]"); /* ch = tolower(readchar());*/ ch = readchar(); @@ -395,7 +397,9 @@ } } else { +#ifdef SIGINT signal(SIGINT, quit); +#endif wmove(cw, 0, 0); wclrtoeol(cw); draw(cw); @@ -637,46 +641,15 @@ /* * Fork and do a shell */ -#ifndef __DJGPP__ - while((pid = fork()) < 0) - sleep(1); - if (pid == 0) { - setuid(playuid); /* Set back to original user */ - setgid(playgid); - execl(sh == NULL ? "/bin/sh" : sh, "shell", "-i", 0); - perror("No shelly"); - byebye(-1); - } - else { - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - while (wait(&ret_status) != pid) - continue; - signal(SIGINT, quit); - signal(SIGQUIT, endit); - -#else - { - char shell[PATH_MAX]; - - if (sh && *sh) - strncpy(shell,sh,PATH_MAX); - else - sprintf(shell, "%s\\bin\\sh.exe", getenv("DJDIR")); - - if (spawnl(P_WAIT,shell, "shell", "-i", 0) == -1) - msg("No shelly: %s", shell); - -#endif - printf("\n%s", retstr); - fflush(stdout); - nonl(); - noecho(); - crmode(); - in_shell = FALSE; - wait_for(cw, '\n'); - restscr(cw); - } + md_shellescape(); + printf("\n%s", retstr); + fflush(stdout); + nonl(); + noecho(); + crmode(); + in_shell = FALSE; + wait_for(cw, '\n'); + restscr(cw); } diff -r 8d1dfc5a912c -r 458df24e973d srogue/configure.ac --- a/srogue/configure.ac Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/configure.ac Wed Apr 30 14:46:30 2014 -0700 @@ -15,6 +15,7 @@ AC_CHECK_HEADERS([arpa/inet.h pwd.h errno.h fcntl.h limits.h nlist.h stdlib.h string.h sys/ioctl.h termios.h unistd.h term.h ncurses/term.h process.h]) # Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_UID_T AC_TYPE_SIZE_T AC_STRUCT_TM # Checks for library functions. diff -r 8d1dfc5a912c -r 458df24e973d srogue/io.c --- a/srogue/io.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/io.c Wed Apr 30 14:46:30 2014 -0700 @@ -263,7 +263,6 @@ #ifdef NEED_GETTIME #include -#include /* * gettime: diff -r 8d1dfc5a912c -r 458df24e973d srogue/main.c --- 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 #include #include -#include #include #include -#include -#include #include #include #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) diff -r 8d1dfc5a912c -r 458df24e973d srogue/mdport.c --- a/srogue/mdport.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/mdport.c Wed Apr 30 14:46:30 2014 -0700 @@ -210,6 +210,9 @@ #ifdef SIGTERM signal(SIGTERM, exit); #endif +#ifdef SIGINT + signal(SIGINT, exit); +#endif } extern void auto_save(int sig); diff -r 8d1dfc5a912c -r 458df24e973d srogue/options.c --- a/srogue/options.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/options.c Wed Apr 30 14:46:30 2014 -0700 @@ -14,14 +14,11 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include #include #include #include "rogue.h" #include "rogue.ext" -extern struct termios terminal; - /* * description of an option and what to do with it */ @@ -137,7 +134,7 @@ } if (c == -1) continue; - else if(c == terminal.c_cc[VERASE]) { /* process erase char */ + else if(c == md_erasechar()) { /* process erase char */ if (sp > buf) { reg int i; @@ -147,7 +144,7 @@ } continue; } - else if (c == terminal.c_cc[VKILL]) { /* process kill character */ + else if (c == md_killchar()) { /* process kill character */ sp = buf; wmove(awin, oy, ox); continue; diff -r 8d1dfc5a912c -r 458df24e973d srogue/rip.c --- a/srogue/rip.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/rip.c Wed Apr 30 14:46:30 2014 -0700 @@ -14,11 +14,9 @@ * See the file LICENSE.TXT for full copyright and licensing information. */ -#include #include #include #include -#include #include #include "rogue.h" #include "rogue.ext" @@ -127,8 +125,7 @@ reg FILE *outf; char *packend; - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); if (aflag != WINNER) { if (aflag == CHICKEN) packend = "when you chickened out"; @@ -213,8 +210,7 @@ encwrite((char *) scoreline, 100, outf); } fclose(outf); - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); clear(); refresh(); endwin(); @@ -300,12 +296,7 @@ } printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts); if (showname) { - struct passwd *pp, *getpwuid(); - - if ((pp = getpwuid(scp->sc_uid)) == NULL) - printf(" (%d)\n", scp->sc_uid); - else - printf(" (%s)\n", pp->pw_name); + printf(" (%s)\n", md_getrealname(scp->sc_uid)); } else printf("\n"); diff -r 8d1dfc5a912c -r 458df24e973d srogue/save.c --- a/srogue/save.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/save.c Wed Apr 30 14:46:30 2014 -0700 @@ -42,10 +42,7 @@ */ ignore() { - int i; - - for (i = 0; i < NSIG; i++) - signal(i, SIG_IGN); + md_ignoreallsignals(); } /* @@ -191,8 +188,7 @@ msg(""); rs_save_file(savef); close(fnum); - signal(SIGINT, byebye); - signal(SIGQUIT, byebye); + md_onsignal_exit(); wclear(cw); draw(cw); } diff -r 8d1dfc5a912c -r 458df24e973d srogue/wizard.c --- a/srogue/wizard.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/wizard.c Wed Apr 30 14:46:30 2014 -0700 @@ -15,14 +15,10 @@ */ #include -#include #include #include "rogue.h" -#include #include "rogue.ext" -extern struct termios terminal; - /* * whatis: * What a certain object is @@ -359,9 +355,9 @@ mpos = 0; sp = buf; while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE) - if (c == terminal.c_cc[VKILL]) + if (c == md_killchar()) sp = buf; - else if (c == terminal.c_cc[VERASE] && sp > buf) + else if (c == md_erasechar() && sp > buf) sp--; else *sp++ = c; diff -r 8d1dfc5a912c -r 458df24e973d srogue/xcrypt.c --- a/srogue/xcrypt.c Sun Apr 27 08:29:14 2014 -0700 +++ b/srogue/xcrypt.c Wed Apr 30 14:46:30 2014 -0700 @@ -51,7 +51,6 @@ #include #include -#include #include #ifdef DEBUG