BSD 4_3 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 1 Feb 1986 05:43:01 +0000 (21:43 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Sat, 1 Feb 1986 05:43:01 +0000 (21:43 -0800)
Work on file usr/contrib/X/Xlib/Xtextlib.c
Work on file usr/contrib/X/Xlib/Xtty.h
Work on file usr/contrib/X/include/X/Xtty.h
Work on file usr/contrib/X/Xlib/Xttylib.c
Work on file usr/contrib/X/Xlib/keymap.c

Synthesized-from: CSRG/cd1/4.3

usr/contrib/X/Xlib/Xtextlib.c [new file with mode: 0644]
usr/contrib/X/Xlib/Xtty.h [new file with mode: 0644]
usr/contrib/X/Xlib/Xttylib.c [new file with mode: 0644]
usr/contrib/X/Xlib/keymap.c [new file with mode: 0644]
usr/contrib/X/include/X/Xtty.h [new symlink]

diff --git a/usr/contrib/X/Xlib/Xtextlib.c b/usr/contrib/X/Xlib/Xtextlib.c
new file mode 100644 (file)
index 0000000..6ad7144
--- /dev/null
@@ -0,0 +1,762 @@
+/* $Header: Xtextlib.c,v 10.4 86/02/01 15:42:32 tony Rel $ */
+/* Library of routines for creating a simple text output window.
+ *
+ * Routines in the library are:
+ *
+ *     TextCreate              Creates a new instance of a text window
+ *     TextDestroy             Destroys the window
+ *     TextClear               Clears a text window
+ *     TextRedisplay           Redisplays the window
+ *     TextEvent               Handles exposure and unmapping events
+ *     TextPutString           Displays a string in a text window
+ *     TextPutChar             Displays a character in a text window
+ *     TextPrintf              Does a printf in a text window
+ *
+ * All these routines pass around a pointer to a TextWindow data structure:
+ *
+ * typedef struct _TextWindow {
+ *     Window w;               Window to use
+ *     FontInfo *font;         Font to use for text
+ *     short num_lines;        Number of lines in the window
+ *     short num_chars;        The length of each line
+ *     short mapped;           Whether or not the window is mapped
+ *     short height;           Height of window in pixels
+ *     short width;            Width of window in pixels
+ *     short first_line;       The index of the first line
+ *     char **lines;           Ptr to array of text lines
+ *     short *line_length;     Ptr to array of line lengths (in pixels)
+ *     short *line_chars;      Ptr to array of line lengths in chars
+ *     short last_line;        Which line is the last
+ *     short last_char;        Length of the last line
+ *     short next_x;           X-coord for next character
+ *     short next_y;           Y-coord for next character
+ *     unsigned int eventmask; List of events we're interested in
+ *     char *scroll_history;   Ptr to list of scroll amounts
+ *     short scroll_count;     Number of outstanding scrolls
+ *     short scroll_start;     Where in the history the history starts
+ *     short old_scrolls;      Number of ignorable outstanding scrolls
+ *     short fastscroll;       Whether or not to use fast scrolling
+ * } TextWindow; 
+ *
+ * Applications should not modify anything in this data structure, obviously!
+ * They may, however, have reason to get information out of it. (Such as the
+ * window id for mapping).
+ *
+ * Information about the first line of the window is stored in the array
+ * entries subscripted by [first_line]; the arrays wrap back up at the end.
+ * Last_char should always be the same as line_chars[last_line]. 
+ * Similarly, next_x should always be the same as line_length[last_line];
+ *
+ * The only complicated thing about these procedures is the way they keep
+ * track of scrolling.  When a scroll is done, X sends ExposeRegions for
+ * every region that needs to be patched up and then an ExposeCopy event.
+ * The ExposeCopy comes even if there were no regions.  The only problem
+ * is that more scrolls may have been done in the meantime.  So we keep a
+ * history of how much cumulative scrolling has been done in the
+ * scroll_history list.  scroll_start tells which one to start with, and
+ * scroll_count tells how many there are (they wrap around).  The list is
+ * num_lines long since anything that's scrolled away longer ago than that
+ * has scrolled off the screen.  The old_scrolls field gets set whenever the
+ * screen is fully updated for some reason or other; it means that that
+ * many ExposeCopy events can be completely ignored since the screen has
+ * been fully updated.
+ */
+
+#include <stdio.h>
+#include "Xlib.h"
+#include "Xtext.h"
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+/* Define the width of the left margin */
+
+#define mar_width 2
+
+char *calloc(), *malloc(), *realloc();
+
+/* The following variable is sometimes set by TextPutString to temporarily
+   disable screen updating. */
+
+static int dont_update = FALSE;
+\f
+/* TextCreate creates a new window which will use the
+ * specified font.  The window is height lines high and width
+ * characters wide.  Note that since a variable-width font may be
+ * used, the width is calculated using the average width of the font.
+ * Colors are used as specified.
+ */
+
+TextWindow *TextCreate (width, height, x, y, parent, fontname,
+               bwidth, fgpixel, bgpixel, bordercolor, fastscroll)
+       int height, width, x, y, bwidth, fastscroll;
+       Window parent;
+       char *fontname;
+       int fgpixel, bgpixel;
+       Pixmap bordercolor;
+{
+       register TextWindow *t;
+       register int i;
+       register FontInfo *f;
+       Window XCreateWindow();
+       Pixmap bgpixmap;
+
+       if ((t = (TextWindow *) malloc(sizeof(TextWindow))) ==
+               NULL) return NULL;
+
+       if ((f = t->font = XOpenFont(fontname)) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       t->fgpixel = fgpixel;
+       t->bgpixel = bgpixel;
+
+       if ((bgpixmap = XMakeTile(bgpixel)) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       t->width = width * f->width + mar_width;
+       t->height = height * f->height;
+
+       t->w = XCreateWindow (parent, x, y, t->width, t->height,
+               bwidth, bordercolor, bgpixmap);
+       if (t->w == NULL) {
+           TextDestroy(t);
+           XFreePixmap(bgpixmap);
+           return NULL;
+       }
+
+       XFreePixmap(bgpixmap);
+
+       t->eventmask = ExposeRegion | ExposeCopy | UnmapWindow;
+       /* (ExposeRegion automatically selects ExposeWindow) */
+
+       XSelectInput (t->w, t->eventmask);
+
+       XSetResizeHint (t->w, mar_width, 0, f->width, f->height);
+       t->fastscroll = fastscroll;
+       t->mapped = FALSE;
+       t->num_lines = height;
+       t->num_chars = width;
+
+       t->first_line = 0;
+
+       if ((t->lines = (char **)
+               calloc (height, sizeof (char *))) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       if ((t->line_length = (short *)
+               calloc (height, sizeof (short))) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       if ((t->line_chars = (short *)
+               calloc (height, sizeof (short))) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       for (i = 0; i < height; i++) {
+           if ((t->lines[i] = (char *)
+                   calloc (width+1, sizeof (char))) == NULL) {
+               TextDestroy(t);
+               return NULL;
+           }
+       }
+
+       if ((t->scroll_history = calloc(height, sizeof (char))) == NULL) {
+           TextDestroy(t);
+           return NULL;
+       }
+
+       t->scroll_count = t->scroll_start = t->old_scrolls = 0;
+       TextClear(t);
+       return t;
+}
+\f
+/* Free all the storage associated with a textwindow */
+
+TextDestroy(t)
+       register TextWindow *t;
+{
+       register int i;
+
+       /* Free things in the order we allocated them.  If something doesn't
+          exist, don't free it!) */
+
+       if (t->font) {
+           if (t->font->fixedwidth == 0) free(t->font->widths);
+           free(t->font);
+       }
+
+       if (t->w) XDestroyWindow(t->w);
+
+       if (t->lines) {
+           for (i = 0; i < t->num_lines; i++) {
+               if (t->lines[i]) free(t->lines[i]);
+           }
+           free(t->lines);
+       }
+
+       if (t->line_length) free (t->line_length);
+       if (t->line_chars) free (t->line_chars);
+       if (t->scroll_history) free (t->scroll_history);
+
+       /* And finally the data structure itself! */
+
+       free (t);
+}
+\f
+/* Clear out a text window and redisplay */
+
+TextClear(t)
+       register TextWindow *t;
+{
+       register int i;
+
+       for (i = 0; i < t->num_lines; i++) {
+           t->lines[i][0] = '\0';
+           t->line_chars[i] = 0;
+           t->line_length[i] = mar_width;      /* Allow a left margin */
+       }
+       t->last_line = 0;
+       t->last_char = 0;
+       t->next_x = mar_width;          /* Allow a left margin */
+       t->next_y = 0;
+       t->first_line = 0;
+
+       TextRedisplay(t);
+}
+\f
+/* Redisplays a text window */
+
+TextRedisplay (t)
+       register TextWindow *t;
+{
+       if (!t->mapped) return;
+
+       /* Clear the border area */
+
+       XPixSet(t->w, 0, 0, mar_width, t->height, t->bgpixel);
+
+       Redisplay_lines(t, 0, t->num_lines - 1);
+
+       /* Any outstanding copies from scrolls can now be ignored */
+
+       t->old_scrolls = t->scroll_count;
+       t->scroll_count = t->scroll_start = 0;
+}
+
+Redisplay_lines(t, start, finish)
+       register TextWindow *t;
+       int start, finish;
+{
+       register int i, j, y, height = t->font->height, x, width;
+
+       if (finish < 0) return;
+       if (start < 0) start = 0;
+
+       y = start * height;
+       j = start + t->first_line;
+
+       for (i = start; i <= finish; i++) {
+           if (j >= t->num_lines) j = 0;
+
+           if (t->line_chars[j]) {
+               XText (t->w, mar_width, y, t->lines[j], t->line_chars[j],
+                       t->font->id, t->fgpixel, t->bgpixel);
+           }
+
+           x = t->line_length[j];
+           width = t->width - x;
+
+           if (width > 0) XPixSet(t->w, x, y, width, height, t->bgpixel);
+           y += height;
+           j++;
+       }
+}
+\f
+/* Handles an event.  If it's not an event it knows how to deal with,
+   returns TRUE, otherwise FALSE. */
+
+int TextEvent(t, e)
+       register TextWindow *t;
+       XEvent *e;
+{
+       XExposeEvent *ee = (XExposeEvent *) e;
+       int offset;
+
+       switch (e->type) {
+           case ExposeWindow:
+               if (ee->height != t->height || ee->width != t->width) {
+                   Change_text_window_size(t, ee->height / t->font->height,
+                           ee->width / t->font->width);
+               }
+               t->mapped = TRUE;
+               TextRedisplay(t);
+               break;
+
+           case ExposeRegion:
+               /* If there have been more scrolls than there are lines,
+                  this stuff has already scrolled off! */
+
+               if (t->scroll_count > t->num_lines) return FALSE;
+
+               /* If this is for an old scroll, ignore it */
+
+               if (ee->detail == ExposeCopy && t->old_scrolls) return FALSE;
+
+               if (t->scroll_count > 0) {
+                   offset = t->scroll_history[t->scroll_start];
+               } else offset = 0;
+               Redisplay_lines(t, ee->y / t->font->height - offset,
+                       (ee->y + ee->height - 1) / t->font->height - offset);
+               break;
+
+           case UnmapWindow:
+               t->mapped = FALSE;
+               break;
+
+           case ExposeCopy:    /* We've finished the events for one scroll */
+               /* If there are old scrolls, just decrement the count and
+                  return */
+
+               if (t->old_scrolls) {
+                   t->old_scrolls--;
+                   return FALSE;
+               }
+               t->scroll_count--;
+               if (t->scroll_count < t->num_lines) {
+                   t->scroll_start++;
+                   if (t->scroll_start >= t->num_lines) t->scroll_start = 0;
+               }
+               break;
+
+           default:
+               return TRUE;
+       }
+       return FALSE;
+}
+\f
+Change_text_window_size (t, new_h, new_w)
+       register TextWindow *t;
+       register int new_h, new_w;
+{
+       register int i;
+       register char *curline;
+
+       Normalize(t);           /* Rearrange lines so that first_line = 0 */
+
+       /* First free up any now extraneous lines */
+
+       for (i = new_h; i < t->num_lines; i++) free(t->lines[i]);
+
+       if ((t->lines = (char **)
+               realloc(t->lines, new_h * sizeof (char *))) == NULL) {
+           return;
+       }
+
+       if ((t->line_length = (short *)
+               realloc(t->line_length, new_h * sizeof (short))) == NULL) {
+           return;
+       }
+
+       if ((t->line_chars = (short *)
+               realloc(t->line_chars, new_h * sizeof (short))) == NULL) {
+           return;
+       }
+
+       if ((t->scroll_history = realloc(t->scroll_history, new_h)) == NULL) {
+           return;
+       }
+
+       for (i = 0; i < new_h; i++) {
+           if (i < t->num_lines) {
+               if ((curline = t->lines[i] =
+                       realloc(t->lines[i], new_w + 1)) == NULL) {
+                   return;
+               }
+
+               if (t->line_chars[i] > new_w) {
+                   t->line_chars[i] = new_w;
+                   curline[new_w] = '\0';      /* Truncate the line */
+                   t->line_length[i] = mar_width +
+                           XStringWidth (curline, t->font, 0, 0);
+               }
+           } else {
+               if ((t->lines[i] = malloc(new_w+1)) == NULL) {
+                   return;
+               }
+               t->lines[i][0] = '\0';
+               t->line_chars[i] = 0;
+               t->line_length[i] = mar_width;
+           }
+       }
+
+       if (t->last_line >= new_h) {
+           t->last_line = new_h - 1;
+           t->last_char = t->line_chars[t->last_line];
+           t->next_x = t->line_length[t->last_line];
+           t->next_y = t->last_line * t->font->height;
+
+       } else if (t->last_char > new_w) {
+           t->last_char = t->line_chars[t->last_line];
+           t->next_x = t->line_length[t->last_line];
+       }
+
+       t->num_lines = new_h;
+       t->num_chars = new_w;
+       t->height = new_h * t->font->height;
+       t->width = new_w * t->font->width + mar_width;
+}
+\f
+/* Routine to re-arrange the lines in a window structure so that first_line
+   is equal to 0. */
+
+Normalize(t)
+       register TextWindow *t;
+{
+       if (t->first_line == 0) return;
+
+       t->last_line -= t->first_line;
+       if (t->last_line < 0) t->last_line += t->num_lines;
+
+       Spin_lines(t, 0, t->num_lines-1, t->first_line);
+
+       t->first_line = 0;
+}
+
+/* Spin lines rotates the m through n lines of the arrays
+   forward offset places.  For example, 012345 spun forward 2 is 234501.
+   It's straightforward to spin the first part of the arrays; and we
+   call Spin_lines recursively to do the last offset elements */
+
+/* Actually, it's tail-recursive, so I just use a loop.  But I can
+   pretend, can't I? */
+
+Spin_lines(t, m, n, offset)
+       register TextWindow *t;
+       int m, n;
+       register int offset;
+{
+       register int i;
+       register int temp;              /* Temporaries */
+       register char *tempc;
+
+       while (1) {
+           if (offset == 0 || offset > n-m) return;
+
+           for (i = m; i <= n-offset; i++) {
+               temp = t->line_length[i];
+               t->line_length[i] = t->line_length[offset+i];
+               t->line_length[offset+i] = temp;
+
+               temp = t->line_chars[i];
+               t->line_chars[i] = t->line_chars[offset+i];
+               t->line_chars[offset+i] = temp;
+
+               tempc = t->lines[i];
+               t->lines[i] = t->lines[offset+i];
+               t->lines[offset+i] = tempc;
+           }
+
+/*         Spin_lines(t, n-offset+1, n, offset - ((n-m+1) % offset)); */
+
+           temp = m;
+           m = n - offset + 1;
+           offset -= (n - temp + 1) % offset;
+       }
+}
+\f
+/* Routine to put a string in a text window.  If fastscroll is
+   set in the TextWindow structure, a single block scroll is done instead
+   of scrolling at each newline. */
+
+#define verybig 10000  /* Amount to scroll if we should refresh instead */
+
+TextPutString (t, str)
+       register TextWindow *t;
+       register char *str;
+{
+       register char *ch = str;
+       register char oldch;
+       int jump = t->fastscroll;       /* Whether to do jump scrolling */
+       int newlines, scroll;
+
+       if (jump) jump = Count_lines (t, str, &newlines, &scroll);
+
+       while (1) {
+           while (*ch != '\0' && *ch != '\n') ch++;
+           if (ch != str) {
+               oldch = *ch;
+               *ch = '\0';
+               Do_text_string (t, str);
+               *ch = oldch;
+           }
+           if (*ch == '\0') break;
+           if (jump && newlines == scroll) {
+               Clear_lines (t, newlines);
+               dont_update = TRUE;     /* Stop updating now */
+           }
+           newlines--;
+           TextPutChar (t, *ch);
+           str = ++ch;
+       }
+       if (t->mapped && jump) {
+           if (scroll != verybig) Scroll_text_window (t, scroll);
+           else TextRedisplay (t);
+       }
+       dont_update = FALSE;
+}
+\f
+/* Count the number of lines in str, calculate how much scrolling
+   will be needed, and return whether this amount is positive */
+
+int Count_lines (t, str, newlines, scroll)
+       register TextWindow *t;
+       register char *str;
+       int *newlines, *scroll;
+{
+       register int num_lines = 0;
+       register int lines_left, height = t->num_lines;
+
+       *scroll = 0;
+
+       while (*str) {
+           if (*str++ == '\n') num_lines++;
+       }
+
+       *newlines = num_lines;
+
+       if (num_lines <= 1) return FALSE;    /* Don't bother jump scrolling */
+
+       /* Would this fill the screen? */
+
+       if (num_lines >= height) {
+           *scroll = verybig;
+           return TRUE;
+       }
+
+       /* Calculate the number of lines left in the window */
+
+       lines_left = height - (t->last_line - t->first_line + 1);
+       if (lines_left >= height) lines_left -= height;
+
+       /* Figure out how many lines to scroll */
+
+       num_lines -= lines_left;
+
+       if (num_lines <= 0) return FALSE;       /* Enough room already */
+
+       *scroll = num_lines;
+       return TRUE;
+}
+\f
+/* Clear a number of lines in the window data structure */
+
+Clear_lines (t, scroll)
+       register TextWindow *t;
+       register int scroll;
+{
+       register int i, start = t->first_line;
+       register int height = t->num_lines;
+
+       /* If this would fill the screen, clear it instead */
+
+       if (scroll >= t->height ) {
+           TextClear (t);
+           return;
+       }
+
+       /* Shift the contents */
+
+       t->first_line += scroll;
+       if (t->first_line >= height) t->first_line -= height;
+
+       /* Now clear the blank lines */
+
+       for (i = 0; i < scroll; i++) {
+           t->lines[start][0] = '\0';
+           t->line_chars[start] = 0;
+           t->line_length[start] = mar_width;  /* Allow a left margin */
+           start++;
+           if (start >= height) start = 0;
+       }
+}
+\f
+/* Store the characters of a string in the window and update the screen,
+   but only if dont_update isn't set */
+
+Do_text_string (t, str)
+       register TextWindow *t;
+       char *str;
+{
+       register char *ch = str;
+       register char *curline = t->lines[t->last_line];
+       register int curchar = t->last_char;
+       register int x = t->next_x;
+       register FontInfo *f = t->font;
+       int start_x = t->next_x, start = curchar,
+               minch = f->firstchar, maxch = f->lastchar;
+
+       /* First store the characters in the line */
+
+       while (*ch != '\0' && curchar < t->num_chars) {
+           curline[curchar] = *ch;
+           if (*ch >= minch && *ch <= maxch) {
+               x += f->fixedwidth ? f->width : f->widths[*ch - minch];
+           }
+           curchar++;
+           ch++;
+       }
+
+       curline[curchar] = '\0';
+       t->line_chars[t->last_line] = t->last_char = curchar;
+       t->line_length[t->last_line] = t->next_x = x;
+
+       if (dont_update || !t->mapped) return;
+
+       /* And then update the screen */
+
+       if (start < t->num_chars) {
+           XText (t->w, start_x, t->next_y, str, curchar-start,
+                   f->id, t->fgpixel, t->bgpixel);
+       }
+}
+\f
+/* Textputchar displays a character in the text window.  It
+ * responds to \n as a special character and just displays anything else.
+ */
+
+TextPutChar (t, ch)
+       register TextWindow *t;
+       char ch;
+{
+       register int i, height = t->num_lines;
+       register char *curline = t->lines[t->last_line];
+       register FontInfo *f = t->font;
+       
+       switch (ch) {
+           case '\0':          /* NULL */
+               break;
+
+           case '\n':          /* newline */
+               if (t->last_line == t->first_line - 1 ||
+                       (t->last_line == height - 1 && t->first_line == 0)) {
+
+                   /* The screen is full...clear out the first line */
+
+                   t->lines[t->first_line][0] = '\0';
+                   t->line_chars[t->first_line] = 0;
+                   t->line_length[t->first_line] = mar_width;
+
+                   t->first_line++;                    /* And advance it */
+                   if (t->first_line == height) t->first_line = 0;
+
+                   if (!dont_update && t->mapped) Scroll_text_window (t, 1);
+
+               } else if (!dont_update) t->next_y += f->height;
+
+               t->last_line++;
+               if (t->last_line == height) t->last_line = 0;
+
+               t->last_char = 0;
+               t->next_x = mar_width;
+               break;
+
+           default:            /* Just insert the character */
+               t->last_char++;
+               t->line_chars[t->last_line]++;
+               if (t->last_char > t->num_chars) break;
+
+               curline[t->last_char] = ch;
+               curline[t->last_char+1] = '\0';
+
+               if (!dont_update && t->mapped) {
+                   XText(t->w, t->next_x, t->next_y, &ch, 1,
+                           f->id, t->fgpixel, t->bgpixel);
+               }
+               if (ch <= f->firstchar && ch >= f->lastchar) {
+                   t->line_length[t->last_line] = t->next_x +=
+                           (f->fixedwidth ? f->width :
+                                            f->widths[ch - f->lastchar]);
+               }
+               break;
+       }
+}
+\f
+/* This procedure moves the contents of a text window up n lines.
+ */
+
+Scroll_text_window (t, n)
+       register TextWindow *t;
+       register int n;
+{
+       register int i, y, x, width, j;
+       int height = t->font->height;
+       int scrollsize = n * height;
+
+       /* First shift up the contents */
+
+       XMoveArea(t->w, 0, scrollsize, 0, 0, t->width, t->height-scrollsize);
+
+       /* Now redisplay the bottom n lines */
+
+       y = height * (t->num_lines - n);
+       i = t->first_line - n;
+       if (i < 0) i += t->num_lines;
+
+       for (j = 0; j < n; j++) {
+           if (t->line_chars[i]) {
+               XText (t->w, mar_width, y, t->lines[i], t->line_chars[i],
+                       t->font->id, t->fgpixel, t->bgpixel);
+           }
+           x = t->line_length[i];
+           width = t->width - x;
+
+           if (width > 0) XPixSet(t->w, x, y, width, height, t->bgpixel);
+           y += height;
+           i++;
+           if (i == t->num_lines) i = 0;
+       }
+
+       /* Add the current scroll to all values in the scroll history,
+          then add a new entry at the end (the history wraps!) */
+
+       i = t->scroll_start;
+
+       for (j = 0; j < t->scroll_count; j++) {
+           t->scroll_history[i] += n;
+           i++;
+           if (i >= t->num_lines) i = 0;
+       }
+       t->scroll_count++;
+       t->scroll_history[i] = n;
+
+       if (t->scroll_count > t->num_lines) t->scroll_start++; /* trash one */
+}
+\f
+#define TEXT_BUFSIZE 2048
+
+TextPrintf(t, format, args)
+       TextWindow *t;
+       char *format;
+{
+       char buffer[TEXT_BUFSIZE+1];
+       struct _iobuf _strbuf;
+
+       _strbuf._flag = _IOWRT+_IOSTRG;
+       _strbuf._ptr = buffer;
+       _strbuf._cnt = TEXT_BUFSIZE;
+       _doprnt(format, &args, &_strbuf);
+       _strbuf._cnt++;     /* Be sure there's room for the \0 */
+       putc('\0', &_strbuf);
+       TextPutString(t, buffer);
+}
diff --git a/usr/contrib/X/Xlib/Xtty.h b/usr/contrib/X/Xlib/Xtty.h
new file mode 100644 (file)
index 0000000..c30729b
--- /dev/null
@@ -0,0 +1,9 @@
+/* $Header: Xtty.h,v 10.3 86/02/01 15:42:44 tony Rel $ */
+typedef struct _TTYWindow {
+       Window w;               /* The window id */
+       int pid;                /* The pid of the subprocess xterm */
+       short file;             /* The file id of the tty to read and write 
+                                  characters to/from */
+} TTYWindow;
+
+TTYWindow *CreateTTYWindow();
diff --git a/usr/contrib/X/Xlib/Xttylib.c b/usr/contrib/X/Xlib/Xttylib.c
new file mode 100644 (file)
index 0000000..9371f0a
--- /dev/null
@@ -0,0 +1,237 @@
+#ifndef lint
+static char *rcsid_Xttylib_c = "$Header: Xttylib.c,v 10.6 86/02/01 15:42:48 tony Rel $";
+#endif
+/* This version has a single reverse-video argument instead of colors.  It
+   really only works well on monochrome displays */
+
+/* Library of routines to create a terminal emulator window
+ *
+ * Routines in this library are:
+ *
+ *     CreateTTYWindow         Creates a new instance of a terminal window
+ *     DestroyTTYWindow        Destroys a terminal window
+ *     TTYPutString            Puts a string in a terminal window
+ *     TTYPutChar              Puts a character in a terminal window
+ *     TTYPrintf               Does a printf in a terminal window
+ *     TTYGetString            Gets s string from a terminal window
+ *     TTYGetChar              Gets a char from a terminal window
+ *     SetStdout               Flushes stdout and assigns it to a window
+ *     ResetStdout             Resets stdout to its inital value
+ *
+ * The terminal window created responds to exactly the same character
+ * sequences as xterm (not surprising).  Creating a window automatically
+ * maps it
+ *
+ * These routines pass around a pointer to a TTYWindow:
+ *
+ * typedef struct _TTYWindow {
+ *     Window w;               The window id
+ *     int pid;                The pid of the subprocess xterm
+ *     short file;             The file id of the tty to read/write characters to/from
+ * } TTYWindow;
+ *
+ *
+ * The SetStdout routine is highly useful in conjunction with curses
+ * since curses always writes to stdout.
+ */
+
+#include <X/Xlib.h>
+#include <stdio.h>
+#include <signal.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sgtty.h>
+#include "Xtty.h"
+
+TTYWindow *CreateTTYWindow(cols, lines, x, y, normFont, boldFont, bwidth,
+               reverse)
+       int lines, cols, x, y, bwidth, reverse;
+       char *normFont, *boldFont;
+{
+       TTYWindow *t;
+
+       if ((t = (TTYWindow *) malloc(sizeof(TTYWindow))) ==
+               NULL) return NULL;
+
+       if (Start_slave_xterm(t, lines, cols, x, y, normFont, boldFont,
+               bwidth, reverse) == 0) {
+           free(t);
+           fprintf(stderr, "Couldn't start slave xterm\n");
+           return NULL;
+       }
+
+       return t;
+}
+
+int ttyMasterPty;
+int keepMasterOpen = 0;
+
+int Start_slave_xterm(t, lines, cols, x, y, normFont, boldFont, bwidth,
+               reverse)
+       TTYWindow *t;
+       int lines, cols, x, y, bwidth, reverse;
+       char *normFont, *boldFont;
+{
+#define BUFSIZE 20
+
+       char ttyName[BUFSIZE];
+       char Sbuf[BUFSIZE], sizeBuf[BUFSIZE], wdBuf[BUFSIZE],
+               inputBuffer[BUFSIZE];
+       int bytesRead, len;
+
+       if (boldFont == NULL) boldFont = normFont;
+
+       ttyMasterPty = GetPty(ttyName);
+       if (ttyMasterPty == -1) return 0;
+
+       if ((t->pid = vfork()) < 0) return 0;
+
+       if (t->pid == 0) {
+           sprintf(Sbuf, "-S%c%c%d", ttyName[8], ttyName[9], ttyMasterPty);
+           sprintf(sizeBuf, "=%dx%d+%d+%d", cols, lines, x, y);
+           sprintf(wdBuf, "%d", bwidth);
+
+           execlp("xterm", "xterm", Sbuf, "-fn", normFont, "-fb", boldFont,
+                   sizeBuf, "-bw", wdBuf, reverse ? "-rv" : (char *) 0,
+                   (char *) 0);
+
+       } else {
+           if (!keepMasterOpen) close(ttyMasterPty);
+
+           /* Open the slave end of the pty */
+
+           ttyName[5] = 't';   /* Change /dev/pty?? to /dev/tty?? */
+
+           t->file = open(ttyName, O_RDWR, 0777);
+           
+           if (t->file < 0) {
+               /* Couldn't open the tty--better get rid of the process */
+               kill (t->pid, SIGINT);
+               return 0;
+           }
+
+           /* Read the windowid from the pty */
+
+           len = 0;
+           while ((bytesRead = read(t->file, inputBuffer + len,
+                   sizeof(Window) - len)) > 0) len += bytesRead;
+
+           /* Flush the rest of the garbahge */
+
+           ioctl(t->file, TIOCFLUSH, (struct sgttyb *) NULL);
+
+           /* the data consists of a binary window ID */
+
+           t->w = *(Window *) inputBuffer;
+       }
+       return 1;
+#undef BUFSIZE
+}
+
+int GetPty(name)
+       char *name;
+{
+       register int devindex, letter;
+       int fd;
+
+       strcpy(name, "/dev/ptyp0");
+
+       for (letter = 0; letter < 4; letter++) {
+           name[8] = "pqrs"[letter];
+           
+           for (devindex = 0; devindex < 16; devindex++) {
+               name[9] = "0123456789abcdef"[devindex];
+               if ((fd = open (name, O_RDWR)) >= 0) return fd;
+           }
+       }
+       
+       return -1;
+}      
+
+DestroyTTYWindow(t)
+       TTYWindow *t;
+{
+       /* close the tty; this should cause the xterm to terminate with an I/O error */
+       close(t->file);  
+       free(t);
+}
+
+TTYPutString(t, str)
+       TTYWindow *t;
+       char *str;
+{
+       write(t->file, str, strlen(str));
+}
+
+TTYPutChar(t, ch)
+       TTYWindow *t;
+       char ch;
+{
+       write(t->file, &ch, 1);
+}
+
+TTYPrintf(t, format, args)
+       TTYWindow *t;
+       char *format;
+{
+#define TTY_BUFSIZE 2048
+       char buffer[TTY_BUFSIZE+1];
+       struct _iobuf _strbuf;
+
+       _strbuf._flag = _IOWRT+_IOSTRG;
+       _strbuf._ptr = buffer;
+       _strbuf._cnt = TTY_BUFSIZE;
+       _doprnt(format, &args, &_strbuf);
+       _strbuf._cnt++;     /* Be sure there's room for the \0 */
+       putc('\0', &_strbuf);
+       TTYPutString(t, buffer);
+#undef TTY_BUFSIZE
+}
+
+static initial_stdout = -1;
+
+SetStdout(t)
+       TTYWindow *t;
+{
+       if (initial_stdout == -1) initial_stdout = stdout->_file;
+       fflush(stdout);
+       stdout->_file = t->file;
+}
+
+ResetStdout()
+{
+       fflush(stdout);
+       stdout->_file = initial_stdout;
+       initial_stdout = -1;
+}
+
+#define CMASK 0377
+
+int TTYGetChar(t)
+       TTYWindow *t;
+{
+       char c;
+
+       if (read(t->file, &c, 1) > 0)
+           return (c & CMASK);
+       else return (EOF);
+}
+
+char *TTYGetString(t, str, n)
+       register TTYWindow *t;
+       char *str;
+       register int n;
+{
+       register char *cs;
+
+       cs = str;
+       while (--n > 0 && read(t->file, cs, 1) > 0) {
+           if (*cs++ == '\n') break;
+       }
+
+       if (cs == str) return NULL;
+
+       *cs = '\0';
+       return str;
+
+}
diff --git a/usr/contrib/X/Xlib/keymap.c b/usr/contrib/X/Xlib/keymap.c
new file mode 100644 (file)
index 0000000..290494a
--- /dev/null
@@ -0,0 +1,263 @@
+#include <X/mit-copyright.h>
+
+/* $Header: keymap.c,v 10.5 86/02/01 15:42:53 tony Rel $ */
+/* Copyright    Massachusetts Institute of Technology    1984, 1985    */
+
+#include "Xlib.h"
+
+KeyMapEntry StdMap [] =
+{
+/* key code    plain   shifted meta    M-shift control C-shift C-M     C-M-S   key label */
+/* 0000 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /* red */
+/* 0001 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /* yellow */
+/* 0002 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /* blue */
+/* 0003 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0004 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0005 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0006 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0007 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0010 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0011 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0012 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0013 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0014 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0015 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0016 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0017 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0020 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0021 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0022 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0023 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0024 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0025 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0026 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0027 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0030 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0031 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0032 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0033 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0034 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0035 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0036 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0037 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0040 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0041 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0042 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0043 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0044 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0045 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0046 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0047 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0050 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0051 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0052 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0053 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0054 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0055 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0056 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0057 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0060 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0061 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0062 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0063 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0064 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0065 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0066 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0067 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0070 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0071 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0072 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0073 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0074 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0075 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0076 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0077 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0100 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0101 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0102 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0103 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0104 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0105 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0106 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0107 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0110 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0111 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0112 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0113 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0114 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0115 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0116 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0117 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0120 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0121 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0122 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0123 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0124 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0125 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0126 */     FUNC1,  FUNC1,  FUNC1,  FUNC1,  FUNC1,  FUNC1,  FUNC1,  FUNC1,  /* F1/Hold Screen */
+/* 0127 */     FUNC2,  FUNC2,  FUNC2,  FUNC2,  FUNC2,  FUNC2,  FUNC2,  FUNC2,  /* F2/Print Screen */
+/* 0130 */     FUNC3,  FUNC3,  FUNC3,  FUNC3,  FUNC3,  FUNC3,  FUNC3,  FUNC3,  /* F3/Set-Up */
+/* 0131 */     FUNC4,  FUNC4,  FUNC4,  FUNC4,  FUNC4,  FUNC4,  FUNC4,  FUNC4,  /* F4 */
+/* 0132 */     FUNC5,  FUNC5,  FUNC5,  FUNC5,  FUNC5,  FUNC5,  FUNC5,  FUNC5,  /* F5/Break */
+/* 0133 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0134 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0135 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0136 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0137 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0140 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0141 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0142 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0143 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0144 */     FUNC6,  FUNC6,  FUNC6,  FUNC6,  FUNC6,  FUNC6,  FUNC6,  FUNC6,  /* F6 */
+/* 0145 */     FUNC7,  FUNC7,  FUNC7,  FUNC7,  FUNC7,  FUNC7,  FUNC7,  FUNC7,  /* F7 */
+/* 0146 */     FUNC8,  FUNC8,  FUNC8,  FUNC8,  FUNC8,  FUNC8,  FUNC8,  FUNC8,  /* F8 */
+/* 0147 */     FUNC9,  FUNC9,  FUNC9,  FUNC9,  FUNC9,  FUNC9,  FUNC9,  FUNC9,  /* F9 */
+/* 0150 */     FUNC10, FUNC10, FUNC10, FUNC10, FUNC10, FUNC10, FUNC10, FUNC10, /* F10 */
+/* 0151 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0152 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0153 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0154 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0155 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0156 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0157 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0160 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0161 */     0033,   0033,   0033,   0033,   0033,   0033,   0033,   0033,   /* F11/ESC */
+/* 0162 */     '\b',   '\b',   '\b',   -1,     '\b',   -1,     -1,     -1,     /* F12/BS */
+/* 0163 */     '\n',   '\n',   '\n',   -1,     '\n',   -1,     -1,     -1,     /* F13/LF */
+/* 0164 */     FUNC14, FUNC14, FUNC14, FUNC14, FUNC14, FUNC14, FUNC14, FUNC14, /* F14 */
+/* 0165 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0166 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0167 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0170 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0171 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0172 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0173 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0174 */     FUNC15, FUNC15, FUNC15, FUNC15, FUNC15, FUNC15, FUNC15, FUNC15, /* Help/F15 */
+/* 0175 */     FUNC16, FUNC16, FUNC16, FUNC16, FUNC16, FUNC16, FUNC16, FUNC16, /* Do/F16 */
+/* 0176 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0177 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0200 */     FUNC17, FUNC17, FUNC17, FUNC17, FUNC17, FUNC17, FUNC17, FUNC17, /* F17 */
+/* 0201 */     FUNC18, FUNC18, FUNC18, FUNC18, FUNC18, FUNC18, FUNC18, FUNC18, /* F18 */
+/* 0202 */     FUNC19, FUNC19, FUNC19, FUNC19, FUNC19, FUNC19, FUNC19, FUNC19, /* F19 */
+/* 0203 */     FUNC20, FUNC20, FUNC20, FUNC20, FUNC20, FUNC20, FUNC20, FUNC20, /* F20/Hyph */
+/* 0204 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0205 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0206 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0207 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0210 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0211 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0212 */     E1,     E1,     E1,     E1,     E1,     E1,     E1,     E1,     /* Find */
+/* 0213 */     E2,     E2,     E2,     E2,     E2,     E2,     E2,     E2,     /* Insert */
+/* 0214 */     E3,     E3,     E3,     E3,     E3,     E3,     E3,     E3,     /* Remove */
+/* 0215 */     E4,     E4,     E4,     E4,     E4,     E4,     E4,     E4,     /* Select */
+/* 0216 */     E5,     E5,     E5,     E5,     E5,     E5,     E5,     E5,     /* Prev Screen */
+/* 0217 */     E6,     E6,     E6,     E6,     E6,     E6,     E6,     E6,     /* Next Screen */
+/* 0220 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0221 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0222 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R0 */
+/* 0223 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0224 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R. */
+/* 0225 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* Enter */
+/* 0226 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R1 */
+/* 0227 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R2 */
+/* 0230 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R3 */
+/* 0231 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R4 */
+/* 0232 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R5 */
+/* 0233 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R6 */
+/* 0234 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R, */
+/* 0235 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R7 */
+/* 0236 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R8 */
+/* 0237 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R9 */
+/* 0240 */     KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, KEYPAD, /* R- */
+/* 0241 */     PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    /* PF1 */
+/* 0242 */     PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    /* PF2 */
+/* 0243 */     PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    /* PF3 */
+/* 0244 */     PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    PFX,    /* PF4 */
+/* 0245 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0246 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0247 */     CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, /* leftarrow */
+/* 0250 */     CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, /* rightarrow */
+/* 0251 */     CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, /* downarrow */
+/* 0252 */     CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, CURSOR, /* uparrow */
+/* 0253 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0254 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0255 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0256 */     SHFT,   SHFT,   SHFT,   SHFT,   SHFT,   SHFT,   SHFT,   SHFT,   /* Shift */
+/* 0257 */     CNTL,   CNTL,   CNTL,   CNTL,   CNTL,   CNTL,   CNTL,   CNTL,   /* Ctrl */
+/* 0260 */     LOCK,   LOCK,   LOCK,   LOCK,   LOCK,   LOCK,   LOCK,   LOCK,   /* Lock */
+/* 0261 */     SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, SYMBOL, /* Compose Character */
+/* 0262 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0263 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0264 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0265 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0266 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0267 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0270 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0271 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0272 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0273 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0274 */     0177,   0177,   0377,   0377,   0030,   0177,   0377,   0377,   /* back */
+/* 0275 */     '\r',   '\r',   0215,   0215,   '\r',   -1,     -1,     -1,     /* Return */
+/* 0276 */     '\t',   '\t',   0211,   0211,   '\t',   -1,     -1,     -1,     /* Tab */
+/* 0277 */     '`',    '~',    0340,   0376,   0036,   0036,   -1,     -1,     /* ` */
+/* 0300 */     '1',    '!',    0261,   0241,   '1',    '!',    -1,     -1,     /* 1 */
+/* 0301 */     'q',    'Q',    0361,   0321,   0021,   0021,   0221,   0221,   /* q */
+/* 0302 */     'a',    'A',    0341,   0301,   0001,   0001,   0201,   0201,   /* a */
+/* 0303 */     'z',    'Z',    0372,   0332,   0032,   0032,   0232,   0232,   /* z */
+/* 0304 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0305 */     '2',    '@',    0262,   0300,   0000,   0000,   0262,   0200,   /* 2 */
+/* 0306 */     'w',    'W',    0367,   0327,   0027,   0027,   0227,   0227,   /* w */
+/* 0307 */     's',    'S',    0363,   0323,   0023,   0023,   0223,   0223,   /* s */
+/* 0310 */     'x',    'X',    0370,   0330,   0030,   0030,   0230,   0230,   /* x */
+/* 0311 */     '<',    '>',    0274,   0276,   -1,     -1,     -1,     -1,     /* < */
+/* 0312 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0313 */     '3',    '#',    0263,   0243,   0033,   '#',    -1,     -1,     /* 3 */
+/* 0314 */     'e',    'E',    0345,   0305,   0005,   0005,   0205,   0205,   /* e */
+/* 0315 */     'd',    'D',    0344,   0304,   0004,   0004,   0204,   0204,   /* d */
+/* 0316 */     'c',    'C',    0343,   0303,   0003,   0003,   0203,   0203,   /* c */
+/* 0317 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0320 */     '4',    '$',    0264,   0244,   0034,   '$',    -1,     -1,     /* 4 */
+/* 0321 */     'r',    'R',    0362,   0322,   0022,   0022,   0222,   0222,   /* r */
+/* 0322 */     'f',    'F',    0346,   0306,   0006,   0006,   0206,   0206,   /* f */
+/* 0323 */     'v',    'V',    0366,   0326,   0026,   0026,   0226,   0226,   /* v */
+/* 0324 */     ' ',    ' ',    0240,   0240,   0000,   0000,   0200,   0200,   /* space */
+/* 0325 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0326 */     '5',    '%',    0265,   0245,   0035,   '%',    -1,     -1,     /* 5 */
+/* 0327 */     't',    'T',    0364,   0324,   0024,   0024,   0224,   0224,   /* t */
+/* 0330 */     'g',    'G',    0347,   0307,   0007,   0007,   0207,   0207,   /* g */
+/* 0331 */     'b',    'B',    0342,   0302,   0002,   0002,   0202,   0202,   /* b */
+/* 0332 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0333 */     '6',    '^',    0266,   0336,   0036,   0036,   -1,     -1,     /* 6 */
+/* 0334 */     'y',    'Y',    0371,   0331,   0031,   0031,   0231,   0231,   /* y */
+/* 0335 */     'h',    'H',    0350,   0310,   0010,   0010,   0210,   0210,   /* h */
+/* 0336 */     'n',    'N',    0356,   0316,   0016,   0016,   0216,   0216,   /* n */
+/* 0337 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0340 */     '7',    '&',    0267,   0246,   0037,   '&',    -1,     -1,     /* 7 */
+/* 0341 */     'u',    'U',    0365,   0325,   0025,   0025,   0225,   0225,   /* u */
+/* 0342 */     'j',    'J',    0352,   0312,   0012,   0012,   0212,   0212,   /* j */
+/* 0343 */     'm',    'M',    0355,   0315,   0015,   0015,   0215,   0215,   /* m */
+/* 0344 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0345 */     '8',    '*',    0270,   0252,   0177,   '*',    -1,     -1,     /* 8 */
+/* 0346 */     'i',    'I',    0351,   0311,   0011,   0011,   0211,   0211,   /* i */
+/* 0347 */     'k',    'K',    0353,   0313,   0013,   0013,   0213,   0213,   /* k */
+/* 0350 */     ',',    '<',    0254,   0274,   -1,     -1,     -1,     -1,     /* , */
+/* 0351 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0352 */     '9',    '(',    0271,   0250,   '9',    '(',    -1,     -1,     /* 9 */
+/* 0353 */     'o',    'O',    0357,   0317,   0017,   0017,   0217,   0217,   /* o */
+/* 0354 */     'l',    'L',    0354,   0314,   0014,   0014,   0214,   0214,   /* l */
+/* 0355 */     '.',    '>',    0256,   0276,   -1,     -1,     -1,     -1,     /* . */
+/* 0356 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0357 */     '0',    ')',    0260,   0251,   '0',    ')',    -1,     -1,     /* 0 */
+/* 0360 */     'p',    'P',    0360,   0320,   0020,   0020,   0220,   0220,   /* p */
+/* 0361 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0362 */     ';',    ':',    0273,   0272,   -1,     -1,     -1,     -1,     /* ; */
+/* 0363 */     '/',    '?',    0257,   0277,   0037,   0037,   0237,   0237,   /* / */
+/* 0364 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0365 */     '=',    '+',    0275,   0253,   -1,     -1,     -1,     -1,     /* = */
+/* 0366 */     ']',    '}',    0335,   0376,   0035,   0035,   0335,   0335,   /* ] */
+/* 0367 */     '\\',   '|',    0334,   0374,   0034,   0034,   0334,   0334,   /* \ */
+/* 0370 */     -1,     -1,     -1,     -1,     -1,     -1,     -1,     -1,     /*  */
+/* 0371 */     '-',    '_',    0255,   0337,   0037,   0037,   0337,   0337,   /* - */
+/* 0372 */     '[',    '{',    0333,   0373,   0033,   0033,   0333,   0333,   /* [ */
+/* 0373 */     '\'',   '"',    0247,   0242,   -1,     -1,     -1,     -1,     /* ' */
+};
diff --git a/usr/contrib/X/include/X/Xtty.h b/usr/contrib/X/include/X/Xtty.h
new file mode 120000 (symlink)
index 0000000..ab6d0b8
--- /dev/null
@@ -0,0 +1 @@
+../../Xlib/Xtty.h
\ No newline at end of file