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
|
* Reset the signal in case we got here via an interrupt
|
||||||
*/
|
*/
|
||||||
|
#ifdef SIGINT
|
||||||
if (signal(SIGINT, quit) != quit)
|
if (signal(SIGINT, quit) != quit)
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
|
#endif
|
||||||
msg("Really quit? [y/n/s]");
|
msg("Really quit? [y/n/s]");
|
||||||
/* ch = tolower(readchar());*/
|
/* ch = tolower(readchar());*/
|
||||||
ch = readchar();
|
ch = readchar();
|
||||||
|
|
@ -395,7 +397,9 @@ quit(int a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#ifdef SIGINT
|
||||||
signal(SIGINT, quit);
|
signal(SIGINT, quit);
|
||||||
|
#endif
|
||||||
wmove(cw, 0, 0);
|
wmove(cw, 0, 0);
|
||||||
wclrtoeol(cw);
|
wclrtoeol(cw);
|
||||||
draw(cw);
|
draw(cw);
|
||||||
|
|
@ -637,46 +641,15 @@ shell()
|
||||||
/*
|
/*
|
||||||
* Fork and do a shell
|
* Fork and do a shell
|
||||||
*/
|
*/
|
||||||
#ifndef __DJGPP__
|
md_shellescape();
|
||||||
while((pid = fork()) < 0)
|
printf("\n%s", retstr);
|
||||||
sleep(1);
|
fflush(stdout);
|
||||||
if (pid == 0) {
|
nonl();
|
||||||
setuid(playuid); /* Set back to original user */
|
noecho();
|
||||||
setgid(playgid);
|
crmode();
|
||||||
execl(sh == NULL ? "/bin/sh" : sh, "shell", "-i", 0);
|
in_shell = FALSE;
|
||||||
perror("No shelly");
|
wait_for(cw, '\n');
|
||||||
byebye(-1);
|
restscr(cw);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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])
|
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.
|
# Checks for typedefs, structures, and compiler characteristics.
|
||||||
|
AC_TYPE_UID_T
|
||||||
AC_TYPE_SIZE_T
|
AC_TYPE_SIZE_T
|
||||||
AC_STRUCT_TM
|
AC_STRUCT_TM
|
||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,6 @@ char ch;
|
||||||
|
|
||||||
#ifdef NEED_GETTIME
|
#ifdef NEED_GETTIME
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pwd.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gettime:
|
* gettime:
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <termios.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
|
|
@ -39,8 +36,6 @@
|
||||||
|
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
||||||
struct termios terminal;
|
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
char **argv;
|
char **argv;
|
||||||
char **envp;
|
char **envp;
|
||||||
|
|
@ -48,8 +43,6 @@ char **envp;
|
||||||
register char *env;
|
register char *env;
|
||||||
register struct linked_list *item;
|
register struct linked_list *item;
|
||||||
register struct object *obj;
|
register struct object *obj;
|
||||||
struct passwd *pw;
|
|
||||||
struct passwd *getpwuid();
|
|
||||||
char alldone, wpt;
|
char alldone, wpt;
|
||||||
char *getpass(), *xcrypt(), *strrchr();
|
char *getpass(), *xcrypt(), *strrchr();
|
||||||
int lowtime;
|
int lowtime;
|
||||||
|
|
@ -132,10 +125,11 @@ char **envp;
|
||||||
|
|
||||||
if ((env = getenv("HOME")) != NULL)
|
if ((env = getenv("HOME")) != NULL)
|
||||||
strcpy(home, env);
|
strcpy(home, env);
|
||||||
else if ((pw = getpwuid(playuid)) != NULL)
|
else {
|
||||||
strcpy(home, pw->pw_dir);
|
strncpy(home, md_gethomedir(), LINLEN);
|
||||||
else
|
if (home[LINLEN-1] != '\0')
|
||||||
home[0] = '\0';
|
home[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(home,"/") == 0)
|
if (strcmp(home,"/") == 0)
|
||||||
home[0] = '\0';
|
home[0] = '\0';
|
||||||
|
|
@ -153,13 +147,7 @@ char **envp;
|
||||||
|
|
||||||
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
if (!use_savedir && (env == NULL || whoami[0] == '\0'))
|
||||||
{
|
{
|
||||||
if((pw = getpwuid(playuid)) == NULL)
|
strucpy(whoami, md_getusername(), strlen(md_getusername()));
|
||||||
{
|
|
||||||
printf("Say, who are you?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
strucpy(whoami, pw->pw_name, strlen(pw->pw_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env == NULL || fruit[0] == '\0')
|
if (env == NULL || fruit[0] == '\0')
|
||||||
|
|
@ -191,8 +179,7 @@ char **envp;
|
||||||
seed = dnum;
|
seed = dnum;
|
||||||
srand48(seed); /* init rnd number gen */
|
srand48(seed); /* init rnd number gen */
|
||||||
|
|
||||||
signal(SIGINT, byebye); /* just in case */
|
md_onsignal_exit(); /* just in case */
|
||||||
signal(SIGQUIT ,byebye);
|
|
||||||
|
|
||||||
init_everything();
|
init_everything();
|
||||||
|
|
||||||
|
|
@ -397,27 +384,7 @@ int number, sides;
|
||||||
*/
|
*/
|
||||||
setup()
|
setup()
|
||||||
{
|
{
|
||||||
signal(SIGHUP, auto_save);
|
md_onsignal_autosave();
|
||||||
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);
|
|
||||||
|
|
||||||
nonl();
|
nonl();
|
||||||
cbreak();
|
cbreak();
|
||||||
|
|
@ -433,9 +400,6 @@ playit()
|
||||||
{
|
{
|
||||||
reg char *opts;
|
reg char *opts;
|
||||||
|
|
||||||
tcgetattr(0,&terminal);
|
|
||||||
|
|
||||||
|
|
||||||
/* parse environment declaration of options */
|
/* parse environment declaration of options */
|
||||||
|
|
||||||
if ((opts = getenv("ROGUEOPTS")) != NULL)
|
if ((opts = getenv("ROGUEOPTS")) != NULL)
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,9 @@ md_onsignal_exit(void)
|
||||||
#ifdef SIGTERM
|
#ifdef SIGTERM
|
||||||
signal(SIGTERM, exit);
|
signal(SIGTERM, exit);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGINT
|
||||||
|
signal(SIGINT, exit);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void auto_save(int sig);
|
extern void auto_save(int sig);
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,11 @@
|
||||||
* See the file LICENSE.TXT for full copyright and licensing information.
|
* See the file LICENSE.TXT for full copyright and licensing information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <termios.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
||||||
extern struct termios terminal;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* description of an option and what to do with it
|
* description of an option and what to do with it
|
||||||
*/
|
*/
|
||||||
|
|
@ -137,7 +134,7 @@ WINDOW *awin;
|
||||||
}
|
}
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
continue;
|
continue;
|
||||||
else if(c == terminal.c_cc[VERASE]) { /* process erase char */
|
else if(c == md_erasechar()) { /* process erase char */
|
||||||
if (sp > buf) {
|
if (sp > buf) {
|
||||||
reg int i;
|
reg int i;
|
||||||
|
|
||||||
|
|
@ -147,7 +144,7 @@ WINDOW *awin;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (c == terminal.c_cc[VKILL]) { /* process kill character */
|
else if (c == md_killchar()) { /* process kill character */
|
||||||
sp = buf;
|
sp = buf;
|
||||||
wmove(awin, oy, ox);
|
wmove(awin, oy, ox);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
15
srogue/rip.c
15
srogue/rip.c
|
|
@ -14,11 +14,9 @@
|
||||||
* See the file LICENSE.TXT for full copyright and licensing information.
|
* See the file LICENSE.TXT for full copyright and licensing information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
@ -127,8 +125,7 @@ int amount, aflag;
|
||||||
reg FILE *outf;
|
reg FILE *outf;
|
||||||
char *packend;
|
char *packend;
|
||||||
|
|
||||||
signal(SIGINT, byebye);
|
md_onsignal_exit();
|
||||||
signal(SIGQUIT, byebye);
|
|
||||||
if (aflag != WINNER) {
|
if (aflag != WINNER) {
|
||||||
if (aflag == CHICKEN)
|
if (aflag == CHICKEN)
|
||||||
packend = "when you chickened out";
|
packend = "when you chickened out";
|
||||||
|
|
@ -213,8 +210,7 @@ int amount, aflag;
|
||||||
encwrite((char *) scoreline, 100, outf);
|
encwrite((char *) scoreline, 100, outf);
|
||||||
}
|
}
|
||||||
fclose(outf);
|
fclose(outf);
|
||||||
signal(SIGINT, byebye);
|
md_onsignal_exit();
|
||||||
signal(SIGQUIT, byebye);
|
|
||||||
clear();
|
clear();
|
||||||
refresh();
|
refresh();
|
||||||
endwin();
|
endwin();
|
||||||
|
|
@ -300,12 +296,7 @@ int showname;
|
||||||
}
|
}
|
||||||
printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts);
|
printf(" [Exp: %d/%ld]",scp->sc_explvl,scp->sc_exppts);
|
||||||
if (showname) {
|
if (showname) {
|
||||||
struct passwd *pp, *getpwuid();
|
printf(" (%s)\n", md_getrealname(scp->sc_uid));
|
||||||
|
|
||||||
if ((pp = getpwuid(scp->sc_uid)) == NULL)
|
|
||||||
printf(" (%d)\n", scp->sc_uid);
|
|
||||||
else
|
|
||||||
printf(" (%s)\n", pp->pw_name);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,7 @@ STAT sbuf;
|
||||||
*/
|
*/
|
||||||
ignore()
|
ignore()
|
||||||
{
|
{
|
||||||
int i;
|
md_ignoreallsignals();
|
||||||
|
|
||||||
for (i = 0; i < NSIG; i++)
|
|
||||||
signal(i, SIG_IGN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -191,8 +188,7 @@ FILE *savef;
|
||||||
msg("");
|
msg("");
|
||||||
rs_save_file(savef);
|
rs_save_file(savef);
|
||||||
close(fnum);
|
close(fnum);
|
||||||
signal(SIGINT, byebye);
|
md_onsignal_exit();
|
||||||
signal(SIGQUIT, byebye);
|
|
||||||
wclear(cw);
|
wclear(cw);
|
||||||
draw(cw);
|
draw(cw);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <termios.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
#include <pwd.h>
|
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
||||||
extern struct termios terminal;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* whatis:
|
* whatis:
|
||||||
* What a certain object is
|
* What a certain object is
|
||||||
|
|
@ -359,9 +355,9 @@ passwd()
|
||||||
mpos = 0;
|
mpos = 0;
|
||||||
sp = buf;
|
sp = buf;
|
||||||
while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
|
while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
|
||||||
if (c == terminal.c_cc[VKILL])
|
if (c == md_killchar())
|
||||||
sp = buf;
|
sp = buf;
|
||||||
else if (c == terminal.c_cc[VERASE] && sp > buf)
|
else if (c == md_erasechar() && sp > buf)
|
||||||
sp--;
|
sp--;
|
||||||
else
|
else
|
||||||
*sp++ = c;
|
*sp++ = c;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue