[comp.sources.sun] v01i050: DGtool - Data General terminal emulator

mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) (07/21/89)

Submitted-by: ksp@maxwell.nde.swri.edu
Posting-number: Volume 1, Issue 50
Archive-name: dgtool

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	README
#	COPYRIGHT
#	Makefile
#	dg.1
#	dg.c
#	dgtool.1
#	dgtool.c
#	dgtool.icon
# This archive created: Fri Jun 30 08:54:06 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(560 characters)'
if test -f 'README'
then
	echo shar: over-writing existing file "'README'"
fi
sed 's/^X//' << \SHAR_EOF > 'README'
X
XThis is a very simple dg terminal emulator. At this time
X(30 June 1989) it provides a d460 type of function key
Xsupport and a d6053 type of screen emulation.
X
XChanges and enhancements to the code are encouraged.
X
XPlease mail a copy of fixes or enhancements to:
X
Xksp@maxwell.nde.swri.edu
X
XNotes:
X	You will need to change the path at the top of
X	dgtool.c to the path you will use for `dg'.
X
X
X		Good luck,
X
X		  -keith
X
XKeith S. Pickens           Southwest Research Institute
Xksp@maxwell.nde.swri.edu
X{sun!texsun, gatech!petro, cs.utexas.edu}!swrinde!maxwell!ksp
SHAR_EOF
if test 560 -ne "`wc -c 'README'`"
then
	echo shar: error transmitting "'README'" '(should have been 560 characters)'
fi
echo shar: extracting "'COPYRIGHT'" '(766 characters)'
if test -f 'COPYRIGHT'
then
	echo shar: over-writing existing file "'COPYRIGHT'"
fi
sed 's/^X//' << \SHAR_EOF > 'COPYRIGHT'
X
XCopyright (c) 1989 Southwest Research Institute
XAll rights reserved.
X
XRedistribution and use in source and binary forms are permitted
Xprovided that the above copyright notice and this paragraph are
Xduplicated in all such forms and that any documentation,
Xadvertising materials, and other materials related to such
Xdistribution and use acknowledge that the software was developed
Xby Southwest Research Institute.  The name of Southwest Research
XInstitute may not be used to endorse or promote products derived
Xfrom this software without specific prior written permission.
XTHIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
XIMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
XWARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
SHAR_EOF
if test 766 -ne "`wc -c 'COPYRIGHT'`"
then
	echo shar: error transmitting "'COPYRIGHT'" '(should have been 766 characters)'
fi
echo shar: extracting "'Makefile'" '(187 characters)'
if test -f 'Makefile'
then
	echo shar: over-writing existing file "'Makefile'"
fi
sed 's/^X//' << \SHAR_EOF > 'Makefile'
XCFLAGS= -O
XLDFLAGS= 
X
Xall: dg dgtool
X
Xdg: dg.o
X	cc ${LDFLAGS} -o dg dg.o
X
Xdgtool: dgtool.o
X	 cc ${LDFLAGS} -o dgtool dgtool.o -lsuntool -lsunwindow -lpixrect
X
Xclean:
X	rm -f *.o dg dgtool
SHAR_EOF
if test 187 -ne "`wc -c 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 187 characters)'
fi
echo shar: extracting "'dg.1'" '(1461 characters)'
if test -f 'dg.1'
then
	echo shar: over-writing existing file "'dg.1'"
fi
sed 's/^X//' << \SHAR_EOF > 'dg.1'
X.\" Copyright (c) 1989 Southwest Research Institute
X.\" All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms are permitted
X.\" provided that the above copyright notice and this paragraph are
X.\" duplicated in all such forms and that any documentation,
X.\" advertising materials, and other materials related to such
X.\" distribution and use acknowledge that the software was developed
X.\" by Southwest Research Institute.  The name of Southwest Research
X.\" Institute may not be used to endorse or promote products derived
X.\" from this software without specific prior written permission.
X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X.\"
X.TH DG 1L "30 June 1989"
X.SH NAME
Xdg\- provide a Data General terminal emulation
X.SH SYNOPSIS
X.B dg
X.I serial line
X[
X.I baud rate
X]
X.SH DESCRIPTION
X.I dg
Xprovides a serial line
Xinterface for a Data General system.
X.I dg
Xonly provides cursor motion emulation for the common DG 6053
Xcommands.
XIt is not complete.
X.SH OPTIONS
X.LP
XThe first argument of
X.I dg
Xspecifies which serial line to use when accessing the DG.
XThe second argument is optional and specifies the baud rate to
Xbe used in communicating with the DG.
XIf no baud rate is given 9600 is used.
X.SH "SEE ALSO"
Xdgtool(1L)
X.SH AUTHOR
XKeith S. Pickens, Southwest Research Institute
SHAR_EOF
if test 1461 -ne "`wc -c 'dg.1'`"
then
	echo shar: error transmitting "'dg.1'" '(should have been 1461 characters)'
