Path: news.larc.nasa.gov!amiga-request
From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
Subject: v91i148: Larn 12.3 - dungeon type adventure game, Part04/17
Reply-To: Sie <S.Raybould@fulcrum.bt.co.uk>
Newsgroups: comp.sources.amiga
Message-ID: <comp.sources.amiga.v91i148@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 148
Archive-name: games/larn-12.3/part04

#!/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 4 (of 17)."
# Contents:  bill.c larnhlp.txt msdos.c tgetent.c
# Wrapped by tadguy@ab20 on Mon Aug 26 21:51:52 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'bill.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bill.c'\"
else
echo shar: Extracting \"'bill.c'\" \(8393 characters\)
sed "s/^X//" >'bill.c' <<'END_OF_FILE'
X/* bill.c */
X#include "header.h"
X#include "larndefs.h"
X
X# ifdef MAIL
X# include "player.h"
X# ifdef VMS
X# define MAILTMP    "sys$scratch:"
X# else
X# define MAILTMP    "/tmp/#"
X# endif
Xstatic int pid;
Xstatic char mail600[sizeof(MAILTMP)+sizeof("mail600")+20];
X# endif
X/*
X *  function to create the tax bill for the user
X */
X# ifdef MAIL
Xstatic letter1()
X# else
Xstatic letter1(gold)
Xlong gold;
X# endif
X  {
X# ifdef MAIL
X  sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 600 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif /*RFCMAIL*/
X# endif
X#ifdef RFCMAIL
X  lprcat("From: LRS (Larn Revenue Service)\n");
X  lprcat("Subject: Undeclared Income\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  the LRS (Larn Revenue Service)\n");
X  standout("\nSubject:"); lprcat("  undeclared income\n");
X#endif /*RFCMAIL*/
X  lprcat("\n   We heard you survived the caverns of Larn.  Let me be the");
X  lprcat("\nfirst to congratulate you on your success.  It is quite a feat.");
X  lprcat("\nIt must also have been very profitable for you.");
X  lprcat("\n\n   The Dungeon Master has informed us that you brought");
X# ifdef MAIL
X  lprintf("\n%d gold pieces back with you from your journey.  As the",(long)c[GOLD]);
X# else
X  lprintf("\n%d gold pieces back with you from your journey.  As the", gold);
X# endif
X  lprcat("\ncounty of Larn is in dire need of funds, we have spared no time");
X  lprintf("\nin preparing your tax bill.  You owe %d gold pieces as",
X# ifdef MAIL
X    (long)c[GOLD]*TAXRATE);
X# else
X    gold * TAXRATE);
X# endif
X  lprcat("\nof this notice, and is due within 5 days.  Failure to pay will");
X  lprcat("\nmean penalties.  Once again, congratulations, We look forward");
X  lprcat("\nto your future successful expeditions.\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
Xstatic letter2()
X  {
X# ifdef MAIL
X  sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 601 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif /*RFCMAIL*/
X# endif
X#ifdef RFCMAIL
X  lprcat("From: King (His Majesty King Wilfred of Larndom)\n");
X  lprcat("Subject: A Noble Deed\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  His Majesty King Wilfred of Larndom\n");
X  standout("\nSubject:"); lprcat("  a noble deed\n");
X#endif /*RFCMAIL*/
X  lprcat("\n   I have heard of your magnificent feat, and I, King Wilfred,");
X  lprcat("\nforthwith declare today to be a national holiday.  Furthermore,");
X  lprcat("\nhence three days, Ye be invited to the castle to receive the");
X  lprcat("\nhonour of Knight of the realm.  Upon thy name shall it be written. . .");
X  lprcat("\nBravery and courage be yours.");
X  lprcat("\nMay you live in happiness forevermore . . .\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
Xstatic letter3()
X  {
X# ifdef MAIL
X  sprintf(mail600,"%s%dmail600",MAILTMP,pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 602 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif /*RFCMAIL*/
X# endif
X#ifdef RFCMAIL
X  lprcat("From: Endelford (Count Endelford)\n");
X  lprcat("Subject: You Bastard!\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  Count Endelford\n");
X  standout("\nSubject:"); lprcat("  You Bastard!\n");
X#endif /*RFCMAIL*/
X  lprcat("\n   I heard (from sources) of your journey.  Congratulations!");
X  lprcat("\nYou Bastard!  With several attempts I have yet to endure the");
X  lprcat(" caves,\nand you, a nobody, makes the journey!  From this time");
X  lprcat(" onward, bewarned\nupon our meeting you shall pay the price!\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
Xstatic letter4()
X  {
X# ifdef MAIL
X  sprintf(mail600,"%s%dmail600", MAILTMP,pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 603 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif /*RFCMAIL*/
X# endif
X#ifdef RFCMAIL
X  lprcat("From: Mainair (Mainair, Duke of Larnty)\n");
X  lprcat("Subject: High Praise\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  Mainair, Duke of Larnty\n");
X  standout("\nSubject:"); lprcat("  High Praise\n");
X#endif /*RFCMAIL*/
X  lprcat("\n   With a certainty a hero I declare to be amongst us!  A nod of");
X  lprcat("\nfavour I send to thee.  Me thinks Count Endelford this day of");
X  lprcat("\nright breath'eth fire as of dragon of whom ye are slayer.  I");
X  lprcat("\nyearn to behold his anger and jealously.  Should ye choose to");
X  lprcat("\nunleash some of thy wealth upon those who be unfortunate, I,");
X  lprcat("\nDuke Mainair, Shall equal thy gift also.\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
Xstatic letter5()
X  {
X# ifdef MAIL
X  sprintf(mail600,"%s%dmail600", MAILTMP,pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 604 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif /*RFCMAIL*/
X# endif
X#ifdef RFCMAIL
X  lprcat("From: StMary (St. Mary's Children's Home)\n");
X  lprcat("Subject: These Poor Children\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  St. Mary's Children's Home\n");
X  standout("\nSubject:"); lprcat("  these poor children\n");
X#endif /*RFCMAIL*/
X  lprcat("\n   News of your great conquests has spread to all of Larndom.");
X  lprcat("\nMight I have a moment of a great man's time.  We here at St.");
X  lprcat("\nMary's Children's Home are very poor, and many children are");
X  lprcat("\nstarving.  Disease is widespread and very often fatal without");
X  lprcat("\ngood food.  Could you possibly find it in your heart to help us");
X  lprcat("\nin our plight?  Whatever you could give will help much.");
X  lprcat("\n(your gift is tax deductible)\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
Xstatic letter6()
X  {
X# ifdef MAIL
X  sprintf(mail600, "%s%dmail600", MAILTMP, pid); /* prepare path */
X  if (lcreat(mail600) < 0) { write(1,"can't write 605 letter\n",23); return(0);}
X#ifndef RFCMAIL
X  lprcat("\n\n\n\n\n\n\n\n\n\n\n\n");
X#endif
X# endif
X#ifdef RFCMAIL
X  lprcat("From: CancerSociety (The National Cancer Society of Larn)\n");
X  lprcat("Subject: Hope\n\n");
X#else /*RFCMAIL*/
X  standout("From:"); lprcat("  The National Cancer Society of Larn\n");
X  standout("\nSubject:"); lprcat("  hope\n");
X#endif /*RFCMAIL*/
X  lprcat("\nCongratulations on your successful expedition.  We are sure much");
X  lprcat("\ncourage and determination were needed on your quest.  There are");
X  lprcat("\nmany though, that could never hope to undertake such a journey");
X  lprcat("\ndue to an enfeebling disease -- cancer.  We at the National");
X  lprcat("\nCancer Society of Larn wish to appeal to your philanthropy in");
X  lprcat("\norder to save many good people -- possibly even yourself a few");
X  lprcat("\nyears from now.  Much work needs to be done in researching this");
X  lprcat("\ndreaded disease, and you can help today.  Could you please see it");
X  lprcat("\nin your heart to give generously?  Your continued good health");
X  lprcat("\ncan be your everlasting reward.\n");
X# ifdef MAIL
X  lwclose();
X# endif
X  return(1);
X  }
X
X
Xstatic int (*pfn[])()= { letter1, letter2, letter3, letter4, letter5, letter6 };
X
X# ifdef MAIL
X/*
X *  function to mail the letters to the player if a winner
X */
Xmailbill()
X    {
X#ifdef VMS
X    register int i;
X    char buf[128];
X    pid = getpid();
X    for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++)
X        if ((*pfn[i])()) {
X            sprintf(buf, "mail %s %s\n", loginname, mail600);
X            oneliner(buf);
X            delete(mail600);
X        }
X    }
X#else
X    register int i;
X    char buf[128];
X    wait(0);  pid=getpid();
X    if (fork() == 0)
X        {
X        resetscroll();
X        for (i=0; i<sizeof(pfn)/sizeof(int (*)()); i++)
X            if ((*pfn[i])())
X                {
X                sleep(20);
X                sprintf(buf,"mail %s < %s",loginname,mail600);
X                system(buf);  unlink(mail600);
X                }
X        exit();
X        }
X    }
X#endif
X# else
X
X/* Page the mail to the terminal    - dgk
X */
Xreadmail(gold)
Xlong    gold;
X{
X    register int i;
X
X    for (i = 0; i < (sizeof pfn) / (sizeof pfn[0]); i++) {
X        resetscroll();
X        clear();
X        (*pfn[i])(gold);    /* a bit dirty 'cause of args */
X        retcont();
X    }
X}
X# endif
END_OF_FILE
if test 8393 -ne `wc -c <'bill.c'`; then
    echo shar: \"'bill.c'\" unpacked with wrong size!
fi
# end of 'bill.c'
fi
if test -f 'larnhlp.txt' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'larnhlp.txt'\"
else
echo shar: Extracting \"'larnhlp.txt'\" \(8427 characters\)
sed "s/^X//" >'larnhlp.txt' <<'END_OF_FILE'
X7    Welcome to the game of Larn.  At this moment, you face a great problem.
XYour daughter has contracted a strange disease, and none of your home remedies
Xseem to have any effect.  You sense that she is in mortal danger, and you must
Xtry to save her.  Time ago you heard of a land of great danger and opportunity.
XPerhaps here is the solution you need.
X
X    It has been said that there once was a great magician who called himself
XPolinneaus.  Many years ago, after having many miraculous successes, Polinneaus
Xretired to the caverns of Larn, where he devoted most of his time to the
Xcreation of magic.   Rumors have it that one day Polinneaus set out to dispel
Xan attacking army in a forest some distance to the north.  It is believed that
Xhere he met his demise.
X
X    The caverns of Larn, it is thought, must be magnificent in design,
Xand contain much magic and treasure.  One option you have is to undertake a
Xjourney into these caverns.
X
X
X    Good Luck!  You're going to need it!
X
X
X
X
X                Help File for The Caverns of Larn, Prompt Mode
X
Xb  move southwest          B  run southwest            S  save the game
Xh  move left               H  run left                 .  stay here
Xj  move down               J  run down                 ^  identify a trap
Xk  move up                 K  run up                   T  take off armor
Xl  move right              L  run right
Xn  move southeast          N  run southeast
Xu  move northeast          U  run northeast
Xy  move northwest          Y  run northwest            ^L redraw the screen
Xc  cast a spell            Z  teleport yourself
Xd  drop an item            e  eat something
Xg  get present pack weight P  give tax status
Xi  inventory your pockets  I  list all items found     ?  this help screen
Xq  quaff a potion          Q  quit the game
Xr  read a scroll           v  print program version
Xw  wield a weapon          W  wear armor               ^L redraw the screen
X
X
X
X
X
X
X                Help File for The Caverns of Larn, Command Mode
X
Xb  move southwest          B  run southwest            A  desecrate an altar
Xc  cast a spell            C  close a door             Z  teleport yourself
Xd  drop an item            D  drink at a fountain      <  go up stairs or
Xe  eat something           E  enter a store, dungeon      volcanic shaft
Xg  get present pack weight                             >  go down stairs or
Xh  move left               H  run left                    volcanic shaft
Xi  inventory your pockets  I  list all items found     ?  this help screen
Xj  move down               J  run down                 ^  identify a trap
Xk  move up                 K  run up                   ,  pick up item
Xl  move right              L  run right                :  look at object you
Xn  move southeast          N  run southeast               are standing on
X                           O  open a door or chest     .  stay here
Xp  pray at an altar        P  give tax status          m  move without picking
Xq  quaff a potion          Q  quit the game               up an object
Xr  read a scroll           R  remove gems from throne  @  toggle auto-pickup
Xs  sit on a throne         S  save the game            /  identify objects in
Xt  tidy up at a fountain   T  take off armor              the game
Xu  move northeast          U  run northeast
Xv  print program version
Xw  wield a weapon          W  wear armor
Xy  move northwest          Y  run northwest            ^L redraw the screen
X                Special Notes
X
XWhen dropping gold, if you type '*' as your amount, all your gold gets dropped.
XIn general, typing in '*' means all of what your interested in.  This is true
Xwhen visiting the bank, or when contributing at altars.
X
XLarn needs the ANSI.SYS (or preferably, the NANSI.SYS) device driver installed
Xin your CONFIG.SYS file.  The supplied "termcap" file describes the escape
Xsequences to change video modes (see ch 13 of the DOS 2.0 manual).  See the
X"TERMCAP" section in LARN.DOC for further details.
X
XWhen in the store, trading post, school, or home, an <escape> will get you out.
X
XWhen casting a spell, if you need a list of spells you can cast, type 'I' as
Xthe first letter of your spell.  The available list of spells will be shown,
Xafter which you may enter the spell code.  This only works on the 1st letter
Xof the spell you are casting.
X
XWhen an inventory list is on the screen from a drop, quaff, read, or similar
Xcommand, you can type the letter of the object that you wish to act apon,
Xwithout having to type a space to get back to the prompt.
X
XThis version of Larn is by Kevin Routley.
X                        Larn Command Line Options
X
Xlarn ++                 restore checkpointed game
Xlarn -s                 list the scoreboard
Xlarn -i                 list scores with inventories
Xlarn -n                 suppress welcome message when beginning a game
Xlarn -h                 print out all the command line options
Xlarn -?                 print out all the command line options
Xlarn -<number>          specify difficulty of the game
Xlarn -o<optsfile>       specify the option file to be used
Xlarn -c                 create new scoreboards -- prompts for a password
Xlarn -l                 print out the larn log file
Xlarn -p                 play in prompt mode
X
X
X
X
X
X
X
X
X
X
X            Background Information for Larn
X
X    Welcome to the game of Larn.  At this moment, you face a great problem.
XYour daughter has contracted a strange disease, and none of your home remedies
Xseem to have any effect.  You sense that she is in mortal danger, and you must
Xtry to save her.  Time ago you heard of a land of great danger and opportunity.
XPerhaps here is the solution you need.
X
X    It has been said that there once was a great magician who called himself
XPolinneaus.  Many years ago, after having many miraculous successes, Polinneaus
Xretired to the caverns of Larn, where he devoted most of his time to the
Xcreation of magic.   Rumors have it that one day Polinneaus set out to dispel
Xan attacking army in a forest some distance to the north.  It is believed that
Xhere he met his demise.
X
X    The caverns of Larn, it is thought, must be magnificent in design,
Xand contain much magic and treasure.  One option you have is to undertake a
Xjourney into these caverns.
X
X    Good Luck!  You're going to need it!
X
X
X
X            How to use the larn.opt option file
X
XThe file "larn.opt", if used, should be in a directory along your PATH.
XA sequence of words terminated by whitespace is used to specify options.
X
X    Word                      Meaning
X    cursor: lowscan highscan  change the shape of the cursor
X    DECRainbow                tell LARN you have that computer
X    enable-checkpointing      turn on periodic checkpointing
X    graphics: wallc floorc    select graphics maze characters
X    keypad                    enable the numeric keypad for moving
X    larndir:  directory       the directory to use for larn files
X    monster:  "monst name"    choose a name for a monster
X    name:     "your name"     choose your playing name
X    no-beep                   disable beeping of the terminal
X    no-introduction           do not display intro message
X    savefile: save-file-name  define what the savegame filename will be
X    swapfile: swap-file-name  define the name of the swapfile
X
XYour name and monster names must be enclosed in double quotation marks and may
Xbe up to 34 characters long.  Longer names are truncated.  Anything enclosed in
Xquotation marks is considered one word, and must be separated from other words
Xby whitespace.
X           Explanation of the Larn scoreboard facility
X
X    Larn supports TWO scoreboards, one for winners, and one for deceased
Xcharacters.  Each player (by userid or playerid, see UIDSCORE in Makefile)
Xis allowed one slot on each scoreboard, if the score is in the top ten for
Xthat scoreboard.  This design helps insure that frequent players of Larn
Xdo not hog the scoreboard, and gives more players a chance for glory.  Level
Xof difficulty is also noted on the scoreboards, and this takes precedence
Xover score for determining what entry is on the scoreboard.  For example:
Xif "Yar, the Bug Slayer" has a score of 128003 on the scoreboard at diff 0,
Xthen a game at diff 1 and a score of 4112 would replace the previous
Xentry on the scoreboard.  Note that when a player dies, the inventory is
Xstored in the scoreboard so that everyone can see what items the player had
Xat the time of death.
X
X
X
X
X
X
X
X
X
X.
END_OF_FILE
if test 8427 -ne `wc -c <'larnhlp.txt'`; then
    echo shar: \"'larnhlp.txt'\" unpacked with wrong size!
fi
# end of 'larnhlp.txt'
fi
if test -f 'msdos.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'msdos.c'\"
else
echo shar: Extracting \"'msdos.c'\" \(11570 characters\)
sed "s/^X//" >'msdos.c' <<'END_OF_FILE'
X#ifdef MSDOS
X# include <stdio.h>
X# include <process.h>
X# include <dos.h>
X# include <fcntl.h>
X# include <sys/types.h>
X# include <sys/stat.h>
X# include "header.h"
X# include "larndefs.h"
X
X# define DEVICE     0x80
X# define RAW        0x20
X# define IOCTL      0x44
X# define STDIN      0
X# define STDOUT     1
X# define GETBITS    0
X# define SETBITS    1
X# define PATHSEP    ';'
X
X/* Normal characters are output when the shift key is not pushed.
X * Shift characters are output when either shift key is pushed.
X */
X#  define KEYPADHI  83
X#  define KEYPADLOW 71
X#  define iskeypad(x)   (KEYPADLOW <= (x) && (x) <= KEYPADHI)
Xstatic struct {
X    char normal, shift;
X    } pad[KEYPADHI - KEYPADLOW + 1] = {
X            {'y', 'Y'},     /* 7 */
X            {'k', 'K'},     /* 8 */
X            {'u', 'U'},     /* 9 */
X            {' ', ' '},     /* - */
X            {'h', 'H'},     /* 4 */
X            {' ', ' '},     /* 5 */
X            {'l', 'L'},     /* 6 */
X            {' ', ' '},     /* + */
X            {'b', 'B'},     /* 1 */
X            {'j', 'J'},     /* 2 */
X            {'n', 'N'},     /* 3 */
X            {'i', 'i'},     /* Ins */
X            {'.', '.'}      /* Del */
X};
X
X/* BIOSgetch gets keys directly with a BIOS call.
X */
X#ifdef    OS2LARN
X# define SHIFT       (RIGHTSHIFT | LEFTSHIFT)
X#else
X# define SHIFT       (0x1 | 0x2)
X#endif
X#  define KEYBRD_BIOS   0x16
X
Xstatic char
XBIOSgetch() {
X    unsigned char scan, shift, ch;
X    union REGS regs;
X
X#ifdef    OS2LARN
X    KBDKEYINFO  kbd;
X
X    KbdCharIn(&kbd,IO_WAIT,(HKBD) 0);
X    ch    = kbd.chChar;
X    scan  = kbd.chScan;
X    shift = kbd.fsState;
X#else
X    /* Get scan code.
X    */
X    regs.h.ah = 0;
X    int86(KEYBRD_BIOS, &regs, &regs);
X    ch = regs.h.al;
X    scan = regs.h.ah;
X
X    /* Get shift status.
X     */
X    regs.h.ah = 2;
X    int86(KEYBRD_BIOS, &regs, &regs);
X    shift = regs.h.al;
X#endif
X
X    /* If scan code is for the keypad, translate it.
X     */
X    if (iskeypad(scan)) {
X        if (shift & SHIFT)
X            ch = pad[scan - KEYPADLOW].shift;
X        else
X            ch = pad[scan - KEYPADLOW].normal;
X    }
X    return ch;
X}
X
Xkgetch()
X{
X    /* BIOSgetch can use the numeric key pad on IBM compatibles. */
X    if (keypad)
X        return BIOSgetch();
X    else
X        return getch();
X}
X
Xdoshell()
X{
X    char *comspec = getenv("COMSPEC");
X
X    clear();
X    lflush();
X    if (comspec == NULL
X    || (spawnl(P_WAIT, comspec, comspec, NULL) < 0)) {
X        write(2, "A> ", 3);
X        while (getche() != '\r')
X            ;
X    }
X}
X
Xstatic  unsigned    old_stdin, old_stdout, ioctl();
X
Xstatic unsigned
Xioctl(handle, mode, setvalue)
Xunsigned setvalue;
X{
X#ifndef OS2LARN
X    union REGS regs;
X
X    regs.h.ah = IOCTL;
X    regs.h.al = mode;
X    regs.x.bx = handle;
X    regs.h.dl = setvalue;
X    regs.h.dh = 0;          /* Zero out dh */
X    intdos(&regs, &regs);
X    return (regs.x.dx);
X#endif
X}
X
Xint rawio;
Xvoid
Xsetraw()
X{
X    if (!rawio)
X        return;
X    old_stdin = ioctl(STDIN, GETBITS, 0);
X    old_stdout = ioctl(STDOUT, GETBITS, 0);
X    if (old_stdin & DEVICE)
X        (void) ioctl(STDIN, SETBITS, old_stdin | RAW);
X    if (old_stdout & DEVICE)
X        (void) ioctl(STDOUT, SETBITS, old_stdout | RAW);
X}
X
Xvoid
Xunsetraw()
X{
X    if (!rawio)
X        return;
X    if (old_stdin)
X        (void) ioctl(STDIN, SETBITS, old_stdin);
X    if (old_stdout)
X        (void) ioctl(STDOUT, SETBITS, old_stdout);
X}
X
X
X/* Add a backslash to any name not ending in /, \ or :   There must
X * be room for the \
X */
Xvoid
Xappend_slash(name)
Xchar *name;
X{
X    char *ptr;
X
X    if (!*name)
X        return;
X    ptr = name + (strlen(name) - 1);
X    if (*ptr != '\\' && *ptr != '/' && *ptr != ':') {
X        *++ptr = '\\';
X        *++ptr = '\0';
X    }
X}
X
X/* Lopen a file somewhere along the PATH
X */
Xplopen(name)
Xchar    *name;
X{
X    char    buf[PATHLEN], *bp, *pp, lastch, *strchr();
X    int fd;
X
X    /* Try the default directory first.  Then look along PATH unless
X     * the name has path components.
X     */
X    if ((fd = lopen(name)) >= 0)
X        return fd;
X    else if (strpbrk(name, "\\/:") == NULL) {
X        pp = getenv("PATH");
X        while (pp && *pp) {
X            bp = buf;
X            while (*pp && *pp != PATHSEP)
X                lastch = *bp++ = *pp++;
X            if (strchr("\\/:", lastch) == NULL)
X                *bp++ = '\\';
X            strcpy(bp, name);
X            if ((fd = lopen(buf)) >= 0)
X                return fd;
X            if (*pp)
X                pp++;
X        }
X    }
X    return -1;
X}
X
X
X/* Follow the PATH, trying to fopen the file.  Takes one additional
X * argument which can be NULL.  Otherwise this argument gets filled
X * in the full path to the file.  Returns as does fopen().
X */
XFILE *
Xfopenp(name, mode, pathname)
Xchar *name, *mode, *pathname;
X{
X    char buffer[BUFSIZ], *buf, *bufp, *pathp, *getenv(), lastch;
X    FILE *fp;
X
X    /* If pathname is given, use it instead of buf so the calling
X     * process knows the path we found name under
X     */
X    if (pathname)
X        buf = pathname;
X    else
X        buf = buffer;
X
X    /* Try the default directory first.  If the file can't be opened,
X     * start looking along the path.
X     */
X    strcpy(buf, name);
X    if (fp = fopen(buf, mode))
X        return fp;
X    else if (strpbrk(name, "\\/:") == NULL) {
X        pathp = getenv("PATH");
X        while (pathp && *pathp) {
X            bufp = buf;
X            while (*pathp && *pathp != PATHSEP)
X                lastch = *bufp++ = *pathp++;
X            if (lastch != '\\' && lastch != '/')
X                *bufp++ = '\\';
X            strcpy(bufp, name);
X            if (fp = fopen(buf, mode))
X                return fp;
X            if (*pathp)
X                pathp++;
X        }
X    }
X    return NULL;
X}
X
X/* Diagnositic information about the disposition of levels between ram
X * and disk.
X */
Xlevelinfo()
X{
X    DISKBLOCK   *dp;
X    RAMBLOCK    *rp;
X
X    cursors();
X    lflush();
X    fprintf(stderr, "\nRAM:\n");
X    for (rp = ramblks; rp; rp = rp->next)
X        fprintf(stderr, "%4d  gt:%6ld\n", rp->level, rp->gtime);
X    fprintf(stderr, "\nDISK:\n");
X    for (dp = diskblks; dp; dp = dp->next)
X        fprintf(stderr, "%4d  gt:%6ld  fpos:%ld\n",
X        dp->level, dp->gtime, dp->fpos);
X    nomove=1;
X    return (yrepcount = 0);
X}
X
Xint swapfd = 0; /* file descriptor for the swap file */
Xint ramlevels = MAXLEVEL + MAXVLEVEL;   /* the maximum */
X
X
X/* Allocate as many levels as possible, then check that the swap file
X * will have enough storage for the overflow.  You must be able to allocate
X * at least one level or there will be nowhere to swap to/from.  If a swap
X * file is opened it remains open for the whole game.
X */
Xallocate_memory()
X{
X    register int    i;
X    DISKBLOCK   *dp, *dp2;
X    RAMBLOCK    *rp;
X
X    /* First allocate the maximum number of disk blocks, some of which
X     * may not be used, but must do the allocation now since we don't
X     * yet know how many levels will be allocatable.
X     */
X    for (i = 0; i < MAXLEVEL + MAXVLEVEL; i++) {
X        if ((dp = (DISKBLOCK *) malloc(sizeof(DISKBLOCK))) == NULL)
X            died(-285);
X        dp->next = diskblks;
X        diskblks = dp;
X    }
X    dp = diskblks;      /* Move this along in the next loop */
X
X    /* Now allocate ram storage, up to ramlevels in count.
X     */
X    for (i = 0; i < MAXLEVEL + MAXVLEVEL; i++) {
X        if (i < ramlevels)
X            rp = (RAMBLOCK *) malloc(sizeof(RAMBLOCK));
X        else
X            rp = NULL;
X        if (rp == NULL) {
X            if (i == 0)
X                died(-285); /* have to have at least one */
X
X            /* Open the swap file if not yet done so
X             */
X            if (swapfd == 0) {
X                swapfd = open(swapfile,
X                    O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
X                    S_IWRITE | S_IREAD);
X                if (swapfd < 0)
X                    error("Can't open swapfile `%s'\n",
X                    swapfile);
X
X                /* First block is FREE and will be used to
X                 * swap out the first level.  When another
X                 * level gets swapped in, its block will be
X                 * FREE.
X                 */
X                if (dp == NULL)
X                    error("NULL1 disk pointer?\n");
X                dp->level = FREEBLOCK;
X                dp->fpos = 0;
X                dp->gtime = 0;
X                lseek(swapfd, (long) sizeof rp->cell, 0);
X            }
X
X            /* And try to seek the size of this level
X             */
X            dp = dp->next;
X            if (dp == NULL)
X                error("NULL2 disk pointer?\n");
X            dp->level = FREEBLOCK;
X            dp->gtime = 0;
X            dp->fpos = tell(swapfd);
X            if (lseek(swapfd, (long) sizeof rp->cell, 1) < 0L)
X                error("Not enough disk space for swapfile `%s'\n",
X                swapfile);
X        } else {
X            rp->next = ramblks;
X            ramblks = rp;
X            rp->level = FREEBLOCK;
X            rp->gtime = 0;
X        }
X    }
X
X    /* dp now points to the last diskblock used.  Truncate the diskblock
X     * list here and free up the other blocks (for what it's worth ...)
X     */
X    dp2 = dp->next;
X    dp->next = NULL;
X    dp = dp2;
X    while (dp) {
X        dp2 = dp->next;
X        free((char *) dp);
X        dp = dp2;
X    }
X}
X
X
X/* VARARGS1 */
Xwarn(format, a1, a2, a3)
Xchar *format;
Xlong a1, a2, a3;
X{
X    fprintf(stderr, format, a1, a2, a3);
X}
X
X/* VARARGS1 */
Xerror(format, a1, a2, a3, a4)
Xchar *format;
Xlong a1, a2, a3, a4;
X{
X    unsetraw();
X    resetcursor();
X    fputc('\n', stderr);
X    fprintf(stderr, format, a1, a2, a3, a4);
X    sleep(5);
X    exit(1);
X}
X
Xstatic unsigned char ocursorstart, ocursorend;
Xunsigned char cursorstart, cursorend;
Xint cursorset;
X
X/* Save the old value of the cursor then put in the new value.
X */
X# define READCURSORPOS  0x03
X# define SETCURSORTYPE  0x01
X# define BIOSVIDEO  0x10
Xsetcursor()
X{
X#ifdef OS2LARN
X  USHORT  rc;
X  VIOCURSORINFO   curinfo;
X
X  if (cursorset == 0)
X      return;
X
X  /* Save the cursor type in 'ocursorstart' and 'ocursorend'. 
X  */
X  rc = VioGetCurType((PVIOCURSORINFO) &curinfo, (HVIO) NULL);
X  if (rc != 0)
X  {
X      /* errors don't happen. */
X  }
X  ocursorstart = curinfo.yStart;
X  ocursorend   = curinfo.cEnd;
X
X  /* set the cursor type according to global variables
X     'cursorstart' and 'cursorend'.
X  */
X  curinfo.cEnd   = cursorend;
X  curinfo.yStart = cursorstart;
X  curinfo.cx     = 0; /* default width, 1 char */
X  curinfo.attr   = 0; /* 'Normal' attribute */
X
X  rc = VioSetCurType((PVIOCURSORINFO) &curinfo, (HVIO) NULL);
X  if (rc != 0)
X  {
X      /* errors don't happen. */
X  }
X
X#else
X    union   REGS    regs;
X
X    if (cursorset == 0)
X        return;
X
X    regs.h.ah = READCURSORPOS;
X    regs.h.bh = 0;
X    int86(BIOSVIDEO, &regs, &regs);
X    ocursorstart = regs.h.ch;
X    ocursorend = regs.h.cl;
X
X    regs.h.ah = SETCURSORTYPE;
X    regs.h.bh = 0;
X    regs.h.ch = cursorstart;
X#if 0
X    regs.h.ch = 0x20 ;
X#endif
X    regs.h.cl = cursorend;
X    int86(BIOSVIDEO, &regs, &regs);
X#endif
X}
X
X/* Restore the old cursor upon exit
X */
Xresetcursor()
X{
X#ifdef OS2LARN
X  VIOCURSORINFO   curinfo;
X
X  if (cursorset == 0)
X      return;
X
X  curinfo.cEnd   = ocursorend;
X  curinfo.yStart = ocursorstart;
X  curinfo.cx     = 0; /* default width, 1 char */
X  curinfo.attr   = 0; /* 'Normal' attribute */
X
X  VioSetCurType((PVIOCURSORINFO) &curinfo, (HVIO) NULL);
X#else
X    union   REGS    regs;
X
X    if (cursorset == 0)
X        return;
X    regs.h.ah = SETCURSORTYPE;
X    regs.h.bh = 0;
X    regs.h.ch = ocursorstart;
X    regs.h.cl = ocursorend;
X    int86(BIOSVIDEO, &regs, &regs);
X#endif
X}
X# endif /* MSDOS */
END_OF_FILE
if test 11570 -ne `wc -c <'msdos.c'`; then
    echo shar: \"'msdos.c'\" unpacked with wrong size!
fi
# end of 'msdos.c'
fi
if test -f 'tgetent.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tgetent.c'\"
else
echo shar: Extracting \"'tgetent.c'\" \(10470 characters\)
sed "s/^X//" >'tgetent.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 *  LIBRARY FUNCTION
X *
X *  tgetent   load buffer with entry for specified terminal
X *
X *  KEY WORDS
X *
X *  termcap functions
X *  utility routines
X *
X *  SYNOPSIS
X *
X *  int tgetent(bp,name)
X *  char *bp;
X *  char *name;
X *
X *  DESCRIPTION
X *
X *  Extracts the entry for terminal <name> from the termcap file
X *  and places it in the character buffer <bp>.   It is currently
X *  assumed that bp is at least 1024 characters.  If the entry in
X *  the termcap file is larger than 1023 characters the excess
X *  characters will be discarded and appropriate status will
X *  be returned.
X *
X *  Also note that since bp is used by other termcap
X *  routines, the storage associated with the termcap entry
X *  cannot be freed until all termcap calls are completed.
X *
X *  Tgetent can be directed to look in a file other than
X *  the default (/etc/termcap) by defining an environment
X *  variable called TERMCAP to be the pathname of the desired
X *  termcap file.  This is useful for debugging new entries.
X#ifndef VMS
X *  NOTE: the pathname MUST begin with a '/' character.
X *
X *  Also, if the string assigned to TERMCAP does not begin with
X *  a '/' and if the environment variable TERM matches <name> then
X *  the string assigned to TERMCAP is copied to buffer <bp> 
X *  instead of reading a termcap file.
X#endif
X *  
X *  If the termcap entry contains a "tc" string then the termcap
X *  entry named in the string is appended to the buffer (minus the
X *  names).
X *
X *  RETURNS
X *
X *  -1  if the termcap file cannot be opened
X *   0  if no entry in termcap file matches <name>
X *   1  if extraction is successful with no errors
X *   2  if extraction is successful but entry truncated
X *
X *  SEE ALSO
X *
X *  tgetnum   extract numeric type capability
X *  tgetflag  test boolean type capability
X *  tgetstr   get string value of capability
X *
X *  AUTHOR
X *
X *  Fred Fish
X *
X */
X
X#include <stdio.h>
X
X#define TRUE 1
X#define FALSE 0
X#define BUFSIZE 1024            /* Assumed size of external buffer */
X
X#define NO_FILE  -1         /* Returned if can't open file */
X#define NO_ENTRY  0         /* Returned if can't find entry */
X#define SUCCESS   1         /* Returned if entry found ok */
X#define TRUNCATED 2         /* Returned if entry found but trunc */
X
X#ifdef MSDOS
XFILE *fopenp();
X#endif
X
X#define DEFAULT_ROOT "termcap"      /* name without path component */
X#ifdef VMS
X#define DEFAULT_FILE "sys$library:termcap"
X#else
X#define DEFAULT_FILE "/etc/termcap" /* default termcap filename */
X#endif VMS
X
Xchar *_tcpbuf;              /* Place to remember buffer pointer */
X
X/*
X *  PSEUDO CODE
X *
X *  Begin tgetent
X *      Erase any previous buffer contents.
X *      Remember the buffer pointer.
X *      If termcap file is not found then
X *      If buffer was filled anyway then
X *          Return SUCCESS.
X *      Else
X *          Return NO_FILE.
X *      End if
X *      Else
X *      While records left to process
X *          If this is entry is what we want then
X *          Close the termcap file.
X *          If entry was truncated then
X *              Return TRUNCATED status
X *          Else
X *              Return SUCCESS status.
X *          End if
X *          End if
X *      End while
X *      Return NO_ENTRY status.
X *      End if
X *  End tgetent
X *          
X */
X
Xint tgetent(bp,name)
Xchar *bp;               /* Pointer to buffer (1024 char min) */
Xchar *name;             /* Pointer to terminal entry to find */
X{
X    FILE *fp, *find_file();
X    char *nbp, tc[80];
X
X    *bp = (char)NULL;
X    _tcpbuf = bp;
X    if ((fp = find_file(bp)) == NULL) {
X    if (*bp != NULL) {
X        return(SUCCESS);
X    } else {
X        return(NO_FILE);
X    }
X    } else {
X    while (fgetlr(bp,BUFSIZE,fp)) {
X        if (gotcha(bp,name)) {
X        fclose(fp);
X        nbp = &bp[strlen(bp)-1];
X        if (*nbp != '\n') {
X            return(TRUNCATED);
X        } else {
X            /* check for a recursive call (i.e. :tc=vt100:)
X             * added 18-dec-86 RDE (single recursion...)
X             */
X            char *area;
X            area = &tc[0];
X            if (tgetstr("tc", &area) == NULL)       
X            return(SUCCESS);
X            else {
X            fp = find_file(0);  /* know it works and is file */
X            while (fgetlr(nbp, BUFSIZE-(nbp-bp), fp)) {
X                if (gotcha(nbp,tc)) {
X                char *cp1, *cp2;    /* scrunch out names */
X                fclose(fp);
X                cp1 = nbp;
X                while (*cp1++ != ':')   /* search for first  */
X                    ;
X                cp2 = nbp;
X                while (*cp2++ = *cp1++) /* move the chars.   */
X                    ;
X                if (bp[strlen(bp)-1] != '\n') {
X                    return(TRUNCATED);
X                } else {
X                    return(SUCCESS);
X                }
X                }
X            }
X            return (NO_ENTRY);
X            }
X        }
X        }
X    }
X    return(NO_ENTRY);
X    }
X}
X
X/*
X *  INTERNAL FUNCTION
X *
X *  find_file    find the termcap file and open it if possible
X *
X *  KEY WORDS
X *
X *  internal functions
X *  find_file
X *
X *  SYNOPSIS
X *
X *  static FILE *find_file(bp)
X *  char *bp;
X *
X *  DESCRIPTION
X *
X *  Attempts to locate and open the termcap file.  Also handles
X *  using the environment TERMCAP string as the actual buffer
X *  (that's why bp has to be an input parameter).
X *
X#ifdef VMS
X *  If TERMCAP is defined as a valid filespec then it will be
X *  opened.  If this fails then the default termcap file will
X *  be used.
X#else
X *  If TERMCAP is defined an begins with a '/' character then
X *  it is taken to be the pathname of the termcap file and
X *  an attempt is made to open it.  If this fails then
X *  the default termcap file is used instead.
X *
X *  If TERMCAP is defined but does not begin with a '/' then
X *  it is assumed to be the actual buffer contents provided
X *  that <name> matches the environment variable TERM.
X#endif
X *
X *  BUGS
X *
X *  There is currently no way to be sure which termcap
X *  file was opened since the default will always be
X *  tried.
X *
X */
X
X/*
X *  PSEUDO CODE
X *
X *  Begin find_file
X *      If there is a TERMCAP environment string then
X *      If the string is not null then
X *          If the string is a pathname then
X *          If that file is opened successfully then
X *              Return its pointer.
X *          End if
X *          Else
X *          If there is a TERM environment string then
X *              If TERM matches <name> then
X *              Copy TERMCAP string to buffer.
X *              Return NULL for no file.
X *              End if
X *          End if
X *          End if
X *      End if
X *      End if
X *      Open default termcap file and return results.
X *  End find_file
X *
X */
X
Xstatic FILE *find_file(bp)
Xchar *bp;
X{
X    FILE *fp, *fopen();
X    char *cp, *ncp, *getenv();
X
X    if ((cp = getenv("TERMCAP")) != NULL) {
X    if (*cp != NULL) {
X#ifdef VMS
X        if ((fp = fopen(cp, "r")) != NULL)
X        return(fp);
X#else
X        if (*cp == '/' || *cp == '\\') {
X        if ((fp = fopen(cp,"r")) != NULL) {
X            return(fp);
X        }
X        } else {
X        if ((ncp = getenv("TERM")) != NULL) {
X            if (strcmp(cp,ncp) == 0) {
X            strcpy(bp,cp);
X            return((FILE *)NULL);
X            }
X        }
X        }
X#endif
X    }
X    }
X    /*
X     * Try current directory, then /etc/termcap
X     */
X    if (fp = fopen(DEFAULT_ROOT, "r"))
X        return fp;
X    else
X#ifdef MSDOS
X    if (fp = fopen(DEFAULT_FILE, "r") )
X            return fp;
X        else    /* try along the PATH */
X        return( fopenp(DEFAULT_ROOT, "r", NULL));
X#else
X        return (fopen(DEFAULT_FILE, "r"));
X#endif
X}
X
X
X/*
X *  INTERNAL FUNCTION
X *
X *  gotcha   test to see if entry is for specified terminal
X *
X *  SYNOPSIS
X *
X *  gotcha(bp,name)
X *  char *bp;
X *  char *name;
X *
X *  DESCRIPTION
X *
X *  Tests to see if the entry in buffer bp matches the terminal
X *  specified by name.  Returns TRUE if match is detected, FALSE
X *  otherwise.
X *
X */
X
X/*
X *  PSEUDO CODE
X *
X *  Begin gotcha
X *      If buffer character is comment character then
X *      Return FALSE since remainder is comment
X *      Else
X *      Initialize name scan pointer.
X *      Compare name and buffer until end or mismatch.
X *      If valid terminators for both name and buffer strings
X *          Return TRUE since a match was found.
X *      Else
X *          Find next non-name character in buffer.
X *          If not an alternate name separater character
X *          Return FALSE since no more names to check.
X *          Else
X *          Test next name and return results.
X *          End if
X *      End if
X *      End if
X *  End gotcha
X *
X */
X
Xgotcha(bp,name)
Xchar *bp;
Xchar *name;
X{
X    char *np;
X 
X    if (*bp == '#') {
X    return(FALSE);
X    } else {
X    np = name;
X    while (*np == *bp && *np != NULL) {np++; bp++;}
X    if (*np == NULL && (*bp == NULL || *bp == '|' || *bp == ':')) {
X        return(TRUE);
X    } else {
X        while (*bp != NULL && *bp != ':' && *bp != '|') {bp++;}
X        if (*bp != '|') {
X        return(FALSE);
X        } else {
X        return(gotcha(++bp,name));
X        }
X    }
X    }
X}
X
X#ifdef MSDOS
X/*
X * index(buffer, char)
X * Find character in buffer.  Return the pointer
X * to it. Shouldn't be necessary to write this
X * myself but VMS didn't.  Oh Well...
X * Used by lots of files in the termcap library.
X * Rich Ellison, 16-DEC-1986
X */
Xchar
X*index(buf, ch)
Xchar    *buf;
Xchar    ch;
X{
X    register int    c;
X    while ((c= *buf++) != '\0')
X        if (c == ch)
X            return (buf-1);
X    return (NULL);
X}
X#endif
END_OF_FILE
if test 10470 -ne `wc -c <'tgetent.c'`; then
    echo shar: \"'tgetent.c'\" unpacked with wrong size!
fi
# end of 'tgetent.c'
fi
echo shar: End of archive 4 \(of 17\).
cp /dev/null ark4isdone
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.
