REPORTING for DBell - DPY (Part 1 of 3)

Landon Noll chongo at nsc.UUCP
Fri Apr 12 19:50:29 AEST 1985


In net.sources:
  I am reposting DBell's DPY sources in response to all the folks who
  needed them for his LIFE and WAR progs.  DBell is no longer on the
  net (in fact in a few days he will no longer be in this hemisphere)
  otherwise he would have done this himself.

In net.sources.games:
  I am reposting DBell's LIFE sources complete with the changes noted
  below.  Both LIFE and WAR (posted to net.sources.games by DBell not long ago)
  require the use of DPY so be sure and GRAB IT FROM NET.SOURCES NOW!!!

---------------------begin DBell's comments-------------------------------
This is a new version of the DPY module that I posted a while ago.  This
new version runs on both 4.2 BSD and System V.  Because of this, there are
some simple changes visible to the callers of the module, all of which were
made in order to make the interfaces system-independent.  The README file
explains these changes in more detail.  There is also a bug fix for padding
characters on certain terminals.

In particular, if you have obtained the LIFE program that I recently posted
to the net, you must make the following changes to the LIFE sources in order
to load it with this new release.  In main.c, delete the include of 'sgtty.h'
and replace the 'dpyinit' call with 'dpyinit((char *)0, (char *)0)'.  In io.c
and view.c, replace all 'dpyclearwindow' calls with 'dpyclrwindow' and all
'dpyclearline' calls with 'dpyclrline'.  These are 'official' changes and so
don't require any notices by the copyright notices.  Enjoy!  (This fix
has been made to the reposted LIFE sources. Ed.)

			David I. Bell
			nsc!daisy!dbell  <--No longer at this address  Ed.
