11.15Sdholland/* $NetBSD: main.c,v 1.15 2012/06/19 05:45:00 dholland 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.13Slukem__COPYRIGHT("@(#) Copyright (c) 1983, 1993\ 351.13Slukem The Regents of the University of California. All rights reserved."); 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.15Sdholland__RCSID("$NetBSD: main.c,v 1.15 2012/06/19 05:45:00 dholland 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.15Sdhollandmain(int argc, char *argv[]) 541.1Scgd{ 551.8Sjsm int ch; 561.8Sjsm 571.7Sjsm /* Revoke setgid privileges */ 581.9Smycroft setgid(getgid()); 591.8Sjsm 601.10Sjsm while ((ch = getopt(argc, argv, "d:m:")) != -1) { 611.8Sjsm switch (ch) { 621.8Sjsm case 'd': 631.8Sjsm Dict_name = optarg; 641.8Sjsm break; 651.10Sjsm case 'm': 661.10Sjsm Minlen = atoi(optarg); 671.10Sjsm if (Minlen < 2) 681.10Sjsm errx(1, "minimum word length too short"); 691.10Sjsm break; 701.8Sjsm case '?': 711.8Sjsm default: 721.10Sjsm (void)fprintf(stderr, "usage: hangman [-d wordlist] [-m minlen]\n"); 731.8Sjsm exit(1); 741.8Sjsm } 751.8Sjsm } 761.7Sjsm 771.14Sdrochner if (!initscr()) 781.14Sdrochner errx(0, "couldn't initialize screen"); 791.1Scgd signal(SIGINT, die); 801.1Scgd setup(); 811.1Scgd for (;;) { 821.1Scgd Wordnum++; 831.1Scgd playgame(); 841.1Scgd Average = (Average * (Wordnum - 1) + Errors) / Wordnum; 851.1Scgd } 861.1Scgd /* NOTREACHED */ 871.1Scgd} 881.1Scgd/* 891.1Scgd * die: 901.1Scgd * Die properly. 911.1Scgd */ 921.1Scgdvoid 931.15Sdhollanddie(int dummy __unused) 941.1Scgd{ 951.1Scgd mvcur(0, COLS - 1, LINES - 1, 0); 961.1Scgd endwin(); 971.1Scgd putchar('\n'); 981.1Scgd exit(0); 991.1Scgd} 100