From 119b0c3058e17f6e6ef7b59013ab9566926e4ab1 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Mon, 5 Jan 2004 14:01:03 +0000 Subject: [PATCH] Simple stub to test SIGHUP etc. stuff in an easier way. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@89 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- nethackstub.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 nethackstub.c diff --git a/nethackstub.c b/nethackstub.c new file mode 100644 index 0000000..e1fea05 --- /dev/null +++ b/nethackstub.c @@ -0,0 +1,111 @@ +/* nethackstub.c + * Copyright (c) 2004 Jilles Tjoelker + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * This program can be used instead of nethack to test dgamelaunch. + */ + +static const char rcsid[] = "$Id: nethackstub.c,v 1.1 2004/01/05 14:01:03 jilles Exp $"; + +#include + +#include +#include +#include + +void +sighup(int sig) +{ + (void)sig; +#define S "SIGHUP received.\n" + write(STDOUT_FILENO, S, -1 + sizeof S); +#undef S +} + +void +sigterm(int sig) +{ + (void)sig; +#define S "SIGTERM received.\n" + write(STDOUT_FILENO, S, -1 + sizeof S); +#undef S +} + +int +main(int argc, char *argv[]) +{ + char buf[256]; + int showusage = 1, n, i; + +#define S "nethackstub started with arguments:\n" + write(STDOUT_FILENO, S, -1 + sizeof S); +#undef S + for (i = 1; i < argc; i++) + { + write(STDOUT_FILENO, argv[i], strlen(argv[i])); +#define S "\n" + write(STDOUT_FILENO, S, -1 + sizeof S); +#undef S + } + + signal(SIGHUP, sighup); + signal(SIGTERM, sigterm); + + for (;;) + { + if (showusage) + { +#define S "i: close stdin - o: close stdout/stderr - q: quit\n" + write(STDOUT_FILENO, S, -1 + sizeof S); +#undef S + } + n = read(STDIN_FILENO, buf, sizeof buf); + if (n <= 0) + break; + for (i = 0; i < n; i++) + { + switch (tolower(buf[i])) + { + case 'i': + close(STDIN_FILENO); + break; + case 'o': + close(STDOUT_FILENO); + close(STDERR_FILENO); + break; + case 'q': + return 0; + break; + case '\r': + case '\n': + case ' ': + break; + default: + showusage = 1; + } + } + } + + for (;;) + pause(); + + return 0; +} + +/* vim:ts=8:cin:sw=4 + */