-+-+-+-+-+-+-+-+ START OF PART 46 -+-+-+-+-+-+-+-+
X#endif TIMECHECK
X
X            `7D
X
X# ifndef MSDOS
X# ifdef VMS
X        /* If keyboard input buffer is too big then flush some? RDE */
X        /* Check this! but for now just ignore it... */
X# else
X#  ifndef SYSV
X        do /* if keyboard input buffer is too big, flush some of it */
X            `7B
X            ioctl(0,FIONREAD,&ic);
X            if (ic>flushno)   read(0,&cc,1);
X            `7D
X        while (ic>flushno);
X#  endif SYSV
X# endif VMS
X# endif MSDOS
X
X# ifdef MSDOS
X        cc = ttgetch();
X# else MSDOS
X# ifdef VMS
X        cc = ttgetch();
X# else
X        if (read(0,&cc,1) != 1)
X            return(lastok = -1);
X# endif VMS
X# endif MSDOS
X        if (cc == '!')      /* ! shell escape */
X            `7B
X            resetscroll();  /* scrolling region, home, clear, no attributes
V */
X            clear();
X# ifdef MSDOS
X            doshell();
X# else MSDOS
X# ifdef VMS
X            lflush();
X            sncbr();
X            oneliner("");
X            scbr();
X# else VMS
X            lflush();
X            sncbr();
X            if ((ic=fork())==0) /* child */
X                `7B
X#ifdef SYSV
X                char *s, *getenv();
X                if ((s=getenv("SHELL")) == (char *) 0)
X                    s = "/bin/sh";
X                execl(s,"larn-shell", (char *)0);
X                exit();
X#else
X                execl("/bin/csh",0);
X                exit();
X                wait(0);
X#endif
X                `7D
X            if (ic<0) /* error */
X                `7B
X                write(2,"Can't fork off a shell!\n",25);
X                sleep(2);
X                `7D
X#ifdef SYSV
X            else
X                wait( (int *)0 );
X#endif SYSV
X# endif VMS
X# endif MSDOS
X            setscroll();
X            return(lastok = 'L'-64);    /* redisplay screen */
X            `7D
X
X        /* get repeat count, showing to player
X        */
X/*        if ((cc <= '9') && (cc >= '0'))*/
X         if (0)
X            `7B
X            yrepcount = yrepcount*10 + cc - '0';
X
X            /* show count to player for feedback
X            */
X            if ( yrepcount >= 10 )
X                `7B
X                cursors();
X                if (firsttime)
X                    lprcat("\n");
X                lprintf("count: %d", (long)yrepcount );
X                firsttime=FALSE;
X                lflush();  /* show count */
X                `7D
X            `7D
X        else
X            `7B
X            /* check for multi-character commands in command mode, and handl
Ve.
X            */
X            if ( cc == 'm' && !prompt_mode )
X                `7B
X                move_no_pickup = TRUE ;
X                cc = ttgetch();
X                `7D
X            if ( yrepcount > 0 )
X                --yrepcount;
X            return(lastok = cc);
X            `7D
X        `7D
X    `7D
X
X/*
X *  flushall()  Function to flush all type-ahead in the input buffer
X */
Xlflushall()
X    `7B
X# ifdef MSDOS
X    while (kbhit())
X        getch();
X# else MSDOS
X# ifdef VMS
X    /* Flush all type-ahead -- RDE */
X    extern int  iochan;     /* defined in IO.C  */
X    int     c;
X
X    SYS$QIOW(0,iochan,IO$_READLBLK`7CIO$M_TIMED`7CIO$M_PURGE,0,0,0,&c,1,0,0,
V0,0);
X
X# else VMS
X#ifdef SYSV
X    ioctl(0,TCFLSH,0);
X#else
X    char cc;
X    int ic;
X    for (;;) `7B      /* if keyboard input buffer is too big, flush some of
V it */
X        ioctl(0,FIONREAD,&ic);
X        if (ic<=0)
X            return;
X        while (ic>0) `7B
X            read(0,&cc,1);
X            --ic;
X        `7D /* gobble up the byte */
X    `7D
X# endif SYSV
X# endif VMS
X# endif MSDOS
X`7D
X
X/*
X    function to set the desired hardness
X    enter with hard= -1 for default hardness, else any desired hardness
X */
Xsethard(hard)
Xint hard;
X`7B
X    register int    j,k;
X    long        i;
X    struct monst    *mp;
X
X    j=c`5BHARDGAME`5D; hashewon();
X    if (restorflag==0)  /* don't set c`5BHARDGAME`5D if restoring game */
X        `7B
X        if (hard >= 0) c`5BHARDGAME`5D= hard;
X        `7D
X    else c`5BHARDGAME`5D=j; /* set c`5BHARDGAME`5D to proper value if restor
Ving game */
X
X    if (k=c`5BHARDGAME`5D)
X      for (j=0; j<=MAXMONST+8; j++) `7B
X        mp = &monster`5Bj`5D;
X        i = ((6+k) * mp->hitpoints + 1)/6;
X        mp->hitpoints = (i<0) ? 32767 : i;
X        i = ((6+k) * mp->damage + 1) / 5;
X        mp->damage = (i>127) ? 127 : i;
X        i = (10 * mp->gold)/(10+k);
X        mp->gold = (i>32767) ? 32767 : i;
X        i = mp->armorclass - k;
X        mp->armorclass = (i< -127) ? -127 : i;
X        i = (7*mp->experience)/(7+k) + 1;
X        mp->experience = (i<=0) ? 1 : i;
X    `7D
X`7D
X
X
X/*
X    function to read and process the larn options file
X*/
Xreadopts()
X    `7B
X    register int j;
X    char original_objects = FALSE ;
X    char namenotchanged = TRUE;     /* set to 0 if a name is specified */
X
X# ifdef MSDOS
X    if (plopen(optsfile) < 0)
X# else
X    if (lopen(optsfile) < 0)
X# endif
X        `7B
X        lprintf("Can't open options file \"%s\"\n", optsfile);
X        lflush();
X        sleep(1);
X        `7D
X    else
X        actual_readopts(&namenotchanged, &original_objects);
X
X    if (namenotchanged)
X        strcpy(logname,loginname);
X
X    /* original objects require object highlighting to be ON (in order
X       to distinguish between objects and monsters).  set up object list
X       properly.
X    */
X    if (original_objects)
X        `7B
X        boldobjects = TRUE ;
X        strncpy( objnamelist, original_objnamelist, MAXOBJECT );
X        `7D
X    else
X        strncpy( objnamelist, hacklike_objnamelist, MAXOBJECT );
X    objnamelist`5BMAXOBJECT`5D = '\0' ;
X
X    /* now set all the invisible objects and monsters to have the
X       same appearance as the floor (as defined by the user)
X    */
X    objnamelist`5BOWALL`5D = wallc;
X
X    objnamelist`5B0`5D        =
X    objnamelist`5BOIVTELETRAP`5D  =
X    objnamelist`5BOTRAPARROWIV`5D =
X    objnamelist`5BOIVDARTRAP`5D   =
X    objnamelist`5BOIVTRAPDOOR`5D  = floorc;
X    monstnamelist`5B0`5D =
X    monstnamelist`5BINVISIBLESTALKER`5D = floorc;
X    for (j=DEMONLORD; j<=DEMONPRINCE; j++)
X        monstnamelist`5Bj`5D = floorc;
X    `7D
X
Xstatic void actual_readopts( namenotchanged, original_objects )
Xchar *namenotchanged;
Xchar *original_objects;
X    `7B
X    register char *i;
X    register int j,k;
X
X    i = " ";
X    while (*i)
X        `7B
X        /* check for EOF
X        */
X        if ((i=(char *)lgetw()) == 0)
X            return;
X#if 0
X        while (*i && ((*i==' ') `7C`7C (*i=='\t'))) i++; /* eat leading whit
Vespace */
X#endif
X        /* leading # a comment, eat the rest of the line.  Handle multiple
X           comment lines in a row.
X        */
X        while (*i == '#')
X            `7B
X            char cc;
X            do
X                cc = (char)lgetc();
X            while ( ( cc != '\n' ) && ( cc != NULL));
X            if ((i = (char *)lgetw()) == 0)
X                return;
X            `7D
X
X        if (strcmp(i,"bold-objects") == 0)
X            boldon=1;
X        else if (strcmp(i,"enable-checkpointing") == 0)
X            ckpflag=1;
X        else if (strcmp(i,"inverse-objects") == 0)
X            boldon=0;
X        else if (strcmp(i,"prompt-on-objects") == 0 )
X            prompt_mode = TRUE ;
X        else if (strcmp(i,"auto-pickup") == 0 )
X            auto_pickup = TRUE ;
X        else if (strcmp(i,"highlight-objects") == 0 )
X            boldobjects = TRUE ;
X        else if (strcmp(i,"original-objects") == 0 )
X            *original_objects = TRUE ;
X        else if (strcmp(i,"female") == 0)
X            sex=0; /* male or female */
X# ifdef MSDOS
X        else if (strcmp(i, "graphics:") == 0)
X            `7B
X            wallc = atoi(lgetw());
X            floorc = atoi(lgetw());
X            `7D
X        else if (strcmp(i, "larndir:") == 0)
X            `7B
X            if ((i=lgetw())==0)
X                break;
X            strncpy(larndir, i, DIRLEN);
X            larndir`5BDIRLEN - 1`5D = 0;
X            `7D
X        else if (strcmp(i, "rawio") == 0)
X            rawio = 1;
X        else if (strcmp(i, "swapfile:") == 0)
X            `7B
X            if ((i = (char *)lgetw()) == 0)
X                break;
X            strncpy(swapfile, i, PATHLEN);
X            swapfile`5BPATHLEN - 1`5D = 0;
X            `7D
X        else if (strcmp(i, "ramlevels:") == 0)
X            ramlevels = atoi(lgetw());
X        else if (strcmp(i, "cursor:") == 0)
X            `7B
X            cursorset = 1;
X            cursorstart = (unsigned char) atoi(lgetw());
X            cursorend = (unsigned char) atoi(lgetw());
X            `7D
X        else if (strcmp(i, "keypad") == 0)
X            keypad = 1;
X        else if (strcmp(i, "DECRainbow") == 0)
X            DECRainbow = 1;
X# endif
X        else if (strcmp(i,"monster:")== 0)   /* name favorite monster */
X            `7B
X            if ((i=(char *)lgetw())==0)
X                break;
X            if (strlen(i)>=MAXMNAME)
X                i`5BMAXMNAME-1`5D=0;
X            strcpy(usermonster`5Busermpoint`5D,i);
X            if (usermpoint >= MAXUM)
X                break; /* defined all of em */
X            if (isalpha(j=usermonster`5Busermpoint`5D`5B0`5D))
X                `7B
X                for (k=1; k<MAXMONST+8; k++) /* find monster */
X                  if (monstnamelist`5Bk`5D == j)
X                    `7B
X                    monster`5Bk`5D.name = &usermonster`5Busermpoint++`5D`5B0
V`5D;
X                    break;
X                    `7D
X                `7D
X            `7D
X        else if (strcmp(i,"male") == 0)
X            sex=1;
X        else if (strcmp(i,"name:") == 0) /* defining players name */
X            `7B
X            if ((i=lgetw())==0)
X                break;
X            if (strlen(i)>=LOGNAMESIZE)
X                i`5BLOGNAMESIZE-1`5D=0;
X            strcpy(logname,i);
X            *namenotchanged = FALSE;
X# ifdef MSDOS
X            strcpy(loginname,i);
X# endif
X            `7D
X        else if (strcmp(i,"no-introduction") == 0)
X            nowelcome=1;
X        else if (strcmp(i,"no-beep") == 0)
X            nobeep=1;
X# ifndef MSDOS
X        else if (strcmp(i,"process-name:")== 0)
X            `7B
X            if ((i=lgetw())==0)
X                break;
X            if (strlen(i)>=PSNAMESIZE)
X                i`5BPSNAMESIZE-1`5D=0;
X            strcpy(psname,i);
X            `7D
X        else if (strcmp(i,"play-day-play") == 0)
X# ifdef TIMECHECK
X            dayplay=1;
X# else
X        ;
X# endif
X# endif
X        else if (strcmp(i,"savefile:") == 0) /* defining savefilename */
X            `7B
X            if ((i=lgetw())==0)
X                break;
X            if (strlen(i)>=SAVEFILENAMESIZE) /* avoid overflow */
X                i`5BSAVEFILENAMESIZE-1`5D=0;
X            strcpy(savefilename,i);
X            `7D
X        else
X            `7B
X            lprintf("Unknown option \"%s\"\n", i);
X            lflush();
X            sleep(1);
X            `7D
X        `7D
X    `7D
$ CALL UNPACK TOK.C;1 2067538061
$ create 'f'
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`0C
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 *      `5Bpad time`5D`5B*`5D<string to send>
X *
X *      where:  pad time => time to delay in milliseconds
X *          * => specifies that time is per line
X *         `20
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`0C
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`5B`5D = `7B
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 */
+-+-+-+-+-+-+-+-  END  OF PART 46 +-+-+-+-+-+-+-+-
