home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-21 | 53.8 KB | 2,189 lines |
- Newsgroups: comp.sources.misc
- From: pvr@wang.com (Peter Reilley)
- Subject: v26i043: beav - Binary file editor and viewer, v1.32, Part07/09
- Message-ID: <1991Nov21.230344.1908@sparky.imd.sterling.com>
- X-Md4-Signature: 9443a1e4dc2594cf2c5f9d2ef185ecfe
- Date: Thu, 21 Nov 1991 23:03:44 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: pvr@wang.com (Peter Reilley)
- Posting-number: Volume 26, Issue 43
- Archive-name: beav/part07
- Environment: UNIX, AIX, MS-DOS, AMIGA
- Supersedes: beav: Volume 22, Issue 10-18
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: extend.c main.c makefile.utx termio.c ttykbd.c window.c
- # Wrapped by kent@sparky on Thu Nov 21 16:47:02 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 7 (of 9)."'
- if test -f 'extend.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'extend.c'\"
- else
- echo shar: Extracting \"'extend.c'\" \(11319 characters\)
- sed "s/^X//" >'extend.c' <<'END_OF_FILE'
- X/*
- X* Extended (M-X) commands.
- X*/
- X#include "def.h"
- X
- Xextern char MSG_not_now[];
- Xextern char MSG_func[];
- Xextern char MSG_unk_func[];
- Xextern char MSG_cmd_t_ex[];
- Xextern char MSG_unk_ext[];
- Xextern char MSG_d_b[];
- Xextern char MSG_unbd[];
- Xextern char MSG_bnd_to[];
- Xextern char MSG_ins_self[];
- Xextern char MSG_bnd_file[];
- Xextern char MSG_bld_wall[];
- Xextern char MSG_wall_head[];
- Xextern char MSG_beavrc[];
- Xextern char MSG_null[];
- X
- X
- X#ifdef CUSTOMIZE
- X
- Xchar *flook();
- X
- Xstatic char *bindnm =
- X{
- X 0
- X}; /* file name for customized key bindings */
- X#endif
- X
- X/*
- X* This function modifies the keyboard
- X* binding table, by adjusting the entries in the
- X* big "bindings" array. Most of the grief deals with the
- X* prompting for additional arguments. This code does not
- X* work right if there is a keyboard macro floating around.
- X* Should be fixed.
- X*/
- Xbool bindtokey ()
- X{
- X
- X register int s;
- X register SYMBOL * sp;
- X register int c;
- X char xname[NXNAME];
- X#ifdef CUSTOMIZE
- X char xname2[NXNAME];
- X#endif
- X
- X if (kbdmip != NULL || kbdmop != NULL)
- X {
- X writ_echo (MSG_not_now);
- X return (FALSE);
- X }
- X
- X if ((s = eread (MSG_func, xname, NXNAME, EFAUTO, NULL)) != TRUE)
- X return (s);
- X if ((sp = symlookup (xname)) == NULL)
- X {
- X writ_echo (MSG_unk_func);
- X return (FALSE);
- X }
- X
- X#ifdef CUSTOMIZE
- X strcpy (xname2, xname);
- X#endif
- X eputc (' ');
- X eputc ('K');
- X eputc ('e');
- X eputc ('y');
- X eputc (':');
- X eputc (' ');
- X ttflush ();
- X c = getkey (); /* Read key. */
- X keyname (xname, c); /* Display keyname. */
- X eputs (xname);
- X ttflush ();
- X if (binding[c] != NULL) /* Unbind old, and */
- X --binding[c] -> s_nkey;
- X binding[c] = sp; /* rebind new. */
- X ++sp -> s_nkey;
- X sp -> s_modify |= SBOUND; /* flag as altered key binding */
- X
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Extended command. Call the message line
- X* routine to read in the command name and apply autocompletion
- X* to it. When it comes back, look the name up in the symbol table
- X* and run the command if it is found and has the right type.
- X* Print an error if there is anything wrong.
- X*/
- Xchar extend (f, n, k)
- X{
- X
- X register SYMBOL * sp;
- X register char s;
- X char xname[NXNAME];
- X
- X if ((s = eread (MSG_cmd_t_ex, xname, NXNAME, EFNEW | EFAUTO, NULL)) != TRUE)
- X return (s);
- X if ((sp = symlookup (xname)) != NULL)
- X return ((*sp -> s_funcp) (f, n, KRANDOM));
- X writ_echo (MSG_unk_ext);
- X return (ABORT);
- X}
- X
- X
- X/*
- X* Read a key from the keyboard, and look it
- X* up in the binding table. Display the name of the function
- X* currently bound to the key. Say that the key is not bound
- X* if it is indeed not bound, or if the type is not a
- X* "builtin". This is a bit of overkill, because this is the
- X* only kind of function there is.
- X*/
- Xbool help ()
- X{
- X register SYMBOL * sp;
- X register int c;
- X char b[20];
- X char buf[80];
- X
- X writ_echo (MSG_d_b);
- X
- X c = getkey ();
- X keyname (b, c);
- X if ((sp = binding[c]) == NULL)
- X {
- X sprintf (buf, MSG_unbd, b);
- X writ_echo (buf);
- X }
- X else
- X {
- X sprintf (buf, MSG_bnd_to, b, sp -> s_name);
- X writ_echo (buf);
- X }
- X return (TRUE);
- X}
- X
- X/*
- X* Sort the lines in the buffer.
- X*/
- Xvoid sort_buf (b_ptr, cnt)
- XBUFFER *b_ptr;
- Xint cnt;
- X{
- X LINE *lp1, *lp2;
- X bool no_swap;
- X int loop1, loop2;
- X
- X for (loop1 = cnt; loop1 > 0; loop1--)
- X {
- X no_swap = TRUE;
- X lp1 = b_ptr -> b_linep -> l_fp; /* point to first line */
- X lp2 = lp1 -> l_fp; /* point to next line */
- X for (loop2 = 0; loop2 <= loop1; loop2++)
- X {
- X /* compare strings and swap if necessary */
- X if (0 < strcmp (&lp1 -> l_text[HFUNCCOL], &lp2 -> l_text[HFUNCCOL]))
- X {
- X lp1 -> l_bp -> l_fp = lp2; /* get pointer to first string */
- X lp2 -> l_fp -> l_bp = lp1; /* make it point to second string */
- X
- X lp1 -> l_fp = lp2 -> l_fp;
- X lp2 -> l_bp = lp1 -> l_bp;
- X
- X lp1 -> l_bp = lp2;
- X lp2 -> l_fp = lp1;
- X
- X lp2 -> l_file_offset = lp1 -> l_file_offset;
- X lp1 -> l_file_offset = lp2 -> l_file_offset + lp2 -> l_used;
- X
- X no_swap = FALSE;
- X }
- X else
- X {
- X /* if no swap then advance both pointers */
- X lp1 = lp2;
- X }
- X lp2 = lp1 -> l_fp;
- X }
- X /* quick exit if sort is finished sooner than expected */
- X if (no_swap)
- X {
- X return;
- X }
- X }
- X}
- X
- X/*
- X* This function creates a table, listing all
- X* of the command keys and their current bindings, and stores
- X* the table in the standard pop-op buffer (the one used by the
- X* directory list command, the buffer list command, etc.). This
- X* lets the editor produce it's own wall chart. The bindings to
- X* "ins-self" are only displayed if there is an argument.
- X*/
- Xchar wallchart (f, n, k)
- X{
- X
- X register char s;
- X register int key, i, j;
- X register SYMBOL * sp;
- X register char *cp1;
- X register char *cp2;
- X char buf[64];
- X WINDOW *wp;
- X
- X if ((s = bclear (blistp)) != TRUE)/* Clear it out. */
- X return (s);
- X i = 0;
- X (void) strcpy (blistp -> b_fname, MSG_null);
- X blistp -> b_flag = BFVIEW;
- X blistp -> b_type = BTHELP;
- X writ_echo (MSG_bld_wall);
- X sprintf (buf, MSG_wall_head);
- X if (addline (buf) == FALSE)
- X return(FALSE);
- X for (key = 0; key < NKEYS; ++key)
- X {
- X /* For all keys. */
- X sp = binding[key];
- X if (sp != NULL &&
- X (f != FALSE || strcmp (sp -> s_name, MSG_ins_self) != 0))
- X {
- X cp1 = &buf[0];
- X while (cp1 < &buf[HFUNCCOL])/* Goto column 3. */
- X *cp1++ = ' ';
- X if ((sp -> s_modify & SBOUND) == 0) /* comment out default binding */
- X buf[0] = '#';
- X cp2 = sp -> s_name; /* Add function name. */
- X while (*cp1++ = *cp2++)
- X ;
- X cp1--;
- X while (cp1 < &buf[HKEY])/* Goto column 32. */
- X *cp1++ = ' ';
- X keyname (&buf[HKEY], key);
- X cp1 = &buf[strlen(buf)];
- X while (cp1 < &buf[HKEYCODE])/* Goto column 50. */
- X *cp1++ = ' ';
- X sprintf (&buf[HKEYCODE], "%4X", key);
- X if (addline (buf) == FALSE)
- X break; /* lets go with what we have */
- X i++;
- X }
- X }
- X
- X /* list unbound functions lest they get lost */
- X for (j = 0; j < NSHASH; j++)
- X {
- X sp = symbol[j];
- X while (sp != NULL)
- X {
- X if (sp -> s_nkey == 0)
- X {
- X cp1 = &buf[0];
- X while (cp1 < &buf[HFUNCCOL])/* Goto column 3. */
- X *cp1++ = ' ';
- X buf[0] = '#';
- X cp2 = sp -> s_name; /* Add function name. */
- X while (*cp1++ = *cp2++)
- X ;
- X cp1--;
- X while (cp1 < &buf[HENDCOL])
- X *cp1++ = ' ';
- X *cp1 = 0;
- X i++;
- X if (addline (buf) == FALSE)
- X break; /* lets go with what we have */
- X }
- X sp = sp -> s_symp;
- X }
- X }
- X sort_buf (blistp, i); /* sort buffer lines */
- X popblist ();
- X writ_echo (MSG_null);
- X /* make new window the current window */
- X wp = wheadp;
- X while (wp != NULL)
- X {
- X if (wp -> w_bufp == blistp)
- X {
- X curwp = wp;
- X curbp = wp -> w_bufp;
- X return (TRUE);
- X }
- X wp = wp -> w_wndp;
- X }
- X return (TRUE);
- X}
- X
- X/* check for BEAVFIL and read it in if found
- X* - also, set local file variable for bindtokey for saving new defs
- X* (this is some what of a hack as it only handles 'bindtokey' changes at
- X* this time - also local file io !!!)
- X*/
- Xvoid check_extend (sfname)
- X
- Xchar *sfname; /* name of startup file (null if default) */
- X
- X{
- X char *fname; /* resulting file name to execute */
- X char rc_name[NFILEN]; /* fixed up name of rc file */
- X char *term;
- X char *getenv();
- X register SYMBOL * sp;
- X char funcname[NXNAME + 1];
- X char keybind[NXNAME + 1];
- X int keyval;
- X FILE * bindf;
- X
- X /* look up the startup file */
- X if ((sfname != NULL) && (*sfname != 0))
- X fname = flook(sfname, TRUE);
- X else
- X {
- X#ifdef UNIX
- X /* hidden file under unix */
- X strcpy (&rc_name[0], ".");
- X strcpy (&rc_name[1], MSG_beavrc);
- X
- X if ((term = getenv("TERM")) != 0)
- X {
- X strcpy (&rc_name[strlen(rc_name)], ".");
- X strcpy (&rc_name[strlen(rc_name)], term);
- X }
- X fname = flook(rc_name, TRUE);
- X /* if fixed up name is not there then check original */
- X if (fname == NULL)
- X {
- X /* hidden file under unix */
- X strcpy (&rc_name[0], ".");
- X strcpy (&rc_name[1], MSG_beavrc);
- X fname = flook(rc_name, TRUE);
- X }
- X#else
- X strcpy (rc_name, MSG_beavrc);
- X fname = flook(rc_name, TRUE);
- X#ifdef AMIGA
- X /* look for .beavrc in the current directory */
- X if(!fname) {
- X rc_name[0] = '.';
- X strcpy (&rc_name[1], MSG_beavrc);
- X fname = flook(rc_name, TRUE);
- X }
- X /* look for .beavrc in S: */
- X if(!fname) {
- X /* Have a look in startup directory */
- X rc_name[0] = 'S';
- X rc_name[1] = ':';
- X rc_name[2] = '.';
- X strcpy (&rc_name[3], MSG_beavrc);
- X fname = flook(rc_name, TRUE);
- X }
- X#endif /* AMIGA */
- X#endif
- X }
- X /* if it isn't around, don't sweat it */
- X if (fname == NULL)
- X return;
- X
- X if (bindf = fopen(fname, "r"))
- X {
- X char buffr[80];
- X char *buffp;
- X
- X buffp = buffr;
- X while (fread (buffp++, sizeof(char), 1, bindf) == 1)
- X {
- X /* scanf is unhappy with commas */
- X if (buffp[-1] == ',')
- X buffp[-1] = '-';
- X
- X /* did we get a whole line */
- X if (buffp[-1] == '\n')
- X {
- X *buffp = 0; /* terminate line */
- X buffp = buffr;
- X sscanf (buffr, "%s %s %x", funcname, keybind, &keyval);
- X if ((buffr[0] == '#') || (keyval == 0))
- X continue;
- X if (sp = symlookup (funcname))
- X {
- X if (binding[keyval] != NULL)/* Unbind old, and */
- X --binding[keyval] -> s_nkey;
- X binding[keyval] = sp;/* rebind new. */
- X ++sp -> s_nkey;
- X sp -> s_modify |= SBOUND; /* flag as altered key binding */
- X }
- X }
- X }
- X fclose (bindf);
- X }
- X}
- X
- X/* Look up the existance of a file along the normal or PATH
- X environment variable. Look first in the HOME directory if
- X asked and possible
- X*/
- X
- Xchar *flook(fname, hflag)
- X
- Xchar *fname; /* base file name to search for */
- Xint hflag; /* Look in the HOME environment variable first? */
- X
- X{
- X register char *home; /* path to home directory */
- X register char *path; /* environmental PATH variable */
- X register char *sp; /* pointer into path spec */
- X register int i; /* index */
- X static char fspec[NFILEN * 2]; /* full path spec to search */
- X char *getenv();
- X FILE * bindf;
- X
- X if (hflag) {
- X home = getenv("HOME");
- X if (home != NULL) {
- X /* build home dir file spec */
- X strcpy(fspec, home);
- X if (fspec[strlen(fspec) - 1] != '/')
- X strcat(fspec, "/");
- X strcat(fspec, fname);
- X
- X /* and try it out */
- X if (bindf = fopen(fspec, "r"))
- X {
- X fclose(bindf);
- X return(fspec);
- X }
- X }
- X }
- X
- X /* always try the current directory first */
- X if (bindf = fopen(fname, "r"))
- X {
- X fclose(bindf);
- X return(fname);
- X }
- X
- X /* get the PATH variable */
- X path = getenv("PATH");
- X if (path != NULL)
- X while (*path) {
- X
- X /* build next possible file spec */
- X sp = fspec;
- X while (*path && (*path != PATHCHR))
- X *sp++ = *path++;
- X
- X /* add a terminating dir separator if we need it */
- X if (sp[-1] != SEPCHAR)
- X *sp++ = SEPCHAR;
- X
- X *sp = 0;
- X strcat(fspec, fname);
- X
- X /* and try it out */
- X if (bindf = fopen(fspec, "r"))
- X {
- X fclose(bindf);
- X return(fspec);
- X }
- X
- X if (*path == PATHCHR)
- X ++path;
- X }
- X
- X return(NULL); /* no such luck */
- X}
- X
- X
- X/* interactive method for loading binding file
- X* (uses above routine, obviously)
- X*/
- Xchar load_extend ()
- X{
- X
- X#ifdef CUSTOMIZE
- X register char s;
- X char fname[NFILEN];
- X
- X if ((s = ereply (MSG_bnd_file, fname, NFILEN, NULL)) != TRUE)
- X return (s);
- X check_extend (fname);
- X writ_echo (okmsg);
- X#endif
- X return (TRUE);
- X}
- X
- Xint find_keyval (name)
- Xchar *name;
- X{
- X SYMBOL * sp;
- X int key;
- X
- X for (key = 0; key < NKEYS; ++key)
- X {
- X /* For all keys. */
- X sp = binding[key];
- X if (sp != NULL && (strcmp (sp -> s_name, name) == 0))
- X return (key);
- X }
- X return (0);
- X}
- END_OF_FILE
- if test 11319 -ne `wc -c <'extend.c'`; then
- echo shar: \"'extend.c'\" unpacked with wrong size!
- fi
- # end of 'extend.c'
- fi
- if test -f 'main.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'main.c'\"
- else
- echo shar: Extracting \"'main.c'\" \(11143 characters\)
- sed "s/^X//" >'main.c' <<'END_OF_FILE'
- X/*
- X* BEAV is based on the source for emacs for display and keyboard handling
- X* functions. The binary file handling and display formats are special
- X* to BEAV. There is a full manual included in this release. There
- X* are makefiles for unix and MSC 5.1 under DOS. The old Wang PC is
- X* supported. This release is for unix. The def_unix.h file is the
- X* header for unix and the def_dos.h file is the header for dos. Rename
- X* the appropriate .h file to def.h to convert to your os.
- X* I am willing to maintain BEAV and will entertain suggestions for
- X* modifications and/or bug fixes. I can be reached at;
- X*
- X* pvr@wang.com
- X*
- X* or at;
- X*
- X* Peter Reilley
- X* 19 Heritage Cir.
- X* Hudson, N.H. 03051
- X*/
- X
- X/*
- X* Bug fix log
- X* 3/04/91 1.20 pvr
- X* Create new file with read/write permisions.
- X* Fix polled mode system hog tty bug.
- X* Add ANSI define for DOS.
- X* Define short for D16 type.
- X* Call ttclose on error exit.
- X* Limit nrow and ncol to actual array size.
- X* Added beavrc key binding functionallity.
- X* Added delete current window command.
- X* Support VT100 type function keys for binding.
- X*/
- X/*
- X*
- X* Mainline, macro commands.
- X*/
- X#include "def.h"
- X
- Xbool execute ();
- Xvoid edinit ();
- Xchar flush_all ();
- Xchar quit ();
- Xchar ctrlg ();
- Xvoid _lowercase ();
- X
- X
- Xextern char MSG_ok[];
- Xextern char MSG_main[];
- Xextern char MSG_prog_name[];
- Xextern char MSG_no_mod[];
- Xextern char MSG_no_s_chg[];
- Xextern char MSG_auto_fl[];
- Xextern char MSG_quit[];
- Xextern char MSG_not_now[];
- Xextern char MSG_st_mac[];
- Xextern char MSG_end_mac[];
- Xextern char MSG_num_mod[];
- Xextern char MSG_null[];
- X
- Xint thisflag; /* Flags, this command */
- Xint lastflag; /* Flags, last command */
- Xint curgoal; /* Goal column */
- Xint com_line_flags; /* Count of cmd line switches */
- XBUFFER * curbp; /* Current buffer */
- XWINDOW * curwp; /* Current window */
- XBUFFER * bheadp; /* BUFFER listhead */
- XWINDOW * wheadp; /* WINDOW listhead */
- XBUFFER * blistp; /* Buffer list BUFFER */
- Xshort kbdm[NKBDM] = {
- X (KCTLX | ')')}; /* Macro (fitz) */
- Xshort *kbdmip; /* Input for above */
- Xshort *kbdmop; /* Output for above */
- XSYMBOL * symbol[NSHASH]; /* Symbol table listhead. */
- XSYMBOL * binding[NKEYS]; /* Key bindings. */
- Xextern ROW_FMT hex_8_fmt;
- Xextern bool ibm_pc, mem_map;
- X
- Xchar *okmsg = {
- X MSG_ok};
- Xint insert_mode = {
- X TRUE};
- Xint extend_buf = {
- X FALSE};
- X
- Xextern bool srch_mode;
- Xextern bool rplc_mode;
- Xextern char *getenv ();
- Xint initial_load = 0;
- Xint flush_count = 0;
- Xint flush_num = 500;
- Xint auto_update = 0;
- X
- Xvoid main (argc, argv)
- Xchar *argv[];
- X{
- X
- X register int c;
- X register int f;
- X register int n;
- X register int mflag;
- X char bname[NBUFN];
- X
- X#if MSDOS
- X is_wang (); /* Check for computer type */
- X
- X#endif
- X init_fmt (); /* initialize format arrays */
- X strcpy (bname, MSG_main); /* Get buffer name. */
- X vtinit (); /* Virtual terminal. */
- X keymapinit (); /* Symbols, bindings. */
- X
- X if (argc == 1)
- X {
- X edinit (bname);
- X update ();
- X eerase ();
- X }
- X
- X else
- X {
- X com_line_flags = 0;
- X initial_load = 1;
- X n = (argc - 1); /* Load them backwards */
- X if (n > com_line_flags)
- X {
- X /* _lowercase (argv[n]); */
- X makename (bname, argv[n]);
- X edinit (bname); /* Buffers, windows. */
- X update ();
- X readin (argv[n--], 0L, MAXPOS);
- X for (; n > com_line_flags; n--)
- X {
- X /* _lowercase (argv[n]); */
- X load_file (argv[n], 0L, MAXPOS);
- X }
- X }
- X else
- X {
- X edinit (bname);
- X update ();
- X }
- X
- X initial_load = 0;
- X }
- X
- X check_extend (NULL); /* check for extended keys */
- X save_buf_init(); /* initialize save buffer */
- X lastflag = 0; /* Fake last flags. */
- X
- Xloop:
- X update ();
- X c = getkey ();
- X if (epresf != FALSE)
- X {
- X eerase ();
- X update ();
- X }
- X f = FALSE;
- X n = 1;
- X if (c == (KCTRL | 'U'))
- X {
- X /* ^U, start argument. */
- X f = TRUE;
- X n = 4;
- X while ((c = getkey ()) == (KCTRL | 'U'))
- X n *= 4;
- X if ((c >= '0' && c <= '9') || c == '-')
- X {
- X if (c == '-')
- X {
- X n = 0;
- X mflag = TRUE;
- X }
- X else
- X {
- X n = c - '0';
- X mflag = FALSE;
- X }
- X while ((c = getkey ()) >= '0' && c <= '9')
- X n = 10 * n + c - '0';
- X if (mflag != FALSE)
- X n = -n;
- X }
- X }
- X if (kbdmip != NULL)
- X {
- X /* Save macro strokes. */
- X if (c != (KCTLX | ')') && kbdmip > &kbdm[NKBDM - 6])
- X {
- X ctrlg (FALSE, 0, KRANDOM);
- X goto loop;
- X }
- X if (f != FALSE)
- X {
- X *kbdmip++ = (KCTRL | 'U');
- X *kbdmip++ = n;
- X }
- X *kbdmip++ = c;
- X }
- X execute (c, f, n); /* Do it. */
- X goto loop;
- X}
- X
- X
- X/*
- X* Command execution. Look up the binding in the the
- X* binding array, and do what it says. Return a very bad status
- X* if there is no binding, or if the symbol has a type that
- X* is not usable (there is no way to get this into a symbol table
- X* entry now). Also fiddle with the flags.
- X*/
- Xchar execute (c, f, n)
- X{
- X
- X register SYMBOL * sp;
- X register int status;
- X
- X if ((sp = binding[c]) != NULL)
- X {
- X thisflag = 0;
- X if (sp -> s_modify & SMOD && (curbp -> b_flag & BFVIEW))
- X {
- X writ_echo (MSG_no_mod);
- X return (ABORT);
- X }
- X if (sp -> s_modify & SSIZE && (curbp -> b_flag & BFSLOCK))
- X {
- X writ_echo (MSG_no_s_chg);
- X return (ABORT);
- X }
- X if ((srch_mode && !(sp -> s_modify & SSRCH)) ||
- X (rplc_mode && !(sp -> s_modify & SRPLC)))
- X {
- X ttbeep ();
- X return (TRUE);
- X }
- X
- X status = (*sp -> s_funcp) (f, n, c);
- X if (sp -> s_modify & SMOD)
- X flush_count++;
- X
- X if (flush_count >= flush_num && auto_update)
- X if (!(kbdmip != NULL || kbdmop != NULL))/* not during macro */
- X {
- X ttbeep ();
- X writ_echo (MSG_auto_fl);
- X flush_all ();
- X }
- X lastflag = thisflag;
- X return (status);
- X }
- X else
- X bad_key (c);
- X
- X lastflag = 0;
- X return (ABORT);
- X}
- X
- X
- X/*
- X* Initialize all of the buffers
- X* and windows. The buffer name is passed down as
- X* an argument, because the main routine may have been
- X* told to read in a file by default, and we want the
- X* buffer name to be right.
- X*/
- Xvoid edinit (bname)
- Xchar bname[];
- X{
- X
- X register BUFFER * bp;
- X register WINDOW * wp;
- X
- X bp = bfind (bname, TRUE); /* Text buffer. */
- X blistp = bcreate (MSG_null); /* Special list buffer. */
- X wp = (WINDOW *) malloc (sizeof (WINDOW));/* Initial window. */
- X if (bp == NULL || wp == NULL || blistp == NULL)
- X abort ();
- X curbp = bp; /* Current ones. */
- X wheadp = wp;
- X curwp = wp;
- X wp -> w_wndp = NULL; /* Initialize window. */
- X wp -> w_bufp = bp;
- X bp -> b_nwnd = 1; /* Displayed. */
- X wp -> w_fmt_ptr = &hex_8_fmt;/* HEX 8 bit display pvr */
- X wp -> w_linep = bp -> b_linep;
- X wp -> w_dotp = bp -> b_linep;
- X wp -> w_doto = 0; /* set dot pos pvr */
- X wp -> w_markp = NULL;
- X wp -> w_marko = 0;
- X wp -> w_toprow = 0;
- X wp -> w_ntrows = nrow - 2; /* 2 = mode, echo. */
- X wp -> w_flag = WFMODE | WFHARD;/* Full. */
- X wp -> w_intel_mode = FALSE; /* default is no byte swap pvr */
- X wp -> w_disp_shift = 0; /* default to no byte shift pvr */
- X wp -> w_loff = 0; /* starting line offset pvr */
- X wp -> w_unit_offset = 0; /* dot offset from file start pvr */
- X}
- X
- X/*
- X* Flush all the dirty buffers that have file names
- X* associated with them.
- X*/
- Xchar flush_all ()
- X{
- X register BUFFER * bp,
- X *savbp = curbp;
- X
- X for (bp = bheadp; bp != NULL; bp = bp -> b_bufp)
- X if (bp -> b_fname != NULL)
- X {
- X curbp = bp; /* jam */
- X filesave ();
- X update ();
- X }
- X flush_count = 0;
- X writ_echo (okmsg);
- X curbp = savbp;
- X if (blistp -> b_nwnd != 0) /* update buffer display */
- X listbuffers ();
- X update ();
- X return (TRUE);
- X}
- X
- X
- X/* call flush_all to empty the buffers
- X* and quit
- X*/
- Xbool flushnquit (f, n, k)
- X{
- X flush_all ();
- X quit (f, n, k);
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Quit command. If an argument, always
- X* quit. Otherwise confirm if a buffer has been
- X* changed and not written out. Normally bound
- X* to "C-X C-C".
- X*/
- Xchar quit (f, n, k)
- X{
- X
- X register char s;
- X
- X if (f != FALSE /* Argument forces it. */
- X || anycb () == FALSE/* All buffers clean. */
- X || (s = eyesno (MSG_quit)) == TRUE)/* User says it's OK. */
- X {
- X
- X vttidy ();
- X exit (GOOD);
- X }
- X
- X return (s);
- X}
- X
- X
- X/*
- X* Begin a keyboard macro.
- X* Error if not at the top level
- X* in keyboard processing. Set up
- X* variables and return.
- X*/
- Xbool ctlxlp (f, n, k)
- X{
- X
- X if (kbdmip != NULL || kbdmop != NULL)
- X {
- X
- X writ_echo (MSG_not_now);
- X return (FALSE);
- X }
- X
- X writ_echo (MSG_st_mac);
- X kbdmip = &kbdm[0];
- X return (TRUE);
- X}
- X
- X
- X/*
- X* End keyboard macro. Check for
- X* the same limit conditions as the
- X* above routine. Set up the variables
- X* and return to the caller.
- X*/
- Xbool ctlxrp (f, n, k)
- X{
- X
- X if (kbdmip == NULL)
- X {
- X
- X writ_echo (MSG_not_now);
- X return (FALSE);
- X }
- X
- X writ_echo (MSG_end_mac);
- X kbdmip = NULL;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Execute a macro.
- X* The command argument is the
- X* number of times to loop. Quit as
- X* soon as a command gets an error.
- X* Return TRUE if all ok, else
- X* FALSE.
- X*/
- Xbool ctlxe (f, n, k)
- X{
- X
- X register int c;
- X register int af;
- X register int an;
- X register int s;
- X
- X if (kbdmip != NULL || kbdmop != NULL)
- X {
- X
- X writ_echo (MSG_not_now);
- X return (FALSE);
- X }
- X
- X if (n <= 0)
- X return (TRUE);
- X do
- X {
- X
- X kbdmop = &kbdm[0];
- X do
- X {
- X
- X af = FALSE;
- X an = 1;
- X if ((c = *kbdmop++) == (KCTRL | 'U'))
- X {
- X
- X af = TRUE;
- X an = *kbdmop++;
- X c = *kbdmop++;
- X }
- X
- X s = TRUE;
- X } while (c != (KCTLX | ')') && (s = execute (c, af, an)) == TRUE);
- X kbdmop = NULL;
- X } while (s == TRUE && --n);
- X return (s);
- X}
- X
- X
- X/*
- X* Abort.
- X* Beep the beeper.
- X* Kill off any keyboard macro,
- X* etc., that is in progress.
- X* Sometimes called as a routine,
- X* to do general aborting of
- X* stuff.
- X*/
- Xchar ctrlg (f, n, k)
- X{
- X /* ttbeep (); */
- X if (kbdmip != NULL)
- X {
- X kbdm[0] = (KCTLX | ')');
- X kbdmip = NULL;
- X }
- X return (ABORT);
- X}
- X
- X
- X/*
- X* Display the version. All this does
- X* is copy the text in the external "version" array into
- X* the message system, and call the message reading code.
- X* Don't call display if there is an argument.
- X*/
- Xchar showversion (f, n, k)
- X{
- X static char *cp;
- X char buf[NCOL];
- X
- X cp = version;
- X sprintf (buf, cp);
- X writ_echo (buf);
- X return (TRUE);
- X}
- X
- X
- X/* ughly to_lower function for
- X* files read in under MSDOS setargv function
- X*/
- Xvoid _lowercase (s)
- Xregister char *s;
- X{
- X
- X#ifdef MSDOS
- X for (; *s; s++)
- X if (ISUPPER (*s))
- X *s = TOLOWER (*s);
- X#endif
- X}
- X
- X
- X/* autosave control
- X*/
- Xbool autosave ()
- X{
- X register WINDOW * wp;
- X int n;
- X char buf[NCOL];
- X
- X if ((ereply (MSG_num_mod, buf, sizeof (buf), NULL)) == TRUE)
- X {
- X
- X n = atoi (buf);
- X if (n >= 0)
- X auto_update = flush_num = n;/* not 0! */
- X else
- X auto_update = 0;
- X }
- X
- X for (wp = wheadp; wp; wp = wp -> w_wndp)
- X if (wp -> w_bufp == curbp)
- X wp -> w_flag |= WFMODE;
- X return (TRUE);
- X}
- END_OF_FILE
- if test 11143 -ne `wc -c <'main.c'`; then
- echo shar: \"'main.c'\" unpacked with wrong size!
- fi
- # end of 'main.c'
- fi
- if test -f 'makefile.utx' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'makefile.utx'\"
- else
- echo shar: Extracting \"'makefile.utx'\" \(668 characters\)
- sed "s/^X//" >'makefile.utx' <<'END_OF_FILE'
- X# This is the makefile for DEC ULTRIX
- XCFLAGS= -O -DUNIX -DBSD -DULTRIX
- X
- XOFILES= basic.o ebcdic.o fileio.o region.o text.o wangpc.o \
- X buffer.o echo.o main.o search.o tty.o window.o \
- X cinfo.o extend.o kbd.o spawn.o ttyio.o termio.o tcap.o word.o \
- X display.o file.o line.o random.o symbol.o ttykbd.o format.o
- X
- X
- XCFILES= basic.c ebcdic.c fileio.c region.c text.c wangpc.c \
- X buffer.c echo.c format.c main.c search.c tty.c window.c \
- X cinfo.c extend.c kbd.c spawn.c ttyio.c termio.c tcap.c word.c \
- X display.c file.c line.c random.c symbol.c ttykbd.c
- X
- XHFILES= def.h
- X
- Xbeav: $(OFILES)
- X $(CC) $(CFLAGS) $(OFILES) -ltermcap -lc -o beav
- X
- X(OFILES): $(HFILES)
- END_OF_FILE
- if test 668 -ne `wc -c <'makefile.utx'`; then
- echo shar: \"'makefile.utx'\" unpacked with wrong size!
- fi
- # end of 'makefile.utx'
- fi
- if test -f 'termio.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'termio.c'\"
- else
- echo shar: Extracting \"'termio.c'\" \(4865 characters\)
- sed "s/^X//" >'termio.c' <<'END_OF_FILE'
- X/*
- X * The functions in this file negotiate with the operating system for
- X * characters, and write characters in a barely buffered fashion on the display.
- X * All operating systems.
- X */
- X
- X#include <sys/types.h> /* 1.13 */
- X
- X#ifdef UNIX /* System V */
- X
- X#include <stdio.h>
- X#include <signal.h>
- X#ifdef BSD
- X#include <sys/ioctl.h>
- X#else
- X#include <termio.h>
- X#endif /* BSD */
- X#include <errno.h>
- X#include <fcntl.h>
- X#include "def.h"
- Xint kbdflgs; /* saved keyboard fd flags */
- Xint kbdpoll; /* in O_NDELAY mode */
- Xint kbdqp; /* there is a char in kbdq */
- Xchar kbdq; /* char we've already read */
- X
- X#ifdef BSD
- Xstruct sgttyb otermb;
- Xstruct sgttyb ntermb;
- X#else
- Xstruct termio otermio; /* original terminal characteristics */
- Xstruct termio ntermio; /* charactoristics to use inside */
- X#endif /* BSD */
- Xextern errno; /* System error number -- Necessary when compiling in BSD 1.13 */
- X
- Xint nrow; /* Terminal size, rows. */
- Xint ncol; /* Terminal size, columns. */
- X
- X/*
- X * This function is called once to set up the terminal device streams.
- X * On VMS, it translates TT until it finds the terminal, then assigns
- X * a channel to it and sets it raw. On CPM it is a no-op.
- X */
- X
- Xvoid ttopen()
- X{
- X#ifdef BSD
- X#ifdef ULTRIX
- X struct winsize ttysize;
- X#else
- X struct ttysize ttysize;
- X#endif
- X
- X ioctl(0, TIOCGETP, &otermb); /* save settings */
- X ntermb = otermb; /* setup new settings */
- X ntermb.sg_flags &= ~ECHO;
- X ntermb.sg_flags |= RAW;
- X ioctl(0, TIOCSETP, &ntermb); /* and activate them */
- X kbdpoll = FALSE;
- X
- X /* on all screens we are not sure of the initial position
- X of the cursor */
- X ttrow = 999;
- X ttcol = 999;
- X#if ULTRIX
- X if (ioctl(0, TIOCGWINSZ, &ttysize) == 0) {
- X nrow = ttysize.ws_row;
- X ncol = ttysize.ws_col;
- X#else
- X if (ioctl(0, TIOCGSIZE, &ttysize) == 0) {
- X nrow = ttysize.ts_lines;
- X ncol = ttysize.ts_cols;
- X#endif
- X } else {
- X nrow = NROW;
- X ncol = NCOL;
- X }
- X#else
- X ioctl(0, TCGETA, &otermio); /* save old settings */
- X ntermio.c_iflag = 0; /* setup new settings */
- X ntermio.c_oflag = 0;
- X ntermio.c_cflag = otermio.c_cflag;
- X ntermio.c_lflag = 0;
- X ntermio.c_line = otermio.c_line;
- X ntermio.c_cc[VMIN] = 1;
- X ntermio.c_cc[VTIME] = 0;
- X ioctl(0, TCSETAW, &ntermio); /* and activate them */
- X kbdflgs = fcntl( 0, F_GETFL, 0 );
- X kbdpoll = FALSE;
- X /* on all screens we are not sure of the initial position
- X of the cursor */
- X ttrow = 999;
- X ttcol = 999;
- X nrow = NROW;
- X ncol = NCOL;
- X#endif
- X }
- X
- X /*
- X * This function gets called just before we go back home to the command
- X * interpreter. On VMS it puts the terminal back in a reasonable state.
- X * Another no-operation on CPM.
- X */
- X void ttclose()
- X {
- X#ifdef BSD
- X if (ioctl(0, TIOCSETP, &otermb) == -1) /* restore terminal settings */
- X printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
- X#else
- X if (ioctl(0, TCSETAW, &otermio) == -1) /* restore terminal settings */
- X printf ("closing ioctl on dev 0 failure, error = %d\n", errno);
- X if (fcntl(0, F_SETFL, kbdflgs) == -1)
- X printf ("closing fcntl on dev 0 failure, error = %d\n", errno);
- X#endif
- X
- X }
- X
- X /*
- X * Write a character to the display. On VMS, terminal output is buffered, and
- X * we just put the characters in the big array, after checking for overflow.
- X * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
- X * MS-DOS (use the very very raw console output routine).
- X */
- X void ttputc(c)
- X {
- X fputc(c, stdout);
- X }
- X
- X /*
- X * Flush terminal buffer. Does real work where the terminal output is buffered
- X * up. A no-operation on systems where byte at a time terminal I/O is done.
- X */
- X void ttflush()
- X {
- X fflush(stdout);
- X }
- X
- X /*
- X * Read a character from the terminal, performing no editing and doing no echo
- X * at all. More complex in VMS that almost anyplace else, which figures. Very
- X * simple on CPM, because the system can do exactly what you want.
- X */
- X ttgetc()
- X {
- X if( kbdqp )
- X kbdqp = FALSE;
- X else
- X {
- X#ifdef BSD
- X int count;
- X
- X if (kbdpoll && (ioctl(0, FIONREAD, &count), count == 0))
- X return FALSE;
- X read(0, &kbdq, 1);
- X#else
- X if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
- X return FALSE;
- X kbdpoll = FALSE;
- X while (read(0, &kbdq, 1) != 1)
- X ;
- X#endif
- X }
- X return ( kbdq & 127 );
- X }
- X
- X /* typahead(): Check to see if any characters are already in the
- X keyboard buffer
- X*/
- X ttkeyready ()
- X {
- X if( !kbdqp )
- X {
- X#ifdef BSD
- X int count;
- X
- X if (!kbdpoll && (ioctl(0, FIONREAD, &count), count == 0))
- X return FALSE;
- X kbdpoll = TRUE; /* fix in 1.13 */
- X kbdqp = TRUE;
- X#else
- X if( !kbdpoll && fcntl( 0, F_SETFL, kbdflgs | O_NDELAY ) < 0 )
- X return(FALSE);
- X kbdpoll = TRUE; /* fix in 1.13 */
- X kbdqp = (1 == read( 0, &kbdq, 1 ));
- X#endif
- X
- X }
- X return ( kbdqp );
- X }
- X#endif
- END_OF_FILE
- if test 4865 -ne `wc -c <'termio.c'`; then
- echo shar: \"'termio.c'\" unpacked with wrong size!
- fi
- # end of 'termio.c'
- fi
- if test -f 'ttykbd.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ttykbd.c'\"
- else
- echo shar: Extracting \"'ttykbd.c'\" \(11099 characters\)
- sed "s/^X//" >'ttykbd.c' <<'END_OF_FILE'
- X/*
- X * Wang PC keyboard handler
- X */
- X#include "def.h"
- X
- Xextern char MSG_sp_key[];
- Xextern char MSG_byte_shift[];
- Xextern char MSG_back_char[];
- Xextern char MSG_quit[];
- Xextern char MSG_forw_del_char[];
- Xextern char MSG_toggle_swap[];
- Xextern char MSG_forw_char[];
- Xextern char MSG_abort[];
- Xextern char MSG_ins_self[];
- Xextern char MSG_back_del_char[];
- Xextern char MSG_refresh[];
- Xextern char MSG_forw_line[];
- Xextern char MSG_back_line[];
- Xextern char MSG_quote[];
- Xextern char MSG_recall[];
- Xextern char MSG_twiddle[];
- Xextern char MSG_forw_page[];
- Xextern char MSG_kill_region[];
- Xextern char MSG_yank[];
- Xextern char MSG_down_window[];
- Xextern char MSG_ins_toggle[];
- Xextern char MSG_display_buffers[];
- Xextern char MSG_quit[];
- Xextern char MSG_exit_flush_all[];
- Xextern char MSG_set_file_name[];
- Xextern char MSG_file_insert[];
- Xextern char MSG_buf_size_lock[];
- Xextern char MSG_flush_all[];
- Xextern char MSG_down_window[];
- Xextern char MSG_up_window[];
- Xextern char MSG_file_read[];
- Xextern char MSG_file_save[];
- Xextern char MSG_file_visit[];
- Xextern char MSG_file_write[];
- Xextern char MSG_swap_dot_and_mark[];
- Xextern char MSG_shrink_window[];
- Xextern char MSG_display_position[];
- Xextern char MSG_start_macro[];
- Xextern char MSG_end_macro[];
- Xextern char MSG_help[];
- Xextern char MSG_only_window[];
- Xextern char MSG_split_window[];
- Xextern char MSG_use_buffer[];
- Xextern char MSG_spawn_cli[];
- Xextern char MSG_execute_macro[];
- Xextern char MSG_goto_line[];
- Xextern char MSG_ins_unit[];
- Xextern char MSG_kill_buffer[];
- Xextern char MSG_load_bindings[];
- Xextern char MSG_forw_window[];
- Xextern char MSG_back_window[];
- Xextern char MSG_view_file[];
- Xextern char MSG_enlarge_window[];
- Xextern char MSG_ascii_mode[];
- Xextern char MSG_binary_mode[];
- Xextern char MSG_buffer_name[];
- Xextern char MSG_decimal_mode[];
- Xextern char MSG_ebcdic_mode[];
- Xextern char MSG_hex_mode[];
- Xextern char MSG_back_del_unit[];
- Xextern char MSG_octal_mode[];
- Xextern char MSG_display_version[];
- Xextern char MSG_unit_size1[];
- Xextern char MSG_unit_size2[];
- Xextern char MSG_unit_size4[];
- Xextern char MSG_reposition_window[];
- Xextern char MSG_set_mark[];
- Xextern char MSG_goto_eob[];
- Xextern char MSG_goto_bob[];
- Xextern char MSG_next_buff[];
- Xextern char MSG_prev_buff[];
- Xextern char MSG_query_replace[];
- Xextern char MSG_display_bindings[];
- Xextern char MSG_auto_save[];
- Xextern char MSG_back_unit[];
- Xextern char MSG_compare[];
- Xextern char MSG_forw_del_unit[];
- Xextern char MSG_forw_unit[];
- Xextern char MSG_link_windows[];
- Xextern char MSG_print[];
- Xextern char MSG_back_search[];
- Xextern char MSG_forw_search[];
- Xextern char MSG_back_page[];
- Xextern char MSG_copy_region[];
- Xextern char MSG_extended_command[];
- Xextern char MSG_up_window[];
- Xextern char MSG_search_again[];
- Xextern char MSG_bind_to_key[];
- Xextern char MSG_file_visit_split[];
- Xextern char MSG_yank_buffer[];
- Xextern char MSG_save_region[];
- Xextern char MSG_use_buffer_split[];
- Xextern char MSG_no_f_tb[];
- X
- X#define SPECIAL 0x1F /* Special keys */
- X
- Xtypedef struct key_name_array
- X{
- X int key_code;
- X char *func_name_str;
- X char *key_name_str;
- X} KEY_NAME_ARRAY;
- X#if MSDOS
- Xextern bool wang_pc;
- Xextern bool ibm_pc;
- X#endif
- X/*
- X * The keyboard's special characters, those things that are prefixed with
- X * a 0x1F, are placed into the keyboard tables as KCTRL || 0x80 || x, for some
- X * x, i.e. they have both the control and 0x80 bits set, so they won't conflict
- X * with anything else on the keyboard.
- X */
- X
- X
- X/*
- X * Names for the keys with basic keycode
- X * between KFIRST and KLAST (inclusive). This is used by
- X * the key name routine in "kbd.c".
- X */
- X#if MSDOS
- XKEY_NAME_ARRAY wang_keys[] =
- X{
- X KCTRL | 0x80, MSG_bind_to_key, "Indent",
- X /* KCTRL | 0x81, NULL, "Page", */
- X KCTRL | 0x82, MSG_reposition_window, "Center",
- X /* KCTRL | 0x83, NULL, "DecTab", */
- X /* KCTRL | 0x84, NULL, "Format", */
- X /* KCTRL | 0x85, NULL, "Merge", */
- X /* KCTRL | 0x86, NULL, "Note", */
- X KCTRL | 0x87, MSG_set_mark, "Stop",
- X KCTRL | 0x88, MSG_forw_search, "Search",
- X KCTRL | 0x89, MSG_yank, "Replace",
- X KCTRL | 0x8A, MSG_copy_region, "Copy",
- X KCTRL | 0x8B, MSG_kill_region, "Move",
- X KCTRL | 0x8C, MSG_extended_command, "Command",
- X KCTRL | 0x8D, MSG_forw_window, "UpDown",
- X /* KCTRL | 0x8E, NULL, "BlankKey", */
- X KCTRL | 0x8F, MSG_goto_line, "GoTo",
- X /* KCTRL | 0x90, NULL, "Sh-Indent", */
- X /* KCTRL | 0x91, NULL, "Sh-Page", */
- X /* KCTRL | 0x92, NULL, "Sh-Center", */
- X /* KCTRL | 0x93, NULL, "Sh-DecTab", */
- X /* KCTRL | 0x94, NULL, "Sh-Format", */
- X /* KCTRL | 0x95, NULL, "Sh-Merge", */
- X /* KCTRL | 0x96, NULL, "Sh-Note", */
- X /* KCTRL | 0x97, NULL, "Sh-Stop", */
- X KCTRL | 0x98, MSG_search_again, "Sh-Search",
- X KCTRL | 0x99, MSG_query_replace, "Sh-Replace",
- X /* KCTRL | 0x9A, NULL, "Sh-Copy", */
- X /* KCTRL | 0x9B, NULL, "Sh-Move", */
- X /* KCTRL | 0x9C, NULL, "Sh-Command", */
- X KCTRL | 0x9D, MSG_split_window, "Sh-UpDown",
- X /* KCTRL | 0x9E, NULL, "Sh-BlankKey", */
- X /* KCTRL | 0x9F, NULL, "Sh-GoTo", */
- X KCTRL | 0xC0, MSG_back_line, "North",
- X KCTRL | 0xC1, MSG_forw_char, "East",
- X KCTRL | 0xC2, MSG_forw_line, "South",
- X KCTRL | 0xC3, MSG_back_char, "West",
- X KCTRL | 0xC4, MSG_byte_shift, "Home",
- X /* KCTRL | 0xC5, NULL, "Execute", */
- X KCTRL | 0xC6, MSG_ins_toggle, "Insert",
- X KCTRL | 0xC7, MSG_forw_del_char, "Delete",
- X KCTRL | 0xC8, MSG_back_page, "PrevPage",
- X KCTRL | 0xC9, MSG_forw_page, "NextPage",
- X /* KCTRL | 0xCB, NULL, "Erase", */
- X /* KCTRL | 0xCD, NULL, "BackTab", */
- X /* KCTRL | 0xD0, NULL, "Sh-North", */
- X KCTRL | 0xD1, MSG_forw_unit, "Sh-East",
- X /* KCTRL | 0xD2, NULL, "Sh-South", */
- X KCTRL | 0xD3, MSG_back_unit, "Sh-West",
- X /* KCTRL | 0xD4, NULL, "Sh-Home", */
- X KCTRL | 0xD5, MSG_execute_macro, "Sh-Execute",
- X /* KCTRL | 0xD6, NULL, "Sh-Insert", */
- X KCTRL | 0xD7, MSG_forw_del_unit, "Sh-Delete",
- X KCTRL | 0xD8, MSG_goto_bob, "Sh-PrevPage",
- X KCTRL | 0xD9, MSG_goto_eob, "Sh-NextPage",
- X /* KCTRL | 0xDB, NULL, "Sh-Erase", */
- X /* KCTRL | 0xDC, NULL, "Sh-Tab", */
- X /* KCTRL | 0xDD, NULL, "Sh-BackTab", */
- X KCTRL | 0xE0, MSG_abort, "Cancel",
- X KMETA | KCTRL | 0xE0, MSG_abort, "Cancel",
- X KCTLX | KCTRL | 0xE0, MSG_abort, "Ctl-X Cancel",
- X KCTRL | 0xE1, MSG_display_bindings, "Help",
- X /* KCTRL | 0xE2, NULL, "Glossary", */
- X KCTRL | 0xE3, MSG_print, "Print",
- X KCTRL | 0xF1, MSG_help, "Sh-Help",
- X /* KCTRL | 0xF2, NULL, "Sh-Glossary", */
- X /* KCTRL | 0xF3, NULL, "Sh-Print", */
- X 0, NULL, NULL
- X};
- X
- XKEY_NAME_ARRAY ibm_keys[] =
- X{
- X KCTLX | 0x80 | 0x3B, MSG_display_bindings, "F1",
- X KCTLX | 0x80 | 0x3C, MSG_set_mark, "F2",
- X KCTLX | 0x80 | 0x3D, MSG_forw_search, "F3",
- X KCTLX | 0x80 | 0x3E, MSG_search_again, "F4",
- X KCTLX | 0x80 | 0x3F, MSG_query_replace, "F5",
- X KCTLX | 0x80 | 0x40, MSG_yank, "F6",
- X KCTLX | 0x80 | 0x41, MSG_copy_region, "F7",
- X KCTLX | 0x80 | 0x42, MSG_kill_region, "F8",
- X KCTLX | 0x80 | 0x43, MSG_goto_line, "F9",
- X KCTLX | 0x80 | 0x44, MSG_abort, "F10",
- X KCTLX | 0x80 | 0x54, MSG_help, "Sh-F1",
- X KCTLX | 0x80 | 0x55, MSG_file_read, "Sh-F2",
- X KCTLX | 0x80 | 0x56, MSG_file_save, "Sh-F3",
- X KCTLX | 0x80 | 0x57, MSG_file_visit, "Sh-F4",
- X KCTLX | 0x80 | 0x58, MSG_file_write, "Sh-F5",
- X KCTLX | 0x80 | 0x59, MSG_flush_all, "Sh-F6",
- X KCTLX | 0x80 | 0x5A, MSG_set_file_name, "Sh-F7",
- X KCTLX | 0x80 | 0x5B, MSG_file_insert, "Sh-F8",
- X KCTLX | 0x80 | 0x5C, MSG_exit_flush_all, "Sh-F9",
- X KCTLX | 0x80 | 0x5D, MSG_quit, "Sh-F10",
- X KCTLX | 0x80 | 0x5E, MSG_display_buffers, "Ctl-F1",
- X KCTLX | 0x80 | 0x5F, MSG_use_buffer, "Ctl-F2",
- X KCTLX | 0x80 | 0x60, MSG_kill_buffer, "Ctl-F3",
- X KCTLX | 0x80 | 0x61, MSG_next_buff, "Ctl-F4",
- X KCTLX | 0x80 | 0x62, MSG_prev_buff, "Ctl-F5",
- X KCTLX | 0x80 | 0x63, MSG_yank_buffer, "Ctl-F6",
- X KCTLX | 0x80 | 0x64, MSG_set_file_name, "Ctl-F7",
- X KCTLX | 0x80 | 0x65, MSG_file_insert, "Ctl-F8",
- X KCTLX | 0x80 | 0x66, MSG_exit_flush_all, "Ctl-F9",
- X KCTLX | 0x80 | 0x67, MSG_quit, "Ctl-F10",
- X KCTLX | 0x80 | 0x48, MSG_back_line, "North",
- X KCTLX | 0x80 | 0x4D, MSG_forw_char, "East",
- X KCTLX | 0x80 | 0x74, MSG_forw_unit, "Ctl-East",
- X KCTLX | 0x80 | 0x50, MSG_forw_line, "South",
- X KCTLX | 0x80 | 0x4B, MSG_back_char, "West",
- X KCTLX | 0x80 | 0x73, MSG_back_unit, "Ctl-West",
- X KCTLX | 0x80 | 0x49, MSG_back_page, "PageDown",
- X KCTLX | 0x80 | 0x47, MSG_goto_bob, "Home",
- X KCTLX | 0x80 | 0x51, MSG_forw_page, "PageUp",
- X KCTLX | 0x80 | 0x4F, MSG_goto_eob, "End",
- X KCTLX | 0x80 | 0x52, MSG_ins_toggle, "Insert",
- X KCTLX | 0x80 | 0x53, MSG_forw_del_char, "Delete",
- X KCTLX | 0x80 | 0x76, MSG_forw_window, "Ctl-PageDown",
- X KCTLX | 0x80 | 0x84, MSG_back_window, "Ctl-PageUp",
- X KCTLX | 0x80 | 0x72, MSG_print, "Ctl-Print",
- X KCTLX | 0x80 | 0x0F, MSG_forw_unit, "Sh-Tab",
- X 0, NULL, NULL
- X};
- X#endif
- X/*
- X * Read in a key, doing the low level mapping
- X * of ASCII code to 11 bit code. This level deals with
- X * mapping the special keys into their spots in the C1
- X * control area. The C0 controls go right through, and
- X * get remapped by "getkey".
- X */
- Xstatic int unkey = KRANDOM; /* jam - for ungetkey */
- Xvoid ungetkey (k)
- X{
- X unkey = k;
- X}
- X
- Xint getkbd ()
- X{
- X register int c;
- X
- X if (unkey == KRANDOM) /* jam */
- X c = ttgetc ();
- X else
- X {
- X c = unkey;
- X unkey = KRANDOM;
- X }
- X if (c == SPECIAL)
- X {
- X c = ttgetc ();
- X if ((c == 0xCD) || (c == 0xDD))/* Backtab is meta */
- X return (METACH);
- X return (c | KCTRL);
- X }
- X if (c == 0)
- X {
- X c = ttgetc ();
- X return (c | 0x80 | KCTLX);
- X }
- X return (c);
- X}
- X
- X
- X/*
- X * Terminal specific keymap initialization.
- X * Attach the special keys to the appropriate built
- X * in functions.
- X * As is the case of all the keymap routines, errors
- X * are very fatal.
- X */
- Xvoid ttykeymapinit ()
- X{
- X#if MSDOS
- X KEY_NAME_ARRAY *ptr;
- X int i;
- X char buf[NCOL];
- X if (wang_pc)
- X ptr = wang_keys;
- X
- X if (ibm_pc)
- X ptr = ibm_keys;
- X
- X if (!wang_pc && !ibm_pc)
- X return;
- X
- X i = 0;
- X while (ptr -> key_code != 0)
- X {
- X if (ptr -> func_name_str != NULL)
- X keydup (ptr -> key_code, ptr -> func_name_str);
- X ptr++;
- X i++;
- X }
- X sprintf (buf, MSG_sp_key, i);
- X writ_echo (buf);
- X#endif
- X}
- X/*
- X* Search key name array for given key code.
- X* return pointer to key name.
- X*/
- Xchar *keystrings (key)
- Xint key;
- X{
- X#if MSDOS
- X KEY_NAME_ARRAY *ptr;
- X
- X if (wang_pc)
- X ptr = wang_keys;
- X
- X if (ibm_pc)
- X ptr = ibm_keys;
- X
- X if (!wang_pc && !ibm_pc)
- X return(NULL);
- X
- X while (ptr -> key_code != 0)
- X {
- X if (key == ptr -> key_code)
- X {
- X return (ptr -> key_name_str);
- X }
- X ptr++;
- X }
- X#endif
- X return (NULL);
- X}
- END_OF_FILE
- if test 11099 -ne `wc -c <'ttykbd.c'`; then
- echo shar: \"'ttykbd.c'\" unpacked with wrong size!
- fi
- # end of 'ttykbd.c'
- fi
- if test -f 'window.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'window.c'\"
- else
- echo shar: Extracting \"'window.c'\" \(10328 characters\)
- sed "s/^X//" >'window.c' <<'END_OF_FILE'
- X/*
- X* Window handling.
- X*/
- X#include "def.h"
- X
- Xbool mvupwind ();
- Xbool shrinkwind ();
- X
- Xextern char MSG_no_splt[];
- Xextern char MSG_cnt_al_w[];
- Xextern char MSG_one_w[];
- Xextern char MSG_imp_chg[];
- X
- X/*
- X* Reposition the window so as to center on the dot.
- X*/
- Xbool reposition ()
- X{
- X long l_val;
- X
- X l_val = DOT_POS(curwp) - (curwp -> w_ntrows * R_BYTES(curwp) / 2L);
- X move_ptr (curwp, l_val, FALSE, TRUE, FALSE);
- X curwp -> w_flag |= WFHARD;
- X return (TRUE);
- X}
- X
- X/*
- X* The command make the next
- X* window (next => down the screen)
- X* the current window. There are no real
- X* errors, although the command does
- X* nothing if there is only 1 window on
- X* the screen.
- X*/
- Xbool nextwind ()
- X{
- X
- X register WINDOW * wp;
- X
- X if ((wp = curwp -> w_wndp) == NULL)
- X wp = wheadp;
- X curwp = wp;
- X curbp = wp -> w_bufp;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* This command makes the previous
- X* window (previous => up the screen) the
- X* current window. There arn't any errors,
- X* although the command does not do a lot
- X* if there is 1 window.
- X*/
- Xbool prevwind ()
- X{
- X
- X register WINDOW * wp1;
- X register WINDOW * wp2;
- X
- X wp1 = wheadp;
- X wp2 = curwp;
- X if (wp1 == wp2)
- X wp2 = NULL;
- X while (wp1 -> w_wndp != wp2)
- X wp1 = wp1 -> w_wndp;
- X curwp = wp1;
- X curbp = wp1 -> w_bufp;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* This command moves the current
- X* window down by "arg" lines. Recompute
- X* the top line in the window. The move up and
- X* move down code is almost completely the same;
- X* most of the work has to do with reframing the
- X* window, and picking a new dot. We share the
- X* code by having "move down" just be an interface
- X* to "move up".
- X*/
- Xbool mvdnwind (f, n, k)
- Xregister int n;
- X{
- X return (mvupwind (f, -n, KRANDOM));
- X}
- X
- X
- X/*
- X* Move the current window up by "arg"
- X* lines. Recompute the new top line of the window.
- X* Look to see if "." is still on the screen. If it is,
- X* you win. If it isn't, then move "." to center it
- X* in the new framing of the window (this command does
- X* not really move "."; it moves the frame).
- X*/
- Xbool mvupwind (f, n, k)
- Xint n;
- X{
- X A32 l_val, l_bytes;
- X
- X l_bytes = (A32)R_BYTES(curwp); /* number of bytes in a row */
- X l_val = n * l_bytes; /* number of bytes to move */
- X move_ptr (curwp, l_val, FALSE, TRUE, TRUE); /* move window */
- X
- X /* check that dot is in window */
- X while (DOT_POS(curwp) < WIND_POS(curwp))
- X {
- X /* dot is before the first window line */
- X move_ptr (curwp, l_bytes, TRUE, TRUE, TRUE);
- X }
- X while (DOT_POS (curwp) >=
- X ((l_bytes * curwp -> w_ntrows) + WIND_POS(curwp)))
- X {
- X /* dot is after the last window line */
- X move_ptr (curwp, -l_bytes, TRUE, TRUE, TRUE);
- X }
- X curwp -> w_flag |= WFHARD;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* This command makes the current
- X* window the only window on the screen.
- X* Try to set the framing
- X* so that "." does not have to move on
- X* the display. Some care has to be taken
- X* to keep the values of dot and mark
- X* in the buffer structures right if the
- X* distruction of a window makes a buffer
- X* become undisplayed.
- X*/
- Xbool onlywind ()
- X{
- X
- X register WINDOW * wp;
- X register LINE * lp;
- X register int i;
- X
- X while (wheadp != curwp)
- X {
- X
- X wp = wheadp;
- X wheadp = wp -> w_wndp;
- X if (--wp -> w_bufp -> b_nwnd == 0)
- X {
- X
- X wp -> w_bufp -> b_dotp = wp -> w_dotp;
- X wp -> w_bufp -> b_doto = wp -> w_doto;
- X wp -> w_bufp -> b_markp = wp -> w_markp;
- X wp -> w_bufp -> b_marko = wp -> w_marko;
- X }
- X
- X free ((char *) wp);
- X }
- X
- X while (curwp -> w_wndp != NULL)
- X {
- X
- X wp = curwp -> w_wndp;
- X curwp -> w_wndp = wp -> w_wndp;
- X if (--wp -> w_bufp -> b_nwnd == 0)
- X {
- X
- X wp -> w_bufp -> b_dotp = wp -> w_dotp;
- X wp -> w_bufp -> b_doto = wp -> w_doto;
- X wp -> w_bufp -> b_markp = wp -> w_markp;
- X wp -> w_bufp -> b_marko = wp -> w_marko;
- X }
- X
- X free ((char *) wp);
- X }
- X
- X lp = curwp -> w_linep;
- X i = curwp -> w_toprow;
- X while (i != 0 && lback (lp) != curbp -> b_linep)
- X {
- X
- X --i;
- X lp = lback (lp);
- X }
- X
- X curwp -> w_toprow = 0;
- X curwp -> w_ntrows = nrow - 2;/* 2 = mode, echo. */
- X curwp -> w_linep = lp;
- X curwp -> w_flag |= WFMODE | WFHARD;
- X return (TRUE);
- X}
- X
- X/*
- X * Delete the current window, placing its space in the window above,
- X * or, if it is the top window, the window below. Bound to C-X 0.
- X */
- X
- Xbool delwind()
- X
- X{
- X register WINDOW *wp; /* window to recieve deleted space */
- X register WINDOW *lwp; /* ptr window before curwp */
- X register int target; /* target line to search for */
- X
- X /* if there is only one window, don't delete it */
- X if (wheadp->w_wndp == NULL) {
- X return(FALSE);
- X }
- X
- X /* find window before curwp in linked list */
- X wp = wheadp;
- X lwp = NULL;
- X while (wp != NULL) {
- X if (wp == curwp)
- X break;
- X lwp = wp;
- X wp = wp->w_wndp;
- X }
- X
- X /* find recieving window and give up our space */
- X wp = wheadp;
- X if (curwp->w_toprow == 0) {
- X /* find the next window down */
- X target = curwp->w_ntrows + 1;
- X while (wp != NULL) {
- X if (wp->w_toprow == target)
- X break;
- X wp = wp->w_wndp;
- X }
- X if (wp == NULL)
- X return(FALSE);
- X wp->w_toprow = 0;
- X wp->w_ntrows += target;
- X } else {
- X /* find the next window up */
- X target = curwp->w_toprow - 1;
- X while (wp != NULL) {
- X if ((wp->w_toprow + wp->w_ntrows) == target)
- X break;
- X wp = wp->w_wndp;
- X }
- X if (wp == NULL)
- X return(FALSE);
- X wp->w_ntrows += 1 + curwp->w_ntrows;
- X }
- X
- X /* get rid of the current window */
- X if (--curwp->w_bufp->b_nwnd == 0) {
- X curwp->w_bufp->b_dotp = curwp->w_dotp;
- X curwp->w_bufp->b_doto = curwp->w_doto;
- X curwp->w_bufp->b_markp = curwp->w_markp;
- X curwp->w_bufp->b_marko = curwp->w_marko;
- X }
- X if (lwp == NULL)
- X wheadp = curwp->w_wndp;
- X else
- X lwp->w_wndp = curwp->w_wndp;
- X free((char *)curwp);
- X curwp = wp;
- X wp -> w_flag |= WFMODE | WFHARD;
- X curbp = wp->w_bufp;
- X return(TRUE);
- X}
- X
- X/*
- X* Split the current window. A window
- X* smaller than 3 lines cannot be split.
- X* The only other error that is possible is
- X* a "malloc" failure allocating the structure
- X* for the new window.
- X*/
- Xbool splitwind ()
- X{
- X
- X register WINDOW * wp;
- X register int ntru;
- X register int ntrl;
- X register int ntrd;
- X register WINDOW * wp1;
- X register WINDOW * wp2;
- X char buf[NCOL], buf1[NCOL];
- X
- X if (curwp -> w_ntrows < 3)
- X {
- X sprintf (buf1, MSG_no_splt, R_BYTE_FMT(curwp));
- X sprintf (buf, buf1, curwp -> w_ntrows);
- X writ_echo (buf);
- X return (FALSE);
- X }
- X
- X if ((wp = (WINDOW *) malloc (sizeof (WINDOW))) == NULL)
- X {
- X err_echo (MSG_cnt_al_w);
- X return (FALSE);
- X }
- X
- X ++curbp -> b_nwnd; /* Displayed twice. */
- X wp -> w_bufp = curbp;
- X wp -> w_dotp = curwp -> w_dotp;
- X wp -> w_doto = curwp -> w_doto;
- X wp -> w_unit_offset = curwp -> w_unit_offset;
- X wp -> w_markp = curwp -> w_markp;
- X wp -> w_marko = curwp -> w_marko;
- X wp -> w_flag = 0;
- X wp -> w_disp_shift = curwp -> w_disp_shift;
- X wp -> w_intel_mode = curwp -> w_intel_mode;
- X wp -> w_fmt_ptr = curwp -> w_fmt_ptr;
- X ntru = (curwp -> w_ntrows - 1) / 2;/* Upper size */
- X ntrl = (curwp -> w_ntrows - 1) - ntru;/* Lower size */
- X
- X curwp -> w_ntrows = ntru;
- X wp -> w_wndp = curwp -> w_wndp;
- X curwp -> w_wndp = wp;
- X wp -> w_toprow = curwp -> w_toprow + ntru + 1;
- X wp -> w_ntrows = ntrl;
- X
- X wind_on_dot (curwp); /* put window on the dot */
- X wp -> w_loff = curwp -> w_loff;/* do the same for the new window */
- X wp -> w_linep = curwp -> w_linep;
- X curwp -> w_flag |= WFMODE | WFHARD;
- X wp -> w_flag |= WFMODE | WFHARD;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Enlarge the current window.
- X* Find the window that loses space. Make
- X* sure it is big enough. If so, hack the window
- X* descriptions, and ask redisplay to do all the
- X* hard work. You don't just set "force reframe"
- X* because dot would move.
- X*/
- Xbool enlargewind (f, n, k)
- X{
- X register WINDOW * adjwp;
- X register LINE * lp;
- X register int i;
- X
- X if (n < 0)
- X return (shrinkwind (f, -n, KRANDOM));
- X if (wheadp -> w_wndp == NULL)
- X {
- X
- X writ_echo (MSG_one_w);
- X return (FALSE);
- X }
- X
- X if ((adjwp = curwp -> w_wndp) == NULL)
- X {
- X adjwp = wheadp;
- X while (adjwp -> w_wndp != curwp)
- X adjwp = adjwp -> w_wndp;
- X }
- X
- X if (adjwp -> w_ntrows <= n)
- X {
- X writ_echo (MSG_imp_chg);
- X return (FALSE);
- X }
- X
- X if (curwp -> w_wndp == adjwp)
- X {
- X /* Shrink below. */
- X lp = adjwp -> w_linep;
- X for (i = 0; i < n && lp != adjwp -> w_bufp -> b_linep; ++i)
- X lp = lforw (lp);
- X adjwp -> w_linep = lp;
- X adjwp -> w_toprow += n;
- X }
- X else
- X {
- X /* Shrink above. */
- X lp = curwp -> w_linep;
- X for (i = 0; i < n && lback (lp) != curbp -> b_linep; ++i)
- X lp = lback (lp);
- X curwp -> w_linep = lp;
- X curwp -> w_toprow -= n;
- X }
- X
- X curwp -> w_ntrows += n;
- X adjwp -> w_ntrows -= n;
- X curwp -> w_flag |= WFMODE | WFHARD;
- X adjwp -> w_flag |= WFMODE | WFHARD;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Shrink the current window.
- X* Find the window that gains space. Hack at
- X* the window descriptions. Ask the redisplay to
- X* do all the hard work.
- X*/
- Xbool shrinkwind (f, n, k)
- X{
- X register WINDOW * adjwp;
- X register LINE * lp;
- X register int i;
- X
- X if (n < 0)
- X return (enlargewind (f, -n, KRANDOM));
- X if (wheadp -> w_wndp == NULL)
- X {
- X writ_echo (MSG_one_w);
- X return (FALSE);
- X }
- X
- X if ((adjwp = curwp -> w_wndp) == NULL)
- X {
- X adjwp = wheadp;
- X while (adjwp -> w_wndp != curwp)
- X adjwp = adjwp -> w_wndp;
- X }
- X
- X if (curwp -> w_ntrows <= n)
- X {
- X writ_echo (MSG_imp_chg);
- X return (FALSE);
- X }
- X
- X if (curwp -> w_wndp == adjwp)
- X {
- X /* Grow below. */
- X lp = adjwp -> w_linep;
- X for (i = 0; i < n && lback (lp) != adjwp -> w_bufp -> b_linep; ++i)
- X lp = lback (lp);
- X adjwp -> w_linep = lp;
- X adjwp -> w_toprow -= n;
- X }
- X else
- X {
- X /* Grow above. */
- X lp = curwp -> w_linep;
- X for (i = 0; i < n && lp != curbp -> b_linep; ++i)
- X lp = lforw (lp);
- X curwp -> w_linep = lp;
- X curwp -> w_toprow += n;
- X }
- X
- X curwp -> w_ntrows -= n;
- X adjwp -> w_ntrows += n;
- X curwp -> w_flag |= WFMODE | WFHARD;
- X adjwp -> w_flag |= WFMODE | WFHARD;
- X return (TRUE);
- X}
- X
- X
- X/*
- X* Pick a window for a pop-up.
- X* Split the screen if there is only
- X* one window. Pick the uppermost window that
- X* isn't the current window. An LRU algorithm
- X* might be better. Return a pointer, or
- X* NULL on error.
- X*/
- XWINDOW * wpopup ()
- X{
- X
- X register WINDOW * wp;
- X
- X if (wheadp -> w_wndp == NULL
- X && splitwind () == FALSE)
- X return (NULL);
- X wp = wheadp; /* Find window to use */
- X while (wp != NULL && wp == curwp)
- X wp = wp -> w_wndp;
- X return (wp);
- X}
- X
- X
- X/*
- X* Refresh the display.
- X* In the normal case the
- X* call to "update" in "main.c" refreshes the screen,
- X* and all of the windows need not be recomputed.
- X*/
- Xbool refresh ()
- X{
- X sgarbf = TRUE;
- X return (TRUE);
- X}
- END_OF_FILE
- if test 10328 -ne `wc -c <'window.c'`; then
- echo shar: \"'window.c'\" unpacked with wrong size!
- fi
- # end of 'window.c'
- fi
- echo shar: End of archive 7 \(of 9\).
- cp /dev/null ark7isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-