Annotation of 43BSDReno/games/hangman/getword.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)getword.c  5.3 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: # include      "hangman.h"
                     25: 
                     26: # if pdp11
                     27: #      define  RN      (((off_t) rand() << 16) | (off_t) rand())
                     28: # else
                     29: #      define  RN      rand()
                     30: # endif
                     31: 
                     32: /*
                     33:  * getword:
                     34:  *     Get a valid word out of the dictionary file
                     35:  */
                     36: getword()
                     37: {
                     38:        register FILE           *inf;
                     39:        register char           *wp, *gp;
                     40: 
                     41:        inf = Dict;
                     42:        for (;;) {
                     43:                fseek(inf, abs(RN % Dict_size), 0);
                     44:                if (fgets(Word, BUFSIZ, inf) == NULL)
                     45:                        continue;
                     46:                if (fgets(Word, BUFSIZ, inf) == NULL)
                     47:                        continue;
                     48:                Word[strlen(Word) - 1] = '\0';
                     49:                if (strlen(Word) < MINLEN)
                     50:                        continue;
                     51:                for (wp = Word; *wp; wp++)
                     52:                        if (!islower(*wp))
                     53:                                goto cont;
                     54:                break;
                     55: cont:          ;
                     56:        }
                     57:        gp = Known;
                     58:        wp = Word;
                     59:        while (*wp) {
                     60:                *gp++ = '-';
                     61:                wp++;
                     62:        }
                     63:        *gp = '\0';
                     64: }
                     65: 
                     66: /*
                     67:  * abs:
                     68:  *     Return the absolute value of an integer
                     69:  */
                     70: off_t
                     71: abs(i)
                     72: off_t  i;
                     73: {
                     74:        if (i < 0)
                     75:                return -(off_t) i;
                     76:        else
                     77:                return (off_t) i;
                     78: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.