---------------------------------------------------------------------------
#---Cut here and place in it's own directory, then feed to Bourne shell---
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
# This archive contains:
#   README (1807 chars)
#   dpy.doc (15578 chars)
#   makefile.bsd (1270 chars)
#   makefile.usg (1816 chars)
#   test1.c (553 chars)
#   test2.c (1446 chars)
#   dpy.h (3445 chars)
#
echo x - README
sed -e 's/^X//' > "README" << '//E*O*F README//'
X			DPY (release 2)
X
XThe DPY module was originally written for a 4.2 BSD UNIX system running on a
XVAX 750.  It now also runs under System V.  There are two makefiles supplied
Xwith this release, with the following names:
X
X	makefile.bsd	for 4.2 BSD.
X	makefile.usg	for System V.
X
XYou should copy the appropriate makefile to the file "makefile" in order to
Xbuild the library that is suitable for your system.
X
XThis is the second release of the DPY module.  There have been some changes
Xin some of the dpy routines since the previous release.  If you have any
Xprograms written for the previous release, you will need to modify them
Xas follows in order to use the new DPY:
X
X	Dpyclearline is now called dpyclrline.
X	Dpyclearwindow is now called dpyclrwindow.
X	Dpyinit is called with different arguments.
X
XThe file dpy.doc describes the new calling formats.  These changes were made
Xin order to make DPY less system dependent.  There are also several bug fixes
Xin this new release.
X
XIf you are running under a different machine, you have to change the makefile
Xto use gensubs.c instead of vaxsubs.s (this contains generic subroutines which
Xrun on all machines).  If you are ambitious, you can speed up dpy by writing
Xyour own assembly level routines to duplicate what gensubs.c does.  Not much
Xassembly code is needed.  (If you are real lucky, you are on a 32016, and the
Xnecessary routines are already written in ns32ksubs.s.)  I am willing to
Xcollect and distribute such subroutines for some other machines.
X
XI have included two toy programs (test1.c and test2.c) which demonstrate some
Xof the capabilities of dpy.  Along with dpy.doc, they should show you how to
Xuse the module.  I am still sorry that dpy.doc is not formatted.  Someday...
X
XComments and bug fixes are welcome.
X			David I. Bell
X			nsc!daisy!dbell
//E*O*F README//
echo x - dpy.doc
sed -e 's/^X//' > "dpy.doc" << '//E*O*F dpy.doc//'
X		DPY - New Screen Updating Routines
X			by David I. Bell
X
X
XDpy is a terminal display package much like curses(3).  Dpy does not
Xprovide all of the capabilities of curses, but instead tries to focus on
Xthe following two goals:
X1.	Allow the programmer to easily define and update many different
X	rectangles of data on the screen at the same time.
X2.	Be as fast as possible.
X
XThe routines in the dpy library are called directly by the user program.
XNone of these routines are a macro, so that there is no need to include a
Xheader file to use dpy.  These routines use the termlib (or curses) library
Xroutines to obtain the proper terminal escape sequences.  Therefore, you
Xload your program as in the following examples:
X
X	cc -o yourprog yourprog.c -ldpy -ltermlib	for BSD
Xor:
X	cc -o yourprog yourprog.c -ldpy -lcurses	for System V
X
XDpy keeps two arrays which hold images of the terminal screen.  The first
Xarray (the "current screen") is a copy of what the terminal screen really
Xlooks like.  The second array (the "future screen") is a copy of what the
Xcalling program wants the screen to look like.  The use of dpy proceeds in
Xtwo phases under the control of the calling program, as follows:
X
XIn the first phase, only the future screen is manipulated.  The calling
Xprogram positions the "current write location" as desired within the future
Xscreen, and writes new information within it.  During this phase, no actual
XI/O occurs and the terminal screen remains unchanged.
X
XIn the second phase, the calling program asks dpy to update the screen.
XDpy compares the future screen contents with the current screen contents,
Xand does whatever terminal I/O is required in order to make the current
Xscreen look like the future screen.  After this is done, the two screen
Ximages are identical.
X
XThe calling program usually uses dpy by looping between the above two
Xphases.  First, it defines what the screen should look like, and then
Xthe screen is updated, then it defines the screen again, and so on.  In
Xdoing so, the program can be "dumb" or "smart".  A dumb program rewrites
Xall of the data in its windows each iteration of the loop, and depends on
Xdpy to prevent terminal I/O for unchanging data.  Thus a dumb program
Xcan be very trivial, and doesn't have to know anything about what is
Xhappening on the screen.  A smart program knows the exact locations of the
Xdesired screen changes each iteration of the loop, and only rewrites those
Xlocations.  This runs somewhat faster than a dumb program, but has the
Xdisadvantage of introducing complexity and possible bugs into the program.
XIf generating a new screen of data is too much work for each iteration,
Xa good compromise is to keep an internal copy of the screen in the program,
Xupdate that appropriately, and give that whole screen to dpy each iteration.
X
XPutting data into the future screen is much like writing to a real terminal.
XThere is a "current write location", which is similar to the cursor of the
Xterminal.  Like a terminal, characters written to dpy appear at the current
Xwrite location, and automatically advance its location.  When the rightmost
Xlocation on a line is reached, the current write location is automatically
Xmoved to the leftmost location on the next line.  Finally, some control
Xcharacters have special effects like on a terminal.  In particular, linefeed
Xmoves to the beginning of the next line, return moves back to the beginning
Xof the current line, tab moves to the next tab stop as if the corresponding
Xnumber of spaces were given, and backspace backs up by one location.  Other
Xcontrol characters appear in ^X format.
X
XThere are some differences between writing to the future screen and most real
Xterminals, however.  Firstly, scrolling does not usually occur.  If the end of
Xthe screen is reached, any further characters are ignored.  Secondly, it is
Xpossible to limit output to a "window", which is a rectangle of any size on
Xthe screen.  The location and size of a window is specified by the program
Xwhen it wants to limit output to a rectangle.  This window acts just like
Xa regular terminal screen of the appropriate size.  Furthermore, coordinates
Xare relative to the window's upper left corner, so a routine which writes
Xin the window does not need to know where it is.  Data in the future screen
Xwhich lies outside of the window is untouched, no matter what is done within
Xthe window.  Typically, a program divides the screen up into several windows
Xwhich do not overlap.  Data can then be written to each window independently,
Xwithout regard to where each window is.  For example, a linefeed character
Xmoves to the beginning of the next line in the current window, instead of
Xto the beginning of the next line of the screen.
X
XThe following is a description of the procedures available in the dpy library:
X
X
Xdpyinit(ttytype, modestring)
Xchar *ttytype, *modestring;
X
X	This routine must be called before any other call to dpy (except for
X	dpyclose).  It allocates memory for the two screen images for dpy,
X	defines the current window to be the whole screen, sets the current
X	write location to the upper left corner of the screen, uses signal(2)
X	to cause the terminal stop character to trap to dpystop for pretty
X	program stopping (only under BSD systems), and sets terminal modes
X	for input of various kinds.  The actual terminal screen is not cleared
X	until the first dpyupdate call is made, so that you can initialize
X	your program based upon the terminal size before deciding to continue.
X	Returns nonzero with an error message typed if cannot initialize.
X
X	The 'ttytype' argument is the terminal type string (example: "vt100"),
X	or NULL to use the TERM environment variable value.  'Modestring' is
X	a string specifying how input is to be treated from the terminal.
X	Each mode is specified by a single letter, preceeded by an (optional)
X	plus sign to enable the mode, or preceeded by a minus sign to disable
X	the mode.  Modes can be separated by spaces.  Modes not mentioned in
X	the string are unchanged.  The currently defined modes letters are:
X		e  (echo)   Echoing of input characters occurs.
X		c  (cbreak) Characters are returned without waiting for
X			    a newline and tty signals are processed.
X		r  (raw)    Characters are returned exactly as typed and
X			    tty signals are disabled.
X	Thus the normal terminal modes before starting dpy are described
X	by the mode string "e -c -r".  If the mode string specified is a
X	NULL pointer, then the default mode string of "-e c" is used.
X	If the dpyread call is to be used in your program, then you must
X	specify that echoing is disabled, and either cbreak or raw mode
X	is enabled.
X
X
Xdpyclose()
X	Homes down to the lower left corner and clears the last line of the
X	terminal screen, frees the memory allocated by dpyinit, and resets
X	the original terminal modes.  Useful when exiting your program.
X	If dpyinit has not yet been called, nothing is done, so it is safe
X	to call dpyclose at any time.
X
X
Xdpywrite(buf, count)
Xchar *buf;
Xint count;
X
X	Writes 'count' characters from location 'buf' to the future screen
X	image at the current write location in the current window, and updates
X	the current write location appropriately.  This call does not do any
X	actual I/O to the terminal.  Control characters are handled reasonably,
X	as is running off the end of a line or the window.  This routine is
X	called by dpychar, dpystr, and dpyprintf, and is therefore the most
X	efficient way to give characters to dpy.  Returns nonzero if not all
X	the characters fit in the window.
X
X
Xdpychar(ch)
Xchar ch;
X
X	Writes a single character to the future screen image.  Returns nonzero
X	if the character couldn't fit in the window.
X
X
Xdpystr(str)
Xchar *str;
X
X	Writes a null terminated string to the future screen image.  Returns
X	nonzero if any of string couldn't fit in the window.
X
X
Xdpyprintf(fmt [,args] ...)
Xchar *fmt;
X
X	Writes a formated string to the future screen image, in the
X	manner of printf.  Returns nonzero if any of the string couldn't
X	fit in the window.
X
X
Xdpyclrline()
X
X	Clears the rest of the line in the future screen image (by changing
X	the characters to spaces), but does not change the current write
X	location.  Writing a linefeed to the future screen performs this
X	function, in addition to moving the write location to the next line.
X
X
Xdpyclrwindow()
X
X	Clears the rest of the window in the future screen image, but
X	does not change the current write location.  When rewriting a
X	window completely, this should be called when done so that any
X	old contents of the window will be sure to be cleared out.
X
X
Xdpyhome()
X
X	Moves the current write location to the top left corner of the window.
X	When being a dumb program which rewrites the whole window, this needs
X	to be called between iterations.
X
X
Xdpygetrow()
X
X	Returns the row number of the current write location.  This is
X	the row number where the next character written would go.  If the
X	next character written would not fit in the window, -1 is returned.
X	This number is relative to the first line of the current window.
X	For example, if the current write location is at the beginning of
X	the top line of the window, this function returns zero.
X
X
Xdpygetcol()
X
X	Returns the column number of the current write location.  This is
X	the column number where is next character written would go.  If the
X	next character written would not fit in the window, -1 is returned.
X	This number is relative to the current window.  For example, if
X	the current write location is at the beginning of a line in the
X	window, this function returns zero.
X
X
Xdpyupdate()
X
X	Makes the terminal screen look like the future screen image,
X	using a minimal amount of terminal I/O.  The cursor is positioned
X	at the current write location when this function is done.
X
X
Xdpyredraw()
X
X	Redraws the screen to make it look like the current screen image.
X	Used to fix the screen when it becomes trashed due to glitches or
X	other programs also writing to the screen.  This does not change
X	the current or future screen images.
X
X
Xdpystop()
X
X	Suspends execution of the process in a nice way.  Homes down to
X	the lower left corner, clears the last line, resets terminal modes,
X	and then stops the process.  If the process is continued, terminal
X	modes are restored, the screen is redrawn, and execution proceeds.
X	This is called automatically when the terminal stop character is
X	typed by the user.  This call is a nop for non-BSD systems.
X
X
Xdpymove(row, col)
Xint row, col;
X
X	Changes the current write location to the given row and column
X	numbers, relative to the upper left corner of the current window.
X	Coordinates start at zero.  Negative numbers measure from the last
X	row or column of the window.  For example, dpymove(-1, 0) positions
X	to the beginning of the last line of the window.  This does not set
X	the actual terminal's cursor location, unless this is also followed
X	by a call to dpyupdate.  Returns nonzero if the coordinates are
X	illegal.
X
X
Xdpyplace(row, col, ch)
Xint row, col;
Xchar ch;
X
X	Place the given character at the given coordinates within the
X	current window, without changing the current write location.  The
X	character placed should not be a control character.  The coordinates
X	can be negative to measure from the last row or column of the window.
X	Like dpywrite and similar routines, this routine only affects the
X	future screen image, and does no terminal I/O.  Returns nonzero if
X	the coordinates are illegal.
X
X
Xdpyget(row, col)
Xint row, col;
X
X	Returns the character which is at the given coordinates within the
X	current window, without changing the current write location.  The
X	coordinates can be negative to measure from the last row or column of
X	the window.  The character returned is from the future screen image,
X	not the current screen image.  Returns negative if the coordinates
X	are illegal.
X
X
Xdpyread(prompt, routine, buf, count)
Xchar *prompt;
Xint (*routine)();
Xchar *buf;
Xint count;
X
X	This is used to read data from the user, while showing the input
X	data on the screen.  The current window is used for this purpose.
X	Editing of the input and updating of the screen is automatically
X	performed by dpy.  To use this feature properly do the following:
X
X	1.	Set a window to the region where you want input to occur.
X		Usually this is one line at the top or bottom of the screen.
X	2.	Call dpyread to read the input.
X
X	If the prompt string pointer is not NULL, then the prompt string will
X	appear at the top of the window, followed by the data typed by the user.
X	To display the user's input without any prompt, use a pointer to a
X	null string.  If the prompt pointer is NULL, then no terminal I/O at
X	all will be performed (useful when input is from a script or file).
X	The buf and count specify the area in the calling program where the
X	data being read is stored.  The data will be what was typed by the
X	user, not what is seen on the screen (for example, control characters
X	appear on the screen as ^X, but appear in the buffer as themselves).
X	If more data is typed than fits in the window, the data in the window
X	is automatically scrolled to keep the current input location visible.
X	Routine is a function variable which specifies a routine which will
X	provide the input characters for dpy.  The routine is called with the
X	previous character read (-1 on the first call).  It returns the
X	next character read, or -1 to return from dpyread.  Providing the
X	previous character as an argument allows a routine to easily return
X	a break character as input, and then end the input on the next call.
X	If 0 is supplied as a routine, a default routine will be used which
X	reads from the standard input until an end of file or newline is typed
X	(which is included in the buffer).  If the character count is exceeded,
X	dpyread will warn the user with a bell and discard further input.
X	Dpyread returns the number of characters read into the buffer, which
X	is not guaranteed to contain a terminating null or newline character.
X
X
Xdpywindow(minrow, maxrow, mincol, maxcol)
Xint minrow, maxrow, mincol, maxcol;
X
X	Specifies a rectangle where characters will be placed in the future
X	screen image, and sets the current write location to the top left
X	corner of the rectangle.  The rectangle is specified by the minimum
X	and maximum row numbers, and minimum and maximum column numbers,
X	where the top left corner of the screen is row 0 and column 0.
X	The coordinates are specified in absolute screen coordinates, and
X	negative numbers specify row or column numbers from the bottom or
X	right edges of the screen.  For example, dpywindow(0, -1, 0, -1)
X	defines a window which is the whole screen.  Returns nonzero if the
X	coordinates are illegal.
X
X
XFinal hints:
X
XA window can be filled with a background character by simply writing that
Xcharacter to the window until a nonzero return value is obtained, meaning
Xthe window is full.
X
XIf a region of the screen is never changed (such as a help text), then that
Xregion should be in its own window.  Then it only needs to be written once.
X
XThe terminal size can be found after calling dpyinit by simply calling
Xdpymove(-1, -1) to move to the lower right of the screen, and then calling
Xdpygetrow and dpygetcol to return the row and column numbers.
X
XWhile writing data to the window, dpygetrow and dpygetcol are useful to
Xremember the location of a particular position in the window, so that
Xthe terminal cursor can be positioned back to that location when all the
Xdata is written.  In this way, you don't have worry about line wrapping
Xand tab and other control character expansions when computing how to
Xposition the cursor on a particular character.
//E*O*F dpy.doc//
echo x - makefile.bsd
sed -e 's/^X//' > "makefile.bsd" << '//E*O*F makefile.bsd//'
X# @(#)makefile.bsd	1.6	2/27/85
X# Makefile for BSD systems
X
X.SUFFIXES: .c .o .s
X
XCFLAGS = -O -DBSD
XCC = cc
XAS = as
XRANLIB = ranlib
XLIBDIR = /usr/lib
X
XCFILES = dpy.c dpymove.c dpyplace.c dpyget.c dpyread.c dpywindow.c
XOFILES = dpy.o dpymove.o dpyplace.o dpyget.o dpyread.o dpywindow.o
XSOURCES = ${CFILES} dpy.h vaxsubs.s ns32ksubs.s gensubs.c
X
X# Machine dependent assembly routines.  Define MACHINEFILES appropriately
X# to select the target machine.  Gensubs is a portable version of the
X# subroutines applicable to any machine (but slower than the assembly ones).
X
XGENFILES = gensubs.o		# generic subroutines
XNS32KFILES= ns32ksubs.o		# National Semiconductor 32032 subroutines
XVAXFILES = vaxsubs.o		# VAX subroutines
XMACHINEFILES = ${VAXFILES}	# subroutines to be used
X
X
Xlibdpy.a: ${OFILES} ${MACHINEFILES}
X	ar rc libdpy.a ${OFILES} ${MACHINEFILES}
X	${RANLIB} libdpy.a
X
Xsources: ${SOURCES}
X
X${SOURCES}:
X	sccs get $@
X
X${OFILES}: dpy.h
X
Xinstall: libdpy.a
X	cp libdpy.a ${LIBDIR}
X	${RANLIB} ${LIBDIR}/libdpy.a
X	chmod 644 ${LIBDIR}/libdpy.a
X
Xtest1:	test1.o libdpy.a
X	${CC} -o test1 test1.o libdpy.a -ltermlib
X
Xtest2:	test2.o libdpy.a
X	${CC} -o test2 test2.o libdpy.a -ltermlib
X
Xclean:
X	rm -f *.o libdpy.a test1 test2
X
X.s.o:
X	${AS} -o $*.o $*.s
X
X.c.o:
X	${CC} -c ${CFLAGS} $*.c
//E*O*F makefile.bsd//
echo x - makefile.usg
sed -e 's/^X//' > "makefile.usg" << '//E*O*F makefile.usg//'
X# @(#)makefile.usg	1.5	2/27/85
X# Makefile for USG systems
X
X.SUFFIXES: .c .o .s
X
XCC = cc
XOFLAG = -O
XDFLAG =
XSYSTEM = -DUSG
XCFLAGS = $(OFLAG) $(DFLAG) $(SYSTEM)
XAS = as
XLIBDIR = /usr/lib
XLIB = libdpy.a
X
XCFILES = dpy.c dpymove.c dpyplace.c dpyget.c dpyread.c dpywindow.c
XOFILES = dpy.o dpymove.o dpyplace.o dpyget.o dpyread.o dpywindow.o
X
XLIBOBJS =	$(LIB)(dpy.o) \
X		$(LIB)(dpymove.o) \
X		$(LIB)(dpyplace.o) \
X		$(LIB)(dpyget.o) \
X		$(LIB)(dpyread.o) \
X		$(LIB)(dpywindow.o)
X
XSOURCES = dpy.h ${CFILES} vaxsubs.s ns32ksubs.s gensubs.c
X
X# Machine dependent assembly routines.  Define MACHINEFILES appropriately
X# to select the target machine.  Gensubs is a portable version of the
X# subroutines applicable to any machine (but slower than the assembly ones).
X
XGENFILES = gensubs.o		# generic subroutines
XNS32KFILES = ns32ksubs.o	# National Semiconductor 32032 subroutines
XVAXFILES = vaxsubs.o		# VAX subroutines
XMACHINEFILES = ${VAXFILES}	# subroutines to be used
X
X
Xlibdpy.a: ${LIBOBJS} $(MACHINEFILES)
X	$(MAKE) -$(MAKEFLAGS) -f dpy.mk.usg $? OFLAG=$(OFLAG) \
X		DFLAG=$(DFLAG) SYSTEM=$(SYSTEM)
X	ar rv libdpy.a $?
X	/bin/rm $?
X
X$(LIB)(vaxsubs.o) vaxsubs.o : vaxsubs.s
X
X$(LIB)(gensubs.o) gensubs.o : gensubs.s
X
X$(LIB)(ns32ksubs.o) ns32ksubs.o : ns32ksubs.s
X
Xsources: ${SOURCES}
X
X$(LIBOBJS) ${OFILES}: dpy.h
X
Xinstall: libdpy.a
X	cp libdpy.a ${LIBDIR}
X	chmod 644 ${LIBDIR}/libdpy.a
X
Xtest1:	test1.o libdpy.a
X	$(CC) test1.o $(LDFLAGS) -o test1 libdpy.a -lcurses
X
Xtest2:	test2.o libdpy.a
X	$(CC) test2.o $(LDFLAGS) -o test2 libdpy.a -lcurses
X
Xprint:	${SOURCES} makefile
X	pr -w120 -n ${SOURCES} makefile >dpy.lst
X	@echo dpy.lst finished
X
Xclean:
X	rm -f *.o libdpy.a test1 test2
X
XPRECIOUS:	libdpy.a
X
X.c.a:
X	@echo $*.c
X
X.s.a:
X	@echo $*.s
X
X.s.o:
X	${AS} -o $*.o $*.s
X
X.c.o:
X	${CC} -c ${CFLAGS} $*.c
X
X.s~.s:
X	$(GET) $(GFLAGS) -p $< > $*.s
//E*O*F makefile.usg//
echo x - test1.c
sed -e 's/^X//' > "test1.c" << '//E*O*F test1.c//'
X/*
X * Example program.  Randomly fill up the screen with numbers until
X * it all turns to asterisks.
X */
X
X#ifdef USG
X#define	random	rand
X#endif USG
X
Xmain()
X{
X	register int row, col, ch;
X	register int rows, cols;
X
X	if (dpyinit((char *)0, "e")) exit(1);
X	dpymove(-1, -1);
X	rows = dpygetrow() + 1;
X	cols = dpygetcol() + 1;
X	dpyhome();
X	while (1) {
X		dpyupdate();
X		row = random() % rows;
X		col = random() % cols;
X		ch = dpyget(row, col);
X		if (ch == ' ') ch = '1';
X		else if (ch == '9') ch = '*';
X		else if (ch != '*') ch++;
X		dpyplace(row, col, ch);
X	}
X}
//E*O*F test1.c//
echo x - test2.c
sed -e 's/^X//' > "test2.c" << '//E*O*F test2.c//'
X/*
X * Example program.  Split the screen into three windows, input using the
X * top window until an escape is typed, and show it in the bottom window.
X * The middle window is just a border.  Continue until a ^E is typed.
X */
X
X#include <signal.h>
X
X#define	BOARDER	10		/* row for boarder window */
X#define	BUFSIZE	1000		/* maximum chars which can be input */
X#define	ESC	'\033'		/* escape character */
X#define	QUIT	'\005'		/* quit character (^E) */
X
Xint	grabchar();		/* routine to read tty chars */
Xint	quit();			/* interrupt routine */
X
Xmain()
X{
X	register int	i;		/* character count */
X	char	buf[BUFSIZE];		/* input buffer */
X
X	signal(SIGINT, quit);
X	if (dpyinit((char *)0, "-ec"))
X		exit(1);
X	dpywindow(BOARDER, BOARDER, 0, -1);
X	while (dpywrite("-----", 5) == 0) ;
X	while (1) {
X		dpywindow(0, BOARDER - 1, 0, -1);
X		i = dpyread("Input: ", grabchar, buf, sizeof(buf));
X		if ((i > 0) && (buf[i-1] == QUIT)) break;
X		dpywindow(BOARDER + 1, -1, 0, -1);
X		dpyprintf("Read %d chars:\n", i);
X		dpywrite(buf, i);
X		dpyclrwindow();
X		dpyupdate();
X	}
X	dpyclose();
X}
X
X
X/*
X * Read next char from tty, quitting on an end of file or escape character.
X * The escape character is removed from the buffer, but the end of file
X * character is kept.
X */
Xgrabchar(oldch)
X{
X	unsigned char	newch;
X
X	if ((oldch == QUIT) || (read(0, &newch, 1) != 1) || (newch == ESC))
X		return(-1);
X	return(newch);
X}
X
X
X/*
X * Here on an interrupt.
X */
Xquit()
X{
X	dpyclose();
X	exit(0);
X}
//E*O*F test2.c//
echo x - dpy.h
sed -e 's/^X//' > "dpy.h" << '//E*O*F dpy.h//'
X/*
X * @(#)dpy.h	1.12	2/27/85
X * @(#)Copyright (C) 1985 by D Bell
X * Modified for USG by Alan P.W. Hewett
X */
X
X#ifdef	BSD
X#include <sys/ioctl.h>
X#endif	BSD
X
X#ifdef	USG
X#include <sys/termio.h>
X#define	CTRL(c)	('c'&037)
X#undef	CERASE
X#define	CERASE	CTRL(h)
X#define	CRPRNT	CTRL(r)
X#define	CWERASE	CTRL(w)
X#define	CLNEXT	CTRL(v)
X#define	bcopy(from,to,size)	memcpy(to,from,size)
X#endif	USG
X
X#define	STDIN	0		/* standard descriptors */
X#define	STDOUT	1
X#define	STDERR	2
X
X/*
X * The window structure contains data describing the state of the screen.
X * The following picture shows a typical screen and window, and shows the
X * relationship of each of the character pointers in the structure.
X *
X *	A----------------------|
X *	|                      |
X *	|    C--------|        |
X *	|    |        |        |
X *	|    E     G  |F       |
X *	|    |        |        |
X *	|    D--------|        |
X *	|                      |
X *	|----------------------|
X *	B
X */
Xstruct	window	{
X	char	*begdata;		/* A: beginning of new screen image */
X	char	*enddata;		/* B: end of screen image */
X	char	*begwin;		/* C: beginning of current window */
X	char	*endwin;		/* D: last row of current window */
X	char	*begrow;		/* E: beginning of current row */
X	char	*endrow;		/* F: end of current row */
X	char	*cp;			/* G: current character pointer */
X	char	*begchange;		/* beginning of changed region */
X	char	*endchange;		/* end of changed region */
X	char	*screen;		/* the actual screen image */
X	int	nrows;			/* number of rows on screen */
X	int	ncols;			/* number of columns on screen */
X	int	delta;			/* distance between rows */
X	int	currow;			/* current row column */
X	int	curcol;			/* cursor column column */
X	int	tabsize;		/* current tab size */
X	char	nocrlf;			/* don't do automatic crlfs */
X	char	noctrl;			/* don't show control characters */
X	char	nomove;			/* don't move cursor when done */
X	char	scroll;			/* scroll screen when end reached */
X	char	inited;			/* we are initialized */
X	char	output;			/* we have output to screen */
X	char	full;			/* window is full */
X	char	c_kill;			/* line erase character */
X	char	c_erase;		/* character erase character */
X	char	c_werase;		/* word erase character */
X	char	c_rprnt;		/* retype line character */
X	char	c_eof;			/* end of file character */
X	char	c_lnext;		/* literal input character */
X	char	tc_am;			/* cursor wraps on last column */
X	char	tc_hocc;		/* character count for tc_ho */
X	char	tc_cecc;		/* character count for tc_ce */
X	char	tc_cdcc;		/* character count for tc_cd */
X	char	*tc_ho;			/* home capability */
X	char	*tc_ce;			/* clear to end of line */
X	char	*tc_cd;			/* clear to end of display */
X	char	*tc_cm;			/* move cursor */
X	char	*tptr;			/* pointer into termcap strings */
X#ifdef	BSD
X	struct	sgttyb	old0ttyblk;	/* original tty parameters for stdin */
X	struct	sgttyb	new0ttyblk;	/* new terminal parameters for stdin */
X	struct	sgttyb	old1ttyblk;	/* original tty parameters for stdout */
X	struct	sgttyb	new1ttyblk;	/* new terminal parameters for stdout */
X#endif	BSD
X#ifdef	USG
X	struct	termio	old0ttyblk;	/* original tty parameters for stdin */
X	struct	termio	new0ttyblk;	/* new terminal parameters for stdin */
X	struct	termio	old1ttyblk;	/* original tty parameters for stdout */
X	struct	termio	new1ttyblk;	/* new terminal parameters for stdout */
X#endif	USG
X	char	tdata[1024];		/* buffer for termcap data */
X	char	tbuf[200];		/* strings for termcap */
X};
X
Xextern	struct	window	window;		/* window structure */
//E*O*F dpy.h//
echo done
-- 
no comment is a comment.



More information about the Comp.sources.unix mailing list