/* yamsweeper : Yet Another Mine sweeper * * Copyright (C) 1992, 1993, 1994 by Hirofumi Yamamoto * * All Rights Reserved * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of the author not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. The author makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * Programmed by hirofumi@info.kawasaki-steel.co.jp for original version. * */ #include #include #include #include #include #ifndef sun #include #endif #include "gentype.h" #include "struct.h" static char rcsid[] = "$Id: main.c,v 1.20 1994/11/03 00:17:08 hirofumi Rel hirofumi $"; extern Widget toplevel; extern Display *d; extern Window r, w; #ifdef __STDC__ #define SSTR(x) #x #define STR(x) SSTR(x) #endif static XtResource resources[] = { { "name", "Name", XtRString, sizeof(String), XtOffset(AppDataPtr, name), XtRString, "Yet another Mine Sweeper" }, { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), XtOffset(AppDataPtr, fg), XtRString, "black" }, { XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel), XtOffset(AppDataPtr, bg), XtRString, "white" }, { XtNfont, XtCFont, XtRFont, sizeof(Font), XtOffset(AppDataPtr, ank), XtRString, "-misc-fixed-bold-r-normal--*-*-*-*-*-*-iso8859-*" }, { "identifier", "Identifier", XtRString, sizeof(String), XtOffset(AppDataPtr, identifier), XtRString, "LOGNAME" }, { "clearFull", "ClearFull", XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr, clearfull), XtRString, "True" }, { "dispResults", "DispResults", XtRBoolean, sizeof(Boolean), XtOffset(AppDataPtr, dispResults), XtRString, "False" }, { "mapSizeX", "MapSizeX", XtRInt, sizeof(int), XtOffset(AppDataPtr, mapSizeX), XtRString, "8" }, { "mapSizeY", "MapSizeY", XtRInt, sizeof(int), XtOffset(AppDataPtr, mapSizeY), XtRString, "8" }, #ifdef __STDC__ { "cursor", XtCCursor, XtRInt, sizeof(XtRInt), XtOffset(AppDataPtr, cursor), XtRString, STR(XC_hand2) }, { "menucursor", XtCCursor, XtRInt, sizeof(XtRInt), XtOffset(AppDataPtr, menucursor), XtRString, STR(XC_sb_left_arrow) }, #endif }; static XrmOptionDescRec options[] = { /* { "-fk", "*kanjiFont", XrmoptionSepArg, NULL },*/ { "-dr", "*dispResults", XrmoptionNoArg, "True" }, { "-x", "*mapSizeX", XrmoptionSepArg, NULL }, { "-y", "*mapSizeY", XrmoptionSepArg, NULL }, #ifdef __STDC__ { "-cursor", "*cursor", XrmoptionSepArg, NULL }, #endif }; void usage() { static char *usageStr[] = { "usage: yamsweeper [-options]", "options:", "Xtoolkit options +", "-x # : horizontal size", "-y # : vertical size", "-dr : show results window (not recommended)", "-V : show version", }; int i; for (i = 0; i < sizeOf(usageStr); ++i) { puts(usageStr[i]); } exit(1); } void #ifdef __STDC__ LogUser(char* s) #else LogUser(s) char* s; #endif { #if LOG_USER char* user = (char *)getenv(appData.identifier); time_t tt = time(NULL); char* ct = ctime(&tt); FILE* fp = fopen(LOGFILE, "a"); if (fp == NULL) { /*perror(LOGFILE);*/ exit(1); return; } fprintf(fp, "%-8s: %-12s at %s", user, s, ct); fflush(fp); fclose(fp); #endif } void #ifdef __STDC__ userint(int sig) #else userint(sig) int sig; #endif { LogUser("break"); exit(1); } int main(argc, argv) int argc; char **argv; { int d; #ifndef unix long t; #else time_t t; #endif toplevel = XtInitialize(argv[0], "Yamsweeper", options, XtNumber(options), &argc, argv); #ifndef __STDC__ appData.cursor = XC_hand2; appData.menucursor = XC_sb_left_arrow; #endif if (argv[1]) { if (!strcmp(argv[1], "-V")) { extern char version[]; puts(version); return 0; } else if (!strcmp(argv[1], "-h")) { usage(); } else usage(); } XtGetApplicationResources(toplevel, &appData, resources, XtNumber(resources), NULL, 0); assignSize(); GlobalInit(toplevel); ChangeColor(); LogUser("invokes"); signal(SIGINT, userint); MainLoop(); LogUser("quits"); return 0; }