BSD 4_1c_2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 9 Mar 1983 09:26:34 +0000 (01:26 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Wed, 9 Mar 1983 09:26:34 +0000 (01:26 -0800)
Work on file usr/src/usr.lib/lib2648/2648.h
Work on file usr/src/usr.lib/lib2648/Makefile
Work on file usr/src/usr.lib/lib2648/bit.h
Work on file usr/src/usr.lib/lib2648/agoto.c
Work on file usr/src/usr.lib/lib2648/aminmax.c
Work on file usr/src/usr.lib/lib2648/aon.c
Work on file usr/src/usr.lib/lib2648/beep.c
Work on file usr/src/usr.lib/lib2648/areaclear.c
Work on file usr/src/usr.lib/lib2648/bitcopy.c
Work on file usr/src/usr.lib/lib2648/cleara.c
Work on file usr/src/usr.lib/lib2648/clearg.c
Work on file usr/src/usr.lib/lib2648/curon.c
Work on file usr/src/usr.lib/lib2648/dispmsg.c
Work on file usr/src/usr.lib/lib2648/draw.c
Work on file usr/man/man0/toc3
Work on file usr/src/usr.lib/lib2648/drawbox.c
Work on file usr/src/usr.lib/lib2648/dumpmat.c
Work on file usr/src/usr.lib/lib2648/error.c
Work on file usr/src/usr.lib/lib2648/emptyrow.c
Work on file usr/src/usr.lib/lib2648/escseq.c
Work on file usr/src/usr.lib/lib2648/gon.c
Work on file usr/src/usr.lib/lib2648/gdefault.c
Work on file usr/src/usr.lib/lib2648/kon.c
Work on file usr/src/usr.lib/lib2648/line.c
Work on file usr/src/usr.lib/lib2648/mat.c
Work on file usr/src/usr.lib/lib2648/message.c
Work on file usr/src/usr.lib/lib2648/minmax.c
Work on file usr/src/usr.lib/lib2648/motion.c
Work on file usr/src/usr.lib/lib2648/move.c
Work on file usr/src/usr.lib/lib2648/newmat.c
Work on file usr/src/usr.lib/lib2648/movecurs.c
Work on file usr/src/usr.lib/lib2648/outchar.c
Work on file usr/src/usr.lib/lib2648/outstr.c
Work on file usr/src/usr.lib/lib2648/printg.c
Work on file usr/src/usr.lib/lib2648/rawchar.c
Work on file usr/src/usr.lib/lib2648/rbon.c
Work on file usr/src/usr.lib/lib2648/rdchar.c
Work on file usr/src/usr.lib/lib2648/set.c
Work on file usr/src/usr.lib/lib2648/readline.c
Work on file usr/src/usr.lib/lib2648/setmat.c
Work on file usr/src/usr.lib/lib2648/sync.c
Work on file usr/src/usr.lib/lib2648/texton.c
Work on file usr/src/usr.lib/lib2648/ttyinit.c
Work on file usr/src/usr.lib/lib2648/update.c
Work on file usr/src/usr.lib/lib2648/video.c
Work on file usr/src/usr.lib/lib2648/zermat.c
Work on file usr/src/usr.lib/lib2648/zoomn.c
Work on file usr/src/usr.lib/lib2648/zoomon.c
Work on file usr/src/usr.lib/lib2648/zoomout.c
Work on file usr/man/man0/ptx.in

Synthesized-from: CSRG/cd1/4.1c.2

50 files changed:
usr/man/man0/ptx.in [new file with mode: 0644]
usr/man/man0/toc3 [new file with mode: 0644]
usr/src/usr.lib/lib2648/2648.h [new file with mode: 0644]
usr/src/usr.lib/lib2648/Makefile [new file with mode: 0644]
usr/src/usr.lib/lib2648/agoto.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/aminmax.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/aon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/areaclear.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/beep.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/bit.h [new file with mode: 0644]
usr/src/usr.lib/lib2648/bitcopy.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/cleara.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/clearg.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/curon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/dispmsg.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/draw.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/drawbox.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/dumpmat.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/emptyrow.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/error.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/escseq.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/gdefault.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/gon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/kon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/line.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/mat.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/message.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/minmax.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/motion.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/move.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/movecurs.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/newmat.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/outchar.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/outstr.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/printg.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/rawchar.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/rbon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/rdchar.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/readline.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/set.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/setmat.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/sync.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/texton.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/ttyinit.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/update.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/video.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/zermat.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/zoomn.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/zoomon.c [new file with mode: 0644]
usr/src/usr.lib/lib2648/zoomout.c [new file with mode: 0644]

diff --git a/usr/man/man0/ptx.in b/usr/man/man0/ptx.in
new file mode 100644 (file)
index 0000000..cc5b7e7
--- /dev/null
@@ -0,0 +1,50 @@
+.if t .pn 26\"PERMUTED INDEX
+.if n .pn 27
+.tr ~
+.ll 6.5i
+.lt 6.7i
+.po .5i
+.ds ET\"
+.de HD
+.po 0
+.lt 7.4i
+.tl '\(rn\(rn''\(rn\(rn'
+.lt
+.po
+'sp 18p
+.if e .tl '\\*(ET'''
+.if o .tl '''\\*(ET'
+'sp 18p
+.ns
+..
+.de FO
+'sp 18p
+.af % i
+.if e .tl '\s9\\*(Dt'- % -'\\*(Ed\s0'
+.if o .tl '\s9\\*(Ed'- % -'\\*(Dt\s0'
+'bp
+..
+.wh 0 HD
+.wh -60p FO
+.if \n(nl .bp
+.br
+.ds ET \s9\f2Permuted \|Index\fP\s0
+.ds Ed Fourth Berkeley Distribution
+.ds Dt March \|1983
+.ce
+\f3PERMUTED \|INDEX\fP
+.sp 1v
+.ps 8
+.vs 9p
+.nf
+.cs 3 36
+.\"    backup from slotput 1, slot, 2
+.de xx
+.ds s1\"
+.if \w\ 2\\$2\ 2 .ds s1 ~~\"
+.ds s2 ~~~\"
+.ds s3\"
+.if \w\ 2\\$4\ 2 .ds s3 ~~\"
+.ds s4 ~~\"
+.ds s5 ~~\"
+.ds y \\*(s4\f3
diff --git a/usr/man/man0/toc3 b/usr/man/man0/toc3
new file mode 100644 (file)
index 0000000..6633ef4
--- /dev/null
@@ -0,0 +1,119 @@
+.xx "intro" "introduction to library functions"
+.xx "abort" "generate a fault"
+.xx "abort" "terminate abruptly with memory image"
+.xx "abs" "integer absolute value"
+.xx "access" "determine accessability of a file"
+.xx "alarm" "execute a subroutine after a specified time"
+.xx "assert" "program verification"
+.xx "atof" "convert ASCII to numbers"
+.xx "bessel" "of two kinds for integer orders"
+.xx "bit" "bit routines"
+.xx "bstring" "byte string operations"
+.xx "byteorder" "convert values between host and network byte order"
+.xx "chdir" "change default directory"
+.xx "crypt" "DES encryption"
+.xx "ctime" "convert date and time to ASCII"
+.xx "ctype" "character classification"
+.xx "curses" "screen functions with ``optimal'' cursor motion"
+.xx "dbm" "data base subroutines"
+.xx "directory" "directory operations"
+.xx "ecvt" "output conversion"
+.xx "end" "last locations in program"
+.xx "etime" "return elapsed execution time"
+.xx "exit" "terminate process with status"
+.xx "exp" "exponential, logarithm, power, square root"
+.xx "fclose" "close or flush a stream"
+.xx "fdate" "return date and time in an ASCII string"
+.xx "ferror" "stream status inquiries"
+.xx "floor" "absolute value, floor, ceiling functions"
+.xx "flush" "flush output to a logical unit"
+.xx "fopen" "open a stream"
+.xx "fork" "create a copy of this process"
+.xx "fread" "buffered binary input/output"
+.xx "frexp" "split into mantissa and exponent"
+.xx "fseek" "reposition a file on a logical unit"
+.xx "fseek" "reposition a stream"
+.xx "gamma" "log gamma function"
+.xx "getarg" "command arguments to Fortran"
+.xx "getc" "get a character from a logical unit"
+.xx "getc" "get character or word from stream"
+.xx "getdisk" "get disk description by its name"
+.xx "getenv" "value for environment name"
+.xx "getenv" "get value of environment variables"
+.xx "getfsent" "get file system descriptor file entry"
+.xx "getgrent" "get group file entry"
+.xx "gethostent" "get network host entry"
+.xx "getlog" "get user's login name"
+.xx "getlogin" "get login name"
+.xx "getnetent" "get network entry"
+.xx "getpass" "read a password"
+.xx "getpid" "get process id"
+.xx "getprotoent" "get protocol entry"
+.xx "getpw" "get name from uid"
+.xx "getpwent" "get password file entry"
+.xx "gets" "get a string from a stream"
+.xx "getservent" "get protocol entry"
+.xx "getuid" "get user or group ID of the caller"
+.xx "getwd" "get current working directory pathname"
+.xx "hypot" "Euclidean distance"
+.xx "idate" "return date or time in numerical form"
+.xx "index" "tell about character objects"
+.xx "inet" "Internet address manipulation routines"
+.xx "initgroups" "initialize group access list"
+.xx "j0" "bessel functions"
+.xx "jobs" "summary of job control facilities"
+.xx "kill" "send a signal to a process"
+.xx "l3tol" "convert between 3-byte integers and long integers"
+.xx "link" "make a link to an existing file"
+.xx "loc" "return the address of an object"
+.xx "malloc" "main memory allocator"
+.xx "mktemp" "make a unique file name"
+.xx "monitor" "prepare execution profile"
+.xx "nlist" "get entries from name list"
+.xx "perror" "system error messages"
+.xx "perror" "get system error messages"
+.xx "plot" "graphics interface"
+.xx "popen" "initiate I/O to/from a process"
+.xx "printf" "formatted output conversion"
+.xx "psignal" "system signal messages"
+.xx "putc" "write a character to a fortran logical unit"
+.xx "putc" "put character or word on a stream"
+.xx "puts" "put a string on a stream"
+.xx "qsort" "quicker sort"
+.xx "qsort" "quick sort"
+.xx "rand" "random number generator"
+.xx "rand" "return random values"
+.xx "random" "better random number generator"
+.xx "range" "return extreme values"
+.xx "rcmd" "routines for returning a stream to a remote command"
+.xx "regex" "regular expression handler"
+.xx "rexec" "return stream to a remote command"
+.xx "scandir" "scan a directory"
+.xx "scanf" "formatted input conversion"
+.xx "setbuf" "assign buffering to a stream"
+.xx "setjmp" "non-local goto"
+.xx "signal" "change the action for a signal"
+.xx "signal" "manage signals"
+.xx "sigset" "manage signals"
+.xx "sin" "trigonometric functions"
+.xx "sinh" "hyperbolic functions"
+.xx "sleep" "suspend execution for interval"
+.xx "sleep" "sleep for awhile"
+.xx "stat" "get file status"
+.xx "stdio" "standard buffered input/output package"
+.xx "string" "string operations"
+.xx "swab" "swap bytes"
+.xx "syslog" "control system log"
+.xx "system" "issue a shell command"
+.xx "system" "execute a unix command"
+.xx "termcap" "terminal independent operation routines"
+.xx "time" "return system time"
+.xx "traper" "trap arithmetic errors"
+.xx "trapov" "trap and repair floating point overflow"
+.xx "ttynam" "find name of a terminal port"
+.xx "ttyname" "find name of a terminal"
+.xx "ungetc" "push character back into input stream"
+.xx "unlink" "remove a directory entry"
+.xx "valloc" "aligned memory allocator"
+.xx "varargs" "variable argument list"
+.xx "wait" "wait for a process to terminate"
diff --git a/usr/src/usr.lib/lib2648/2648.h b/usr/src/usr.lib/lib2648/2648.h
new file mode 100644 (file)
index 0000000..000da1c
--- /dev/null
@@ -0,0 +1,53 @@
+/*     2648.h  4.1     83/03/09        */
+/*
+ * lib2648: routines to deal directly with the HP 2648 Graphics terminal.
+ */
+
+#include <stdio.h>
+
+#define ESC    '\033'  /* Escape */
+
+/* Normal/inverse video */
+#define NORMAL 0       /* not inverse video */
+#define INVERSE        1       /* inverse video */
+
+/* Kinds of lines we can draw */
+#define MX     10      /* exclusive or what's on screen */
+#define MC     11      /* clear what's on screen */
+#define MS     12      /* set what's on screen */
+
+/* Escape sequence modes the terminal might be in */
+#define NONE   20      /* not in an escape sequence */
+#define ESCD   21      /* in an escape * d sequence */
+#define ESCP   22      /* in an escape * p sequence */
+#define ESCM   23      /* in an escape * m sequence */
+#define TEXT   24      /* in graphics text mode */
+
+/*
+ * Constants for 2648 ^E/^F handshaking.
+ */
+#define ENQ    5       /* ^E sent by system to terminal */
+#define ACK    6       /* ^F reply by terminal to system */
+#define TBLKSIZ        32      /* Max # chars between handshakes */
+
+/*
+ * Misc. variables used by lib2648.
+ */
+int    _on2648;        /* true if getenv("TERM") is hp2648 */
+int    _video;         /* are we in inverse video mode? */
+int    _actsmode;      /* line type mode screen actually in */
+int    _supsmode;      /* line type mode screen supposed to be in */
+int    _escmode;       /* flavor of escape sequence currently in */
+int    _cursoron;      /* true if cursor is on */
+
+int    _outcount;      /* # of consecutive chars without read sent */
+char   _pushback[BUFSIZ]; /* queue of chars pushed back onto the input */
+char   *_pb_front, *_pb_back;
+
+int    _penx, _peny;   /* where pen is really at */
+int    _curx, _cury;   /* where cursor is really at */
+int    _supx, _supy;   /* where pen and cursor are supposed to be */
+
+#ifdef TRACE
+FILE   *trace;         /* trace file for debugging */
+#endif
diff --git a/usr/src/usr.lib/lib2648/Makefile b/usr/src/usr.lib/lib2648/Makefile
new file mode 100644 (file)
index 0000000..d32d557
--- /dev/null
@@ -0,0 +1,40 @@
+#
+#      Makefile        4.1     83/03/09
+#
+LIBDIR=        /usr/lib
+DESTDIR=
+CFLAGS=        -DTRACE -O
+VGRIND=        csh /usr/ucb/vgrind
+SRCS=  2648.h bit.h \
+       agoto.c aminmax.c aon.c areaclear.c beep.c bitcopy.c cleara.c \
+       clearg.c curon.c dispmsg.c draw.c drawbox.c dumpmat.c \
+       emptyrow.c error.c escseq.c gdefault.c gon.c kon.c line.c mat.c \
+       message.c minmax.c motion.c move.c movecurs.c newmat.c outchar.c \
+       outstr.c printg.c rawchar.c rbon.c rdchar.c readline.c set.c \
+       setmat.c sync.c texton.c ttyinit.c update.c video.c zermat.c \
+       zoomn.c zoomon.c zoomout.c
+OBJS=  agoto.o aminmax.o aon.o areaclear.o beep.o bitcopy.o cleara.o \
+       clearg.o curon.o dispmsg.o draw.o drawbox.o dumpmat.o \
+       emptyrow.o error.o escseq.o gdefault.o gon.o kon.o line.o mat.o \
+       message.o minmax.o motion.o move.o movecurs.o newmat.o outchar.o \
+       outstr.o printg.o rawchar.o rbon.o rdchar.o readline.o set.o \
+       setmat.o sync.o texton.o ttyinit.o update.o video.o zermat.o \
+       zoomn.o zoomon.o zoomout.o
+
+lib2648.a:     ${OBJS}
+       ar cr lib2648.a `lorder ${OBJS} | tsort`
+
+install:       lib2648.a
+       install lib2648.a ${DESTDIR}${LIBDIR}/lib2648.a
+       ranlib ${DESTDIR}${LIBDIR}/lib2648.a
+
+tags:  /tmp
+       ctags ${SRCS}
+
+clean:
+       rm lib2648.a ${OBJS}
+
+vgrind:
+       tee index </dev/null
+       ${VGRIND} -h lib2648 ${SRCS}
+       ${VGRIND} -x index
diff --git a/usr/src/usr.lib/lib2648/agoto.c b/usr/src/usr.lib/lib2648/agoto.c
new file mode 100644 (file)
index 0000000..c205790
--- /dev/null
@@ -0,0 +1,22 @@
+/*     agoto.c 4.1     83/03/09        */
+/*
+ * position the alphanumeric cursor to (x, y).
+ */
+
+#include "2648.h"
+
+agoto(x, y)
+int x, y;
+{
+       char mes[20];
+       sprintf(mes, "\33*dE\33&a%dr%dC", x, y);
+       outstr(mes);
+}
+
+/*
+ * lower left corner of screen.
+ */
+lowleft()
+{
+       outstr("\33F");
+}
diff --git a/usr/src/usr.lib/lib2648/aminmax.c b/usr/src/usr.lib/lib2648/aminmax.c
new file mode 100644 (file)
index 0000000..7987fca
--- /dev/null
@@ -0,0 +1,35 @@
+/*     aminmax.c       4.1     83/03/09        */
+/*
+ * aminmax: find the 4 edges of the glyph within a window.
+ * This version is approximate, in that it may include some
+ * blank areas.  But it's much faster because it doesn't have
+ * to call mat over and over.
+ */
+
+#include "bit.h"
+
+aminmax(g, nrow, ncol, rmin, cmin, rmax, cmax)
+bitmat g;
+int nrow, ncol;
+int *rmin, *cmin, *rmax, *cmax;
+{
+       register int i, j;
+       register int nc = (ncol+7)>>3;
+       register int r1, r2, c1, c2;
+
+       r1 = nrow; c1 = nc; r2 = c2 = 0;
+       for (i=0; i<nrow; i++)
+               for (j=0; j<nc; j++)
+                       if (g[i*nc+j]) {
+                               r1 = min(r1, i);
+                               r2 = max(r2, i);
+                               c1 = min(c1, j);
+                               c2 = max(c2, j);
+                       }
+       if (r2 < r1) {
+               /* empty glyph! */
+               r1 = c1 = r2 = c2 = 1;
+       }
+       *rmin = r1; *rmax = r2;
+       *cmin = 8*c1; *cmax = 8*c2+7;
+}
diff --git a/usr/src/usr.lib/lib2648/aon.c b/usr/src/usr.lib/lib2648/aon.c
new file mode 100644 (file)
index 0000000..c82501d
--- /dev/null
@@ -0,0 +1,17 @@
+/*     aon.c   4.1     83/03/09        */
+
+#include "2648.h"
+
+aon()
+{
+       sync();
+       escseq(ESCD);
+       outchar('e');
+}
+
+aoff()
+{
+       sync();
+       escseq(ESCD);
+       outchar('f');
+}
diff --git a/usr/src/usr.lib/lib2648/areaclear.c b/usr/src/usr.lib/lib2648/areaclear.c
new file mode 100644 (file)
index 0000000..07603de
--- /dev/null
@@ -0,0 +1,30 @@
+/*     areaclear.c     4.1     83/03/09        */
+
+#include "2648.h"
+
+areaclear(rmin, cmin, rmax, cmax)
+int rmin, cmin, rmax, cmax;
+{
+       int osm;
+       char mes[20];
+       register int i;
+
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "areaclear(%d, %d, %d, %d)\n", rmin, cmin, rmax, cmax);
+#endif
+       osm = _supsmode;
+       setclear();
+       sync();
+#ifdef notdef
+       /* old kludge because I couldn't get area fill to work */
+       for (i=rmax; i>=rmin; i--) {
+               move(cmin, i);
+               draw(cmax, i);
+       }
+#endif
+       sprintf(mes, "%da1b%d %d %d %de", (_video==NORMAL) ? 1 : 2, cmin, rmin, cmax, rmax);
+       escseq(ESCM);
+       outstr(mes);
+       _supsmode = osm;
+}
diff --git a/usr/src/usr.lib/lib2648/beep.c b/usr/src/usr.lib/lib2648/beep.c
new file mode 100644 (file)
index 0000000..64aaef1
--- /dev/null
@@ -0,0 +1,9 @@
+/*     beep.c  4.1     83/03/09        */
+
+#include "2648.h"
+
+beep()
+{
+       escseq(NONE);
+       outchar('\7');
+}
diff --git a/usr/src/usr.lib/lib2648/bit.h b/usr/src/usr.lib/lib2648/bit.h
new file mode 100644 (file)
index 0000000..2b89718
--- /dev/null
@@ -0,0 +1,18 @@
+/*     bit.h   4.1     83/03/09        */
+/*
+ * Bit matrix manipulations for font editor.
+ *
+ * General structure of a bit matrix: each row is packed into as few
+ * bytes as possible, taking the bits from left to right within bytes.
+ * The matrix is a sequence of such rows, i.e. up to 7 bits are wasted
+ * at the end of each row.
+ */
+
+#include <stdio.h>
+typedef char * bitmat;
+#ifdef TRACE
+       FILE *trace;
+#endif
+
+#define max(x,y)       ((x) > (y) ?   (x)  : (y))
+#define min(x,y)       ((x) < (y) ?   (x)  : (y))
diff --git a/usr/src/usr.lib/lib2648/bitcopy.c b/usr/src/usr.lib/lib2648/bitcopy.c
new file mode 100644 (file)
index 0000000..1ed96d0
--- /dev/null
@@ -0,0 +1,19 @@
+/*     bitcopy.c       4.1     83/03/09        */
+/*
+ * Copy from msrc to mdest.
+ * This is done as it is because it would be much slower to do it
+ * a bit at a time.
+ */
+
+#include "bit.h"
+
+bitcopy(mdest, msrc, rows, cols)
+bitmat mdest, msrc;
+int rows, cols;
+{
+       register int size = ((cols + 7) >> 3) * rows;
+       register char *p, *q;
+
+       for (p = &mdest[size], q = &msrc[size]; p>=mdest; )
+               *--p = *--q;
+}
diff --git a/usr/src/usr.lib/lib2648/cleara.c b/usr/src/usr.lib/lib2648/cleara.c
new file mode 100644 (file)
index 0000000..112b96a
--- /dev/null
@@ -0,0 +1,10 @@
+/*     cleara.c        4.1     83/03/09        */
+
+#include "2648.h"
+
+cleara()
+{
+       sync();
+       escseq(NONE);
+       outstr("\33H\33J");
+}
diff --git a/usr/src/usr.lib/lib2648/clearg.c b/usr/src/usr.lib/lib2648/clearg.c
new file mode 100644 (file)
index 0000000..2aa3f8f
--- /dev/null
@@ -0,0 +1,10 @@
+/*     clearg.c        4.1     83/03/09        */
+
+#include "2648.h"
+
+clearg()
+{
+       sync();
+       escseq(ESCD);
+       outchar((_video==INVERSE) ? 'b' : 'a');
+}
diff --git a/usr/src/usr.lib/lib2648/curon.c b/usr/src/usr.lib/lib2648/curon.c
new file mode 100644 (file)
index 0000000..470a15d
--- /dev/null
@@ -0,0 +1,23 @@
+/*     curon.c 4.1     83/03/09        */
+
+#include "2648.h"
+
+curon()
+{
+       if (_cursoron)
+               return;
+       sync();
+       escseq(ESCD);
+       outchar('k');
+       _cursoron = 1;
+}
+
+curoff()
+{
+       if (!_cursoron)
+               return;
+       sync();
+       escseq(ESCD);
+       outchar('l');
+       _cursoron = 0;
+}
diff --git a/usr/src/usr.lib/lib2648/dispmsg.c b/usr/src/usr.lib/lib2648/dispmsg.c
new file mode 100644 (file)
index 0000000..bf8b3b7
--- /dev/null
@@ -0,0 +1,35 @@
+/*     dispmsg.c       4.1     83/03/09        */
+/*
+ * display a message, str, starting at (x, y).
+ */
+
+#include "2648.h"
+
+dispmsg(str, x, y, maxlen)
+char *str;
+int x, y;
+{
+       int oldx, oldy;
+       int oldcuron;
+       int oldquiet;
+       extern int QUIET;
+
+       oldx = _curx; oldy = _cury;
+       oldcuron = _cursoron;
+       zoomout();
+       areaclear(y, x, y+8, x+6*maxlen);
+       setset();
+       curon();
+       movecurs(x, y);
+       texton();
+       oldquiet = QUIET;
+       QUIET = 0;
+       outstr(str);
+       if (oldquiet)
+               outstr("\r\n");
+       QUIET = oldquiet;
+       textoff();
+       movecurs(oldx, oldy);
+       if (oldcuron == 0)
+               curoff();
+}
diff --git a/usr/src/usr.lib/lib2648/draw.c b/usr/src/usr.lib/lib2648/draw.c
new file mode 100644 (file)
index 0000000..89fced9
--- /dev/null
@@ -0,0 +1,21 @@
+/*     draw.c  4.1     83/03/09        */
+/*
+ * draw a line from the current place to (x,y).  Such lines are
+ * supposed to be horizontal, and are affected by the current mode.
+ */
+
+#include "2648.h"
+
+draw(x, y)
+{
+#ifdef TRACE
+       if (trace) {
+               fprintf(trace, "draw(%d,%d)\n", x, y);
+       }
+#endif
+       sync();
+       escseq(ESCP);
+       motion(x, y);
+       _supx = x;
+       _supy = y;
+}
diff --git a/usr/src/usr.lib/lib2648/drawbox.c b/usr/src/usr.lib/lib2648/drawbox.c
new file mode 100644 (file)
index 0000000..2cadb5e
--- /dev/null
@@ -0,0 +1,22 @@
+/*     drawbox.c       4.1     83/03/09        */
+/*
+ * Draw a box around a window.  The lower left corner of the box is at (r, c).
+ * Color is 1 for drawing a box, 0 for erasing.
+ * The box is nrow by ncol.
+ */
+
+#include "2648.h"
+
+drawbox(r, c, color, nrow, ncol)
+int r, c, color, nrow, ncol;
+{
+       if (color)
+               setset();
+       else
+               setclear();
+       move(c, r);
+       draw(c+ncol-1, r);
+       draw(c+ncol-1, r+nrow-1);
+       draw(c, r+nrow-1);
+       draw(c, r);
+}
diff --git a/usr/src/usr.lib/lib2648/dumpmat.c b/usr/src/usr.lib/lib2648/dumpmat.c
new file mode 100644 (file)
index 0000000..3b952c8
--- /dev/null
@@ -0,0 +1,30 @@
+/*     dumpmat.c       4.1     83/03/09        */
+
+#include "bit.h"
+
+#ifdef TRACE
+/*
+ * dumpmat: debugging dumpmat of a window or other bit matrix.
+ * msg is a handy label, m is the matrix, rows, cols is the size of the matrix.
+ */
+dumpmat(msg, m, rows, cols)
+char *msg;
+bitmat m;
+int rows, cols;
+{
+       register int r, c;
+       int r1, r2, c1, c2;
+
+       if (trace == NULL)
+               return;
+       fprintf(trace, "\ndumpmat %s, m=%x, rows=%d, cols=%d\n", msg, m, rows, cols);
+       minmax(m, rows, cols, &r1, &c1, &r2, &c2);
+       fprintf(trace, "r1=%d, r2=%d, c1=%d, c2=%d\n", r1, r2, c1, c2);
+       for (r=r1; r<=r2; r++) {
+               fprintf(trace, "%2d ", r);
+               for (c=c1; c<=c2; c++)
+                       fprintf(trace, "%c", mat(m, rows, cols, r, c, 5) ? 'X' : '.');
+               fprintf(trace, "\n");
+       }
+       fprintf(trace, "\n");
+}
diff --git a/usr/src/usr.lib/lib2648/emptyrow.c b/usr/src/usr.lib/lib2648/emptyrow.c
new file mode 100644 (file)
index 0000000..817bad1
--- /dev/null
@@ -0,0 +1,23 @@
+/*     emptyrow.c      4.1     83/03/09        */
+/*
+ * emptyrow: returns true if row r of m is all zeros.
+ *
+ * Note that we assume the garbage at the end of the
+ * row is all zeros.
+ */
+
+#include "bit.h"
+
+emptyrow(m, rows, cols, r)
+bitmat m;
+int rows, cols, r;
+{
+       char *top, *bot;
+
+       bot = &m[r*((cols+7)>>3)];
+       top = bot + ((cols-1) >> 3);
+       while (bot <= top)
+               if (*bot++)
+                       return(0);
+       return (1);
+}
diff --git a/usr/src/usr.lib/lib2648/error.c b/usr/src/usr.lib/lib2648/error.c
new file mode 100644 (file)
index 0000000..82e2cd3
--- /dev/null
@@ -0,0 +1,11 @@
+/*     error.c 4.1     83/03/09        */
+/*
+ * error: default handling of errors.
+ */
+
+error(msg)
+char *msg;
+{
+       message(msg);
+       /* Maybe it would be nice to longjmp somewhere here */
+}
diff --git a/usr/src/usr.lib/lib2648/escseq.c b/usr/src/usr.lib/lib2648/escseq.c
new file mode 100644 (file)
index 0000000..3177084
--- /dev/null
@@ -0,0 +1,49 @@
+/*     escseq.c        4.1     83/03/09        */
+/*
+ * escseq: get us out of any escape sequence we are in the middle of
+ * and put us into the requested kind of escape sequence.
+ */
+
+#include "2648.h"
+
+escseq(mode)
+int mode;
+{
+       if (mode == _escmode)
+               return;
+       /* Get out of previous mode */
+       switch (_escmode) {
+       case NONE:
+               break;
+       case ESCD:
+               if (mode == TEXT) {
+                       outchar('s');
+                       _escmode = mode;
+                       return;
+               }
+       case ESCP:
+       case ESCM:
+               outchar('Z');   /* no-op */
+               break;
+       case TEXT:
+               outstr("\33*dT");
+               break;
+       }
+       /* Get into new mode */
+       switch (_escmode = mode) {
+       case NONE:
+               break;
+       case ESCD:
+               outstr("\33*d");
+               break;
+       case ESCP:
+               outstr("\33*p");
+               break;
+       case ESCM:
+               outstr("\33*m");
+               break;
+       case TEXT:
+               outstr("\33*dS");
+               break;
+       }
+}
diff --git a/usr/src/usr.lib/lib2648/gdefault.c b/usr/src/usr.lib/lib2648/gdefault.c
new file mode 100644 (file)
index 0000000..e4c75d9
--- /dev/null
@@ -0,0 +1,12 @@
+/*     gdefault.c      4.1     83/03/09        */
+/*
+ * reset terminal to default graphics state
+ */
+
+#include "2648.h"
+
+gdefault()
+{
+       escseq(ESCM);
+       outstr("r");
+}
diff --git a/usr/src/usr.lib/lib2648/gon.c b/usr/src/usr.lib/lib2648/gon.c
new file mode 100644 (file)
index 0000000..13a09eb
--- /dev/null
@@ -0,0 +1,17 @@
+/*     gon.c   4.1     83/03/09        */
+
+#include "2648.h"
+
+gon()
+{
+       sync();
+       escseq(ESCD);
+       outchar('c');
+}
+
+goff()
+{
+       sync();
+       escseq(ESCD);
+       outchar('d');
+}
diff --git a/usr/src/usr.lib/lib2648/kon.c b/usr/src/usr.lib/lib2648/kon.c
new file mode 100644 (file)
index 0000000..32a492c
--- /dev/null
@@ -0,0 +1,18 @@
+/*     kon.c   4.1     83/03/09        */
+/*
+ * Turn on keypad, so it sends codes instead of doing them in local.
+ */
+
+#include "2648.h"
+
+kon()
+{
+       escseq(NONE);
+       outstr("\33&s1A");
+}
+
+koff()
+{
+       escseq(NONE);
+       outstr("\33&s0A");
+}
diff --git a/usr/src/usr.lib/lib2648/line.c b/usr/src/usr.lib/lib2648/line.c
new file mode 100644 (file)
index 0000000..6e7a812
--- /dev/null
@@ -0,0 +1,25 @@
+/*     line.c  4.1     83/03/09        */
+/*
+ * line: draw a line from point 1 to point 2.
+ */
+
+#include "2648.h"
+
+line(x1, y1, x2, y2)
+int x1, y1, x2, y2;
+{
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "line((%d, %d), (%d, %d)),", x1, y1, x2, y2);
+#endif
+       if (x1==_penx && y1==_peny) {
+               /*
+                * Get around a bug in the HP terminal where one point
+                * lines don't get drawn more than once.
+                */
+               move(x1, y1+1);
+               sync();
+       }
+       move(x1, y1);
+       draw(x2, y2);
+}
diff --git a/usr/src/usr.lib/lib2648/mat.c b/usr/src/usr.lib/lib2648/mat.c
new file mode 100644 (file)
index 0000000..f01ef2b
--- /dev/null
@@ -0,0 +1,20 @@
+/*     mat.c   4.1     83/03/09        */
+/*
+ * mat: retrieve the value in m[r, c].
+ * rows and cols are the size of the matrix in all these routines.
+ */
+
+#include "bit.h"
+
+int
+mat(m, rows, cols, r, c)
+register bitmat m;
+register int c;
+int rows, cols, r;
+{
+       register int thisbyte;
+
+       thisbyte = m[r*((cols+7)>>3) + (c>>3)] & 0xff;
+       thisbyte &= 0x80 >> (c&7);
+       return (thisbyte != 0);
+}
diff --git a/usr/src/usr.lib/lib2648/message.c b/usr/src/usr.lib/lib2648/message.c
new file mode 100644 (file)
index 0000000..579f3c7
--- /dev/null
@@ -0,0 +1,12 @@
+/*     message.c       4.1     83/03/09        */
+/*
+ * message: print str on the screen in the message area.
+ */
+
+#include "2648.h"
+
+message(str)
+char *str;
+{
+       dispmsg(str, 4, 4, 100);
+}
diff --git a/usr/src/usr.lib/lib2648/minmax.c b/usr/src/usr.lib/lib2648/minmax.c
new file mode 100644 (file)
index 0000000..bcbfba9
--- /dev/null
@@ -0,0 +1,37 @@
+/*     minmax.c        4.1     83/03/09        */
+/*
+ * minmax: find the 4 edges of the glyph within a window.
+ */
+
+#include "bit.h"
+
+minmax(g, nrow, ncol, rmin, cmin, rmax, cmax)
+bitmat g;
+int nrow, ncol;
+int *rmin, *cmin, *rmax, *cmax;
+{
+       register int i, j;
+       register int r1, r2, c1, c2;
+       int ar1, ar2, ac1, ac2;
+
+       aminmax(g, nrow, ncol, &ar1, &ac1, &ar2, &ac2);
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "aminmax returns %d, %d, %d, %d\n", ar1, ac1, ar2, ac2);
+#endif
+       r1 = nrow; c1 = ncol; r2 = c2 = 0;
+       for (i=ar1; i<=ar2; i++)
+               for (j=ac1; j<=ac2; j++)
+                       if (mat(g, nrow, ncol, i, j, 8)) {
+                               r1 = min(r1, i);
+                               r2 = max(r2, i);
+                               c1 = min(c1, j);
+                               c2 = max(c2, j);
+                       }
+       if (r2 < r1) {
+               /* empty glyph! */
+               r1 = c1 = r2 = c2 = 1;
+       }
+       *rmin = r1; *rmax = r2;
+       *cmin = c1; *cmax = c2;
+}
diff --git a/usr/src/usr.lib/lib2648/motion.c b/usr/src/usr.lib/lib2648/motion.c
new file mode 100644 (file)
index 0000000..1853b5c
--- /dev/null
@@ -0,0 +1,36 @@
+/*     motion.c        4.1     83/03/09        */
+/*
+ * Move the pen to x, y.  We assume we are already in ESCP mode.
+ */
+
+#include "2648.h"
+
+motion(x, y)
+{
+       char lox, loy, hix, hiy;
+       int delx, dely;
+
+       delx = x-_penx; dely = y-_peny;
+       if (-16 <= delx && delx <= 15 && -16 <= dely && dely <= 15) {
+               /*
+                * Optimization: if within 15 in both directions, can use
+                * HP short incremental mode, only 3 bytes.
+                */
+               outchar('j');
+               outchar(32 + (delx & 31));
+               outchar(32 + (dely & 31));
+       } else {
+               /*
+                * Otherwise must use binary absolute mode, 5 bytes.
+                * We never use ascii mode or binary incremental, since
+                * those both take many more bytes.
+                */
+               outchar('i');
+               outchar(32+ ((x>>5) & 31));
+               outchar(32+ (x&31));
+               outchar(32+ ((y>>5) & 31));
+               outchar(32+ (y&31));
+       }
+       _penx = x;
+       _peny = y;
+}
diff --git a/usr/src/usr.lib/lib2648/move.c b/usr/src/usr.lib/lib2648/move.c
new file mode 100644 (file)
index 0000000..11cc665
--- /dev/null
@@ -0,0 +1,17 @@
+/*     move.c  4.1     83/03/09        */
+/*
+ * move to (x, y).  Both the _pen and cursor are supposed to be moved.
+ * We really just remember it for later, in case we move again.
+ */
+
+#include "2648.h"
+
+move(x, y)
+{
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "\tmove(%d, %d), ", x, y);
+#endif
+       _supx = x;
+       _supy = y;
+}
diff --git a/usr/src/usr.lib/lib2648/movecurs.c b/usr/src/usr.lib/lib2648/movecurs.c
new file mode 100644 (file)
index 0000000..dd943c8
--- /dev/null
@@ -0,0 +1,17 @@
+/*     movecurs.c      4.1     83/03/09        */
+
+#include "2648.h"
+
+movecurs(x, y)
+{
+       char mes[20];
+
+       if (x==_curx && y==_cury)
+               return;
+       sprintf(mes, "%d,%do", x, y);
+       escseq(ESCD);
+       outstr(mes);
+       escseq(NONE);
+       _curx = x;
+       _cury = y;
+}
diff --git a/usr/src/usr.lib/lib2648/newmat.c b/usr/src/usr.lib/lib2648/newmat.c
new file mode 100644 (file)
index 0000000..bd2b1a4
--- /dev/null
@@ -0,0 +1,31 @@
+/*     newmat.c        4.1     83/03/09        */
+/*
+ * newmat: return a brand new bitmat with the proper size.
+ * To get rid of it just call free.
+ */
+
+#include "bit.h"
+
+bitmat
+newmat(rows, cols)
+int rows, cols;
+{
+       int size = ((cols + 7) >> 3) * rows;
+       char *m;
+
+#ifdef TRACE
+       if (size <= 0 && trace) {
+               fprintf(trace, "newmat: rows=%d, cols=%d\n", rows, cols);
+               abort();
+       }
+       if (trace)
+               fprintf(trace, "newmat: malloc(%d) =", size);
+#endif
+       m = (char *) malloc(size);
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "%x\n", m);
+#endif
+       zermat(m, rows, cols);
+       return (m);
+}
diff --git a/usr/src/usr.lib/lib2648/outchar.c b/usr/src/usr.lib/lib2648/outchar.c
new file mode 100644 (file)
index 0000000..f7df7c6
--- /dev/null
@@ -0,0 +1,45 @@
+/*     outchar.c       4.1     83/03/09        */
+
+#include "2648.h"
+
+outchar(c)
+char c;
+{
+       extern int QUIET;
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "%s", rdchar(c));
+#endif
+       if (QUIET)
+               return;
+       _outcount++;
+       putchar(c);
+
+       /* Do 2648 ^E/^F handshake */
+       if (_outcount > TBLKSIZ && _on2648) {
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "ENQ .. ");
+#endif
+               putchar(ENQ);
+               fflush(stdout);
+               c = getchar();
+               while (c != ACK) {
+                       if (_pb_front == NULL) {
+                               _pb_front = _pushback;
+                               _pb_back = _pb_front - 1;
+                       }
+                       *++_pb_back = c;
+#ifdef TRACE
+                       if (trace)
+                               fprintf(trace, "push back %s, front=%d, back=%d, ", rdchar(c), _pb_front-_pushback, _pb_front-_pushback);
+#endif
+                       c = getchar();
+               }
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "ACK\n");
+#endif
+               _outcount = 0;
+       }
+}
diff --git a/usr/src/usr.lib/lib2648/outstr.c b/usr/src/usr.lib/lib2648/outstr.c
new file mode 100644 (file)
index 0000000..fa478f8
--- /dev/null
@@ -0,0 +1,13 @@
+/*     outstr.c        4.1     83/03/09        */
+/*
+ * Low level output routines
+ */
+
+#include "2648.h"
+
+outstr(str)
+char *str;
+{
+       while (*str)
+               outchar(*str++);
+}
diff --git a/usr/src/usr.lib/lib2648/printg.c b/usr/src/usr.lib/lib2648/printg.c
new file mode 100644 (file)
index 0000000..7ac4636
--- /dev/null
@@ -0,0 +1,33 @@
+/*     printg.c        4.1     83/03/09        */
+
+#include "2648.h"
+
+printg()
+{
+       int oldvid = _video;
+       int c, c2;
+
+       if (oldvid==INVERSE)
+               togvid();
+       sync();
+       escseq(NONE);
+       outstr("\33&p4d5u0C");
+       outchar('\21'); /* test handshaking fix */
+
+       /*
+        * The terminal sometimes sends back S<cr> or F<cr>.
+        * Ignore them.
+        */
+       fflush(stdout);
+       c = getchar();
+       if (c=='F' || c=='S') {
+               c2 = getchar();
+               if (c2 != '\r' && c2 != '\n')
+                       ungetc(c2, stdin);
+       } else {
+               ungetc(c, stdin);
+       }
+
+       if (oldvid==INVERSE)
+               togvid();
+}
diff --git a/usr/src/usr.lib/lib2648/rawchar.c b/usr/src/usr.lib/lib2648/rawchar.c
new file mode 100644 (file)
index 0000000..73f40e8
--- /dev/null
@@ -0,0 +1,37 @@
+/*     rawchar.c       4.1     83/03/09        */
+/*
+ * get a character from the terminal, with no line buffering.
+ */
+
+#include "2648.h"
+
+rawchar()
+{
+       char c;
+
+       sync();
+       escseq(NONE);
+       fflush(stdout);
+       if (_pb_front && _on2648) {
+               c = *_pb_front++;
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "%s from queue, front=%d, back=%d\n", rdchar(c), _pb_front-_pushback, _pb_back-_pushback);
+#endif
+               if (_pb_front > _pb_back) {
+                       _pb_front = _pb_back = NULL;
+#ifdef TRACE
+                       if (trace)
+                               fprintf(trace, "reset pushback to null\n");
+#endif
+               }
+               return (c);
+       }
+       _outcount = 0;
+       c = getchar();
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "rawchar '%s'\n", rdchar(c));
+#endif
+       return (c);
+}
diff --git a/usr/src/usr.lib/lib2648/rbon.c b/usr/src/usr.lib/lib2648/rbon.c
new file mode 100644 (file)
index 0000000..ef7f735
--- /dev/null
@@ -0,0 +1,18 @@
+/*     rbon.c  4.1     83/03/09        */
+
+#include "2648.h"
+
+rbon()
+{
+       setset();
+       sync();
+       escseq(ESCD);
+       outchar('m');
+}
+
+rboff()
+{
+       sync();
+       escseq(ESCD);
+       outchar('n');
+}
diff --git a/usr/src/usr.lib/lib2648/rdchar.c b/usr/src/usr.lib/lib2648/rdchar.c
new file mode 100644 (file)
index 0000000..c98f746
--- /dev/null
@@ -0,0 +1,26 @@
+/*     rdchar.c        4.1     83/03/09        */
+/*
+ * rdchar: returns a readable representation of an ASCII char, using ^ notation.
+ */
+
+#include <ctype.h>
+
+char *rdchar(c)
+char c;
+{
+       static char ret[4];
+       register char *p;
+
+       /*
+        * Due to a bug in isprint, this prints spaces as ^`, but this is OK
+        * because we want something to show up on the screen.
+        */
+       ret[0] = ((c&0377) > 0177) ? '\'' : ' ';
+       c &= 0177;
+       ret[1] = isprint(c) ? ' ' : '^';
+       ret[2] = isprint(c) ?  c  : c^0100;
+       ret[3] = 0;
+       for (p=ret; *p==' '; p++)
+               ;
+       return (p);
+}
diff --git a/usr/src/usr.lib/lib2648/readline.c b/usr/src/usr.lib/lib2648/readline.c
new file mode 100644 (file)
index 0000000..f973455
--- /dev/null
@@ -0,0 +1,63 @@
+/*     readline.c      4.1     83/03/09        */
+/*
+ * Read a line from the keyboard in the message line.  The line
+ * goes into caller provided buffer msg, whos size is maxlen bytes.
+ */
+
+#include "2648.h"
+
+readline(prompt, msg, maxlen)
+char *prompt;
+char *msg;
+int maxlen;
+{
+       register char c;
+       register char *cp;
+       int oldx, oldy;
+       int oldcuron;
+       int oldquiet;
+       extern int QUIET;
+
+       oldx = _curx; oldy = _cury;
+       oldcuron = _cursoron;
+       areaclear(4, 4, 4+8, 719);
+       setset();
+       zoomout();
+       curon();
+       movecurs(4, 4);
+       texton();
+
+       oldquiet = QUIET;
+       QUIET = 0;
+       outstr(prompt);
+       if (oldquiet)
+               outstr("\r\n");
+       QUIET = oldquiet;
+
+       for (cp=msg; ; cp) {
+               fflush(stdout);
+               c = getchar();
+               switch (c) {
+               case '\n':
+               case '\r':
+               case ESC:
+                       *cp++ = 0;
+                       textoff();
+                       movecurs(oldx, oldy);
+                       if (oldcuron == 0)
+                               curoff();
+                       return;
+               case '\b':
+                       if (--cp >= msg)
+                               outchar(c);
+                       else
+                               cp = msg;
+                       break;
+               default:
+                       *cp++ = c;
+                       outstr(rdchar(c));
+                       if (cp-msg >= maxlen)
+                               error("line too long");
+               }
+       }
+}
diff --git a/usr/src/usr.lib/lib2648/set.c b/usr/src/usr.lib/lib2648/set.c
new file mode 100644 (file)
index 0000000..416f1bd
--- /dev/null
@@ -0,0 +1,21 @@
+/*     set.c   4.1     83/03/09        */
+/*
+ * Routines to set line type.
+ */
+
+#include "2648.h"
+
+setxor()
+{
+       _supsmode = MX;
+}
+
+setclear()
+{
+       _supsmode = _video==INVERSE ? MS : MC;
+}
+
+setset()
+{
+       _supsmode = _video==INVERSE ? MC : MS;
+}
diff --git a/usr/src/usr.lib/lib2648/setmat.c b/usr/src/usr.lib/lib2648/setmat.c
new file mode 100644 (file)
index 0000000..2c4a1a0
--- /dev/null
@@ -0,0 +1,28 @@
+/*     setmat.c        4.1     83/03/09        */
+/*
+ * setmat: set the value in m[r, c] to nval.
+ */
+
+#include "bit.h"
+
+setmat(m, rows, cols, r, c, nval)
+bitmat m;
+int rows, cols, r, c, nval;
+{
+       register int offset, thisbit;
+
+       if (r<0 || c<0 || r>=rows || c>=cols) {
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "setmat range error: (%d, %d) <- %d in a (%d, %d) matrix %x\n", r, c, nval, rows, cols, m);
+#endif
+
+               return;
+       }
+       offset = r*((cols+7)>>3) + (c>>3);
+       thisbit = 0x80 >> (c&7);
+       if (nval)
+               m[offset] |= thisbit;
+       else
+               m[offset] &= ~thisbit;
+}
diff --git a/usr/src/usr.lib/lib2648/sync.c b/usr/src/usr.lib/lib2648/sync.c
new file mode 100644 (file)
index 0000000..55a6c74
--- /dev/null
@@ -0,0 +1,34 @@
+/*     sync.c  4.1     83/03/09        */
+/*
+ * Make the screen & screen mode look like what it's supposed to.
+ *
+ * There are two basic things to do here, put the _pen
+ * in the right place, and make the line drawing mode be right.
+ * We don't sync the cursor here, only when there's user input & it's on.
+ */
+
+#include "2648.h"
+
+sync()
+{
+       if (_supx != _penx || _supy != _peny) {
+               escseq(ESCP);
+               outchar('a');
+               motion(_supx, _supy);
+       }
+       if (_supsmode != _actsmode) {
+               escseq(ESCM);
+               switch (_actsmode = _supsmode) {
+               case MX:
+                       outchar('3');
+                       break;
+               case MC:
+                       outchar('1');
+                       break;
+               case MS:
+                       outchar('2');
+                       break;
+               }
+               outchar('a');
+       }
+}
diff --git a/usr/src/usr.lib/lib2648/texton.c b/usr/src/usr.lib/lib2648/texton.c
new file mode 100644 (file)
index 0000000..e8cade3
--- /dev/null
@@ -0,0 +1,24 @@
+/*     texton.c        4.1     83/03/09        */
+
+#include "2648.h"
+
+texton()
+{
+       sync();
+       escseq(TEXT);
+}
+
+textoff()
+{
+       sync();
+
+       /*
+        * The following is needed because going into text mode
+        * leaves the pen where the cursor last was.
+        */
+       _penx = -40; _peny = 40;
+       escseq(ESCP);
+       outchar('a');
+       motion(_supx, _supy);
+       _penx = _supx; _peny = _supy;
+}
diff --git a/usr/src/usr.lib/lib2648/ttyinit.c b/usr/src/usr.lib/lib2648/ttyinit.c
new file mode 100644 (file)
index 0000000..2fe10e6
--- /dev/null
@@ -0,0 +1,57 @@
+/*     ttyinit.c       4.1     83/03/09        */
+/*
+ * sgtty stuff
+ */
+
+#include <sgtty.h>
+
+struct sgttyb  _ttyb;
+struct tchars  _otch, _ntch;
+int    _normf;
+
+/*
+ * Routines for dealing with the unix tty modes
+ */
+
+#include "2648.h"
+
+ttyinit()
+{
+       if (strcmp(getenv("TERM"), "hp2648") == 0)
+               _on2648 = 1;
+       ioctl(fileno(stdin), TIOCGETP, &_ttyb);
+       ioctl(fileno(stdin), TIOCGETC, &_otch);
+       _ntch = _otch;
+       _ntch.t_quitc = _ntch.t_startc = _ntch.t_stopc = -1;
+       _normf = _ttyb.sg_flags;
+       _ttyb.sg_flags |= CBREAK;
+       _ttyb.sg_flags &= ~(ECHO|CRMOD);
+       ioctl(fileno(stdin), TIOCSETN, &_ttyb);
+       ioctl(fileno(stdin), TIOCSETC, &_ntch);
+       gdefault();
+       zoomn(1);
+       zoomon();
+       kon();
+       rboff();
+       _cursoron = 1;  /* to force it off */
+       _escmode = NONE;
+       curoff();
+       clearg();
+       gon();
+       aoff();
+}
+
+done()
+{
+       goff();
+       koff();
+       aon();
+       sync();
+       escseq(NONE);
+       lowleft();
+       printf("\n");
+       fflush(stdout);
+       _ttyb.sg_flags = _normf;
+       ioctl(fileno(stdin), TIOCSETN, &_ttyb);
+       ioctl(fileno(stdin), TIOCSETC, &_otch);
+}
diff --git a/usr/src/usr.lib/lib2648/update.c b/usr/src/usr.lib/lib2648/update.c
new file mode 100644 (file)
index 0000000..9e5bc28
--- /dev/null
@@ -0,0 +1,72 @@
+/*     update.c        4.1     83/03/09        */
+/*
+ * update: the key output optimization routine of the whole editor.
+ * The input consists of two bit matrices (mold is what's on the screen,
+ * mnew is what we want to be on the screen) and the coordinates of
+ * the lower left corner on the screen where this matrix is.
+ * This routine does whatever is necessary to get the screen to look
+ * like mnew, assuming that it currently looks like mold.
+ *
+ * (If I could patent this process for bread and other food I
+ * would be a rich man.)
+ */
+
+#include "bit.h"
+
+update(mold, mnew, rows, cols, baser, basec)
+bitmat mold, mnew;
+int rows, cols, baser, basec;
+{
+       int irow;
+       register int i, j, k;
+       int r1, r2, c1, c2, nr1, nr2, nc1, nc2;
+       extern int QUIET;
+
+#ifdef TRACE
+       if (trace)
+               fprintf(trace, "update(mold=%x, mnew=%x, rows=%d, cols=%d, baser=%d, basec=%d)\n", mold, mnew, rows, cols, baser, basec);
+#endif
+
+       if (QUIET)
+               return;
+       aminmax(mold, rows, cols, &r1, &c1, &r2, &c2);
+       aminmax(mnew, rows, cols, &nr1, &nc1, &nr2, &nc2);
+       r1 = min(r1, nr1); r2 = max(r2, nr2);
+       c1 = min(c1, nc1); c2 = max(c2, nc2);
+
+       dumpmat("mold:", mold, rows, cols);
+       dumpmat("mnew:", mnew, rows, cols);
+
+       for (i=r1; i<=r2; i++) {
+               irow = baser + rows - i - 1;
+               if (emptyrow(mnew, rows, cols, i)) {
+                       if (emptyrow(mold, rows, cols, i)) {
+                               continue;       /* identically blank. skip. */
+                       }
+                       /*
+                        * Row i is to be cleared.  Look for some more
+                        * rows to clear and do it all at once.
+                        */
+                       for (j=i+1; j<rows && emptyrow(mnew,rows,cols,j); j++)
+                               ;
+                       areaclear(baser+rows-j, basec, irow, basec+cols-1);
+                       i = j-1;        /* skip the others */
+               } else for (j=c1; j<=c2; j++) {
+                       /*
+                        * Result row is not all blank.  We look for stretches
+                        * of bits that have to be changed (in either
+                        * direction) and draw an exclusive or line over all
+                        * the bits in each stretch.
+                        */
+                       if (mat(mold,rows,cols,i,j,1)!=mat(mnew,rows,cols,i,j,2)){
+                               for (k=j+1; k<cols && mat(mold,rows,cols,i,k,3)!=
+                                       mat(mnew,rows,cols,i,k,4); k++)
+                                       ;
+                               k--;
+                               setxor();
+                               line(basec+j, irow, basec+k, irow);
+                               j = k;  /* skip the others */
+                       }
+               }
+       }
+}
diff --git a/usr/src/usr.lib/lib2648/video.c b/usr/src/usr.lib/lib2648/video.c
new file mode 100644 (file)
index 0000000..c70d078
--- /dev/null
@@ -0,0 +1,20 @@
+/*     video.c 4.1     83/03/09        */
+
+#include "2648.h"
+
+vidnorm()
+{
+       _video = NORMAL;
+}
+
+vidinv()
+{
+       _video = INVERSE;
+}
+
+togvid()
+{
+       _video = (_video==NORMAL) ? INVERSE : NORMAL;
+       escseq(ESCM);
+       outstr("3a1b0 0 719 359e");
+}
diff --git a/usr/src/usr.lib/lib2648/zermat.c b/usr/src/usr.lib/lib2648/zermat.c
new file mode 100644 (file)
index 0000000..469342c
--- /dev/null
@@ -0,0 +1,17 @@
+/*     zermat.c        4.1     83/03/09        */
+/*
+ * zermat: set a matrix to all zeros
+ */
+
+#include "bit.h"
+
+zermat(m, rows, cols)
+bitmat m;
+int rows, cols;
+{
+       register int size = ((cols + 7) >> 3) * rows;
+       register char *p;
+
+       for (p = &m[size]; p>=m; )
+               *--p = 0;
+}
diff --git a/usr/src/usr.lib/lib2648/zoomn.c b/usr/src/usr.lib/lib2648/zoomn.c
new file mode 100644 (file)
index 0000000..c62c516
--- /dev/null
@@ -0,0 +1,12 @@
+/*     zoomn.c 4.1     83/03/09        */
+
+#include "2648.h"
+
+zoomn(size)
+char size;
+{
+       sync();
+       escseq(ESCD);
+       outchar(size+'0');
+       outchar('i');
+}
diff --git a/usr/src/usr.lib/lib2648/zoomon.c b/usr/src/usr.lib/lib2648/zoomon.c
new file mode 100644 (file)
index 0000000..465cf9d
--- /dev/null
@@ -0,0 +1,15 @@
+/*     zoomon.c        4.1     83/03/09        */
+
+#include "2648.h"
+
+zoomon()
+{
+       escseq(ESCD);
+       outchar('g');
+}
+
+zoomoff()
+{
+       escseq(ESCD);
+       outchar('h');
+}
diff --git a/usr/src/usr.lib/lib2648/zoomout.c b/usr/src/usr.lib/lib2648/zoomout.c
new file mode 100644 (file)
index 0000000..27a8ac7
--- /dev/null
@@ -0,0 +1,9 @@
+/*     zoomout.c       4.1     83/03/09        */
+/*
+ * zoomout: zoom to level 1.
+ */
+
+zoomout()
+{
+       zoomn(1);
+}