fi
echo shar: extracting "'dg.c'" '(7795 characters)'
if test -f 'dg.c'
then
	echo shar: over-writing existing file "'dg.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'dg.c'
X/*
X * Copyright (c) 1989 Southwest Research Institute
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by Southwest Research Institute.  The name of Southwest Research
X * Institute may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xstatic char     sccsid[] = "@(#)dg.c	1.5 6/29/89             Copyright (c) 1989\
X by Southwest Research Institute, San Antonio, Texas";
X#endif
X
X#include <stdio.h>
X#include <signal.h>
X#include <sgtty.h>
X#include <sys/wait.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netdb.h>
X
X#define	queue_char( c )	*end_of_queue++ = c 
X#define	flush_the_queue()	{\
Xwrite(1, write_queue, end_of_queue - write_queue);\
Xend_of_queue = write_queue;\
X}
X
Xchar buf1[256];
Xchar buf0[256];
X
Xchar	write_queue[2048];
Xchar	motion_buf[16];
Xchar	*end_of_queue;
X
Xint master, slave, child, pid;
Xchar linec, linen;
X
Xstruct baud_tab {
X	char	*baud_string;
X	int	baud_rate;
X} baud_tab[] = {
X	"50",	B50,
X	"75",	B75,
X	"110",	B110,
X	"134",	B134,
X	"150",	B150,
X	"200",	B200,
X	"300",	B300,
X	"600",	B600,
X	"1200", B1200,
X	"1800", B1800,
X	"2400", B2400,
X	"4800",	B4800,
X	"9600",	B9600,
X	"19200",	EXTA,
X	NULL,	0
X};
X
Xstruct sgttyb tmode;
Xint savemode;
Xint fd, tflag;
Xchar	*host;
X
Xdone()
X{
X     union wait status;
X
X     if (wait3(&status, WNOHANG, 0) == 0)
X	  return;
X
X     ioctl (0, TIOCNXCL, &tmode);
X     tmode.sg_flags = savemode;
X     ioctl (0, TIOCSETP, &tmode);
X     kill(pid, SIGTERM);
X     kill(0, SIGTERM);
X     exit(0);
X
X}
X
X
Xmain( argc, argv)
Xint	argc;
Xchar	**argv;
X{
X     int	baud = B9600;
X     int	is_host = 0;
X
X     end_of_queue = write_queue;
X
X     if ((argc > 3) || (argc < 2) ) {
X	  fprintf(stderr, "dg /dev/tty?|hostname  [buad]\n");
X	  fprintf(stderr, "type ^~ to exit\n");
X	  exit(1);
X     }
X
X     host = argv[1];
X     if (gethostbyname(host) != NULL)
X	  is_host = 1;
X
X     if (is_host) {
X	  setup_master();
X	  signal(SIGCHLD, done);
X	  fd = master;
X     } else {
X	  fd = open(*(++argv), 2);
X	  argc--;
X
X	  if (argc > 1) {
X	       baud = find_baud(*(++argv));
X	  }
X
X	  if (fd < 0) {
X	       fprintf(stderr, "dg: can't open the line to the DG or find a host\n");
X	       exit(1);
X	  }
X     }
X     ioctl (fd,TIOCGETP, &tmode);
X     tmode.sg_flags = RAW + TANDEM;
X     tmode.sg_ispeed = baud;
X     tmode.sg_ospeed = baud;
X     ioctl (fd,TIOCSETP, &tmode);
X     ioctl (fd,TIOCEXCL, &tmode);
X
X     ioctl (0,TIOCGETP, &tmode);
X     savemode = tmode.sg_flags;
X     tmode.sg_flags = RAW;
X     ioctl (0,TIOCSETP, &tmode);
X
X     pid = fork();
X     if (pid) {
X	  write(fd, buf1, strlen(buf1));
X	  writer();
X     } else {
X	  if (is_host) {
X	       if (fork()) {
X		    reader();
X	       } else {
X		    start_telnet();
X	       }
X	  } else {
X	       reader();
X	  }
X     }
X}
X
Xqueue_string(string)
Xchar	*string;
X{
X	register char	*cp;
X
X	cp = string;
X	while (*cp)
X		*end_of_queue++ = *cp++;
X}
X
Xfind_baud(string)
Xchar *string;
X{
X	struct baud_tab	*btp;
X
X	btp = baud_tab;
X
X	while(btp->baud_string != NULL) {
X		if (strcmp (string, btp->baud_string) == 0)
X			return(btp->baud_rate);
X		btp++;
X	}
X	fprintf(stderr, "dg: unknown baud rate\n");
X	fprintf(stderr, "known baud rates are:\n");
X
X	btp = baud_tab;
X	while(btp->baud_string != NULL) {
X		fprintf(stderr, "\t%s\n", btp->baud_string);
X		btp++;
X	}
X	exit(1);
X}
X
Xstart_telnet()
X{
X     int t;
X     char *term, *getenv(), *telnet, *tail, *rindex();
X
X     telnet = "/usr/ucb/telnet";
X     tail = "telnet";
X     
X     if ((t = open("/dev/tty", 2)) >= 0) {
X	  ioctl(t, TIOCNOTTY, (char *)0);
X	  close(t);
X     }
X     setup_slave();
X     close(master);
X     dup2(slave, 0);
X     dup2(slave, 1);
X     dup2(slave, 2);
X     close(slave);
X     execl(telnet, tail, host, (char *)0);
X     perror(telnet);
X     fail();
X}
X
Xfail()
X{
X     kill(0, SIGTERM);
X     exit(0);
X}
X
Xsetup_master()
X{
X     char line[11];
X
X     for (linec = 'p'; linec <= 's'; linec++) {
X	  sprintf(line, "/dev/pty%c0", linec);
X	  if (access(line, 0) != 0)
X	       break;
X	  for (linen = 0; linen < 16; linen++) {
X	       sprintf(line, "/dev/pty%c%1x", linec, linen);
X	       master = open(line, 2);
X	       if (master >= 0) {
X		    return;
X	       }
X	  }
X     }
X     fprintf(stderr, "Can't find a pty\n");
X     fail();
X}
X
Xsetup_slave()
X{
X     char line[11];
X
X     sprintf(line, "/dev/tty%c%1x", linec, linen);
X     slave = open(line, 2);
X     if (slave < 0) {
X	  perror(line);
X	  fail();
X     }
X}
X
Xreader()
X{
X     register int	count;
X     register int	index;
X     register int	row, col;
X     register char	*cp, *end, c;
X
X     for(;;) {
X	  count = read(fd, buf0, 256);
X	  end = buf0 + count;
X	  for (cp = buf0; cp < end; cp++) {
X	       c = *cp & 0177;
X	       switch(c) {
X	       case '\000':
X		    break;
X	       case '\003':
X		    break;
X	       case '\005':	/* read cursor position - this is a real hack */
X		    queue_string("\033[1;1H");
X		    write(fd, "\037\000\000", 3);
X		    break;
X	       case '\031':	/* bc=^y */
X		    queue_string("\010");
X		    break;
X	       case '\020':	/* cm=4^p%r%.%. */
X		    cp++;
X		    if (cp >= end) {
X			 count = read(fd, buf0, 1);
X			 end = buf0 + count;
X			 cp = buf0;
X		    }
X		    col = *cp & 0177;
X		    cp++;
X		    if (cp >= end) {
X			 count = read(fd, buf0, 1);
X			 end = buf0 + count;
X			 cp = buf0;
X		    }
X		    row = *cp & 0177;
X		    col++;
X		    row++;
X		    sprintf(motion_buf, "\033[%d;%dH", row, col);
X		    queue_string(motion_buf);
X		    break;
X	       case '\036':	/* extended commands */
X		    cp++;
X		    if (cp >= end) {
X			 count = read(fd, buf0, 1);
X			 end = buf0 + count;
X			 cp = buf0;
X		    }
X		    switch(*cp) {
X		    case '\105':	/* reverse video off */
X			 queue_string("\033[m");
X			 break;
X		    case '\104':	/* reverse video on */
X			 queue_string("\033[7m");
X			 break;
X		    default:
X			 break;
X		    }
X		    break;
X	       case '\027':	/* up=^w */
X		    queue_string("\033[A");
X		    break;
X	       case '\013':	/* ce=^k */
X		    queue_string("\033[K");
X		    break;
X	       case '\024':	/* us=^t */
X		    /* start underscore */
X		    queue_string("\033[4m");
X		    break;
X	       case '\025':	/* ue=^u */
X		    /* end undersore */
X		    queue_string("\033[m");
X		    break;
X	       case '\034':	/* so=^\ */
X		    queue_string("\033[m");
X		    break;
X	       case '\035':	/* se=^] */
X		    queue_string("\033[1m");
X		    break;
X	       case '\030':	/* kr=^x */
X		    queue_string("\033[C");
X		    break;
X	       case '\032':	/* kd=^z */
X		    queue_string("\033[B");
X		    break;
X	       case '\010':	/* kh=^h */
X		    queue_string("\033[1;1H");
X		    break;
X	       case '\022':	/* is=^r */
X		    break;
X	       case '\012':	/* nl */
X		    queue_string("\n\r");
X		    break;
X	       default:
X		    queue_char((int)c);
X	       }
X	  }
X	  flush_the_queue();
X     }
X
X}
X
Xwriter()
X{
X     register int	count;
X     register int	index;
X     register int	row, col;
X     register char	*cp, *end, c;
X
X     for(;;) {
X	  count = read(0, buf1, 256);
X	  index = 0;
X	  while (index < count) {
X	       if (tflag && (buf1[index] == '~') ) {
X 		    kill(pid, SIGTERM);
X		    ioctl (0, TIOCNXCL, &tmode);
X		    tmode.sg_flags = savemode;
X		    ioctl (0, TIOCSETP, &tmode);
X		    exit(0);;
X	       } else {
X		    tflag = 0;
X	       }
X	       if (buf1[index] == '^')
X		    tflag = 1;
X	       ++index;
X	  }
X	  write(fd, buf1, count);
X     }
X}
X
X
SHAR_EOF
if test 7795 -ne "`wc -c 'dg.c'`"
then
	echo shar: error transmitting "'dg.c'" '(should have been 7795 characters)'
