]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - larn/tok.c
speed limit 80
[bsdgames-darwin.git] / larn / tok.c
index 6ca1f672619072d5477dd52ddcbd0d2f5e197a6b..6bab595e457876faaab1322438892d00661555ea 100644 (file)
@@ -1,9 +1,9 @@
-/*     $NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $ */
+/*     $NetBSD: tok.c,v 1.11 2012/06/19 05:30:44 dholland Exp $        */
 
 /* tok.c               Larn is copyrighted 1986 by Noah Morgan. */
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $");
+__RCSID("$NetBSD: tok.c,v 1.11 2012/06/19 05:30:44 dholland Exp $");
 #endif                         /* not lint */
 
 #include <sys/types.h>
@@ -16,6 +16,9 @@ __RCSID("$NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $");
 #include "header.h"
 #include "extern.h"
 
+/* Keystrokes (roughly) between checkpoints */
+#define CHECKPOINT_INTERVAL    400
+
 static char     lastok = 0;
 int             yrepcount = 0;
 #ifndef FLUSHNO
@@ -32,7 +35,7 @@ static u_char     usermpoint = 0;     /* the user monster pointer */
        lexical analyzer for larn
  */
 int
-yylex()
+yylex(void)
 {
        char            cc;
        int             ic;
@@ -53,9 +56,9 @@ yylex()
        lflush();
        while (1) {
                c[BYTESIN]++;
+               /* check for periodic checkpointing */
                if (ckpflag)
-                       if ((c[BYTESIN] % 400) == 0) {  /* check for periodic
-                                                        * checkpointing */
+                       if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) {
 #ifndef DOCHECKPOINTS
                                savegame(ckpfile);
 #else
@@ -108,7 +111,7 @@ yylex()
  *     flushall()              Function to flush all type-ahead in the input buffer
  */
 void
-flushall()
+flushall(void)
 {
        char            cc;
        int             ic;
@@ -129,10 +132,11 @@ flushall()
        enter with hard= -1 for default hardness, else any desired hardness
  */
 void
-sethard(hard)
-       int             hard;
+sethard(int hard)
 {
        int    j, k, i;
+       struct monst *mp;
+
        j = c[HARDGAME];
        hashewon();
        if (restorflag == 0) {  /* don't set c[HARDGAME] if restoring game */
@@ -144,16 +148,17 @@ sethard(hard)
 
        if ((k = c[HARDGAME]) != 0)
                for (j = 0; j <= MAXMONST + 8; j++) {
-                       i = ((6 + k) * monster[j].hitpoints + 1) / 6;
-                       monster[j].hitpoints = (i < 0) ? 32767 : i;
-                       i = ((6 + k) * monster[j].damage + 1) / 5;
-                       monster[j].damage = (i > 127) ? 127 : i;
-                       i = (10 * monster[j].gold) / (10 + k);
-                       monster[j].gold = (i > 32767) ? 32767 : i;
-                       i = monster[j].armorclass - k;
-                       monster[j].armorclass = (i < -127) ? -127 : i;
-                       i = (7 * monster[j].experience) / (7 + k) + 1;
-                       monster[j].experience = (i <= 0) ? 1 : i;
+                       mp = &monster[j];
+                       i = ((6 + k) * mp->hitpoints + 1) / 6;
+                       mp->hitpoints = (i < 0) ? 32767 : i;
+                       i = ((6 + k) * mp->damage + 1) / 5;
+                       mp->damage = (i > 127) ? 127 : i;
+                       i = (10 * mp->gold) / (10 + k);
+                       mp->gold = (i > 32767) ? 32767 : i;
+                       i = mp->armorclass - k;
+                       mp->armorclass = (i < -127) ? -127 : i;
+                       i = (7 * mp->experience) / (7 + k) + 1;
+                       mp->experience = (i <= 0) ? 1 : i;
                }
 }
 
@@ -161,13 +166,14 @@ sethard(hard)
        function to read and process the larn options file
  */
 void
-readopts()
+readopts(void)
 {
        const char  *i;
        int    j, k;
        int             flag;
-       flag = 1;               /* set to 0 if he specifies a name for his
-                                * character */
+
+       flag = 1;               /* set to 0 if a name is specified */
+
        if (lopen(optsfile) < 0) {
                strcpy(logname, loginname);
                return;         /* user name if no character name */
@@ -178,76 +184,51 @@ readopts()
                        break;  /* check for EOF */
                while ((*i == ' ') || (*i == '\t'))
                        i++;    /* eat leading whitespace */
-               switch (*i) {
-               case 'b':
-                       if (strcmp(i, "bold-objects") == 0)
-                               boldon = 1;
-                       break;
-
-               case 'e':
-                       if (strcmp(i, "enable-checkpointing") == 0)
-                               ckpflag = 1;
-                       break;
-
-               case 'i':
-                       if (strcmp(i, "inverse-objects") == 0)
-                               boldon = 0;
-                       break;
-
-               case 'f':
-                       if (strcmp(i, "female") == 0)
-                               sex = 0;        /* male or female */
-                       break;
 
-               case 'm':
-                       if (strcmp(i, "monster:") == 0) {       /* name favorite monster */
-                               if ((i = lgetw()) == 0)
-                                       break;
-                               strlcpy(usermonster[usermpoint], i, MAXMNAME);
-                               if (usermpoint >= MAXUM)
-                                       break;  /* defined all of em */
-                               if (isalpha(j = usermonster[usermpoint][0])) {
-                                       for (k = 1; k < MAXMONST + 8; k++)      /* find monster */
-                                               if (monstnamelist[k] == j) {
-                                                       monster[k].name = &usermonster[usermpoint++][0];
-                                                       break;
-                                               }
-                               }
-                       } else if (strcmp(i, "male") == 0)
-                               sex = 1;
-                       break;
-
-               case 'n':
-                       if (strcmp(i, "name:") == 0) {  /* defining players name */
-                               if ((i = lgetw()) == 0)
-                                       break;
-                               strlcpy(logname, i, LOGNAMESIZE);
-                               flag = 0;
-                       } else if (strcmp(i, "no-introduction") == 0)
-                               nowelcome = 1;
-                       else if (strcmp(i, "no-beep") == 0)
-                               nobeep = 1;
-                       break;
-
-               case 'p':
-                       if (strcmp(i, "process-name:") == 0) {
-                               if ((i = lgetw()) == 0)
-                                       break;
-                               strlcpy(psname, i, PSNAMESIZE);
-                       } else if (strcmp(i, "play-day-play") == 0) {
-                               /* bypass time restrictions: ignored */
+               if (strcmp(i, "bold-objects") == 0)
+                       boldon = 1;
+               else if (strcmp(i, "enable-checkpointing") == 0)
+                       ckpflag = 1;
+               else if (strcmp(i, "inverse-objects") == 0)
+                       boldon = 0;
+               else if (strcmp(i, "female") == 0)
+                       sex = 0;        /* male or female */
+               else if (strcmp(i, "monster:") == 0) {  /* name favorite monster */
+                       if ((i = lgetw()) == 0)
+                               break;
+                       strlcpy(usermonster[usermpoint], i, MAXMNAME);
+                       if (usermpoint >= MAXUM)
+                               continue;       /* defined all of em */
+                       if (isalpha(j = usermonster[usermpoint][0])) {
+                               for (k = 1; k < MAXMONST + 8; k++)      /* find monster */
+                                       if (monstnamelist[k] == j) {
+                                               monster[k].name = &usermonster[usermpoint++][0];
+                                               break;
+                                       }
                        }
-                       break;
-
-               case 's':
-                       if (strcmp(i, "savefile:") == 0) {      /* defining savefilename */
-                               if ((i = lgetw()) == 0)
-                                       break;
-                               strcpy(savefilename, i);
-                               flag = 0;
-                       }
-                       break;
-               };
+               } else if (strcmp(i, "male") == 0)
+                       sex = 1;
+               else if (strcmp(i, "name:") == 0) {     /* defining players name */
+                       if ((i = lgetw()) == 0)
+                               break;
+                       strlcpy(logname, i, LOGNAMESIZE);
+                       flag = 0;
+               } else if (strcmp(i, "no-introduction") == 0)
+                       nowelcome = 1;
+               else if (strcmp(i, "no-beep") == 0)
+                       nobeep = 1;
+               else if (strcmp(i, "process-name:") == 0) {
+                       if ((i = lgetw()) == 0)
+                               break;
+                       strlcpy(psname, i, PSNAMESIZE);
+               } else if (strcmp(i, "play-day-play") == 0) {
+                       /* bypass time restrictions: ignored */
+               } else if (strcmp(i, "savefile:") == 0) {       /* defining savefilename */
+                       if ((i = lgetw()) == 0)
+                               break;
+                       strcpy(savefilename, i);
+                       flag = 0;
+               }
        }
        if (flag)
                strcpy(logname, loginname);