Path: news.larc.nasa.gov!amiga-request
From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
Subject: v91i146: Larn 12.3 - dungeon type adventure game, Part02/17
Reply-To: Sie <S.Raybould@fulcrum.bt.co.uk>
Newsgroups: comp.sources.amiga
Message-ID: <comp.sources.amiga.v91i146@ab20.larc.nasa.gov>
References: <comp.sources.amiga.v91i145@ab20.larc.nasa.gov>
Date: 27 Aug 91 01:51:57 GMT
Approved: tadguy@uunet.UU.NET (Tad Guy)
X-Mail-Submissions-To: amiga@uunet.uu.net
X-Post-Discussions-To: comp.sys.amiga.misc

Submitted-by: Sie <S.Raybould@fulcrum.bt.co.uk>
Posting-number: Volume 91, Issue 146
Archive-name: games/larn-12.3/part02

#!/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 archive 2 (of 17)."
# Contents:  fortune.c header.h larndefs.h regen.c savelev.c signal.c
#   termcap.vms tgoto.c tputs.c
# Wrapped by tadguy@ab20 on Mon Aug 26 21:51:52 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'fortune.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fortune.c'\"
else
echo shar: Extracting \"'fortune.c'\" \(4374 characters\)
sed "s/^X//" >'fortune.c' <<'END_OF_FILE'
X/* fortune.c */
X#ifdef VMS
X#include <types.h>
X#include <stat.h>
X#include <file.h>
X#else
X# include <sys/types.h>
X# include <sys/stat.h>
X# ifndef BSD4.1
X#  include <fcntl.h>
X# else BSD4.1
X# define O_RDONLY 0
X# endif BSD4.1
X#endif VMS
X
X#include "header.h"
X#include "player.h"
X#include "larndefs.h"
Xextern char fortfile[];
X
Xoutfortune()
X    {
X    char *p;
X
X    lprcat("\nThe cookie was delicious.");
X    if (c[BLINDCOUNT])
X        return;
X#ifdef MSDOS
X    msdosfortune();
X#else
X    if (p=fortune(fortfile))
X        {
X        lprcat("  Inside you find a scrap of paper that says:\n");
X        lprcat(p);
X        }
X#endif
X    }
X
X# ifdef MSDOS
X# include <stdio.h>
X/* Rumors has been entirely rewritten to be disk based.  This is marginally
X * slower, but requires no mallocked memory.  Notice this in only valid for
X * files smaller than 32K.
X */
Xstatic int fortsize = 0;
X
Xstatic msdosfortune()
X{
X    int fd, status, i;
X    char    buf[BUFSIZ], ch;
X
X    if (fortsize < 0)   /* We couldn't open fortunes */
X        return;
X    if ((fd = open(fortfile, O_RDONLY | O_BINARY)) >= 0) {
X        if (fortsize == 0)
X            fortsize = (int) lseek(fd, 0L, 2);
X        if (lseek(fd, (long) rund(fortsize), 0) < 0)
X            return;
X
X        /* Skip to next newline or EOF
X         */
X        do {
X            status = read(fd, &ch, 1);
X        } while (status != EOF && ch != '\n');
X        if (status == EOF)
X            if (lseek(fd, 0L, 0) < 0) /* back to the beginning */
X                return;
X
X        /* Read in the line.  Search for CR ('\r'), not NL
X         */
X        for (i = 0; i < BUFSIZ - 1; i++)
X            if (read(fd, &buf[i], 1) == EOF || buf[i] == '\r')
X                break;
X        buf[i] = '\0';
X
X        /* And spit it out
X         */
X        lprcat("  Inside you find a scrap of paper that says:\n");
X        lprcat(buf);
X        close(fd);
X    } else
X        fortsize = -1;  /* Don't try opening it again */
X}
X
X# else
X
X/*
X *  function to return a random fortune from the fortune file
X */
Xstatic char *base=0;    /* pointer to the fortune text */
Xstatic char **flines=0; /* array of pointers to each fortune */
Xstatic int fd=0;    /* true if we have load the fortune info */
Xstatic int nlines=0;    /* # lines in fortune database */
X
Xstatic char *fortune(file)
Xchar *file;
X{
X    register char *p;
X    register int lines,tmp;
X    struct stat statbuf;
X    void *malloc();
X
X    if (fd == 0) {
X        if ((fd=open(file,O_RDONLY)) < 0)   /* open the file */
X            return(0); /* can't find file */
X
X        /* find out how big fortune file is and get memory for it */
X        statbuf.st_size = 16384;
X#ifdef AMIGA
X                if((stat(file, &statbuf) < 0)
X#else
X		if((fstat(fd, &statbuf) < 0)
X#endif /* AMIGA */
X        || ((base=(char *)malloc(1+statbuf.st_size)) == 0)) {
X            close(fd);
X            fd= -1;
X            free((char*)base);
X            return(0);  /* can't stat file */
X        }
X
X        /* read in the entire fortune file */
X#ifdef VMS
X        /*
X         * fstat lies about the size (each record has up to
X         * three bytes of fill reported as actual size).
X         * vread returns correct size.
X         */
X        statbuf.st_size = vread(fd,base,statbuf.st_size);
X        if (statbuf.st_size <= 0)
X#else
X        if (vread(fd,base,statbuf.st_size) != statbuf.st_size)
X#endif
X        {
X            close(fd);
X            fd= -1;
X            free((char*)base);
X            return(0);  /* can't read file */
X        }
X        close(fd);
X        base[statbuf.st_size]=0;   /* final NULL termination */
X
X        /* count up all the lines (and 0 terminate) to know memory
X         * needs
X         */
X        for (p=base,lines=0; p<base+statbuf.st_size; p++) /* count lines */
X            if (*p == '\n') *p=0,lines++;
X        nlines = lines;
X
X        /* get memory for array of pointers to each fortune */
X        if ((flines=(char**)malloc(nlines*sizeof(char*))) == 0) {
X            free((char*)base);
X            fd= -1;
X            return(0); /* malloc() failure */
X        }
X
X        /* now assign each pointer to a line */
X        for (p=base,tmp=0; tmp<nlines; tmp++)
X            {
X            flines[tmp]=p;  while (*p++); /* advance to next line */
X            }
X    }
X
X    if (fd > 2) /* if we have a database to look at */
X        return(flines[rund((nlines<=0)?1:nlines)]);
X    else
X        return(0);
X}
X# endif
END_OF_FILE
if test 4374 -ne `wc -c <'fortune.c'`; then
    echo shar: \"'fortune.c'\" unpacked with wrong size!
fi
# end of 'fortune.c'
fi
if test -f 'header.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'header.h'\"
else
echo shar: Extracting \"'header.h'\" \(3718 characters\)
sed "s/^X//" >'header.h' <<'END_OF_FILE'
X/*  header.h        Larn is copyrighted 1986 by Noah Morgan. */
X
X#ifdef MSDOS
X#   define LARNHOME ""
X#endif
X
X#ifdef AMIGA
X#   define LARNHOME "LARN:"
X#endif
X
X#ifndef WIZID
X#   define WIZID  1000
X#endif
X
X#define TRUE 1
X#define FALSE 0
X
X#ifdef VMS
X#define unlink(x)   delete(x)    /* remove a file */
X#endif
X
X#define SCORENAME   "larn.scr"
X#define LOGFNAME    "larn.log"
X#define HELPNAME    "larn.hlp"
X#define LEVELSNAME  "larn.maz"
X#define FORTSNAME   "larn.ftn"
X#define PLAYERIDS   "larn.pid"
X#define HOLIFILE    "holidays"
X#ifdef MSDOS
X#   define LARNOPTS "larn.opt"
X#   define SAVEFILE "larn.sav"
X#   define SWAPFILE "larn.swp"
X#   define CKPFILE  "larn.ckp"
X#else
X# ifdef VMS
X#   define LARNOPTS "larn.opt"
X#   define SAVEFILE "larn.sav"
X#   define CKPFILE  "larn.ckp"
X# else
X#   define LARNOPTS ".larnopts"
X#   define SAVEFILE "Larn.sav"
X#   define CKPFILE  "Larn.ckp"
X# ifndef AMIGA
X#   define MAIL     /* disable the mail routines for MSDOS */
X# endif AMIGA
X# endif VMS
X#endif MSDOS
X
X#define MAXLEVEL 11    /*  max # levels in the dungeon         */
X#define MAXVLEVEL 3    /*  max # of levels in the temple of the luran  */
X#define MAXX 67
X#define MAXY 17
X
X#define SCORESIZE 10    /* this is the number of people on a scoreboard max */
X#define MAXPLEVEL 100   /* maximum player level allowed        */
X#define SPNUM 38        /* maximum number of spells in existance   */
X#define TIMELIMIT 30000 /* maximum number of moves before the game is called */
X#define TAXRATE 1/20    /* tax rate for the LRS */
X
X
X/*  this is the structure that holds the entire dungeon specifications  */
Xstruct cel
X    {
X    short   hitp;   /*  monster's hit points    */
X    char    mitem;  /*  the monster ID          */
X    char    item;   /*  the object's ID         */
X    short   iarg;   /*  the object's argument   */
X    char    know;   /*  have we been here before*/
X    };
X
X/* this is the structure for maintaining & moving the spheres of annihilation */
Xstruct sphere
X    {
X    struct sphere *p;   /* pointer to next structure */
X    char x,y,lev;       /* location of the sphere */
X    char dir;           /* direction sphere is going in */
X    char lifetime;      /* duration of the sphere */
X    };
X
X# ifdef MSDOS
X/* Since only 1 level is needed at one time, each level can be swapped
X * to disk if there is not enough memory to allocate it.  Thus, there
X * need only be room for 1 level.  When a level is needed, if it is
X * already in memory, there is nothing to do.  If it isn't, get it from
X * disk after swapping out the oldest level - dgk.
X */
X# define FREEBLOCK  -99
Xtypedef struct _ramblock RAMBLOCK;
Xtypedef struct _diskblock DISKBLOCK;
Xstruct _ramblock {
X    RAMBLOCK    *next;          /* For a linked list */
X    int     level;          /* Level stored or FREEBLOCK */
X    long        gtime;          /* The time stored */
X    struct  cel cell[MAXX * MAXY];  /* The storage */
X};
Xstruct _diskblock {
X    DISKBLOCK   *next;          /* For linked list */
X    int     level;          /* Level stored or FREEBLOCK */
X    long        gtime;          /* The time stored */
X    long        fpos;           /* The disk position */
X};
Xextern RAMBLOCK *ramblks;
Xextern DISKBLOCK *diskblks;
X
X# endif MSDOS
X
X# ifdef MSDOS
X#  define NULL 0L       /* For large model only */
X# else
X#  define NULL 0
X# endif MSDOS
X#define BUFBIG  4096            /* size of the output buffer */
X#define MAXIBUF 4096            /* size of the input buffer */
X#define LOGNAMESIZE 40          /* max size of the players name */
X#define PSNAMESIZE 40           /* max size of the process name */
X#define SAVEFILENAMESIZE 128    /* max size of the savefile path */
X
X#ifdef AMIGA
X#define vread read
X#define exit(n) {AmEnd();exit(n);}
X#endif AMIGA
END_OF_FILE
if test 3718 -ne `wc -c <'header.h'`; then
    echo shar: \"'header.h'\" unpacked with wrong size!
fi
# end of 'header.h'
fi
if test -f 'larndefs.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'larndefs.h'\"
else
echo shar: Extracting \"'larndefs.h'\" \(5196 characters\)
sed "s/^X//" >'larndefs.h' <<'END_OF_FILE'
X/*
X  Function, data declarations
X*/
Xextern char regen_bottom;
Xextern char floorc, wallc;
Xextern char boldobjects;
Xextern char auto_pickup;
Xextern char VERSION,SUBVERSION;
Xextern char aborted[],beenhere[],boldon,cheat,ckpfile[],ckpflag;
Xextern char *class[],course[],diagfile[],fortfile[],helpfile[],holifile[];
Xextern char ckpfile[];
X# ifdef MSDOS
Xextern int  swapfd;
Xextern char swapfile[];
Xextern long tell(), lseek();
X# endif
Xextern char *inbuffer;
Xextern char item[MAXX][MAXY],iven[],know[MAXX][MAXY],larnlevels[],lastmonst[];
Xextern char level,*levelname[],logfile[],loginname[],logname[],*lpbuf,*lpend;
Xextern char *lpnt,mitem[MAXX][MAXY],monstlevel[];
Xextern char monstnamelist[],nch[],ndgg[],nlpts[],nomove,nosignal,nowelcome;
Xextern char nplt[],nsw[],*objectname[];
Xextern char hacklike_objnamelist[];
Xextern char original_objnamelist[];
Xextern char objnamelist[],optsfile[],*potionname[],playerids[],potprob[];
Xextern char predostuff,psname[],restorflag,savefilename[],scorefile[],scprob[];
Xextern char screen[MAXX][MAXY],*scrollname[],sex,*spelcode[],*speldescript[];
Xextern char spelknow[],*spelname[],*spelmes[];
Xextern char splev[],stealth[MAXX][MAXY],wizard;
Xextern short diroffx[],diroffy[],hitflag,hit2flag,hit3flag,hitp[MAXX][MAXY];
Xextern short iarg[MAXX][MAXY],ivenarg[],lasthx,lasthy,lastnum,lastpx,lastpy;
Xextern short nobeep,oldx,oldy,playerx,playery;
Xextern int dayplay,enable_scroll,yrepcount,userid,wisid,lfd,fd;
Xextern long initialtime,outstanding_taxes,skill[],gtime,c[],cbak[];
Xextern unsigned long lrandx;
X# ifndef MSDOS      /* Different storage under MSDOS */
Xextern struct cel *cell;
X# endif
Xextern struct sphere *spheres;
X
Xvoid *malloc();
Xchar *fortune(),*getenv(),*getlogin(),*lgetw(),*lgetl(),*ctime();
Xchar *tmcapcnv(),*tgetstr(),*tgoto();
Xlong paytaxes(),lgetc(),lrint(),time();
Xunsigned long readnum();
X
X    /* macro to create scroll #'s with probability of occurrence */
X#define newscroll() (scprob[rund(81)])
X    /* macro to return a potion # created with probability of occurrence */
X#define newpotion() (potprob[rund(41)])
X    /* macro to return the + points on created leather armor */
X#define newleather() (nlpts[rund(c[HARDGAME]?13:15)])
X    /* macro to return the + points on chain armor */
X#define newchain() (nch[rund(10)])
X    /* macro to return + points on plate armor */
X#define newplate() (nplt[rund(c[HARDGAME]?4:12)])
X    /* macro to return + points on new daggers */
X#define newdagger() (ndgg[rund(13)])
X    /* macro to return + points on new swords */
X#define newsword() (nsw[rund(c[HARDGAME]?6:13)])
X    /* macro to destroy object at present location */
X#define forget() (item[playerx][playery]=know[playerx][playery]=0)
X    /* macro to wipe out a monster at a location */
X#define disappear(x,y) (mitem[x][y]=know[x][y]=0)
X
X#ifdef VT100
X    /* macro to turn on bold display for the terminal */
X#define setbold() (lprcat(boldon?"\33[1m":"\33[7m"))
X    /* macro to turn off bold display for the terminal */
X#define resetbold() (lprcat("\33[m"))
X    /* macro to setup the scrolling region for the terminal */
X#define setscroll() (lprcat("\33[20;24r"))
X    /* macro to clear the scrolling region for the terminal */
X#define resetscroll() (lprcat("\33[;24r"))
X    /* macro to clear the screen and home the cursor */
X#define clear() (lprcat("\33[2J\33[f"), regen_bottom=TRUE)
X#define cltoeoln() lprcat("\33[K")
X#else /* VT100 */
X    /* defines below are for use in the termcap mode only */
X#define ST_START 1
X#define ST_END   2
X#define BOLD     3
X#define END_BOLD 4
X#define CLEAR    5
X#define CL_LINE  6
X#define T_INIT   7
X#define T_END    8
X#define CL_DOWN 14
X#define CURSOR  15
X    /* macro to turn on bold display for the terminal */
X#define setbold() (*lpnt++ = ST_START)
X    /* macro to turn off bold display for the terminal */
X#define resetbold() (*lpnt++ = ST_END)
X    /* macro to setup the scrolling region for the terminal */
X#define setscroll() enable_scroll=1
X    /* macro to clear the scrolling region for the terminal */
X#define resetscroll() enable_scroll=0
X    /* macro to clear the screen and home the cursor */
X#define clear() (*lpnt++ =CLEAR, regen_bottom=TRUE)
X    /* macro to clear to end of line */
X#define cltoeoln() (*lpnt++ = CL_LINE)
X#endif /* VT100 */
X
X    /* macro to output one byte to the output buffer */
X#define lprc(ch) ((lpnt>=lpend)?(*lpnt++ =(ch), lflush()):(*lpnt++ =(ch)))
X
X    /* macro to seed the random number generator */
X#define srand(x) (lrandx=x)
X#ifdef MACRORND
X    /* macros to generate random numbers   1<=rnd(N)<=N   0<=rund(N)<=N-1 */
X#define rnd(x)  ((((lrandx=lrandx*1103515245+12345)>>7)%(x))+1)
X#define rund(x) ((((lrandx=lrandx*1103515245+12345)>>7)%(x))  )
X#endif /* MACRORND */
X
X#define KNOWNOT   0x00
X#define HAVESEEN  0x1
X#define KNOWHERE  0x2
X#define KNOWALL   (HAVESEEN | KNOWHERE)
X#ifdef MSDOS
X# ifdef OS2LARN
X#  define PATHLEN   256
X#  define DIRLEN    256
X#  define INCL_BASE
X#  include <os2.h>
X#  define sleep(x)	DosSleep(x*1000L);
X# else
X#  define PATHLEN   80
X#  define DIRLEN    64
X# endif
X  extern   char    larndir[];
X  extern int       raw_io, DECRainbow, keypad, ramlevels, cursorset;
X  extern unsigned char cursorstart, cursorend;
X#endif MSDOS
X
Xextern char prompt_mode ;
END_OF_FILE
if test 5196 -ne `wc -c <'larndefs.h'`; then
    echo shar: \"'larndefs.h'\" unpacked with wrong size!
fi
# end of 'larndefs.h'
fi
if test -f 'regen.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'regen.c'\"
else
echo shar: Extracting \"'regen.c'\" \(3917 characters\)
sed "s/^X//" >'regen.c' <<'END_OF_FILE'
X/* regen.c */
X#include "header.h"
X#include "larndefs.h"
X#include "monsters.h"
X#include "player.h"
X
X/*
X    regen()
X
X    subroutine to regenerate player hp and spells
X */
Xregen()
X    {
X    register int i,flag;
X    register long *d;
X    d = c;
X#ifdef EXTRA
X    d[MOVESMADE]++;
X#endif
X    if (d[TIMESTOP])  { if(--d[TIMESTOP]<=0) bottomline();  return; }   /* for stop time spell */
X    flag=0;
X
X    if (d[STRENGTH]<3)  { d[STRENGTH]=3; flag=1; }
X    if (d[HP] != d[HPMAX])
X        if (d[REGENCOUNTER]-- <= 0)     /*  regenerate hit points   */
X            {
X            d[REGENCOUNTER] = 22 + (d[HARDGAME]<<1) - d[LEVEL];
X            if ((d[HP] += d[REGEN]) > d[HPMAX])  d[HP] = d[HPMAX];
X            bottomhp();
X            }
X
X    if (d[SPELLS] < d[SPELLMAX])        /*  regenerate spells   */
X        if (d[ECOUNTER]-- <= 0)
X            {
X            d[ECOUNTER] = 100+4*(d[HARDGAME]-d[LEVEL]-d[ENERGY]);
X            d[SPELLS]++;    bottomspell();
X            }
X
X    if (d[HERO])            if (--d[HERO]<=0) { for (i=0; i<6; i++) d[i] -= 10; flag=1; }
X    if (d[ALTPRO])          if (--d[ALTPRO]<=0)         { d[MOREDEFENSES]-=3; flag=1; }
X    if (d[PROTECTIONTIME])  if (--d[PROTECTIONTIME]<=0) { d[MOREDEFENSES]-=2; flag=1; }
X    if (d[DEXCOUNT])        if (--d[DEXCOUNT]<=0)       { d[DEXTERITY]-=3; flag=1; }
X    if (d[STRCOUNT])        if (--d[STRCOUNT]<=0)       { d[STREXTRA]-=3; flag=1; }
X    if (d[BLINDCOUNT])      if (--d[BLINDCOUNT]<=0)     { cursors();  lprcat("\nThe blindness lifts  "); beep(); }
X    if (d[CONFUSE])         if (--d[CONFUSE]<=0) { cursors();  lprcat("\nYou regain your senses"); beep(); }
X    if (d[GIANTSTR])        if (--d[GIANTSTR]<=0) { d[STREXTRA] -= 20; flag=1; }
X    if (d[CHARMCOUNT])      if ((--d[CHARMCOUNT]) <= 0) flag=1;
X    if (d[INVISIBILITY])    if ((--d[INVISIBILITY]) <= 0) flag=1;
X    if (d[CANCELLATION])    if ((--d[CANCELLATION]) <= 0) flag=1;
X    if (d[WTW])             if ((--d[WTW]) <= 0) flag=1;
X    if (d[HASTESELF])       if ((--d[HASTESELF]) <= 0) flag=1;
X    if (d[AGGRAVATE])       --d[AGGRAVATE]; 
X    if (d[SCAREMONST])      if ((--d[SCAREMONST]) <= 0) flag=1; 
X    if (d[STEALTH])         if ((--d[STEALTH]) <= 0) flag=1; 
X    if (d[AWARENESS])       --d[AWARENESS];
X    if (d[HOLDMONST])       if ((--d[HOLDMONST]) <= 0) flag=1;
X    if (d[HASTEMONST])      --d[HASTEMONST];
X    if (d[FIRERESISTANCE])  if ((--d[FIRERESISTANCE]) <= 0) flag=1;
X    if (d[GLOBE])           if (--d[GLOBE]<=0) { d[MOREDEFENSES]-=10; flag=1; }
X    if (d[SPIRITPRO])       if (--d[SPIRITPRO] <= 0) flag=1;
X    if (d[UNDEADPRO])       if (--d[UNDEADPRO] <= 0) flag=1;
X    if (d[HALFDAM])         if (--d[HALFDAM]<=0)  { cursors();  lprcat("\nYou now feel better "); beep(); }
X    if (d[SEEINVISIBLE])
X      if (--d[SEEINVISIBLE]<=0)
X        { monstnamelist[INVISIBLESTALKER] = floorc;
X          if (!d[BLINDCOUNT]) {
X            cursors();
X            lprcat("\nYou feel your vision return to normal");
X            beep();
X          }
X        }
X    if (d[ITCHING])
X        {
X        if (d[ITCHING]>1)
X            if ((d[WEAR]!= -1) || (d[SHIELD]!= -1))
X                if (rnd(100)<50)
X                    {
X                    d[WEAR]=d[SHIELD]= -1; cursors();
X                    lprcat("\nThe hysteria of itching forces you to remove your armor!"); 
X                    beep(); recalc();  bottomline();
X                    }
X        if (--d[ITCHING]<=0) { cursors();  lprcat("\nYou now feel the irritation subside!"); beep(); }
X        }
X    if (d[CLUMSINESS])
X        {
X        if (d[WIELD] != -1)
X            if (d[CLUMSINESS]>1)
X              if (item[playerx][playery]==0)    /* only if nothing there */
X                if (rnd(100)<33) /* drop your weapon due to clumsiness */
X                    drop_object((int)d[WIELD]);
X        if (--d[CLUMSINESS]<=0) { cursors();  lprcat("\nYou now feel less awkward!"); beep(); }
X        }
X    if (flag) bottomline();
X    }
END_OF_FILE
if test 3917 -ne `wc -c <'regen.c'`; then
    echo shar: \"'regen.c'\" unpacked with wrong size!
fi
# end of 'regen.c'
fi
if test -f 'savelev.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'savelev.c'\"
else
echo shar: Extracting \"'savelev.c'\" \(4091 characters\)
sed "s/^X//" >'savelev.c' <<'END_OF_FILE'
X/* savelev.c */
X#include "header.h"
X#include "larndefs.h"
X
X# ifdef MSDOS
X
Xextern int swapfd;      /* swap file file descriptor */
X
XDISKBLOCK *
Xgetfreediskblk()
X{
X    DISKBLOCK   *dp;
X
X    for (dp = diskblks; dp; dp = dp->next)
X        if (dp->level == FREEBLOCK)
X            return dp;
X    levelinfo();
X    error("Can't find a free disk block ?\n");
X}
X
XRAMBLOCK *
Xgetramblk(lev)
X{
X    RAMBLOCK    *rp, *orp;
X    DISKBLOCK   *dp;
X    long        otime;
X    unsigned int    bytes;
X
X    /* Check if the level is in memory already.
X     */
X    for (rp = ramblks; rp; rp = rp->next)
X        if (rp->level == lev)
X            return rp;
X
X    /* Else grab the first available one.
X     */
X    for (rp = ramblks; rp; rp = rp->next)
X        if (rp->level == FREEBLOCK)
X            return rp;
X
X    /* No ramblocks free, so swap out the oldest level
X     */
X    dp = getfreediskblk();
X
X# ifdef ndef
Xwarn("\nTrying to swap\n");
X# endif
X
X    /* Find the oldest level for swapping out.
X     */
X    otime = ramblks->gtime;
X    orp = ramblks;
X    for (rp = ramblks->next; rp; rp = rp->next) {
X        if (rp->gtime < otime) {
X            otime = rp->gtime;
X            orp = rp;
X        }
X    }
X
X    /* Send the oldest level out to disk.
X     */
X    if (lseek(swapfd, dp->fpos, 0) < 0)
X        error("Can't seek to %ld\n", dp->fpos);
X
X    bytes = sizeof rp->cell;
X    if (write(swapfd, (char *) orp->cell, bytes) != bytes)
X        error("Out of space writing swap file !\n");
X
X    /* Update the level information
X     */
X    dp->level = orp->level;
X    dp->gtime = orp->gtime;
X    orp->level = FREEBLOCK;
X# ifdef ndef
Xwarn("Successful swap\n");
X# endif
X    return orp;
X}
X
X
X# endif
X
X/*
X *  routine to save the present level into storage
X */
Xsavelevel()
X    {
X    register struct cel *pcel;
X    register char *pitem,*pknow,*pmitem;
X    register short *phitp,*piarg;
X    register struct cel *pecel;
X
X# ifdef MSDOS
X    RAMBLOCK    *rp;
X
X    rp = getramblk(level);
X    pcel = rp->cell;
X    rp->gtime = gtime;
X    rp->level = level;
X# else
X    pcel = &cell[level*MAXX*MAXY];  /* pointer to this level's cells */
X# endif
X    pecel = pcel + MAXX*MAXY;   /* pointer to past end of this level's cells */
X    pitem=item[0]; piarg=iarg[0]; pknow=know[0]; pmitem=mitem[0]; phitp=hitp[0];
X    while (pcel < pecel)
X        {
X        pcel->mitem  = *pmitem++;
X        pcel->hitp   = *phitp++;
X        pcel->item   = *pitem++;
X        pcel->know   = *pknow++;
X        pcel->iarg   = *piarg++;
X        pcel++;
X        }
X    }
X
X
X/*
X *  routine to restore a level from storage
X */
Xgetlevel()
X    {
X    register struct cel *pcel;
X    register char *pitem,*pknow,*pmitem;
X    register short *phitp,*piarg;
X    register struct cel *pecel;
X
X# ifdef MSDOS
X    RAMBLOCK    *rp;
X    DISKBLOCK   *dp;
X    unsigned int    bytes;
X
X    /* Is the level in memory already ?
X     */
X    for (rp = ramblks; rp; rp = rp->next)
X        if (rp->level == level)
X            goto haverp;
X
X    /* Is it on disk ?
X     */
X    for (dp = diskblks; dp; dp = dp->next)
X        if (dp->level == level)
X            break;
X    if (dp == NULL) {
X        levelinfo();
X        error("Level %d is neither in memory nor on disk\n", level);
X    }
X
X    /* Make room for it and read it in.
X     */
X    rp = getramblk(level);
X    if (lseek(swapfd, dp->fpos, 0) < 0)
X        error("Can't seek to %ld\n", dp->fpos);
X    bytes = sizeof rp->cell;
X    if (read(swapfd, (char *) rp->cell, bytes) != bytes)
X        error("Didn't read %u bytes\n", bytes);
X
X    /* The disk space is available for future swaps.
X     */
X    dp->level = FREEBLOCK;
Xhaverp:
X    pcel = rp->cell;
X    rp->level = FREEBLOCK;
X# else
X    pcel = &cell[level*MAXX*MAXY];  /* pointer to this level's cells */
X# endif
X    pecel = pcel + MAXX*MAXY;   /* pointer to past end of this level's cells */
X    pitem=item[0]; piarg=iarg[0]; pknow=know[0]; pmitem=mitem[0]; phitp=hitp[0];
X    while (pcel < pecel)
X        {
X        *pmitem++ = pcel->mitem;
X        *phitp++ = pcel->hitp;
X        *pitem++ = pcel->item;
X        *pknow++ = pcel->know;
X        *piarg++ = pcel->iarg;
X        pcel++;
X        }
X    }
END_OF_FILE
if test 4091 -ne `wc -c <'savelev.c'`; then
    echo shar: \"'savelev.c'\" unpacked with wrong size!
fi
# end of 'savelev.c'
fi
if test -f 'signal.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'signal.c'\"
else
echo shar: Extracting \"'signal.c'\" \(5625 characters\)
sed "s/^X//" >'signal.c' <<'END_OF_FILE'
X#include <signal.h>
X#include "header.h"
X#include "larndefs.h"
X
X#define BIT(a) (1<<((a)-1))
X
Xextern char savefilename[],wizard,predostuff,nosignal;
X
Xstatic s2choose()   /* text to be displayed if ^C during intro screen */
X    {
X    cursor(1,24); lprcat("Press "); setbold(); lprcat("return"); resetbold();
X    lprcat(" to continue: ");   lflush();
X    }
X
Xstatic void cntlc()    /* what to do for a ^C */
X    {
X    if (nosignal) return;   /* don't do anything if inhibited */
X#ifndef AMIGA
X# ifndef MSDOS
X    signal(SIGQUIT,SIG_IGN);
X# endif MSDOS
X#endif AMIGA
X    signal(SIGINT,SIG_IGN);
X    quit(); if (predostuff==1) s2choose(); else showplayer();
X    lflush();
X# ifndef MSDOS
X#ifndef AMIGA
X    signal(SIGQUIT,cntlc);
X#endif /* AMIGA */
X# endif
X    signal(SIGINT,cntlc);
X    }
X
X#ifndef MSDOS
X/*
X *  subroutine to save the game if a hangup signal
X */
Xstatic sgam()
X    {
X    savegame(savefilename);  wizard=1;  died(-257); /* hangup signal */
X    }
X#endif
X
X#ifdef SIGTSTP
Xstatic tstop() /* control Y */
X    {
X    if (nosignal)   return;  /* nothing if inhibited */
X    lcreat((char*)0);  clearvt100();    lflush();     signal(SIGTSTP,SIG_DFL);
X#ifdef SIGVTALRM
X    /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/
X    sigsetmask(sigblock(0)& ~BIT(SIGTSTP));
X#endif
X    kill(getpid(),SIGTSTP);
X
X    setupvt100();  signal(SIGTSTP,tstop);
X    if (predostuff==1) s2choose(); else drawscreen();
X    showplayer();   lflush();
X    }
X#endif SIGTSTP
X
X/*
X *  subroutine to issue the needed signal traps  called from main()
X */
Xstatic void sigfpe()  { sigpanic(SIGFPE); }
X# ifndef MSDOS
X#ifndef AMIGA
Xstatic sigbus()  { sigpanic(SIGBUS); }
Xstatic sigill()  { sigpanic(SIGILL); }   static sigtrap() { sigpanic(SIGTRAP); }
Xstatic sigiot()  { sigpanic(SIGIOT); }   static sigemt()  { sigpanic(SIGEMT); }
Xstatic sigsegv() { sigpanic(SIGSEGV); }  static sigsys()  { sigpanic(SIGSYS); }
Xstatic sigpipe() { sigpanic(SIGPIPE); }  static sigterm() { sigpanic(SIGTERM); }
X#endif /* AMIGA */
X# endif /* MSDOS */
X
Xsigsetup()
X    {
X    signal(SIGINT,  cntlc);
X    signal(SIGFPE,  sigfpe);
X# ifndef MSDOS
X#ifndef AMIGA
X    signal(SIGBUS,  sigbus);        signal(SIGQUIT, cntlc);
X    signal(SIGKILL, SIG_IGN);       signal(SIGHUP,  sgam);
X    signal(SIGILL,  sigill);        signal(SIGTRAP, sigtrap);
X    signal(SIGIOT,  sigiot);        signal(SIGEMT,  sigemt);
X    signal(SIGSEGV, sigsegv);       signal(SIGSYS,  sigsys);
X    signal(SIGPIPE, sigpipe);       signal(SIGTERM, sigterm);
X#ifdef SIGTSTP
X    signal(SIGTSTP,tstop);      signal(SIGSTOP,tstop);
X#endif SIGTSTP
X#endif /* AMIGA */
X# endif
X    }
X
X#ifdef MSDOS
X#define NSIG 9
X#endif
X
X#ifdef VMS
X#define NSIG 16
X#endif
X
X#ifdef BSD  /* for BSD UNIX? */
X
Xstatic char *signame[NSIG] = { "",
X"SIGHUP",  /*   1    hangup */
X"SIGINT",  /*   2    interrupt */
X"SIGQUIT", /*   3    quit */
X"SIGILL",  /*   4    illegal instruction (not reset when caught) */
X"SIGTRAP", /*   5    trace trap (not reset when caught) */
X"SIGIOT",  /*   6    IOT instruction */
X"SIGEMT",  /*   7    EMT instruction */
X"SIGFPE",  /*   8    floating point exception */
X"SIGKILL", /*   9    kill (cannot be caught or ignored) */
X"SIGBUS",  /*   10   bus error */
X"SIGSEGV", /*   11   segmentation violation */
X"SIGSYS",  /*   12   bad argument to system call */
X"SIGPIPE", /*   13   write on a pipe with no one to read it */
X"SIGALRM", /*   14   alarm clock */
X"SIGTERM", /*   15   software termination signal from kill */
X"SIGURG",  /*   16   urgent condition on IO channel */
X"SIGSTOP", /*   17   sendable stop signal not from tty */
X"SIGTSTP", /*   18   stop signal from tty */
X"SIGCONT", /*   19   continue a stopped process */
X"SIGCHLD", /*   20   to parent on child stop or exit */
X"SIGTTIN", /*   21   to readers pgrp upon background tty read */
X"SIGTTOU", /*   22   like TTIN for output if (tp->t_local&LTOSTOP) */
X"SIGIO",   /*   23   input/output possible signal */
X"SIGXCPU", /*   24   exceeded CPU time limit */
X"SIGXFSZ", /*   25   exceeded file size limit */
X"SIGVTALRM",/*  26   virtual time alarm */
X"SIGPROF", /*   27   profiling time alarm */
X"","","","" };
X
X#else BSD   /* for system V? */
X
Xstatic char *signame[NSIG+1] = { "",
X"SIGHUP",  /*   1    hangup */
X"SIGINT",  /*   2    interrupt */
X"SIGQUIT", /*   3    quit */
X"SIGILL",  /*   4    illegal instruction (not reset when caught) */
X"SIGTRAP", /*   5    trace trap (not reset when caught) */
X"SIGIOT",  /*   6    IOT instruction */
X"SIGEMT",  /*   7    EMT instruction */
X# if MSDOS|AMIGA
X"SIGFPE"}; /*   8    floating point exception */
X# else MSDOS
X"SIGFPE",  /*   8    floating point exception */
X"SIGKILL", /*   9    kill (cannot be caught or ignored) */
X"SIGBUS",  /*   10   bus error */
X"SIGSEGV", /*   11   segmentation violation */
X"SIGSYS",  /*   12   bad argument to system call */
X"SIGPIPE", /*   13   write on a pipe with no one to read it */
X"SIGALRM", /*   14   alarm clock */
X# ifdef VMS
X"SIGTERM"}; /*  15   software termination signal from kill */
X# else VMS
X"SIGTERM", /*   15   software termination signal from kill */
X"SIGUSR1",  /*  16   user defines signal 1 */
X"SIGUSR2", /*   17   user defines signal 2 */
X"SIGCLD",  /*   18   child death */
X"SIGPWR" };  /*   19   power fail */
X# endif VMS
X# endif MSDOS
X# endif BSD
X
X/*
X *  routine to process a fatal error signal
X */
Xstatic sigpanic(sig)
Xint sig;
X{
X    char buf[128];
X    signal(sig,SIG_DFL);
X    sprintf(buf,"\nLarn - Panic! Signal %d received [%s]",sig,signame[sig]);
X    write(2,buf,strlen(buf));  sleep(2);
X    sncbr();
X    savegame(savefilename); 
X# ifdef MSDOS
X    exit(1);
X# else
X    kill(getpid(),sig); /* this will terminate us */
X# endif
X}
END_OF_FILE
if test 5625 -ne `wc -c <'signal.c'`; then
    echo shar: \"'signal.c'\" unpacked with wrong size!