fi
echo shar: extracting "'dgtool.1'" '(1773 characters)'
if test -f 'dgtool.1'
then
	echo shar: over-writing existing file "'dgtool.1'"
fi
sed 's/^X//' << \SHAR_EOF > 'dgtool.1'
X.\" Copyright (c) 1989 Southwest Research Institute
X.\" All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms are permitted
X.\" provided that the above copyright notice and this paragraph are
X.\" duplicated in all such forms and that any documentation,
X.\" advertising materials, and other materials related to such
X.\" distribution and use acknowledge that the software was developed
X.\" by Southwest Research Institute.  The name of Southwest Research
X.\" Institute may not be used to endorse or promote products derived
X.\" from this software without specific prior written permission.
X.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X.\"
X.TH DGTOOL 1L "30 June 1989"
X.SH NAME
Xdgtool \- provide a Data General terminal emulation in a window
X.SH SYNOPSIS
X.B dgtool
X.I serial line
X[
X.I baud rate
X]
X[
X.I window options
X]
X.SH DESCRIPTION
X.I dgtool
Xprovides a window with a terminal emulation and a serial line or telnet
Xinterface for a Data General system.
XThe DG function keys F1\-F15 are replaced by F1\-F9 and R1\-R6
Xon the Sun-3 keyboard.
XHome is generated by the R11 key and R7, R9, R13, R15 are the
X``C'' function keys.
XThe cursor motion emulation and serial line access is handled
Xby
X.IR dg (1L).
X.SH OPTIONS
X.LP
XThe first argument of
X.I dgtool
Xspecifies which serial line or host to use when accessing the DG.
XThe second argument is optional and specifies the baud rate to
Xbe used in communicating with the DG.
X.I dgtool
Xwill also accept the standard window arguments, see
X.IR suntools (1).
X.SH "SEE ALSO"
Xsuntools(1), dg(1L)
X.SH AUTHOR
XKeith S. Pickens, Southwest Research Institute
SHAR_EOF
if test 1773 -ne "`wc -c 'dgtool.1'`"
then
	echo shar: error transmitting "'dgtool.1'" '(should have been 1773 characters)'
