X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/84e7d0704483ce39bbdeacd5e676168db6fa664f..HEAD:/hack/hack.engrave.c diff --git a/hack/hack.engrave.c b/hack/hack.engrave.c index 8261967f..cd82725d 100644 --- a/hack/hack.engrave.c +++ b/hack/hack.engrave.c @@ -1,12 +1,69 @@ -/* $NetBSD: hack.engrave.c,v 1.4 1997/10/19 16:57:58 christos Exp $ */ +/* $NetBSD: hack.engrave.c,v 1.14 2011/08/07 06:03:45 dholland Exp $ */ /* - * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. + * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, + * Amsterdam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the Stichting Centrum voor Wiskunde en + * Informatica, nor the names of its contributors may be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982 Jay Fenlason + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #ifndef lint -__RCSID("$NetBSD: hack.engrave.c,v 1.4 1997/10/19 16:57:58 christos Exp $"); +__RCSID("$NetBSD: hack.engrave.c,v 1.14 2011/08/07 06:03:45 dholland Exp $"); #endif /* not lint */ #include @@ -25,11 +82,14 @@ struct engr { #define DUST 1 #define ENGRAVE 2 #define BURN 3 -} *head_engr; +}; + +static struct engr *head_engr; + +static void del_engr(struct engr *); -struct engr * -engr_at(x, y) - xchar x, y; +static struct engr * +engr_at(xchar x, xchar y) { struct engr *ep = head_engr; while (ep) { @@ -41,13 +101,12 @@ engr_at(x, y) } int -sengr_at(s, x, y) - char *s; - xchar x, y; +sengr_at(const char *s, xchar x, xchar y) { struct engr *ep = engr_at(x, y); char *t; - int n; + size_t n; + if (ep && ep->engr_time <= moves) { t = ep->engr_txt; /* @@ -64,20 +123,20 @@ sengr_at(s, x, y) } void -u_wipe_engr(cnt) - int cnt; +u_wipe_engr(int cnt) { if (!u.uswallow && !Levitation) wipe_engr_at(u.ux, u.uy, cnt); } void -wipe_engr_at(x, y, cnt) - xchar x, y, cnt; +wipe_engr_at(xchar x, xchar y, xchar cnt) { struct engr *ep = engr_at(x, y); - int lth, pos; + int pos; char ch; + size_t lth; + if (ep) { if ((ep->engr_type != DUST) || Levitation) { cnt = rn2(1 + 50 / (cnt + 1)) ? 0 : 1; @@ -101,8 +160,7 @@ wipe_engr_at(x, y, cnt) } void -read_engr_at(x, y) - int x, y; +read_engr_at(int x, int y) { struct engr *ep = engr_at(x, y); if (ep && ep->engr_txt[0]) { @@ -124,16 +182,14 @@ read_engr_at(x, y) } void -make_engr_at(x, y, s) - int x, y; - char *s; +make_engr_at(int x, int y, const char *s) { struct engr *ep; if ((ep = engr_at(x, y)) != NULL) del_engr(ep); - ep = (struct engr *) - alloc((unsigned) (sizeof(struct engr) + strlen(s) + 1)); + ep = alloc(sizeof(*ep) + strlen(s) + 1); + ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = x; @@ -146,7 +202,7 @@ make_engr_at(x, y, s) } int -doengrave() +doengrave(void) { int len; char *sp; @@ -177,7 +233,7 @@ doengrave() if (uwep && uwep->cursed) { /* Andreas Bormann */ pline("Since your weapon is welded to your hand,"); - pline("you use the %s.", aobjnam(uwep, (char *) 0)); + pline("you use the %s.", aobjnam(uwep, NULL)); otmp = uwep; } else { if (!otmp) @@ -263,7 +319,7 @@ doengrave() } if (oep) len += strlen(oep->engr_txt) + spct; - ep = (struct engr *) alloc((unsigned) (sizeof(struct engr) + len + 1)); + ep = alloc(sizeof(*ep) + len + 1); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = u.ux; @@ -288,8 +344,7 @@ doengrave() } void -save_engravings(fd) - int fd; +save_engravings(int fd) { struct engr *ep = head_engr; while (ep) { @@ -297,36 +352,34 @@ save_engravings(fd) ep = ep->nxt_engr; continue; } - bwrite(fd, (char *) &(ep->engr_lth), sizeof(ep->engr_lth)); - bwrite(fd, (char *) ep, sizeof(struct engr) + ep->engr_lth); + bwrite(fd, &(ep->engr_lth), sizeof(ep->engr_lth)); + bwrite(fd, ep, sizeof(struct engr) + ep->engr_lth); ep = ep->nxt_engr; } - bwrite(fd, (char *) nul, sizeof(unsigned)); + bwrite(fd, nul, sizeof(unsigned)); head_engr = 0; } void -rest_engravings(fd) - int fd; +rest_engravings(int fd) { struct engr *ep; unsigned lth; head_engr = 0; while (1) { - mread(fd, (char *) <h, sizeof(unsigned)); + mread(fd, <h, sizeof(unsigned)); if (lth == 0) return; - ep = (struct engr *) alloc(sizeof(struct engr) + lth); - mread(fd, (char *) ep, sizeof(struct engr) + lth); + ep = alloc(sizeof(*ep) + lth); + mread(fd, ep, sizeof(*ep) + lth); ep->nxt_engr = head_engr; ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */ head_engr = ep; } } -void -del_engr(ep) - struct engr *ep; +static void +del_engr(struct engr *ep) { struct engr *ept; if (ep == head_engr) @@ -342,5 +395,5 @@ del_engr(ep) return; fnd: ; } - free((char *) ep); + free(ep); }