From 84e7d0704483ce39bbdeacd5e676168db6fa664f Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 19 Oct 1997 16:56:41 +0000 Subject: WARNsify... --- hack/hack.unix.c | 427 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 236 insertions(+), 191 deletions(-) (limited to 'hack/hack.unix.c') diff --git a/hack/hack.unix.c b/hack/hack.unix.c index 10c0e660..0160c463 100644 --- a/hack/hack.unix.c +++ b/hack/hack.unix.c @@ -1,10 +1,13 @@ +/* $NetBSD: hack.unix.c,v 1.5 1997/10/19 16:59:21 christos Exp $ */ + /* * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ +#include #ifndef lint -static char rcsid[] = "$NetBSD: hack.unix.c,v 1.4 1996/02/06 22:47:25 jtc Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: hack.unix.c,v 1.5 1997/10/19 16:59:21 christos Exp $"); +#endif /* not lint */ /* This file collects some Unix dependencies; hack.pager.c contains some more */ @@ -17,59 +20,66 @@ static char rcsid[] = "$NetBSD: hack.unix.c,v 1.4 1996/02/06 22:47:25 jtc Exp $" * - determination of what files are "very old" */ -#include #include -#include "hack.h" /* mainly for index() which depends on BSD */ - -#include /* for time_t and stat */ -#include +#include /* for time_t and stat */ +#include #ifdef BSD -#include +#include #else -#include -#endif BSD +#include +#endif /* BSD */ +#include +#include +#include +#include -extern char *getenv(); -extern time_t time(); +#include "hack.h" /* mainly for strchr() which depends on BSD */ +#include "extern.h" + +void setrandom() { - (void) srandom((int) time ((time_t *) 0)); + (void) srandom((int) time((time_t *) 0)); } -struct tm * +struct tm * getlt() { - time_t date; - struct tm *localtime(); + time_t date; (void) time(&date); - return(localtime(&date)); + return (localtime(&date)); } +int getyear() { - return(1900 + getlt()->tm_year); + return (1900 + getlt()->tm_year); } -char * +char * getdate() { - static char datestr[7]; - register struct tm *lt = getlt(); + static char datestr[7]; + struct tm *lt = getlt(); (void) sprintf(datestr, "%2d%2d%2d", - lt->tm_year, lt->tm_mon + 1, lt->tm_mday); - if(datestr[2] == ' ') datestr[2] = '0'; - if(datestr[4] == ' ') datestr[4] = '0'; - return(datestr); + lt->tm_year, lt->tm_mon + 1, lt->tm_mday); + if (datestr[2] == ' ') + datestr[2] = '0'; + if (datestr[4] == ' ') + datestr[4] = '0'; + return (datestr); } -phase_of_the_moon() /* 0-7, with 0: new, 4: full */ -{ /* moon period: 29.5306 days */ - /* year: 365.2422 days */ - register struct tm *lt = getlt(); - register int epact, diy, golden; +int +phase_of_the_moon() +{ /* 0-7, with 0: new, 4: full *//* moon + * period: 29.5306 days */ + /* year: 365.2422 days */ + struct tm *lt = getlt(); + int epact, diy, golden; diy = lt->tm_yday; golden = (lt->tm_year % 19) + 1; @@ -77,50 +87,57 @@ phase_of_the_moon() /* 0-7, with 0: new, 4: full */ if ((epact == 25 && golden > 11) || epact == 24) epact++; - return( (((((diy + epact) * 6) + 11) % 177) / 22) & 7 ); + return ((((((diy + epact) * 6) + 11) % 177) / 22) & 7); } +int night() { - register int hour = getlt()->tm_hour; + int hour = getlt()->tm_hour; - return(hour < 6 || hour > 21); + return (hour < 6 || hour > 21); } +int midnight() { - return(getlt()->tm_hour == 0); + return (getlt()->tm_hour == 0); } -struct stat buf, hbuf; +struct stat buf, hbuf; -gethdate(name) char *name; { -/* old version - for people short of space */ -/* -/* register char *np; -/* if(stat(name, &hbuf)) -/* error("Cannot get status of %s.", -/* (np = rindex(name, '/')) ? np+1 : name); -/* -/* version using PATH from: seismo!gregc@ucsf-cgl.ARPA (Greg Couch) */ +void +gethdate(name) + char *name; +{ +#if 0 + /* old version - for people short of space */ + char *np; -/* - * The problem with #include is that this include file - * does not exist on all systems, and moreover, that it sometimes includes - * again, so that the compiler sees these typedefs twice. - */ + if(stat(name, &hbuf)) + error("Cannot get status of %s.", + (np = strrchr(name, '/')) ? np+1 : name); +#else + /* version using PATH from: seismo!gregc@ucsf-cgl.ARPA (Greg Couch) */ + + + /* + * The problem with #include is that this include file + * does not exist on all systems, and moreover, that it sometimes includes + * again, so that the compiler sees these typedefs twice. + */ #define MAXPATHLEN 1024 -register char *np, *path; -char filename[MAXPATHLEN+1]; - if (index(name, '/') != NULL || (path = getenv("PATH")) == NULL) + char *np, *path; + char filename[MAXPATHLEN + 1]; + if (strchr(name, '/') != NULL || (path = getenv("PATH")) == NULL) path = ""; for (;;) { - if ((np = index(path, ':')) == NULL) + if ((np = strchr(path, ':')) == NULL) np = path + strlen(path); /* point to end str */ - if (np - path <= 1) /* %% */ + if (np - path <= 1) /* %% */ (void) strcpy(filename, name); else { (void) strncpy(filename, path, np - path); @@ -134,122 +151,136 @@ char filename[MAXPATHLEN+1]; path = np + 1; } error("Cannot get status of %s.", - (np = rindex(name, '/')) ? np+1 : name); + (np = strrchr(name, '/')) ? np + 1 : name); +#endif } -uptodate(fd) { - if(fstat(fd, &buf)) { +int +uptodate(fd) +{ + if (fstat(fd, &buf)) { pline("Cannot get status of saved level? "); - return(0); + return (0); } - if(buf.st_mtime < hbuf.st_mtime) { + if (buf.st_mtime < hbuf.st_mtime) { pline("Saved level is out of date. "); - return(0); + return (0); } - return(1); + return (1); } /* see whether we should throw away this xlock file */ -veryold(fd) { - register int i; - time_t date; +int +veryold(fd) + int fd; +{ + int i; + time_t date; - if(fstat(fd, &buf)) return(0); /* cannot get status */ - if(buf.st_size != sizeof(int)) return(0); /* not an xlock file */ + if (fstat(fd, &buf)) + return (0); /* cannot get status */ + if (buf.st_size != sizeof(int)) + return (0); /* not an xlock file */ (void) time(&date); - if(date - buf.st_mtime < 3L*24L*60L*60L) { /* recent */ - int lockedpid; /* should be the same size as hackpid */ + if (date - buf.st_mtime < 3L * 24L * 60L * 60L) { /* recent */ + int lockedpid; /* should be the same size as + * hackpid */ - if(read(fd, (char *)&lockedpid, sizeof(lockedpid)) != - sizeof(lockedpid)) + if (read(fd, (char *) &lockedpid, sizeof(lockedpid)) != + sizeof(lockedpid)) /* strange ... */ - return(0); - - /* From: Rick Adams - /* This will work on 4.1cbsd, 4.2bsd and system 3? & 5. - /* It will do nothing on V7 or 4.1bsd. */ - if(!(kill(lockedpid, 0) == -1 && errno == ESRCH)) - return(0); + return (0); + + /* + * From: Rick Adams This will work on + * 4.1cbsd, 4.2bsd and system 3? & 5. It will do nothing + * on V7 or 4.1bsd. + */ + if (!(kill(lockedpid, 0) == -1 && errno == ESRCH)) + return (0); } (void) close(fd); - for(i = 1; i <= MAXLEVEL; i++) { /* try to remove all */ + for (i = 1; i <= MAXLEVEL; i++) { /* try to remove all */ glo(i); (void) unlink(lock); } glo(0); - if(unlink(lock)) return(0); /* cannot remove it */ - return(1); /* success! */ + if (unlink(lock)) + return (0); /* cannot remove it */ + return (1); /* success! */ } +void getlock() { - extern int hackpid, locknum; - register int i = 0, fd; + extern int hackpid, locknum; + int i = 0, fd; (void) fflush(stdout); /* we ignore QUIT and INT at this point */ if (link(HLOCK, LLOCK) == -1) { - register int errnosv = errno; + int errnosv = errno; perror(HLOCK); printf("Cannot link %s to %s\n", LLOCK, HLOCK); - switch(errnosv) { + switch (errnosv) { case ENOENT: - printf("Perhaps there is no (empty) file %s ?\n", HLOCK); - break; + printf("Perhaps there is no (empty) file %s ?\n", HLOCK); + break; case EACCES: - printf("It seems you don't have write permission here.\n"); - break; + printf("It seems you don't have write permission here.\n"); + break; case EEXIST: - printf("(Try again or rm %s.)\n", LLOCK); - break; + printf("(Try again or rm %s.)\n", LLOCK); + break; default: - printf("I don't know what is wrong."); + printf("I don't know what is wrong."); } getret(); - error(""); - /*NOTREACHED*/ + error("%s", ""); + /* NOTREACHED */ } - regularize(lock); glo(0); - if(locknum > 25) locknum = 25; + if (locknum > 25) + locknum = 25; do { - if(locknum) lock[0] = 'a' + i++; + if (locknum) + lock[0] = 'a' + i++; - if((fd = open(lock, 0)) == -1) { - if(errno == ENOENT) goto gotlock; /* no such file */ + if ((fd = open(lock, 0)) == -1) { + if (errno == ENOENT) + goto gotlock; /* no such file */ perror(lock); (void) unlink(LLOCK); error("Cannot open %s", lock); } - - if(veryold(fd)) /* if true, this closes fd and unlinks lock */ + if (veryold(fd))/* if true, this closes fd and unlinks lock */ goto gotlock; (void) close(fd); - } while(i < locknum); + } while (i < locknum); (void) unlink(LLOCK); error(locknum ? "Too many hacks running now." - : "There is a game in progress under your name."); + : "There is a game in progress under your name."); gotlock: fd = creat(lock, FMASK); - if(unlink(LLOCK) == -1) + if (unlink(LLOCK) == -1) error("Cannot unlink %s.", LLOCK); - if(fd == -1) { + if (fd == -1) { error("cannot creat lock file."); } else { - if(write(fd, (char *) &hackpid, sizeof(hackpid)) - != sizeof(hackpid)){ + if (write(fd, (char *) &hackpid, sizeof(hackpid)) + != sizeof(hackpid)) { error("cannot write lock"); } - if(close(fd) == -1) { + if (close(fd) == -1) { error("cannot close lock"); } } -} +} #ifdef MAIL @@ -284,151 +315,165 @@ gotlock: * - Do something to the text when the scroll is enchanted or cancelled. */ #include "def.mkroom.h" -static struct stat omstat,nmstat; -static char *mailbox; -static long laststattime; +static struct stat omstat, nmstat; +static char *mailbox; +static long laststattime; -getmailstatus() { - if(!(mailbox = getenv("MAIL"))) +void +getmailstatus() +{ + if (!(mailbox = getenv("MAIL"))) return; - if(stat(mailbox, &omstat)){ + if (stat(mailbox, &omstat)) { #ifdef PERMANENT_MAILBOX pline("Cannot get status of MAIL=%s .", mailbox); mailbox = 0; #else omstat.st_mtime = 0; -#endif PERMANENT_MAILBOX +#endif /* PERMANENT_MAILBOX */ } } -ckmailstatus() { - if(!mailbox +void +ckmailstatus() +{ + if (!mailbox #ifdef MAILCKFREQ - || moves < laststattime + MAILCKFREQ -#endif MAILCKFREQ - ) + || moves < laststattime + MAILCKFREQ +#endif /* MAILCKFREQ */ + ) return; laststattime = moves; - if(stat(mailbox, &nmstat)){ + if (stat(mailbox, &nmstat)) { #ifdef PERMANENT_MAILBOX pline("Cannot get status of MAIL=%s anymore.", mailbox); mailbox = 0; #else nmstat.st_mtime = 0; -#endif PERMANENT_MAILBOX - } else if(nmstat.st_mtime > omstat.st_mtime) { - if(nmstat.st_size) +#endif /* PERMANENT_MAILBOX */ + } else if (nmstat.st_mtime > omstat.st_mtime) { + if (nmstat.st_size) newmail(); - getmailstatus(); /* might be too late ... */ + getmailstatus();/* might be too late ... */ } } -newmail() { +void +newmail() +{ /* produce a scroll of mail */ - register struct obj *obj; - register struct monst *md; - extern char plname[]; - extern struct obj *mksobj(), *addinv(); - extern struct monst *makemon(); - extern struct permonst pm_mail_daemon; + struct obj *obj; + struct monst *md; obj = mksobj(SCR_MAIL); - if(md = makemon(&pm_mail_daemon, u.ux, u.uy)) /* always succeeds */ - mdrush(md,0); + if (md = makemon(&pm_mail_daemon, u.ux, u.uy)) /* always succeeds */ + mdrush(md, 0); pline("\"Hello, %s! I have some mail for you.\"", plname); - if(md) { - if(dist(md->mx,md->my) > 2) + if (md) { + if (dist(md->mx, md->my) > 2) pline("\"Catch!\""); more(); /* let him disappear again */ - mdrush(md,1); + mdrush(md, 1); mondead(md); } - obj = addinv(obj); - (void) identify(obj); /* set known and do prinv() */ + (void) identify(obj); /* set known and do prinv() */ } /* make md run through the cave */ -mdrush(md,away) -register struct monst *md; -boolean away; +void +mdrush(md, away) + struct monst *md; + boolean away; { - register int uroom = inroom(u.ux, u.uy); - if(uroom >= 0) { - register int tmp = rooms[uroom].fdoor; - register int cnt = rooms[uroom].doorct; - register int fx = u.ux, fy = u.uy; - while(cnt--) { - if(dist(fx,fy) < dist(doors[tmp].x, doors[tmp].y)){ + int uroom = inroom(u.ux, u.uy); + if (uroom >= 0) { + int tmp = rooms[uroom].fdoor; + int cnt = rooms[uroom].doorct; + int fx = u.ux, fy = u.uy; + while (cnt--) { + if (dist(fx, fy) < dist(doors[tmp].x, doors[tmp].y)) { fx = doors[tmp].x; fy = doors[tmp].y; } tmp++; } tmp_at(-1, md->data->mlet); /* open call */ - if(away) { /* interchange origin and destination */ + if (away) { /* interchange origin and destination */ unpmon(md); - tmp = fx; fx = md->mx; md->mx = tmp; - tmp = fy; fy = md->my; md->my = tmp; + tmp = fx; + fx = md->mx; + md->mx = tmp; + tmp = fy; + fy = md->my; + md->my = tmp; } - while(fx != md->mx || fy != md->my) { - register int dx,dy,nfx = fx,nfy = fy,d1,d2; - - tmp_at(fx,fy); - d1 = DIST(fx,fy,md->mx,md->my); - for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) - if(dx || dy) { - d2 = DIST(fx+dx,fy+dy,md->mx,md->my); - if(d2 < d1) { - d1 = d2; - nfx = fx+dx; - nfy = fy+dy; - } - } - if(nfx != fx || nfy != fy) { - fx = nfx; - fy = nfy; + while (fx != md->mx || fy != md->my) { + int dx, dy, nfx = fx, nfy = fy, d1, + d2; + + tmp_at(fx, fy); + d1 = DIST(fx, fy, md->mx, md->my); + for (dx = -1; dx <= 1; dx++) + for (dy = -1; dy <= 1; dy++) + if (dx || dy) { + d2 = DIST(fx + dx, fy + dy, md->mx, md->my); + if (d2 < d1) { + d1 = d2; + nfx = fx + dx; + nfy = fy + dy; + } + } + if (nfx != fx || nfy != fy) { + fx = nfx; + fy = nfy; } else { - if(!away) { - md->mx = fx; - md->my = fy; - } - break; - } + if (!away) { + md->mx = fx; + md->my = fy; + } + break; + } } - tmp_at(-1,-1); /* close call */ + tmp_at(-1, -1); /* close call */ } - if(!away) + if (!away) pmon(md); } -readmail() { -#ifdef DEF_MAILREADER /* This implies that UNIX is defined */ - register char *mr = 0; +void +readmail() +{ +#ifdef DEF_MAILREADER /* This implies that UNIX is defined */ + char *mr = 0; more(); - if(!(mr = getenv("MAILREADER"))) + if (!(mr = getenv("MAILREADER"))) mr = DEF_MAILREADER; - if(child(1)){ + if (child(1)) { execl(mr, mr, (char *) 0); exit(1); } -#else DEF_MAILREADER +#else /* DEF_MAILREADER */ (void) page_file(mailbox, FALSE); -#endif DEF_MAILREADER - /* get new stat; not entirely correct: there is a small time - window where we do not see new mail */ +#endif /* DEF_MAILREADER */ + /* + * get new stat; not entirely correct: there is a small time window + * where we do not see new mail + */ getmailstatus(); } -#endif MAIL +#endif /* MAIL */ -regularize(s) /* normalize file name - we don't like ..'s or /'s */ -register char *s; +void +regularize(s) /* normalize file name - we don't like ..'s + * or /'s */ + char *s; { - register char *lp; + char *lp; - while((lp = index(s, '.')) || (lp = index(s, '/'))) + while ((lp = strchr(s, '.')) || (lp = strchr(s, '/'))) *lp = '_'; } -- cgit v1.2.3-56-ge451