[comp.sources.misc] v02i100: GNU Termcap ported to MS-DOS.

root@nccnat.UUCP (Paul Shields) (04/21/88)

comp.sources.misc: Volume 2, Issue 100
Submitted-By: "Paul Shields" <root@nccnat.UUCP>
Archive-Name: ms-termcap

Here is GNU Termcap, from GNU Emacs, ported to MS-DOS.  I find
this quite useful with an ansi screen driver, and have managed to get 
Micro Emacs to work over the RS232 port this way.

Sorry about the fact that there's no documentation. Please refer to the
termcap library documentation for Unix.  One last note: please examine
config.h for possible changes. 

Paul Shields,		    York University, Toronto Canada
shields@yunccn.UUCP	    
or yunccn!nccnat!root.	    

---------------- cut here ----------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  CONFIG.H FILES.LS MAKEFILE.LC MAKEFILE.SCO MK.BAT
#   TERMCAP.C TEXTERN.C TPARAM.C
# Wrapped by root@nccnat.UUCP on Wed Apr 20 22:52:08 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f CONFIG.H -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"CONFIG.H\"
else
echo shar: Extracting \"CONFIG.H\" \(3394 characters\)
sed "s/^X//" >CONFIG.H <<'END_OF_CONFIG.H'
X/* GNU Emacs site configuration template file.
X   Copyright (C) 1986 Free Software Foundation, Inc.
X
XThis file is part of GNU Emacs.
X
XGNU Emacs is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY.  No author or distributor
Xaccepts responsibility to anyone for the consequences of using it
Xor for whether it serves any particular purpose or works at all,
Xunless he says so in writing.  Refer to the GNU Emacs General Public
XLicense for full details.
X
XEveryone is granted permission to copy, modify and redistribute
XGNU Emacs, but only under the conditions described in the
XGNU Emacs General Public License.   A copy of this license is
Xsupposed to have been given to you along with GNU Emacs so you
Xcan know your rights and responsibilities.  It should be in a
Xfile named COPYING.  Among other things, the copyright notice
Xand this notice must be preserved on all copies.  */
X
X
X
X/* Include here a s- file that describes the system type you are using.
X   See the file ../etc/MACHINES for a list of systems and
X   the names of the s- files to use for them.
X   See s-template.h for documentation on writing s- files.  */
X/* #include "s-vms4-4.h" */
X 
X/* Include here a m- file that describes the machine and system you use.
X   See the file ../etc/MACHINES for a list of machines and
X   the names of the m- files to use for them.
X   See m-template.h for info on what m- files should define.
X   */
X/* #include "m-vax.h" */
X
X/* Load in the conversion definitions if this system
X   needs them and the source file being compiled has not
X   said to inhibit this.  */
X
X#ifdef SHORTNAMES
X#ifndef NO_SHORTNAMES
X#include "../shortnames/remap.h"
X#endif /* not NO_SHORTNAMES */
X#endif /* SHORTNAMES */
X
X/* define HAVE_X_WINDOWS if you want to use the X window system */
X
X/* #define HAVE_X_WINDOWS */
X
X/* define HAVE_X_MENU if you want to use the X window menu system.
X   This appears to work on some machines that support X
X   and not on others.  */
X
X/* #define HAVE_X_MENU */
X
X/* subprocesses should be defined if you want to
X have code for asynchronous subprocesses
X (as used in M-x compile and M-x shell).
X These do not work for some USG systems yet;
X for the ones where they work, the s-*.h file defines this flag.  */
X
X/* 
X#ifndef VMS
X#ifndef USG
X#define subprocesses
X#endif
X#endif
X */
X
X/* Define USER_FULL_NAME to return a string
X that is the user's full name.
X It can assume that the variable `pw'
X points to the password file entry for this user.
X
X At some sites, the pw_gecos field contains
X the user's full name.  If neither this nor any other
X field contains the right thing, use pw_name,
X giving the user's login name, since that is better than nothing.  */
X
X#define USER_FULL_NAME pw->pw_gecos
X
X/* Define AMPERSAND_FULL_NAME if you use the convention
X  that & in the full name stands for the login id.  */
X
X/* #define AMPERSAND_FULL_NAME */
X
X/* Maximum screen width we handle. */
X
X#define MScreenWidth 300
X
X/* Maximum screen length we handle. */
X
X#define MScreenLength 300
X
X/* # bytes of pure Lisp code to leave space for.
X  s-vms.h and m-sun2.h can override this default.  */
X
X#ifndef PURESIZE
X#ifdef HAVE_X_WINDOWS
X#define PURESIZE 120000
X#else
X#define PURESIZE 115800
X#endif
X#endif
X
X/* Define HIGHPRI as a negative number
X if you want Emacs to run at a higher than normal priority.
X For this to take effect, you must install it as setuid root. */
X
X/* #define HIGHPRI */
X
END_OF_CONFIG.H
if test 3394 -ne `wc -c <CONFIG.H`; then
    echo shar: \"CONFIG.H\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f FILES.LS -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"FILES.LS\"
else
echo shar: Extracting \"FILES.LS\" \(520 characters\)
sed "s/^X//" >FILES.LS <<'END_OF_FILES.LS'
Xtotal 88
X-rw-rw-r--   1 bin      staff       3394 Mar 19 11:08 config.h
X-rw-r--r--   1 shields  staff          0 Apr 20 23:31 files.ls
X-rw-rw-r--   1 bin      staff        996 Apr 20 23:30 makefile.lc
X-rw-rw-r--   1 bin      staff        399 Apr 20 23:29 makefile.sco
X-rw-rw-r--   1 bin      staff        159 Mar 19 11:07 mk.bat
X-rw-rw-r--   1 bin      staff      18812 Mar 21 22:50 termcap.c
X-rw-rw-r--   1 bin      staff       5113 Mar 19 11:09 textern.c
X-rw-rw-r--   1 bin      staff      11046 Mar 21 22:39 tparam.c
END_OF_FILES.LS
if test 520 -ne `wc -c <FILES.LS`; then
    echo shar: \"FILES.LS\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f MAKEFILE.LC -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"MAKEFILE.LC\"
else
echo shar: Extracting \"MAKEFILE.LC\" \(996 characters\)
sed "s/^X//" >MAKEFILE.LC <<'END_OF_MAKEFILE.LC'
X# Lattice C Makefile for termcap library.
X# 
X# Note: This version of termcap is from GNU emacs. See the .c source
X#       files for a note on the license. 
X
XDEBUG  = -d
XTEST   =
XMODEL  = s
XCC     = lc
XCFLAGS = -m$(MODEL) -n -cws -o.\ -i.. -R$(MODEL)termcap $(DEBUG) $(TEST)
X
Xall: $(MODEL)termcap.lib
X
Xstermcap.lib: termcap.obj tparam.obj textern.obj
X	oml $(MODEL)termcap l >$(MODEL)termcap.lst
X	copy $(MODEL)termcap.lib /usr/lib
X
Xptermcap.lib: termcap.obj tparam.obj textern.obj
X	oml $(MODEL)termcap l >$(MODEL)termcap.lst
X	copy $(MODEL)termcap.lib /usr/lib
X
Xdtermcap.lib: termcap.obj tparam.obj textern.obj
X	oml $(MODEL)termcap l >$(MODEL)termcap.lst
X	copy $(MODEL)termcap.lib /usr/lib
X
Xltermcap.lib: termcap.obj tparam.obj textern.obj
X	oml $(MODEL)termcap l >$(MODEL)termcap.lst
X	copy $(MODEL)termcap.lib /usr/lib
X
Xtermcap.obj:    ../termcap.c
X	$(CC) $(CFLAGS) ../termcap.c
X
Xtparam.obj:     ../tparam.c
X	$(CC) $(CFLAGS) ../tparam.c
X
Xtextern.obj:     ../textern.c
X	$(CC) $(CFLAGS) ../textern.c
X
END_OF_MAKEFILE.LC
if test 996 -ne `wc -c <MAKEFILE.LC`; then
    echo shar: \"MAKEFILE.LC\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f MAKEFILE.SCO -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"MAKEFILE.SCO\"
else
echo shar: Extracting \"MAKEFILE.SCO\" \(399 characters\)
sed "s/^X//" >MAKEFILE.SCO <<'END_OF_MAKEFILE.SCO'
X# SCO Xenix Makefile for termcap library.
X# 
X# Note: This version of termcap is from GNU emacs. See the .c source
X#       files for a note on the license. 
X
XDEBUG  = -d
XTEST   =
XCFLAGS = -DSYSV
X
Xall: termcap.obj tparam.obj textern.obj
X
Xtermcap.obj:    termcap.c  
X	cc $(CFLAGS) termcap.c -c
X
Xtparam.obj:     tparam.c 
X	cc $(CFLAGS) tparam.c -c
X
Xtextern.obj:    textern.c 
X	cc $(CFLAGS) textern.c -c
END_OF_MAKEFILE.SCO
if test 399 -ne `wc -c <MAKEFILE.SCO`; then
    echo shar: \"MAKEFILE.SCO\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f MK.BAT -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"MK.BAT\"
else
echo shar: Extracting \"MK.BAT\" \(159 characters\)
sed "s/^X//" >MK.BAT <<'END_OF_MK.BAT'
Xif .%1 == . goto usage
X:top
Xcd %1
Xmake -f ../Makefile.lc "MODEL=%1" >make.err
Xcd ..
Xshift
Xif .%1 == . goto end
Xgoto top
X:usage
Xecho    usage:  mk s p d l
X:end
END_OF_MK.BAT
if test 159 -ne `wc -c <MK.BAT`; then
    echo shar: \"MK.BAT\" unpacked with wrong size!
fi
chmod +x MK.BAT
# end of overwriting check
fi
if test -f TERMCAP.C -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"TERMCAP.C\"
else
echo shar: Extracting \"TERMCAP.C\" \(18812 characters\)
sed "s/^X//" >TERMCAP.C <<'END_OF_TERMCAP.C'
X/* Work-alike for termcap, plus extra features.
X   Copyright (C) 1985, 1986 Free Software Foundation, Inc.
X
X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
X   Dec 1987 - Mar 1988.
X
X		       NO WARRANTY
X
X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X   1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1986 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X   2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X	  a) cause the modified files to carry prominent notices stating
X	  that you changed the files and the date of any change; and
X
X	  b) cause the whole of any work that you distribute or publish,
X	  that in whole or in part contains or is a derivative of this
X	  program or any part thereof, to be licensed at no charge to all
X	  third parties on terms identical to those contained in this
X	  License Agreement (except that you may choose to grant more
X	  extensive warranty protection to third parties, at your option).
X
X	  c) You may charge a distribution fee for the physical act of
X	  transferring a copy, and you may at your option offer warranty
X	  protection in exchange for a fee.
X
X	3. You may copy and distribute this program or any portion of it in
Xcompiled, executable or object code form under the terms of Paragraphs
X1 and 2 above provided that you do the following:
X
X	  a) cause each such copy to be accompanied by the
X	  corresponding machine-readable source code, which must
X	  be distributed under the terms of Paragraphs 1 and 2 above; or,
X
X	  b) cause each such copy to be accompanied by a
X	  written offer, with no time limit, to give any third party
X	  free (except for a nominal shipping charge) a machine readable
X	  copy of the corresponding source code, to be distributed
X	  under the terms of Paragraphs 1 and 2 above; or,
X
X	  c) in the case of a recipient of this program in compiled, executable
X	  or object code form (without the corresponding source code) you
X	  shall cause copies you distribute to be accompanied by a copy
X	  of the written offer of source code which you received along
X	  with the copy you received.
X
X	4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X	5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X
X
X/* BUFSIZE is the initial size allocated for the buffer
X   for reading the termcap file.
X   It is not a limit.
X   Make it large normally for speed.
X   Make it variable when debugging, so can exercise
X   increasing the space dynamically.  */
X
X#ifdef emacs
X#include "config.h"
X#else
X#include <fcntl.h>
X#endif
X
X/* MODS for MS-DOS by Paul Shields, December 1987. */
X#ifdef MSDOS
X#include <stdlib.h>
X#endif
X
X#if defined(MSDOS) || defined(SYSV)
X#define  bcopy(b,a,n) memcpy(a,b,n)
X#endif
X
X#ifndef BUFSIZE
X# ifdef DEBUG
X#  include <stdio.h>
X#  define  BUFSIZE bufsize
X   int bufsize = 2048;
X   extern int  debuglevel;
X# else
X#  define BUFSIZE 2048
X# endif
X#endif
X
X#ifndef emacs
Xstatic void
Xmemory_out ()
X{
X	write (2, "memory exhausted\n", 25);
X	exit (1);
X}
X
Xstatic char *
Xxmalloc (size)
X       int size;
X{
X	register char *tem = malloc (size);
X	if (!tem)
X	    memory_out ();
X	return tem;
X}
X
Xstatic char *
Xxrealloc (ptr, size)
X	   int ptr;
X	   int size;
X{
X	register char *tem = realloc (ptr, size);
X	if (!tem)
X	    memory_out ();
X	return tem;
X}
X#endif /* not emacs */
X
X/* Looking up capabilities in the entry already found */
X
X/* The pointer to the data made by tgetent is left here
X	 for tgetnum, tgetflag and tgetstr to find.  */
X
Xstatic char *term_entry;
X
Xstatic char *tgetst1 ();
X
X/* This is the main subroutine that is used to search
X	 an entry for a particular capability */
X
Xstatic char *
Xfind_capability (bp, cap)
X	   register char *bp, *cap;
X{
X	for (; *bp; bp++)
X	    if (bp[0] == ':' && bp[1] == cap[0] && bp[2] == cap[1])
X            return &bp[4];
X	return 0;
X}
X
Xint
Xtgetnum (cap)
X	   char *cap;
X{
X	register char *ptr = find_capability (term_entry, cap);
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"cap: %s, num: %d\n", cap, atoi(ptr));
X#endif
X	if (!ptr || ptr[-1] != '#')
X	    return -1;
X	return atoi (ptr);
X}
X
Xint
Xtgetflag (cap)
X	   char *cap;
X{
X	register char *ptr = find_capability (term_entry, cap);
X	return 0 != ptr && ptr[-1] == ':';
X}
X
X/* Look up a string-valued capability `cap'.
X	 If `area' is nonzero, it points to a pointer to a block in which
X	 to store the string.  That pointer is advanced over the space used.
X	 If `area' is zero, space is allocated with `malloc'.  */
X
Xchar *
Xtgetstr (cap, area)
X	   char *cap;
X	   char **area;
X{
X	register char *ptr = find_capability (term_entry, cap);
X	if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~'))
X	    return 0;
X	return tgetst1 (ptr, area);
X}
X
X/* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted,
X   gives meaning of character following \, or a space if no special meaning.
X   Eight characters per line within the string.  */
X
Xstatic char esctab[] = "\
X\040\007\010\040\040\033\014\040\
X\040\040\040\040\040\040\012\040\
X\040\040\015\040\011\040\013\040\
X\040\040\040\040\040\040\040\040";
X
X/* Given a pointer to a string value inside a termcap entry (`ptr'),
X   copy the value and process \ and ^ abbreviations.
X   Copy into block that *area points to,
X   or to newly allocated storage if area is 0.  */
X
Xstatic char *
Xtgetst1 (ptr, area)
X	   char *ptr;
X	   char **area;
X{
X	register char *p, *r;
X	register int c;
X	register int size;
X	char *ret;
X	register int c1;
X
X	if (!ptr)
X	  return 0;
X
X	/* `ret' gets address of where to store the string */
X	if (!area)
X	  {
X	    /* Compute size of block needed (may overestimate) */
X	    p = ptr;
X	    while ((c = *p++) && c != ':');
X	    ret = xmalloc (p - ptr + 1);
X	  }
X	else
X	  ret = *area;
X
X	/* Copy the string value, stopping at null or colon.  */
X	/* Also process ^ and \ abbreviations.  */
X	p = ptr;
X	r = ret;
X	while ((c = *p++) && c != ':')
X	  {
X	    if (c == '^')
X	c = *p++ & 037;
X	    else if (c == '\\')
X	{
X	  c = *p++;
X	  if (c >= '0' && c <= '7')
X	    {
X	      c -= '0';
X	      size = 0;
X
X	      while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7')
X		{
X		  c *= 8;
X		  c += c1 - '0';
X		  p++;
X		}
X	    }
X	  else if (c >= 0100 && c < 0200)
X	    {
X	      c1 = esctab[(c & ~040) - 0100];
X	      if (c1 != ' ')
X		c = c1;
X	    }
X	}
X	    *r++ = c;
X	  }
X	*r = 0;
X	/* Update *area */
X	if (area)
X	  *area = r + 1;
X	return ret;
X}
X
X/* Outputting a string with padding */
Xextern short ospeed;
Xextern char PC;
X
X/* Actual baud rate if positive;
X	 - baud rate / 100 if negative.  */
X
Xstatic short speeds[] =
X	{
X#ifdef VMS
X	  0, 50, 75, 110, 134, 150, -3, -6, -12, -18,
X	  -20, -24, -36, -48, -72, -96, -192
X#else /* not VMS */
X	  0, 50, 75, 110, 135, 150, -2, -3, -6, -12,
X	  -18, -24, -48, -96, -192, -384
X#endif /* not VMS */
X	};
X
Xvoid
Xtputs (string, nlines, outfun)
X	   register char *string;
X	   int nlines;
X	   register int (*outfun) ();
X{
X	register int padcount = 0;
X
X	if (string == (char *) 0)
X	  return;
X	while (*string >= '0' && *string <= '9')
X	  {
X	    padcount += *string++ - '0';
X	    padcount *= 10;
X	  }
X	if (*string == '.')
X	  {
X	    string++;
X	    padcount += *string++ - '0';
X	  }
X	if (*string == '*')
X	  {
X	    string++;
X	    padcount *= nlines;
X	  }
X	while (*string)
X	  (*outfun) (*string++);
X
X	/* padcount is now in units of tenths of msec.  */
X	padcount *= speeds[ospeed];
X	padcount += 500;
X	padcount /= 1000;
X	if (speeds[ospeed] < 0)
X	  padcount = -padcount;
X	else
X	  {
X	    padcount += 50;
X	    padcount /= 100;
X	  }
X
X	while (padcount-- > 0)
X	  (*outfun) (PC);
X}
X
X/* Finding the termcap entry in the termcap data base */
X
Xstruct buffer
X	{
X	  char *beg;
X	  int size;
X	  char *ptr;
X	  int ateof;
X	  int full;
X	};
X
X/* Forward declarations of static functions */
X
Xstatic int scan_file ();
Xstatic char *gobble_line ();
Xstatic int compare_contin ();
Xstatic int name_match ();
X
X#ifdef VMS
X
X#include <rmsdef.h>
X#include <fab.h>
X#include <nam.h>
X
Xstatic int
Xlegal_filename_p (fn)
X	   char *fn;
X{
X	struct FAB fab = cc$rms_fab;
X	struct NAM nam = cc$rms_nam;
X	char esa[NAM$C_MAXRSS];
X
X	fab.fab$l_fna = fn;
X	fab.fab$b_fns = strlen(fn);
X	fab.fab$l_nam = &nam;
X	fab.fab$l_fop = FAB$M_NAM;
X
X	nam.nam$l_esa = esa;
X	nam.nam$b_ess = sizeof esa;
X
X	return SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL;
X}
X
X#endif /* VMS */
X
X/* Find the termcap entry data for terminal type `name'
X	 and store it in the block that `bp' points to.
X	 Record its address for future use.
X
X	 If `bp' is zero, space is dynamically allocated.  */
X
Xint
Xtgetent (bp, name)
X	   char *bp, *name;
X{
X	register char *tem;
X	register int fd;
X	struct buffer buf;
X	register char *bp1;
X	char *bp2;
X	char *term;
X	int malloc_size = 0;
X	register int c;
X	char *tcenv;			/* TERMCAP value, if it contains :tc=.  */
X	char *indirect = 0;		/* Terminal type in :tc= in TERMCAP value.  */
X	int filep;
X
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"tgetent(buf, %s)\n", name);
X#endif
X
X	tem = (char *) getenv ("TERMCAP");
X	if (tem && *tem == 0) tem = 0;
X
X#ifdef VMS
X	filep = (tem && legal_filename_p (tem));
X#else
X	filep = (tem && (*tem == '/'));
X#endif /* VMS */
X
X	/* If tem is non-null and starts with / (in the un*x case, that is),
X	   it is a file name to use instead of /etc/termcap.
X	   If it is non-null and does not start with /,
X	   it is the entry itself, but only if
X	   the name the caller requested matches the TERM variable.  */
X
X	if (tem && !filep && !strcmp (name, getenv ("TERM")))
X	 {
X	    indirect = tgetst1 (find_capability (tem, "tc"), 0);
X	    if (!indirect)
X  	     {
X	       if (!bp)
X	         bp = tem;
X	       else
X	         strcpy (bp, tem);
X	       goto ret;
X	     }
X	    else
X	     {			/* we will need to read /etc/termcap */
X	       tcenv = tem;
X           tem = 0;
X	     }
X	 }
X	else
X	    indirect = (char *) 0;
X
X	if (!tem)
X#ifdef VMS
X	  tem = "emacs_library:[etc]termcap.dat";
X#else
X	  tem = "/etc/termcap";
X#endif
X
X	/* Here we know we must search a file and tem has its name.  */
X
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"%s: ", tem);
X#endif
X	fd = open (tem, 0, 0);
X	if (fd < 0)
X	  return -1;
X
X	buf.size = BUFSIZE;
X	buf.beg = xmalloc (buf.size);
X	term = indirect ? indirect : name;
X
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"...opened\n");
X#endif
X	if (!bp)
X	  {
X	    malloc_size = indirect ? strlen (tcenv) + 1 : buf.size;
X	    bp = xmalloc (malloc_size);
X	  }
X	bp1 = bp;
X
X	if (indirect)			/* copy the data from the environment variable */
X	  {
X	    strcpy (bp, tcenv);
X	    bp1 += strlen (tcenv);
X	  }
X
X	while (term)
X	  {
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"term = %s\n", term);
X#endif
X	    /* Scan file, reading it via buf, till find start of main entry */
X	    if (scan_file (term, fd, &buf) == 0)
X	        return 0;
X
X	    /* Free old `term' if appropriate.  */
X	    if (term != name)
X	        free (term);
X
X	    /* If `bp' is malloc'd by us, make sure it is big enough.  */
X	    if (malloc_size)
X	     {
X	        malloc_size = bp1 - bp + buf.size;
X	        tem = xrealloc (bp, malloc_size);
X        	bp1 += tem - bp;
X        	bp = tem;
X	     }
X
X	    bp2 = bp1;
X
X	    /* Copy the line of the entry from buf into bp.  */
X	    tem = buf.ptr;
X	    while ((*bp1++ = c = *tem++) && c != '\n') {
X	        /* Drop out any \ newline sequence, and following whitespace */
X	        if (c == '\\' && *tem == '\n')
X	         {
X	            bp1--;
X	            tem++;
X	            while ((c = *tem++) == ' ' || c == '\t')
X                    ;
X	            tem--;
X	         }
X        }
X	    *bp1 = 0;
X
X	    /* Does this entry refer to another terminal type's entry?  */
X	    /* If something is found, copy it into heap and null-terminate it */
X	    term = tgetst1 (find_capability (bp2, "tc"), 0);
X	  }
X
X	close (fd);
X	free (buf.beg);
X
X	if (malloc_size)
X	  {
X	    bp = xrealloc (bp, bp1 - bp + 1);
X	  }
X
X ret:
X	term_entry = bp;
X
X#ifdef DEBUG
X    if(debuglevel & 4)
X        fprintf(stderr,"term_entry = %s\n", term_entry);
X#endif
X	if (malloc_size)
X	  return (int) bp;
X	return 1;
X}
X
X/* Given file open on `fd' and buffer `bufp',
X   scan the file from the beginning until a line is found
X   that starts the entry for terminal type `string'.
X   Returns 1 if successful, with that line in `bufp',
X   or returns 0 if no entry found in the file.  */
X
Xstatic int
Xscan_file (string, fd, bufp)
X	   char *string;
X	   int fd;
X	   register struct buffer *bufp;
X{
X	register char *end;
X
X	bufp->ptr = bufp->beg;
X	bufp->full = 0;
X	bufp->ateof = 0;
X	*bufp->ptr = 0;
X
X	lseek (fd, 0L, 0);
X
X	while (!bufp->ateof)
X	  {
X	    /* Read a line into the buffer */
X	    end = 0;
X	    do
X	{
X	  /* if it is continued, append another line to it,
X	     until a non-continued line ends */
X	  end = gobble_line (fd, bufp, end);
X	}
X	    while (!bufp->ateof && end[-2] == '\\');
X
X	    if (*bufp->ptr != '#'
X	  && name_match (bufp->ptr, string))
X	return 1;
X
X	    /* Discard the line just processed */
X	    bufp->ptr = end;
X	  }
X	return 0;
X}
X
X/* Return nonzero if NAME is one of the names specified
X	 by termcap entry LINE.  */
X
Xstatic int
Xname_match (line, name)
X	   char *line, *name;
X{
X	register char *tem;
X
X	if (!compare_contin (line, name))
X	  return 1;
X	/* This line starts an entry.  Is it the right one?  */
X	for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++)
X	  if (*tem == '|' && !compare_contin (tem + 1, name))
X	    return 1;
X
X	return 0;
X}
X
Xstatic int
Xcompare_contin (str1, str2)
X	   register char *str1, *str2;
X{
X	register int c1, c2;
X	while (1)
X	  {
X	    c1 = *str1++;
X	    c2 = *str2++;
X	    while (c1 == '\\' && *str1 == '\n')
X	{
X	  str1++;
X	  while ((c1 = *str1++) == ' ' || c1 == '\t');
X	}
X	    if (c2 == '\0')		/* end of type being looked up */
X	{
X	  if (c1 == '|' || c1 == ':') /* If end of name in data base, */
X	    return 0;		/* we win. */
X	  else
X	    return 1;
X	      }
X	    else if (c1 != c2)
X	return 1;
X	  }
X}
X
X/* Make sure that the buffer <- `bufp' contains a full line
X	 of the file open on `fd', starting at the place `bufp->ptr'
X	 points to.  Can read more of the file, discard stuff before
X	 `bufp->ptr', or make the buffer bigger.
X
X	 Returns the pointer to after the newline ending the line,
X	 or to the end of the file, if there is no newline to end it.
X
X	 Can also merge on continuation lines.  If `append_end' is
X	 nonzero, it points past the newline of a line that is
X	 continued; we add another line onto it and regard the whole
X	 thing as one line.  The caller decides when a line is continued.  */
X
Xstatic char *
Xgobble_line (fd, bufp, append_end)
X	   int fd;
X	   register struct buffer *bufp;
X	   char *append_end;
X{
X	register char *end;
X	register int nread;
X	register char *buf = bufp->beg;
X	register char *tem;
X
X	if (append_end == 0)
X	  append_end = bufp->ptr;
X
X	while (1)
X	  {
X	    end = append_end;
X	    while (*end && *end != '\n') end++;
X	    if (*end)
X	      break;
X	    if (bufp->ateof)
X	return buf + bufp->full;
X	    if (bufp->ptr == buf)
X	{
X	  if (bufp->full == bufp->size)
X	    {
X	      bufp->size *= 2;
X	      tem = xrealloc (buf, bufp->size);
X	      bufp->ptr += tem - buf;
X	      append_end += tem - buf;
X	      bufp->beg = buf = tem;
X	    }
X	}
X	    else
X	{
X	  append_end -= bufp->ptr - buf;
X	  bcopy (bufp->ptr, buf, bufp->full -= bufp->ptr - buf);
X	  bufp->ptr = buf;
X	}
X	    if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full)))
X	bufp->ateof = 1;
X	    bufp->full += nread;
X	    if (bufp->full != bufp->size)
X	buf[bufp->full] = 0;
X	  }
X	return end + 1;
X}
X
X#ifdef TEST
X#include <stdio.h>
X
Xmain (argc, argv)
X	   int argc;
X	   char **argv;
X{
X	char *term;
X	char *buf;
X
X	term = argv[1];
X	printf ("TERM: %s\n", term);
X
X	buf = (char *) tgetent (0, term);
X	if ((int) buf <= 0)
X	  {
X	    printf ("No entry.\n");
X	    return 0;
X	  }
X
X	printf ("Entry: %s\n", buf);
X
X	tprint ("cm");
X	tprint ("AL");
X
X	printf ("co: %d\n", tgetnum ("co"));
X	printf ("am: %d\n", tgetflag ("am"));
X}
X
Xtprint (cap)
X	   char *cap;
X{
X	char *x = tgetstr (cap, 0);
X	register char *y;
X
X	printf ("%s: ", cap);
X	if (x)
X	  {
X	    for (y = x; *y; y++)
X	if (*y <= ' ' || *y == 0177)
X	  printf ("\\%0o", *y);
X	else
X	  putchar (*y);
X	    free (x);
X	  }
X	else
X	  printf ("none");
X	putchar ('\n');
X}
X
X#endif /* TEST */
END_OF_TERMCAP.C
if test 18812 -ne `wc -c <TERMCAP.C`; then
    echo shar: \"TERMCAP.C\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f TEXTERN.C -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"TEXTERN.C\"
else
echo shar: Extracting \"TEXTERN.C\" \(5113 characters\)
sed "s/^X//" >TEXTERN.C <<'END_OF_TEXTERN.C'
X/* Termcap External Variables.
X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
X
X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
X   Dec 1987 - Mar 1988.
X
X		       NO WARRANTY
X
X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1986 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more
X    extensive warranty protection to third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
X  3. You may copy and distribute this program or any portion of it in
Xcompiled, executable or object code form under the terms of Paragraphs
X1 and 2 above provided that you do the following:
X
X    a) cause each such copy to be accompanied by the
X    corresponding machine-readable source code, which must
X    be distributed under the terms of Paragraphs 1 and 2 above; or,
X
X    b) cause each such copy to be accompanied by a
X    written offer, with no time limit, to give any third party
X    free (except for a nominal shipping charge) a machine readable
X    copy of the corresponding source code, to be distributed
X    under the terms of Paragraphs 1 and 2 above; or,
X
X    c) in the case of a recipient of this program in compiled, executable
X    or object code form (without the corresponding source code) you
X    shall cause copies you distribute to be accompanied by a copy
X    of the written offer of source code which you received along
X    with the copy you received.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
Xshort ospeed;                   /* these are defined in case user doesn't */
Xchar PC;
X
END_OF_TEXTERN.C
if test 5113 -ne `wc -c <TEXTERN.C`; then
    echo shar: \"TEXTERN.C\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f TPARAM.C -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"TPARAM.C\"
else
echo shar: Extracting \"TPARAM.C\" \(11046 characters\)
sed "s/^X//" >TPARAM.C <<'END_OF_TPARAM.C'
X/* Merge parameters into a termcap entry string.
X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
X
X   Hacked for MS-DOS by Paul Shields, shields@yunccn.UUCP,
X   Dec 1987 - Mar 1988.
X
X		       NO WARRANTY
X
X   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1986 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more
X    extensive warranty protection to third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
X  3. You may copy and distribute this program or any portion of it in
Xcompiled, executable or object code form under the terms of Paragraphs
X1 and 2 above provided that you do the following:
X
X    a) cause each such copy to be accompanied by the
X    corresponding machine-readable source code, which must
X    be distributed under the terms of Paragraphs 1 and 2 above; or,
X
X    b) cause each such copy to be accompanied by a
X    written offer, with no time limit, to give any third party
X    free (except for a nominal shipping charge) a machine readable
X    copy of the corresponding source code, to be distributed
X    under the terms of Paragraphs 1 and 2 above; or,
X
X    c) in the case of a recipient of this program in compiled, executable
X    or object code form (without the corresponding source code) you
X    shall cause copies you distribute to be accompanied by a copy
X    of the written offer of source code which you received along
X    with the copy you received.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X
X/* config.h may rename various library functions such as malloc.  */
X#ifdef emacs
X#include "config.h"
X#else
X#include <fcntl.h>
X#endif
X
X/* MODS for MS-DOS by Paul Shields, December 1987. */
X#ifdef MSDOS
X#include <stdlib.h>
X#endif
X
X/* Assuming STRING is the value of a termcap string entry
X   containing `%' constructs to expand parameters,
X   merge in parameter values and store result in block OUTSTRING points to.
X   LEN is the length of OUTSTRING.  If more space is needed,
X   a block is allocated with `malloc'.
X
X   The value returned is the address of the resulting string.
X   This may be OUTSTRING or may be the address of a block got with `malloc'.
X   In the latter case, the caller must free the block.
X
X   The fourth and following args to tparam serve as the parameter values.  */
X
Xstatic char *tparam1 ();
X
X/* VARARGS 2 */
Xchar *
Xtparam (string, outstring, len, arg0, arg1, arg2, arg3)
X     char *string;
X     char *outstring;
X     int len;
X     int arg0, arg1, arg2, arg3;
X{
X#ifdef NO_ARG_ARRAY
X  int arg[4];
X  arg[0] = arg0;
X  arg[1] = arg1;
X  arg[2] = arg2;
X  arg[3] = arg3;
X  return tparam1 (string, outstring, len, 0, 0, arg);
X#else
X  return tparam1 (string, outstring, len, 0, 0, &arg0);
X#endif
X}
X
Xchar *BC = 0,
X     *UP = 0;
X
Xstatic char tgoto_buf[50];
X
Xchar *
Xtgoto (cm, hpos, vpos)
X     char *cm;
X     int hpos, vpos;
X{
X  int args[2];
X  if (!cm)
X    return 0;
X  args[0] = vpos;
X  args[1] = hpos;
X  return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
X}
X
Xstatic char *
Xtparam1 (string, outstring, len, up, left, argp)
X     char *string;
X     char *outstring;
X     int len;
X     char *up, *left;
X     register int *argp;
X{
X  register int c;
X  register char *p = string;
X  register char *op = outstring;
X  char *outend;
X  int outlen = 0;
X
X  register int tem;
X  int *oargp = argp;
X  char *doleft = 0;
X  char *doup = 0;
X
X  outend = outstring + len;
X
X  while (1)
X    {
X      /* If the buffer might be too short, make it bigger.  */
X      if (op + 5 >= outend)
X	{
X	  register char *new;
X	  if (outlen == 0)
X	    {
X	      new = (char *) malloc (outlen = 40 + len);
X	      outend += 40;
X	    }
X	  else
X	    {
X	      outend += outlen;
X	      new = (char *) realloc (outstring, outlen *= 2);
X	    }
X	  op += new - outstring;
X	  outend += new - outstring;
X	  outstring = new;
X	}
X      if (!(c = *p++))
X	break;
X      if (c == '%')
X	{
X	  c = *p++;
X	  tem = *argp;
X	  switch (c)
X	    {
X	    case 'd':		/* %d means output in decimal */
X	      if (tem < 10)
X		goto onedigit;
X	      if (tem < 100)
X		goto twodigit;
X	    case '3':		/* %3 means output in decimal, 3 digits. */
X	      if (tem > 999)
X		{
X		  *op++ = tem / 1000 + '0';
X		  tem %= 1000;
X		}
X	      *op++ = tem / 100 + '0';
X	    case '2':		/* %2 means output in decimal, 2 digits. */
X	    twodigit:
X	      tem %= 100;
X	      *op++ = tem / 10 + '0';
X	    onedigit:
X	      *op++ = tem % 10 + '0';
X	      argp++;
X	      break;
X
X	    case 'C':
X	      /* For c-100: print quotient of value by 96, if nonzero,
X		 then do like %+ */
X	      if (tem >= 96)
X		{
X		  *op++ = tem / 96;
X		  tem %= 96;
X		}
X	    case '+':		/* %+x means add character code of char x */
X	      tem += *p++;
X	    case '.':		/* %. means output as character */
X	      if (left)
X		{
X		  /* If want to forbid output of 0 and \n,
X		     and this is one, increment it.  */
X		  if (tem == 0 || tem == '\n')
X		    {
X		      tem++;
X		      if (argp == oargp)
X			outend -= strlen (doleft = left);
X		      else
X			outend -= strlen (doup = up);
X		    }
X		}
X	      *op++ = tem | 0200;
X	    case 'f':		/* %f means discard next arg */
X	      argp++;
X	      break;
X
X	    case 'b':		/* %b means back up one arg (and re-use it) */
X	      argp--;
X	      break;
X
X	    case 'r':		/* %r means interchange following two args */
X	      argp[0] = argp[1];
X	      argp[1] = tem;
X	      oargp++;
X	      break;
X
X	    case '>':		/* %>xy means if arg is > char code of x, */
X	      if (argp[0] > *p++) /* then add char code of y to the arg, */
X		argp[0] += *p;	/* and in any case don't output. */
X	      p++;		/* Leave the arg to be output later. */
X	      break;
X
X	    case 'a':		/* %a means arithmetic */
X	      /* Next character says what operation.
X		 Add or subtract either a constant or some other arg */
X	      /* First following character is + to add or - to subtract
X		 or = to assign.  */
X	      /* Next following char is 'p' and an arg spec
X		 (0100 plus position of that arg relative to this one)
X		 or 'c' and a constant stored in a character */
X	      tem = p[2] & 0177;
X	      if (p[1] == 'p')
X		tem = argp[tem - 0100];
X	      if (p[0] == '-')
X		argp[0] -= tem;
X	      else if (p[0] == '+')
X		argp[0] += tem;
X	      else if (p[0] == '*')
X		argp[0] *= tem;
X	      else if (p[0] == '/')
X		argp[0] /= tem;
X	      else
X		argp[0] = tem;
X
X	      p += 3;
X	      break;
X
X	    case 'i':		/* %i means add one to arg, */
X	      argp[0] ++;	/* and leave it to be output later. */
X	      argp[1] ++;	/* Increment the following arg, too!  */
X	      break;
X
X	    case '%':		/* %% means output %; no arg. */
X	      goto ordinary;
X
X	    case 'n':		/* %n means xor each of next two args with 140 */
X	      argp[0] ^= 0140;
X	      argp[1] ^= 0140;
X	      break;
X
X	    case 'm':		/* %m means xor each of next two args with 177 */
X	      argp[0] ^= 0177;
X	      argp[1] ^= 0177;
X	      break;
X
X	    case 'B':		/* %B means express arg as BCD char code. */
X	      argp[0] += 6 * (tem / 10);
X	      break;
X
X	    case 'D':		/* %D means weird Delta Data transformation */
X	      argp[0] -= 2 * (tem % 16);
X	      break;
X	    }
X	}
X      else
X	/* Ordinary character in the argument string.  */
X      ordinary:
X	*op++ = c;
X    }
X  *op = 0;
X  if (doleft)
X    strcpy (op, doleft);
X  if (doup)
X    strcpy (op, doup);
X  return outstring;
X}
X
X#ifdef TEST
X
Xmain (argc, argv)
X     int argc;
X     char **argv;
X{
X  char buf[50];
X  int args[3];
X  args[0] = atoi (argv[2]);
X  args[1] = atoi (argv[3]);
X  args[2] = atoi (argv[4]);
X  tparam1 (argv[1], buf, "LEFT", "UP", args);
X  printf ("%s\n", buf);
X  return 0;
X}
X
X#endif /* TEST */
END_OF_TPARAM.C
if test 11046 -ne `wc -c <TPARAM.C`; then
    echo shar: \"TPARAM.C\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0