fi
# end of 'signal.c'
fi
if test -f 'termcap.vms' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'termcap.vms'\"
else
echo shar: Extracting \"'termcap.vms'\" \(4005 characters\)
sed "s/^X//" >'termcap.vms' <<'END_OF_FILE'
Xsl|lpr|printer|print|printing|line printer:\
X	:cr=^M:do=^J:nl=^J:bl=^G:le=^H:bs:co#132:hc:os:
Xsu|dumb|un|unknown:\
X	:am:bl=^G:co#80:cr=^M:do=^J:nl=^J:
Xsx|ansi|any ansi terminal with pessimistic assumptions:\
X	:co#80:li#24:cl=50\E[;H\E[2J:\
X	:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\
X	:ce=\E[K:ho=\E[H:pt:
X#
X# not sure if vt102 belongs exactly here, but it works with rainbow
X# emulation of a vt102...
X#
Xdr|vt100p|vt102-80|vt100p-nam|dec vt100p:\
X	:am:al=\E[L:bl=^G:bs:cd=50\E[J:ce=3\E[K:cl=50\E[;H\E[2J:\
X	:cm=10\E[%i%d;%dH:co#80:cr=^M:cs=\E[%i%d;%dr:dc=\E[P:\
X	:dl=\E[M:do=^J:ei=\E[4l:ho=\E[H:im=\E[4h:is=\E[1;24r\E[24;1H:\
X	:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:kb=^H:kd=\EOB:ke=\E[?1l\E>:\
X	:kl=\EOD:kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:li#24:md=2\E[1m:\
X	:mr=2\E[7m:mb=2\E[5m:me=2\E[m:mi:nd=\E[C:nl=^J:pt:rc=\E8:\
X	:rf=/usr/lib/tabset/vt100:rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\
X	:sc=\E7:se=\E[m:so=\E[7m:sr=\EM:ta=^I:ue=\E[m:up=\E[A:us=\E[4m:\
X	:vt#3:xn:
Xda|vt200|VT200-80|vt2xx|vt200-80|vt220|vt220-80|vt200-nam|dec vt200:\
X	:ae=4\E(B:as=2\E(<:se=2\E[27m:ue=2\E[24m:tc=vt100p:
Xdd|vt200-132|vt220-132|VT200-132|vt200-w|dec vt200 132 cols:\
X	:co#132:tc=vt200:
Xdb|vt300|vt300-80|vt3xx|dec vt300|vt320|vt320-80|vt300-nam|VT300-80|dec vt300 80 cols:\
X	:ds=\E[1$}\E[;H\E[K\E[0$}:\
X	:es:fs=\E[0$}:hs:ts=\E[1$}\E[;H\E[K:\
X	:tc=vt200:
Xdc|vt300-132|vt320-132|vt300-w|VT300-132|dec vt300 132 cols:\
X	:co#132:tc=vt300:
Xd0|vt100|VT100-80|vt100-80|vt100-am|dec vt100:\
X	:cr=^M:do=^J:nl=^J:bl=^G:co#80:li#24:cl=50\E[;H\E[2J:\
X	:le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
X	:ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
X	:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\
X	:rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
X	:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
X	:ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:ta=^I:pt:sr=5\EM:vt#3:xn:\
X	:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:
Xd1|vt100-nam|vt100 w/no am:\
X	:am@:xn@:tc=vt100-am:
Xd3|vt132|vt132-80|dec vt132:\
X	:al=99\E[L:dl=99\E[M:ip=7:dc=7\E[P:ei=\E[4l:im=\E[4h:xn:dN#30:tc=vt100:
Xd4|vt132-132|vt132 132 cols:\
X	:co#132:tc=vt132:
Xd6|vt125|vt125-80|vt125-am|DEC vt125:\
X	:cr=^M:do=^J:nl=^J:bl=^G:co#80:li#24:cl=50\E[H\E[2J:\
X	:le=^H:am:bs:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:ce=3\E[K:cd=50\E[J:\
X	:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:\
X	:me=2\E[m:is=\E[1;24r\E[24;1H\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\
X	:ks=\E[?1h\E=:ke=\E[?1l\E>:ku=\EOA:kd=\EOB:\
X	:kr=\EOC:kl=\EOD:kb=^H:ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:ta=^I:\
X	:pt:sr=5\EM:vt#3:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:
Xdt|vt100-132|vt100-w|dec vt100 132 cols (w/advanced video):\
X	:co#132:li#24:rs=\E>\E[?3h\E[?4l\E[?5l\E[?8h:tc=vt100-am:
Xdv|vt100-w-nam|dec vt100 132 cols (w/advanced video), no am:\
X	:co#132:li#24:rs=\E>\E[?3h\E[?4l\E[?5l\E[?8h:vt@:tc=vt100-nam:
Xdw|vt52|vt52-80|dec vt52:\
X	:cr=^M:do=^J:nl=^J:bl=^G:\
X	:le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :co#80:li#24:nd=\EC:\
X	:ta=^I:pt:sr=\EI:up=\EA:ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:
Xkb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith|heathkit h19:\
X	:cr=^M:nl=^J:bl=^G:\
X	:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:\
X	:dl=1*\EM:do=\EB:ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:\
X	:ms:ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:\
X	:kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:kn#8:\
X	:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:\
X	:l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:\
X	:es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
XkA|h19-a|h19a|heath-ansi|heathkit-a|heathkit h19 ansi mode:\
X	:cr=^M:nl=^J:bl=^G:\
X	:al=1*\E[1L:am:le=^H:bs:cd=\E[J:ce=\E[K:cl=\E[2J:cm=\E[%i%2;%2H:co#80:\
X	:dc=\E[1P:dl=1*\E[1M:do=\E[1B:ei=\E[4l:ho=\E[H:im=\E[4h:li#24:mi:\
X	:nd=\E[1C:as=\E[10m:ae=\E[11m:ms:ta=^I:pt:se=\E[0m:so=\E[7m:up=\E[1A:\
X	:vs=\E[>4h:ve=\E[>4l:kb=^h:ku=\E[1A:kd=\E[1B:kl=\E[1D:kr=\E[1C:\
X	:kh=\E[H:kn#8:k1=\EOS:k2=\EOT:k3=\EOU:k4=\EOV:k5=\EOW:l6=blue:\
X	:l7=red:l8=white:k6=\EOP:k7=\EOQ:k8=\EOR:\
X	:sr=\EM:is=\E<\E[>1;2;3;4;5;6;7;8;9l\E[0m\E[11m\E[?7h:
END_OF_FILE
if test 4005 -ne `wc -c <'termcap.vms'`; then
    echo shar: \"'termcap.vms'\" unpacked with wrong size!
fi
# end of 'termcap.vms'
fi
if test -f 'tgoto.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tgoto.c'\"
else
echo shar: Extracting \"'tgoto.c'\" \(6360 characters\)
sed "s/^X//" >'tgoto.c' <<'END_OF_FILE'
X/************************************************************************
X *                                  *
X *          Copyright (c) 1982, Fred Fish           *
X *              All Rights Reserved             *
X *                                  *
X *  This software and/or documentation is released for public   *
X *  distribution for personal, non-commercial use only.     *
X *  Limited rights to use, modify, and redistribute are hereby  *
X *  granted for non-commercial purposes, provided that all      *
X *  copyright notices remain intact and all changes are clearly *
X *  documented.  The author makes no warranty of any kind with  *
X *  respect to this product and explicitly disclaims any implied    *
X *  warranties of merchantability or fitness for any particular *
X *  purpose.                            *
X *                                  *
X ************************************************************************
X */
X
X
X/*
X *  LIBRARY FUNCTION
X *
X *  tgoto   expand cursor addressing string from cm capability
X *
X *  KEY WORDS
X *
X *  termcap
X *
X *  SYNOPSIS
X *
X *  char *tgoto(cm,destcol,destline)
X *  char *cm;
X *  int destcol;
X *  int destline;
X *
X *  DESCRIPTION
X *
X *  Returns cursor addressing string, decoded from the cm
X *  capability string, to move cursor to column destcol on
X *  line destline.
X *
X *  The following sequences uses one input argument, either
X *  line or column, and place the appropriate substitution
X *  in the output string:
X *
X *      %d  substitute decimal value (in ASCII)
X *      %2  like %d but forces field width to 2
X *      %3  like %d but forces field width to 3
X *      %.  like %c
X *      %+x like %c but adds ASCII value of x
X *
X *  The following sequences cause processing modifications
X *  but do not "use up" one of the arguments.  If they
X *  act on an argument they act on the next one to
X *  be converted.
X *
X *      %>xy    if next value to be converted is
X *          greater than value of ASCII char x
X *          then add value of ASCII char y.
X *      %r  reverse substitution of line
X *          and column (line is substituted
X *          first by default).
X *      %i  causes input values destcol and
X *          destline to be incremented.
X *      %%  gives single % character in output.
X *
X *  BUGS
X *
X *  Does not implement some of the more arcane sequences for
X *  radically weird terminals (specifically %n, %B, & %D).
X *  If you have one of these you deserve whatever happens.
X *
X */
X
X/*
X *  Miscellaneous stuff
X */
X
X#include <stdio.h>
X
X#define MAXARGS 2
X
Xstatic char *in;        /* Internal copy of input string pointer */
Xstatic char *out;       /* Pointer to output array */
Xstatic int args[MAXARGS];   /* Maximum number of args to convert */
Xstatic int pcount;      /* Count of args processed */
Xstatic char output[64];     /* Converted string */
X
X
X/*
X *  PSEUDO CODE
X *
X *  Begin tgoto
X *      If no string to process then
X *      Return pointer to error string.
X *      Else
X *      Initialize pointer to input string.
X *      Initialize pointer to result string.
X *      First arg is line number by default.
X *      Second arg is col number by default.
X *      No arguments processed yet.
X *      While there is another character to process
X *          If character is a not a % character then
X *          Simply copy to output.
X *          Else
X *          Process the control sequence.
X *          End if
X *      End while
X *      TERMINATE STRING!  (rde)
X *      Return pointer to static output string.
X *      End if
X *  End tgoto
X *
X */
X
Xchar *tgoto(cm,destcol,destline)
Xchar *cm;
Xint destcol;
Xint destline;
X{
X    if (cm == NULL) {
X    return("OOPS");
X    } else {
X    in = cm;
X    out = output;
X    args[0] = destline;
X    args[1] = destcol;
X    pcount = 0;
X    while (*in != NULL) {
X        if (*in != '%') {
X        *out++ = *in++;
X        } else {
X        process();
X        }
X    }
X    *out = '\0';    /* rde 18-DEC-86: don't assume out was all zeros */
X    return(output);
X    }
X}
X
X/*
X *  INTERNAL FUNCTION
X *
X *  process   process the conversion/command sequence
X *
X *  SYNOPSIS
X *
X *  static process()
X *
X *  DESCRIPTION
X *
X *  Processes the sequence beginning with the % character.
X *  Directly manipulates the input string pointer, the
X *  output string pointer, and the arguments.  Leaves
X *  the input string pointer pointing to the next character
X *  to be processed, and the output string pointer pointing
X *  to the next output location.  If conversion of
X *  one of the numeric arguments occurs, then the pcount
X *  is incremented.
X *
X */
X
X/*
X *  PSEUDO CODE
X *
X *  Begin process
X *      Skip over the % character.
X *      Switch on next character after %
X *      Case 'd':
X *      Process %d type conversion (variable width).
X *      Reinitialize output pointer.
X *      Break;
X *      Case '2':
X *      Process %d type conversion (width 2).
X *      Reinitialize output pointer.
X *      Break;
X *      Case '3':
X *      Process %d type conversion (width 3).
X *      Reinitialize output pointer.
X *      Break;
X *      Case '.'
X *      Process %c type conversion.
X *      Break;
X *      Case '+':
X *      Process %c type conversion with offset.
X *      Break;
X *      Case '>':
X *      Process argument modification.
X *      Break;
X *      Case 'r':
X *      Process argument reversal.
X *      Break;
X *      Case 'i':
X *      Increment argument values.
X *      Break;
X *      Case '%':
X *      Copy to output, incrementing pointers.
X *      Break;
X *      End switch
X *  End process
X *
X */
X
X
Xstatic process()
X{
X    int temp;
X
X    in++;
X    switch(*in++) {
X    case 'd':
X    sprintf(out,"%d",args[pcount++]);
X    out = &output[strlen(output)];  
X    break;
X    case '2':
X    sprintf(out,"%02d",args[pcount++]);
X    out += 2 ;
X/*
X    out = &output[strlen(output)];
X*/
X    break;
X    case '3':
X    sprintf(out,"%03d",args[pcount++]);
X    out = &output[strlen(output)];
X    break;
X    case '.':
X    *out++ = args[pcount++];
X    break;
X    case '+':
X    *out++ = args[pcount++] + *in++;
X    break;
X    case '>':
X    if (args[pcount] > *in++) {
X        args[pcount] += *in++;
X    } else {
X        in++;
X    }
X    break;
X    case 'r':
X    temp = args[pcount];
X    args[pcount] = args[pcount+1];
X    args[pcount+1] = temp;
X    break;
X    case 'i':
X    args[pcount]++;
X    args[pcount+1]++;
X    break;
X    case '%':
X    *out++ = '%';
X    break;
X    }
X}
END_OF_FILE
if test 6360 -ne `wc -c <'tgoto.c'`; then
    echo shar: \"'tgoto.c'\" unpacked with wrong size!
fi
# end of 'tgoto.c'
fi
if test -f 'tputs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tputs.c'\"
else
echo shar: Extracting \"'tputs.c'\" \(5800 characters\)
sed "s/^X//" >'tputs.c' <<'END_OF_FILE'
X/************************************************************************
X *                                  *
X *          Copyright (c) 1982, Fred Fish           *
X *              All Rights Reserved             *
X *                                  *
X *  This software and/or documentation is released for public   *
X *  distribution for personal, non-commercial use only.     *
X *  Limited rights to use, modify, and redistribute are hereby  *
X *  granted for non-commercial purposes, provided that all      *
X *  copyright notices remain intact and all changes are clearly *
X *  documented.  The author makes no warranty of any kind with  *
X *  respect to this product and explicitly disclaims any implied    *
X *  warranties of merchantability or fitness for any particular *
X *  purpose.                            *
X *                                  *
X ************************************************************************
X */
X
X
X/*
X *  LIBRARY FUNCTION
X *
X *  tputs     output string with appropriate padding
X *
X *  KEY WORDS
X *
X *  termcap
X *
X *  SYNOPSIS
X *
X *  tputs(cp,affcnt,outc)
X *  char *cp;
X *  int affcnt;
X *  int (*outc)();
X *
X *  DESCRIPTION
X *
X *  Outputs string pointed to by cp, using function outc, and
X *  following it with the appropriate number of padding characters.
X *  Affcnt contains the number of lines affected, which is used
X *  as a multiplier for the specified per line pad time.  If
X *  per line pad count is not applicable, affcnt should be 1,
X *  NOT zero.
X *
X *  The format of the string pointed to by cp is:
X *
X *      [pad time][*]<string to send>
X *
X *      where:  pad time => time to delay in milliseconds
X *          * => specifies that time is per line
X *          
X *  The pad character is assumed to reside in the external
X *  variable "PC".  Also, the external variable "ospeed"
X *  should contain the output speed of the terminal as
X *  encoded in /usr/include/sgtty.h  (B0-B9600).
X *
X *  BUGS
X *
X *  Digit conversion is based on native character set
X *  being ASCII.
X *
X */
X
X/*
X *  Miscellaneous stuff
X */
X
X#include <stdio.h>
X#include <ctype.h>
X
X# ifndef MSDOS
Xextern char PC;         /* Pad character to use */
Xextern char ospeed;     /* Encoding of output speed */
X
Xstatic int times[] = {
X    0,              /* Tenths of ms per char 0 baud */
X    2000,           /* Tenths of ms per char 50 baud */
X    1333,           /* Tenths of ms per char 75 baud */
X    909,            /* Tenths of ms per char 110 baud */
X    743,            /* Tenths of ms per char 134 baud */
X    666,            /* Tenths of ms per char 150 baud */
X    500,            /* Tenths of ms per char 200 baud */
X    333,            /* Tenths of ms per char 300 baud */
X    166,            /* Tenths of ms per char 600 baud */
X    83,             /* Tenths of ms per char 1200 baud */
X    55,             /* Tenths of ms per char 1800 baud */
X    41,             /* Tenths of ms per char 2400 baud */
X    20,             /* Tenths of ms per char 4800 baud */
X    10              /* Tenths of ms per char 9600 baud */
X};
X# endif
X
X
X/*
X *  PSEUDO CODE
X *
X *  Begin tgoto
X *      If string pointer is invalid then
X *      Return without doing anything.
X *      Else
X *      For each pad digit (if any)
X *          Do decimal left shift.
X *          Accumulate the lower digit.
X *      End for
X *      Adjust scale to tenths of milliseconds
X *      If there is a fractional field
X *          Skip the decimal point.
X *          If there is a valid tenths digit
X *          Accumulate the tenths.
X *          End if
X *          Discard remaining digits.
X *      End if
X *      If per line is specified then
X *          Adjust the pad time.
X *          Discard the per line flag char.
X *      End if
X *      While there are any characters left
X *          Send them out via output function.
X *      End while
X *      Transmit any padding required.
X *      End if
X *  End tgoto
X *
X */
X
Xtputs(cp,affcnt,outc)
Xchar *cp;
Xint affcnt;
Xint (*outc)();
X{
X    int ptime;          /* Pad time in tenths of milliseconds */
X
X    if (cp == NULL || *cp == NULL) {
X    return;
X    } else {
X    for (ptime = 0; isdigit(*cp); cp++) {
X        ptime *= 10;
X        ptime += (*cp - '0');
X    }
X    ptime *= 10;
X    if (*cp == '.') {
X        cp++;
X        if (isdigit(*cp)) {
X        ptime += (*cp++ - '0');
X        }
X        while (isdigit(*cp)) {cp++;}
X    }
X    if (*cp == '*') {
X        ptime *= affcnt;
X        cp++;
X    }
X    while (*cp != NULL) {
X        (*outc)(*cp++);
X    }
X# ifndef MSDOS
X# ifndef VMS
X    do_padding(ptime,outc);
X# endif
X# endif
X    }
X}
X
X# ifndef MSDOS
X/*
X *  FUNCTION
X *
X *  do_padding    transmit any pad characters required
X *
X *  SYNOPSIS
X *
X *  static do_padding(ptime,outc)
X *  int ptime;
X *  int (*outc)();
X *
X *  DESCRIPTION
X *
X *  Does any padding required as specified by ptime (in tenths
X *  of milliseconds), the output speed given in the external
X *  variable ospeed, and the pad character given in the
X *  external variable PC.
X *
X */
X
X/*
X *  PSEUDO CODE
X *
X *  Begin do_padding
X *      If there is a non-zero pad time then
X *      If the external speed is in range then
X *          Look up the delay per pad character.
X *          Round pad time up by half a character.
X *          Compute number of characters to send.
X *          For each pad character to send
X *          Transmit the pad character.
X *          End for
X *      End if
X *      End if
X *  End do_padding
X *
X */
X
Xstatic do_padding(ptime,outc)
Xint ptime;
Xint (*outc)();
X{
X    register int nchars;
X    register int tpc;
X
X    if (ptime != 0) {
X    if (ospeed > 0 && ospeed <= (sizeof(times)/ sizeof(int))) {
X        tpc = times[ospeed];
X        ptime += (tpc / 2);
X        nchars = ptime / tpc;
X        for ( ; nchars > 0; --nchars) {
X        (*outc)(PC);
X        }
X    }
X    }
X}
X# endif
END_OF_FILE
if test 5800 -ne `wc -c <'tputs.c'`; then
    echo shar: \"'tputs.c'\" unpacked with wrong size!
fi
# end of 'tputs.c'
fi
echo shar: End of archive 2 \(of 17\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 17 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.misc.