fi
echo shar: extracting "'dgtool.c'" '(9201 characters)'
if test -f 'dgtool.c'
then
	echo shar: over-writing existing file "'dgtool.c'"
fi
sed 's/^X//' << \SHAR_EOF > 'dgtool.c'
X/*
X * Copyright (c) 1989 Southwest Research Institute
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by Southwest Research Institute.  The name of Southwest Research
X * Institute may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xstatic char     sccsid[] = "@(#)dgtool.c	1.9	6/29/89		Copyright (c) 1989\
X by Southwest Research Institute, San Antonio, Texas";
X#endif
X
X/* 
X * path name for `dg' - this is system dependent
X */
X
X
X#define DG	"/usr/local/bin/dg"
X
X#include <stdio.h>
X#include <strings.h>
X#include <suntool/sunview.h>
X#include <suntool/panel.h>
X#include <suntool/canvas.h>
X#include <sunwindow/win_cursor.h>
X#include <suntool/tty.h>
X#include <sundev/kbio.h>
X#include <sundev/kbd.h>
X#include <sgtty.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netdb.h>
X
X#define NUM_KEYS_TO_SAVE	8
X
XFrame    base_frame;
XTty	tty_win;
Xstatic void	input_proc();
Xstatic Notify_value	my_tty_interposer();
Xstatic Notify_value	my_destroy_interposer();
Xstatic int	kb_fd;
X
Xstatic struct kiockey save_keys[NUM_KEYS_TO_SAVE] = {
X					{0, 0x45, 0, ""}, /* up arrow */
X					{0, 0x5d, 0, ""}, /* right arrow */
X					{0, 0x5b, 0, ""}, /*left arrow */
X					{0, 0x71, 0, ""}, /*down arrow */
X					{SHIFTMASK, 0x45, 0, ""}, /* up arrow */
X					{SHIFTMASK, 0x5d, 0, ""}, /* right arrow */
X					{SHIFTMASK, 0x5b, 0, ""}, /*left arrow */
X					{SHIFTMASK, 0x71, 0, ""}, /*down arrow */
X};
X
Xstatic void	get_keys();
Xstatic void	fix_keys();
Xstatic void	reset_keys();
Xstatic void	do_key();
Xstatic void	check_baud();
Xstatic void	do_c_key();
X
X/* support an icon */
Xstatic short    icon_image[] = {
X#include	"dgtool.icon"
X};
X
XDEFINE_ICON_FROM_IMAGE(dgtool_icon, icon_image);
X
Xstruct baud_tab {
X    char    *baud_string;
X    int baud_rate;
X} baud_tab[] = {
X    "50",   B50,
X    "75",   B75,
X    "110",  B110,
X    "134",  B134,
X    "150",  B150,
X    "200",  B200,
X    "300",  B300,
X    "600",  B600,
X    "1200", B1200,
X    "1800", B1800,
X    "2400", B2400,
X    "4800", B4800,
X    "9600", B9600,
X    "19200",    EXTA,
X    NULL,   0
X};
X
Xmain(argc, argv)
Xint             argc;
Xchar          **argv;
X{
X	int	test_fd;
X
X	kb_fd = open("/dev/kbd", 2);
X	if (kb_fd < 0) {
X		fprintf(stderr, "dgtool: keyboard open failed\n");
X		exit(1);
X	}
X
X	base_frame = window_create(0, FRAME,
X				   WIN_ROWS,	25,
X				   WIN_COLUMNS,	80,
X				   FRAME_LABEL, "dgtool",
X				   FRAME_ICON, &dgtool_icon,
X				   FRAME_ARGC_PTR_ARGV, &argc, argv,
X				   0);
X
X	if ((argc > 3) || (argc < 2)) {
X		fprintf(stderr, "dgtool /dev/tty?|host [baud] [window args]\n");
X		exit(1);
X	}
X
X	if ( ((test_fd = open(argv[1], 2)) < 0 ) && (gethostbyname(argv[0]) != NULL) ) {
X		fprintf(stderr, "dgtool: can't open the line to the DG or find a host\n");
X		exit(1);
X	} else {
X	     if (test_fd >= 0)
X		close(test_fd);
X	}
X	if (argc == 3) {
X		check_baud(argv[2]);
X	}
X
X	argv[0] = DG;
X
X	tty_win = window_create(base_frame, TTY, TTY_ARGV, argv, 0);
X
X	window_set(tty_win, WIN_CONSUME_KBD_EVENTS,
X			WIN_ASCII_EVENTS,
X			WIN_RIGHT_KEYS,
X			WIN_TOP_KEYS,
X			0,
X			0);
X	window_set(tty_win, WIN_IGNORE_KBD_EVENT, WIN_UP_EVENTS, 0);
X
X	notify_interpose_destroy_func(base_frame, my_destroy_interposer);
X	notify_interpose_event_func(tty_win, my_tty_interposer, NOTIFY_SAFE);
X
X	window_main_loop(base_frame);
X	exit(0);
X}
X
X
X
Xstatic void
Xget_keys()
X{
X     register int i;
X
X     for( i = 0; i < NUM_KEYS_TO_SAVE; i++) {
X	  if (ioctl(kb_fd, KIOCGETKEY, &save_keys[i]) < 0) {
X	       fprintf(stderr, "dgtool: getkeys - kb ioctl failed\n");
X	       exit(1);
X	  }
X     }
X}
X
Xstatic void
Xreset_keys()
X{
X     register int i;
X
X     for( i = 0; i < NUM_KEYS_TO_SAVE; i++) {
X	  if (ioctl(kb_fd, KIOCSETKEY, &save_keys[i]) < 0) {
X	       fprintf(stderr, "dgtool: reset_keys - kb ioctl failed\n");
X	       exit(1);
X	  }
X     }
X}
X
Xstatic void
Xfix_keys()
X{
X	struct kiockey	tmp_key;
X
X	tmp_key = save_keys[0];	/* up arrow */
X	tmp_key.kio_entry = 027;
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X
X	tmp_key = save_keys[4];	/* shifted up arrow */
X	strcpy(tmp_key.kio_string, "\036\027");
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X
X	tmp_key = save_keys[1];	/* right arrow */
X	tmp_key.kio_entry = 030;
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X	tmp_key = save_keys[5];	/* shifted right arrow */
X	strcpy(tmp_key.kio_string, "\036\030");
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X
X	tmp_key = save_keys[2];	/* left arrow */
X	tmp_key.kio_entry = 031;
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X	tmp_key = save_keys[6];	/* shifted left arrow */
X	strcpy(tmp_key.kio_string, "\036\031");
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X
X	tmp_key = save_keys[3];	/* down arrow */
X	tmp_key.kio_entry = 032;
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X	tmp_key = save_keys[7];	/* shifted down arrow */
X	strcpy(tmp_key.kio_string, "\036\032");
X	if (ioctl(kb_fd, KIOCSETKEY, &tmp_key) < 0) {
X		fprintf(stderr, "dgtool: kb ioctl failed\n");
X		exit(1);
X	}
X
X}
X
Xstatic Notify_value
Xmy_destroy_interposer(frame, status)
XFrame	frame;
XDestroy_status	status;
X{
X	if (status == DESTROY_CLEANUP) {
X		reset_keys();
X	}
X	return(notify_next_destroy_func(frame, status));
X}
X
Xstatic Notify_value
Xmy_tty_interposer(frame, event, arg, type)
XFrame	frame;
XEvent	*event;
XNotify_arg	arg;
XNotify_event_type	type;
X{
X	register int	input;
X	register int	shift, ctrl;
X	char	baby_buffer;	/* for arrow keys */
X	Notify_value	value;
X
X	input = event_id(event);
X
X	if (input == KBD_USE) {
X		get_keys();
X		fix_keys();
X	}
X
X	if (input == KBD_DONE) {
X		reset_keys();
X	}
X
X	if ((event_is_key_top(event)) || (event_is_key_right(event)) ) {
X
X		if ( event_ctrl_is_down(event)) {
X			ctrl = 1;
X		} else {
X			ctrl = 0;
X		}
X
X		if ( event_shift_is_down(event)) {
X			shift = 1;
X		} else {
X			shift = 0;
X		}
X
X		switch(input) {
X		/*
X		 * function keys
X		 */
X		case KEY_RIGHT(6):
X			do_key(0160, shift, ctrl);
X			break;
X		case KEY_TOP(1):
X			do_key(0161, shift, ctrl);
X			break;
X		case KEY_TOP(2):
X			do_key(0162, shift, ctrl);
X			break;
X		case KEY_TOP(3):
X			do_key(0163, shift, ctrl);
X			break;
X		case KEY_TOP(4):
X			do_key(0164, shift, ctrl);
X			break;
X		case KEY_TOP(5):
X			do_key(0165, shift, ctrl);
X			break;
X		case KEY_TOP(6):
X			do_key(0166, shift, ctrl);
X			break;
X		case KEY_TOP(7):
X			do_key(0167, shift, ctrl);
X			break;
X		case KEY_TOP(8):
X			do_key(0170, shift, ctrl);
X			break;
X		case KEY_TOP(9):
X			do_key(0171, shift, ctrl);
X			break;
X		case KEY_RIGHT(1):
X			do_key(0172, shift, ctrl);
X			break;
X		case KEY_RIGHT(2):
X			do_key(0173, shift, ctrl);
X			break;
X		case KEY_RIGHT(3):
X			do_key(0174, shift, ctrl);
X			break;
X		case KEY_RIGHT(4):
X			do_key(0175, shift, ctrl);
X			break;
X		case KEY_RIGHT(5):
X			do_key(0176, shift, ctrl);
X			break;
X		/*
X		 * home
X		 */
X		case KEY_RIGHT(11):
X			baby_buffer = 010;
X			ttysw_input(tty_win, &baby_buffer, 1);
X			break;
X		/*
X		 * "c" keys
X		 */
X		case KEY_RIGHT(7):
X			do_c_key(0134, shift);
X			break;
X		case KEY_RIGHT(9):
X			do_c_key(0135, shift);
X			break;
X		case KEY_RIGHT(13):
X			do_c_key(0136, shift);
X			break;
X		case KEY_RIGHT(15):
X			do_c_key(0137, shift);
X			break;
X		default:
X			break;
X		}
X		return(NOTIFY_DONE);
X	}
X	value = notify_next_event_func(frame, event, arg, type);
X	return(value);
X}
X
Xstatic void
Xdo_key(code, shift, ctrl)
Xint	code, shift, ctrl;
X{
X	register char	out_code;
X	static char	buffer[2] = "\036";
X
X
X	if (shift && ctrl) {
X		out_code = code - 0120;
X	} else if (shift) {
X		out_code = code - 020;
X	} else if (ctrl) {
X		out_code = code - 0100;
X	} else {
X		out_code = code;
X	}
X	buffer[1] = out_code;
X	ttysw_input(tty_win, buffer, 2);
X}
X
Xstatic void
Xcheck_baud(string)
Xchar *string;
X{
X    struct baud_tab *btp;
X 
X    btp = baud_tab;
X 
X    while(btp->baud_string != NULL) {
X        if (strcmp (string, btp->baud_string) == 0)
X            return;
X        btp++;
X    }
X    fprintf(stderr, "dgtool: unknown baud rate\n");
X    fprintf(stderr, "known baud rates are:\n");
X 
X    btp = baud_tab;
X    while(btp->baud_string != NULL) {
X        fprintf(stderr, "\t%s\n", btp->baud_string);
X        btp++;
X    }
X    exit(1);
X}
X
Xstatic void
Xdo_c_key(code, shift)
Xint	code, shift;
X{
X	register char	out_code;
X	static char	buffer[2] = "\036";
X
X
X	if (shift) {
X		out_code = code - 04;
X	} else {
X		out_code = code;
X	}
X	buffer[1] = out_code;
X	ttysw_input(tty_win, buffer, 2);
X}
SHAR_EOF
if test 9201 -ne "`wc -c 'dgtool.c'`"
then
	echo shar: error transmitting "'dgtool.c'" '(should have been 9201 characters)'
