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.
This commit is contained in:
parent
de1e0f2759
commit
791df4324f
10 changed files with 34 additions and 115 deletions
|
|
@ -369,8 +369,10 @@ quit(int a)
|
|||
/*
|
||||
* 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 @@ quit(int a)
|
|||
}
|
||||
}
|
||||
else {
|
||||
#ifdef SIGINT
|
||||
signal(SIGINT, quit);
|
||||
#endif
|
||||
wmove(cw, 0, 0);
|
||||
wclrtoeol(cw);
|
||||
draw(cw);
|
||||
|
|
@ -637,46 +641,15 @@ shell()
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ AC_HEADER_STDC
|
|||
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.
|
||||
|
|
|
|||
|
|
@ -263,7 +263,6 @@ char ch;
|
|||
|
||||
#ifdef NEED_GETTIME
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
/*
|
||||
* gettime:
|
||||
|
|
|
|||
|
|
@ -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 @@ char **envp;
|
|||
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 @@ char **envp;
|
|||
|
||||
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 @@ char **envp;
|
|||
|
||||
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 @@ char **envp;
|
|||
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 @@ int number, sides;
|
|||
*/
|
||||
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 @@ playit()
|
|||
{
|
||||
reg char *opts;
|
||||
|
||||
tcgetattr(0,&terminal);
|
||||
|
||||
|
||||
/* parse environment declaration of options */
|
||||
|
||||
if ((opts = getenv("ROGUEOPTS")) != NULL)
|
||||
|
|
|
|||
|
|
@ -210,6 +210,9 @@ md_onsignal_exit(void)
|
|||
#ifdef SIGTERM
|
||||
signal(SIGTERM, exit);
|
||||
#endif
|
||||
#ifdef SIGINT
|
||||
signal(SIGINT, exit);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void auto_save(int sig);
|
||||
|
|
|
|||
|
|
@ -14,14 +14,11 @@
|
|||
* See the file LICENSE.TXT for full copyright and licensing information.
|
||||
*/
|
||||
|
||||
#include <termios.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "rogue.h"
|
||||
#include "rogue.ext"
|
||||
|
||||
extern struct termios terminal;
|
||||
|
||||
/*
|
||||
* description of an option and what to do with it
|
||||
*/
|
||||
|
|
@ -137,7 +134,7 @@ WINDOW *awin;
|
|||
}
|
||||
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 @@ WINDOW *awin;
|
|||
}
|
||||
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;
|
||||
|
|
|
|||
15
srogue/rip.c
15
srogue/rip.c
|
|
@ -14,11 +14,9 @@
|
|||
* See the file LICENSE.TXT for full copyright and licensing information.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
#include "rogue.h"
|
||||
#include "rogue.ext"
|
||||
|
|
@ -127,8 +125,7 @@ int amount, aflag;
|
|||
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 @@ int amount, aflag;
|
|||
encwrite((char *) scoreline, 100, outf);
|
||||
}
|
||||
fclose(outf);
|
||||
signal(SIGINT, byebye);
|
||||
signal(SIGQUIT, byebye);
|
||||
md_onsignal_exit();
|
||||
clear();
|
||||
refresh();
|
||||
endwin();
|
||||
|
|
@ -300,12 +296,7 @@ int showname;
|
|||
}
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -42,10 +42,7 @@ STAT sbuf;
|
|||
*/
|
||||
ignore()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NSIG; i++)
|
||||
signal(i, SIG_IGN);
|
||||
md_ignoreallsignals();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -191,8 +188,7 @@ FILE *savef;
|
|||
msg("");
|
||||
rs_save_file(savef);
|
||||
close(fnum);
|
||||
signal(SIGINT, byebye);
|
||||
signal(SIGQUIT, byebye);
|
||||
md_onsignal_exit();
|
||||
wclear(cw);
|
||||
draw(cw);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,10 @@
|
|||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <ctype.h>
|
||||
#include "rogue.h"
|
||||
#include <pwd.h>
|
||||
#include "rogue.ext"
|
||||
|
||||
extern struct termios terminal;
|
||||
|
||||
/*
|
||||
* whatis:
|
||||
* What a certain object is
|
||||
|
|
@ -359,9 +355,9 @@ passwd()
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue