xvt-2.1.orig/ 40755 765 765 0 6410235245 10775 5ustar cpb4cpb4xvt-2.1.orig/COPYING100644 765 765 2226 6410233422 12122 0ustar cpb4cpb4/* xvt 2.1 * Copyright 1992-94, 1997 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ xvt-2.1.orig/Makefile100644 765 765 7010 6410225021 12517 0ustar cpb4cpb4# @(#)Makefile 1.8 9/12/93 (UKC) # # To build xvt for one of the supported architectures: # # 1. Uncomment the appropriate ARCH= line below # # 2. Comment out the SITE=UKC line unless this is UKC # # 3. write out the edited Makefile and type 'make config' # # 4. look at the Makefile and check that the uncommented options # seem sensible. If you want to use a different C compiler # or different libraries or include files then edit the Makefile # by hand. # # 5. Type make depend (if your system has makedepend(1) installed). # # 6. Type make # ###################################################################### # # Supported architectures. Only one of these lines should be uncommented. # ARCH=SUNOS4 #ARCH=SUNOS5 #ARCH=OSF1 #ARCH=AIX3 #ARCH=ULTRIX #ARCH=HPUX #ARCH=LINUX # # # If this line is uncommented then `Make config' will unclude several options # that are probably only wanted at UKC. # #SITE=UKC # # # Directories to install the binary and the manual page # BIN=/usr/local/X11 MANDIR=/usr/local/man/man1 # ###################################################################### # # Lines in this section are automatically commented or uncommented # by running `make config'. Edit them by hand if the configured # options are not appropriate. # # # Enable the code that allows xvt to provide a Hex encoded Magic Cookie # for inclusion in a .Xauthority file. # #MAGIC_COOKIE=-DMAGIC_COOKIE #SITE UKC # # # Needed for the Magic Cookie code but not otherwise. # #AUTHLIB=-lXau #SITE UKC # # # Enable code that can make use of the UKC locations database. This # is almost obsolete, even at UKC, and totally useless anywhere else. # #UKC_LOCATIONS=-DUKC_LOCATIONS #SITE UKC # # # Enable some extra debugging code # #DEBUG=-DDEBUG #SITE UKC # #OPTIONS=$(MAGIC_COOKIE) $(DEBUG) #ARCH SUNOS5 OSF1 AIX3 ULTRIX LINUX OPTIONS=$(MAGIC_COOKIE) $(UKC_LOCATIONS) $(DEBUG) #ARCH SUNOS4 # # Additional architecture dependent defines # # add lines and columns to environment - delays startup # #DEFS=-DLC_ENV #ARCH HPUX # # Additional directories to search for include files. These may need # modifying if you have local include directories. # #ANSI_INCLUDE=-I/usr/local/lib/ansi-include #SITE UKC INCLUDE=$(ANSI_INCLUDE) #ARCH SUNOS4 #INCLUDE=-I/usr/openwin/include #ARCH SUNOS5 #INCLUDE=-I/usr/include/X11R5 #ARCH HPUX # # # Any architecture dependent libraries or library search paths. # #LIB=-lnsl $(AUTHLIB) #ARCH SUNOS5 LIB=$(AUTHLIB) #ARCH SUNOS4 OSF1 AIX3 ULTRIX LINUX #LDFLAGS=-i -R /usr/openwin/lib -L /usr/openwin/lib #ARCH SUNOS5 #LDFLAGS=-L/usr/lib/X11R5 #ARCH HPUX # # # The C compiler # #CC=gcc -g -ansi -Wall -Wmissing-prototypes #SITE UKC #CC=cc #ARCH OSF1 AIX3 HPUX ULTRIX # # End of automatically configured options. # ###################################################################### # OBJ=xvt.o xsetup.o command.o screen.o sbar.o ttyinit.o SRC=xvt.c xsetup.c command.c screen.c sbar.c ttyinit.c # CFLAGS=-O $(INCLUDE) $(OPTIONS) $(DEFS) -D$(ARCH) # xvt: $(OBJ) $(CC) $(LDFLAGS) -o xvt $(OBJ) $(LIB) -lX11 install: $(BIN)/xvt $(MANDIR)/xvt.1 $(MANDIR)/xvt.1: xvt.1 cp xvt.1 $@ chmod 0644 $@ $(BIN)/xvt: xvt cp xvt $@.new strip $@.new chown root $@.new chmod 04755 $@.new mv $@.new $@ clean: rm -f $(OBJ) xvt tags: $(SRC) ctags $(SRC) config: ./cmake ARCH $(ARCH) < Makefile | ./cmake SITE $(SITE) >Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile depend: makedepend -- $(CFLAGS) -- $(SRC) # DO NOT DELETE THIS LINE -- make depend depends on it. xvt-2.1.orig/README100644 765 765 14426 6410226551 12001 0ustar cpb4cpb4 README file for xvt 2.1 ----------------------- Xvt is an X terminal-emulator that is designed to be more or less compatible with xterm while using much less swap space. It is mainly intended for use at sites which use large numbers of X terminals but may also be useful on single workstations that are short of memory. On a SPARCstation running SunOS4, an initially invoked xvt uses about 1/3 megabyte of swap while xterm uses about 1.3 megabytes (obtained by running pstat rather than ps which seems to give unreliable size figures on SPARCs). The main way that xvt achieves its small size is by avoiding the use of the X toolkit. Supported architectures ----------------------- One of the major changes between xvt-1.0 and 2.0 is that xvt-2.0 is much more portable. The released version should build and run on all the architectures I have access to, namely: SunOS4, SunOS5, HP-UX 8.0, HP-UX 9.0, DEC OSF/1 V1.2 and ULTRIX 3.?. In addition, the teletype initialisation code has been completely restructured to make it more portable. Almost all the system dependent code is in the single source file, ttyinit.c. Xterm features not supported ---------------------------- - Tektronix 4014 emulation - Session logging - Pop-up menus. The only one of xterm's popup menu commands that is provided in xvt is displaying and hiding of the scrollbar and this is done simply by pressing any mouse key in the window with the CONTROL key held down. - Toolkit style configurability. In particular, xvt does not allow the user to remap the mouse or keyboard keys. Major xterm features that are supported --------------------------------------- - VT100 emulation. Most of the main escape sequences are supported - certainly all those used by the standard screen based UNIX applications. - Lines that scroll off the top of the window are saved can be scrolled back with a scrollbar. - Text selection and insertion including double and triple click for words and lines. Differences between xvt2.1 and xvt2.0 ------------------------------------- - Fix to make xvt terminate correctly when the shell is exit under Solaris 2.3. - LINES and COLUMNS environment variables added under HP/UX. - Minor changes to the Makefile. - Text selection now works with the Caps Lock key down. - Fixed a bug that caused the occasional loss of typed characters. - Fixed a bug which caused xvt to occasionally start up with its tty width set one or two columns too wide. - The standard vt100 screen clear escape sequences now save the cleared lines to the list of saved scrolled lines. - Minor changes to support Linux. Differences between xvt2.0 and xvt1.0 ------------------------------------- - xvt2.0 is eight bit clean and will generate and display eight bit characters. The META key can be used to generate characters with the eighth bit set (in eight bit mode) or prefixed by escape (in seven bit mode). - The teletype setup code has been rewritten to make it much more portable. See the comments at the head of ttyinit.c. - Exposure handling has been made much more efficient so that xvt should now be useable with window managers that provide opaque window movement. - VT100 graphics characters are supported for fonts that include them. - There is now a -ls option to enable the use of a login shell. - Colored text cursors are now supported. - There is support for the -C (console window) option but only on SunOS 4. - Bold characters are generated by overstriking if no bold font is specified. - Function keys generate escape sequences as in xterm. - A number of bugs have been fixed: - Setting the title without a terminating ^G no longer locks up. - Paste followed by a keystroke will always insert in the correct order. - Pasting an uninitialised string will not cause a crash. Other differences between xvt and xterm --------------------------------------- - Xvt has a couple of additional enquiry escape sequences: ESC[7n - causes xvt to respond with the name of its X display in a form that can be used to initialise the DISPLAY environment variable. If this is done in a user's .cshrc file it provides a way to automatically update DISPLAY after an rlogin. Something like the following should work if the initial ^[ in the echo command is an ESC character: if(!($?DISPLAY)) then if($?term) then if($term =~ xterm*) then stty -echo >/dev/tty echo -n '^[[7n' >/dev/tty setenv DISPLAY `line /dev/tty endif endif endif ESC[8n - causes xvt to respond with a hex encoded copy of the server's magic cookie which can be used to update a user's .Xauthority file. We have a program to do this which could be made available if anyone is interested. Known Bugs ---------- - xvt does not know about transferring selections in installments and so making large selections or trying to insert large selections will fail. The maximum selection size supported is server dependent but seems to be a little under 64k on all our servers. - xvt does not look in all the approved places for its X resources. It does, however, work correctly with resources that have been loaded into the server using xrdb Building and installing xvt --------------------------- Xvt does not use imake but does come with a simple Makefile configuration scheme that provides some help with getting the Makefile right. If you want to build xvt on one of the supported architectures then you should uncomment the appropriate definition at the start of the Makefile and then run `make config', which will modify other Makefile comments to bring them into line with the chosen architecture. To install xvt, you should edit the MANDIR and BIN pathnames in the Makefile and then type 'make install' as root. When installed for general use, xvt needs to belong to root and have the setuid flag set so that it can make entries in the /etc/utmp file. Thanks to all the people who have mailed bug reports, patches and local improvements. Some requested additions have gone into V2.0, others perhaps should have, but were left out due to lack of time. Please send bug reports and WIBNIs to: John Bovey Computing Laboratory University of Kent at Canterbury Canterbury Kent UK email: jdb@ukc.ac.uk xvt-2.1.orig/cmake100755 765 765 1136 5472175053 12110 0ustar cpb4cpb4#!/bin/sh # # Script used to configure the xvt makefile. Run as cmake FOO BAR it will # # uncomment all lines containing #FOO followed by BAR on the same line # # comment out all lines containing #FOO not followed by BAR # # leave all other lines unchanged # if test $# -eq 1 then arg="none" elif test $# -eq 2 then arg=$2 else echo "usage is cmake arg1 [ arg2 ]" >&2 exit 1 fi awk ' /#'$1'.*'$arg'/ { if ($0 ~ /^#/) printf("%s\n",substr($0,2)); else printf("%s\n",$0); next; } /#'$1'/ { if ($0 ~ /^#/) printf("%s\n",$0); else printf("#%s\n",$0); next; } { print $0; } ' xvt-2.1.orig/command.c100644 765 765 75270 6410001522 12674 0ustar cpb4cpb4/* Copyright 1992, 1993 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_command_c_sccsid[] = "@(#)command.c 1.3 9/12/93 (UKC)"; #ifdef __STDC__ #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "xvt.h" #include "token.h" #include "command.h" #include "ttyinit.h" #include "screen.h" #include "xsetup.h" #ifdef AIX3 #include #endif /* AIX3 */ #define NLMAX 15 /* max number of lines to scroll */ #define KBUFSIZE 256 /* size of keyboard mapping buffer */ #define COM_BUF_SIZE 2048 /* size of buffer used to read from the command */ #define COM_PUSH_MAX 20 /* max number of characters that can be pushed back into the input queue */ #define MP_INTERVAL 500 /* multi-press interval in milliseconds */ /* Special character returned by get_com_char(). */ #define GCC_NULL 0x100 /* Input buffer is empty */ #define ESC 033 /* Flags used to control get_com_char(); */ #define BUF_ONLY 1 #define GET_XEVENTS 2 /* Global variables that are set up at the beginning and then not changed */ extern Display *display; extern Window vt_win; extern Window sb_win; extern Window main_win; int comm_fd = -1; /* file descriptor connected to the command */ int fd_width; /* width of file descriptors being used */ static int x_fd; /* file descriptor of the X server connection */ static int app_cur_keys = 0;/* flag to say cursor keys are in application mode */ static int app_kp_keys = 0; /* flag to set application keypad keys */ static int sun_function_keys = 0; /* flag set to use Sun function key mapping */ static Atom wm_del_win; static unsigned char *send_buf = NULL; /* characters waiting to be sent to the command */ static unsigned char *send_nxt = NULL; /* next character to be sent */ static int send_count = 0; /* number of characters waiting to be sent */ /* Static variables used to record interesting X events. */ /* Small X event structure used to queue interesting X events that need to * be converted into tokens. */ struct xeventst { int xe_type; int xe_button; int xe_state; int xe_x; int xe_y; int xe_width; int xe_height; int xe_detail; unsigned long xe_time; Window xe_window; Atom xe_property; /* for selection requests */ Atom xe_target; Window xe_requestor; /* ditto */ struct xeventst *xe_next; struct xeventst *xe_prev; }; static struct xeventst *xevent_start = NULL; static struct xeventst *xevent_last = NULL; /* start and end of queue */ /* Variables used for buffered command input. */ static unsigned char com_buf[COM_BUF_SIZE]; static unsigned char *com_buf_next, *com_buf_top; static unsigned char com_stack[COM_PUSH_MAX]; /* stack of pushed back characters */ static unsigned char *com_stack_top; /* Thanks to Rob McMullen for the following function key mapping tables * and code. */ /* Structure used to describe the string generated by a function key, * keypad key, etc. */ struct keystringst { char ks_type; /* the way to generate the string (see below) */ unsigned char ks_value; /* value used in creating the string */ }; /* Different values for ks_type which determine how the value is used to * generate the string. */ #define KS_TYPE_NONE (char)0 /* No output */ #define KS_TYPE_CHAR (char)1 /* as printf("%c",ks_value) */ #define KS_TYPE_XTERM (char)2 /* as printf("\033[%d",ks_value) */ #define KS_TYPE_SUN (char)3 /* as printf("\033[%dz",ks_value) */ #define KS_TYPE_APPKEY (char)4 /* as printf("\033O%c",ks_value) */ #define KS_TYPE_NONAPP (char)5 /* as printf("\033[%c",ks_value) */ /* Structure used to map a keysym to a string. */ struct keymapst { KeySym km_keysym; struct keystringst km_normal; /* The usual string */ struct keystringst km_alt; /* The alternative string */ }; /* Table of function key mappings */ static struct keymapst func_key_table[] = { {XK_F1, {KS_TYPE_XTERM,11}, {KS_TYPE_SUN,224}}, {XK_F2, {KS_TYPE_XTERM,12}, {KS_TYPE_SUN,225}}, {XK_F3, {KS_TYPE_XTERM,13}, {KS_TYPE_SUN,226}}, {XK_F4, {KS_TYPE_XTERM,14}, {KS_TYPE_SUN,227}}, {XK_F5, {KS_TYPE_XTERM,15}, {KS_TYPE_SUN,228}}, {XK_F6, {KS_TYPE_XTERM,17}, {KS_TYPE_SUN,229}}, {XK_F7, {KS_TYPE_XTERM,18}, {KS_TYPE_SUN,230}}, {XK_F8, {KS_TYPE_XTERM,19}, {KS_TYPE_SUN,231}}, {XK_F9, {KS_TYPE_XTERM,20}, {KS_TYPE_SUN,232}}, {XK_F10, {KS_TYPE_XTERM,21}, {KS_TYPE_SUN,233}}, {XK_F11, {KS_TYPE_XTERM,23}, {KS_TYPE_SUN,192}}, {XK_F12, {KS_TYPE_XTERM,24}, {KS_TYPE_SUN,193}}, {XK_F13, {KS_TYPE_XTERM,25}, {KS_TYPE_SUN,194}}, {XK_F14, {KS_TYPE_XTERM,26}, {KS_TYPE_SUN,195}}, {XK_F15, {KS_TYPE_XTERM,28}, {KS_TYPE_SUN,196}}, {XK_F16, {KS_TYPE_XTERM,29}, {KS_TYPE_SUN,197}}, {XK_F17, {KS_TYPE_XTERM,31}, {KS_TYPE_SUN,198}}, {XK_F18, {KS_TYPE_XTERM,32}, {KS_TYPE_SUN,199}}, {XK_F19, {KS_TYPE_XTERM,33}, {KS_TYPE_SUN,200}}, {XK_F20, {KS_TYPE_XTERM,34}, {KS_TYPE_SUN,201}}, {XK_F21, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,208}}, {XK_F22, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,209}}, {XK_F23, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,210}}, {XK_F24, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,211}}, {XK_F25, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,212}}, {XK_F26, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,213}}, {XK_F27, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,214}}, {XK_F28, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,215}}, {XK_F29, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,216}}, {XK_F30, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,217}}, {XK_F31, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,218}}, {XK_F32, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,219}}, {XK_F33, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,220}}, {XK_F34, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,221}}, {XK_F35, {KS_TYPE_NONE,0}, {KS_TYPE_SUN,222}}, {XK_Find, {KS_TYPE_XTERM,1}, {KS_TYPE_SUN,1}}, {XK_Insert, {KS_TYPE_XTERM,2}, {KS_TYPE_SUN,2}}, {XK_Delete, {KS_TYPE_XTERM,3}, {KS_TYPE_SUN,3}}, {XK_Select, {KS_TYPE_XTERM,4}, {KS_TYPE_SUN,4}}, {XK_Prior, {KS_TYPE_XTERM,5}, {KS_TYPE_SUN,5}}, {XK_Next, {KS_TYPE_XTERM,6}, {KS_TYPE_SUN,6}}, {XK_Help, {KS_TYPE_XTERM,28}, {KS_TYPE_SUN,196}}, {XK_Menu, {KS_TYPE_XTERM,29}, {KS_TYPE_SUN,197}}, {0, {KS_TYPE_NONE,0}, {KS_TYPE_NONE,0}} }; /* PC keys and VT100 keypad function keys */ static struct keymapst other_key_table[]={ { XK_Up, {KS_TYPE_NONAPP,'A'}, {KS_TYPE_APPKEY,'A'}}, { XK_Down, {KS_TYPE_NONAPP,'B'}, {KS_TYPE_APPKEY,'B'}}, { XK_Right, {KS_TYPE_NONAPP,'C'}, {KS_TYPE_APPKEY,'C'}}, { XK_Left, {KS_TYPE_NONAPP,'D'}, {KS_TYPE_APPKEY,'D'}}, { XK_Home, {KS_TYPE_NONAPP,'h'}, {KS_TYPE_APPKEY,'h'}}, { XK_End, {KS_TYPE_NONAPP,'\0'}, {KS_TYPE_APPKEY,'\0'}}, { XK_KP_F1, {KS_TYPE_APPKEY,'P'}, {KS_TYPE_APPKEY,'P'}}, { XK_KP_F2, {KS_TYPE_APPKEY,'Q'}, {KS_TYPE_APPKEY,'Q'}}, { XK_KP_F3, {KS_TYPE_APPKEY,'R'}, {KS_TYPE_APPKEY,'R'}}, { XK_KP_F4, {KS_TYPE_APPKEY,'S'}, {KS_TYPE_APPKEY,'S'}}, {0, {KS_TYPE_NONE,0}, {KS_TYPE_NONE,0}} }; /* VT100 numeric keypad keys */ static struct keymapst kp_key_table[]={ { XK_KP_0, {KS_TYPE_CHAR,'0'}, {KS_TYPE_APPKEY,'p'}}, { XK_KP_1, {KS_TYPE_CHAR,'1'}, {KS_TYPE_APPKEY,'q'}}, { XK_KP_2, {KS_TYPE_CHAR,'2'}, {KS_TYPE_APPKEY,'r'}}, { XK_KP_3, {KS_TYPE_CHAR,'3'}, {KS_TYPE_APPKEY,'s'}}, { XK_KP_4, {KS_TYPE_CHAR,'4'}, {KS_TYPE_APPKEY,'t'}}, { XK_KP_5, {KS_TYPE_CHAR,'5'}, {KS_TYPE_APPKEY,'u'}}, { XK_KP_6, {KS_TYPE_CHAR,'6'}, {KS_TYPE_APPKEY,'v'}}, { XK_KP_7, {KS_TYPE_CHAR,'7'}, {KS_TYPE_APPKEY,'w'}}, { XK_KP_8, {KS_TYPE_CHAR,'8'}, {KS_TYPE_APPKEY,'x'}}, { XK_KP_9, {KS_TYPE_CHAR,'9'}, {KS_TYPE_APPKEY,'y'}}, { XK_KP_Add, {KS_TYPE_CHAR,'+'}, {KS_TYPE_APPKEY,'k'}}, { XK_KP_Subtract,{KS_TYPE_CHAR,'-'}, {KS_TYPE_APPKEY,'m'}}, { XK_KP_Multiply,{KS_TYPE_CHAR,'*'}, {KS_TYPE_APPKEY,'j'}}, { XK_KP_Divide, {KS_TYPE_CHAR,'/'}, {KS_TYPE_APPKEY,'o'}}, { XK_KP_Separator,{KS_TYPE_CHAR,','}, {KS_TYPE_APPKEY,'l'}}, { XK_KP_Decimal,{KS_TYPE_CHAR,'.'}, {KS_TYPE_APPKEY,'n'}}, { XK_KP_Enter, {KS_TYPE_CHAR,'\r'}, {KS_TYPE_APPKEY,'M'}}, { XK_KP_Space, {KS_TYPE_CHAR,' '}, {KS_TYPE_APPKEY,' '}}, { XK_KP_Tab, {KS_TYPE_CHAR,'\t'}, {KS_TYPE_APPKEY,'I'}}, {0, {KS_TYPE_NONE,0}, {KS_TYPE_NONE,0}} }; #ifdef __STDC__ static void push_xevent(struct xeventst *); static struct xeventst *pop_xevent(void); static unsigned char * get_keycode_value(struct keymapst *,KeySym,unsigned char *,int); static unsigned char *lookup_key(XEvent *,int *); static int get_com_char(int); static void push_com_char(int); #ifdef DEBUG static void show_token_args(struct tokenst *); static void show_hex_token_args(struct tokenst *); #endif /* DEBUG */ #else /* __STDC__ */ static void push_xevent(); static struct xeventst *pop_xevent(); static unsigned char * get_keycode_value(); static unsigned char *lookup_key(); static int get_com_char(); static void push_com_char(); #ifdef DEBUG static void show_token_args(); static void show_hex_token_args(); #endif /* DEBUG */ #endif /* __STDC__ */ /* Push a mini X event onto the queue */ static void push_xevent(xe) struct xeventst *xe; { xe->xe_next = xevent_start; xe->xe_prev = NULL; if (xe->xe_next != NULL) xe->xe_next->xe_prev = xe; else xevent_last = xe; } static struct xeventst * pop_xevent() { struct xeventst *xe; if (xevent_last == NULL) return(NULL); xe = xevent_last; xevent_last = xe->xe_prev; if (xevent_last != NULL) xevent_last->xe_next = NULL; else xevent_start = NULL; return(xe); } /* Initialise the command connection. This should be called after the X * server connection is established. */ void init_command(command,argv) char *command; char **argv; { /* Enable the delete window protocol. */ wm_del_win = XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,main_win,&wm_del_win,1); if ((comm_fd = run_command(command,argv)) < 0) { error("Quitting"); quit(1); } x_fd = XConnectionNumber(display); com_buf_next = com_buf_top = com_buf; com_stack_top = com_stack; } /* Set the current cursor keys mode. */ void set_cur_keys(mode) int mode; { app_cur_keys = (mode == HIGH); } /* Set the current keypad keys mode. */ void set_kp_keys(mode) int mode; { app_kp_keys = (mode == HIGH); } /* Enable or disable the use of Sun function key mapping. */ void set_sun_function_keys(value) int value; { sun_function_keys = value; } /* Look up function key keycode */ static unsigned char * get_keycode_value(keymaptable,keysym,buf,use_alternate) struct keymapst *keymaptable; KeySym keysym; unsigned char *buf; int use_alternate; { struct keymapst *km; struct keystringst *ks; for (km = keymaptable; km->km_keysym != 0; km++) { if (km->km_keysym == keysym) { ks = use_alternate ? &km->km_alt : &km->km_normal; switch (ks->ks_type) { case KS_TYPE_NONE: return NULL; case KS_TYPE_CHAR: sprintf((char *)buf,"%c",ks->ks_value); return buf; case KS_TYPE_XTERM: sprintf((char *)buf,"\033[%d~",ks->ks_value); return buf; case KS_TYPE_SUN: sprintf((char *)buf,"\033[%dz",ks->ks_value); return buf; case KS_TYPE_APPKEY: sprintf((char *)buf,"\033O%c",ks->ks_value); return buf; case KS_TYPE_NONAPP: sprintf((char *)buf,"\033[%c",ks->ks_value); return buf; } } } return NULL; } /* Convert the keypress event into a string. */ static unsigned char * lookup_key(ev,pcount) int *pcount; XEvent *ev; { KeySym keysym; int count; static unsigned char kbuf[KBUFSIZE]; unsigned char *s; unsigned char *str; count = XLookupString(&ev->xkey,kbuf,KBUFSIZE,&keysym,NULL); s = NULL; if (IsFunctionKey(keysym) || IsMiscFunctionKey(keysym) || keysym == XK_Next || keysym == XK_Prior) s = get_keycode_value(func_key_table,keysym,kbuf,sun_function_keys); else if (IsCursorKey(keysym) || IsPFKey(keysym)) s = get_keycode_value(other_key_table,keysym,kbuf,app_cur_keys); else s = get_keycode_value(kp_key_table,keysym,kbuf,app_kp_keys); if (s != NULL) { *pcount = strlen((char *)s); str = s; } else { str = kbuf; if ((ev->xkey.state & Mod1Mask) && (count == 1)) { if (is_eightbit()) { kbuf[0] |= 0200; *pcount = 1; } else { kbuf[1] = kbuf[0]; kbuf[0] = '\033'; *pcount = 2; } } else *pcount = count; } return (str); } /* Return the next input character after first passing any keyboard input * to the command. If flags & BUF_ONLY is true then only buffered characters are * returned and once the buffer is empty the special value GCC_NULL is * returned. If flags and GET_XEVENTS is true then GCC_NULL is returned * when an X event arrives. */ static int get_com_char(flags) int flags; { XEvent event; struct xeventst *xe; fd_set in_fdset, out_fdset; unsigned char *s; int count, sv; unsigned char mask = is_eightbit() ? 0xff : 0x7f; extern int errno; if (com_stack_top > com_stack) return(*--com_stack_top); if (com_buf_next < com_buf_top) return(*com_buf_next++ & mask); else if (flags & BUF_ONLY) return(GCC_NULL); for (;;) { FD_ZERO(&in_fdset); while (XPending(display) == 0) { if (FD_ISSET(x_fd,&in_fdset)) /* If we get to this point something is wrong * because there is X input available but no * events. Exit the program to avoid looping * forever. */ quit(0); FD_SET(comm_fd,&in_fdset); FD_SET(x_fd,&in_fdset); FD_ZERO(&out_fdset); if (send_count > 0) FD_SET(comm_fd,&out_fdset); do sv = select(fd_width,&in_fdset,&out_fdset,NULL,NULL); while (sv < 0 && errno == EINTR); if (sv < 0) { error("select failed"); quit(-1); } if (FD_ISSET(comm_fd,&out_fdset)) { count = send_count < 100 ? send_count : 100; count = write(comm_fd,send_nxt,count); if (count < 0) { error("failed to write to command"); quit(-1); } send_count -= count; send_nxt += count; } if (FD_ISSET(comm_fd,&in_fdset)) break; } if (FD_ISSET(comm_fd,&in_fdset)) break; XNextEvent(display,&event); if (event.type == KeyPress) { s = lookup_key(&event,&count); if (count != 0) send_string(s,count); } else if (event.type == ClientMessage) { if (event.xclient.format == 32 && event.xclient.data.l[0] == wm_del_win) quit(0); } else if (event.type == MappingNotify) { XRefreshKeyboardMapping(&event.xmapping); } else if (event.type == SelectionRequest) { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_window = event.xselectionrequest.owner; xe->xe_time = event.xselectionrequest.time; xe->xe_requestor = event.xselectionrequest.requestor; xe->xe_target = event.xselectionrequest.target; xe->xe_property = event.xselectionrequest.property; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else if (event.type == SelectionNotify) { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_time = event.xselection.time; xe->xe_requestor = event.xselection.requestor; xe->xe_property = event.xselection.property; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else if (event.type == FocusIn || event.type == FocusOut) { if (event.xfocus.mode != NotifyNormal) continue; switch (event.xfocus.detail) { case NotifyAncestor : case NotifyInferior : case NotifyNonlinear : break; default : continue; } xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_time = event.xselection.time; xe->xe_detail = event.xfocus.detail; push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } else { xe = (struct xeventst *)cmalloc(sizeof(struct xeventst)); xe->xe_type = event.type; xe->xe_window = event.xany.window; if (event.type == Expose || event.type == GraphicsExpose) { xe->xe_x = event.xexpose.x; xe->xe_y = event.xexpose.y; xe->xe_width = event.xexpose.width; xe->xe_height = event.xexpose.height; } else { xe->xe_time = event.xbutton.time; xe->xe_x = event.xbutton.x; xe->xe_y = event.xbutton.y; xe->xe_state = event.xbutton.state; xe->xe_button = event.xbutton.button; } push_xevent(xe); if (flags & GET_XEVENTS) return(GCC_NULL); } } count = read(comm_fd,com_buf,COM_BUF_SIZE); if (count <= 0) { if (errno == EWOULDBLOCK) { return(GCC_NULL); } else { return(EOF); } } com_buf_next = com_buf; com_buf_top = com_buf + count; return(*com_buf_next++ & mask); } /* Push an input character back into the input queue. */ static void push_com_char(c) int c; { if (com_stack_top < com_stack + COM_PUSH_MAX) *com_stack_top++ = c; } /* Send count characters directly to the command. */ void send_string(buf,count) unsigned char *buf; int count; { unsigned char *s; register unsigned char *s1, *s2; register int i; if (count == 0) return; if (send_count == 0) { if (send_buf != NULL) { free(send_buf); send_buf = NULL; } send_buf = (unsigned char *)cmalloc(count); s2 = send_buf; s1 = buf; for (i = 0; i < count; i++, s1++, s2++) *s2 = *s1; send_nxt = send_buf; send_count = count; } else { s = (unsigned char *)cmalloc(send_count + count); memcpy(s,send_nxt,send_count); s2 = s + send_count; s1 = buf; for (i = 0; i < count; i++, s1++, s2++) *s2 = *s1; free(send_buf); send_buf = send_nxt = s; send_count += count; } } /* Send printf formatted output to the command. Only used for small ammounts * of data. */ /*VARARGS1*/ void #ifdef __STDC__ cprintf(char *fmt,...) { va_list args; static unsigned char buf[1024]; va_start(args,fmt); #else cprintf(va_alist) va_dcl { char *fmt; va_list args; static unsigned char buf[1024]; va_start(args); fmt = va_arg(args,char *); #endif vsprintf((char *)buf,fmt,args); va_end(args); send_string(buf,strlen((char *)buf)); } /* Return an input token */ void get_token(tk) struct tokenst *tk; { int c, i, n; struct xeventst *xe; static unsigned int time1 = 0, time2 = 0; tk->tk_private = 0; tk->tk_type = TK_NULL; if ((xe = pop_xevent()) != NULL) { if (xe->xe_window == vt_win) tk->tk_region = SCREEN; else if (xe->xe_window == sb_win) tk->tk_region = SCROLLBAR; else if (xe->xe_window == main_win) tk->tk_region = MAINWIN; else tk->tk_region = -1; switch (xe->xe_type) { case EnterNotify : tk->tk_type = TK_ENTRY; tk->tk_arg[0] = 1; tk->tk_nargs = 1; break; case LeaveNotify : tk->tk_type = TK_ENTRY; tk->tk_arg[0] = 0; tk->tk_nargs = 1; break; case FocusIn : tk->tk_type = TK_FOCUS; tk->tk_arg[0] = 1; tk->tk_arg[1] = xe->xe_detail; tk->tk_nargs = 2; break; case FocusOut : tk->tk_type = TK_FOCUS; tk->tk_arg[0] = 0; tk->tk_arg[1] = xe->xe_detail; tk->tk_nargs = 2; break; case Expose : tk->tk_type = TK_EXPOSE; tk->tk_arg[0] = xe->xe_x; tk->tk_arg[1] = xe->xe_y; tk->tk_arg[2] = xe->xe_width; tk->tk_arg[3] = xe->xe_height; tk->tk_nargs = 4; break; case ConfigureNotify : tk->tk_type = TK_RESIZE; tk->tk_nargs = 0; break; case SelectionClear : tk->tk_type = TK_SELCLEAR; tk->tk_arg[0] = xe->xe_time; tk->tk_nargs = 1; break; case SelectionNotify : tk->tk_type = TK_SELNOTIFY; tk->tk_arg[0] = xe->xe_time; tk->tk_arg[1] = xe->xe_requestor; tk->tk_arg[2] = xe->xe_property; tk->tk_nargs = 3; break; case SelectionRequest : tk->tk_type = TK_SELREQUEST; tk->tk_arg[0] = xe->xe_time; tk->tk_arg[1] = xe->xe_requestor; tk->tk_arg[2] = xe->xe_target; tk->tk_arg[3] = xe->xe_property; tk->tk_nargs = 4; break; case ButtonPress : if (xe->xe_window == vt_win && xe->xe_state == ControlMask) { tk->tk_type = TK_SBSWITCH; tk->tk_nargs = 0; break; } if (xe->xe_window == vt_win && (xe->xe_state & ControlMask) == 0) { switch (xe->xe_button) { case Button1 : if (xe->xe_time - time2 < MP_INTERVAL) { time1 = 0; time2 = 0; tk->tk_type = TK_SELLINE; } else if (xe->xe_time - time1 < MP_INTERVAL) { time2 = xe->xe_time; tk->tk_type = TK_SELWORD; } else { time1 = xe->xe_time; tk->tk_type = TK_SELSTART; } break; case Button2 : tk->tk_type = TK_NULL; break; case Button3 : tk->tk_type = TK_SELEXTND; break; } tk->tk_arg[0] = xe->xe_x; tk->tk_arg[1] = xe->xe_y; tk->tk_nargs = 2; break; } if (xe->xe_window == sb_win) { if (xe->xe_button == Button2) { tk->tk_type = TK_SBGOTO; tk->tk_arg[0] = xe->xe_y; tk->tk_nargs = 1; } } break; case ButtonRelease : if (xe->xe_window == sb_win) { switch (xe->xe_button) { case Button1 : tk->tk_type = TK_SBUP; tk->tk_arg[0] = xe->xe_y; tk->tk_nargs = 1; break; case Button3 : tk->tk_type = TK_SBDOWN; tk->tk_arg[0] = xe->xe_y; tk->tk_nargs = 1; break; } } else if (xe->xe_window == vt_win && (xe->xe_state & ControlMask) == 0) { switch (xe->xe_button) { case Button1 : case Button3 : tk->tk_type = TK_SELECT; tk->tk_arg[0] = xe->xe_time; tk->tk_nargs = 1; break; case Button2 : tk->tk_type = TK_SELINSRT; tk->tk_arg[0] = xe->xe_time; tk->tk_arg[1] = xe->xe_x; tk->tk_arg[2] = xe->xe_y; tk->tk_nargs = 3; break; } } break; case MotionNotify : if (xe->xe_window == sb_win && (xe->xe_state & Button2Mask)) { Window root, child; int root_x, root_y, x, y; unsigned int mods; XQueryPointer(display,sb_win,&root,&child, &root_x,&root_y,&x,&y,&mods); if (mods & Button2Mask) { tk->tk_type = TK_SBGOTO; tk->tk_arg[0] = y; tk->tk_nargs = 1; } break; } if (xe->xe_window == vt_win && (xe->xe_state & Button1Mask) && !(xe->xe_state & ControlMask)) { tk->tk_type = TK_SELDRAG; tk->tk_arg[0] = xe->xe_x; tk->tk_arg[1] = xe->xe_y; tk->tk_nargs = 2; break; } break; } free((void *)xe); return; } if ((c = get_com_char(GET_XEVENTS)) == GCC_NULL) { tk->tk_type = TK_NULL; return; } if (c == EOF) { tk->tk_type = TK_EOF; return; } if (is_string_char(c)) { i = 0; tk->tk_nlcount = 0; do { tk->tk_string[i++] = c; c = get_com_char(1); if (c == '\n' && ++tk->tk_nlcount >= NLMAX) { tk->tk_nlcount--; break; } } while (is_string_char(c) && i < TKS_MAX); tk->tk_length = i; tk->tk_string[i] = 0; tk->tk_type = TK_STRING; if (c != GCC_NULL) push_com_char(c); } else if (c == ESC) { c = get_com_char(0); if (c == '[') { c = get_com_char(0); if (c >= '<' && c <= '?') { tk->tk_private = c; c = get_com_char(0); } /* read any numerical arguments */ i = 0; do { n = 0; while (c >= '0' && c <= '9') { n = n * 10 + c - '0'; c = get_com_char(0); } if (i < TK_MAX_ARGS) tk->tk_arg[i++] = n; if (c == ESC) push_com_char(c); if (c < ' ') return; if (c < '@') c = get_com_char(0); } while (c < '@' && c >= ' '); if (c == ESC) push_com_char(c); if (c < ' ') return; tk->tk_nargs = i; tk->tk_type = c; } else if (c == ']') { c = get_com_char(0); n = 0; while (c >= '0' && c <= '9') { n = n * 10 + c - '0'; c = get_com_char(0); } tk->tk_arg[0] = n; tk->tk_nargs = 1; c = get_com_char(0); i = 0; while ((c & 0177) >= ' ' && i < TKS_MAX) { if (c >= ' ') tk->tk_string[i++] = c; c = get_com_char(0); } tk->tk_length = i; tk->tk_string[i] = 0; tk->tk_type = TK_TXTPAR; } else if (c == '#' || c == '(' || c == ')') { tk->tk_type = c; c = get_com_char(0); tk->tk_arg[0] = c; tk->tk_nargs = 1; } else if (c == '7' || c == '8' || c == '=' || c == '>') { tk->tk_type = c; tk->tk_nargs = 0; } else { switch (c) { case 'D' : tk->tk_type = TK_IND; break; case 'E' : tk->tk_type = TK_NEL; break; case 'H' : tk->tk_type = TK_HTS; break; case 'M' : tk->tk_type = TK_RI; break; case 'N' : tk->tk_type = TK_SS2; break; case 'O' : tk->tk_type = TK_SS3; break; case 'Z' : tk->tk_type = TK_DECID; break; default : return; } } } else { tk->tk_type = TK_CHAR; tk->tk_char = c; } } #ifdef DEBUG /* Print out a token's numerical arguments. Just used by show_token() */ static void show_token_args(tk) struct tokenst *tk; { int i; for (i = 0; i < tk->tk_nargs; i++) { if (i == 0) printf(" (%d",tk->tk_arg[i]); else printf(",%d",tk->tk_arg[i]); } if (tk->tk_nargs > 0) printf(")"); if (tk->tk_private !=0) putchar(tk->tk_private); } /* Print out a token's numerical arguments in hex. Just used by show_token() */ static void show_hex_token_args(tk) struct tokenst *tk; { int i; for (i = 0; i < tk->tk_nargs; i++) { if (i == 0) printf(" (0x%x",tk->tk_arg[i]); else printf(",0x%x",tk->tk_arg[i]); } if (tk->tk_nargs > 0) printf(")"); if (tk->tk_private !=0) putchar(tk->tk_private); } /* Print out the contents of an input token - used for debugging. */ void show_token(tk) struct tokenst *tk; { /* Screen out token types that are not currently of interest. */ switch (tk->tk_type) { case TK_SELDRAG : return; } switch (tk->tk_type) { case TK_STRING : printf("token(TK_STRING)"); printf(" \"%s\"",tk->tk_string); break; case TK_TXTPAR : printf("token(TK_TXTPAR)"); printf(" (%d) \"%s\"",tk->tk_arg[0],tk->tk_string); break; case TK_CHAR : printf("token(TK_CHAR)"); printf(" <%o>",tk->tk_char); break; case TK_EOF : printf("token(TK_EOF)"); show_token_args(tk); break; case TK_FOCUS : printf("token(TK_FOCUS)"); printf(" <%d>",tk->tk_region); show_token_args(tk); break; case TK_ENTRY : printf("token(TK_ENTRY)"); printf(" <%d>",tk->tk_region); show_token_args(tk); break; case TK_SBSWITCH : printf("token(TK_SBSWITCH)"); show_token_args(tk); break; case TK_SBGOTO : printf("token(TK_SBGOTO)"); show_token_args(tk); break; case TK_SBUP : printf("token(TK_SBUP)"); show_token_args(tk); break; case TK_SBDOWN : printf("token(TK_SBDOWN)"); show_token_args(tk); break; case TK_EXPOSE : printf("token(TK_EXPOSE)"); printf("(%d)",tk->tk_region); show_token_args(tk); break; case TK_RESIZE : printf("token(TK_RESIZE)"); show_token_args(tk); break; case TK_SELSTART : printf("token(TK_SELSTART)"); show_token_args(tk); break; case TK_SELEXTND : printf("token(TK_SELEXTND)"); show_token_args(tk); break; case TK_SELDRAG : printf("token(TK_SELDRAG)"); show_token_args(tk); break; case TK_SELINSRT : printf("token(TK_SELINSRT)"); show_token_args(tk); break; case TK_SELECT : printf("token(TK_SELECT)"); show_token_args(tk); break; case TK_SELWORD : printf("token(TK_SELWORD)"); show_token_args(tk); break; case TK_SELLINE : printf("token(TK_SELLINE)"); show_token_args(tk); break; case TK_SELCLEAR : printf("token(TK_SELCLEAR)"); show_token_args(tk); break; case TK_SELNOTIFY : printf("token(TK_SELNOTIFY)"); show_hex_token_args(tk); break; case TK_SELREQUEST : printf("token(TK_SELREQUEST)"); show_hex_token_args(tk); break; case TK_CUU : printf("token(TK_CUU)"); show_token_args(tk); break; case TK_CUD : printf("token(TK_CUD)"); show_token_args(tk); break; case TK_CUF : printf("token(TK_CUF)"); show_token_args(tk); break; case TK_CUB : printf("token(TK_CUB)"); show_token_args(tk); break; case TK_CUP : printf("token(TK_CUP)"); show_token_args(tk); break; case TK_ED : printf("token(TK_ED)"); show_token_args(tk); break; case TK_EL : printf("token(TK_EL)"); show_token_args(tk); break; case TK_IL : printf("token(TK_IL)"); show_token_args(tk); break; case TK_DL : printf("token(TK_DL)"); show_token_args(tk); break; case TK_DCH : printf("token(TK_DCH)"); show_token_args(tk); break; case TK_ICH : printf("token(TK_ICH)"); show_token_args(tk); break; case TK_DA : printf("token(TK_DA)"); show_token_args(tk); break; case TK_HVP : printf("token(TK_HVP)"); show_token_args(tk); break; case TK_TBC : printf("token(TK_TBC)"); show_token_args(tk); break; case TK_SET : printf("token(TK_SET)"); show_token_args(tk); break; case TK_RESET : printf("token(TK_RESET)"); show_token_args(tk); break; case TK_SGR : printf("token(TK_SGR)"); show_token_args(tk); break; case TK_DSR : printf("token(TK_DSR)"); show_token_args(tk); break; case TK_DECSTBM : printf("token(TK_DECSTBM)"); show_token_args(tk); break; case TK_DECSWH : printf("token(TK_DECSWH)"); show_token_args(tk); break; case TK_SCS0 : printf("token(TK_SCS0)"); show_token_args(tk); break; case TK_SCS1 : printf("token(TK_SCS1)"); show_token_args(tk); break; case TK_DECSC : printf("token(TK_DECSC)"); show_token_args(tk); break; case TK_DECRC : printf("token(TK_DECRC)"); show_token_args(tk); break; case TK_DECPAM : printf("token(TK_DECPAM)"); show_token_args(tk); break; case TK_DECPNM : printf("token(TK_DECPNM)"); show_token_args(tk); break; case TK_IND : printf("token(TK_IND)"); show_token_args(tk); break; case TK_NEL : printf("token(TK_NEL)"); show_token_args(tk); break; case TK_HTS : printf("token(TK_HTS)"); show_token_args(tk); break; case TK_RI : printf("token(TK_RI)"); show_token_args(tk); break; case TK_SS2 : printf("token(TK_SS2)"); show_token_args(tk); break; case TK_SS3 : printf("token(TK_SS3)"); show_token_args(tk); break; case TK_DECID : printf("token(TK_DECID)"); show_token_args(tk); break; case TK_NULL : return; default : printf("unknown token <%o>",tk->tk_type); show_token_args(tk); break; } printf("\n"); } #endif /* DEBUG */ xvt-2.1.orig/command.h100644 765 765 4524 6410001634 12657 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)command.h 1.2 16/11/93 (UKC) */ #define TKS_MAX 5000 /* max length of a string token */ #define TK_MAX_ARGS 200 /* max number of numerical arguments */ /* Structure used to represent a piece of input from the program * or an interesting X event. */ struct tokenst { int tk_type; /* the token type */ int tk_private; /* non zero for private control sequences */ int tk_char; /* single (unprintable) character */ unsigned char tk_string[TKS_MAX + 1];/* the text for string tokens */ int tk_nlcount; /* number of newlines in the string */ int tk_length; /* length of string */ int tk_arg[TK_MAX_ARGS];/* first two numerical arguments */ int tk_nargs; /* number of numerical arguments */ int tk_region; /* terminal or scrollbar */ }; #ifdef __STDC__ void init_command(char *,char **); void set_cur_keys(int); void set_kp_keys(int); void set_sun_function_keys(int); void send_string(unsigned char *,int); void cprintf(char *,...); void get_token(struct tokenst *); void show_token(struct tokenst *); #else /* __STDC__ */ void init_command(); void set_cur_keys(); void set_kp_keys(); void set_sun_function_keys(); void send_string(); void cprintf(); void get_token(); void show_token(); #endif /* __STDC__ */ xvt-2.1.orig/sbar.c100644 765 765 6632 6410001655 12170 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_sbar_c_sccsid[] = "@(#)sbar.c 1.2 16/11/93 (UKC)"; #include #include #include #include #include "xvt.h" #include "xsetup.h" #include "command.h" #include "ttyinit.h" #include "sbar.h" /* External global variables that are initialised at startup. */ extern Display *display; extern Window sb_win; /* scroll bar window */ extern GC sbgc; static unsigned int width; /* scrollbar width */ static unsigned int height; /* scrollbar height */ static int mtop; /* top of marked area */ static int mbot; /* bottom of marked area */ /* Most recent arguments to sbar_show */ static int last_length = 100; /* initial values to give a full bar */ static int last_low = 0; static int last_high = 100; static unsigned char stipple_bits[] = { 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, }; /* Initialise scrollbar data structures - called just once. */ void sbar_init() { Pixmap stipple; XGCValues gcv; stipple = XCreateBitmapFromData(display,sb_win,stipple_bits,16,16); if (stipple == 0) { error("Cannot create scrollbar bitmap"); quit(1); } gcv.fill_style = FillOpaqueStippled; gcv.stipple = stipple; XChangeGC(display,sbgc,GCFillStyle|GCStipple,&gcv); sbar_reset(); } /* Redraw the scrollbar after a size change */ void sbar_reset() { Window root; int x, y; unsigned int border_width, depth; XGetGeometry(display,sb_win,&root,&x,&y,&width,&height,&border_width,&depth); mbot = -1; /* force a redraw */ sbar_show(last_length,last_low,last_high); } /* Redraw the scrollbar to show the area from low to high proportional to length. */ void sbar_show(length,low,high) int length, low, high; { int top, bot; if (length == 0) return; last_length = length; last_low = low; last_high = high; top = height - 1 - height * high / length; bot = height - 1 - height * low / length; if (top == mtop && bot == mbot) return; if (top > 0) XClearArea(display,sb_win,0,0,width,top - 1,False); if (bot >= top) XFillRectangle(display,sb_win,sbgc,0,top,width,bot - top + 1); if (bot < height - 1) XClearArea(display,sb_win,0,bot + 1,width,height - bot - 1,False); } xvt-2.1.orig/sbar.h100644 765 765 2543 6410001674 12173 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)sbar.h 1.2 16/11/93 (UKC) */ #ifdef __STDC__ void sbar_init(void); void sbar_reset(void); void sbar_show(int,int,int); #else /* __STDC__ */ void sbar_init(); void sbar_reset(); void sbar_show(); #endif /* __STDC__ */ xvt-2.1.orig/screen.c100644 765 765 160142 6410001705 12551 0ustar cpb4cpb4/* Copyright 1992, 1994 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_screen_c_sccsid[] = "@(#)screen.c 1.6 11/1/94 (UKC)"; #include #include #include #include #include #include #include #include #include #include #include #include "xvt.h" #include "screen.h" #include "command.h" #include "ttyinit.h" #include "xsetup.h" #include "sbar.h" /* Structure describing the current state of the screen. */ struct screenst { unsigned char **text; /* backup copy of screen->text */ unsigned char **rend; /* character rendition styles etc. */ int row; /* cursor position */ int col; /* ditto */ int tmargin; /* top scroll margin */ int bmargin; /* bottom scroll margin */ int decom; /* origin mode flag */ int wrap; /* auto-wrap flag */ int wrap_next; /* wrap before the next printed character */ int insert; /* insert mode flag */ }; /* structure describing a saved line */ struct slinest { unsigned char *sl_text; /* the text of the line */ unsigned char *sl_rend; /* the rendition style */ int sl_length; /* length of the line */ }; /* selection endpoint types. */ enum seltype { SCREEN, SAVED, NOSEL }; /* structure describing a selection endpoint. */ struct selst { enum seltype se_type; int se_index; /* index into the sline or screen array */ int se_col; /* column of the character */ }; #ifdef __STDC__ static void repair_damage(void); static Bool grexornoex(Display *,XEvent *,char *); static Bool sel_pred(Display *,XEvent *,char *); static void send_selection(unsigned char *,int); static void wait_for_selection(Time); static void change_offset(int); static void paint_rval_text(unsigned char *,int,int,int,int); static void paint_rvec_text(unsigned char *,unsigned char *,int,int,int); static void refresh(int,int,int,int); static void show_selection(int,int,int,int); static void scroll(int,int,int); static void scroll1(int); static void home_screen(void); static void cursor(void); static void rc_to_selend(int,int,struct selst *); static void fix_rc(int *,int *); static void selend_to_rc(int *,int *,struct selst *); static void change_selection(struct selst *,struct selst *); static unsigned char *convert_line(unsigned char *,int *,int,int); static int selcmp(struct selst *,struct selst *); static void adjust_selection(struct selst *); static int save_selection(void); static void check_selection(int,int); static int cclass(int); #else /* __STDC__ */ static void repair_damage(); static Bool grexornoex(); static Bool sel_pred(); static void send_selection(); static void wait_for_selection(); static void change_offset(); static void paint_rval_text(); static void paint_rvec_text(); static void refresh(); static void show_selection(); static void scroll(); static void scroll1(); static void home_screen(); static void cursor(); static void rc_to_selend(); static void fix_rc(); static void selend_to_rc(); static void change_selection(); static unsigned char *convert_line(); static int selcmp(); static void adjust_selection(); static int save_selection(); static void check_selection(); static int cclass(); #endif /* __STDC__ */ #define MAX_WIDTH 250 /* max width of selected lines */ #define PROP_SIZE 1024 /* chunk size for retrieving the selection property */ #define SEL_KEY_DEL 2000 /* time delay in allowing keyboard input to be accepted before a selection arrives. */ #define POUND 036 /* ascii value representing a pound in at least some fonts */ /* Character classes used when selecting words with a double click. */ static int char_class[256] = { 32, 1, 1, 1, 1, 1, 1, 1, 1, 32, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 58, 59, 60, 61, 62, 63, 64, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 91, 92, 93, 94, 48, 96, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 123, 124, 125, 126, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; /* External global variables that are initialised at startup. */ extern Display *display; extern Window vt_win; extern Window main_win; extern Colormap colormap; extern XFontStruct *mainfont; /* main font structure */ extern XFontStruct *boldfont; /* bold font structure */ extern GC txgc; /* GC for drawing text */ extern GC negc; /* GC without graphics exposures */ extern GC hlgc; /* GC used for highlighting selection */ extern GC cugc; /* GC used for the text cursor */ extern unsigned long foreground; /* foreground pixel value */ extern unsigned long background; /* background pixel value */ extern int reverse_wrap; /* reverse wrap allowed */ static struct selst selend1, selend2; /* the selection endpoints */ static struct selst selanchor; /* the selection anchor */ static unsigned char *selection_text = NULL; /* text version of the current selection */ static int selection_length; /* length of selection text */ static enum selunit selection_unit; /* current unit of selection */ /* Screen state variables that are the same for both screens. */ static int pwidth; /* width in pixels */ static int pheight; /* height in pixels */ static int cwidth = 0; /* width in characters */ static int cheight = 0; /* height in characters */ static int focus = 0; /* window has the keyboard focus */ static int rstyle; /* rendition style and current character flags */ static int gg[2]; /* character set Gn */ static int cset; /* which character set is currently active */ static int save_rstyle; /* when it needs to be saved */ /* screen state variables */ static struct screenst screen1; /* main screen */ static struct screenst screen2; /* second screen */ static struct screenst *screen = NULL; /* current of screen1 and screen2 */ static struct screenst save_screen; static int sline_top; /* high water mark of saved scrolled lines */ static int sline_max; /* Max number of saved lines */ static struct slinest **sline; /* main array of saved lines */ static int offset = 0; /* current vertical offset for displaying saved lines */ static int fheight; /* height of a character in the font */ static int fwidth; /* width of a font character */ /* Perform any initialisation on the screen data structures. Called just once * at startup. saved_lines is the number of saved lines. */ void scr_init(saved_lines) int saved_lines; { int i; /* Initialise the array of lines that have scrolled of the top. */ sline_max = saved_lines; if (sline_max < MAX_SCROLL) sline_max = MAX_SCROLL; sline = (struct slinest **)cmalloc(sline_max * sizeof(struct slinest *)); for (i = 0; i < sline_max; i++) sline[i] = NULL; sline_top = 0; screen1.text = NULL; screen1.rend = NULL; screen1.row = 0; screen1.col = 0; screen1.wrap = 1; screen1.decom = 0; screen1.insert = 0; screen2.text = NULL; screen2.rend = NULL; screen2.row = 0; screen2.col = 0; screen2.wrap = 1; screen2.decom = 0; screen2.insert = 0; save_screen.row = 0; save_screen.col = 0; screen = &screen1; rstyle = 0; gg[0] = CS_USASCII; gg[1] = CS_USASCII; cset = 0; fwidth = XTextWidth(mainfont,"M",1); fheight = mainfont->ascent + mainfont->descent; scr_reset(); } /* Reset the screen - called whenever the screen needs to be repaired completely. */ void scr_reset() { Window root; int x, y, n, i, j, onscreen; unsigned int width, height, border_width, depth; int cw, ch; unsigned char **r1, **r2, **s1, **s2; struct slinest *sl; XGetGeometry(display,vt_win,&root,&x,&y,&width,&height,&border_width,&depth); cw = (width - 2 * MARGIN) / fwidth; ch = (height - 2 * MARGIN) / fheight; if (screen->text == NULL || cw != cwidth || ch != cheight) { offset = 0; /* Recreate the screen backup arrays. * The screen arrays are one byte wider than the screen and * the last byte is used as a flag which is non-zero of the * line wrapped automatically. */ s1 = (unsigned char **)cmalloc(ch * sizeof(unsigned char *)); s2 = (unsigned char **)cmalloc(ch * sizeof(unsigned char *)); r1 = (unsigned char **)cmalloc(ch * sizeof(unsigned char *)); r2 = (unsigned char **)cmalloc(ch * sizeof(unsigned char *)); for (y = 0; y < ch; y++) { s1[y] = (unsigned char *)cmalloc(cw + 1); s2[y] = (unsigned char *)cmalloc(cw + 1); r1[y] = (unsigned char *)cmalloc(cw + 1); r2[y] = (unsigned char *)cmalloc(cw + 1); memset(s1[y],0,cw + 1); memset(s2[y],0,cw + 1); memset(r1[y],0,cw + 1); memset(r2[y],0,cw + 1); } if (screen1.text != NULL) { /* Now fill up the screen from the old screen and saved lines. */ if (screen1.row >= ch) { /* scroll up to save any lines that will be lost. */ scroll1(screen1.row - ch + 1); screen1.row = ch - 1; } /* calculate working no. of lines. */ i = sline_top + screen1.row + 1; j = i > ch ? ch - 1 : i - 1; i = screen1.row; screen1.row = j; onscreen = 1; for (; j >= 0; j--) { if (onscreen) { n = cw < cwidth ? cw : cwidth; memcpy(s1[j],screen1.text[i],n); memcpy(s2[j],screen2.text[i],n); memcpy(r1[j],screen1.rend[i],n); memcpy(r2[j],screen2.rend[i],n); s1[j][cw] = screen1.text[i][cwidth]; s2[j][cw] = screen2.text[i][cwidth]; r1[j][cw] = screen1.rend[i][cwidth]; r2[j][cw] = screen2.rend[i][cwidth]; i--; if (i < 0) { onscreen = 0; i = 0; } } else { if (i >= sline_top) break; sl = sline[i]; n = cw < sl->sl_length ? cw : sl->sl_length; memcpy(s1[j],sl->sl_text,n); free(sl->sl_text); if (sl->sl_rend != NULL) { memcpy(r1[j],sl->sl_rend,n); r1[j][cw] = sl->sl_rend[sl->sl_length]; free(sl->sl_rend); } free((void *)sl); i++; } } if (onscreen) abort(); for (j = i; j < sline_top; j++) sline[j - i] = sline[j]; for (j = sline_top - i; j < sline_top; j++) sline[j] = NULL; sline_top -= i; for (y = 0; y < cheight; y++) { free(screen1.text[y]); free(screen2.text[y]); free(screen1.rend[y]); free(screen2.rend[y]); } free((void *)screen1.text); free((void *)screen2.text); free((void *)screen1.rend); free((void *)screen2.rend); } screen1.text = s1; screen2.text = s2; screen1.rend = r1; screen2.rend = r2; cwidth = cw; cheight = ch; pwidth = width; pheight = height; screen1.tmargin = 0; screen1.bmargin = cheight - 1; screen1.decom = 0; screen1.wrap_next = 0; screen2.tmargin = 0; screen2.bmargin = cheight - 1; screen2.decom = 0; screen2.wrap_next = 0; scr_start_selection(0,0,CHAR); } tty_set_size(cwidth,cheight); if (screen->col >= cwidth) screen->col = cwidth - 1; if (screen->row >= cheight) screen->row = cheight - 1; sbar_show(cheight + sline_top - 1, offset, offset + cheight - 1); refresh(0,cheight - 1,0,cwidth - 1); cursor(); } /* Refresh the reagion of the screen delimited by the aruments. Used to * repair after minor exposure events. */ void scr_refresh(x,y,width,height) int x, y, width, height; { int row1, row2, col1, col2; col1 = (x - MARGIN) / fwidth; col2 = (x + width - MARGIN + fwidth - 1) / fwidth - 1; if (col1 < 0) col1 = 0; if (col1 >= cwidth) col1 = cwidth - 1; if (col2 < 0) col2 = 0; if (col2 >= cwidth) col2 = cwidth - 1; row1 = (y - MARGIN) / fheight; row2 = (y + height - MARGIN + fheight - 1) / fheight - 1; if (row1 < 0) row1 = 0; if (row1 >= cheight) row1 = cheight - 1; if (row2 < 0) row2 = 0; if (row2 >= cheight) row2 = cheight - 1; refresh(row1,row2,col1,col2); if (screen->row >= row1 && screen->row <= row2 && screen->col >= col1 && screen->col <= col2) cursor(); } /* Parse the string as a sequence of character classes and use it to * modify the char_class table. */ void scr_char_class(s) unsigned char *s; { int first, last, value, i; while (isdigit(*s)) { first = last = value = 0; while (isdigit(*s)) { first = first * 10 + *s - '0'; s++; } if (*s == '-') { s++; while (isdigit(*s)) { last = last * 10 + *s - '0'; s++; } } else last = first; if (*s == ':') s++; while (isdigit(*s)) { value = value * 10 + *s - '0'; s++; } if (*s == ',') s++; if (last > 255) last = 255; for (i = first; i <= last; i++) char_class[i] = value; } } /* Handle a backspace */ void scr_backspace() { if (screen->col == 0 && reverse_wrap && screen->row > 0) { cursor(); screen->row--; screen->col = cwidth - 1; cursor(); } else if (screen->wrap_next && reverse_wrap) screen->wrap_next = 0; else scr_move(-1,0,COL_RELATIVE|ROW_RELATIVE); } /* Ring the bell */ void scr_bell() { XBell(display,0); } /* Change between the alternate and the main screens */ void scr_change_screen(direction) int direction; { home_screen(); screen = (direction == HIGH) ? &screen2 : &screen1; selend2.se_type = NOSEL; refresh(0,cheight - 1,0,cwidth - 1); cursor(); } /* Change the rendition style. */ void scr_change_rendition(style) int style; { if (style == 0) rstyle &= ~RS_STYLE; else rstyle |= style; } /* Set character class set to style. */ void scr_set_char_set(set,style) int set, style; { gg[set] = style; if (cset == set) rstyle = (rstyle & ~CS_STYLE) | style; } /* Set which character set we are using. */ void scr_shift(set) int set; { cset = set; rstyle = (rstyle & ~CS_STYLE) | gg[cset]; } /* Return the width and height of the screen. */ void scr_get_size(width_p,height_p) int *width_p, *height_p; { *width_p = cwidth; *height_p = cheight; } /* Indicate a change of keyboard focus. type is 1 for entry events and 2 for * focus events. */ void scr_focus(type,is_in) int type,is_in; { cursor(); if (is_in) focus |= type; else focus &= ~type; cursor(); } /* Display the string at the current position. nlcount is the number of new lines * in the string. */ void scr_string(str,len,nlcount) unsigned char *str; int len, nlcount; { int x, x2, y, n, i; unsigned int width; unsigned char *s, *r; home_screen(); cursor(); if (nlcount > 0) { if (screen->row > screen->bmargin) nlcount = 0; else nlcount -= screen->bmargin - screen->row; if (nlcount < 0) nlcount = 0; else if (nlcount > screen->row - screen->tmargin) nlcount = screen->row - screen->tmargin; if (nlcount > MAX_SCROLL) nlcount = MAX_SCROLL; scroll(screen->tmargin,screen->bmargin,nlcount); screen->row -= nlcount; } while (len > 0) { if (*str == '\n') { if (screen->row == screen->bmargin) scroll(screen->tmargin,screen->bmargin,1); else if (screen->row < cheight - 1) screen->row++; check_selection(screen->row,screen->row); screen->wrap_next = 0; len--; str++; continue; } if (*str == '\r') { screen->col = 0; screen->wrap_next = 0; len--; str++; continue; } if (*str == '\t') { if (screen->col < cwidth - 1) { s = screen->text[screen->row]; if (s[screen->col] == 0) s[screen->col] = '\t'; screen->col++; while (screen->col % 8 != 0 && screen->col < cwidth - 1) screen->col++; } len--; str++; continue; } if (screen->wrap_next) { screen->text[screen->row][cwidth] = 1; if (screen->row == screen->bmargin) scroll(screen->tmargin,screen->bmargin,1); else if (screen->row < cheight - 1) screen->row++; screen->col = 0; screen->wrap_next = 0; } check_selection(screen->row,screen->row); x = MARGIN + fwidth * screen->col; y = MARGIN + fheight * screen->row; for (n = 0; str[n] >= ' '; n++) ; n = n + screen->col > cwidth ? cwidth - screen->col : n; if (screen->insert) { s = screen->text[screen->row]; r = screen->rend[screen->row]; for (i = cwidth - 1; i >= screen->col + n; i--) { s[i] = s[i - n]; r[i] = r[i - n]; } width = (cwidth - screen->col - n) * fwidth; x2 = x + n * fwidth; if (width > 0) { XCopyArea(display,vt_win,vt_win,txgc,x,y,width,fheight,x2,y); repair_damage(); } } paint_rval_text(str,rstyle,n,x,y); memcpy(screen->text[screen->row] + screen->col,str,n); if (rstyle == 0) memset(screen->rend[screen->row] + screen->col,0,n); else { for (i = 0; i < n; i++) screen->rend[screen->row][screen->col + i] = rstyle; screen->rend[screen->row][cwidth] = 1; } len -= n; str += n; screen->col += n; if (len > 0 && screen->col == cwidth && *str >= ' ') { if (screen->wrap) { screen->text[screen->row][cwidth] = 1; if (screen->row == screen->bmargin) scroll(screen->tmargin,screen->bmargin,1); else screen->row++; screen->col = 0; } else { screen->col = cwidth - 1; cursor(); return; } } } if (screen->col == cwidth) { screen->col = cwidth - 1; screen->wrap_next = screen->wrap; } cursor(); } /* Return true if the character is one that can be handled by scr_string() */ int is_string_char(c) int c; { c &= 0177; return(c >= ' ' || c == '\n' || c == '\r' || c == '\t'); } /* Move the cursor to a new position. The relative argument is a pair of * flags that specify relative rather than absolute motion. */ void scr_move(x,y,relative) int x, y, relative; { home_screen(); cursor(); screen->col = (relative & COL_RELATIVE) ? screen->col + x : x; if (screen->col < 0) screen->col = 0; if (screen->col >= cwidth) screen->col = cwidth - 1; if (relative & ROW_RELATIVE) { if (y > 0) { if (screen->row <= screen->bmargin && screen->row + y > screen->bmargin) screen->row = screen->bmargin; else screen->row += y; } else if (y < 0) { if (screen->row >= screen->tmargin && screen->row + y < screen->tmargin) screen->row = screen->tmargin; else screen->row += y; } } else { if (screen->decom) { screen->row = y + screen->tmargin; if (screen->row > screen->bmargin) screen->row = screen->bmargin; } else screen->row = y; } if (screen->row < 0) screen->row = 0; if (screen->row >= cheight) screen->row = cheight - 1; screen->wrap_next = 0; check_selection(screen->row,screen->row); cursor(); } /* Move the cursor down one line and scroll if necessary. */ void scr_index() { home_screen(); cursor(); if (screen->row == screen->bmargin) scroll(screen->tmargin,screen->bmargin,1); else screen->row++; screen->wrap_next = 0; check_selection(screen->row,screen->row); cursor(); } /* Move the cursor up one line and scroll if necessary. */ void scr_rindex() { home_screen(); cursor(); if (screen->row == screen->tmargin) scroll(screen->tmargin,screen->bmargin,-1); else screen->row--; screen->wrap_next = 0; check_selection(screen->row,screen->row); cursor(); } /* Save the cursor position and rendition style. */ void scr_save_cursor() { save_screen.row = screen->row; save_screen.col = screen->col; save_rstyle = rstyle; } /* Restore the cursor position and rendition style. */ void scr_restore_cursor() { cursor(); screen->row = save_screen.row; if (screen->row >= cheight) screen->row = cheight - 1; screen->col = save_screen.col; if (screen->col >= cwidth) screen->col = cwidth - 1; scr_change_rendition(save_rstyle); cursor(); } /* erase part or the whole of a line */ void scr_erase_line(mode) int mode; { int i, x, y, width, height; unsigned char *r, *s; home_screen(); y = MARGIN + screen->row * fheight; height = fheight; s = screen->text[screen->row]; r = screen->rend[screen->row]; switch (mode) { case START : x = MARGIN; width = (screen->col + 1) * fwidth; memset(s,0,screen->col + 1); memset(r,0,screen->col + 1); break; case END : x = MARGIN + screen->col * fwidth; width = (cwidth - screen->col) * fwidth; memset(s + screen->col,0,cwidth - screen->col + 1); memset(r + screen->col,0,cwidth - screen->col); break; case ENTIRE : x = MARGIN; width = cwidth * fwidth; memset(s,0,cwidth + 1); memset(r,0,cwidth); break; default : return; } /* patch in the final rendition flag if there is any non-zero * rendition. */ r[cwidth] = 0; for (i = 0; i < cwidth; i++) if (r[i] != 0) { r[cwidth] = 1; break; } cursor(); check_selection(screen->row,screen->row); XClearArea(display,vt_win,x,y,width,height,False); screen->wrap_next = 0; cursor(); } /* erase part or the whole of the screen */ void scr_erase_screen(mode) int mode; { int x, y, width, height; int i; home_screen(); screen->wrap_next = 0; x = MARGIN; width = fwidth * cwidth; switch (mode) { case START : y = MARGIN; height = screen->row * fheight; for (i = 0; i < screen->row; i++) { memset(screen->text[i],0,cwidth + 1); memset(screen->rend[i],0,cwidth + 1); } check_selection(0,screen->row - 1); if (height > 0) XClearArea(display,vt_win,x,y,width,height,False); scr_erase_line(mode); break; case END : if (screen->row != 0 || screen->col != 0) { y = MARGIN + (screen->row + 1) * fheight; height = (cheight - screen->row - 1) * fheight; for (i = screen->row + 1; i < cheight; i++) { memset(screen->text[i],0,cwidth + 1); memset(screen->rend[i],0,cwidth + 1); } check_selection(screen->row + 1,cheight - 1); if (height > 0) XClearArea(display,vt_win,x,y,width,height,False); scr_erase_line(mode); break; } /* If we are positioned at the top left hand corner then * it is effectively a whole screen clear. * Drop through so that we do not need to duplicate * the scroll-up code. */ case ENTIRE : y = MARGIN; height = cheight * fheight; if (screen == &screen1) scroll1(cheight); else for (i = 0; i < cheight; i++) { memset(screen->text[i],0,cwidth + 1); memset(screen->rend[i],0,cwidth + 1); } cursor(); check_selection(0,cheight - 1); XClearArea(display,vt_win,x,y,width,height,False); cursor(); sbar_show(cheight + sline_top - 1, 0, cheight - 1); break; default : return; } } /* Delete count lines and scroll up the bottom of the screen to fill the gap */ void scr_delete_lines(count) int count; { if (count > screen->bmargin - screen->row + 1) return; home_screen(); cursor(); while (count > MAX_SCROLL) { scroll(screen->row,screen->bmargin,MAX_SCROLL); count -= MAX_SCROLL; } scroll(screen->row,screen->bmargin,count); screen->wrap_next = 0; cursor(); } /* Insert count blank lines at the current position and scroll the lower lines * down. */ void scr_insert_lines(count) int count; { if (screen->row > screen->bmargin) return; if (count > screen->bmargin - screen->row + 1) count = screen->bmargin - screen->row + 1; home_screen(); cursor(); while (count > MAX_SCROLL) { scroll(screen->row,screen->bmargin,-MAX_SCROLL); count -= MAX_SCROLL; } scroll(screen->row,screen->bmargin,-count); screen->wrap_next = 0; cursor(); } /* Delete count characters from the current position. */ void scr_delete_characters(count) int count; { int x1, x2, y, width, i; unsigned char *r, *s; if (count > cwidth - screen->col) count = cwidth - screen->col; if (count <= 0) return; home_screen(); cursor(); check_selection(screen->row,screen->row); s = screen->text[screen->row]; r = screen->rend[screen->row]; for (i = screen->col + count; i < cwidth; i++) { s[i - count] = s[i]; r[i - count] = r[i]; } memset(s + cwidth - count,0,count); memset(r + cwidth - count,0,count); y = MARGIN + screen->row * fheight; x2 = MARGIN + screen->col * fwidth; x1 = x2 + count * fwidth; width = (cwidth - count - screen->col) * fwidth; if (width > 0) { XCopyArea(display,vt_win,vt_win,txgc,x1,y,width,fheight,x2,y); repair_damage(); } x1 = x2 + width; width = count * fwidth; XClearArea(display,vt_win,x1,y,width,fheight,False); screen->wrap_next = 0; cursor(); } /* Insert count spaces from the current position. */ void scr_insert_characters(count) int count; { int x1, x2, y, width, i; unsigned char *r, *s; if (count > cwidth - screen->col) count = cwidth - screen->col; if (count <= 0) return; home_screen(); cursor(); check_selection(screen->row,screen->row); s = screen->text[screen->row]; r = screen->rend[screen->row]; for (i = cwidth - 1; i >= screen->col + count; i--) { s[i] = s[i - count]; r[i] = r[i - count]; } memset(s + screen->col,0,count); memset(r + screen->col,0,count); y = MARGIN + screen->row * fheight; x1 = MARGIN + screen->col * fwidth; x2 = x1 + count * fwidth; width = (cwidth - count - screen->col) * fwidth; if (width > 0) XCopyArea(display,vt_win,vt_win,negc,x1,y,width,fheight,x2,y); x1 = MARGIN + screen->col * fwidth; width = count * fwidth; XClearArea(display,vt_win,x1,y,width,fheight,False); screen->wrap_next = 0; cursor(); } /* Tab to the next tab_stop. */ void scr_tab() { home_screen(); if (screen->col == cwidth - 1) return; cursor(); check_selection(screen->row,screen->row); if (screen->text[screen->row][screen->col] == 0) screen->text[screen->row][screen->col] = '\t'; screen->col++; while (screen->col % 8 != 0 && screen->col < cwidth - 1) screen->col++; cursor(); } /* Attempt to set the top ans bottom scroll margins. */ void scr_set_margins(top,bottom) int top, bottom; { if (top < 0) top = 0; if (bottom >= cheight) bottom = cheight - 1; if (top > bottom) return; screen->tmargin = top; screen->bmargin = bottom; scr_move(0,0,0); } /* Set or unset automatic wrapping. */ void scr_set_wrap(mode) int mode; { screen->wrap = mode == HIGH; } /* Set or unset margin origin mode. */ void scr_set_decom(mode) int mode; { screen->decom = mode == HIGH; scr_move(0,0,0); } /* Set or unset automatic insert mode. */ void scr_set_insert(mode) int mode; { screen->insert = mode == HIGH; } /* Fill the screen with 'E's - useful for testing. */ void scr_efill() { int x, y; for (y = 0; y < cheight; y++) for (x = 0; x < cwidth; x++) { screen->text[y][x] = 'E'; screen->rend[y][x] = 0; } home_screen(); check_selection(0,cheight - 1); refresh(0,cheight - 1,0,cwidth - 1); cursor(); } /* Move the display so that line represented by scrollbar value y is at the top * of the screen. */ void scr_move_to(y) int y; { int n, lnum; y = pheight - 1 - y; lnum = y * (cheight + sline_top - 1) / (pheight - 1); n = lnum - cheight + 1; change_offset(n); } /* Move the display by a distance represented by the value. */ void scr_move_by(y) int y; { int n; if (y >= 0){ y = (y - MARGIN) / fheight; n = offset - y; } else { y = (-y - MARGIN) / fheight; n = offset + y; } change_offset(n); } /* Make the selection currently delimited by the selection end markers. */ void scr_make_selection(time) int time; { if (save_selection() < 0) return; XSetSelectionOwner(display,XA_PRIMARY,vt_win,(Time)time); if (XGetSelectionOwner(display,XA_PRIMARY) != vt_win) error("Could not get primary selection"); /* Place in CUT_BUFFER0 for backup. */ XChangeProperty(display,DefaultRootWindow(display),XA_CUT_BUFFER0, XA_STRING,8,PropModeReplace,selection_text,selection_length); } /* respond to a request for our current selection. */ void scr_send_selection(time,requestor,target,property) int time, requestor, target, property; { XEvent event; int status; event.xselection.type = SelectionNotify; event.xselection.selection = XA_PRIMARY; event.xselection.target = XA_STRING; event.xselection.requestor = requestor; event.xselection.time = time; if (target == XA_STRING) { XChangeProperty(display,requestor,property,XA_STRING,8,PropModeReplace, selection_text,selection_length); event.xselection.property = property; } else event.xselection.property = None; status = XSendEvent(display,requestor,False,0,&event); } /* Request the current primary selection */ void scr_request_selection(time,x,y) int time; int x, y; { Atom sel_property; /* First check that the release is within the window. */ if (x < 0 || x >= pwidth || y < 0 || y >= pheight) return; if (selection_text != NULL) { /* The selection is internal */ send_selection(selection_text,selection_length); return; } if (XGetSelectionOwner(display,XA_PRIMARY) == None) { /* No primary selection so use the cut buffer. */ Atom actual_type; int actual_format; unsigned long nitems, bytes_after, nread; unsigned char *data; nread = 0; do { if (XGetWindowProperty(display,DefaultRootWindow(display), XA_CUT_BUFFER0,nread / 4,PROP_SIZE,False, XA_STRING,&actual_type,&actual_format, &nitems,&bytes_after,&data) != Success) return; if (nitems == 0 || data == NULL) return; send_selection(data,nitems); nread += nitems; XFree(data); } while (bytes_after > 0); return; } sel_property = XInternAtom(display,"VT_SELECTION",False); XConvertSelection(display,XA_PRIMARY,XA_STRING,sel_property,vt_win,time); wait_for_selection(time); } /* Send the selection to the command after converting LF to CR. */ static void send_selection(str,count) unsigned char *str; int count; { int i; for (i = 0; i < count; i++) if (str[i] == '\n') str[i] = '\r'; send_string(str,count); } /* Wait for the selection to arrive and move it to the head of the * queue. We wait until we either get the selection or we get * keyboard input that was generated more than SEL_KEY_DEL after time. */ static void wait_for_selection(time) Time time; { XEvent event; XPeekIfEvent(display,&event,sel_pred,(char *)&time); if (event.type == SelectionNotify) { XIfEvent(display,&event,sel_pred,NULL); XPutBackEvent(display,&event); } } /* Predicate function used when waiting for selection events. If arg is * NULL then we return true for Selection Notify events. If arg is not * NULL then it is assumed to point to a time and we also return true for * keyboard events that arrive after more than SEL_KEY_DEL after the time. */ static Bool sel_pred(dpy,ev,arg) Display *dpy; XEvent *ev; char *arg; { if (ev->type == SelectionNotify) return (True); if (arg != NULL && ev->type == KeyPress && (ev->xkey.time - *(Time *)arg) > SEL_KEY_DEL) return (True); return (False); } /* Respond to a notification that a primary selection has been sent */ void scr_paste_primary(time,window,property) int time, window, property; { Atom actual_type; int actual_format; unsigned long nitems, bytes_after, nread; unsigned char *data; if (property == None) return; nread = 0; do { if (XGetWindowProperty(display,window,property,nread / 4,PROP_SIZE,True, AnyPropertyType,&actual_type,&actual_format, &nitems,&bytes_after,&data) != Success) return; if (actual_type != XA_STRING) return; if (nitems == 0 || data == NULL) return; send_selection(data,nitems); nread += nitems; XFree(data); } while (bytes_after > 0); } /* Clear the current selection. */ void scr_clear_selection() { if (selection_text != NULL) { free(selection_text); selection_text = NULL; selection_length = 0; } show_selection(0,cheight - 1,0,cwidth - 1); selend1.se_type = selend2.se_type = NOSEL; } /* Extend the selection. */ void scr_extend_selection(x,y,drag) int x, y; int drag; { int row, col, r1, r2, c1, c2; struct selst sesave1, sesave2; struct selst *se; if (selend1.se_type == NOSEL) return; col = (x - MARGIN) / fwidth; row = (y - MARGIN) / fheight; fix_rc(&row,&col); if (selend2.se_type == NOSEL) { rc_to_selend(row,col,&selend2); show_selection(0,cheight - 1,0,cwidth - 1); return; } sesave1 = selend1; sesave2 = selend2; if (drag) { /* Anchor the start end. */ selend1 = selanchor; rc_to_selend(row,col,&selend2); adjust_selection(&selend2); } else { selend_to_rc(&r1,&c1,&selend1); selend_to_rc(&r2,&c2,&selend2); /* Determine which is the nearest endpoint. */ if (abs(r1 - row) < abs(r2 - row)) se = &selend1; else if (abs(r2 - row) < abs(r1 - row)) se = &selend2; else if (r1 == r2) { if (row < r1) se = (c1 < c2) ? &selend1 : &selend2; else if (row > r1) se = (c1 > c2) ? &selend1 : &selend2; else se = abs(c1 - col) < abs(c2 - col) ? &selend1 : &selend2; } else se = &selend2; rc_to_selend(row,col,se); adjust_selection(se); } change_selection(&sesave1,&sesave2); } /* start a selection using the specified unit. */ void scr_start_selection(x,y,unit) int x,y; enum selunit unit; { int row, col; show_selection(0,cheight - 1,0,cwidth - 1); col = (x - MARGIN) / fwidth; row = (y - MARGIN) / fheight; selection_unit = unit; fix_rc(&row,&col); rc_to_selend(row,col,&selanchor); selend2 = selend1 = selanchor; adjust_selection(&selend2); show_selection(0,cheight - 1,0,cwidth - 1); } /* Send the name of the current display to the command. */ void scr_report_display() { char *dname; struct utsname ut; dname = DisplayString(display); (void)uname(&ut); if (strncmp(dname, "unix:", 5) == 0) cprintf("%s%s\r",ut.nodename,dname + 4); else if (dname[0] == ':') cprintf("%s%s\r",ut.nodename,dname); else cprintf("%s\r",dname); } /* Report the current cursor position. */ void scr_report_position() { cprintf("\033[%d;%dR",screen->row + 1,screen->col + 1); } /* Return true if the event is a graphics exposure or noexposure. */ static Bool grexornoex(dpy,ev,arg) Display *dpy; XEvent *ev; char *arg; { return(ev->type == GraphicsExpose || ev->type == NoExpose); } /* Check for and repair any damage after copying an area of the window. */ static void repair_damage() { XEvent event; int row1, row2, col1, col2; do { /* Get the next graphics exposure or noexposure event. */ XIfEvent(display,&event,grexornoex,NULL); if (event.type == NoExpose) return; row1 = (event.xgraphicsexpose.y - MARGIN) / fheight; if (row1 < 0) row1 = 0; row2 = (event.xgraphicsexpose.y + event.xgraphicsexpose.height - MARGIN) / fheight; if (row2 >= cheight) row2 = cheight - 1; col1 = (event.xgraphicsexpose.x - MARGIN) / fwidth; if (col1 < 0) col1 = 0; col2 = (event.xgraphicsexpose.x + event.xgraphicsexpose.width - MARGIN) / fwidth; if (col2 >= cwidth) col2 = cwidth - 1; refresh(row1,row2,col1,col2); } while (event.xgraphicsexpose.count > 0); } /* Change the value of the scrolled screen offset and repaint the screen */ static void change_offset(n) int n; { int y1, y2, height, d; if (n > sline_top) n = sline_top; if (n < 0) n = 0; if (n == offset) return; cursor(); d = n - offset; offset = n; if (d > 0 && d < cheight) { /* Text has moved down by less than a screen so raster * the lines that did not move off. */ y1 = MARGIN; y2 = y1 + d * fheight; height = (cheight - d) * fheight; XCopyArea(display,vt_win,vt_win,txgc,0,y1,pwidth,height,0,y2); refresh(0,d - 1,0,cwidth - 1); repair_damage(); } else if (d < 0 && -d < cheight) { /* Text has moved down by less than a screen. */ d = -d; y2 = MARGIN; y1 = y2 + d * fheight; height = (cheight - d) * fheight; XCopyArea(display,vt_win,vt_win,txgc,0,y1,pwidth,height,0,y2); refresh(cheight - d,cheight - 1,0,cwidth - 1); repair_damage(); } else refresh(0,cheight - 1,0,cwidth - 1); cursor(); sbar_show(cheight + sline_top - 1, offset, offset + cheight - 1); } /* Paint the text using the rendition value at the screen position. */ static void paint_rval_text(str,rval,len,x,y) unsigned char *str; int rval; int len, x, y; { unsigned char *buf; int overstrike; int i; if (rval & RS_RVID) { XSetForeground(display,txgc,background); XSetBackground(display,txgc,foreground); } overstrike = 0; if (rval & RS_BOLD) { if (boldfont != NULL) { XSetFont(display,txgc,boldfont->fid); y += boldfont->ascent; } else { overstrike = 1; y += mainfont->ascent; } } else y += mainfont->ascent; if ((rval & CS_STYLE) == CS_USASCII) { XDrawImageString(display,vt_win,txgc,x,y,str,len); if (overstrike) XDrawString(display,vt_win,txgc,x + 1,y,str,len); } else { buf = (unsigned char *)cmalloc(len); if ((rval & CS_STYLE) == CS_UKASCII) { for (i = 0; i < len; i++) buf[i] = (str[i] == '#') ? POUND : str[i]; } else if ((rval & CS_STYLE) == CS_SPECIAL) { for (i = 0; i < len; i++) if (str[i] >= 0140 && str[i] <= 0176) buf[i] = (str[i] & 037) + 1; else buf[i] = str[i]; } XDrawImageString(display,vt_win,txgc,x,y,buf,len); if (overstrike) XDrawString(display,vt_win,txgc,x + 1,y,buf,len); free((void *)buf); } y++; if (rval & RS_ULINE) XDrawLine(display,vt_win,txgc,x,y,x + len * fwidth,y); if (rval & RS_RVID) { XSetForeground(display,txgc,foreground); XSetBackground(display,txgc,background); } if (rval & RS_BOLD) XSetFont(display,txgc,mainfont->fid); } /* Display the string using the rendition vector at the screen coordinates */ static void paint_rvec_text(str,rvec,len,x,y) unsigned char *str, *rvec; int len, x, y; { int i; if (rvec == NULL) { paint_rval_text(str,0,len,x,y); return; } while (len > 0) { for (i = 0; i < len; i++) if (rvec[i] != rvec[0]) break; paint_rval_text(str,rvec[0],i,x,y); str += i; rvec += i; len -= i; x += i * fwidth; } } /* Repaint the box delimited by row1 to row2 and col1 to col2 of the displayed * screen from the backup screen. */ static void refresh(row1,row2,col1,col2) int row1, row2, col1, col2; { unsigned char *s, *str, *r; int x, y, x1, y1, x2, width, i, m; struct slinest *sl; str = (unsigned char *)cmalloc(cwidth + 1); y = row1; x1 = MARGIN + col1 * fwidth; y1 = MARGIN + row1 * fheight; /* First do any 'scrolled off' lines that are visible. */ for (i = offset - 1 - row1; y <= row2 && i >= 0; y++, i--) { sl = sline[i]; m = (col2 + 1) < sl->sl_length ? (col2 + 1) : sl->sl_length; s = sl->sl_text; m -= col1; for (x = 0; x < m; x++) str[x] = s[x + col1] < ' ' ? ' ' : s[x + col1]; r = sl->sl_rend == NULL ? NULL : sl->sl_rend + col1; paint_rvec_text(str,r,m,x1,y1); x2 = x1 + m * fwidth; width = (col2 - col1 + 1 - m) * fwidth; if (width > 0) XClearArea(display,vt_win,x2,y1,width,fheight,False); y1 += fheight; } /* Now do the remainder from the current screen */ i = offset > row1 ? 0 : row1 - offset; for (; y <= row2; y++, i++) { s = screen->text[i]; m = col1 - 1; for (x = col1; x <= col2; x++) if (s[x] < ' ') str[x - col1] = ' '; else { str[x - col1] = s[x]; m = x; } m++; m -= col1; r = screen->rend[i][cwidth] == 0 ? NULL : screen->rend[i] + col1; paint_rvec_text(str,r,m,x1,y1); x2 = x1 + m * fwidth; width = (col2 - col1 + 1 - m) * fwidth; if (width > 0) XClearArea(display,vt_win,x2,y1,width,fheight,False); y1 += fheight; } free(str); show_selection(row1,row2,col1,col2); } /* Paint any part of the selection that is between rows row1 and row2 inclusive * and between cols col1 and col2 inclusive. */ static void show_selection(row1,row2,col1,col2) int row1, row2, col1, col2; { int r1, c1, r2, c2, sr, sc, er, ec; int x1, x2, y, row; if (selend1.se_type == NOSEL || selend2.se_type == NOSEL) return; if (selcmp(&selend1,&selend2) == 0) return; selend_to_rc(&r1,&c1,&selend1); selend_to_rc(&r2,&c2,&selend2); col2++; /* Obtain initial and final endpoints for the selection. */ if (r1 < r2 || (r1 == r2 && c1 <= c2)) { sr = r1; sc = c1; er = r2; ec = c2; } else { sr = r2; sc = c2; er = r1; ec = c1; } if (sr < row1) { sr = row1; sc = col1; } if (sc < col1) sc = col1; if (er > row2) { er = row2; ec = col2; } if (ec > col2) ec = col2; if (sr > er) return; /* Paint in the reverse video. */ for (row = sr; row <= er; row++) { y = MARGIN + row * fheight; x1 = MARGIN + (row == sr ? sc : col1) * fwidth; x2 = MARGIN + ((row == er) ? ec : col2) * fwidth; if (x2 > x1) XFillRectangle(display,vt_win,hlgc,x1,y,x2 - x1,fheight); } } /* Scroll count lines from row1 to row2 inclusive. row1 should be <= row1. * scrolling is up for a +ve count and down for a -ve count. * count is limited to a maximum of MAX_SCROLL lines. */ static void scroll(row1,row2,count) int row1, row2, count; { int y1, y2, height, i, j; unsigned char *save[MAX_SCROLL], *rend[MAX_SCROLL]; struct slinest *sl; unsigned char *r, *s; row2++; if (row1 == 0 && screen == &screen1 && count > 0) { /* Save lines that scroll of the top of the screen. */ for (i = 1; i <= count; i++) { if ((sl = sline[sline_max - i]) != NULL) { free(sl->sl_text); if (sl->sl_rend != NULL) free(sl->sl_rend); free((void *)sl); } if (selend1.se_type == SAVED && selend1.se_index == sline_max-i) { show_selection(0,cheight - 1,0,cwidth - 1); selend1.se_type = NOSEL; } if (selend2.se_type == SAVED && selend2.se_index == sline_max-i) { show_selection(0,cheight - 1,0,cwidth - 1); selend2.se_type = NOSEL; } } for (i = sline_max - count - 1; i >= 0; i--) { sline[i + count] = sline[i]; if (selend1.se_type == SAVED && selend1.se_index == i) selend1.se_index = i + count; if (selend2.se_type == SAVED && selend2.se_index == i) selend2.se_index = i + count; } for (i = 0; i < count; i++) { s = screen->text[i]; r = screen->rend[i]; for (j = cwidth - 1; j >= 0 && s[j] == 0; j--) ; j++; sl = (struct slinest *)cmalloc(sizeof(struct slinest)); sl->sl_text = (unsigned char *)cmalloc(j + 1); memcpy(sl->sl_text,s,j); sl->sl_text[j] = s[cwidth]; if (r[cwidth] == 0) sl->sl_rend = NULL; else { sl->sl_rend = (unsigned char *)cmalloc(j + 1); memcpy(sl->sl_rend,r,j); } sl->sl_length = j; sline[count - i - 1] = sl; if (selend1.se_type == SCREEN && selend1.se_index == i) { selend1.se_type = SAVED; selend1.se_index = count - i - 1; } if (selend2.se_type == SCREEN && selend2.se_index == i) { selend2.se_type = SAVED; selend2.se_index = count - i - 1; } } sline_top += count; if (sline_top > sline_max) sline_top = sline_max; sbar_show(cheight + sline_top - 1, offset, offset + cheight - 1); } if (count > 0) { j = row1; for (i = 0; i < count; i++, j++) { save[i] = screen->text[j]; rend[i] = screen->rend[j]; if (selend1.se_type == SCREEN && selend1.se_index == j) { show_selection(0,cheight - 1,0,cwidth - 1); selend1.se_type = NOSEL; } if (selend2.se_type == SCREEN && selend2.se_index == j) { show_selection(0,cheight - 1,0,cwidth - 1); selend2.se_type = NOSEL; } } for (; j < row2; j++) { screen->text[j - count] = screen->text[j]; screen->rend[j - count] = screen->rend[j]; if (selend1.se_type == SCREEN && selend1.se_index == j) selend1.se_index = j - count; if (selend2.se_type == SCREEN && selend2.se_index == j) selend2.se_index = j - count; } for (i = 0; i < count; i++) { memset(save[i],0,cwidth + 1); screen->text[row2 - i - 1] = save[i]; memset(rend[i],0,cwidth + 1); screen->rend[row2 - i - 1] = rend[i]; } if (count < row2 - row1) { y2 = MARGIN + row1 * fheight; y1 = y2 + count * fheight; height = (row2 - row1 - count) * fheight; XCopyArea(display,vt_win,vt_win,txgc,0,y1,pwidth,height,0,y2); repair_damage(); } height = count * fheight; y1 = MARGIN + (row2 - count) * fheight; XClearArea(display,vt_win,0,y1,pwidth,height,False); } if (count < 0) { count = -count; j = row2 - 1; for (i = 0; i < count; i++, j--) { save[i] = screen->text[j]; rend[i] = screen->rend[j]; if (selend1.se_type == SCREEN && selend1.se_index == j) { show_selection(0,cheight - 1,0,cwidth - 1); selend1.se_type = NOSEL; } if (selend2.se_type == SCREEN && selend2.se_index == j) { show_selection(0,cheight - 1,0,cwidth - 1); selend2.se_type = NOSEL; } } for (; j >= row1; j--) { screen->text[j + count] = screen->text[j]; screen->rend[j + count] = screen->rend[j]; if (selend1.se_type == SCREEN && selend1.se_index == j) selend1.se_index = j + count; if (selend2.se_type == SCREEN && selend2.se_index == j) selend2.se_index = j + count; } for (i = 0; i < count; i++) { memset(save[i],0,cwidth + 1); screen->text[row1 + i] = save[i]; memset(rend[i],0,cwidth + 1); screen->rend[row1 + i] = rend[i]; } if (count < row2 - row1) { y1 = MARGIN + row1 * fheight; y2 = y1 + count * fheight; height = (row2 - row1 - count) * fheight; XCopyArea(display,vt_win,vt_win,txgc,0,y1,pwidth,height,0,y2); repair_damage(); } height = count * fheight; y1 = MARGIN + row1 * fheight; XClearArea(display,vt_win,0,y1,pwidth,height,False); } } /* Scroll screen1 up by count lines saving lines as needed. This is used * after the screen size is reduced. */ static void scroll1(count) int count; { int i, j, n; unsigned char *save[MAX_SCROLL], *rend[MAX_SCROLL]; struct slinest *sl; unsigned char *r, *s; while (count > 0) { /* If count is greater than MAX_SCROLL then scroll in * installements. */ n = count > MAX_SCROLL ? MAX_SCROLL : count; count -= n; /* Save lines that scroll of the top of the screen. */ for (i = 1; i <= n; i++) { if ((sl = sline[sline_max - i]) != NULL) { free(sl->sl_text); if (sl->sl_rend != NULL) free(sl->sl_rend); free((void *)sl); } } for (i = sline_max - n - 1; i >= 0; i--) { sline[i + n] = sline[i]; } for (i = 0; i < n; i++) { s = screen1.text[i]; r = screen1.rend[i]; for (j = cwidth - 1; j >= 0 && s[j] == 0; j--) ; j++; sl = (struct slinest *)cmalloc(sizeof(struct slinest)); sl->sl_text = (unsigned char *)cmalloc(j + 1); memcpy(sl->sl_text,s,j); sl->sl_text[j] = s[cwidth]; if (r[cwidth] == 0) sl->sl_rend = NULL; else { sl->sl_rend = (unsigned char *)cmalloc(j + 1); memcpy(sl->sl_rend,r,j); } sl->sl_length = j; sline[n - i - 1] = sl; } sline_top += n; if (sline_top > sline_max) sline_top = sline_max; j = 0; for (i = 0; i < n; i++, j++) { save[i] = screen1.text[j]; rend[i] = screen1.rend[j]; } for (; j < cheight; j++) { screen1.text[j - n] = screen1.text[j]; screen1.rend[j - n] = screen1.rend[j]; } for (i = 0; i < n; i++) { memset(save[i],0,cwidth + 1); screen1.text[cheight - i - 1] = save[i]; memset(rend[i],0,cwidth + 1); screen1.rend[cheight - i - 1] = rend[i]; } } } /* Reposition the scrolled text so that the scrollbar is at the bottom. */ static void home_screen() { if (offset > 0) { offset = 0; refresh(0,cheight - 1,0,cwidth - 1); cursor(); sbar_show(cheight + sline_top - 1, 0, cheight - 1); } } /* Draw the cursor at the current position. */ static void cursor() { int x, y; if (offset > 0) return; x = MARGIN + fwidth * screen->col; y = MARGIN + fheight * screen->row; XFillRectangle(display,vt_win,cugc,x,y,fwidth,fheight); if (focus == 0) XFillRectangle(display,vt_win,cugc,x + 1,y + 1,fwidth - 2,fheight - 2); } /* Convert a row and column coordinates into a selection endpoint. */ static void rc_to_selend(row,col,se) int row, col; struct selst *se; { int i; i = (row - offset); if (i >= 0) se->se_type = SCREEN; else { se->se_type = SAVED; i = -1 - i; } se->se_index = i; se->se_col = col; } /* Fix the coordinates so that they are within the screen and do not lie within * empty space. */ static void fix_rc(rowp,colp) int *rowp, *colp; { int i, len, row, col; unsigned char *s; col = *colp; if (col < 0) col = 0; if (col > cwidth) col = cwidth; row = *rowp; if (row < 0) row = 0; if (row >= cheight) row = cheight - 1; if (selection_unit == CHAR) { i = (row - offset); if (i >= 0) { s = screen->text[i]; if (col > 0 && s[col - 1] < ' ') while (col < cwidth && s[col] < ' ') col++; } else { i = -1 - i; len = sline[i]->sl_length; s = sline[i]->sl_text; if (col > 0 && s[col - 1] < ' ') while (col <= len && s[col] < ' ') col++; if (col > len) col = cwidth; } } *colp = col; *rowp = row; } /* Convert the selection into a row and column. */ static void selend_to_rc(rowp,colp,se) int *rowp, *colp; struct selst *se; { if (se->se_type == NOSEL) return; *colp = se->se_col; if (se->se_type == SCREEN) *rowp = se->se_index + offset; else *rowp = offset - se->se_index - 1; } /* Repaint the displayed selection to reflect the new value. ose1 and ose2 * are assumed to represent the currently displayed selection endpoints. */ static void change_selection(ose1,ose2) struct selst *ose1, *ose2; { int rs, cs, re, ce, n; int row; int row1, row2; int x1, x2, y; struct selst *se, *se1, *se2; if (selcmp(ose1,ose2) > 0) { se = ose1; ose1 = ose2; ose2 = se; } if (selcmp(&selend1,&selend2) <= 0) { se1 = &selend1; se2 = &selend2; } else { se1 = &selend2; se2 = &selend1; } if ((n = selcmp(se1,ose1)) != 0) { /* repaint the start. */ if (n < 0) { selend_to_rc(&rs,&cs,se1); selend_to_rc(&re,&ce,ose1); } else { selend_to_rc(&rs,&cs,ose1); selend_to_rc(&re,&ce,se1); } row1 = rs < 0 ? 0 : rs; row2 = re >= cheight ? cheight - 1 : re; /* Invert the changed area */ for (row = row1; row <= row2; row++) { y = MARGIN + row * fheight; x1 = MARGIN + (row == rs ? cs * fwidth : 0); x2 = MARGIN + ((row == re) ? ce : cwidth) * fwidth; XFillRectangle(display,vt_win,hlgc,x1,y,x2 - x1,fheight); } } if ((n = selcmp(se2,ose2)) != 0) { /* repaint the end. */ if (n < 0) { selend_to_rc(&rs,&cs,se2); selend_to_rc(&re,&ce,ose2); } else { selend_to_rc(&rs,&cs,ose2); selend_to_rc(&re,&ce,se2); } row1 = rs < 0 ? 0 : rs; row2 = re >= cheight ? cheight - 1 : re; /* Invert the changed area */ for (row = row1; row <= row2; row++) { y = MARGIN + row * fheight; x1 = MARGIN + (row == rs ? cs * fwidth : 0); x2 = MARGIN + ((row == re) ? ce : cwidth) * fwidth; XFillRectangle(display,vt_win,hlgc,x1,y,x2 - x1,fheight); } } } /* Convert a section of displayed text line into a text string suitable for pasting. * *lenp is the length of the input string, i1 is index of the first character to * convert and i2 is the last. The length of the returned string is returned * in *lenp; */ static unsigned char * convert_line(str,lenp,i1,i2) unsigned char *str; int *lenp; int i1, i2; { static unsigned char buf[MAX_WIDTH + 3]; unsigned char *s; int i; int newline; newline = (i2 + 1 == cwidth) && (str[*lenp] == 0); if (i2 >= *lenp) i2 = *lenp - 1; if (i2 - i1 >= MAX_WIDTH) i2 = i1 + MAX_WIDTH; while (i2 >= i1 && str[i2] == 0) i2--; s = buf; for (i = i1; i <= i2; i++) { if (str[i] >= ' ') *s++ = str[i]; else if (str[i] == '\t') { *s++ = '\t'; while (i < i2 && str[i + 1] == 0) i++; } else *s++ = ' '; } if (newline) *s++ = '\n'; *s = 0; *lenp = s - buf; return (buf); } /* Compare the two selections and return -1, 0 or 1 depending on * whether se2 is after, equal to or before se1. */ static int selcmp(se1,se2) struct selst *se1, *se2; { if (se1->se_type == SAVED && se2->se_type == SAVED) { if (se1->se_index > se2->se_index) return(-1); if (se1->se_index < se2->se_index) return(1); if (se1->se_col < se2->se_col) return(-1); if (se2->se_col < se1->se_col) return(1); return(0); } if (se1->se_type == SCREEN && se2->se_type == SCREEN) { if (se1->se_index < se2->se_index) return(-1); if (se1->se_index > se2->se_index) return(1); if (se1->se_col < se2->se_col) return(-1); if (se2->se_col < se1->se_col) return(1); return(0); } if (se1->se_type == SAVED) return(-1); return(1); } /* Adjust the selection to a word or line boundary. If the include endpoint is * non NULL then the selection is forced to be large enough to include it. */ static void adjust_selection(include) struct selst *include; { struct selst *se1, *se2; int i, len; unsigned char *s; if (selection_unit == CHAR) return; if (selcmp(&selend1,&selend2) <= 0) { se1 = &selend1; se2 = &selend2; } else { se2 = &selend1; se1 = &selend2; } if (selection_unit == WORD) { i = se1->se_col; s = se1->se_type == SCREEN ? screen->text[se1->se_index] : sline[se1->se_index]->sl_text; while (i > 0 && cclass(s[i]) == cclass(s[i-1])) i--; se1->se_col = i; i = se2->se_col; if (se2 == include || selcmp(se2,&selanchor) == 0) i++; if (se2->se_type == SCREEN) { s = screen->text[se2->se_index]; len = cwidth; } else { s = sline[se2->se_index]->sl_text; len = sline[se2->se_index]->sl_length; } while (i < len && cclass(s[i]) == cclass(s[i-1])) i++; se2->se_col = (i > len) ? cwidth : i; } else if (selection_unit == LINE) { se1->se_col = 0; se2->se_col = cwidth; } } /* Convert the currently marked screen selection as a text string and save it * as the current saved selection. 0 is returned for a success, -1 for a failure. */ static int save_selection() { unsigned char *str, *s; int i, len, total, col1, col2; struct selst *se1, *se2; struct slinest *sl; if (selend1.se_type == NOSEL || selend2.se_type == NOSEL) return(-1); if (selend1.se_type == selend2.se_type && selend1.se_index == selend2.se_index && selend1.se_col == selend2.se_col) return(-1); if (selection_text != NULL) free(selection_text); /* Set se1 and se2 to point to the first and second selection endpoints. */ if (selcmp(&selend1,&selend2) <= 0) { se1 = &selend1; se2 = &selend2; } else { se2 = &selend1; se1 = &selend2; } str = (unsigned char *)cmalloc(total = 1); if (se1->se_type == SAVED) { col1 = se1->se_col; for (i = se1->se_index; i >= 0; i--) { sl = sline[i]; if (se2->se_type == SAVED && se2->se_index == i) { col2 = se2->se_col - 1; i = 0; /* force loop exit */ } else col2 = cwidth - 1; len = sl->sl_length; s = convert_line(sl->sl_text,&len,col1,col2); str = (unsigned char *)realloc(str,total + len); if (str == NULL) abort(); strncpy((char *)str + total - 1,(char *)s,len); total += len; col1 = 0; } } if (se2->se_type == SCREEN) { if (se1->se_type == SCREEN) { i = se1->se_index; col1 = se1->se_col; } else { i = 0; col1 = 0; } for (; i <= se2->se_index; i++) { col2 = i == se2->se_index ? se2->se_col : cwidth; if (--col2 < 0) break; len = cwidth; s = convert_line(screen->text[i],&len,col1,col2); str = (unsigned char *)realloc(str,total + len); if (str == NULL) abort(); strncpy((char *)str + total - 1,(char *)s,len); total += len; col1 = 0; } } str[total - 1] = 0; selection_text = str; selection_length = total - 1; return(0); } /* Determine if the current selection overlaps row1-row2 and if it does then * remove it from the screen. */ static void check_selection(row1,row2) int row1,row2; { int r1, r2, x; if (selend1.se_type == NOSEL || selend2.se_type == NOSEL) return; r1 = selend1.se_type == SCREEN ? selend1.se_index : -1; r2 = selend2.se_type == SCREEN ? selend2.se_index : -1; if (r1 > r2) { x = r1; r1 = r2; r2 = x; } if (row2 < r1 || row1 > r2) return; show_selection(0,cheight - 1,0,cwidth - 1); selend2.se_type = NOSEL; } /* Return a character class for selecting words */ static int cclass(c) int c; { return (char_class[c]); } xvt-2.1.orig/screen.h100644 765 765 10204 6410001715 12530 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)screen.h 1.2 16/11/93 (UKC) */ /* flags for scr_move() */ #define COL_RELATIVE 1 /* column movement is relative */ #define ROW_RELATIVE 2 /* row movement is relative */ #define MAX_SCROLL 50 /* max number of lines that can scroll at once */ /* arguments to the screen delete functions */ #define END 0 #define START 1 #define ENTIRE 2 /* rendition style flags. */ #define RS_NONE 0x00 /* Normal */ #define RS_BOLD 0x01 /* Bold face */ #define RS_ULINE 0x02 /* underline */ #define RS_BLINK 0x04 /* blinking */ #define RS_RVID 0x08 /* reverse video */ #define RS_STYLE 0x0f /* style mask */ /* character set flags. */ #define CS_USASCII 0x00 #define CS_UKASCII 0x10 #define CS_SPECIAL 0x20 #define CS_STYLE 0x30 /* The current selection unit */ enum selunit { CHAR, WORD, LINE }; #ifdef __STDC__ int is_string_char(int); void scr_backspace(void); void scr_bell(void); void scr_change_rendition(int); void scr_change_screen(int); void scr_char_class(unsigned char *); void scr_clear_selection(void); void scr_delete_characters(int); void scr_delete_lines(int); void scr_efill(void); void scr_erase_line(int); void scr_erase_screen(int); void scr_extend_selection(int,int,int); void scr_focus(int,int); void scr_get_size(int *,int *); void scr_index(void); void scr_init(int); void scr_insert_characters(int); void scr_insert_lines(int); void scr_make_selection(int); void scr_move(int,int,int); void scr_move_by(int); void scr_move_to(int); void scr_paste_primary(int,int,int); void scr_refresh(int,int,int,int); void scr_report_display(void); void scr_report_position(void); void scr_request_selection(int,int,int); void scr_reset(void); void scr_restore_cursor(void); void scr_rindex(void); void scr_save_cursor(void); void scr_send_selection(int,int,int,int); void scr_set_char_set(int,int); void scr_set_decom(int); void scr_set_insert(int); void scr_set_margins(int,int); void scr_set_wrap(int); void scr_shift(int); void scr_start_selection(int,int,enum selunit); void scr_string(unsigned char *,int,int); void scr_tab(void); #else /* __STDC__ */ int is_string_char(); void scr_backspace(); void scr_bell(); void scr_change_rendition(); void scr_change_screen(); void scr_char_class(); void scr_clear_selection(); void scr_delete_characters(); void scr_delete_lines(); void scr_efill(); void scr_erase_line(); void scr_erase_screen(); void scr_extend_selection(); void scr_focus(); void scr_get_size(); void scr_index(); void scr_init(); void scr_insert_characters(); void scr_insert_lines(); void scr_make_selection(); void scr_move(); void scr_move_by(); void scr_move_to(); void scr_paste_primary(); void scr_refresh(); void scr_report_display(); void scr_report_position(); void scr_request_selection(); void scr_reset(); void scr_restore_cursor(); void scr_rindex(); void scr_save_cursor(); void scr_send_selection(); void scr_set_char_set(); void scr_set_decom(); void scr_set_insert(); void scr_set_margins(); void scr_set_wrap(); void scr_shift(); void scr_start_selection(); void scr_string(); void scr_tab(); #endif /* __STDC__ */ xvt-2.1.orig/token.h100644 765 765 7670 6410001730 12363 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)token.h 1.2 16/11/93 (UKC) */ /* Values of tk_region for Xevent generated tokens. */ #define MAINWIN 0 #define SCREEN 1 #define SCROLLBAR 2 /* Token types */ #define TK_NULL 0 /* null token to be ignored */ #define TK_STRING 1 /* string of printable characters */ #define TK_CHAR 2 /* single character */ #define TK_EOF 3 /* read end of file */ #define TK_ENTRY 4 /* cursor crossed window boundery */ #define TK_EXPOSE 5 /* window has been exposed */ #define TK_RESIZE 6 /* main window has been resized */ #define TK_SBSWITCH 7 /* switch scrollbar in or out */ #define TK_SBGOTO 8 /* scrollbar goto */ #define TK_SBUP 9 /* scrollbar move up */ #define TK_SBDOWN 10 /* scrollbar move down */ #define TK_SELSTART 11 /* start the selection */ #define TK_SELEXTND 12 /* extend the selection */ #define TK_SELDRAG 13 /* drag the selection */ #define TK_SELINSRT 14 /* insert the selection */ #define TK_SELWORD 15 /* select a word */ #define TK_SELLINE 16 /* select a line */ #define TK_SELECT 17 /* confirm the selection */ #define TK_SELCLEAR 18 /* selection clear request */ #define TK_SELNOTIFY 19 /* selection notify request */ #define TK_SELREQUEST 20 /* selection request */ #define TK_TXTPAR 21 /* seq with text parameter */ #define TK_FOCUS 22 /* keyboard focus event */ /* DEC VT100 control sequence token types */ #define TK_CUU 'A' /* Cursor up */ #define TK_CUD 'B' /* cursor down */ #define TK_CUF 'C' /* cursor back */ #define TK_CUB 'D' /* cursor back */ #define TK_CUP 'H' /* position cursor */ #define TK_ED 'J' /* erase to start or end of screen */ #define TK_EL 'K' /* erase to start or end of line */ #define TK_IL 'L' /* insert lines */ #define TK_DL 'M' /* delete lines */ #define TK_DCH 'P' /* Delete characters */ #define TK_ICH '@' /* insert characters */ #define TK_DA 'c' /* device attributes request */ #define TK_HVP 'f' /* horizontal and vertical position */ #define TK_TBC 'g' /* tab clear */ #define TK_SET 'h' /* set mode */ #define TK_RESET 'l' /* reset mode */ #define TK_SGR 'm' /* set graphics rendition */ #define TK_DSR 'n' /* report status or position */ #define TK_DECSTBM 'r' /* set top and bottom margins */ #define TK_DECSWH '#' /* set character width or height */ #define TK_SCS0 '(' /* set character set G0 */ #define TK_SCS1 ')' /* set character set G1 */ #define TK_DECSC '7' /* save cursor position */ #define TK_DECRC '8' /* restore cursor position */ #define TK_DECPAM '=' /* keypad to applications mode */ #define TK_DECPNM '>' /* keypad to numeric mode */ #define TK_IND 0x100 /* index downward */ #define TK_NEL 0x101 /* beginning of next line */ #define TK_HTS 0x102 /* horizontal tab set */ #define TK_RI 0x103 /* reverse index */ #define TK_SS2 0x104 /* single shift 2 */ #define TK_SS3 0x105 /* single shift 3 */ #define TK_DECID 0x106 /* request terminal ID */ xvt-2.1.orig/ttyinit.c100644 765 765 42051 6410233472 12764 0ustar cpb4cpb4/* Copyright 1992-94, 1997 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_ttyinit_c_sccsid[] = "@(#)ttyinit.c 1.3 11/1/94 (UKC)"; #ifdef __STDC__ #include #else #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "xvt.h" #include "token.h" #include "command.h" #include "ttyinit.h" #include "screen.h" #include "xsetup.h" /* NOTES ON PORTING * * Almost all the non-portable parts of xvt are concerned with setting up * and configuring the pseudo-teletype (pty) link that connects xvt itself * to the commands running in its window. In practice, there are four * different tasks that need to be done to get a pty up and running and * each of these tasks can be done in different ways, depending on the * flavour of UNIX. The four tasks are: * * Obtaining a free pty * -------------------- * This is handled in the function get_pseudo_teletype. On BSD flavours * of UNIX, the directory /dev contains a block of pty master devices, * with names pty??, and a matching set of slave teletype devices with the * initial 'p' replaced by a 't'. The way to find a free pseudoteletype * pair is to try opening pty devices, one by one, until one is opened * successfully. Then the matching tty device is opened to form the other * end of the pair. The alternative (SVR4?) approach is to open /dev/ptmx * and then use a sequence of system calls to request and initialise the * pty pair. Either of the two approaches are selected by defining one of * BSD_PTY and SVR4_PTY, but the only system I have found which supports * SVR4_PTY is SunOS 5. * * Creation of a controlling teletype * ---------------------------------- * After the fork(), the slave tty needs to be made into the controlling * teletype for the child process (which will eventually exec the command * program, usually a shell). On some systems this is done with a * TIOCSCTTY ioctl after calling setsid() to create a new session. On * most other systems, the procedure is to call setsid() and then re-open * the tty. This latter approach is the default - if your system uses * TIOCSCTTY then #define SCTTY_IOCTL. * * Configure the teletype * ---------------------- * This is handled in set_ttymodes(). SVR4 systems use the termios * structure and the tcsetattr() system call whereas BSD systems use the * sgttyb structure and TIOC ioctls. In the systems I have ported to, * termios is prevalent and so this is the default. If your system does * not have termios then you will need to #define BSD_TTY to enable the * use of sgttyb instead. * * Adding an entry to utmp * ----------------------- * Xvt needs to add an entry to /etc/utmp if the session is to be visible * to programs like finger and who. On BSD systems this involved finding * the correct position in the utmp file and then using write(2) to insert * an entry. On SVR4 systems the work is done by pututline(3) and * family. SunOS 5 has a utmp extension which stores additional * information about each session. The relevent #defines are SVR4_UTMP, * BSD_UTMP and SVR4_UTMPX. If you don't need utmp entries then you don't * need to define any of these. */ /* Definitions that enable machine dependent parts of the code. */ #ifdef SUNOS4 #define BSD_PTY #define BSD_UTMP #define TTYTAB "/etc/ttytab" /* File to search for tty utmp slot number */ #define SCTTY_IOCTL #endif /* SUNOS */ #ifdef SUNOS5 #include #include #include #include #define SVR4_UTMPX #define SVR4_PTY #endif /* SUNOS5 */ #ifdef OSF1 #include #define SVR4_UTMP #define BSD_PTY #define SCTTY_IOCTL #endif /* OSF1 */ #ifdef AIX3 #include #include #define SVR4_UTMP #define BSD_PTY #endif /* AIX3 */ #ifdef ULTRIX #include #include #define BSD_PTY #define BSD_TTY #define BSD_UTMP #define TTYTAB "/etc/ttys" /* File to search for tty utmp slot number */ #endif /* ULTRIX */ #ifdef HPUX #define SVR4_UTMP #define BSD_PTY #endif /* HPUX */ #ifdef LINUX #define BSD_PTY #define SVR4_UTMP #endif #ifdef UKC_LOCATIONS #include #define LOCTMPFILE "/etc/loctmp" #endif /* UKC_LOCATIONS */ #ifdef __STDC__ static void catch_child(int); static void catch_sig(int); static void write_utmp(void); static void tidy_utmp(void); static void set_ttymodes(void); #ifdef BSD_UTMP static int get_tslot(char *); #endif /* BSD_UTMP */ static char *get_pseudo_tty(int *,int *); #else /* __STDC__ */ static void catch_child(); static void catch_sig(); static void write_utmp(); static void tidy_utmp(); static void set_ttymodes(); #ifdef BSD_UTMP static int get_tslot(); #endif /* BSD_UTMP */ static char *get_pseudo_tty(); #endif /* __STDC__ */ /* Global variables that are set up at the beginning and then not changed */ extern Display *display; extern int comm_fd; /* file descriptor connected to the command */ extern int fd_width; /* Number of available file descriptors */ static int comm_pid = -1; /* process id of child */ static char *tty_name = NULL; /* name of the slave teletype */ #ifdef BSD_UTMP static int tslot = -1; /* index to our slot in the utmp file */ #endif /* BSD_UTMP */ static struct utmp utent; /* our current utmp entry */ /* Catch a SIGCHLD signal and exit if the direct child has died. */ static void catch_child(sig) int sig; { int status; if (wait(&status) == comm_pid) quit(0); signal(SIGCHLD,catch_child); } /* Catch a fatal signal and tidy up before quitting */ static void catch_sig(sig) int sig; { tidy_utmp(); signal(sig,SIG_DFL); setuid(getuid()); kill(getpid(),sig); } /* Attempt to create and write an entry to the utmp file */ static void write_utmp() { struct passwd *pw; #ifdef SVR4_UTMP memset(&utent,0,sizeof(utent)); utent.ut_type = USER_PROCESS; strncpy(utent.ut_id,tty_name + 8,sizeof(utent.ut_id)); strncpy(utent.ut_line,tty_name + 5,sizeof(utent.ut_line)); pw = getpwuid(getuid()); if (pw != NULL) strncpy(utent.ut_name,pw->pw_name,sizeof(utent.ut_name)); strncpy(utent.ut_host,XDisplayString(display),sizeof(utent.ut_host)); time(&utent.ut_time); pututline(&utent); endutent(); #endif /* SVR4_UTMP */ #ifdef SVR4_UTMPX struct utmpx utentx; int n; memset(&utentx,0,sizeof(utentx)); utentx.ut_type = USER_PROCESS; utentx.ut_pid = comm_pid; if (sscanf(tty_name,"/dev/pts/%d",&n) != 1) { error("Can's parse tty name %s",tty_name); return; } sprintf(utentx.ut_id,"vt%02x",n); sprintf(utentx.ut_line,"pts/%d",n); pw = getpwuid(getuid()); if (pw != NULL) strncpy(utentx.ut_name,pw->pw_name,sizeof(utent.ut_name)); strncpy(utentx.ut_host,XDisplayString(display),sizeof(utentx.ut_host)); utentx.ut_syslen = strlen(utentx.ut_host) + 1; time(&utentx.ut_xtime); getutmp(&utentx,&utent); pututline(&utent); pututxline(&utentx); updwtmpx(WTMPX_FILE,&utentx); endutent(); #endif /* SVR4_UTMPX */ #ifdef BSD_UTMP #ifndef UTMP_FILE #define UTMP_FILE "/etc/utmp" #endif /* !UTMP_FILE */ int ut_fd; if ((tslot = get_tslot(tty_name + 5)) < 0) error("can't locate tty %s in %s",tty_name,TTYTAB); /* Attempt to write an entry into the utmp file. */ if (tslot > 0) { if ((ut_fd = open(UTMP_FILE, O_WRONLY)) >= 0) { memset(&utent,0,sizeof(utent)); strncpy(utent.ut_line,tty_name + 5,sizeof(utent.ut_line)); pw = getpwuid(getuid()); if (pw != NULL) strncpy(utent.ut_name,pw->pw_name,sizeof(utent.ut_name)); strncpy(utent.ut_host,XDisplayString(display),sizeof(utent.ut_host)); time(&utent.ut_time); lseek(ut_fd,(long)(tslot * sizeof(struct utmp)),0); write(ut_fd,(char *)&utent,sizeof(struct utmp)); close(ut_fd); } } #endif /* BSD_UTMP */ #ifdef UKC_LOCATIONS if (tslot > 0) { struct ttyb locent; int loc_fd = open(LOCTMPFILE, O_WRONLY); if (loc_fd < 0 && errno == ENOENT) { /* Need to create the file. */ loc_fd = creat(LOCTMPFILE, 0644); } if (loc_fd >= 0) { memset(&locent,0,sizeof(struct ttyb)); strncpy(locent.t_name,XDisplayString (display),LN_NAMEL); locent.t_name[LN_NAMEL - 1] = '\0'; strcpy(locent.t_extra, "(xvt)"); lseek(loc_fd, (long)(tslot*sizeof(locent)), 0); write(loc_fd, (char *)&locent, sizeof(locent)); close(loc_fd); } } #endif /* UKC_LOCATIONS */ } /* Tidy up the utmp entry etc prior to exiting. */ static void tidy_utmp() { #if defined(SVR4_UTMP) || defined(SVR4_UTMPX) setutent(); if (getutid(&utent) == NULL) return; utent.ut_type = DEAD_PROCESS; time(&utent.ut_time); pututline(&utent); #endif /* SVR4_UTMP || SVR4_UTMPX */ #ifdef SVR4_UTMPX updwtmp(WTMP_FILE,&utent); #endif /* SVR4_UTMPX */ #ifdef BSD_UTMP int ut_fd; if (tslot < 0) return; if ((ut_fd = open(UTMP_FILE,O_WRONLY)) < 0) return; memset(&utent,0,sizeof(utent)); lseek(ut_fd,(long)(tslot * sizeof(struct utmp)),0); write(ut_fd,(char *)&utent,sizeof(struct utmp)); close(ut_fd); #endif /* BSD_UTMP */ #ifdef BSD_PTY chmod(tty_name,0666); #endif /* BSD_PTY */ } /* Quit with the status after first removing our entry from the utmp file. */ void quit(status) int status; { tidy_utmp(); exit(status); } #ifdef BSD_UTMP /* Look up the tty name in the etc/ttytab file and return a slot number * that can be used to access the utmp file. We cannot use ttyslot() * because the tty name is not that of fd 0. */ static int get_tslot(ttynam) char *ttynam; { FILE *fs; char buf[200], name[200]; int i; if ((fs = fopen(TTYTAB,"r")) == NULL) return(-1); i = 1; while (fgets(buf,200,fs) != NULL) { if (*buf == '#') continue; if (sscanf(buf,"%s",name) != 1) continue; if (strcmp(ttynam,name) == 0) { fclose(fs); return(i); } i++; } fclose(fs); return(-1); } #endif /* BSD_UTMP */ /* Acquire a pseudo teletype from the system. The return value is the * name of the slave part of the pair or NULL if unsucsessful. If * successful then the master and slave file descriptors are returned * via the arguments. */ static char * get_pseudo_tty(pmaster,pslave) int *pmaster, *pslave; { #ifdef BSD_PTY int mfd, sfd; char *s3, *s4; static char ptyc3[] = "pqrstuvwxyz"; static char ptyc4[] = "0123456789abcdef"; static char ptynam[] = "/dev/ptyxx"; static char ttynam[] = "/dev/ttyxx"; /* First find a master pty that we can open. */ mfd = -1; for (s3 = ptyc3; *s3 != 0; s3++) { for (s4 = ptyc4; *s4 != 0; s4++) { ptynam[8] = ttynam[8] = *s3; ptynam[9] = ttynam[9] = *s4; if ((mfd = open(ptynam,O_RDWR)) >= 0) { if (geteuid() == 0 || access(ttynam,R_OK|W_OK) == 0) break; else { close(mfd); mfd = -1; } } } if (mfd >= 0) break; } if (mfd < 0) { error("Can't open a pseudo teletype"); return(NULL); } if ((sfd = open(ttynam,O_RDWR)) < 0) { error("could not open slave tty %s",ttynam); return(NULL); } #endif /* BSD_PTY */ #ifdef SVR4_PTY char *ttynam; int mfd, sfd; if ((mfd = open("/dev/ptmx",O_RDWR)) < 0) { error("Can't open a pseudo teletype"); return(NULL); } grantpt(mfd); unlockpt(mfd); ttynam = ptsname(mfd); if ((sfd = open(ttynam,O_RDWR)) < 0) { error("could not open slave tty %s",ttynam); return(NULL); } ioctl(sfd,I_PUSH,"ptem"); ioctl(sfd,I_PUSH,"ldterm"); #endif /* SVR4_PTY */ *pslave = sfd; *pmaster = mfd; return(ttynam); } /* Initialise the terminal attributes. */ static void set_ttymodes() { int width, height; #ifndef BSD_TTY /* Set the terminal using the standard System V termios interface */ static struct termios term; memset((char *)&term,0,sizeof(term)); term.c_iflag = BRKINT | IGNPAR | ICRNL | IXON; #ifdef IMAXBEL term.c_iflag |= IMAXBEL; #endif /* IMAXBEL */ if (!is_eightbit()) term.c_iflag |= ISTRIP; term.c_oflag = OPOST | ONLCR; term.c_cflag = B9600 | CREAD; if (!is_eightbit()) term.c_cflag |= PARENB | CS7; else term.c_cflag |= CS8; term.c_lflag = ISIG | IEXTEN | ICANON | ECHO | ECHOE | ECHOK; #ifdef ECHOCTL term.c_lflag |= ECHOCTL; #endif /* ECHOCTL */ #ifdef ECHOKE term.c_lflag |= ECHOKE; #endif /* ECHOKE */ term.c_cc[VINTR] = 003; /* ^C */ term.c_cc[VQUIT] = 034; /* ^\ */ term.c_cc[VERASE] = 0177; /* DEL */ term.c_cc[VKILL] = 025; /* ^U */ term.c_cc[VEOF] = 004; /* ^D */ term.c_cc[VSTART] = 021; /* ^Q */ term.c_cc[VSTOP] = 023; /* ^S */ term.c_cc[VSUSP] = 032; /* ^Z */ #ifdef VREPRINT term.c_cc[VREPRINT] = 022; /* ^R */ #endif /* VREPRINT */ #ifdef VWERASE term.c_cc[VWERASE] = 027; /* ^W */ #endif /* VWERASE */ #ifdef VLNEXT term.c_cc[VLNEXT] = 026; /* ^V */ #endif /* VLNEXT */ #ifdef VDSUSP term.c_cc[VDSUSP] = 031; /* ^Y */ #endif /* VDSUSP */ #ifdef VDISCARD term.c_cc[VDISCARD] = 017; /* ^O */ #endif /* VDISCARD */ tcsetattr(0,TCSANOW,&term); #else /* BSD_TTY */ /* Use sgtty rather than termios interface to configure the terminal */ int ldisc, lmode; struct sgttyb tty; struct tchars tc; struct ltchars ltc; #ifdef NTTYDISC ldisc = NTTYDISC; (void)ioctl(0,TIOCSETD,&ldisc); #endif /* NTTYDISC */ tty.sg_ispeed = B9600; tty.sg_ospeed = B9600; tty.sg_erase = 0177; tty.sg_kill = 025; /* ^U */ tty.sg_flags = CRMOD | ECHO | EVENP | ODDP; (void)ioctl(0,TIOCSETP,&tty); tc.t_intrc = 003; /* ^C */ tc.t_quitc = 034; /* ^\ */ tc.t_startc = 021; /* ^Q */ tc.t_stopc = 023; /* ^S */ tc.t_eofc = 004; /* ^D */ tc.t_brkc = -1; (void)ioctl(0,TIOCSETC,&tc); ltc.t_suspc = 032; /* ^Z */ ltc.t_dsuspc = 031; /* ^Y */ ltc.t_rprntc = 022; /* ^R */ ltc.t_flushc = 017; /* ^O */ ltc.t_werasc = 027; /* ^W */ ltc.t_lnextc = 026; /* ^V */ (void)ioctl(0,TIOCSLTC,<c); lmode = LCRTBS | LCRTERA | LCTLECH | LPASS8 | LCRTKIL; (void)ioctl(0,TIOCLSET,&lmode); #endif /* BSD_TTY */ scr_get_size(&width,&height); tty_set_size(width,height); #ifdef TIOCCONS if (is_console()) if (ioctl(0,TIOCCONS,0) != 0) { error("Could not set console"); perror(""); } #endif /* TIOCCONS */ } /* 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 run_command(command,argv) char *command; char **argv; { int ptyfd, ttyfd; int uid, gid; int i; extern int messages; if ((tty_name = get_pseudo_tty(&ptyfd,&ttyfd)) == NULL) return(-1); fcntl(ptyfd,F_SETFL,O_NDELAY); fd_width = sysconf(_SC_OPEN_MAX); for (i = 1; i <= 15; i++) signal(i,catch_sig); comm_pid = fork(); if (comm_pid < 0) { error("Can't fork"); return(-1); } if (comm_pid == 0) { struct group *gr; pid_t pgid; if ((pgid = setsid()) < 0) error("failed to start session"); /* Having started a new session, we need to establish * a controlling teletype for it. On some systems * this can be done with an ioctl but on others * we need to re-open the slave tty. */ #ifdef SCTTY_IOCTL (void)ioctl(ttyfd,TIOCSCTTY,0); #else /* !SCTTY_IOCTL */ i = ttyfd; if ((ttyfd = open(tty_name,O_RDWR)) < 0) { error("Can't open teletype %s\n",tty_name); return(-1); } close(i); #endif /* !SCTTY_IOCTL */ uid = getuid(); if ((gr = getgrnam("tty")) != NULL) gid = gr->gr_gid; else gid = -1; fchown(ttyfd,uid,gid); fchmod(ttyfd,messages ? 0620 : 0600); for (i = 0; i < fd_width; i++) if (i != ttyfd) close(i); dup(ttyfd); dup(ttyfd); dup(ttyfd); if (ttyfd > 2) close(ttyfd); #ifdef BSD_TTY ioctl(0, TIOCSPGRP, (char *)&pgid); setpgrp (0, pgid); #endif /* BSD_TTY */ set_ttymodes(); setgid(getgid()); setuid(uid); execvp(command,argv); error("Couldn't execute %s",command); quit(1); } signal(SIGCHLD,catch_child); write_utmp(); return(ptyfd); } /* Tell the teletype handler what size the window is. Called initially from * the child and after a window size change from the parent. */ void tty_set_size(width,height) int width, height; { #ifdef TIOCSWINSZ struct winsize wsize; if (comm_pid < 0) return; wsize.ws_row = height; wsize.ws_col = width; wsize.ws_xpixel = 0; wsize.ws_ypixel = 0; ioctl((comm_pid == 0) ? 0 : comm_fd,TIOCSWINSZ,(char *)&wsize); #endif /* TIOCSWINSZ */ } xvt-2.1.orig/ttyinit.h100644 765 765 2550 6410001753 12744 0ustar cpb4cpb4/* Copyright 1992 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)ttyinit.h 1.1 16/11/93 (UKC) */ #ifdef __STDC__ void quit(int); void tty_set_size(int,int); int run_command(char *, char **); #else /* __STDC__ */ void quit(); void tty_set_size(); int run_command(); #endif /* __STDC__ */ xvt-2.1.orig/xsetup.c100644 765 765 67671 6410001765 12625 0ustar cpb4cpb4/* Copyright 1992, 1993, 1994 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_xsetup_c_sccsid[] = "@(#)xsetup.c 1.4 11/1/94 (UKC)"; #ifdef __STDC__ #include #else #include #endif #include #include #include #include #include #ifdef MAGIC_COOKIE #include #endif /* MAGIC_COOKIE */ #include #include #include #include #include "xvt.h" #include "command.h" #include "ttyinit.h" #include "xsetup.h" #include "screen.h" #include "sbar.h" #ifdef __STDC__ static int error_handler(Display *,XErrorEvent *); static int io_error_handler(Display *); static char *scopy(char *); static int extract_nonX_args(int, char **); static unsigned char *get_resource(char *,char *); static int affirmative(unsigned char *); static void extract_resources(void); static void create_window(int,char **); #else /* __STDC__ */ static int error_handler(); static int io_error_handler(); static char *scopy(); static int extract_nonX_args(); static unsigned char *get_resource(); static int affirmative(); static void extract_resources(); static void create_window(); #endif /* __STDC__ */ #define XVT_CLASS "XTerm" #define SBAR_WIDTH 15 /* width of scroll bar */ #define VT_EVENTS ( ExposureMask |\ EnterWindowMask|\ LeaveWindowMask |\ ButtonPressMask |\ ButtonReleaseMask |\ Button1MotionMask \ ) #define MW_EVENTS ( KeyPressMask |\ FocusChangeMask |\ StructureNotifyMask \ ) #define SB_EVENTS ( ExposureMask |\ EnterWindowMask|\ LeaveWindowMask |\ Button2MotionMask |\ ButtonReleaseMask |\ ButtonPressMask \ ) /* External global variables that are initialised at startup. */ Display *display; Window vt_win; /* vt100 window */ Window sb_win; /* scroll bar window */ Window main_win; /* parent window */ Colormap colormap; XFontStruct *mainfont; /* main font structure */ XFontStruct *boldfont; /* bold font structure */ GC txgc; /* GC for drawing text */ GC negc; /* GC for moving areas without graphics exposure */ GC hlgc; /* GC used for highlighting selections */ GC cugc; /* GC used for the text cursor */ GC sbgc; /* GC used for drawing the scrollbar */ unsigned long foreground; /* foreground pixel value */ unsigned long background; /* background pixel value */ int reverse_wrap = 0; /* enable reverse wrapround */ int debugging = 0; /* enable debugging output */ int messages = 0; /* flag to enable messages */ static char *xvt_name; /* the name the program is run under */ static char *res_name; /* the resource name */ static char *window_name; /* window name for titles etc. */ static char *icon_name; /* name to display in the icon */ static char *name_name = NULL; /* name set with -name option */ static int screen; /* the X screen number */ static Visual *visual; static XrmDatabase rDB; /* merged resources database */ static unsigned long border; /* border pixel value */ static int border_width = 1; static int save_lines = DEF_SAVED_LINES; /* number of saved lines */ static unsigned long cursorclr; static XColor foreground_color; static XColor background_color; static XColor cursor_color; static int iconic = 0; /* start up iconized */ static int logshell = 0; /* flag nonzero if using a login shell */ static int eight_bit_input = 1; /* eight bit input enabled */ static int console_flag = 0; /* true if we want a console window */ static int show_scrollbar = 0; /* scroll-bar displayed if true */ #define OPTABLESIZE 26 static XrmOptionDescRec optable[] = { {"-display", ".display", XrmoptionSepArg, (caddr_t)NULL}, {"-geometry", "*geometry", XrmoptionSepArg, (caddr_t)NULL}, {"-background", "*background", XrmoptionSepArg, (caddr_t)NULL}, {"-bg", "*background", XrmoptionSepArg, (caddr_t)NULL}, {"-foreground", "*foreground", XrmoptionSepArg, (caddr_t)NULL}, {"-fg", "*foreground", XrmoptionSepArg, (caddr_t)NULL}, {"-bd", "*borderColor", XrmoptionSepArg, (caddr_t)NULL}, {"-bw", "*borderWidth", XrmoptionSepArg, (caddr_t)NULL}, {"-font", "*font", XrmoptionSepArg, (caddr_t)NULL}, {"-fn", "*font", XrmoptionSepArg, (caddr_t)NULL}, {"-fb", "*boldFont", XrmoptionSepArg, (caddr_t)NULL}, {"-title", "*title", XrmoptionSepArg, (caddr_t)NULL}, {"-T", "*title", XrmoptionSepArg, (caddr_t)NULL}, {"-n", "*iconName", XrmoptionSepArg, (caddr_t)NULL}, {"-sl", "*saveLines", XrmoptionSepArg, (caddr_t)NULL}, {"-cc", "*charClass", XrmoptionSepArg, (caddr_t)NULL}, {"-cr", "*cursorColor", XrmoptionSepArg, (caddr_t)NULL}, {"-sb", "*scrollBar", XrmoptionNoArg, "on"}, {"-rw", "*reverseWrap", XrmoptionNoArg, "on"}, {"-msg", "*messages", XrmoptionNoArg, "on"}, {"-iconic", "*iconic", XrmoptionNoArg, "on"}, {"-8", "*eightBitInput",XrmoptionNoArg, "on"}, {"-7", "*eightBitInput",XrmoptionNoArg, "off"}, {"-ls", "*loginShell", XrmoptionNoArg, "on"}, {"-sf", "*sunFunctionKeys",XrmoptionNoArg, "on"}, {"-debug", "*debug", XrmoptionNoArg, "on"}, }; static char *usearray[] = { "-e ... execute command with arguments - must be last argument", "-display specify the display (server)", "-geometry the initial window geometry", "-background background colour", "-bg same as -background", "-foreground foreground colour", "-fg same as -foreground", "-bd border colour", "-bw border width", "-font normal font", "-fn font used for bold text", "-name name used for matching X resources", "-title text in window titlebar", "-T same as -title", "-n name in icon or icon window", "-sl number of lines saved after scrolling off window", "-cc character classes for double click", "-cr text cursor colour", "-sb provide an initial scrollbar", "-rw enable reverse wrap", "-msg allow messages", "-iconic start up already iconized", "-8 process eight-bit characters", "-7 strip input and output characters to 7 bits", "-ls run a login shell", "-C connect to console (not all systems)", "-console same as -C", "-sf use Sun function key escape codes", NULL }; static XSizeHints sizehints = { PMinSize | PResizeInc | PBaseSize, 0, 0, 80, 24, /* x, y, width and height */ 1, 1, /* Min width and height */ 0, 0, /* Max width and height */ 1, 1, /* Width and height increments */ {0, 0}, {0, 0}, /* Aspect ratio - not used */ 2 * MARGIN, 2 * MARGIN, /* base size */ 0 }; /* Return true if we should be running a login shell. */ int is_logshell() { return(logshell); } /* Return true is we are handling eight bit characters. */ int is_eightbit() { return(eight_bit_input); } /* Return true if this window should be a console. */ int is_console() { return(console_flag); } /* Error handling function, tidy up and then exit. */ static int error_handler(dpy,evp) Display *dpy; XErrorEvent *evp; { quit(1); return(0); } static int io_error_handler(dpy) Display *dpy; { quit(1); return(0); } /* Utility function to return a malloced copy of a string. */ static char * scopy(str) char *str; { char *s; if ((s = malloc(strlen((char *)str) + 1)) == NULL) abort(); strcpy(s,str); return(s); } /* Do any necessary preprocessing of the environment ready for passing to * the command. */ void fix_environment() { int i, j, k; #ifdef LC_ENV int cols, lines; #endif /* LC_ENV */ char **com_env; extern char **environ; static char *elist[] = { "TERM=", "DISPLAY=", "WINDOWID=", #ifdef LC_ENV "COLUMNS=", "LINES=", #endif /* LC_ENV */ NULL }; char buf[500]; for (i = 0; environ[i] != NULL; i++) ; com_env = (char **)cmalloc((i + 4) * sizeof(char *)); for (i = j = 0; environ[i] != NULL; i++) { for (k = 0; elist[k] != NULL; k++) if (strncmp(elist[k],environ[i],strlen(elist[k])) == 0) break; if (elist[k] == NULL) com_env[j++] = environ[i]; } com_env[j++] = scopy(TERM_ENV); sprintf(buf,"DISPLAY=%s",DisplayString(display)); com_env[j++] = scopy(buf); sprintf(buf,"WINDOWID=%d",(int)main_win); com_env[j++] = scopy(buf); #ifdef LC_ENV scr_get_size(&cols,&lines); sprintf(buf,"LINES=%d",lines); com_env[j++] = scopy(buf); sprintf(buf,"COLUMNS=%d",cols); com_env[j++] = scopy(buf); #endif /* LC_ENV */ com_env[j] = NULL; environ = com_env; } /* Take a pass through the arguments extracting any that do not correspond * to X resources. Recognised arguments are removed from the list and * the new value of argc is returned. */ static int extract_nonX_args(argc,argv) int argc; char **argv; { int i, j; char *s; xvt_name = argv[0]; res_name = NULL; for (j = i = 1; i < argc; i++) { if (strcmp(argv[i],"-name") == 0) { if (argv[++i] != NULL) { res_name = scopy(argv[i]); name_name = scopy(argv[i]); } else error("missing -name argument"); } else if (strcmp(argv[i],"-C") == 0 || strcmp(argv[i],"-console") == 0) { console_flag = 1; } else argv[j++] = argv[i]; } argv[j] = NULL; if (res_name == NULL) { s = strrchr(xvt_name,'/'); if (s != NULL) s++; else s = xvt_name; res_name = scopy(s); } return(j); } /* Open the display, initialise the rDB resources database and create the * window. if command is non-null it is the name of -e option command. * iargc and iargv are the original argc, argv so the can be written to a * COMMAND resource. */ void init_display(argc,argv,iargc,iargv,command) int argc, iargc; char **argv, **iargv; char *command; { char str1[256],str2[256]; char *display_name = NULL; XrmDatabase commandlineDB, serverDB; XrmValue value; XGCValues gcv; char *str_type; char *s; argc = extract_nonX_args(argc,argv); icon_name = name_name != NULL ? name_name : command; window_name = name_name != NULL ? name_name : command; XrmInitialize(); commandlineDB = NULL; XrmParseCommand(&commandlineDB,optable,OPTABLESIZE,res_name,&argc,argv); if (argc > 1) { usage(0); exit(1); } /* See if there was a display named in the command line */ sprintf(str1,"%s.display",res_name); sprintf(str2,"%s.Display",XVT_CLASS); if (XrmGetResource(commandlineDB,str1,str2,&str_type,&value) == True) { strncpy(str1,value.addr,(int)value.size); display_name = str1; } if ((display = XOpenDisplay(display_name)) == NULL) { error("can't open display %s",XDisplayName(display_name)); quit(1); } /* Get the resources from the server if there are any. */ if ((s = XResourceManagerString(display)) != NULL) { serverDB = XrmGetStringDatabase(s); XrmMergeDatabases(serverDB,&rDB); } XrmMergeDatabases(commandlineDB,&rDB); screen = DefaultScreen(display); visual = DefaultVisual(display,screen); colormap = DefaultColormap(display,screen); extract_resources(); #ifdef DEBUG_X XSynchronize(display,True),XSetErrorHandler(abort); #else if (!debugging) { XSetErrorHandler(error_handler); XSetIOErrorHandler(io_error_handler); } #endif /* Get colormap entries and create the graphics contexts. */ if (cursorclr == 0 || DefaultDepth(display,screen) == 1) { /* We are not using a colored text cursor so we can use * read only shared colormap entries for foreground and background. */ if (foreground == 0) XParseColor(display,colormap,"black",&foreground_color); if (XAllocColor(display,colormap,&foreground_color) != 0) foreground = foreground_color.pixel; else { error("can't allocate foreground color %s - using black",s); foreground = BlackPixel(display,screen); } if (background == 0) XParseColor(display,colormap,"white",&background_color); if (XAllocColor(display,colormap,&background_color) != 0) background = background_color.pixel; else { error("can't allocate background color %s - using white",s); background = WhitePixel(display,screen); } if (background == foreground) { /* If the background and foreground colours end up the same then * try and remap the background to something different. This * will only work on a monochrome display. */ char *bgclr; bgclr = foreground == BlackPixel(display,screen) ? "white" : "black"; XParseColor(display,colormap,bgclr,&background_color); if (XAllocColor(display,colormap,&background_color) != 0) background = background_color.pixel; } cursorclr = foreground; } else { unsigned long plane_masks[2]; unsigned long pixels[1]; if (XAllocColorCells(display,colormap,False,plane_masks,2,pixels,1) == 0) { error("Cannot allocate colormap cells"); foreground = BlackPixel(display,screen); background = background_color.pixel; cursorclr = foreground; } else { if (foreground == 0) XParseColor(display,colormap,"black",&foreground_color); foreground_color.pixel = foreground = pixels[0]; foreground_color.flags = DoRed | DoBlue | DoGreen; XStoreColor(display,colormap,&foreground_color); if (background == 0) XParseColor(display,colormap,"white",&background_color); background_color.pixel = background = pixels[0] | plane_masks[0]; background_color.flags = DoRed | DoBlue | DoGreen; XStoreColor(display,colormap,&background_color); background_color.pixel = pixels[0] | plane_masks[1]; XStoreColor(display,colormap,&background_color); cursor_color.pixel = cursorclr = pixels[0] | plane_masks[0] | plane_masks[1]; cursor_color.flags = DoRed | DoBlue | DoGreen; XStoreColor(display,colormap,&cursor_color); } } create_window(iargc,iargv); gcv.foreground = foreground; gcv.background = background; gcv.font = mainfont->fid; txgc = XCreateGC(display,main_win,GCForeground|GCBackground|GCFont,&gcv); gcv.graphics_exposures = False; negc = XCreateGC(display,main_win, GCForeground|GCBackground|GCGraphicsExposures,&gcv); gcv.foreground = foreground; gcv.background = background; sbgc = XCreateGC(display,main_win,GCForeground|GCBackground|GCFont,&gcv); gcv.function = GXinvert; gcv.plane_mask = foreground ^ background; hlgc = XCreateGC(display,main_win,GCFunction | GCPlaneMask,&gcv); gcv.function = GXinvert; gcv.plane_mask = cursorclr ^ background; cugc = XCreateGC(display,main_win,GCFunction | GCPlaneMask,&gcv); /* initialise the screen data structures. */ scr_init(save_lines); sbar_init(); } /* Extract the named resource from the database and return a pointer to a static * string containing it. */ static unsigned char * get_resource(name,class) char *name, *class; { static unsigned char resource[256]; unsigned char str1[256], str2[256]; XrmValue value; char *str_type; sprintf((char *)str1,"%s.%s",res_name,name); sprintf((char *)str2,"%s.%s",XVT_CLASS,class); if (XrmGetResource(rDB,str1,str2,&str_type,&value) == True) { strncpy((char *)resource,value.addr,(int)value.size); return(resource); } /* The following is added for compatibility with xterm. */ sprintf((char *)str1,"%s.vt100.%s",res_name,name); sprintf((char *)str2,"%s.VT100.%s",XVT_CLASS,class); if (XrmGetResource(rDB,str1,str2,&str_type,&value) == True) { strncpy((char *)resource,value.addr,(int)value.size); return(resource); } return(NULL); } /* Return true if s is "on" or "yes". */ static int affirmative(s) unsigned char *s; { if (strcmp((char *)s,"on") == 0) return(1); if (strcmp((char *)s,"yes") == 0) return(1); return(0); } /* Extract the resource fields that are needed to open the window. */ static void extract_resources() { unsigned char *s; int x, y, width, height; int flags; XColor color; /* First get the font since we need it to set the size. */ if ((s = get_resource("font","Font")) == NULL) s = (unsigned char *)DEF_FONT; if ((mainfont = XLoadQueryFont(display,s)) == NULL) { error("can't access font %s, trying %s",s,FIXED_FONT); if ((mainfont = XLoadQueryFont(display,FIXED_FONT)) == NULL) { error("can't access font %s - quitting",FIXED_FONT); quit(1); } } sizehints.width_inc = XTextWidth(mainfont,"M",1); sizehints.height_inc = mainfont->ascent + mainfont->descent; /* Determine whether debugging is enabled. */ if ((s = get_resource("debug","Debug")) != NULL) debugging = affirmative(s); /* Determine whether to allow messages. */ if ((s = get_resource("messages","Messages")) != NULL) messages = affirmative(s); /* Determine whether to start up iconized. */ if ((s = get_resource("iconic","Iconic")) != NULL) iconic = affirmative(s); /* Determine whether to display the scrollbar. */ if ((s = get_resource("scrollBar","ScrollBar")) != NULL) show_scrollbar = affirmative(s); if (show_scrollbar) sizehints.base_width += SBAR_WIDTH; if ((s = get_resource("borderWidth","BorderWidth")) != NULL) border_width = atoi((char *)s); flags = 0; if ((s = get_resource("geometry","Geometry")) != NULL) flags = XParseGeometry(s,&x,&y,&width,&height); if (flags & WidthValue) { sizehints.width = width; sizehints.flags |= USSize; } if (flags & HeightValue) { sizehints.height = height; sizehints.flags |= USSize; } sizehints.width = sizehints.width * sizehints.width_inc + sizehints.base_width; sizehints.height = sizehints.height * sizehints.height_inc + sizehints.base_height; sizehints.min_width = sizehints.width_inc + sizehints.base_width; sizehints.min_height = sizehints.height_inc + sizehints.base_height; if (flags & XValue) { if (flags & XNegative) x = DisplayWidth(display,screen) + x - sizehints.width - 2 * border_width; sizehints.x = x; sizehints.flags |= USPosition; } if (flags & YValue) { if (flags & YNegative) y = DisplayHeight(display,screen) + y - sizehints.height - 2 * border_width; sizehints.y = y; sizehints.flags |= USPosition; } if (flags & XNegative) sizehints.win_gravity = flags & YNegative ? SouthEastGravity : NorthEastGravity; else sizehints.win_gravity = flags & YNegative ? SouthWestGravity : NorthWestGravity; sizehints.flags |= PWinGravity; /* Do the foreground, background and border colours. */ border = foreground; if ((s = get_resource("borderColor","BorderColor")) != NULL) { if (XParseColor(display,colormap,s,&color) == 0) error("invalid border color %s",s); else if (XAllocColor(display,colormap,&color) == 0) error("can't allocate color %s",s); else border = color.pixel; } foreground = 0; if ((s = get_resource("foreground","Foreground")) != NULL) { if (XParseColor(display,colormap,s,&foreground_color) != 0) foreground = 1; else error("invalid foreground color %s",s); } background = 0; if ((s = get_resource("background","Background")) != NULL) { if (XParseColor(display,colormap,s,&background_color) != 0) background = 1; else error("invalid background color %s",s); } cursorclr = 0; if ((s = get_resource("cursorColor","CursorColor")) != NULL) { if (XParseColor(display,colormap,s,&cursor_color) != 0) cursorclr = 1; else error("invalid cursor color %s",s); } /* Get the window and icon names */ if ((s = get_resource("iconName","IconName")) != NULL) { icon_name = scopy((char *)s); window_name = scopy((char *)s); } if ((s = get_resource("title","Title")) != NULL) window_name = scopy((char *)s); if (window_name == NULL) window_name = scopy(res_name); if (icon_name == NULL) icon_name = scopy(res_name); /* Extract the bold font if there is one. */ if ((s = get_resource("boldFont","BoldFont")) != NULL) if ((boldfont = XLoadQueryFont(display,s)) == NULL) error("can't access font %s\n",s); /* Get the character class. */ if ((s = get_resource("charClass","CharClass")) != NULL) scr_char_class(s); /* Get the reverse wrapround flag. */ if ((s = get_resource("reverseWrap","ReverseWrap")) != NULL) reverse_wrap = affirmative(s); /* Get the eight bit flag. */ if ((s = get_resource("eightBitInput","EightBitInput")) != NULL) eight_bit_input = affirmative(s); /* Get the login shell flag. */ if ((s = get_resource("loginShell","LoginShell")) != NULL) logshell = affirmative(s); /* Determine whether to use Sun function key escape codes. */ if ((s = get_resource("sunFunctionKeys","SunFunctionKeys")) != NULL) set_sun_function_keys(affirmative(s)); /* extract xvt specific arguments. */ if ((s = get_resource("saveLines","SaveLines")) != NULL) save_lines = atoi((char *)s); } /* Open the window. */ static void create_window(argc,argv) int argc; char **argv; { XTextProperty wname, iname; XClassHint class; XWMHints wmhints; Cursor cursor; main_win = XCreateSimpleWindow(display,DefaultRootWindow(display), sizehints.x,sizehints.y,sizehints.width,sizehints.height, border_width,foreground,background); if (XStringListToTextProperty(&window_name,1,&wname) == 0) { error("cannot allocate window name"); quit(1); } if (XStringListToTextProperty(&icon_name,1,&iname) == 0) { error("cannot allocate icon name"); quit(1); } class.res_name = res_name; class.res_class = XVT_CLASS; wmhints.input = True; wmhints.initial_state = iconic ? IconicState : NormalState; wmhints.flags = InputHint | StateHint; XSetWMProperties(display,main_win,&wname,&iname,argv,argc, &sizehints,&wmhints,&class); XFree(iname.value); XFree(wname.value); XSelectInput(display,main_win,MW_EVENTS); sb_win = XCreateSimpleWindow(display,main_win,-1,-1,SBAR_WIDTH - 1, sizehints.height,1,border,background); cursor = XCreateFontCursor(display,XC_sb_v_double_arrow); XRecolorCursor(display,cursor,&foreground_color,&background_color); XDefineCursor(display,sb_win,cursor); XSelectInput(display,sb_win,SB_EVENTS); vt_win = XCreateSimpleWindow(display,main_win,0,0, sizehints.width, sizehints.height,0,border,background); if (show_scrollbar) { XMoveWindow(display,vt_win,SBAR_WIDTH,0); XResizeWindow(display,vt_win,sizehints.width - SBAR_WIDTH,sizehints.height); } cursor = XCreateFontCursor(display,XC_xterm); XRecolorCursor(display,cursor,&foreground_color,&background_color); XDefineCursor(display,vt_win,cursor); XSelectInput(display,vt_win,VT_EVENTS); } /* Map the window */ void map_window() { #ifdef LC_ENV XEvent event; #endif /* LC_ENV */ XMapWindow(display,vt_win); if (show_scrollbar) XMapWindow(display,sb_win); XMapWindow(display,main_win); #ifdef LC_ENV /* Setup the window now so that we can add LINES and COLUMNS to * the environment. */ XMaskEvent(display,ExposureMask,&event); resize_window(); scr_reset(); #endif /* LC_ENV */ } /* Called after a possible window size change. If the window size has changed * initiate a redraw by resizing the subwindows and return 1. If the window * size has not changed then return 0; */ int resize_window() { Window root; int x, y; unsigned int width, height, bdr_width, depth; static unsigned int last_width = 0, last_height = 0; XGetGeometry(display,main_win,&root,&x,&y,&width,&height,&bdr_width,&depth); if (height == last_height && width == last_width) return (0); last_height = height; last_width = width; if (show_scrollbar) { XResizeWindow(display,sb_win,SBAR_WIDTH - 1,height); XResizeWindow(display,vt_win,width - SBAR_WIDTH,height); } else XResizeWindow(display,vt_win,width,height); return(1); } /* Toggle scrollbar. */ void switch_scrollbar() { Window root; int x, y; unsigned int width, height, bdr_width, depth; XGetGeometry(display,main_win,&root,&x,&y,&width,&height,&bdr_width,&depth); if (show_scrollbar) { XUnmapWindow(display,sb_win); XMoveWindow(display,vt_win,0,0); width -= SBAR_WIDTH; sizehints.base_width -= SBAR_WIDTH; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | PMinSize | PResizeInc | PBaseSize; XSetWMNormalHints(display,main_win,&sizehints); XResizeWindow(display,main_win,width,height); show_scrollbar = 0; } else { XMapWindow(display,sb_win); XMoveWindow(display,vt_win,SBAR_WIDTH,0); width += SBAR_WIDTH; sizehints.base_width += SBAR_WIDTH; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | PMinSize | PResizeInc | PBaseSize; XSetWMNormalHints(display,main_win,&sizehints); XResizeWindow(display,main_win,width,height); show_scrollbar = 1; } } /* Change the window name displayed in the title bar. */ void change_window_name(str) unsigned char *str; { XTextProperty name; if (XStringListToTextProperty((char **)&str,1,&name) == 0) { error("cannot allocate window name"); return; } XSetWMName(display,main_win,&name); XFree(name.value); } /* Change the icon name. */ void change_icon_name(str) unsigned char *str; { XTextProperty name; if (XStringListToTextProperty((char **)&str,1,&name) == 0) { error("cannot allocate icon name"); return; } XSetWMIconName(display,main_win,&name); XFree(name.value); } /* Print an error message. */ /*VARARGS1*/ void #ifdef __STDC__ error(char *fmt,...) { va_list args; va_start(args,fmt); #else error(va_alist) va_dcl { char *fmt; va_list args; va_start(args); fmt = va_arg(args,char *); #endif fprintf(stderr,"%s: ",xvt_name); vfprintf(stderr,fmt,args); va_end(args); fprintf(stderr,"\n"); } /* Print out a usage message and exit. */ void usage(full) int full; { int i; if (full) { fprintf(stderr,"xvt: permitted arguments are:\n"); for (i = 0; usearray[i] != NULL; i++) fprintf(stderr,"%s\n",usearray[i]); } else { fprintf(stderr,"xvt: unrecognised argument\n"); fprintf(stderr,"Type xvt -help for an option list.\n"); } } /* Send a 'Magic Cookie' authorisation string to the command. */ void send_auth() { #ifdef MAGIC_COOKIE static char hexdigits[] = "0123456789abcdef"; char *display_name, *nptr, *dot; char *buf, *optr; Xauth *auth; int i, nlen, len; struct hostent *h; char hostname[64]; display_name = DisplayString(display); if ((nptr = strchr(display_name, ':')) == NULL) return; if (nptr == display_name || nptr - display_name > sizeof(hostname)) return; memcpy(hostname, display_name, nptr - display_name); hostname[nptr - display_name] = '\0'; ++nptr; if ((h = gethostbyname(hostname)) == NULL) return; if (h->h_addrtype != AF_INET) return; if ((dot = strchr(nptr, '.')) != NULL) nlen = dot - nptr; else nlen = strlen(nptr); auth = XauGetAuthByAddr(FamilyInternet, 4, h->h_addr_list[0], nlen, nptr, 0, ""); if (auth == NULL) return; len = 2 + 2 + 2 + auth->address_length + 2 + auth->number_length + 2 + auth->name_length + 2 + auth->data_length; if ((buf = (char *)cmalloc(len * 2 + 1)) == NULL) { XauDisposeAuth(auth); return; } optr = buf; #define PUTSHORT(o, n) *o++ = (n >> 8) & 0xff, *o++ = n & 0xff #define PUTBYTES(o, s, n) PUTSHORT(o, n), memcpy(o, s, n), o += n PUTSHORT(optr, (len - 2) * 2); PUTSHORT(optr, auth->family); PUTBYTES(optr, auth->address, auth->address_length); PUTBYTES(optr, auth->number, auth->number_length); PUTBYTES(optr, auth->name, auth->name_length); PUTBYTES(optr, auth->data, auth->data_length); #undef PUTSHORT #undef PUTBYTES if (optr != buf + len) abort(); for (i = len - 1; i >= 0; --i) { buf[i * 2 + 1] = hexdigits[buf[i] & 0xf]; buf[i * 2] = hexdigits[(buf[i] >> 4) & 0xf]; } buf[len * 2] = '\r'; send_string((unsigned char *)buf, len * 2 + 1); free(buf); XauDisposeAuth(auth); return; #endif /* MAGIC_COOKIE */ } xvt-2.1.orig/xsetup.h100644 765 765 3542 6410001773 12574 0ustar cpb4cpb4/* Copyright 1992, 1994 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)xsetup.h 1.3 11/1/94 (UKC) */ #ifdef __STDC__ void fix_environment(void); void init_display(int,char **,int,char **,char *); int resize_window(void); void switch_scrollbar(void); void change_window_name(unsigned char *); void change_icon_name(unsigned char *); void error(char *,...); void send_auth(void); void map_window(void); int is_logshell(void); int is_eightbit(void); int is_console(void); void usage(int); #else /* __STDC__ */ void fix_environment(); void init_display(); int resize_window(); void switch_scrollbar(); void change_window_name(); void change_icon_name(); void error(); void send_auth(); void map_window(); int is_logshell(); int is_eightbit(); int is_console(); void usage(); #endif /* __STDC__ */ xvt-2.1.orig/xvt.1100644 765 765 31660 5472175052 12031 0ustar cpb4cpb4'\" t .\" @(#)xvt.1 1.2 16/11/93 (UKC) .TH XVT 1 "10 February 1992" .UC .SH NAME xvt \- VT100 emulator for the X window system .SH SYNOPSIS \fBxvt\fP [ \fIoptions\fP ] .SH DESCRIPTION \fIXvt\fP is a VT100 terminal emulator for X. It is intended as a replacement for \fIxterm\fP(1) for users who do not require the more esoteric features of \fIxterm\fP. Specifically \fIxvt\fP does not implement the Tektronix 4014 emulation, session logging and toolkit style configurability. As a result, \fIxvt\fP uses much less swap space than \fIxterm\fP \- a significant advantage on a machine serving many X sessions. .SH OPTIONS The options supported by \fIxvt\fP (which, with the exception of \fB-msg\fP, are a subset of those supported by \fIxterm\fP) are listed below. Most command line arguments have X resource equivalents and these are listed in the following table. .IP "\fB-e\fP \fIcommand\fP [ \fIarguments\fP ]" Run the command with its command line arguments in the \fIxvt\fP window. If this option is used, it must be the last on the command line. If there is no \fB-e\fP option then the default is to run the program specified by the SHELL environment variable or, failing that, \fIcsh\fP(1). This option also causes the window title and icon name to be set to the name of the program being executed if the are not overwritten by a more specific option. .IP "\fB-display\fP \fIdisplay-name\fP" Attempt to open the \fIxvt\fP window on the named X display. In the absence if this option, the display specified by the DISPLAY environment variable is used. .IP "\fB-geometry\fP \fIwindow-geometry\fP Create the window with the specified X window geometry. .IP "\fB-background\fP \fIcolor\fP Use the specified color as the window's background color. .IP "\fB-bg\fP \fIcolor\fP Same as \fB-background\fP. .IP "\fB-foreground\fP \fIcolor\fP Use the specified colour as the window's foreground color. .IP "\fB-fg\fP \fIcolor\fP Same as \fB-foreground\fP. .IP "\fB-cr\fP \fIcolor\fP Set the color used for the text cursor. .IP "\fB-bw\fP \fInumber\fP Set the window border width to \fInumber\fP pixels. Many window managers ignore existing window borders and construct their own and so, if you are using such a window manager, this option will be ignored. .IP "\fB-bd\fP \fIcolor\fP Set the border color. As with border width, this option will usually be disregarded with respect to the window's outer border. It does, however, set the color of the line separating the scroll bar from the main part of the window. .IP "\fB-font\fP \fIfontname\fP Set the main text font used by \fIxvt\fP. .IP "\fB-fn\fP \fIfontname\fP Same as \fB-font\fP. .IP "\fB-fb\fP \fIfontname\fP Set the font used for the vt100 bold rendition style. If this option is not set then \fIxvt\fP will render in bold by overprinting the normal font. .IP "\fB-name\fP \fIname\fP" Set the name that is used when looking up X resource values for this instance of \fIxvt\fP. This option also sets the icon name and window title unless they are set explicitely. .IP "\fB-title\fP \fItext\fP Set the string that is displayed in the window's title bar if it has one. .IP "\fB-T\fP \fItext\fP Same as \fB-title\fP .IP "\fB-n\fP \fItext\fP Set the name that will be used to label the window's icon or displayed in an icon manager window. This option also sets the window's title unless it is set expicitely. .IP "\fB-sl\fP \fInumber\fP Set an upper bound for the number of lines that will be saved when they have scrolled off the top of the window. .IP "\fB-sb\fP Start up with the scrollbar visible. The scrollbar can be displayed or hidden at any time simply by holding down the CONTROL key on the keyboard and pressing any mouse button. The visibility of the scrollbar does not determine whether scrolled text is saved or not \- as with \fIxterm\fP, text scrolled off the top of the window is always saved up to the current maximum number of lines. .IP "\fB-rw\fP Enable reverse wrapping of the cursor so that, for example, lines typed to a shell that are longer than the width of the screen can be edited. This is the same as the \fIxterm\fP reverse wrap option. .IP "\fB-cc\fP \fIstring\fP Input or modify the character classes that are used to determine what is a word when a double click is used to select a word of displayed text. This is identical to the same option in \fIxterm\fP \- see the xterm manual page for a description of the syntax of \fIstring\fP. .IP "\fB-iconic\fP Start up with the window already iconized. .IP "\fB-msg\fP Enable messages to the terminal window from programs like \fIwrite\fP(1). By default, \fIxvt\fP windows have messages disabled. Executing an \fIxvt\fP with the \fB-msg\fP option has the same effect as running it normally and then executing the command \fImesg y\fP to enable messages. .IP \fB-8\fP Treat characters as having eight bits \- this is the default. When in eight bit mode, \fIxvt\fP displays eight bit characters and pressing a keyboard key with the \fIMeta\fP key held down generates the character code with the MSB set. .IP \fB-7\fP Treat characters as having seven bits. In this mode, each character is stripped to seven bits before it is displayed and pressing a keybaord key with the \fIMeta\fP key held down causes the normal character to be preceeded by the Escape character. .IP \fB-ls\fP Run a login shell. This option causes \fIxvt\fP to execute its shell with a name beginning with `-'. In the case of \fIcsh\fP(1) this results in the \fI.login\fP and \fI.logout\fP files being interpreted at the start and end of the session. .IP "\fB-sf\fP Enable Sun function key escape codes. The default is standard \fIxterm\fP compatible function codes. .IP \fB-rv\fP Run in reverse video \- that is, exchange the foreground and background colors. This option has no effect if either the foreground ar background color is set explicitely. .IP \fB-C\fP Connect this terminal to the system console. This option is only implemented for SunOS 4 and for a user who has read and write access to /dev/console. .IP \fB-console\fP Same as \fB-C\fP. .SH X RESOURCES Almost all the command line options have X resource counterparts and these are listed in the following table. Like \fIxterm\fP, \fIxvt\fP uses the class name \fIXTerm\fP and so resource options set for \fIXTerm\fP will work for both \fIxterm\fP and \fIxvt\fP windows. .sp .\" troff version of table .if n .ig IG .TS center box tab(/) ; cb s s c | c s c | c c l | l | l . Command line options and X resources _ /X resource Command line/Instance/Class = -background or -bg/background/Background -bd/borderColor/BorderColor -bw/borderWidth/BorderWidth -C or -console/\fINone\fP/\fINone\fP -cc/charClass/CharClass -cr/cursorColor/CursorColor -display/\fINone\fP/\fINone\fP -e/\fINone\fP/\fINone\fP -fb/boldFont/BoldFont -font or -fn/font/Font -foreground or -fg/foreground/Foreground -geometry/geometry/Geometry -iconic/iconic/Iconic -ls/loginShell/LoginShell -msg/messages/Messages -n/iconName/IconName -name/\fINone\fP/\fINone\fP -rv/reverseVideo/ReverseVideo -rw/reverseWrap/ReverseWrap -sb/scrollBar/ScrollBar -sf/sunFunctionKeys/SunFunctionKeys -sl/saveLines/SaveLines -title or -T/title/Title -8 (on) and -7 (off)/eightBitInput/EightBitInput .TE .IG .\" nroff version of table .if t .ig IG .TS center tab(/) ; cb s s c c s c c c l l l . Command line options and X resources _ /X resource Command line/Instance/Class = -background or -bg/background/Background -bd/borderColor/BorderColor -bw/borderWidth/BorderWidth -C or -console/-/- -cc/charClass/CharClass -cr/cursorColor/CursorColor -display/-/- -e/-/- -fb/boldFont/BoldFont -font or -fn/font/Font -foreground or -fg/foreground/Foreground -geometry/geometry/Geometry -iconic/iconic/Iconic -ls/loginShell/LoginShell -msg/messages/Messages -n/iconName/IconName -name/-/- -rv/reverseVideo/ReverseVideo -rw/reverseWrap/ReverseWrap -sb/scrollBar/ScrollBar -sf/sunFunctionKeys/SunFunctionKeys -sl/saveLines/SaveLines -title or -T/title/Title -8 (on) and -7 (off)/eightBitInput/EightBitInput .TE .IG .SH NAMES TITLES AND ICON NAMES One occasionally confusing aspect of \fIxvt\fP and other X applications is the collection of names that an application window can have and the relationship between the names and the command line options used to set them. This section attempts to make the situation a bit clearer in the case of \fIxvt\fP. .LP In fact, each terminal window has three names, its resource name, its title and its icon name. These three names are distinct and have different functions, although they usually have the same value. The resource name is the command name used to identify X resource options in the resources database, The title is the text that is displayed in the title bar, if there is one, and the icon name is the name that appears in the window's icon or represents it in the icon manager window. .LP The rule about which option sets which name is that \fB-name\fP and \fB-e\fP set both the title and the icon name in addition to their main function and \fB-n\fP sets the title as well as the icon name. Conflicts are resolved by giving the options priorities which are, in increasing order, \fB-e\fP, \fB-name\fP, \fB-n\fP and \fB-title\fP. Hence, for example, \fB-e\fP only sets the title if none of the other options is used. .SH THE SCROLL BAR Lines of text that scroll off the top of the \fIxvt\fP window are saved automatically (up to a preset maximum number) and can be viewed by scrolling them back into the window with the scrollbar. The scrollbar itself can be displayed or hidden by clicking any mouse button in the window while holding down the CONTROL key on the keyboard. When using the scrollbar, the left and right mouse buttons are used for scrolling by a few lines at a time and the middle button is used for continuous scrolling. To use the middle button, press it in the scroll bar and hold it down. the central shaded part of the scrollbar will then attach itself to the cursor and can be slid up or down to show different parts of the sequence of saved lines. When scrolling with the left and right buttons, the left button is used to scroll up and the right is used to scroll down. Assuming that there are enough hidden lines, the distance scrolled with either button is equal to the number of lines between the cursor and the top of the window. Hence, pressing the left cursor opposite a line of text will result in that line being moved to be the top of the window and pressing the right button will cause the top line to be moved down so that it is opposite the cursor. .SH TEXT SELECTION AND INSERTION \fIXvt\fP uses the same kind of text selection and insertion mechanism as \fIxterm\fP. Pressing and releasing the middle mouse button in an \fIxvt\fP window causes the current text selection to be inserted as if it had been typed on the keyboard. For the insertion to take place, both the button press and the button release need to be done with the cursor in the \fIxvt\fP window. .LP The left and right mouse buttons are used to select text, with the left button being used to start a selection and the right button being used to modify an existing selection. Any continuous block of displayed text can be selected. If both ends of the text block are visible in the window then the easiest way to select it is to position the cursor at one end and press the left mouse button, then drag the cursor to the other end with the button held down before releasing the button. If the block is larger than the window then you must first use the left mouse button to select one end, then use the scroll bar to scroll the other end into view and finally use the right mouse button to extend the selection. The effect of pressing the right mouse button is to move the nearest end of the current selection to the current cursor position. .LP The other way to make selections in xvt is to use double and triple clicks of the left mouse button with a double click selecting a word and a triple click selecting a whole line. For this purpose, a word is a sequence of characters in the same class. The default character classes are: .IP + 3 the upper and lower case letters, digits and '_' (underscore) all in one class; .IP + the white space characters all in one class; .IP + each of the remaining punctuation characters in a class by itself. .LP If you want to change the character classes so that, for example, you can select a UNIX pathname or a mail address in one double click, then you can do so by using the \fB-cc\fP command line option or the \fIcharClass\fP X resource. Multiple clicking can be combined with dragging to select a sequence of consecutive words or lines. .LP Although \fIxvt\fP essentially mimics the behaviour of \fIxterm\fP in its support of text selection and insertion, there are a couple of minor differences: .IP + 3 \fIxvt\fP respects TAB characters in selected text and does not automatically convert them into spaces as does \fIxterm\fP; .IP + \fIxvt\fP will let you abort a text insertion if you realise you have made a mistake before releasing the middle mouse button. .SH BUGS Pasting very large quantities of text does not work. .SH AUTHOR John Bovey, University of Kent, 1992 and 1993. xvt-2.1.orig/xvt.c100644 765 765 25336 6410002010 12066 0ustar cpb4cpb4/* Copyright 1992, 1994 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ char xvt_xvt_c_sccsid[] = "@(#)xvt.c 1.4 11/1/94 (UKC)"; #include #include #include #include "xvt.h" #include "command.h" #include "ttyinit.h" #include "xsetup.h" #include "screen.h" #include "sbar.h" #include "token.h" #ifdef UKC_LOCATIONS #define LOCTMPFILE "/etc/loctmp" #endif /* UKC_LOCATIONS */ #ifdef __STDC__ void main(int,char **); #else void main(); #endif extern int debugging; static int size_set = 0; /* flag set once the window size has been set */ /* Malloc that checks for NULL return. */ void * cmalloc(size) int size; { char *s; if ((s = malloc((unsigned int)size)) == NULL) abort(); return((void *)s); } /* 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. */ void main(argc,argv) int argc; char **argv; { int i, n, x, y; int mode; int iargc; struct tokenst token; char *shell, *command = NULL, *s; char **com_argv; char *shell_argv[2]; static char **iargv; /* Check for a -V or -help option. */ for (i = 0; i < argc; i++) { if (strcmp(argv[i],"-V") == 0) { printf("xvt version %s\n",VERSION); exit(0); } if (strcmp(argv[i],"-help") == 0) { usage(1); exit(1); } } /* Make a copy of the command line argument array */ iargv = (char **)cmalloc((argc + 1) * sizeof(char *)); for (i = 0; i < argc; i++) { iargv[i] = (char *)cmalloc(strlen(argv[i]) + 1); strcpy(iargv[i],argv[i]); } iargv[i] = NULL; iargc = argc; com_argv = NULL; /* Look for a -e flag and if it is there use it to initialise * the command and its arguments. */ for (i = 0; i < argc; i++) if (strcmp(argv[i],"-e") == 0) break; if (i < argc - 1) { argv[i] = NULL; com_argv = argv + i + 1; command = argv[i + 1]; argc = i; } init_display(argc,argv,iargc,iargv,command); map_window(); if (command == NULL) { /* Set up a shell command and arguments */ if ((shell = getenv("SHELL")) != NULL) command = shell; else command = COMMAND; if ((s = strrchr(command,'/')) != NULL) s++; else s = command; shell_argv[0] = (char *)cmalloc(strlen(s) + 2); sprintf(shell_argv[0],"%s%s",is_logshell() ? "-" : "",s); shell_argv[1] = NULL; com_argv = shell_argv; } fix_environment(); init_command(command,com_argv); for (;;) { get_token(&token); switch (token.tk_type) { case TK_STRING : scr_string(token.tk_string,token.tk_length,token.tk_nlcount); break; case TK_CHAR : switch (token.tk_char) { case '\n' : scr_index(); break; case '\r' : scr_move(0,0,ROW_RELATIVE); break; case '\b' : scr_backspace(); break; case '\t' : scr_tab(); break; case '\007' : /* bell */ scr_bell(); break; case '\016' : /* change to char set G1 */ scr_shift(1); break; case '\017' : /* change to char set G0 */ scr_shift(0); break; } break; case TK_EOF : quit(0); break; case TK_ENTRY : /* keyboard focus changed */ scr_focus(1,token.tk_arg[0]); break; case TK_FOCUS : scr_focus(2,token.tk_arg[0]); break; case TK_EXPOSE : /* window exposed */ switch (token.tk_region) { case SCREEN : if (!size_set) { /* Force a full reset if an exposure event * arrives after a resize. */ scr_reset(); size_set = 1; } else { scr_refresh(token.tk_arg[0],token.tk_arg[1], token.tk_arg[2],token.tk_arg[3]); } break; case SCROLLBAR : sbar_reset(); break; } break; case TK_RESIZE : if (resize_window() != 0) size_set = 0; break; case TK_TXTPAR : /* change title or icon name */ switch (token.tk_arg[0]) { case 0 : change_window_name(token.tk_string); change_icon_name(token.tk_string); break; case 1 : change_icon_name(token.tk_string); break; case 2 : change_window_name(token.tk_string); break; } break; case TK_SBSWITCH : switch_scrollbar(); break; case TK_SBGOTO : scr_move_to(token.tk_arg[0]); break; case TK_SBUP : scr_move_by(token.tk_arg[0]); break; case TK_SBDOWN : scr_move_by(-token.tk_arg[0]); break; case TK_SELSTART : scr_start_selection(token.tk_arg[0],token.tk_arg[1],CHAR); break; case TK_SELEXTND : scr_extend_selection(token.tk_arg[0],token.tk_arg[1],0); break; case TK_SELDRAG : scr_extend_selection(token.tk_arg[0],token.tk_arg[1],1); break; case TK_SELWORD : scr_start_selection(token.tk_arg[0],token.tk_arg[1],WORD); break; case TK_SELLINE : scr_start_selection(token.tk_arg[0],token.tk_arg[1],LINE); break; case TK_SELECT : scr_make_selection(token.tk_arg[0]); break; case TK_SELCLEAR : scr_clear_selection(); break; case TK_SELREQUEST : scr_send_selection(token.tk_arg[0],token.tk_arg[1], token.tk_arg[2],token.tk_arg[3]); break; case TK_SELINSRT : scr_request_selection(token.tk_arg[0],token.tk_arg[1],token.tk_arg[2]); break; case TK_SELNOTIFY : scr_paste_primary(token.tk_arg[0],token.tk_arg[1],token.tk_arg[2]); break; case TK_CUU : /* cursor up */ n = token.tk_arg[0]; n = n == 0 ? -1 : -n; scr_move(0,n,ROW_RELATIVE | COL_RELATIVE); break; case TK_CUD : /* cursor down */ n = token.tk_arg[0]; n = n == 0 ? 1 : n; scr_move(0,n,ROW_RELATIVE | COL_RELATIVE); break; case TK_CUF : /* cursor forward */ n = token.tk_arg[0]; n = n == 0 ? 1 : n; scr_move(n,0,ROW_RELATIVE | COL_RELATIVE); break; case TK_CUB : /* cursor back */ n = token.tk_arg[0]; n = n == 0 ? -1 : -n; scr_move(n,0,ROW_RELATIVE | COL_RELATIVE); break; case TK_HVP : case TK_CUP : /* position cursor */ if (token.tk_nargs == 1) if (token.tk_arg[0] == 0) { x = 0; y = 0; } else { x = 0; y = token.tk_arg[0] - 1; } else { y = token.tk_arg[0] - 1; x = token.tk_arg[1] - 1; } scr_move(x,y,0); break; case TK_ED : scr_erase_screen(token.tk_arg[0]); break; case TK_EL : scr_erase_line(token.tk_arg[0]); break; case TK_IL : n = token.tk_arg[0]; if (n == 0) n = 1; scr_insert_lines(n); break; case TK_DL : n = token.tk_arg[0]; if (n == 0) n = 1; scr_delete_lines(n); break; case TK_DCH : n = token.tk_arg[0]; if (n == 0) n = 1; scr_delete_characters(n); break; case TK_ICH : n = token.tk_arg[0]; if (n == 0) n = 1; scr_insert_characters(n); break; case TK_DA : cprintf("\033[?6c"); /* I am a VT102 */ break; case TK_TBC : break; case TK_SET : case TK_RESET : mode = (token.tk_type == TK_SET) ? HIGH : LOW; if (token.tk_private == '?') { switch (token.tk_arg[0]) { case 1 : set_cur_keys(mode); break; case 6 : scr_set_decom(mode); break; case 7 : scr_set_wrap(mode); break; case 47 : /* switch to main screen */ scr_change_screen(mode); break; } } else if (token.tk_private == 0) { switch (token.tk_arg[0]) { case 4 : scr_set_insert(mode); break; } } break; case TK_SGR : if (token.tk_nargs == 0) scr_change_rendition(RS_NONE); else { for (i = 0; i < token.tk_nargs; i++) { switch (token.tk_arg[i]) { case 0 : scr_change_rendition(RS_NONE); break; case 1 : scr_change_rendition(RS_BOLD); break; case 4 : scr_change_rendition(RS_ULINE); break; case 5 : scr_change_rendition(RS_BLINK); break; case 7 : scr_change_rendition(RS_RVID); break; } } } break; case TK_DSR : /* request for information */ switch (token.tk_arg[0]) { case 6 : scr_report_position(); break; case 7 : /* display name */ scr_report_display(); break; case 8 : /* send magic cookie */ send_auth(); break; } break; case TK_DECSTBM : /* set top and bottom margins */ if (token.tk_private == '?') /* xterm uses this combination to reset parameters. */ break; if (token.tk_nargs < 2 || token.tk_arg[0] >= token.tk_arg[1]) scr_set_margins(0,10000); else scr_set_margins(token.tk_arg[0] - 1,token.tk_arg[1] - 1); break; case TK_DECSWH : /* ESC # digit */ if (token.tk_arg[0] == '8') scr_efill(); /* fill screen with Es */ break; case TK_SCS0 : switch (token.tk_arg[0]) { case 'A' : scr_set_char_set(0,CS_UKASCII); break; case 'B' : scr_set_char_set(0,CS_USASCII); break; case '0' : scr_set_char_set(0,CS_SPECIAL); break; } break; case TK_SCS1 : switch (token.tk_arg[0]) { case 'A' : scr_set_char_set(1,CS_UKASCII); break; case 'B' : scr_set_char_set(1,CS_USASCII); break; case '0' : scr_set_char_set(1,CS_SPECIAL); break; } break; case TK_DECSC : scr_save_cursor(); break; case TK_DECRC : scr_restore_cursor(); break; case TK_DECPAM : set_kp_keys(HIGH); break; case TK_DECPNM : set_kp_keys(LOW); break; case TK_IND : /* Index (same as \n) */ scr_index(); break; case TK_NEL : break; case TK_HTS : break; case TK_RI : /* Reverse index */ scr_rindex(); break; case TK_SS2 : break; case TK_SS3 : break; case TK_DECID : cprintf("\033[?6c"); /* I am a VT102 */ break; } #ifdef DEBUG if (debugging) show_token(&token); #endif /* DEBUG */ } } xvt-2.1.orig/xvt.h100644 765 765 4261 6410236472 12072 0ustar cpb4cpb4/* Copyright 1992, 1997 John Bovey, University of Kent at Canterbury. * * Redistribution and use in source code and/or executable forms, with * or without modification, are permitted provided that the following * condition is met: * * Any redistribution must retain the above copyright notice, this * condition and the following disclaimer, either as part of the * program source code included in the redistribution or in human- * readable materials provided with the redistribution. * * THIS SOFTWARE IS PROVIDED "AS IS". Any express or implied * warranties concerning this software are disclaimed by the copyright * holder to the fullest extent permitted by applicable law. In no * event shall the copyright-holder be liable for any damages of any * kind, however caused and on any theory of liability, arising in any * way out of the use of, or inability to use, this software. * * ------------------------------------------------------------------- * * In other words, do not misrepresent my work as your own work, and * do not sue me if it causes problems. Feel free to do anything else * you wish with it. */ /* @(#)xvt.h 1.3 16/11/93 (UKC) */ #define VERSION "2.1" /* Overall release number of the current version */ #define MARGIN 2 /* gap between the text and the window edges */ /* Some wired in defaults so we can run without any external resources. */ #define DEF_FONT "8x13" #define FIXED_FONT "fixed" /* last resort font */ #define DEF_SAVED_LINES 64 /* number of saved lines that have scrolled of the top */ #define TERM_ENV "TERM=xterm" #define COMMAND "/bin/csh" /* default command to run */ /* arguments to set and reset functions. */ #define LOW 0 #define HIGH 1 #ifdef __STDC__ void *cmalloc(int); #else /* __STDC__ */ void *cmalloc(); #endif /* __STDC__ */ #ifdef __STDC__ /* Standard system prototypes included here because they are not in a convenient * system header file. */ #ifdef SUNOS5 int gethostname(char *,int); int getdtablesize(); int grantpt(int); int unlockpt(int); char *ptsname(int); #else /* !SUNOS5 */ #ifndef LINUX int ioctl(int fd, unsigned request, char *arg); #endif /* LINUX */ #endif /* !SUNOS5 */ #endif /* __STDC__ */