fi
echo shar: extracting "'dgtool.icon'" '(2838 characters)'
if test -f 'dgtool.icon'
then
	echo shar: over-writing existing file "'dgtool.icon'"
fi
sed 's/^X//' << \SHAR_EOF > 'dgtool.icon'
X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
X * @(#)dgtool.i	1.1 6/28/89 Copyright (c) 1989 by Southwest Research Institute, San Antonio, TX
X *
X * Copyright (c) 1989 Southwest Research Institute
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by Southwest Research Institute.  The name of Southwest Research
X * Institute may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
X	0xC000,0x0000,0x0000,0x0003,0xC000,0x0039,0xCE00,0x0003,
X	0xC00F,0x8039,0xCE02,0x2003,0xC892,0x404A,0x5251,0xC7C3,
X	0xD740,0x004A,0x5220,0x8923,0xC200,0x01CE,0x7380,0x0003,
X	0xC030,0x0F4A,0x50F0,0x0003,0xC000,0xF54A,0x50AF,0x0413,
X	0xC003,0x5B4A,0x50DA,0xC3E3,0xD405,0xB57A,0x4CAD,0xA083,
X	0xC81B,0x554A,0x42AA,0xD803,0xC035,0x5B4A,0x42DA,0xAC2B,
X	0xC055,0xB54A,0x42AD,0xAA13,0xC05B,0x554A,0x52AA,0xDA03,
X	0xC0B5,0x5BCE,0x73DA,0xAD03,0xC1D5,0xBF4A,0x52FD,0xAB83,
X	0xC35B,0xF06B,0x9C0F,0xDAC3,0xC1FF,0x006B,0x9C00,0xFF83,
X	0xC049,0x0000,0x0024,0x8A03,0xC063,0x0000,0x0018,0xA203,
X	0xD145,0x1111,0x0000,0xC68B,0xD151,0x1111,0x0000,0x928B,
X	0xFBC9,0x3BBB,0x0880,0x8BDF,0xD163,0x1111,0x0500,0xA28B,
X	0xFFFF,0xFFFF,0x0201,0xC7FF,0xD541,0xD555,0x0201,0x92AB,
X	0xD545,0xD555,0x0001,0x8AAB,0xFBC5,0xBBBB,0x0001,0xA3DF,
X	0xD545,0xD555,0x0001,0xC6AB,0xD545,0xD555,0x0221,0x92AB,
X	0xFBC5,0xBBBB,0x05D1,0x8BDF,0xD545,0x5555,0x0080,0xFEAB,
X	0xD545,0x5555,0x0000,0x82AB,0xFBCD,0xBBBB,0x0001,0x9BDF,
X	0xD555,0x5555,0x0000,0xAAAB,0xD555,0x5555,0x0000,0xAAAB,
X	0xFBD5,0xBBBB,0x0001,0xABDF,0xD555,0x5555,0x0000,0xAAAB,
X	0xD555,0x555F,0x0000,0xAAAB,0xFBD5,0xBBBB,0x0001,0xABDF,
X	0xD555,0x555F,0x0000,0xAAAB,0xD54D,0x5555,0x0000,0x9AAB,
X	0xFBC1,0xBBBB,0x0001,0x8BDF,0xD57F,0x5555,0x0800,0xAAAB,
X	0xD545,0x5555,0x1010,0xAAAB,0xFBD1,0xBBBB,0x1019,0xABDF,
X	0xD549,0x5555,0x133C,0xAAAB,0xD563,0x5555,0x17F8,0xAAAB,
X	0xFBC5,0xBBBB,0x17F1,0x93DF,0xD551,0x5555,0x0FFC,0x82AB,
X	0xD549,0x5555,0x0EF2,0xFEAB,0xFBE3,0xBBBB,0x0E61,0xA3DF,
X	0xD545,0xD555,0x0C61,0xC6AB,0xD551,0xD555,0x0821,0x92AB,
X	0xFBC9,0xBBBB,0x0821,0x8BDF,0xD563,0xD555,0x0411,0xA2AB,
X	0xD545,0xD555,0x0001,0xC6AB,0xFFD1,0xFFFF,0x0001,0x93FF,
X	0xC07F,0x0000,0x0000,0xFE03,0xC000,0x0000,0x0000,0x0003,
X	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
SHAR_EOF
if test 2838 -ne "`wc -c 'dgtool.icon'`"
then
	echo shar: error transmitting "'dgtool.icon'" '(should have been 2838 characters)'
fi
#	End of shell archive
exit 0