1999-08-17 16:01:18 -07:00
|
|
|
/*--------------------------------*-C-*---------------------------------*
|
|
|
|
* File: command.c
|
|
|
|
*/
|
|
|
|
/* notes: */
|
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* Copyright 1992 John Bovey, University of Kent at Canterbury.
|
|
|
|
*
|
|
|
|
* You can do what you like with this source code as long as
|
|
|
|
* you don't try to make money out of it and you include an
|
|
|
|
* unaltered copy of this message (including the copyright).
|
|
|
|
*
|
|
|
|
* This module has been very heavily modified by R. Nation
|
|
|
|
* <nation@rocket.sanders.lockheed.com>
|
|
|
|
* No additional restrictions are applied
|
|
|
|
*
|
|
|
|
* Additional modification by Garrett D'Amore <garrett@netcom.com> to
|
|
|
|
* allow vt100 printing. No additional restrictions are applied.
|
|
|
|
*
|
|
|
|
* Integrated modifications by Steven Hirsch <hirsch@emba.uvm.edu> to
|
|
|
|
* properly support X11 mouse report mode and support for DEC
|
|
|
|
* "private mode" save/restore functions.
|
|
|
|
*
|
|
|
|
* Integrated key-related changes by Jakub Jelinek <jj@gnu.ai.mit.edu>
|
|
|
|
* to handle Shift+function keys properly.
|
|
|
|
* Should be used with enclosed termcap / terminfo database.
|
|
|
|
*
|
|
|
|
* Extensive modifications by mj olesen <olesen@me.QueensU.CA>
|
|
|
|
* No additional restrictions.
|
|
|
|
*
|
|
|
|
* Further modification and cleanups for Solaris 2.x and Linux 1.2.x
|
|
|
|
* by Raul Garcia Garcia <rgg@tid.es>. No additional restrictions.
|
|
|
|
*
|
|
|
|
* As usual, the author accepts no responsibility for anything, nor does
|
|
|
|
* he guarantee anything whatsoever.
|
|
|
|
*----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static const char cvs_ident[] = "$Id$";
|
|
|
|
|
|
|
|
/* includes: */
|
|
|
|
#include "config.h"
|
1999-08-17 18:12:47 -07:00
|
|
|
#include "feature.h"
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
/* System Headers */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2000-03-14 19:17:45 -08:00
|
|
|
#include <string.h>
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
# include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
1999-10-19 10:44:02 -07:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-08-17 16:01:18 -07:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
/* X11 Headers */
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xos.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/IntrinsicP.h>
|
1999-12-30 04:44:45 -08:00
|
|
|
#ifdef PTY_GRP_NAME
|
1999-08-17 16:01:18 -07:00
|
|
|
# include <grp.h>
|
|
|
|
#endif
|
|
|
|
#ifdef TIME_WITH_SYS_TIME
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <time.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
# else
|
|
|
|
# include <time.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#if defined (__svr4__)
|
2002-05-04 07:25:30 -07:00
|
|
|
# include <sys/resource.h> /* for struct rlimit */
|
|
|
|
# include <sys/stropts.h> /* for I_PUSH */
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef HAVE_SYS_STRTIO_H
|
|
|
|
# include <sys/strtio.h>
|
|
|
|
# endif
|
|
|
|
# ifdef HAVE_BSDTTY_H
|
|
|
|
# include <bsdtty.h>
|
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
# define _NEW_TTY_CTRL /* to get proper defines in <termios.h> */
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
# include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
# include <termios.h>
|
|
|
|
#else
|
|
|
|
# include <sgtty.h>
|
|
|
|
#endif
|
|
|
|
#if defined(__sun) && defined(__SVR4)
|
|
|
|
# include <sys/strredir.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#if defined(linux)
|
2002-05-04 07:25:30 -07:00
|
|
|
# include <linux/tty.h> /* For N_TTY_BUF_SIZE. */
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Eterm-specific Headers */
|
|
|
|
#include "command.h"
|
1999-10-07 15:18:14 -07:00
|
|
|
#include "startup.h"
|
1999-08-17 18:12:47 -07:00
|
|
|
#include "events.h"
|
1999-09-22 15:15:46 -07:00
|
|
|
#include "font.h"
|
1999-08-17 16:01:18 -07:00
|
|
|
#include "grkelot.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "pixmap.h"
|
|
|
|
#ifdef PROFILE
|
|
|
|
# include "profile.h"
|
|
|
|
#endif
|
1999-08-17 18:12:47 -07:00
|
|
|
#include "screen.h"
|
|
|
|
#include "scrollbar.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "term.h"
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef UTMP_SUPPORT
|
1999-08-17 18:12:47 -07:00
|
|
|
# include "eterm_utmp.h"
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
1999-08-17 18:12:47 -07:00
|
|
|
#include "windows.h"
|
2000-06-26 09:33:23 -07:00
|
|
|
#include "buttons.h"
|
2002-05-13 15:47:08 -07:00
|
|
|
#include "menus.h"
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
#ifdef ESCREEN
|
2002-06-08 08:44:08 -07:00
|
|
|
# include "screamcfg.h"
|
|
|
|
# ifdef NS_HAVE_TWIN
|
|
|
|
# include <Tw/Tw.h>
|
|
|
|
TW_DECL_MAGIC(libscream_magic);
|
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
#endif
|
|
|
|
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
static RETSIGTYPE handle_child_signal(int);
|
|
|
|
static RETSIGTYPE handle_exit_signal(int);
|
|
|
|
static RETSIGTYPE handle_crash(int);
|
|
|
|
|
1999-08-17 16:01:18 -07:00
|
|
|
/* local variables */
|
1999-08-17 18:12:47 -07:00
|
|
|
int my_ruid, my_euid, my_rgid, my_egid;
|
1999-08-17 16:01:18 -07:00
|
|
|
char initial_dir[PATH_MAX + 1];
|
2002-06-08 08:44:08 -07:00
|
|
|
static char *ptydev = NULL, *ttydev = NULL; /* pty/tty name */
|
2002-05-04 07:25:30 -07:00
|
|
|
int cmd_fd = -1; /* file descriptor connected to the command */
|
2000-03-08 19:38:31 -08:00
|
|
|
int pipe_fd = -1;
|
2002-05-04 07:25:30 -07:00
|
|
|
pid_t cmd_pid = -1; /* process id if child */
|
|
|
|
int Xfd = -1; /* file descriptor of X server connection */
|
|
|
|
unsigned int num_fds = 0; /* number of file descriptors being used */
|
|
|
|
struct stat ttyfd_stat; /* original status of the tty we will use */
|
1999-08-17 18:12:47 -07:00
|
|
|
int refresh_count = 0, refresh_limit = 1, refresh_type = FAST_REFRESH;
|
|
|
|
unsigned char cmdbuf_base[CMD_BUF_SIZE], *cmdbuf_ptr, *cmdbuf_endp;
|
2002-06-02 17:24:22 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* Addresses pasting large amounts of data
|
|
|
|
* code pinched from xterm
|
|
|
|
*/
|
2002-05-04 07:25:30 -07:00
|
|
|
static char *v_buffer; /* pointer to physical buffer */
|
|
|
|
static char *v_bufstr = NULL; /* beginning of area to write */
|
|
|
|
static char *v_bufptr; /* end of area to write */
|
|
|
|
static char *v_bufend; /* end of physical buffer */
|
2002-06-02 17:24:22 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef USE_XIM
|
2000-11-16 15:45:01 -08:00
|
|
|
XIM xim_input_method = NULL;
|
2002-05-04 07:25:30 -07:00
|
|
|
XIC xim_input_context = NULL; /* input context */
|
1999-11-19 15:21:09 -08:00
|
|
|
static XIMStyle xim_input_style = 0;
|
2002-06-02 17:24:22 -07:00
|
|
|
|
1999-12-02 18:31:33 -08:00
|
|
|
# ifndef XSetIMValues
|
|
|
|
extern char *XSetIMValues(XIM im, ...);
|
|
|
|
# endif
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Substitutes for missing system functions */
|
1999-08-17 18:12:47 -07:00
|
|
|
#if !defined(_POSIX_VERSION) && defined(__svr4__)
|
1999-08-17 16:01:18 -07:00
|
|
|
int
|
|
|
|
getdtablesize(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
struct rlimit rlim;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
getrlimit(RLIMIT_NOFILE, &rlim);
|
|
|
|
return rlim.rlim_cur;
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Take care of suid/sgid super-user (root) privileges */
|
|
|
|
void
|
|
|
|
privileges(int mode)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef __CYGWIN32__
|
2002-05-04 07:25:30 -07:00
|
|
|
return;
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
switch (mode) {
|
|
|
|
case IGNORE:
|
|
|
|
/* Revoke suid/sgid privs and return to normal uid/gid -- mej */
|
|
|
|
D_UTMP(("[%ld]: Before privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid()));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_SETRESGID
|
2002-05-04 07:25:30 -07:00
|
|
|
setresgid(my_rgid, my_rgid, my_egid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(HAVE_SAVED_UIDS)
|
2002-05-04 07:25:30 -07:00
|
|
|
setregid(my_rgid, my_rgid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
setregid(my_egid, -1);
|
|
|
|
setregid(-1, my_rgid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SETRESUID
|
2002-05-04 07:25:30 -07:00
|
|
|
setresuid(my_ruid, my_ruid, my_euid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(HAVE_SAVED_UIDS)
|
2002-05-04 07:25:30 -07:00
|
|
|
setreuid(my_ruid, my_ruid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
setreuid(my_euid, -1);
|
|
|
|
setreuid(-1, my_ruid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_UTMP(("[%ld]: After privileges(REVERT): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid()));
|
|
|
|
break;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
case SAVE:
|
|
|
|
break;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
case RESTORE:
|
|
|
|
D_UTMP(("[%ld]: Before privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid()));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_SETRESUID
|
2002-05-04 07:25:30 -07:00
|
|
|
setresuid(my_ruid, my_euid, my_euid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(HAVE_SAVED_UIDS)
|
2002-05-04 07:25:30 -07:00
|
|
|
setreuid(my_ruid, my_euid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
setreuid(-1, my_euid);
|
|
|
|
setreuid(my_ruid, -1);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SETRESGID
|
2002-05-04 07:25:30 -07:00
|
|
|
setresgid(my_rgid, my_egid, my_egid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(HAVE_SAVED_UIDS)
|
2002-05-04 07:25:30 -07:00
|
|
|
setregid(my_rgid, my_egid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
setregid(-1, my_egid);
|
|
|
|
setregid(my_rgid, -1);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_UTMP(("[%ld]: After privileges(INVOKE): [ %ld, %ld ] [ %ld, %ld ]\n", getpid(), getuid(), getgid(), geteuid(), getegid()));
|
|
|
|
break;
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
sig_to_str(int sig)
|
|
|
|
{
|
|
|
|
#ifdef SIGHUP
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGHUP) {
|
|
|
|
return ("SIGHUP");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGINT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGINT) {
|
|
|
|
return ("SIGINT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGQUIT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGQUIT) {
|
|
|
|
return ("SIGQUIT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGILL
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGILL) {
|
|
|
|
return ("SIGILL");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGTRAP
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGTRAP) {
|
|
|
|
return ("SIGTRAP");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGABRT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGABRT) {
|
|
|
|
return ("SIGABRT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGIOT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGIOT) {
|
|
|
|
return ("SIGIOT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGEMT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGEMT) {
|
|
|
|
return ("SIGEMT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGFPE
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGFPE) {
|
|
|
|
return ("SIGFPE");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGKILL
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGKILL) {
|
|
|
|
return ("SIGKILL");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGBUS
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGBUS) {
|
|
|
|
return ("SIGBUS");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSEGV
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGSEGV) {
|
|
|
|
return ("SIGSEGV");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSYS
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGSYS) {
|
|
|
|
return ("SIGSYS");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGPIPE
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGPIPE) {
|
|
|
|
return ("SIGPIPE");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGALRM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGALRM) {
|
|
|
|
return ("SIGALRM");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGTERM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGTERM) {
|
|
|
|
return ("SIGTERM");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGUSR1
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGUSR1) {
|
|
|
|
return ("SIGUSR1");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGUSR2
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGUSR2) {
|
|
|
|
return ("SIGUSR2");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGCHLD
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGCHLD) {
|
|
|
|
return ("SIGCHLD");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGCLD
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGCLD) {
|
|
|
|
return ("SIGCLD");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGPWR
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGPWR) {
|
|
|
|
return ("SIGPWR");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGVTALRM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGVTALRM) {
|
|
|
|
return ("SIGVTALRM");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGPROF
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGPROF) {
|
|
|
|
return ("SIGPROF");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGIO
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGIO) {
|
|
|
|
return ("SIGIO");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGPOLL
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGPOLL) {
|
|
|
|
return ("SIGPOLL");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGWINCH
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGWINCH) {
|
|
|
|
return ("SIGWINCH");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGWINDOW
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGWINDOW) {
|
|
|
|
return ("SIGWINDOW");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGSTOP
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGSTOP) {
|
|
|
|
return ("SIGSTOP");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGTSTP
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGTSTP) {
|
|
|
|
return ("SIGTSTP");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGCONT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGCONT) {
|
|
|
|
return ("SIGCONT");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGTTIN
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGTTIN) {
|
|
|
|
return ("SIGTTIN");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGTTOU
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGTTOU) {
|
|
|
|
return ("SIGTTOU");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGURG
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGURG) {
|
|
|
|
return ("SIGURG");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGLOST
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGLOST) {
|
|
|
|
return ("SIGLOST");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGRESERVE
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGRESERVE) {
|
|
|
|
return ("SIGRESERVE");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGDIL
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGDIL) {
|
|
|
|
return ("SIGDIL");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGXCPU
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGXCPU) {
|
|
|
|
return ("SIGXCPU");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SIGXFSZ
|
2002-05-04 07:25:30 -07:00
|
|
|
if (sig == SIGXFSZ) {
|
|
|
|
return ("SIGXFSZ");
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
return ("Unknown signal");
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
event_type_to_name(int type)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (type == KeyPress) {
|
|
|
|
return "KeyPress";
|
|
|
|
}
|
|
|
|
if (type == KeyRelease) {
|
|
|
|
return "KeyRelease";
|
|
|
|
}
|
|
|
|
if (type == ButtonPress) {
|
|
|
|
return "ButtonPress";
|
|
|
|
}
|
|
|
|
if (type == ButtonRelease) {
|
|
|
|
return "ButtonRelease";
|
|
|
|
}
|
|
|
|
if (type == MotionNotify) {
|
|
|
|
return "MotionNotify";
|
|
|
|
}
|
|
|
|
if (type == EnterNotify) {
|
|
|
|
return "EnterNotify";
|
|
|
|
}
|
|
|
|
if (type == LeaveNotify) {
|
|
|
|
return "LeaveNotify";
|
|
|
|
}
|
|
|
|
if (type == FocusIn) {
|
|
|
|
return "FocusIn";
|
|
|
|
}
|
|
|
|
if (type == FocusOut) {
|
|
|
|
return "FocusOut";
|
|
|
|
}
|
|
|
|
if (type == KeymapNotify) {
|
|
|
|
return "KeymapNotify";
|
|
|
|
}
|
|
|
|
if (type == Expose) {
|
|
|
|
return "Expose";
|
|
|
|
}
|
|
|
|
if (type == GraphicsExpose) {
|
|
|
|
return "GraphicsExpose";
|
|
|
|
}
|
|
|
|
if (type == NoExpose) {
|
|
|
|
return "NoExpose";
|
|
|
|
}
|
|
|
|
if (type == VisibilityNotify) {
|
|
|
|
return "VisibilityNotify";
|
|
|
|
}
|
|
|
|
if (type == CreateNotify) {
|
|
|
|
return "CreateNotify";
|
|
|
|
}
|
|
|
|
if (type == DestroyNotify) {
|
|
|
|
return "DestroyNotify";
|
|
|
|
}
|
|
|
|
if (type == UnmapNotify) {
|
|
|
|
return "UnmapNotify";
|
|
|
|
}
|
|
|
|
if (type == MapNotify) {
|
|
|
|
return "MapNotify";
|
|
|
|
}
|
|
|
|
if (type == MapRequest) {
|
|
|
|
return "MapRequest";
|
|
|
|
}
|
|
|
|
if (type == ReparentNotify) {
|
|
|
|
return "ReparentNotify";
|
|
|
|
}
|
|
|
|
if (type == ConfigureNotify) {
|
|
|
|
return "ConfigureNotify";
|
|
|
|
}
|
|
|
|
if (type == ConfigureRequest) {
|
|
|
|
return "ConfigureRequest";
|
|
|
|
}
|
|
|
|
if (type == GravityNotify) {
|
|
|
|
return "GravityNotify";
|
|
|
|
}
|
|
|
|
if (type == ResizeRequest) {
|
|
|
|
return "ResizeRequest";
|
|
|
|
}
|
|
|
|
if (type == CirculateNotify) {
|
|
|
|
return "CirculateNotify";
|
|
|
|
}
|
|
|
|
if (type == CirculateRequest) {
|
|
|
|
return "CirculateRequest";
|
|
|
|
}
|
|
|
|
if (type == PropertyNotify) {
|
|
|
|
return "PropertyNotify";
|
|
|
|
}
|
|
|
|
if (type == SelectionClear) {
|
|
|
|
return "SelectionClear";
|
|
|
|
}
|
|
|
|
if (type == SelectionRequest) {
|
|
|
|
return "SelectionRequest";
|
|
|
|
}
|
|
|
|
if (type == SelectionNotify) {
|
|
|
|
return "SelectionNotify";
|
|
|
|
}
|
|
|
|
if (type == ColormapNotify) {
|
|
|
|
return "ColormapNotify";
|
|
|
|
}
|
|
|
|
if (type == ClientMessage) {
|
|
|
|
return "ClientMessage";
|
|
|
|
}
|
|
|
|
if (type == MappingNotify) {
|
|
|
|
return "MappingNotify";
|
|
|
|
}
|
|
|
|
return "Bad Event!";
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
request_code_to_name(int code)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (code == X_CreateWindow) {
|
|
|
|
return "XCreateWindow";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeWindowAttributes) {
|
|
|
|
return "XChangeWindowAttributes";
|
|
|
|
}
|
|
|
|
if (code == X_GetWindowAttributes) {
|
|
|
|
return "XGetWindowAttributes";
|
|
|
|
}
|
|
|
|
if (code == X_DestroyWindow) {
|
|
|
|
return "XDestroyWindow";
|
|
|
|
}
|
|
|
|
if (code == X_DestroySubwindows) {
|
|
|
|
return "XDestroySubwindows";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeSaveSet) {
|
|
|
|
return "XChangeSaveSet";
|
|
|
|
}
|
|
|
|
if (code == X_ReparentWindow) {
|
|
|
|
return "XReparentWindow";
|
|
|
|
}
|
|
|
|
if (code == X_MapWindow) {
|
|
|
|
return "XMapWindow";
|
|
|
|
}
|
|
|
|
if (code == X_MapSubwindows) {
|
|
|
|
return "XMapSubwindows";
|
|
|
|
}
|
|
|
|
if (code == X_UnmapWindow) {
|
|
|
|
return "XUnmapWindow";
|
|
|
|
}
|
|
|
|
if (code == X_UnmapSubwindows) {
|
|
|
|
return "XUnmapSubwindows";
|
|
|
|
}
|
|
|
|
if (code == X_ConfigureWindow) {
|
|
|
|
return "XConfigureWindow";
|
|
|
|
}
|
|
|
|
if (code == X_CirculateWindow) {
|
|
|
|
return "XCirculateWindow";
|
|
|
|
}
|
|
|
|
if (code == X_GetGeometry) {
|
|
|
|
return "XGetGeometry";
|
|
|
|
}
|
|
|
|
if (code == X_QueryTree) {
|
|
|
|
return "XQueryTree";
|
|
|
|
}
|
|
|
|
if (code == X_InternAtom) {
|
|
|
|
return "XInternAtom";
|
|
|
|
}
|
|
|
|
if (code == X_GetAtomName) {
|
|
|
|
return "XGetAtomName";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeProperty) {
|
|
|
|
return "XChangeProperty";
|
|
|
|
}
|
|
|
|
if (code == X_DeleteProperty) {
|
|
|
|
return "XDeleteProperty";
|
|
|
|
}
|
|
|
|
if (code == X_GetProperty) {
|
|
|
|
return "XGetProperty";
|
|
|
|
}
|
|
|
|
if (code == X_ListProperties) {
|
|
|
|
return "XListProperties";
|
|
|
|
}
|
|
|
|
if (code == X_SetSelectionOwner) {
|
|
|
|
return "XSetSelectionOwner";
|
|
|
|
}
|
|
|
|
if (code == X_GetSelectionOwner) {
|
|
|
|
return "XGetSelectionOwner";
|
|
|
|
}
|
|
|
|
if (code == X_ConvertSelection) {
|
|
|
|
return "XConvertSelection";
|
|
|
|
}
|
|
|
|
if (code == X_SendEvent) {
|
|
|
|
return "XSendEvent";
|
|
|
|
}
|
|
|
|
if (code == X_GrabPointer) {
|
|
|
|
return "XGrabPointer";
|
|
|
|
}
|
|
|
|
if (code == X_UngrabPointer) {
|
|
|
|
return "XUngrabPointer";
|
|
|
|
}
|
|
|
|
if (code == X_GrabButton) {
|
|
|
|
return "XGrabButton";
|
|
|
|
}
|
|
|
|
if (code == X_UngrabButton) {
|
|
|
|
return "XUngrabButton";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeActivePointerGrab) {
|
|
|
|
return "XChangeActivePointerGrab";
|
|
|
|
}
|
|
|
|
if (code == X_GrabKeyboard) {
|
|
|
|
return "XGrabKeyboard";
|
|
|
|
}
|
|
|
|
if (code == X_UngrabKeyboard) {
|
|
|
|
return "XUngrabKeyboard";
|
|
|
|
}
|
|
|
|
if (code == X_GrabKey) {
|
|
|
|
return "XGrabKey";
|
|
|
|
}
|
|
|
|
if (code == X_UngrabKey) {
|
|
|
|
return "XUngrabKey";
|
|
|
|
}
|
|
|
|
if (code == X_AllowEvents) {
|
|
|
|
return "XAllowEvents";
|
|
|
|
}
|
|
|
|
if (code == X_GrabServer) {
|
|
|
|
return "XGrabServer";
|
|
|
|
}
|
|
|
|
if (code == X_UngrabServer) {
|
|
|
|
return "XUngrabServer";
|
|
|
|
}
|
|
|
|
if (code == X_QueryPointer) {
|
|
|
|
return "XQueryPointer";
|
|
|
|
}
|
|
|
|
if (code == X_GetMotionEvents) {
|
|
|
|
return "XGetMotionEvents";
|
|
|
|
}
|
|
|
|
if (code == X_TranslateCoords) {
|
|
|
|
return "XTranslateCoords";
|
|
|
|
}
|
|
|
|
if (code == X_WarpPointer) {
|
|
|
|
return "XWarpPointer";
|
|
|
|
}
|
|
|
|
if (code == X_SetInputFocus) {
|
|
|
|
return "XSetInputFocus";
|
|
|
|
}
|
|
|
|
if (code == X_GetInputFocus) {
|
|
|
|
return "XGetInputFocus";
|
|
|
|
}
|
|
|
|
if (code == X_QueryKeymap) {
|
|
|
|
return "XQueryKeymap";
|
|
|
|
}
|
|
|
|
if (code == X_OpenFont) {
|
|
|
|
return "XOpenFont";
|
|
|
|
}
|
|
|
|
if (code == X_CloseFont) {
|
|
|
|
return "XCloseFont";
|
|
|
|
}
|
|
|
|
if (code == X_QueryFont) {
|
|
|
|
return "XQueryFont";
|
|
|
|
}
|
|
|
|
if (code == X_QueryTextExtents) {
|
|
|
|
return "XQueryTextExtents";
|
|
|
|
}
|
|
|
|
if (code == X_ListFonts) {
|
|
|
|
return "XListFonts";
|
|
|
|
}
|
|
|
|
if (code == X_ListFontsWithInfo) {
|
|
|
|
return "XListFontsWithInfo";
|
|
|
|
}
|
|
|
|
if (code == X_SetFontPath) {
|
|
|
|
return "XSetFontPath";
|
|
|
|
}
|
|
|
|
if (code == X_GetFontPath) {
|
|
|
|
return "XGetFontPath";
|
|
|
|
}
|
|
|
|
if (code == X_CreatePixmap) {
|
|
|
|
return "XCreatePixmap";
|
|
|
|
}
|
|
|
|
if (code == X_FreePixmap) {
|
|
|
|
return "XFreePixmap";
|
|
|
|
}
|
|
|
|
if (code == X_CreateGC) {
|
|
|
|
return "XCreateGC";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeGC) {
|
|
|
|
return "XChangeGC";
|
|
|
|
}
|
|
|
|
if (code == X_CopyGC) {
|
|
|
|
return "XCopyGC";
|
|
|
|
}
|
|
|
|
if (code == X_SetDashes) {
|
|
|
|
return "XSetDashes";
|
|
|
|
}
|
|
|
|
if (code == X_SetClipRectangles) {
|
|
|
|
return "XSetClipRectangles";
|
|
|
|
}
|
|
|
|
if (code == X_FreeGC) {
|
|
|
|
return "XFreeGC";
|
|
|
|
}
|
|
|
|
if (code == X_ClearArea) {
|
|
|
|
return "XClearArea";
|
|
|
|
}
|
|
|
|
if (code == X_CopyArea) {
|
|
|
|
return "XCopyArea";
|
|
|
|
}
|
|
|
|
if (code == X_CopyPlane) {
|
|
|
|
return "XCopyPlane";
|
|
|
|
}
|
|
|
|
if (code == X_PolyPoint) {
|
|
|
|
return "XPolyPoint";
|
|
|
|
}
|
|
|
|
if (code == X_PolyLine) {
|
|
|
|
return "XPolyLine";
|
|
|
|
}
|
|
|
|
if (code == X_PolySegment) {
|
|
|
|
return "XPolySegment";
|
|
|
|
}
|
|
|
|
if (code == X_PolyRectangle) {
|
|
|
|
return "XPolyRectangle";
|
|
|
|
}
|
|
|
|
if (code == X_PolyArc) {
|
|
|
|
return "XPolyArc";
|
|
|
|
}
|
|
|
|
if (code == X_FillPoly) {
|
|
|
|
return "XFillPoly";
|
|
|
|
}
|
|
|
|
if (code == X_PolyFillRectangle) {
|
|
|
|
return "XPolyFillRectangle";
|
|
|
|
}
|
|
|
|
if (code == X_PolyFillArc) {
|
|
|
|
return "XPolyFillArc";
|
|
|
|
}
|
|
|
|
if (code == X_PutImage) {
|
|
|
|
return "XPutImage";
|
|
|
|
}
|
|
|
|
if (code == X_GetImage) {
|
|
|
|
return "XGetImage";
|
|
|
|
}
|
|
|
|
if (code == X_PolyText8) {
|
|
|
|
return "XPolyText8";
|
|
|
|
}
|
|
|
|
if (code == X_PolyText16) {
|
|
|
|
return "XPolyText16";
|
|
|
|
}
|
|
|
|
if (code == X_ImageText8) {
|
|
|
|
return "XImageText8";
|
|
|
|
}
|
|
|
|
if (code == X_ImageText16) {
|
|
|
|
return "XImageText16";
|
|
|
|
}
|
|
|
|
if (code == X_CreateColormap) {
|
|
|
|
return "XCreateColormap";
|
|
|
|
}
|
|
|
|
if (code == X_FreeColormap) {
|
|
|
|
return "XFreeColormap";
|
|
|
|
}
|
|
|
|
if (code == X_CopyColormapAndFree) {
|
|
|
|
return "XCopyColormapAndFree";
|
|
|
|
}
|
|
|
|
if (code == X_InstallColormap) {
|
|
|
|
return "XInstallColormap";
|
|
|
|
}
|
|
|
|
if (code == X_UninstallColormap) {
|
|
|
|
return "XUninstallColormap";
|
|
|
|
}
|
|
|
|
if (code == X_ListInstalledColormaps) {
|
|
|
|
return "XListInstalledColormaps";
|
|
|
|
}
|
|
|
|
if (code == X_AllocColor) {
|
|
|
|
return "XAllocColor";
|
|
|
|
}
|
|
|
|
if (code == X_AllocNamedColor) {
|
|
|
|
return "XAllocNamedColor";
|
|
|
|
}
|
|
|
|
if (code == X_AllocColorCells) {
|
|
|
|
return "XAllocColorCells";
|
|
|
|
}
|
|
|
|
if (code == X_AllocColorPlanes) {
|
|
|
|
return "XAllocColorPlanes";
|
|
|
|
}
|
|
|
|
if (code == X_FreeColors) {
|
|
|
|
return "XFreeColors";
|
|
|
|
}
|
|
|
|
if (code == X_StoreColors) {
|
|
|
|
return "XStoreColors";
|
|
|
|
}
|
|
|
|
if (code == X_StoreNamedColor) {
|
|
|
|
return "XStoreNamedColor";
|
|
|
|
}
|
|
|
|
if (code == X_QueryColors) {
|
|
|
|
return "XQueryColors";
|
|
|
|
}
|
|
|
|
if (code == X_LookupColor) {
|
|
|
|
return "XLookupColor";
|
|
|
|
}
|
|
|
|
if (code == X_CreateCursor) {
|
|
|
|
return "XCreateCursor";
|
|
|
|
}
|
|
|
|
if (code == X_CreateGlyphCursor) {
|
|
|
|
return "XCreateGlyphCursor";
|
|
|
|
}
|
|
|
|
if (code == X_FreeCursor) {
|
|
|
|
return "XFreeCursor";
|
|
|
|
}
|
|
|
|
if (code == X_RecolorCursor) {
|
|
|
|
return "XRecolorCursor";
|
|
|
|
}
|
|
|
|
if (code == X_QueryBestSize) {
|
|
|
|
return "XQueryBestSize";
|
|
|
|
}
|
|
|
|
if (code == X_QueryExtension) {
|
|
|
|
return "XQueryExtension";
|
|
|
|
}
|
|
|
|
if (code == X_ListExtensions) {
|
|
|
|
return "XListExtensions";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeKeyboardMapping) {
|
|
|
|
return "XChangeKeyboardMapping";
|
|
|
|
}
|
|
|
|
if (code == X_GetKeyboardMapping) {
|
|
|
|
return "XGetKeyboardMapping";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeKeyboardControl) {
|
|
|
|
return "XChangeKeyboardControl";
|
|
|
|
}
|
|
|
|
if (code == X_GetKeyboardControl) {
|
|
|
|
return "XGetKeyboardControl";
|
|
|
|
}
|
|
|
|
if (code == X_Bell) {
|
|
|
|
return "XBell";
|
|
|
|
}
|
|
|
|
if (code == X_ChangePointerControl) {
|
|
|
|
return "XChangePointerControl";
|
|
|
|
}
|
|
|
|
if (code == X_GetPointerControl) {
|
|
|
|
return "XGetPointerControl";
|
|
|
|
}
|
|
|
|
if (code == X_SetScreenSaver) {
|
|
|
|
return "XSetScreenSaver";
|
|
|
|
}
|
|
|
|
if (code == X_GetScreenSaver) {
|
|
|
|
return "XGetScreenSaver";
|
|
|
|
}
|
|
|
|
if (code == X_ChangeHosts) {
|
|
|
|
return "XChangeHosts";
|
|
|
|
}
|
|
|
|
if (code == X_ListHosts) {
|
|
|
|
return "XListHosts";
|
|
|
|
}
|
|
|
|
if (code == X_SetAccessControl) {
|
|
|
|
return "XSetAccessControl";
|
|
|
|
}
|
|
|
|
if (code == X_SetCloseDownMode) {
|
|
|
|
return "XSetCloseDownMode";
|
|
|
|
}
|
|
|
|
if (code == X_KillClient) {
|
|
|
|
return "XKillClient";
|
|
|
|
}
|
|
|
|
if (code == X_RotateProperties) {
|
|
|
|
return "XRotateProperties";
|
|
|
|
}
|
|
|
|
if (code == X_ForceScreenSaver) {
|
|
|
|
return "XForceScreenSaver";
|
|
|
|
}
|
|
|
|
if (code == X_SetPointerMapping) {
|
|
|
|
return "XSetPointerMapping";
|
|
|
|
}
|
|
|
|
if (code == X_GetPointerMapping) {
|
|
|
|
return "XGetPointerMapping";
|
|
|
|
}
|
|
|
|
if (code == X_SetModifierMapping) {
|
|
|
|
return "XSetModifierMapping";
|
|
|
|
}
|
|
|
|
if (code == X_GetModifierMapping) {
|
|
|
|
return "XGetModifierMapping";
|
|
|
|
}
|
|
|
|
if (code == X_NoOperation) {
|
|
|
|
return "XNoOperation";
|
|
|
|
}
|
|
|
|
return "Unknown";
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
2000-06-26 16:37:05 -07:00
|
|
|
const char *
|
|
|
|
get_ctrl_char_name(char c)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
const char *lookup[] = {
|
2002-06-08 08:44:08 -07:00
|
|
|
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", /* 0-7 */
|
|
|
|
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", /* 8-15 */
|
|
|
|
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", /* 16-23 */
|
|
|
|
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" /* 24-31 */
|
2002-05-04 07:25:30 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return ((c < ' ') ? (lookup[(int) c]) : (""));
|
2000-06-26 16:37:05 -07:00
|
|
|
}
|
|
|
|
|
1999-09-08 10:57:06 -07:00
|
|
|
static void
|
2002-05-04 07:25:30 -07:00
|
|
|
hard_exit(void)
|
|
|
|
{
|
1999-09-08 10:57:06 -07:00
|
|
|
|
|
|
|
#ifdef HAVE__EXIT
|
2002-05-04 07:25:30 -07:00
|
|
|
_exit(-1);
|
1999-09-08 10:57:06 -07:00
|
|
|
#elif defined(SIGKILL)
|
2002-05-04 07:25:30 -07:00
|
|
|
kill(cmd_pid, SIGKILL);
|
|
|
|
abort();
|
1999-09-08 10:57:06 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
kill(cmd_pid, 9);
|
|
|
|
abort();
|
1999-09-08 10:57:06 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-08-17 16:01:18 -07:00
|
|
|
/* Try to get a stack trace when we croak */
|
|
|
|
void
|
|
|
|
dump_stack_trace(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
char cmd[256];
|
|
|
|
struct stat st;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef NO_STACK_TRACE
|
2002-05-04 07:25:30 -07:00
|
|
|
return;
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
print_error("Attempting to dump a stack trace....\n");
|
|
|
|
signal(SIGTSTP, exit); /* Don't block on tty output, just die */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_U_STACK_TRACE
|
2002-05-04 07:25:30 -07:00
|
|
|
U_STACK_TRACE();
|
2000-08-31 22:46:04 -07:00
|
|
|
return;
|
2002-05-04 07:25:30 -07:00
|
|
|
#elif defined(GDB)
|
|
|
|
if (((stat(GDB_CMD_FILE, &st)) != 0) || (!S_ISREG(st.st_mode))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snprintf(cmd, sizeof(cmd), GDB " -x " GDB_CMD_FILE " " APL_NAME " %d", getpid());
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(PSTACK)
|
2002-05-04 07:25:30 -07:00
|
|
|
snprintf(cmd, sizeof(cmd), PSTACK " %d", getpid());
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(DBX)
|
|
|
|
# ifdef _AIX
|
2002-05-04 07:25:30 -07:00
|
|
|
snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -a %d", getpid());
|
1999-08-17 16:01:18 -07:00
|
|
|
# elif defined(__sgi)
|
2002-05-04 07:25:30 -07:00
|
|
|
snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " -p %d", getpid());
|
1999-08-17 16:01:18 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
snprintf(cmd, sizeof(cmd), "/bin/echo 'where\ndetach' | " DBX " %s %d", orig_argv0, getpid());
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
print_error("Your system does not support any of the methods Eterm uses. Exiting.\n");
|
|
|
|
return;
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
signal(SIGALRM, (eterm_sighandler_t) hard_exit);
|
|
|
|
alarm(3);
|
|
|
|
system(cmd);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* signal handling, exit handler */
|
|
|
|
/*
|
|
|
|
* Catch a SIGCHLD signal and exit if the direct child has died
|
|
|
|
*/
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
static RETSIGTYPE
|
|
|
|
handle_child_signal(int sig)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int pid, save_errno = errno;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("Received signal %s (%d)\n", sig_to_str(sig), sig));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
do {
|
|
|
|
errno = 0;
|
|
|
|
} while ((-1 == (pid = waitpid(-1, NULL, WNOHANG))) && (errno == EINTR));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("pid == %d, cmd_pid == %d\n", pid, cmd_pid));
|
|
|
|
/* If the child that exited is the command we spawned, or if the
|
|
|
|
child exited before fork() returned in the parent, it must be
|
|
|
|
our immediate child that exited. We exit gracefully. */
|
2002-07-03 10:55:48 -07:00
|
|
|
if (((pid == cmd_pid) && (cmd_pid != -1))
|
|
|
|
|| ((pid == -1) && (errno == ECHILD) && (cmd_pid != -1))
|
|
|
|
|| ((pid == 0) && (cmd_pid != -1) && ((kill(cmd_pid, 0)) < 0))) {
|
2002-05-04 07:25:30 -07:00
|
|
|
if (Options & Opt_pause) {
|
|
|
|
paused = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
exit(EXIT_SUCCESS);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
2002-07-03 10:55:48 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
errno = save_errno;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("handle_child_signal: installing signal handler\n"));
|
|
|
|
signal(SIGCHLD, handle_child_signal);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
SIG_RETURN(0);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles signals usually sent by a user, like HUP, TERM, INT. */
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
static RETSIGTYPE
|
|
|
|
handle_exit_signal(int sig)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig);
|
|
|
|
signal(sig, SIG_DFL);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef UTMP_SUPPORT
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
|
|
|
remove_utmp_entry();
|
|
|
|
privileges(REVERT);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("exit(%s)\n", sig_to_str(sig)));
|
|
|
|
exit(sig);
|
|
|
|
SIG_RETURN(0);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles abnormal termination signals -- mej */
|
|
|
|
static RETSIGTYPE
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
handle_crash(int sig)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
print_error("Received terminal signal %s (%d)\n", sig_to_str(sig), sig);
|
|
|
|
signal(sig, SIG_DFL); /* Let the OS handle recursive seg faults */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Lock down security so we don't write any core files as root. */
|
|
|
|
privileges(REVERT);
|
|
|
|
umask(077);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Make an attempt to dump a stack trace */
|
|
|
|
dump_stack_trace();
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Exit */
|
|
|
|
exit(sig);
|
|
|
|
SIG_RETURN(0);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
void
|
|
|
|
install_handlers(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Ignore SIGHUP */
|
|
|
|
/* signal(SIGHUP, handle_exit_signal); */
|
|
|
|
signal(SIGHUP, SIG_IGN);
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
#ifndef __svr4__
|
2002-05-04 07:25:30 -07:00
|
|
|
signal(SIGINT, handle_exit_signal);
|
|
|
|
#endif
|
|
|
|
signal(SIGTERM, handle_exit_signal);
|
|
|
|
signal(SIGCHLD, handle_child_signal);
|
|
|
|
signal(SIGQUIT, handle_crash);
|
|
|
|
signal(SIGSEGV, handle_crash);
|
|
|
|
signal(SIGBUS, handle_crash);
|
|
|
|
signal(SIGABRT, handle_crash);
|
|
|
|
signal(SIGFPE, handle_crash);
|
|
|
|
signal(SIGILL, handle_crash);
|
|
|
|
signal(SIGSYS, handle_crash);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
Wed Apr 12 21:18:19 PDT 2000 Michael Jennings <mej@eterm.org>
This is the initial commit with Imlib2 support. READ THIS CAREFULLY.
There is important information in this commit message that will keep
you from getting screwed.
First off, support for Imlib 1.x is GONE. It is no longer supported
as of now. If you want to continue using it, do NOT install this
version. I tried to support both for awhile, but the code ended up
being way too ugly and hackish. Imlib2 is the future. And trust me,
when you see what we do with this future, you'll be happy for the
switch.
The good news is that most of the basics work. Transparency still
works, and the basic image stuff works. Most users won't notice any
major problems, so long as your Imlib2 is 100% up-to-date.
However, a few things still don't work:
1. Auto mode is a bit broken. You'll get X errors in XFree86 4.0.
Don't use it if you're running XFree 4.
2. Color modifiers for images don't work. At all.
3. Transparency shading/tinting will not work in 8bpp or lower. Life
blows sometimes. Sorry. Time for a real video card. :-)
4. The built-in icon is broken.
5. You WILL need to update your theme.cfg files. The borders on the
horizontal and vertical bar images were incorrect when combined with
the new anti-aliased scaling. The horizontal bars should have a right
border of 3. Vertical bars should have a bottom border of 3. The
menu images should have both right *and* bottom borders of 3. You can
either make those changes by hand, or use the --with-theme-update
option to autogen.sh. Your call.
I think that covers everything I've run into. I will point out that
I don't really take advantage of a lot of the Imlib2 features just
yet. My first priority is to make all the stuff that worked before
work again (or at least the important stuff). Then I'll work on
new features.
So there it is. If you're not ready for it, don't use it. But if you
are, I hope you like it.
SVN revision: 2478
2000-04-12 21:19:05 -07:00
|
|
|
}
|
|
|
|
|
Fri May 26 20:43:03 PDT 2000 Michael Jennings <mej@eterm.org>
Okay, there are a few changes here. First off, I made multi-byte font
support the default now, as long as you have ISO 10646 fonts. In
order to do this, I made the default encoding type "Latin1" so as not
to interfere with 8-bit ISO 8859-1 characters. This means that if you
relied on the default multi-byte encoding method to be SJIS, you'll
need to update your theme files.
I also set it up so that Eterm will ignore SIGHUP, at least until I do
something with it (like reloading the theme or something).
I fixed the proportional font size algorithm. If there is more than
a 3-pixel variance between the minimum and maximum sizes for glyphs in
a proportional font, Eterm will set the size to 2 standard deviations
above the average width. This is so that they won't look so spread
out and ugly, but it still doesn't look perfect. Not much I can do on
that front...terminals must have fixed-width columns.
And then there's the biggie. I put in the ability to configure the
now-infamous font effects. I left a black drop shadow in as the
default, but you can now customize it via the --font-fx option or in
the config file using "font effects <stuff>" in the attributes
context. You can even use "fx" instead of "effects" for short.
So what goes in the <stuff> part? Well, you have several options.
To use a single-color outline, say "outline <color>". Likewise, a
single-color drop shadow is "shadow [corner] <color>"; "bottom_right"
is the default corner if you don't specify one. For a 3-D embossed
look, "emboss <dark_color> <light_color>". The opposite, a carved-
out look, can be had with "carved <dark_color> <light_color>". (Of
course, with those last two, the 3-D look will only work if you
choose the colors wisely.)
Those are all the shortcuts. The long way is to specify a series of
corner/color pairs, like "tl blue" for top-left blue, or
"bottom_right green". You can abbreviate using "tl," "tr," "bl," or
"br," or you can spell out "top_left," "top_right," "bottom_left," or
"bottom_right." If you omit a corner name, the first one defaults to
top-left, the second to top-right, and so on as listed above.
SVN revision: 2714
2000-05-26 20:41:22 -07:00
|
|
|
/* Exit gracefully, clearing the utmp entry and restoring tty attributes */
|
1999-08-17 16:01:18 -07:00
|
|
|
void
|
|
|
|
clean_exit(void)
|
|
|
|
{
|
2000-09-01 21:12:16 -07:00
|
|
|
#if DEBUG >= DEBUG_MEM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
|
|
|
unsigned short i;
|
|
|
|
|
|
|
|
/* Deallocate all our crap to help find memory leaks */
|
|
|
|
selection_clear();
|
|
|
|
scr_release();
|
|
|
|
bbar_free(buttonbar);
|
|
|
|
menulist_clear(menu_list);
|
|
|
|
font_cache_clear();
|
|
|
|
eterm_font_list_clear();
|
2001-10-21 06:21:05 -07:00
|
|
|
# ifdef PIXMAP_SUPPORT
|
2002-06-08 08:44:08 -07:00
|
|
|
FOREACH_IMAGE(free_eterm_image(&(images[idx])););
|
2001-10-21 06:21:05 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
for (i = 0; i < NRS_COLORS; i++) {
|
|
|
|
if (rs_color[i]) {
|
|
|
|
FREE(rs_color[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conf_free_subsystem();
|
2000-12-29 14:59:13 -08:00
|
|
|
# ifdef USE_XIM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (xim_input_context) {
|
|
|
|
XUnsetICFocus(xim_input_context);
|
|
|
|
XDestroyIC(xim_input_context);
|
|
|
|
}
|
|
|
|
if (xim_input_method) {
|
|
|
|
XCloseIM(xim_input_method);
|
|
|
|
}
|
2000-12-29 14:59:13 -08:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
XCloseDisplay(Xdisplay);
|
|
|
|
}
|
2000-09-01 21:12:16 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifndef __CYGWIN32__
|
2002-05-04 07:25:30 -07:00
|
|
|
if (ttydev) {
|
|
|
|
D_CMD(("Restoring \"%s\" to mode %03o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, ttyfd_stat.st_uid, ttyfd_stat.st_gid));
|
|
|
|
if (chmod(ttydev, ttyfd_stat.st_mode) != 0) {
|
|
|
|
D_UTMP(("chmod(\"%s\", %03o) failed: %s\n", ttydev, ttyfd_stat.st_mode, strerror(errno)));
|
|
|
|
}
|
|
|
|
if (chown(ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid) != 0) {
|
|
|
|
D_UTMP(("chown(\"%s\", %d, %d) failed: %s\n", ttydev, ttyfd_stat.st_uid, ttyfd_stat.st_gid, strerror(errno)));
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#endif /* __CYGWIN32__ */
|
|
|
|
|
|
|
|
#ifdef UTMP_SUPPORT
|
2002-05-04 07:25:30 -07:00
|
|
|
remove_utmp_entry();
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(REVERT);
|
2000-08-31 11:05:14 -07:00
|
|
|
#if DEBUG >= DEBUG_MEM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (DEBUG_LEVEL >= DEBUG_MEM) {
|
|
|
|
MALLOC_DUMP();
|
|
|
|
PIXMAP_DUMP();
|
|
|
|
GC_DUMP();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
PABLO_STOP_TRACING();
|
|
|
|
DPRINTF1(("Cleanup done. I am outta here!\n"));
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* Acquire a pseudo-teletype from the system. */
|
|
|
|
/*
|
|
|
|
* On failure, returns -1.
|
|
|
|
* On success, returns the file descriptor.
|
|
|
|
*
|
|
|
|
* If successful, ttydev and ptydev point to the names of the
|
|
|
|
* master and slave parts
|
|
|
|
*/
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef __sgi
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int sgi_get_pty(void);
|
1999-10-27 11:10:40 -07:00
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int
|
1999-08-17 18:12:47 -07:00
|
|
|
sgi_get_pty(void)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
int fd = -1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
|
|
|
ptydev = ttydev = _getpty(&fd, O_RDWR | O_NDELAY, 0620, 0);
|
|
|
|
privileges(REVERT);
|
|
|
|
return (ptydev == NULL ? -1 : fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-11 11:37:55 -07:00
|
|
|
#ifdef HAVE_DEV_PTC
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int aix_get_pty(void);
|
1999-10-27 11:10:40 -07:00
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int
|
1999-08-17 16:01:18 -07:00
|
|
|
aix_get_pty(void)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int fd = -1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((fd = open("/dev/ptc", O_RDWR)) < 0)
|
|
|
|
return (-1);
|
|
|
|
else
|
|
|
|
ptydev = ttydev = ttyname(fd);
|
|
|
|
return (fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-11 11:37:55 -07:00
|
|
|
#ifdef HAVE_SCO_PTYS
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int sco_get_pty(void);
|
1999-10-27 11:10:40 -07:00
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int
|
1999-08-17 16:01:18 -07:00
|
|
|
sco_get_pty(void)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
static char pty_name[] = "/dev/ptyp??\0\0\0";
|
|
|
|
static char tty_name[] = "/dev/ttyp??\0\0\0";
|
|
|
|
int idx;
|
|
|
|
int fd = -1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
ptydev = pty_name;
|
|
|
|
ttydev = tty_name;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
for (idx = 0; idx < 256; idx++) {
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
sprintf(ptydev, "/dev/ptyp%d", idx);
|
|
|
|
sprintf(ttydev, "/dev/ttyp%d", idx);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (access(ttydev, F_OK) < 0) {
|
|
|
|
idx = 256;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((fd = open(ptydev, O_RDWR)) >= 0) {
|
|
|
|
if (access(ttydev, R_OK | W_OK) == 0)
|
|
|
|
return (fd);
|
|
|
|
close(fd);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
return (-1);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-11 11:37:55 -07:00
|
|
|
#ifdef HAVE_DEV_PTMX
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int svr_get_pty(void);
|
1999-10-27 11:10:40 -07:00
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int
|
1999-08-17 16:01:18 -07:00
|
|
|
svr_get_pty(void)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int fd = -1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* open the STREAMS, clone device /dev/ptmx (master pty) */
|
|
|
|
if ((fd = open("/dev/ptmx", O_RDWR)) < 0) {
|
|
|
|
return (-1);
|
1999-08-17 16:01:18 -07:00
|
|
|
} else {
|
2002-05-04 07:25:30 -07:00
|
|
|
if (grantpt(fd) != 0) {
|
|
|
|
print_error("grantpt(%d) failed: %s\n", fd, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
} else if (unlockpt(fd) != 0) {
|
|
|
|
print_error("unlockpt(%d) failed: %s\n", fd, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
} else {
|
|
|
|
ptydev = ttydev = ptsname(fd);
|
|
|
|
if (ttydev == NULL) {
|
|
|
|
print_error("ptsname(%d) failed: %s\n", fd, strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PTYCHAR1 "pqrstuvwxyz"
|
|
|
|
#define PTYCHAR2 "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int gen_get_pty(void);
|
1999-10-27 11:10:40 -07:00
|
|
|
|
2000-03-14 19:17:45 -08:00
|
|
|
inline int
|
1999-08-17 16:01:18 -07:00
|
|
|
gen_get_pty(void)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
static char pty_name[] = "/dev/pty??";
|
|
|
|
static char tty_name[] = "/dev/tty??";
|
|
|
|
int len = sizeof(tty_name);
|
|
|
|
char *c1, *c2;
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
ptydev = pty_name;
|
|
|
|
ttydev = tty_name;
|
|
|
|
|
|
|
|
for (c1 = PTYCHAR1; *c1; c1++) {
|
|
|
|
ptydev[len - 3] = ttydev[len - 3] = *c1;
|
|
|
|
for (c2 = PTYCHAR2; *c2; c2++) {
|
|
|
|
ptydev[len - 2] = ttydev[len - 2] = *c2;
|
|
|
|
if ((fd = open(ptydev, O_RDWR)) >= 0) {
|
|
|
|
if (access(ttydev, R_OK | W_OK) == 0)
|
|
|
|
return (fd);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-1);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
get_pty(void)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int fd = -1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#if defined(__sgi)
|
2002-05-04 07:25:30 -07:00
|
|
|
fd = sgi_get_pty();
|
1999-10-11 11:37:55 -07:00
|
|
|
#elif defined(HAVE_DEV_PTC)
|
2002-05-04 07:25:30 -07:00
|
|
|
fd = aix_get_pty();
|
1999-10-11 11:37:55 -07:00
|
|
|
#elif defined(HAVE_DEV_PTMX)
|
2002-05-04 07:25:30 -07:00
|
|
|
fd = svr_get_pty();
|
1999-10-11 11:37:55 -07:00
|
|
|
#elif defined(HAVE_SCO_PTYS)
|
2002-05-04 07:25:30 -07:00
|
|
|
fd = sco_get_pty();
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Fall back on this method */
|
|
|
|
if (fd == -1) {
|
|
|
|
fd = gen_get_pty();
|
|
|
|
}
|
|
|
|
if (fd != -1) {
|
|
|
|
fcntl(fd, F_SETFL, O_NDELAY);
|
|
|
|
return (fd);
|
|
|
|
} else {
|
|
|
|
print_error("Can't open pseudo-tty -- %s\n", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* establish a controlling teletype for new session */
|
|
|
|
/*
|
|
|
|
* On some systems this can be done with ioctl() but on others we
|
|
|
|
* need to re-open the slave tty.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
get_tty(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
int fd;
|
|
|
|
pid_t pid;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* setsid() [or setpgrp] must be before open of the terminal,
|
|
|
|
* otherwise there is no controlling terminal (Solaris 2.4, HP-UX 9)
|
|
|
|
*/
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifndef ultrix
|
|
|
|
# ifdef NO_SETSID
|
2002-05-04 07:25:30 -07:00
|
|
|
pid = setpgrp(0, 0);
|
1999-08-17 16:01:18 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
pid = setsid();
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
if (pid < 0) {
|
|
|
|
D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid));
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* ultrix */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
|
|
|
if (ttydev == NULL) {
|
|
|
|
print_error("Slave tty device name is NULL. Failed to open slave pty.\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
} else if ((fd = open(ttydev, O_RDWR)) < 0) {
|
|
|
|
print_error("Can't open slave tty %s -- %s\n", ttydev, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
} else {
|
|
|
|
D_TTY(("Opened slave tty %s\n", ttydev));
|
|
|
|
privileges(REVERT);
|
|
|
|
}
|
|
|
|
|
1999-08-17 16:01:18 -07:00
|
|
|
#if defined (__svr4__)
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* Push STREAMS modules:
|
|
|
|
* ptem: pseudo-terminal hardware emulation module.
|
|
|
|
* ldterm: standard terminal line discipline.
|
|
|
|
* ttcompat: V7, 4BSD and XENIX STREAMS compatibility module.
|
|
|
|
*/
|
|
|
|
ioctl(fd, I_PUSH, "ptem");
|
|
|
|
ioctl(fd, I_PUSH, "ldterm");
|
|
|
|
ioctl(fd, I_PUSH, "ttcompat");
|
1999-08-17 16:01:18 -07:00
|
|
|
#else /* __svr4__ */
|
2002-05-04 07:25:30 -07:00
|
|
|
{
|
|
|
|
unsigned int mode = 0620;
|
|
|
|
gid_t gid = my_rgid;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-12-30 04:44:45 -08:00
|
|
|
# ifdef PTY_GRP_NAME
|
2002-05-04 07:25:30 -07:00
|
|
|
{
|
|
|
|
struct group *gr = getgrnam(PTY_GRP_NAME);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (gr) {
|
|
|
|
gid = gr->gr_gid;
|
|
|
|
mode = 0620;
|
|
|
|
}
|
|
|
|
}
|
1999-12-30 04:44:45 -08:00
|
|
|
# endif
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifndef __CYGWIN32__
|
2002-06-08 08:44:08 -07:00
|
|
|
fchown(fd, my_ruid, gid); /* fail silently */
|
2002-05-04 07:25:30 -07:00
|
|
|
fchmod(fd, mode);
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(REVERT);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* __svr4__ */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* Close all file descriptors. If only stdin/out/err are closed,
|
|
|
|
* child processes remain alive upon deletion of the window.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
unsigned short i;
|
|
|
|
unsigned long max_fds;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* get number of available file descriptors */
|
2002-01-03 09:41:23 -08:00
|
|
|
#ifdef _POSIX_VERSION
|
2002-05-04 07:25:30 -07:00
|
|
|
max_fds = sysconf(_SC_OPEN_MAX);
|
2002-01-03 09:41:23 -08:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
max_fds = getdtablesize();
|
2002-01-03 09:41:23 -08:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_TTY(("Closing file descriptors 0-%d.\n", max_fds));
|
|
|
|
for (i = 0; i < max_fds; i++) {
|
|
|
|
if (i != fd)
|
|
|
|
close(i);
|
|
|
|
}
|
|
|
|
D_TTY(("...closed.\n"));
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Reopen stdin, stdout and stderr over the tty file descriptor */
|
|
|
|
dup(fd); /* 0: stdin */
|
|
|
|
dup(fd); /* 1: stdout */
|
|
|
|
dup(fd); /* 2: stderr */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (fd > 2)
|
|
|
|
close(fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef ultrix
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((fd = open("/dev/tty", O_RDONLY)) >= 0) {
|
|
|
|
ioctl(fd, TIOCNOTTY, 0);
|
|
|
|
close(fd);
|
|
|
|
} else {
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef NO_SETSID
|
2002-05-04 07:25:30 -07:00
|
|
|
pid = setpgrp(0, 0);
|
1999-08-17 16:01:18 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
pid = setsid();
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
if (pid < 0) {
|
|
|
|
D_TTYMODE(("%s: setsid() failed: %s, PID == %d\n", rs_name, strerror(errno), pid));
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* no error, we could run with no tty to begin with */
|
1999-08-17 16:01:18 -07:00
|
|
|
#else /* ultrix */
|
|
|
|
|
|
|
|
# ifdef TIOCSCTTY
|
2002-05-04 07:25:30 -07:00
|
|
|
ioctl(0, TIOCSCTTY, 0);
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* set process group */
|
1999-08-17 16:01:18 -07:00
|
|
|
# if defined (_POSIX_VERSION) || defined (__svr4__)
|
2002-05-04 07:25:30 -07:00
|
|
|
tcsetpgrp(0, pid);
|
1999-08-17 16:01:18 -07:00
|
|
|
# elif defined (TIOCSPGRP)
|
2002-05-04 07:25:30 -07:00
|
|
|
ioctl(0, TIOCSPGRP, &pid);
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* svr4 problems: reports no tty, no job control */
|
|
|
|
/* # if !defined (__svr4__) && defined (TIOCSPGRP) */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
close(open(ttydev, O_RDWR, 0));
|
|
|
|
/* # endif */
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* ultrix */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(REVERT);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_TTY(("Returning fd == %d\n", fd));
|
|
|
|
return (fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* debug_ttymode() */
|
|
|
|
#if DEBUG >= DEBUG_TTYMODE && defined(HAVE_TERMIOS_H)
|
|
|
|
|
|
|
|
/* cpp token stringize doesn't work on all machines <sigh> */
|
|
|
|
# define SHOW_TTY_FLAG(flag,name) do { \
|
|
|
|
if ((ttymode->c_iflag) & (flag)) { \
|
|
|
|
fprintf(stderr, "+%s ", name); \
|
|
|
|
} else { \
|
|
|
|
fprintf(stderr, "-%s ", name); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
# define SHOW_CONT_CHAR(entry, name) fprintf(stderr, "%s=%#3o ", name, ttymode->c_cc[entry])
|
|
|
|
static void
|
2000-09-01 21:12:16 -07:00
|
|
|
debug_ttymode(ttymode_t *ttymode)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* c_iflag bits */
|
|
|
|
fprintf(stderr, "Input flags: ");
|
|
|
|
SHOW_TTY_FLAG(IGNBRK, "IGNBRK");
|
|
|
|
SHOW_TTY_FLAG(BRKINT, "BRKINT");
|
|
|
|
SHOW_TTY_FLAG(IGNPAR, "IGNPAR");
|
|
|
|
SHOW_TTY_FLAG(PARMRK, "PARMRK");
|
|
|
|
SHOW_TTY_FLAG(INPCK, "INPCK");
|
|
|
|
SHOW_TTY_FLAG(ISTRIP, "ISTRIP");
|
|
|
|
SHOW_TTY_FLAG(INLCR, "INLCR");
|
|
|
|
SHOW_TTY_FLAG(IGNCR, "IGNCR");
|
|
|
|
SHOW_TTY_FLAG(ICRNL, "ICRNL");
|
|
|
|
SHOW_TTY_FLAG(IXON, "IXON");
|
|
|
|
SHOW_TTY_FLAG(IXOFF, "IXOFF");
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef IUCLC
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_TTY_FLAG(IUCLC, "IUCLC");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef IXANY
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_TTY_FLAG(IXANY, "IXANY");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef IMAXBEL
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_TTY_FLAG(IMAXBEL, "IMAXBEL");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
fprintf(stderr, "Control character mappings: ");
|
|
|
|
SHOW_CONT_CHAR(VINTR, "VINTR");
|
|
|
|
SHOW_CONT_CHAR(VQUIT, "VQUIT");
|
|
|
|
SHOW_CONT_CHAR(VERASE, "VERASE");
|
|
|
|
SHOW_CONT_CHAR(VKILL, "VKILL");
|
|
|
|
SHOW_CONT_CHAR(VEOF, "VEOF");
|
|
|
|
SHOW_CONT_CHAR(VEOL, "VEOL");
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef VEOL2
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VEOL2, "VEOL2");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VSWTC
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VSWTC, "VSWTC");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VSWTCH
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VSWTCH, "VSWTCH");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VSTART, "VSTART");
|
|
|
|
SHOW_CONT_CHAR(VSTOP, "VSTOP");
|
|
|
|
SHOW_CONT_CHAR(VSUSP, "VSUSP");
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef VDSUSP
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VDSUSP, "VDSUSP");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VREPRINT
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VREPRINT, "VREPRINT");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VDISCRD
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VDISCRD, "VDISCRD");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VWERSE
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VWERSE, "VWERSE");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VLNEXT
|
2002-05-04 07:25:30 -07:00
|
|
|
SHOW_CONT_CHAR(VLNEXT, "VLNEXT");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
fprintf(stderr, "\n\n");
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
# undef SHOW_TTY_FLAG
|
|
|
|
# undef SHOW_CONT_CHAR
|
|
|
|
#endif /* DEBUG_TTYMODE */
|
|
|
|
|
|
|
|
/* get_ttymode() */
|
|
|
|
static void
|
2000-09-01 21:12:16 -07:00
|
|
|
get_ttymode(ttymode_t *tio)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* standard System V termios interface
|
|
|
|
*/
|
|
|
|
if (GET_TERMIOS(0, tio) < 0) {
|
|
|
|
/* return error - use system defaults */
|
|
|
|
tio->c_cc[VINTR] = CINTR;
|
|
|
|
tio->c_cc[VQUIT] = CQUIT;
|
|
|
|
tio->c_cc[VERASE] = CERASE;
|
|
|
|
tio->c_cc[VKILL] = CKILL;
|
|
|
|
tio->c_cc[VSTART] = CSTART;
|
|
|
|
tio->c_cc[VSTOP] = CSTOP;
|
|
|
|
tio->c_cc[VSUSP] = CSUSP;
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef VDSUSP
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VDSUSP] = CDSUSP;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VREPRINT
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VREPRINT] = CRPRNT;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VDISCRD
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VDISCRD] = CFLUSH;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VWERSE
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VWERSE] = CWERASE;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VLNEXT
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VLNEXT] = CLNEXT;
|
1999-10-01 08:49:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VSTATUS
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VSTATUS] = CSTATUS;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
tio->c_cc[VEOF] = CEOF;
|
|
|
|
tio->c_cc[VEOL] = VDISABLE;
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef VEOL2
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VEOL2] = VDISABLE;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VSWTC
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VSWTC] = VDISABLE;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# ifdef VSWTCH
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VSWTCH] = VDISABLE;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# if VMIN != VEOF
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VMIN] = 1;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
# if VTIME != VEOL
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->c_cc[VTIME] = 0;
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* input modes */
|
|
|
|
tio->c_iflag = (BRKINT | IGNPAR | ICRNL | IXON
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef IMAXBEL
|
2002-05-04 07:25:30 -07:00
|
|
|
| IMAXBEL
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* output modes */
|
|
|
|
tio->c_oflag = (OPOST | ONLCR);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* control modes */
|
|
|
|
tio->c_cflag = (CS8 | CREAD);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* line discipline modes */
|
|
|
|
tio->c_lflag = (ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK
|
1999-08-17 16:01:18 -07:00
|
|
|
# if defined (ECHOCTL) && defined (ECHOKE)
|
2002-05-04 07:25:30 -07:00
|
|
|
| ECHOCTL | ECHOKE
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#if defined(FORCE_BACKSPACE) && 0
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode(1, PrivMode_BackSpace);
|
|
|
|
tio->c_cc[VERASE] = '\b'; /* force ^H for stty setting... */
|
|
|
|
SET_TERMIOS(0, tio); /* ...and make it stick -- casey */
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(FORCE_DELETE) && 0
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode(0, PrivMode_BackSpace);
|
|
|
|
tio->c_cc[VERASE] = 0x7f; /* force ^? for stty setting... */
|
|
|
|
SET_TERMIOS(0, tio); /* ...and make it stick -- casey */
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode((tio->c_cc[VERASE] == '\b'), PrivMode_BackSpace);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* HAVE_TERMIOS_H */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* sgtty interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get parameters -- gtty */
|
|
|
|
if (ioctl(0, TIOCGETP, &(tio->sg)) < 0) {
|
2002-06-08 08:44:08 -07:00
|
|
|
tio->sg.sg_erase = CERASE; /* ^H */
|
|
|
|
tio->sg.sg_kill = CKILL; /* ^U */
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
tio->sg.sg_flags = (CRMOD | ECHO | EVENP | ODDP);
|
|
|
|
|
|
|
|
/* get special characters */
|
|
|
|
if (ioctl(0, TIOCGETC, &(tio->tc)) < 0) {
|
2002-06-08 08:44:08 -07:00
|
|
|
tio->tc.t_intrc = CINTR; /* ^C */
|
|
|
|
tio->tc.t_quitc = CQUIT; /* ^\ */
|
|
|
|
tio->tc.t_startc = CSTART; /* ^Q */
|
|
|
|
tio->tc.t_stopc = CSTOP; /* ^S */
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->tc.t_eofc = CEOF; /* ^D */
|
|
|
|
tio->tc.t_brkc = -1;
|
|
|
|
}
|
|
|
|
/* get local special chars */
|
|
|
|
if (ioctl(0, TIOCGLTC, &(tio->lc)) < 0) {
|
2002-06-08 08:44:08 -07:00
|
|
|
tio->lc.t_suspc = CSUSP; /* ^Z */
|
|
|
|
tio->lc.t_dsuspc = CDSUSP; /* ^Y */
|
|
|
|
tio->lc.t_rprntc = CRPRNT; /* ^R */
|
|
|
|
tio->lc.t_flushc = CFLUSH; /* ^O */
|
|
|
|
tio->lc.t_werasc = CWERASE; /* ^W */
|
|
|
|
tio->lc.t_lnextc = CLNEXT; /* ^V */
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
/* get line discipline */
|
|
|
|
ioctl(0, TIOCGETD, &(tio->line));
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifdef NTTYDISC
|
2002-05-04 07:25:30 -07:00
|
|
|
tio->line = NTTYDISC;
|
|
|
|
# endif /* NTTYDISC */
|
|
|
|
tio->local = (LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
# ifdef FORCE_BACKSPACE
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode(1, PrivMode_BackSpace);
|
|
|
|
tio->sg.sg_erase = '\b';
|
|
|
|
SET_TTYMODE(0, tio);
|
1999-08-17 16:01:18 -07:00
|
|
|
# elif defined (FORCE_DELETE)
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode(0, PrivMode_BackSpace);
|
|
|
|
tio->sg.sg_erase = 0x7f;
|
|
|
|
SET_TTYMODE(0, tio);
|
1999-08-17 16:01:18 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
PrivMode((tio->sg.sg_erase == '\b'), PrivMode_BackSpace);
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif /* HAVE_TERMIOS_H */
|
|
|
|
}
|
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* Xlocale */
|
|
|
|
XFontSet
|
|
|
|
create_fontset(const char *font1, const char *font2)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
XFontSet fontset = 0;
|
|
|
|
char *fontname, **ml, *ds;
|
|
|
|
int mc;
|
|
|
|
const char fs_base[] = ",-misc-fixed-*-r-*-*-*-120-*-*-*-*-*-*,*";
|
|
|
|
|
2002-10-04 18:19:41 -07:00
|
|
|
ASSERT_RVAL(font1 != NULL, (XFontSet) 0);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
if (font2) {
|
|
|
|
fontname = MALLOC(strlen(font1) + strlen(font2) + sizeof(fs_base) + 2);
|
|
|
|
if (fontname) {
|
|
|
|
strcpy(fontname, font1);
|
|
|
|
strcat(fontname, ",");
|
|
|
|
strcat(fontname, font2);
|
|
|
|
strcat(fontname, fs_base);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fontname = MALLOC(strlen(font1) + sizeof(fs_base) + 1);
|
|
|
|
if (fontname) {
|
|
|
|
strcpy(fontname, font1);
|
|
|
|
strcat(fontname, fs_base);
|
|
|
|
}
|
Fri Nov 19 23:05:31 PST 1999 Michael Jennings <mej@eterm.org>
Once again, I've rendered old themes obselete. :-)
I added a new config file attribute and command-line parameter. The
option is --default-font-index, but I wouldn't necessarily use it.
The config file attribute makes more sense. :-)
Anyway, your themes will now need to have a line like this:
font default <index>
in the attributes section. This tells Eterm which font it should use
on startup. (<index> is a number between 0 and the highest-numbered
font you define.) You can now have up to 256 fonts. Font 0 is no
longer necessarily the default font; it is the smallest font. And the
larger the font index, the larger the font should be. (Of course,
this assumes you want Ctrl-> and Ctrl-< to increase/decrease your font
size. In reality, you can have your fonts in any order, and those
keys will cycle through them in order.)
Before, font 0 was always the default, and you didn't have much
freedom in rearranging your fonts. Plus, you were limited to 5. Not
any more. :-) The new system is much more straight-forward, logical,
and powerful.
So please be sure to update your themes by hand, or remove your theme
directory before installing this new version. If your theme lacks
the "font default" line, your Eterms will start with the wrong font.
:-]
SVN revision: 1344
1999-11-19 21:17:29 -08:00
|
|
|
}
|
|
|
|
if (fontname) {
|
2002-05-04 07:25:30 -07:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
fontset = XCreateFontSet(Xdisplay, fontname, &ml, &mc, &ds);
|
|
|
|
FREE(fontname);
|
|
|
|
if (mc) {
|
|
|
|
XFreeStringList(ml);
|
|
|
|
fontset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fontset;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(USE_XIM) || defined(MULTI_CHARSET)
|
|
|
|
|
|
|
|
#ifdef USE_XIM
|
|
|
|
static int xim_real_init(void);
|
2002-06-02 17:24:22 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
# ifdef USE_X11R6_XIM
|
1999-08-18 15:00:59 -07:00
|
|
|
static void xim_destroy_cb(XIM xim, XPointer client_data, XPointer call_data);
|
2002-05-04 07:25:30 -07:00
|
|
|
static void xim_instantiate_cb(Display * display, XPointer client_data, XPointer call_data);
|
1999-08-17 18:12:47 -07:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
void
|
|
|
|
init_locale(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
char *locale = NULL;
|
|
|
|
|
|
|
|
locale = setlocale(LC_ALL, "");
|
2001-12-29 12:47:49 -08:00
|
|
|
XSetLocaleModifiers("");
|
2002-05-04 07:25:30 -07:00
|
|
|
TermWin.fontset = (XFontSet) 0;
|
|
|
|
if ((locale == NULL) || (!XSupportsLocale())) {
|
|
|
|
print_warning("Locale not supported; defaulting to portable \"C\" locale.\n");
|
|
|
|
locale = setlocale(LC_ALL, "C");
|
|
|
|
XSetLocaleModifiers("");
|
|
|
|
REQUIRE(locale);
|
|
|
|
REQUIRE(XSupportsLocale());
|
|
|
|
} else {
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef USE_XIM
|
2000-11-24 18:55:40 -08:00
|
|
|
#ifdef MULTI_CHARSET
|
2002-05-04 07:25:30 -07:00
|
|
|
TermWin.fontset = create_fontset(etfonts[def_font_idx], etmfonts[def_font_idx]);
|
2000-11-24 18:55:40 -08:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
TermWin.fontset = create_fontset(etfonts[def_font_idx], "-misc-fixed-medium-r-semicondensed--13-*-75-*-c-*-iso10646-1");
|
2000-11-24 18:55:40 -08:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((TermWin.fontset == (XFontSet) 0) || (xim_real_init() != -1)) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
# ifdef USE_X11R6_XIM
|
2002-05-04 07:25:30 -07:00
|
|
|
XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL);
|
1999-08-17 18:12:47 -07:00
|
|
|
# endif
|
2000-11-16 15:45:01 -08:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
#endif /* USE_XIM || MULTI_CHARSET */
|
1999-08-17 18:12:47 -07:00
|
|
|
|
|
|
|
#ifdef USE_XIM
|
|
|
|
static void
|
|
|
|
xim_set_size(XRectangle * size)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
size->x = TermWin.internalBorder;
|
|
|
|
size->y = TermWin.internalBorder + bbar_calc_docked_height(BBAR_DOCKED_TOP);
|
2002-10-07 19:18:09 -07:00
|
|
|
size->width = Width2Pixel(TERM_WINDOW_GET_COLS());
|
|
|
|
size->height = Height2Pixel(TERM_WINDOW_GET_ROWS());
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xim_set_color(unsigned long *fg, unsigned long *bg)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
*fg = PixColors[fgColor];
|
|
|
|
*bg = PixColors[bgColor];
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xim_send_spot(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
XPoint spot;
|
|
|
|
static XPoint oldSpot = { -1, -1 };
|
|
|
|
XVaNestedList preedit_attr;
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (xim_input_context == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xim_input_style & XIMPreeditPosition) {
|
|
|
|
xim_get_position(&spot);
|
|
|
|
if (spot.x != oldSpot.x || spot.y != oldSpot.y) {
|
|
|
|
oldSpot.x = spot.x;
|
|
|
|
oldSpot.y = spot.y;
|
|
|
|
preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL);
|
|
|
|
XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL);
|
|
|
|
XFree(preedit_attr);
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-05-04 07:25:30 -07:00
|
|
|
xim_get_area(XRectangle * preedit_rect, XRectangle * status_rect, XRectangle * needed_rect)
|
1999-08-17 18:12:47 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
preedit_rect->x = needed_rect->width + (scrollbar_is_visible() && !(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0);
|
2002-10-07 19:18:09 -07:00
|
|
|
preedit_rect->y = Height2Pixel(TERM_WINDOW_GET_ROWS() - 1);
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
preedit_rect->width = Width2Pixel(TERM_WINDOW_GET_COLS() + 1) - needed_rect->width + (!(Options & Opt_scrollbar_right) ? (scrollbar_trough_width()) : 0);
|
2002-05-04 07:25:30 -07:00
|
|
|
preedit_rect->height = Height2Pixel(1);
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
status_rect->x = (scrollbar_is_visible() && !(Options & Opt_scrollbar_right)) ? (scrollbar_trough_width()) : 0;
|
2002-10-07 19:18:09 -07:00
|
|
|
status_rect->y = Height2Pixel(TERM_WINDOW_GET_ROWS() - 1);
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(TERM_WINDOW_GET_COLS() + 1);
|
2002-05-04 07:25:30 -07:00
|
|
|
status_rect->height = Height2Pixel(1);
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_X11R6_XIM
|
|
|
|
static void
|
|
|
|
xim_destroy_cb(XIM xim, XPointer client_data, XPointer call_data)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
xim_input_context = NULL;
|
|
|
|
xim_input_method = NULL;
|
|
|
|
XRegisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL);
|
|
|
|
xim = NULL;
|
|
|
|
client_data = call_data = (XPointer) 0;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-05-04 07:25:30 -07:00
|
|
|
xim_instantiate_cb(Display * display, XPointer client_data, XPointer call_data)
|
1999-08-17 18:12:47 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
xim_real_init();
|
|
|
|
if (xim_input_context) {
|
|
|
|
XUnregisterIMInstantiateCallback(Xdisplay, NULL, NULL, NULL, xim_instantiate_cb, NULL);
|
|
|
|
}
|
|
|
|
display = NULL;
|
|
|
|
client_data = call_data = (XPointer) 0;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
|
|
|
xim_real_init(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
char *p, *s, buf[64], tmp[1024];
|
|
|
|
char *end, *next_s;
|
|
|
|
XIMStyles *xim_styles = NULL;
|
|
|
|
int found;
|
|
|
|
XPoint spot;
|
|
|
|
XRectangle rect, status_rect, needed_rect;
|
|
|
|
unsigned long fg, bg;
|
|
|
|
XVaNestedList preedit_attr = NULL;
|
|
|
|
XVaNestedList status_attr = NULL;
|
|
|
|
|
|
|
|
REQUIRE_RVAL(xim_input_context == NULL, -1);
|
|
|
|
|
|
|
|
xim_input_style = 0;
|
|
|
|
|
|
|
|
if (rs_input_method && *rs_input_method) {
|
|
|
|
strncpy(tmp, rs_input_method, sizeof(tmp) - 1);
|
|
|
|
for (s = tmp; *s; s = next_s + 1) {
|
|
|
|
for (; *s && isspace(*s); s++);
|
|
|
|
if (!*s) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (end = s; (*end && (*end != ',')); end++);
|
|
|
|
for (next_s = end--; ((end >= s) && isspace(*end)); end--);
|
|
|
|
*(end + 1) = '\0';
|
|
|
|
if (*s) {
|
|
|
|
snprintf(buf, sizeof(buf), "@im=%s", s);
|
|
|
|
if (((p = XSetLocaleModifiers(buf)) != NULL) && (*p) && ((xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL)) != NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!*next_s) {
|
|
|
|
break;
|
|
|
|
}
|
1999-08-18 15:00:59 -07:00
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* try with XMODIFIERS env. var. */
|
|
|
|
if (xim_input_method == NULL && getenv("XMODIFIERS") && (p = XSetLocaleModifiers("")) != NULL && *p) {
|
|
|
|
xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL);
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* try with no modifiers base */
|
|
|
|
if (xim_input_method == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p) {
|
|
|
|
xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL);
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (xim_input_method == NULL) {
|
|
|
|
xim_input_method = XOpenIM(Xdisplay, NULL, NULL, NULL);
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (xim_input_method == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef USE_X11R6_XIM
|
2002-05-04 07:25:30 -07:00
|
|
|
{
|
|
|
|
XIMCallback destroy_cb;
|
|
|
|
|
|
|
|
destroy_cb.callback = xim_destroy_cb;
|
|
|
|
destroy_cb.client_data = NULL;
|
|
|
|
if (XSetIMValues(xim_input_method, XNDestroyCallback, &destroy_cb, NULL)) {
|
|
|
|
print_error("Could not set destroy callback to IM\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((XGetIMValues(xim_input_method, XNQueryInputStyle, &xim_styles, NULL)) || (!xim_styles)) {
|
|
|
|
print_error("input method doesn't support any style\n");
|
|
|
|
XCloseIM(xim_input_method);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strncpy(tmp, (rs_preedit_type ? rs_preedit_type : "OverTheSpot,OffTheSpot,Root"), sizeof(tmp) - 1);
|
|
|
|
for (found = 0, s = tmp; *s && !found; s = next_s + 1) {
|
|
|
|
unsigned short i;
|
|
|
|
|
|
|
|
for (; *s && isspace(*s); s++);
|
|
|
|
if (!*s) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (end = s; (*end && (*end != ',')); end++);
|
|
|
|
for (next_s = end--; ((end >= s) && isspace(*end)); end--);
|
|
|
|
*(end + 1) = '\0';
|
|
|
|
|
|
|
|
if (!strcmp(s, "OverTheSpot")) {
|
|
|
|
xim_input_style = (XIMPreeditPosition | XIMStatusNothing);
|
|
|
|
} else if (!strcmp(s, "OffTheSpot")) {
|
|
|
|
xim_input_style = (XIMPreeditArea | XIMStatusArea);
|
|
|
|
} else if (!strcmp(s, "Root")) {
|
|
|
|
xim_input_style = (XIMPreeditNothing | XIMStatusNothing);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < xim_styles->count_styles; i++) {
|
|
|
|
if (xim_input_style == xim_styles->supported_styles[i]) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(xim_styles);
|
|
|
|
|
|
|
|
if (found == 0) {
|
|
|
|
print_error("input method doesn't support my preedit type\n");
|
|
|
|
XCloseIM(xim_input_method);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((xim_input_style != (XIMPreeditNothing | XIMStatusNothing))
|
|
|
|
&& (xim_input_style != (XIMPreeditArea | XIMStatusArea))
|
|
|
|
&& (xim_input_style != (XIMPreeditPosition | XIMStatusNothing))) {
|
|
|
|
print_error("This program does not support the preedit type\n");
|
|
|
|
XCloseIM(xim_input_method);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (xim_input_style & XIMPreeditPosition) {
|
|
|
|
xim_set_size(&rect);
|
|
|
|
xim_get_position(&spot);
|
|
|
|
xim_set_color(&fg, &bg);
|
2002-06-02 17:24:22 -07:00
|
|
|
preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL);
|
2002-05-04 07:25:30 -07:00
|
|
|
} else if (xim_input_style & XIMPreeditArea) {
|
|
|
|
xim_set_color(&fg, &bg);
|
|
|
|
/* The necessary width of preedit area is unknown until create input context. */
|
|
|
|
needed_rect.width = 0;
|
|
|
|
xim_get_area(&rect, &status_rect, &needed_rect);
|
|
|
|
preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL);
|
|
|
|
status_attr = XVaCreateNestedList(0, XNArea, &status_rect, XNForeground, fg, XNBackground, bg, XNFontSet, TermWin.fontset, NULL);
|
|
|
|
}
|
|
|
|
xim_input_context =
|
|
|
|
XCreateIC(xim_input_method, XNInputStyle, xim_input_style, XNClientWindow, TermWin.parent, XNFocusWindow, TermWin.parent,
|
|
|
|
preedit_attr ? XNPreeditAttributes : NULL, preedit_attr, status_attr ? XNStatusAttributes : NULL, status_attr, NULL);
|
|
|
|
if (preedit_attr) {
|
|
|
|
XFree(preedit_attr);
|
|
|
|
}
|
|
|
|
if (status_attr) {
|
|
|
|
XFree(status_attr);
|
|
|
|
}
|
|
|
|
if (xim_input_context == NULL) {
|
|
|
|
print_error("Failed to create input context\n");
|
|
|
|
XCloseIM(xim_input_method);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (xim_input_style & XIMPreeditArea)
|
|
|
|
xim_set_status_position();
|
|
|
|
return 0;
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xim_set_status_position(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
XRectangle preedit_rect, status_rect, *needed_rect, rect;
|
|
|
|
XVaNestedList preedit_attr, status_attr;
|
|
|
|
XPoint spot;
|
|
|
|
|
|
|
|
REQUIRE(xim_input_context != NULL);
|
|
|
|
|
|
|
|
if (xim_input_style & XIMPreeditPosition) {
|
|
|
|
xim_set_size(&rect);
|
|
|
|
xim_get_position(&spot);
|
|
|
|
|
|
|
|
preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, NULL);
|
|
|
|
XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL);
|
|
|
|
XFree(preedit_attr);
|
|
|
|
} else if (xim_input_style & XIMPreeditArea) {
|
|
|
|
/* Getting the necessary width of preedit area */
|
|
|
|
status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL);
|
|
|
|
XGetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL);
|
|
|
|
XFree(status_attr);
|
|
|
|
|
|
|
|
xim_get_area(&preedit_rect, &status_rect, needed_rect);
|
|
|
|
|
|
|
|
preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL);
|
|
|
|
status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL);
|
|
|
|
XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL);
|
|
|
|
XFree(preedit_attr);
|
|
|
|
XFree(status_attr);
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
void
|
|
|
|
xim_set_fontset(void)
|
1999-08-17 18:12:47 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
XVaNestedList preedit_attr = NULL;
|
|
|
|
XVaNestedList status_attr = NULL;
|
|
|
|
|
|
|
|
REQUIRE(xim_input_context != NULL);
|
|
|
|
|
|
|
|
if (xim_input_style & XIMStatusArea) {
|
|
|
|
status_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL);
|
|
|
|
}
|
|
|
|
if (xim_input_style & (XIMPreeditArea | XIMPreeditPosition)) {
|
|
|
|
preedit_attr = XVaCreateNestedList(0, XNFontSet, TermWin.fontset, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status_attr && preedit_attr) {
|
|
|
|
XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL);
|
|
|
|
} else if (preedit_attr) {
|
|
|
|
XSetICValues(xim_input_context, XNPreeditAttributes, preedit_attr, NULL);
|
|
|
|
} else if (status_attr) {
|
|
|
|
XSetICValues(xim_input_context, XNStatusAttributes, status_attr, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preedit_attr) {
|
|
|
|
XFree(preedit_attr);
|
|
|
|
}
|
|
|
|
if (status_attr) {
|
|
|
|
XFree(status_attr);
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
|
|
|
#endif /* USE_XIM */
|
|
|
|
|
1999-08-17 16:01:18 -07:00
|
|
|
/* run_command() */
|
|
|
|
/*
|
|
|
|
* Run the command in a subprocess and return a file descriptor for the
|
|
|
|
* master end of the pseudo-teletype pair with the command talking to
|
|
|
|
* the slave.
|
|
|
|
*/
|
|
|
|
int
|
2000-11-16 15:45:01 -08:00
|
|
|
run_command(char **argv)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
ttymode_t tio;
|
|
|
|
int ptyfd;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Save and then give up any super-user privileges */
|
|
|
|
privileges(IGNORE);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
ptyfd = get_pty();
|
|
|
|
if (ptyfd < 0)
|
|
|
|
return (-1);
|
|
|
|
AT_LEAST(num_fds, ((unsigned int) (ptyfd + 1)));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* store original tty status for restoration clean_exit() -- rgg 04/12/95 */
|
|
|
|
lstat(ttydev, &ttyfd_stat);
|
|
|
|
D_CMD(("Original settings of %s are mode %o, uid %d, gid %d\n", ttydev, ttyfd_stat.st_mode, ttyfd_stat.st_uid, ttyfd_stat.st_gid));
|
|
|
|
|
|
|
|
/* install exit handler for cleanup */
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef HAVE_ATEXIT
|
2002-05-04 07:25:30 -07:00
|
|
|
atexit(clean_exit);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
|
|
|
# if defined (__sun__)
|
2002-05-04 07:25:30 -07:00
|
|
|
on_exit(clean_exit, NULL); /* non-ANSI exit handler */
|
1999-08-17 16:01:18 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
print_error("no atexit(), UTMP entries can't be cleaned\n");
|
1999-08-17 16:01:18 -07:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/*
|
|
|
|
* get tty settings before fork()
|
|
|
|
* and make a reasonable guess at the value for BackSpace
|
|
|
|
*/
|
|
|
|
get_ttymode(&tio);
|
|
|
|
/* add Backspace value */
|
|
|
|
SavedModes |= (PrivateModes & PrivMode_BackSpace);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* add value for scrollbar */
|
|
|
|
if (scrollbar_is_visible()) {
|
|
|
|
PrivateModes |= PrivMode_scrollbar;
|
|
|
|
SavedModes |= PrivMode_scrollbar;
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#if DEBUG >= DEBUG_TTYMODE && defined(HAVE_TERMIOS_H)
|
2002-05-04 07:25:30 -07:00
|
|
|
if (DEBUG_LEVEL >= DEBUG_TTYMODE) {
|
|
|
|
debug_ttymode(&tio);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("Forking\n"));
|
|
|
|
cmd_pid = fork();
|
|
|
|
D_CMD(("After fork(), cmd_pid == %d\n", cmd_pid));
|
|
|
|
if (cmd_pid < 0) {
|
|
|
|
print_error("fork(): %s\n", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (cmd_pid == 0) {
|
|
|
|
|
|
|
|
/* Child process. Reset the signal handlers right away. */
|
|
|
|
signal(SIGINT, SIG_DFL);
|
|
|
|
signal(SIGQUIT, SIG_DFL);
|
|
|
|
signal(SIGCHLD, SIG_DFL);
|
|
|
|
signal(SIGSEGV, SIG_DFL);
|
|
|
|
signal(SIGBUS, SIG_DFL);
|
|
|
|
signal(SIGABRT, SIG_DFL);
|
|
|
|
signal(SIGFPE, SIG_DFL);
|
|
|
|
signal(SIGILL, SIG_DFL);
|
|
|
|
signal(SIGSYS, SIG_DFL);
|
|
|
|
signal(SIGALRM, SIG_DFL);
|
1999-12-30 04:44:45 -08:00
|
|
|
#ifdef SIGTSTP
|
2002-05-04 07:25:30 -07:00
|
|
|
signal(SIGTSTP, SIG_IGN);
|
|
|
|
signal(SIGTTIN, SIG_IGN);
|
|
|
|
signal(SIGTTOU, SIG_IGN);
|
1999-12-30 04:44:45 -08:00
|
|
|
#endif
|
1999-08-17 16:01:18 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_UNSETENV
|
2002-05-04 07:25:30 -07:00
|
|
|
unsetenv("LINES");
|
|
|
|
unsetenv("COLUMNS");
|
|
|
|
unsetenv("TERMCAP");
|
1999-12-30 04:44:45 -08:00
|
|
|
#endif
|
2002-10-07 19:18:09 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
DEBUG_LEVEL = 0;
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
get_tty();
|
|
|
|
SET_TTYMODE(0, &tio);
|
2002-10-07 19:18:09 -07:00
|
|
|
tt_winsize(0);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* become virtual console, fail silently */
|
|
|
|
if (Options & Opt_console) {
|
|
|
|
int fd = 1;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(INVOKE);
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef SRIOCSREDIR
|
2002-05-04 07:25:30 -07:00
|
|
|
fd = open(CONSOLE, O_WRONLY);
|
|
|
|
if (fd < 0 || ioctl(fd, SRIOCSREDIR, 0) < 0) {
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#elif defined(TIOCCONS)
|
2002-05-04 07:25:30 -07:00
|
|
|
ioctl(0, TIOCCONS, &fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* SRIOCSREDIR */
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(REVERT);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Permanently revoke all privileges for the child process.
|
|
|
|
Root shells for everyone are tres uncool.... ;^) -- mej */
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef _HPUX_SOURCE
|
2002-05-04 07:25:30 -07:00
|
|
|
setresuid(my_ruid, my_ruid, my_euid);
|
|
|
|
setresgid(my_rgid, my_rgid, my_egid);
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
/* No special treatment is needed for systems with saved uids/gids,
|
|
|
|
because the exec*() calls reset the saved uid/gid to the
|
|
|
|
effective uid/gid -- mej */
|
1999-08-17 16:01:18 -07:00
|
|
|
# ifndef __CYGWIN32__
|
2002-05-04 07:25:30 -07:00
|
|
|
setregid(my_rgid, my_rgid);
|
|
|
|
setreuid(my_ruid, my_ruid);
|
|
|
|
# endif /* __CYGWIN32__ */
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* _HPUX_SOURCE */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_UTMP(("Child process reset\n"));
|
|
|
|
my_euid = my_ruid;
|
|
|
|
my_egid = my_rgid;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
#ifdef HAVE_USLEEP
|
2002-05-04 07:25:30 -07:00
|
|
|
usleep(10); /* Attempt to force a context switch so that the parent runs before us. */
|
2002-05-13 15:47:08 -07:00
|
|
|
#else
|
|
|
|
sleep(1); /* ugliness */
|
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("[%d] About to spawn shell\n", getpid()));
|
|
|
|
if (chdir(initial_dir)) {
|
|
|
|
print_warning("Unable to chdir to \"%s\" -- %s\n", initial_dir, strerror(errno));
|
|
|
|
}
|
|
|
|
if (argv != NULL) {
|
1999-08-17 16:01:18 -07:00
|
|
|
#if DEBUG >= DEBUG_CMD
|
2002-05-04 07:25:30 -07:00
|
|
|
if (DEBUG_LEVEL >= DEBUG_CMD) {
|
|
|
|
int i;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
for (i = 0; argv[i]; i++) {
|
|
|
|
DPRINTF(("argv[%d] = \"%s\"\n", i, argv[i]));
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("[%d] execvp(\"%s\", %8p) is next. I'm outta here!\n", getpid(), NONULL(argv[0]), argv));
|
|
|
|
execvp(argv[0], argv);
|
|
|
|
print_error("execvp() failed, cannot execute \"%s\": %s\n", argv[0], strerror(errno));
|
|
|
|
} else {
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
const char *argv0, *shell;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((shell = getenv("SHELL")) == NULL || *shell == '\0')
|
|
|
|
shell = "/bin/sh";
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
argv0 = my_basename(shell);
|
|
|
|
if (Options & Opt_login_shell) {
|
|
|
|
char *p = MALLOC(strlen(argv0) + 2);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
p[0] = '-';
|
|
|
|
strcpy(&p[1], argv0);
|
|
|
|
argv0 = p;
|
|
|
|
}
|
|
|
|
execlp(shell, argv0, NULL);
|
|
|
|
print_error("execlp() failed, cannot execute \"%s\": %s\n", shell, strerror(errno));
|
|
|
|
}
|
|
|
|
sleep(3); /* Sleep to make sure fork() returns in the parent, and so user can read error message */
|
|
|
|
exit(EXIT_FAILURE);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#ifdef UTMP_SUPPORT
|
2002-05-04 07:25:30 -07:00
|
|
|
privileges(RESTORE);
|
|
|
|
if (Options & Opt_write_utmp) {
|
|
|
|
add_utmp_entry(ttydev, display_name, ptyfd);
|
|
|
|
}
|
|
|
|
privileges(IGNORE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
D_CMD(("Returning ptyfd == %d\n", ptyfd));
|
|
|
|
return (ptyfd);
|
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
|
|
|
|
#ifdef ESCREEN
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/***************************************************************************/
|
2002-05-23 11:14:41 -07:00
|
|
|
/* Escreen: callbacks */
|
|
|
|
/***********************/
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
set_scroll_x(void *xd, int x)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("%d\n", x));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
set_scroll_y(void *xd, int y)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("%d\n", y));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
set_scroll_w(void *xd, int w)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("%d\n", w));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
set_scroll_h(void *xd, int h)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("%d\n", h));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
redraw(void *xd)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("redraw\n"));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
redraw_xywh(void *xd, int x, int y, int w, int h)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
D_ESCREEN(("%d,%d %dx%d\n", x, y, w, h));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
static button_t *screen_button_create(char *text, char code)
|
2002-05-13 16:19:30 -07:00
|
|
|
{
|
|
|
|
button_t *b;
|
|
|
|
char p[3];
|
2002-05-13 15:47:08 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
REQUIRE_RVAL(text, NULL);
|
|
|
|
REQUIRE_RVAL(*text, NULL);
|
|
|
|
b = button_create(text);
|
|
|
|
REQUIRE_RVAL(b, NULL);
|
2002-05-13 15:47:08 -07:00
|
|
|
|
2002-05-13 16:19:30 -07:00
|
|
|
p[0] = NS_SCREEN_ESCAPE;
|
|
|
|
p[1] = code;
|
|
|
|
p[2] = '\0';
|
2002-06-13 22:41:23 -07:00
|
|
|
D_ESCREEN(("Creating button \"%s\" for display %c (%s)\n", NONULL(text), code, safe_print_string(p, 2)));
|
2002-05-13 16:19:30 -07:00
|
|
|
button_set_action(b, ACTION_ECHO, p);
|
2002-06-08 09:50:38 -07:00
|
|
|
b->flags |= NS_SCREAM_BUTTON;
|
2002-05-13 15:47:08 -07:00
|
|
|
|
2002-05-13 16:19:30 -07:00
|
|
|
return b;
|
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
/* add a new screen display to button bar.
|
|
|
|
if our user's configured a bbar, we'll add to that,
|
2002-06-02 17:24:22 -07:00
|
|
|
otherwise, we'll create one.
|
|
|
|
xd address of the pointer to the buttonbar in question
|
|
|
|
after insert after which display?
|
|
|
|
name the display's name */
|
|
|
|
static int
|
|
|
|
ins_disp(void *xd, int after, int as, char *name)
|
2002-05-04 07:25:30 -07:00
|
|
|
{
|
2002-06-08 09:50:38 -07:00
|
|
|
buttonbar_t *bbar = (buttonbar_t *) xd;
|
2002-05-04 07:25:30 -07:00
|
|
|
button_t *button;
|
2002-05-13 15:47:08 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
USE_VAR(after);
|
2002-05-23 11:14:41 -07:00
|
|
|
REQUIRE_RVAL(xd, NS_FAIL);
|
|
|
|
REQUIRE_RVAL(name, NS_FAIL);
|
|
|
|
REQUIRE_RVAL(*name, NS_FAIL);
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
if (!(button = screen_button_create(name, '0' + as))) {
|
2002-05-13 16:19:30 -07:00
|
|
|
return NS_FAIL;
|
2002-05-23 11:14:41 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_add_button(bbar, button);
|
|
|
|
return NS_SUCC;
|
2002-05-13 15:47:08 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
#if 0
|
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
/* add supa-dupa right buttons for screen-features.
|
|
|
|
if our user's configured a bbar, we'll add to that,
|
|
|
|
otherwise, we'll create one. */
|
2002-05-23 11:14:41 -07:00
|
|
|
static int
|
2002-06-08 09:50:38 -07:00
|
|
|
add_screen_ctl_button(buttonbar_t *bbar, char *name, char key)
|
2002-05-13 15:47:08 -07:00
|
|
|
{
|
|
|
|
button_t *button;
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
REQUIRE_RVAL(bbar, NS_FAIL);
|
2002-05-23 11:14:41 -07:00
|
|
|
REQUIRE_RVAL(name, NS_FAIL);
|
|
|
|
REQUIRE_RVAL(*name, NS_FAIL);
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
if (!(button = screen_button_create(name, key)))
|
2002-05-13 16:19:30 -07:00
|
|
|
return NS_FAIL;
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_add_button(bbar, button);
|
|
|
|
return NS_SUCC;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
2002-06-02 17:24:22 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
/* delete n'th button
|
2002-06-02 17:24:22 -07:00
|
|
|
xd address of the pointer to the buttonbar in question
|
|
|
|
n index of the button (not screen, not data -- the button) */
|
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
del_disp(void *xd, int n)
|
|
|
|
{
|
2002-06-08 09:50:38 -07:00
|
|
|
buttonbar_t *bbar = (buttonbar_t *) xd;
|
2002-05-04 07:25:30 -07:00
|
|
|
button_t *button, *b2;
|
|
|
|
int bi = n;
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
REQUIRE_RVAL(bbar, NS_FAIL);
|
|
|
|
REQUIRE_RVAL(bbar->buttons, NS_FAIL);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
b2 = button = bbar->buttons;
|
2002-05-23 11:14:41 -07:00
|
|
|
if (n == 0) {
|
2002-05-04 07:25:30 -07:00
|
|
|
bbar->buttons = bbar->buttons->next;
|
2002-05-23 11:14:41 -07:00
|
|
|
if (bbar->current == button) {
|
2002-05-04 07:25:30 -07:00
|
|
|
bbar->current = bbar->buttons;
|
2002-05-23 11:14:41 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
} else {
|
2002-05-23 11:14:41 -07:00
|
|
|
for (; n > 0; n--) {
|
2002-05-04 07:25:30 -07:00
|
|
|
b2 = button;
|
|
|
|
if (!(button = button->next)) {
|
2002-05-23 11:14:41 -07:00
|
|
|
D_ESCREEN(("cannot delete button %d: does not exist...\n", bi));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_FAIL;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
b2->next = button->next;
|
2002-05-23 11:14:41 -07:00
|
|
|
if (bbar->current == button) {
|
2002-05-04 07:25:30 -07:00
|
|
|
bbar->current = b2;
|
2002-05-23 11:14:41 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
button->next = NULL;
|
|
|
|
button_free(button);
|
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
bbar_redraw(bbar);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_SUCC;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update the button-representation of a screen-display.
|
2002-06-02 17:24:22 -07:00
|
|
|
xd address of the pointer to the buttonbar in question
|
2002-05-04 07:25:30 -07:00
|
|
|
n the button's index (in the list of buttons)
|
|
|
|
flags the new flags for the display (or -1 to ignore)
|
|
|
|
name the new name for the display (or NULL)
|
|
|
|
<- error code */
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
upd_disp(void *xd, int n, int flags, char *name)
|
|
|
|
{
|
2002-06-08 09:50:38 -07:00
|
|
|
buttonbar_t *bbar = (buttonbar_t *) xd;
|
2002-05-04 07:25:30 -07:00
|
|
|
button_t *button;
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
REQUIRE_RVAL(bbar, NS_FAIL);
|
|
|
|
REQUIRE_RVAL(bbar->buttons, NS_FAIL);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
button = bbar->buttons;
|
2002-05-23 11:14:41 -07:00
|
|
|
for (; (n > 0) && (button->next); n--, button = button->next);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-18 13:27:41 -07:00
|
|
|
/* See if we actually need to update anything. If not, don't. */
|
|
|
|
if ((name && button->text && !strcmp(name, button->text))
|
|
|
|
&& ((flags | NS_SCREAM_BUTTON) == button->flags)) {
|
|
|
|
return NS_SUCC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update display name */
|
2002-05-04 07:25:30 -07:00
|
|
|
if (name && (!button->text || strcmp(name, button->text))) {
|
2002-05-23 11:14:41 -07:00
|
|
|
button_set_text(button, name);
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-18 13:27:41 -07:00
|
|
|
/* Update flags */
|
2002-05-23 11:14:41 -07:00
|
|
|
if (flags >= 0) {
|
2002-06-08 09:50:38 -07:00
|
|
|
button->flags = (flags | NS_SCREAM_BUTTON);
|
2002-06-26 14:02:12 -07:00
|
|
|
D_ESCREEN(("upd_disp: new flags for \"%s\": %d\n", button->text, flags));
|
2002-05-23 11:14:41 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-18 13:27:41 -07:00
|
|
|
/* Redraw buttonbar to reflect new information */
|
2002-05-13 15:47:08 -07:00
|
|
|
bbar_redraw(bbar);
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_SUCC;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
/* expire all buttons
|
|
|
|
xd address of the pointer to the buttonbar in question
|
|
|
|
n how many buttons do we want to throw out (normally all of them)?
|
|
|
|
<- error code */
|
|
|
|
static int
|
|
|
|
expire_buttons(void *xd, int n)
|
|
|
|
{
|
2002-06-08 09:50:38 -07:00
|
|
|
buttonbar_t *bbar = (buttonbar_t *) xd;
|
2002-06-02 17:24:22 -07:00
|
|
|
button_t *b, *p;
|
|
|
|
|
|
|
|
REQUIRE_RVAL(bbar, NS_FAIL);
|
|
|
|
if (n < 1) {
|
|
|
|
return NS_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((b = bbar->buttons)) {
|
|
|
|
for (; n; n--) {
|
|
|
|
p = b;
|
|
|
|
b = b->next;
|
|
|
|
}
|
|
|
|
p->next = NULL;
|
|
|
|
button_free(bbar->buttons);
|
|
|
|
bbar->buttons = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_SUCC;
|
|
|
|
}
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* display a status line the screen program sent us */
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
err_msg(void *xd, int err, char *msg)
|
2002-05-23 11:14:41 -07:00
|
|
|
{
|
2002-07-11 17:44:42 -07:00
|
|
|
#if DEBUG >= DEBUG_ESCREEN
|
|
|
|
if (DEBUG_LEVEL >= DEBUG_ESCREEN) {
|
|
|
|
char *sc[] = { "Copy mode", "Bell in", "Wuff, Wuff!!" };
|
|
|
|
int n, nsc = sizeof(sc) / sizeof(char *);
|
|
|
|
|
|
|
|
/* there are certain things that would make sense if we were displaying
|
|
|
|
a status-line; they do not, however, warrant an alert-box, so we drop
|
|
|
|
them here. */
|
|
|
|
if (strlen(msg)) {
|
|
|
|
for (n = 0; n < nsc; n++) {
|
|
|
|
if (!strncmp(msg, sc[n], strlen(sc[n]))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n >= nsc) {
|
|
|
|
menu_dialog(NULL, msg, 0, NULL, NULL);
|
2002-05-22 08:38:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-11 17:44:42 -07:00
|
|
|
#endif
|
|
|
|
USE_VAR(xd);
|
|
|
|
USE_VAR(err);
|
|
|
|
USE_VAR(msg);
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_SUCC;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send text to the application (normally "screen") in the terminal */
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
inp_text(void *xd, int id, char *txt)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
|
|
|
USE_VAR(id);
|
|
|
|
|
2002-06-13 22:41:23 -07:00
|
|
|
D_ESCREEN(("Writing \"%s\" to subprocess.\n", safe_print_string(txt, strlen(txt))));
|
2002-05-04 07:25:30 -07:00
|
|
|
tt_write(txt, strlen(txt));
|
2002-05-13 15:47:08 -07:00
|
|
|
return NS_SUCC;
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
|
2002-05-13 15:47:08 -07:00
|
|
|
/* open a dialog */
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-22 13:55:06 -07:00
|
|
|
input_dialog(void *xd, char *prompt, int maxlen, char **retstr, int (*inp_tab) (void *, char *, size_t, size_t))
|
2002-05-13 15:47:08 -07:00
|
|
|
{
|
2002-05-22 13:55:06 -07:00
|
|
|
switch (menu_dialog(xd, prompt, maxlen, retstr, inp_tab)) {
|
2002-05-13 16:19:30 -07:00
|
|
|
case 0:
|
|
|
|
return NS_SUCC;
|
|
|
|
case -2:
|
|
|
|
return NS_USER_CXL;
|
|
|
|
default:
|
|
|
|
return NS_FAIL;
|
|
|
|
}
|
|
|
|
}
|
2002-05-13 15:47:08 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* run a program (normally "screen") inside the terminal */
|
2002-06-02 17:24:22 -07:00
|
|
|
static int
|
2002-05-04 07:25:30 -07:00
|
|
|
exe_prg(void *xd, char **argv)
|
|
|
|
{
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
2002-05-04 07:25:30 -07:00
|
|
|
return run_command(argv);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
|
|
|
|
/****** Azundris' playthings :-) ******/
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-06-26 14:02:12 -07:00
|
|
|
#ifdef HAVE_HUMOR
|
2002-05-22 08:38:35 -07:00
|
|
|
#define DIRECT_MASK (~(RS_Cursor|RS_Select|RS_fontMask))
|
|
|
|
#define COLOUR_MASK (RS_fgMask|RS_bgMask)
|
|
|
|
#define DIRECT_SET_SCREEN(x,y,fg,bg) (screen.text[ys+y])[x]=fg; (screen.rend[ys+y])[x]=bg&DIRECT_MASK;
|
|
|
|
#define CLEAR (1<<16)
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
static void
|
2002-05-22 08:38:35 -07:00
|
|
|
direct_write_screen(int x, int y, char *fg, rend_t bg)
|
|
|
|
{
|
|
|
|
int ys = TermWin.saveLines - TermWin.view_start;
|
|
|
|
text_t *t = screen.text[ys + y];
|
|
|
|
rend_t *r = screen.rend[ys + y];
|
2002-05-23 11:14:41 -07:00
|
|
|
|
|
|
|
REQUIRE(fg);
|
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
while (*fg && (x >= 0) && (x < TERM_WINDOW_GET_REPORTED_COLS())) {
|
2002-05-22 08:38:35 -07:00
|
|
|
t[x] = *(fg++);
|
|
|
|
r[x++] = bg & DIRECT_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
static void
|
2002-05-22 08:38:35 -07:00
|
|
|
bosconian(int n)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int ys = TermWin.saveLines - TermWin.view_start;
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
for (; n != 0; n--) {
|
2002-10-07 19:18:09 -07:00
|
|
|
for (y = 0; y < TERM_WINDOW_GET_ROWS(); y++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
text_t *t = screen.text[ys + y];
|
|
|
|
rend_t *r = screen.rend[ys + y];
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
for (x = 0; x < TERM_WINDOW_GET_COLS(); x++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
t[x] = random() & 0xff;
|
|
|
|
r[x] = random() & COLOUR_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scr_refresh(FAST_REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
static void
|
2002-05-22 08:38:35 -07:00
|
|
|
unbosconian(void)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
int ys = TermWin.saveLines - TermWin.view_start;
|
|
|
|
rend_t bg;
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-22 08:38:35 -07:00
|
|
|
do {
|
|
|
|
bg = CLEAR;
|
2002-10-07 19:18:09 -07:00
|
|
|
for (y = 0; (bg == CLEAR) && y < TERM_WINDOW_GET_ROWS(); y++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
rend_t *r = screen.rend[ys + y];
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
for (x = 0; (bg == CLEAR) && x < TERM_WINDOW_GET_COLS(); x++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
if (r[x] != CLEAR) {
|
|
|
|
bg = r[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bg != CLEAR) {
|
2002-10-07 19:18:09 -07:00
|
|
|
for (y = 0; y < TERM_WINDOW_GET_ROWS(); y++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
text_t *t = screen.text[ys + y];
|
|
|
|
rend_t *r = screen.rend[ys + y];
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
for (x = 0; x < TERM_WINDOW_GET_COLS(); x++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
if (r[x] == bg) {
|
|
|
|
r[x] = CLEAR;
|
|
|
|
t[x] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scr_refresh(FAST_REFRESH);
|
|
|
|
}
|
|
|
|
} while (bg != CLEAR);
|
|
|
|
}
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
#undef DIRECT_MASK
|
|
|
|
#undef COLOUR_MASK
|
|
|
|
#undef DIRECT_SET_SCREEN
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
static void
|
2002-05-22 08:38:35 -07:00
|
|
|
matrix(int n)
|
|
|
|
{
|
|
|
|
int x, y, w, f;
|
|
|
|
int ys = TermWin.saveLines - TermWin.view_start;
|
2002-10-07 19:18:09 -07:00
|
|
|
text_t *s = MALLOC(TERM_WINDOW_GET_COLS());
|
2002-05-22 08:38:35 -07:00
|
|
|
text_t *t, *t2;
|
|
|
|
rend_t *r, *r2;
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
puts("fail");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
MEMSET(s, 0, TERM_WINDOW_GET_COLS());
|
2002-06-02 17:24:22 -07:00
|
|
|
#define MATRIX_HI CLEAR
|
|
|
|
#define MATRIX_LO ((4<<8)|CLEAR)
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
while (n--) {
|
2002-10-07 19:18:09 -07:00
|
|
|
for (x = 0; x < TERM_WINDOW_GET_COLS(); x++) {
|
2002-05-22 08:38:35 -07:00
|
|
|
if (!(random() & 3)) {
|
|
|
|
if ((y = s[x])) {
|
|
|
|
w = random() & 15;
|
|
|
|
} else {
|
|
|
|
w = 0;
|
|
|
|
}
|
|
|
|
t = screen.text[ys + y];
|
|
|
|
r = screen.rend[ys + y];
|
|
|
|
|
|
|
|
switch (w) {
|
|
|
|
case 0: /* restart */
|
|
|
|
if (s[x]) {
|
|
|
|
r[x] = MATRIX_LO;
|
|
|
|
s[x] = 0;
|
|
|
|
t = screen.text[ys];
|
|
|
|
r = screen.rend[ys];
|
|
|
|
}
|
|
|
|
r[x] = MATRIX_HI;
|
|
|
|
t[x] = random() & 0xff;
|
|
|
|
s[x]++;
|
|
|
|
/* fall-through */
|
|
|
|
|
|
|
|
case 1: /* continue */
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2002-05-23 11:14:41 -07:00
|
|
|
for (f = random() & 7; f != 0; f--) {
|
2002-10-07 19:18:09 -07:00
|
|
|
if (y < TERM_WINDOW_GET_ROWS() - 1) {
|
2002-05-22 08:38:35 -07:00
|
|
|
t2 = screen.text[ys + y + 1];
|
|
|
|
r2 = screen.rend[ys + y + 1];
|
|
|
|
t2[x] = t[x];
|
|
|
|
r2[x] = r[x];
|
|
|
|
s[x]++;
|
|
|
|
y++;
|
|
|
|
} else {
|
|
|
|
s[x] = 0;
|
|
|
|
f = 0;
|
|
|
|
}
|
|
|
|
r[x] = MATRIX_LO;
|
|
|
|
t[x] = random() & 0xff;
|
|
|
|
if (f) {
|
|
|
|
scr_refresh(FAST_REFRESH);
|
|
|
|
t = screen.text[ys + y];
|
|
|
|
r = screen.rend[ys + y];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
default:
|
2002-06-08 08:44:08 -07:00
|
|
|
t[x] = random() & 0xff; /* hold */
|
2002-05-22 08:38:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scr_refresh(FAST_REFRESH);
|
|
|
|
}
|
2002-05-22 13:55:06 -07:00
|
|
|
FREE(s);
|
2002-05-22 08:38:35 -07:00
|
|
|
}
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
#undef MATRIX_HI
|
|
|
|
#undef MATRIX_LO
|
2002-05-22 08:38:35 -07:00
|
|
|
|
|
|
|
/* do whatever for ms milli-seconds */
|
2002-05-23 11:14:41 -07:00
|
|
|
static int
|
2002-05-22 08:38:35 -07:00
|
|
|
waitstate(void *xd, int ms)
|
|
|
|
{
|
|
|
|
int y = 1;
|
2002-05-23 11:14:41 -07:00
|
|
|
time_t dur = (time_t) (ms / 1000);
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
USE_VAR(xd);
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-22 08:38:35 -07:00
|
|
|
if (!(random() & 7)) {
|
|
|
|
if (!(random() & 3)) {
|
|
|
|
matrix(31);
|
|
|
|
unbosconian();
|
|
|
|
}
|
|
|
|
bosconian(4);
|
|
|
|
unbosconian();
|
|
|
|
}
|
|
|
|
|
|
|
|
direct_write_screen(0, y++, " **** COMMODORE 64 BASIC V2 ****", (0 << 8) | CLEAR);
|
|
|
|
direct_write_screen(0, y++, " 64K RAM SYSTEM 38911 BASIC BYTES FREE", (0 << 8) | CLEAR);
|
|
|
|
y += 2;
|
|
|
|
direct_write_screen(0, y++, "READY.", (0 << 8) | CLEAR);
|
|
|
|
screen.row = y;
|
|
|
|
screen.col = 0;
|
|
|
|
|
|
|
|
scr_refresh(FAST_REFRESH);
|
|
|
|
|
|
|
|
sleep(dur);
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-05-22 08:38:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2002-06-26 14:02:12 -07:00
|
|
|
#endif
|
2002-06-02 17:24:22 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
static _ns_efuns *
|
|
|
|
escreen_reg_funcs(void)
|
|
|
|
{
|
|
|
|
_ns_efuns *efuns;
|
|
|
|
|
|
|
|
/* Register functions */
|
|
|
|
efuns = ns_new_efuns();
|
|
|
|
|
|
|
|
ns_register_ssx(efuns, set_scroll_x);
|
|
|
|
ns_register_ssy(efuns, set_scroll_y);
|
|
|
|
ns_register_ssw(efuns, set_scroll_w);
|
|
|
|
ns_register_ssh(efuns, set_scroll_h);
|
|
|
|
|
|
|
|
ns_register_red(efuns, redraw);
|
|
|
|
ns_register_rda(efuns, redraw_xywh);
|
|
|
|
ns_register_exb(efuns, expire_buttons);
|
|
|
|
|
|
|
|
ns_register_ins(efuns, ins_disp);
|
|
|
|
ns_register_del(efuns, del_disp);
|
|
|
|
ns_register_upd(efuns, upd_disp);
|
|
|
|
|
|
|
|
ns_register_err(efuns, err_msg);
|
|
|
|
ns_register_exe(efuns, exe_prg);
|
|
|
|
|
|
|
|
ns_register_txt(efuns, inp_text);
|
|
|
|
ns_register_inp(efuns, input_dialog);
|
|
|
|
ns_register_tab(efuns, menu_tab);
|
|
|
|
|
2002-06-26 14:02:12 -07:00
|
|
|
#ifdef HAVE_HUMOR
|
2002-06-08 09:50:38 -07:00
|
|
|
ns_register_fun(efuns, waitstate);
|
2002-06-26 14:02:12 -07:00
|
|
|
#endif
|
2002-06-08 09:50:38 -07:00
|
|
|
|
|
|
|
return efuns;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
make_escreen_menu(buttonbar_t *bbar)
|
2002-06-08 08:44:08 -07:00
|
|
|
{
|
2002-06-26 14:02:12 -07:00
|
|
|
static int been_here = 0;
|
2002-06-08 08:44:08 -07:00
|
|
|
button_t *button;
|
|
|
|
menu_t *m;
|
|
|
|
menuitem_t *i;
|
|
|
|
|
2002-06-26 14:02:12 -07:00
|
|
|
if (been_here) { /* the start function may be called more than once */
|
|
|
|
return 0; /* in later versions, but we only want one EScreen menu */
|
|
|
|
}
|
|
|
|
|
|
|
|
been_here = 1;
|
|
|
|
|
2002-06-08 08:44:08 -07:00
|
|
|
if ((m = menu_create(NS_MENU_TITLE))) {
|
|
|
|
char *sc[] = {
|
|
|
|
/* display functions */
|
2002-06-26 14:02:12 -07:00
|
|
|
"New", "es_display(new)", /* \x01:screen\r */
|
|
|
|
"New...", "es_display(new,ask)",
|
2002-06-08 09:50:38 -07:00
|
|
|
"Rename...", "es_display(name,ask)",
|
|
|
|
"Backlog...", "es_display(backlog)",
|
|
|
|
"Monitor", "es_display(monitor)",
|
|
|
|
"Close", "es_display(close)",
|
2002-06-08 08:44:08 -07:00
|
|
|
"-", "",
|
|
|
|
/* region functions */
|
2002-06-08 09:50:38 -07:00
|
|
|
"Split", "es_region(new)",
|
|
|
|
"Unsplit", "es_region(full)",
|
2002-06-26 14:02:12 -07:00
|
|
|
"Prev region", "es_region(prev)", /* NS_SCREEN_PRVS_REG */
|
2002-06-08 09:50:38 -07:00
|
|
|
"Next region", "es_region(next)",
|
|
|
|
"Kill region", "es_region(kill)",
|
2002-06-08 08:44:08 -07:00
|
|
|
"-", "",
|
|
|
|
/* screen functions */
|
2002-06-08 09:50:38 -07:00
|
|
|
"Reset", "es_reset",
|
|
|
|
"Statement", "es_statement",
|
2002-06-08 08:44:08 -07:00
|
|
|
"-", ""
|
|
|
|
};
|
|
|
|
int n, nsc = sizeof(sc) / sizeof(char *);
|
2002-06-08 09:50:38 -07:00
|
|
|
int j, k = menu_list ? menu_list->nummenus : 0;
|
2002-06-08 08:44:08 -07:00
|
|
|
|
|
|
|
if (menu_list) {
|
2002-06-08 09:50:38 -07:00
|
|
|
for (n = 0; n < menu_list->nummenus; n++) {
|
|
|
|
/* blend in w/ l&f */
|
2002-06-08 08:44:08 -07:00
|
|
|
if (menu_list->menus[n]->font) {
|
|
|
|
m->font = menu_list->menus[n]->font;
|
|
|
|
m->fwidth = menu_list->menus[n]->fwidth;
|
|
|
|
m->fheight = menu_list->menus[n]->fheight;
|
|
|
|
#ifdef MULTI_CHARSET
|
|
|
|
m->fontset = menu_list->menus[n]->fontset;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < (nsc - 1); n += 2) {
|
2002-06-08 09:50:38 -07:00
|
|
|
if (!strcmp(sc[n], "-")) {
|
|
|
|
/* separator */
|
2002-06-08 08:44:08 -07:00
|
|
|
if ((i = menuitem_create(NULL))) {
|
|
|
|
menu_add_item(m, i);
|
|
|
|
menuitem_set_action(i, MENUITEM_SEP, NULL);
|
|
|
|
}
|
2002-06-08 09:50:38 -07:00
|
|
|
} else if ((i = menuitem_create(sc[n]))) {
|
2002-06-08 08:44:08 -07:00
|
|
|
menuitem_set_action(i, MENUITEM_SCRIPT, sc[n + 1]);
|
|
|
|
menu_add_item(m, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((i = menuitem_create("About..."))) {
|
|
|
|
menuitem_set_action(i, MENUITEM_ALERT, "Screen/Twin compatibility layer by Azundris <scream@azundris.com>");
|
|
|
|
menu_add_item(m, i);
|
|
|
|
}
|
2002-06-08 09:50:38 -07:00
|
|
|
menu_list = menulist_add_menu(menu_list, m);
|
|
|
|
for (j = k; j < menu_list->nummenus; j++) {
|
|
|
|
event_data_add_mywin(&menu_event_data, menu_list->menus[j]->win);
|
|
|
|
}
|
|
|
|
if (!k) {
|
|
|
|
menu_init();
|
|
|
|
}
|
2002-06-08 08:44:08 -07:00
|
|
|
|
|
|
|
if ((button = button_create(NS_MENU_TITLE))) {
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_add_rbutton(bbar, button);
|
2002-06-26 20:17:45 -07:00
|
|
|
bbar_calc_button_sizes(bbar);
|
2002-06-08 09:50:38 -07:00
|
|
|
button_set_action(button, ACTION_MENU, NS_MENU_TITLE);
|
2002-06-08 08:44:08 -07:00
|
|
|
}
|
2002-06-08 09:50:38 -07:00
|
|
|
return 1;
|
2002-06-08 08:44:08 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
/* Set everything up for escreen mode */
|
|
|
|
int
|
|
|
|
escreen_init(char **argv)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
int ns_err;
|
|
|
|
_ns_efuns *efuns;
|
2002-06-08 09:50:38 -07:00
|
|
|
buttonbar_t *bbar;
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-26 14:02:12 -07:00
|
|
|
if (TermWin.screen_mode == NS_MODE_NONE) {
|
2002-06-08 09:50:38 -07:00
|
|
|
return run_command(argv);
|
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
efuns = escreen_reg_funcs();
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
/* Create buttonbar for Escreen's use. */
|
|
|
|
if ((bbar = bbar_create()) == NULL) {
|
|
|
|
if (buttonbar != NULL) {
|
|
|
|
bbar = buttonbar;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2002-06-14 06:06:34 -07:00
|
|
|
if (buttonbar == NULL) {
|
|
|
|
buttonbar = bbar;
|
|
|
|
}
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_set_font(bbar, "-*-helvetica-medium-r-normal--10-*-*-*-p-*-iso8859-1");
|
2002-10-07 19:18:09 -07:00
|
|
|
bbar_init(bbar, TERM_WINDOW_GET_WIDTH());
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_add(bbar);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-06-26 14:02:12 -07:00
|
|
|
if ((TermWin.screen = ns_attach_by_URL(rs_url, rs_hop, &efuns, &ns_err, bbar)) == NULL) {
|
|
|
|
D_CMD(("ns_attach_by_URL(%s,%s) failed\n", rs_url, rs_hop));
|
2002-06-08 09:50:38 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (rs_delay >= 0) {
|
|
|
|
TermWin.screen->delay = rs_delay; /* more flexible ways later */
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
make_escreen_menu(bbar);
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
bbar_set_docked(bbar, BBAR_DOCKED_BOTTOM);
|
|
|
|
bbar_set_visible(bbar, 0);
|
|
|
|
bbar_show(bbar, 1);
|
|
|
|
parent_resize();
|
2002-05-04 07:25:30 -07:00
|
|
|
|
2002-06-28 13:44:40 -07:00
|
|
|
bbar_redraw(bbar); /* get a bar in twin too */
|
|
|
|
|
2002-06-08 09:50:38 -07:00
|
|
|
/* add_screen_ctl_button(bbar,"New",'c'); */
|
2002-06-26 14:02:12 -07:00
|
|
|
D_CMD(("TermWin.screen->fd = %d\n", TermWin.screen->fd));
|
2002-06-08 09:50:38 -07:00
|
|
|
return TermWin.screen->fd;
|
2002-05-23 11:14:41 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-02 17:24:22 -07:00
|
|
|
|
|
|
|
|
2002-05-23 11:14:41 -07:00
|
|
|
/* init_command() */
|
|
|
|
void
|
|
|
|
init_command(char **argv)
|
|
|
|
{
|
2002-06-02 17:24:22 -07:00
|
|
|
int (*command_func) (char **);
|
2002-05-23 11:14:41 -07:00
|
|
|
|
|
|
|
/* Use init function appropriate for how we were compiled. */
|
|
|
|
#ifdef ESCREEN
|
|
|
|
command_func = escreen_init;
|
2002-05-04 07:25:30 -07:00
|
|
|
#else
|
2002-05-23 11:14:41 -07:00
|
|
|
command_func = run_command;
|
2002-05-04 07:25:30 -07:00
|
|
|
#endif
|
2002-05-23 11:14:41 -07:00
|
|
|
|
|
|
|
/* Initialize the command connection. This should be called after
|
|
|
|
the X server connection is established. */
|
|
|
|
|
|
|
|
/* Enable delete window protocol */
|
|
|
|
XSetWMProtocols(Xdisplay, TermWin.parent, &(props[PROP_DELETE_WINDOW]), 1);
|
|
|
|
|
|
|
|
init_locale();
|
|
|
|
|
|
|
|
#ifdef META8_OPTION
|
|
|
|
meta_char = (Options & Opt_meta8 ? 0x80 : 033);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GREEK_SUPPORT
|
|
|
|
greek_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Xfd = XConnectionNumber(Xdisplay);
|
|
|
|
D_CMD(("Xfd = %d\n", Xfd));
|
|
|
|
cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
|
|
|
|
AT_LEAST((int) num_fds, Xfd + 1);
|
|
|
|
if (pipe_fd >= 0) {
|
|
|
|
AT_LEAST((int) num_fds, pipe_fd + 1);
|
|
|
|
}
|
|
|
|
if ((cmd_fd = command_func(argv)) < 0) {
|
2002-06-26 14:02:12 -07:00
|
|
|
print_error("Unable to run sub-command.\n");
|
2002-05-04 07:25:30 -07:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* window resizing */
|
|
|
|
/*
|
|
|
|
* Tell the teletype handler what size the window is.
|
|
|
|
* Called after a window size change.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tt_winsize(int fd)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
struct winsize ws;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (fd < 0)
|
|
|
|
return;
|
2001-08-28 00:36:44 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
MEMSET(&ws, 0, sizeof(struct winsize));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-10-07 19:18:09 -07:00
|
|
|
ws.ws_row = (unsigned short) TERM_WINDOW_GET_REPORTED_ROWS();
|
|
|
|
ws.ws_col = (unsigned short) TERM_WINDOW_GET_REPORTED_COLS();
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifndef __CYGWIN32__
|
2002-10-07 19:18:09 -07:00
|
|
|
ws.ws_xpixel = (unsigned short) TERM_WINDOW_GET_WIDTH();
|
|
|
|
ws.ws_ypixel = (unsigned short) TERM_WINDOW_GET_HEIGHT();
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-10-07 19:18:09 -07:00
|
|
|
D_CMD(("Sending TIOCSWINSZ to fd %d: %hdx%hd (%hdx%hd)\n",
|
|
|
|
fd, ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel));
|
2002-05-04 07:25:30 -07:00
|
|
|
ioctl(fd, TIOCSWINSZ, &ws);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tt_resize(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
tt_winsize(cmd_fd);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attempt to `write' COUNT to the input buffer */
|
|
|
|
unsigned int
|
|
|
|
cmd_write(const unsigned char *str, unsigned int count)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int n;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
n = (count - (cmdbuf_ptr - cmdbuf_base));
|
|
|
|
/* need to insert more chars that space available in the front */
|
|
|
|
if (n > 0) {
|
|
|
|
/* try and get more space from the end */
|
|
|
|
unsigned char *src, *dst;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-06-08 08:44:08 -07:00
|
|
|
dst = (cmdbuf_base + sizeof(cmdbuf_base) - 1); /* max pointer */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((cmdbuf_ptr + n) > dst)
|
2002-06-08 08:44:08 -07:00
|
|
|
n = (dst - cmdbuf_ptr); /* max # chars to insert */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if ((cmdbuf_endp + n) > dst)
|
2002-06-08 08:44:08 -07:00
|
|
|
cmdbuf_endp = (dst - n); /* truncate end if needed */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* equiv: memmove ((cmdbuf_ptr+n), cmdbuf_ptr, n); */
|
|
|
|
src = cmdbuf_endp;
|
|
|
|
dst = src + n;
|
|
|
|
/* FIXME: anything special to avoid possible pointer wrap? */
|
|
|
|
while (src >= cmdbuf_ptr)
|
|
|
|
*dst-- = *src--;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* done */
|
|
|
|
cmdbuf_ptr += n;
|
|
|
|
cmdbuf_endp += n;
|
|
|
|
}
|
|
|
|
while (count-- && cmdbuf_ptr > cmdbuf_base) {
|
|
|
|
/* sneak one in */
|
|
|
|
cmdbuf_ptr--;
|
|
|
|
*cmdbuf_ptr = str[count];
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
return (0);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BACKGROUND_CYCLING_SUPPORT
|
|
|
|
RETSIGTYPE
|
|
|
|
check_pixmap_change(int sig)
|
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
static time_t last_update = 0;
|
|
|
|
time_t now;
|
|
|
|
static unsigned long image_idx = 0;
|
|
|
|
void (*old_handler) (int);
|
|
|
|
static unsigned char in_cpc = 0;
|
|
|
|
|
|
|
|
if (in_cpc)
|
|
|
|
SIG_RETURN(0);
|
|
|
|
in_cpc = 1;
|
|
|
|
D_PIXMAP(("check_pixmap_change(%d): rs_anim_delay == %lu seconds, last_update == %lu\n", sig, rs_anim_delay, last_update));
|
|
|
|
if (!rs_anim_delay)
|
|
|
|
SIG_RETURN(0);
|
|
|
|
if (last_update == 0) {
|
|
|
|
last_update = time(NULL);
|
|
|
|
old_handler = signal(SIGALRM, check_pixmap_change);
|
|
|
|
alarm(rs_anim_delay);
|
|
|
|
in_cpc = 0;
|
|
|
|
SIG_RETURN(0);
|
|
|
|
}
|
|
|
|
now = time(NULL);
|
|
|
|
D_PIXMAP(("now %lu >= %lu (last_update %lu + rs_anim_delay %lu) ?\n", now, last_update + rs_anim_delay, last_update, rs_anim_delay));
|
|
|
|
if (now >= last_update + rs_anim_delay || 1) {
|
|
|
|
D_PIXMAP(("Time to update pixmap. now == %lu\n", now));
|
|
|
|
imlib_context_set_image(images[image_bg].current->iml->im);
|
|
|
|
imlib_free_image_and_decache();
|
|
|
|
images[image_bg].current->iml->im = NULL;
|
|
|
|
xterm_seq(XTerm_Pixmap, rs_anim_pixmaps[image_idx++]);
|
|
|
|
last_update = now;
|
|
|
|
old_handler = signal(SIGALRM, check_pixmap_change);
|
|
|
|
alarm(rs_anim_delay);
|
|
|
|
if (rs_anim_pixmaps[image_idx] == NULL) {
|
|
|
|
image_idx = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
in_cpc = 0;
|
2002-05-04 07:25:30 -07:00
|
|
|
if (old_handler) {
|
|
|
|
SIG_RETURN((*old_handler) (sig));
|
|
|
|
} else {
|
|
|
|
SIG_RETURN(sig);
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
#endif /* BACKGROUND_CYCLING_SUPPORT */
|
|
|
|
|
|
|
|
/* cmd_getc() - Return next input character */
|
|
|
|
/*
|
|
|
|
* Return the next input character after first passing any keyboard input
|
|
|
|
* to the command.
|
|
|
|
*/
|
|
|
|
unsigned char
|
|
|
|
cmd_getc(void)
|
|
|
|
{
|
|
|
|
#define TIMEOUT_USEC 2500
|
2002-05-04 07:25:30 -07:00
|
|
|
static short refreshed = 0;
|
|
|
|
fd_set readfds;
|
|
|
|
int retval;
|
|
|
|
struct timeval value, *delay;
|
|
|
|
|
|
|
|
/* If there has been a lot of new lines, then update the screen
|
|
|
|
* What the heck I'll cheat and only refresh less than every page-full.
|
|
|
|
* the number of pages between refreshes is refresh_limit, which
|
|
|
|
* is incremented here because we must be doing flat-out scrolling.
|
|
|
|
*
|
|
|
|
* refreshing should be correct for small scrolls, because of the
|
|
|
|
* time-out
|
|
|
|
*/
|
2002-10-07 19:18:09 -07:00
|
|
|
if (refresh_count >= (refresh_limit * (TERM_WINDOW_GET_ROWS() - 1))) {
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("Refresh count %d >= limit %d * rows. (Refresh period %d.)\n", refresh_count, refresh_limit, REFRESH_PERIOD));
|
|
|
|
if (refresh_limit < REFRESH_PERIOD)
|
|
|
|
refresh_limit++;
|
|
|
|
refresh_count = 0;
|
|
|
|
refreshed = 1;
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef PROFILE
|
2002-05-04 07:25:30 -07:00
|
|
|
P_CALL(scr_refresh(refresh_type), "cmd_getc()->scr_refresh()");
|
1999-08-17 16:01:18 -07:00
|
|
|
#else
|
2002-05-04 07:25:30 -07:00
|
|
|
scr_refresh(refresh_type);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef ESCREEN
|
2002-06-02 17:24:22 -07:00
|
|
|
if (TermWin.screen) {
|
|
|
|
switch (TermWin.screen->backend) {
|
|
|
|
case NS_MODE_NONE:
|
|
|
|
break;
|
|
|
|
case NS_MODE_NEGOTIATE:
|
|
|
|
# ifdef NS_HAVE_SCREEN
|
|
|
|
case NS_MODE_SCREEN:
|
|
|
|
parse_screen_status_if_necessary();
|
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
# ifdef NS_HAVE_SCREAM
|
|
|
|
case NS_MODE_SCREAM:
|
|
|
|
break;
|
2002-06-08 08:44:08 -07:00
|
|
|
# endif
|
|
|
|
# ifdef NS_HAVE_TWIN
|
|
|
|
case NS_MODE_TWIN:
|
|
|
|
if (!TermWin.screen->twin) {
|
2002-06-26 14:02:12 -07:00
|
|
|
if (!TermWin.screen->timestamp) {
|
|
|
|
TermWin.screen->timestamp = time(NULL);
|
|
|
|
} else if (TermWin.screen->timestamp < time(NULL)) {
|
|
|
|
if (!Tw_CheckMagic(libscream_magic)) {
|
|
|
|
D_ESCREEN(("ns_attach_by_sess: Tw_CheckMagic failed\n"));
|
2002-06-08 08:44:08 -07:00
|
|
|
TermWin.screen->backend = TermWin.screen_mode = NS_MODE_NONE;
|
|
|
|
} else {
|
2002-06-26 14:02:12 -07:00
|
|
|
if (!(TermWin.screen->twin = Tw_Open(TermWin.screen->twin_str))) {
|
|
|
|
ns_desc_twin(TermWin.screen, "cmd_getc->Tw_Open");
|
|
|
|
TermWin.screen->backend = TermWin.screen_mode = NS_MODE_NONE;
|
|
|
|
} else {
|
|
|
|
D_ESCREEN(("ns_attach_by_sess: Tw_Open(%s) succeeded: handle @ %p\n", TermWin.screen->twin_str, TermWin.screen->twin));
|
|
|
|
}
|
2002-06-08 08:44:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-06-02 17:24:22 -07:00
|
|
|
# endif
|
|
|
|
default:
|
|
|
|
D_ESCREEN(("mode %d not supported...\n", TermWin.screen->backend));
|
2002-06-08 08:44:08 -07:00
|
|
|
TermWin.screen->backend = TermWin.screen_mode = NS_MODE_NONE;
|
2002-06-02 17:24:22 -07:00
|
|
|
}
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* characters already read in */
|
|
|
|
if (CHARS_READ()) {
|
|
|
|
RETURN_CHAR();
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
for (;;) {
|
|
|
|
v_doPending();
|
2002-06-08 08:44:08 -07:00
|
|
|
while (XPending(Xdisplay)) { /* process pending X events */
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
XEvent ev;
|
|
|
|
|
|
|
|
refreshed = 0;
|
|
|
|
XNextEvent(Xdisplay, &ev);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef USE_XIM
|
2002-05-04 07:25:30 -07:00
|
|
|
if (xim_input_context != NULL) {
|
|
|
|
if (!XFilterEvent(&ev, ev.xkey.window)) {
|
|
|
|
event_dispatch(&ev);
|
|
|
|
}
|
|
|
|
} else
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
event_dispatch(&ev);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* in case button actions pushed chars to cmdbuf */
|
|
|
|
if (CHARS_READ()) {
|
|
|
|
RETURN_CHAR();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paused == 1 && cmd_fd == -1) {
|
|
|
|
const char *done = " -- Task Finished, ESC to exit";
|
2000-07-10 14:14:56 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
append_to_title(rs_finished_title ? rs_finished_title : done);
|
|
|
|
append_to_icon_name(rs_finished_title ? rs_finished_title : done);
|
2000-07-10 14:14:56 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
paused++;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (rs_finished_text) {
|
|
|
|
cmd_write((unsigned char *) rs_finished_text, strlen(rs_finished_text));
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
|
2002-05-04 07:25:30 -07:00
|
|
|
if (scrollbar_uparrow_is_pressed()) {
|
|
|
|
if (!scroll_arrow_delay-- && scr_page(UP, 1)) {
|
|
|
|
scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY;
|
|
|
|
refreshed = 0;
|
|
|
|
}
|
|
|
|
} else if (scrollbar_downarrow_is_pressed()) {
|
|
|
|
if (!scroll_arrow_delay-- && scr_page(DN, 1)) {
|
|
|
|
scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY;
|
|
|
|
refreshed = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif /* SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
/* Nothing to do! */
|
|
|
|
FD_ZERO(&readfds);
|
|
|
|
if (cmd_fd >= 0) {
|
|
|
|
FD_SET(cmd_fd, &readfds);
|
|
|
|
}
|
|
|
|
FD_SET(Xfd, &readfds);
|
|
|
|
if (pipe_fd >= 0) {
|
|
|
|
FD_SET(pipe_fd, &readfds);
|
|
|
|
}
|
|
|
|
value.tv_usec = TIMEOUT_USEC;
|
|
|
|
value.tv_sec = 0;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (refreshed
|
1999-08-17 16:01:18 -07:00
|
|
|
#ifdef SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
|
2002-05-04 07:25:30 -07:00
|
|
|
&& !(scrollbar_arrow_is_pressed())
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
2002-05-04 07:25:30 -07:00
|
|
|
) {
|
|
|
|
delay = NULL;
|
|
|
|
} else {
|
|
|
|
delay = &value;
|
2002-04-07 19:16:09 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
retval = select(num_fds, &readfds, NULL, NULL, delay);
|
|
|
|
|
|
|
|
if (retval < 0) {
|
|
|
|
if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) {
|
2002-06-08 08:44:08 -07:00
|
|
|
if (errno != EINTR) { /* may have rcvd SIGCHLD or so */
|
|
|
|
print_error(" (%ld) Error reading from tty -- %s\n", getpid(), strerror(errno));
|
|
|
|
cmd_fd = -1;
|
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
|
|
|
if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) {
|
|
|
|
print_error("Error reading from pipe -- %s\n", strerror(errno));
|
|
|
|
pipe_fd = -1;
|
|
|
|
}
|
|
|
|
if (pipe_fd < 0 && cmd_fd < 0 && !paused) {
|
|
|
|
exit(errno);
|
|
|
|
}
|
|
|
|
} else if (retval == 0) {
|
|
|
|
refresh_count = 0;
|
|
|
|
refresh_limit = 1;
|
|
|
|
if (!refreshed) {
|
|
|
|
refreshed = 1;
|
|
|
|
D_CMD(("select() timed out, time to update the screen.\n"));
|
|
|
|
scr_refresh(refresh_type);
|
|
|
|
if (scrollbar_is_visible()) {
|
|
|
|
scrollbar_anchor_update_position(1);
|
|
|
|
}
|
2002-04-07 19:16:09 -07:00
|
|
|
#ifdef USE_XIM
|
2002-05-04 07:25:30 -07:00
|
|
|
xim_send_spot();
|
2002-04-07 19:16:09 -07:00
|
|
|
#endif
|
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
} else {
|
|
|
|
/* We have something to read from. */
|
|
|
|
if (cmd_fd >= 0 && FD_ISSET(cmd_fd, &readfds)) {
|
|
|
|
/* See if we can read from the application */
|
|
|
|
register unsigned int count = CMD_BUF_SIZE;
|
|
|
|
|
|
|
|
cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
|
|
|
|
while (count) {
|
|
|
|
|
|
|
|
register int n = read(cmd_fd, cmdbuf_endp, count);
|
|
|
|
|
|
|
|
if (n <= 0) {
|
|
|
|
if (paused) {
|
|
|
|
cmd_fd = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cmdbuf_endp += n;
|
|
|
|
count -= n;
|
|
|
|
}
|
|
|
|
/* some characters read in */
|
|
|
|
if (CHARS_BUFFERED()) {
|
|
|
|
RETURN_CHAR();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pipe_fd >= 0 && FD_ISSET(pipe_fd, &readfds)) {
|
|
|
|
register unsigned int count = CMD_BUF_SIZE / 2;
|
|
|
|
|
|
|
|
cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
|
|
|
|
while (count) {
|
|
|
|
|
|
|
|
register int n = read(pipe_fd, cmdbuf_endp, count);
|
|
|
|
|
|
|
|
if (n <= 0)
|
|
|
|
break;
|
|
|
|
n = add_carriage_returns(cmdbuf_endp, n);
|
|
|
|
cmdbuf_endp += n;
|
|
|
|
count -= n;
|
|
|
|
}
|
|
|
|
/* some characters read in */
|
|
|
|
if (CHARS_BUFFERED()) {
|
|
|
|
RETURN_CHAR();
|
|
|
|
}
|
|
|
|
}
|
1999-10-28 08:22:58 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
2002-05-04 07:25:30 -07:00
|
|
|
return (0);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
2000-03-01 19:31:41 -08:00
|
|
|
/* Put a character back in the buffer. Only use this once at a time. */
|
|
|
|
void
|
|
|
|
cmd_ungetc(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
cmdbuf_ptr--;
|
2000-03-01 19:31:41 -08:00
|
|
|
}
|
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* tt_write(), tt_printf() - output to command */
|
|
|
|
/*
|
|
|
|
* Send count characters directly to the command
|
|
|
|
*/
|
1999-08-17 16:01:18 -07:00
|
|
|
void
|
1999-08-17 18:12:47 -07:00
|
|
|
tt_write(const unsigned char *buf, unsigned int count)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
v_writeBig(cmd_fd, (char *) buf, count);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
#if 0 /* Fixes the bug that hung Eterm when pasting a lot of stuff */
|
|
|
|
while (count > 0) {
|
|
|
|
int n = write(cmd_fd, buf, count);
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (n > 0) {
|
|
|
|
count -= n;
|
|
|
|
buf += n;
|
|
|
|
}
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
#endif
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/*
|
|
|
|
* Send printf() formatted output to the command.
|
|
|
|
* Only use for small ammounts of data.
|
|
|
|
*/
|
|
|
|
void
|
2000-01-07 07:51:22 -08:00
|
|
|
tt_printf(const unsigned char *fmt, ...)
|
1999-08-17 18:12:47 -07:00
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
static unsigned char buf[256];
|
|
|
|
va_list arg_ptr;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
va_start(arg_ptr, fmt);
|
|
|
|
vsnprintf((char *) buf, sizeof(buf), (char *) fmt, arg_ptr);
|
|
|
|
va_end(arg_ptr);
|
|
|
|
tt_write(buf, strlen((char *) buf));
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* Read and process output from the application */
|
|
|
|
void
|
|
|
|
main_loop(void)
|
|
|
|
{
|
2002-05-04 07:25:30 -07:00
|
|
|
/* int ch; */
|
|
|
|
register int ch;
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
D_CMD(("PID %d\n", getpid()));
|
|
|
|
D_CMD(("Command buffer base == %8p, length %lu, end at %8p\n", cmdbuf_base, CMD_BUF_SIZE, cmdbuf_base + CMD_BUF_SIZE - 1));
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
#ifdef BACKGROUND_CYCLING_SUPPORT
|
2002-05-04 07:25:30 -07:00
|
|
|
if (rs_anim_delay) {
|
|
|
|
check_pixmap_change(0);
|
|
|
|
}
|
2000-06-26 16:37:05 -07:00
|
|
|
#endif
|
2002-05-22 08:38:35 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
do {
|
2002-06-08 08:44:08 -07:00
|
|
|
while ((ch = cmd_getc()) == 0); /* wait for something */
|
2002-05-04 07:25:30 -07:00
|
|
|
if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') {
|
|
|
|
/* Read a text string from the input buffer */
|
|
|
|
int nlines = 0;
|
|
|
|
|
|
|
|
/* unsigned char * str; */
|
|
|
|
register unsigned char *str;
|
|
|
|
|
|
|
|
D_CMD(("Command buffer contains %d characters.\n", cmdbuf_endp - cmdbuf_ptr));
|
|
|
|
D_VT(("\n%s\n\n", safe_print_string(cmdbuf_ptr - 1, cmdbuf_endp - cmdbuf_ptr + 1)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* point to the start of the string,
|
|
|
|
* decrement first since already did get_com_char ()
|
|
|
|
*/
|
|
|
|
str = --cmdbuf_ptr;
|
|
|
|
while (cmdbuf_ptr < cmdbuf_endp) {
|
|
|
|
|
|
|
|
ch = *cmdbuf_ptr++;
|
|
|
|
#if DEBUG >= DEBUG_VT
|
|
|
|
if (DEBUG_LEVEL >= DEBUG_VT) {
|
|
|
|
if (ch < 32) {
|
|
|
|
D_VT(("\'%s\' (%d 0x%02x %03o)\n", get_ctrl_char_name(ch), ch, ch, ch));
|
|
|
|
} else {
|
|
|
|
D_VT(("\'%c\' (%d 0x%02x %03o)\n", ch, ch, ch, ch));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (ch >= ' ' || ch == '\t' || ch == '\r') {
|
|
|
|
/* nothing */
|
|
|
|
} else if (ch == '\n') {
|
|
|
|
nlines++;
|
2002-10-07 19:18:09 -07:00
|
|
|
if (++refresh_count >= (refresh_limit * (TERM_WINDOW_GET_ROWS() - 1)))
|
2002-05-04 07:25:30 -07:00
|
|
|
break;
|
|
|
|
} else { /* unprintable */
|
|
|
|
cmdbuf_ptr--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-06-02 17:24:22 -07:00
|
|
|
D_SCREEN(("Adding %d lines (%d chars); str == %8p, cmdbuf_ptr == %8p, cmdbuf_endp == %8p\n", nlines, cmdbuf_ptr - str, str, cmdbuf_ptr, cmdbuf_endp));
|
2002-05-04 07:25:30 -07:00
|
|
|
scr_add_lines(str, nlines, (cmdbuf_ptr - str));
|
|
|
|
} else {
|
|
|
|
switch (ch) {
|
2001-05-16 18:50:12 -07:00
|
|
|
# ifdef NO_ENQ_ANS
|
2002-05-04 07:25:30 -07:00
|
|
|
case 005:
|
|
|
|
break;
|
1999-08-17 18:12:47 -07:00
|
|
|
# else
|
2002-05-04 07:25:30 -07:00
|
|
|
case 005: /* ^E (ENQ) terminal status enquiry */
|
|
|
|
tt_printf(VT100_ANS);
|
|
|
|
break;
|
1999-08-17 18:12:47 -07:00
|
|
|
# endif
|
2002-05-04 07:25:30 -07:00
|
|
|
case 007: /* ^G (BEL) */
|
|
|
|
scr_bell();
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
scr_backspace();
|
|
|
|
break;
|
|
|
|
case 013: /* ^K (VT) */
|
|
|
|
case 014: /* ^L (FF) */
|
|
|
|
scr_index(UP);
|
|
|
|
break;
|
|
|
|
case 016: /* ^N (SO) shift out (enter ACS mode) */
|
|
|
|
scr_charset_choose(1);
|
|
|
|
break;
|
|
|
|
case 017: /* ^O (SI) shift in (leave ACS mode) */
|
|
|
|
scr_charset_choose(0);
|
|
|
|
break;
|
|
|
|
case 033:
|
|
|
|
process_escape_seq();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (ch != EOF);
|
1999-08-17 18:12:47 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* output a burst of any pending data from a paste... */
|
|
|
|
int
|
|
|
|
v_doPending(void)
|
|
|
|
{
|
1999-08-17 16:01:18 -07:00
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
if (v_bufstr >= v_bufptr)
|
|
|
|
return (0);
|
|
|
|
v_writeBig(cmd_fd, NULL, 0);
|
|
|
|
return (1);
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
|
1999-08-17 18:12:47 -07:00
|
|
|
/* Write data to the pty as typed by the user, pasted with the mouse,
|
|
|
|
* or generated by us in response to a query ESC sequence.
|
|
|
|
* Code stolen from xterm
|
1999-08-17 16:01:18 -07:00
|
|
|
*/
|
|
|
|
void
|
1999-08-17 18:12:47 -07:00
|
|
|
v_writeBig(int f, char *d, int len)
|
1999-08-17 16:01:18 -07:00
|
|
|
{
|
|
|
|
|
2002-05-04 07:25:30 -07:00
|
|
|
int written;
|
|
|
|
int c = len;
|
|
|
|
|
|
|
|
if (v_bufstr == NULL && len > 0) {
|
|
|
|
|
|
|
|
v_buffer = MALLOC(len);
|
|
|
|
v_bufstr = v_buffer;
|
|
|
|
v_bufptr = v_buffer;
|
|
|
|
v_bufend = v_buffer + len;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Append to the block we already have.
|
|
|
|
* Always doing this simplifies the code, and
|
|
|
|
* isn't too bad, either. If this is a short
|
|
|
|
* block, it isn't too expensive, and if this is
|
|
|
|
* a long block, we won't be able to write it all
|
|
|
|
* anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (len > 0) {
|
2002-06-08 08:44:08 -07:00
|
|
|
if (v_bufend < v_bufptr + len) { /* we've run out of room */
|
2002-05-04 07:25:30 -07:00
|
|
|
if (v_bufstr != v_buffer) {
|
|
|
|
/* there is unused space, move everything down */
|
|
|
|
/* possibly overlapping bcopy here */
|
|
|
|
|
|
|
|
/* bcopy(v_bufstr, v_buffer, v_bufptr - v_bufstr); */
|
|
|
|
memcpy(v_buffer, v_bufstr, v_bufptr - v_bufstr);
|
|
|
|
v_bufptr -= v_bufstr - v_buffer;
|
|
|
|
v_bufstr = v_buffer;
|
|
|
|
}
|
|
|
|
if (v_bufend < v_bufptr + len) {
|
|
|
|
/* still won't fit: get more space */
|
|
|
|
/* Don't use XtRealloc because an error is not fatal. */
|
2002-06-08 08:44:08 -07:00
|
|
|
int size = v_bufptr - v_buffer; /* save across realloc */
|
2002-05-04 07:25:30 -07:00
|
|
|
|
|
|
|
v_buffer = REALLOC(v_buffer, size + len);
|
|
|
|
if (v_buffer) {
|
|
|
|
v_bufstr = v_buffer;
|
|
|
|
v_bufptr = v_buffer + size;
|
|
|
|
v_bufend = v_bufptr + len;
|
|
|
|
} else {
|
|
|
|
/* no memory: ignore entire write request */
|
|
|
|
print_error("cannot allocate buffer space\n");
|
2002-06-08 08:44:08 -07:00
|
|
|
v_buffer = v_bufstr; /* restore clobbered pointer */
|
2002-05-04 07:25:30 -07:00
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-08 08:44:08 -07:00
|
|
|
if (v_bufend >= v_bufptr + len) { /* new stuff will fit */
|
|
|
|
memcpy(v_bufptr, d, len); /* bcopy(d, v_bufptr, len); */
|
2002-05-04 07:25:30 -07:00
|
|
|
v_bufptr += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Write out as much of the buffer as we can.
|
|
|
|
* Be careful not to overflow the pty's input silo.
|
|
|
|
* We are conservative here and only write
|
|
|
|
* a small amount at a time.
|
|
|
|
*
|
|
|
|
* If we can't push all the data into the pty yet, we expect write
|
|
|
|
* to return a non-negative number less than the length requested
|
|
|
|
* (if some data written) or -1 and set errno to EAGAIN,
|
|
|
|
* EWOULDBLOCK, or EINTR (if no data written).
|
|
|
|
*
|
|
|
|
* (Not all systems do this, sigh, so the code is actually
|
|
|
|
* a little more forgiving.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (v_bufptr > v_bufstr) {
|
|
|
|
written = write(f, v_bufstr, v_bufptr - v_bufstr <= MAX_PTY_WRITE ? v_bufptr - v_bufstr : MAX_PTY_WRITE);
|
|
|
|
if (written < 0) {
|
|
|
|
written = 0;
|
|
|
|
}
|
|
|
|
D_TTY(("Wrote %d characters\n", written));
|
|
|
|
v_bufstr += written;
|
2002-06-08 08:44:08 -07:00
|
|
|
if (v_bufstr >= v_bufptr) /* we wrote it all */
|
2002-05-04 07:25:30 -07:00
|
|
|
v_bufstr = v_bufptr = v_buffer;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we have lots of unused memory allocated, return it
|
|
|
|
*/
|
2002-06-08 08:44:08 -07:00
|
|
|
if (v_bufend - v_bufptr > 1024) { /* arbitrary hysteresis */
|
2002-05-04 07:25:30 -07:00
|
|
|
/* save pointers across realloc */
|
|
|
|
int start = v_bufstr - v_buffer;
|
|
|
|
int size = v_bufptr - v_buffer;
|
|
|
|
int allocsize = size ? size : 1;
|
|
|
|
|
|
|
|
v_buffer = REALLOC(v_buffer, allocsize);
|
|
|
|
if (v_buffer) {
|
|
|
|
v_bufstr = v_buffer + start;
|
|
|
|
v_bufptr = v_buffer + size;
|
|
|
|
v_bufend = v_buffer + allocsize;
|
|
|
|
} else {
|
|
|
|
/* should we print a warning if couldn't return memory? */
|
2002-06-08 08:44:08 -07:00
|
|
|
v_buffer = v_bufstr - start; /* restore clobbered pointer */
|
2002-05-04 07:25:30 -07:00
|
|
|
}
|
1999-08-17 16:01:18 -07:00
|
|
|
}
|
|
|
|
}
|