Annotation of 43BSDReno/games/hangman/getguess.c, revision 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[] = "@(#)getguess.c 5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: # include      "hangman.h"
        !            25: 
        !            26: /*
        !            27:  * getguess:
        !            28:  *     Get another guess
        !            29:  */
        !            30: getguess()
        !            31: {
        !            32:        register int    i;
        !            33:        register int    ch;
        !            34:        register bool   correct;
        !            35: 
        !            36:        leaveok(stdscr, FALSE);
        !            37:        for (;;) {
        !            38:                move(PROMPTY, PROMPTX + sizeof "Guess: ");
        !            39:                refresh();
        !            40:                ch = readch();
        !            41:                if (isalpha(ch)) {
        !            42:                        if (isupper(ch))
        !            43:                                ch = tolower(ch);
        !            44:                        if (Guessed[ch - 'a'])
        !            45:                                mvprintw(MESGY, MESGX, "Already guessed '%c'", ch);
        !            46:                        else
        !            47:                                break;
        !            48:                }
        !            49:                else if (ch == CTRL('D'))
        !            50:                        die();
        !            51:                else
        !            52:                        mvprintw(MESGY, MESGX, "Not a valid guess: '%s'",
        !            53:                                unctrl(ch));
        !            54:        }
        !            55:        leaveok(stdscr, TRUE);
        !            56:        move(MESGY, MESGX);
        !            57:        clrtoeol();
        !            58: 
        !            59:        Guessed[ch - 'a'] = TRUE;
        !            60:        correct = FALSE;
        !            61:        for (i = 0; Word[i] != '\0'; i++)
        !            62:                if (Word[i] == ch) {
        !            63:                        Known[i] = ch;
        !            64:                        correct = TRUE;
        !            65:                }
        !            66:        if (!correct)
        !            67:                Errors++;
        !            68: }
        !            69: 
        !            70: /*
        !            71:  * readch;
        !            72:  *     Read a character from the input
        !            73:  */
        !            74: readch()
        !            75: {
        !            76:        register int    cnt, r;
        !            77:        auto char       ch;
        !            78: 
        !            79:        cnt = 0;
        !            80:        for (;;) {
        !            81:                if (read(0, &ch, sizeof ch) <= 0)
        !            82:                {
        !            83:                        if (++cnt > 100)
        !            84:                                die();
        !            85:                }
        !            86:                else if (ch == CTRL('L')) {
        !            87:                        wrefresh(curscr);
        !            88:                        mvcur(0, 0, curscr->_cury, curscr->_curx);
        !            89:                }
        !            90:                else
        !            91:                        return ch;
        !            92:        }
        !            93: }

unix.superglobalmegacorp.com

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