main.c revision 1.12
11.12Sperry/* $NetBSD: main.c,v 1.12 2007/12/15 19:44:41 perry Exp $ */ 21.3Scgd 31.1Scgd/* 41.3Scgd * Copyright (c) 1983, 1993 51.3Scgd * The Regents of the University of California. All rights reserved. 61.1Scgd * 71.1Scgd * Redistribution and use in source and binary forms, with or without 81.1Scgd * modification, are permitted provided that the following conditions 91.1Scgd * are met: 101.1Scgd * 1. Redistributions of source code must retain the above copyright 111.1Scgd * notice, this list of conditions and the following disclaimer. 121.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 131.1Scgd * notice, this list of conditions and the following disclaimer in the 141.1Scgd * documentation and/or other materials provided with the distribution. 151.11Sagc * 3. Neither the name of the University nor the names of its contributors 161.1Scgd * may be used to endorse or promote products derived from this software 171.1Scgd * without specific prior written permission. 181.1Scgd * 191.1Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201.1Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211.1Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221.1Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231.1Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241.1Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251.1Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261.1Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271.1Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281.1Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291.1Scgd * SUCH DAMAGE. 301.1Scgd */ 311.1Scgd 321.4Slukem#include <sys/cdefs.h> 331.1Scgd#ifndef lint 341.4Slukem__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ 351.4Slukem The Regents of the University of California. All rights reserved.\n"); 361.1Scgd#endif /* not lint */ 371.1Scgd 381.1Scgd#ifndef lint 391.3Scgd#if 0 401.3Scgdstatic char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; 411.3Scgd#else 421.12Sperry__RCSID("$NetBSD: main.c,v 1.12 2007/12/15 19:44:41 perry Exp $"); 431.3Scgd#endif 441.1Scgd#endif /* not lint */ 451.1Scgd 461.10Sjsm#include <err.h> 471.4Slukem#include "hangman.h" 481.1Scgd 491.1Scgd/* 501.1Scgd * This game written by Ken Arnold. 511.1Scgd */ 521.4Slukemint 531.8Sjsmmain(argc, argv) 541.8Sjsm int argc; 551.8Sjsm char *argv[]; 561.1Scgd{ 571.8Sjsm int ch; 581.8Sjsm 591.7Sjsm /* Revoke setgid privileges */ 601.9Smycroft setgid(getgid()); 611.8Sjsm 621.10Sjsm while ((ch = getopt(argc, argv, "d:m:")) != -1) { 631.8Sjsm switch (ch) { 641.8Sjsm case 'd': 651.8Sjsm Dict_name = optarg; 661.8Sjsm break; 671.10Sjsm case 'm': 681.10Sjsm Minlen = atoi(optarg); 691.10Sjsm if (Minlen < 2) 701.10Sjsm errx(1, "minimum word length too short"); 711.10Sjsm break; 721.8Sjsm case '?': 731.8Sjsm default: 741.10Sjsm (void)fprintf(stderr, "usage: hangman [-d wordlist] [-m minlen]\n"); 751.8Sjsm exit(1); 761.8Sjsm } 771.8Sjsm } 781.7Sjsm 791.1Scgd initscr(); 801.1Scgd signal(SIGINT, die); 811.1Scgd setup(); 821.1Scgd for (;;) { 831.1Scgd Wordnum++; 841.1Scgd playgame(); 851.1Scgd Average = (Average * (Wordnum - 1) + Errors) / Wordnum; 861.1Scgd } 871.1Scgd /* NOTREACHED */ 881.1Scgd} 891.1Scgd/* 901.1Scgd * die: 911.1Scgd * Die properly. 921.1Scgd */ 931.1Scgdvoid 941.4Slukemdie(dummy) 951.12Sperry int dummy __unused; 961.1Scgd{ 971.1Scgd mvcur(0, COLS - 1, LINES - 1, 0); 981.1Scgd endwin(); 991.1Scgd putchar('\n'); 1001.1Scgd exit(0); 1011.1Scgd} 102