From 54a6ff4e941f27f74b5c69277796845213e0d171 Mon Sep 17 00:00:00 2001 From: Paul Janzen Date: Thu, 18 Jul 2002 07:13:58 +0000 Subject: - string handling patch from David Holland, minimally modified. Highlights are fewer magic constants, sprintf->snprintf, and better scorefile handling. Also, won't hang if forking a subshell fails. - a few needless functions have been trimmed, and a few extra defaults have been added to a few switches, just in case. --- games/rogue/pack.c | 95 ++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'games/rogue/pack.c') diff --git a/games/rogue/pack.c b/games/rogue/pack.c index 592f8cdbe6e..d041214153a 100644 --- a/games/rogue/pack.c +++ b/games/rogue/pack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pack.c,v 1.6 2001/08/12 19:52:56 pjanzen Exp $ */ +/* $OpenBSD: pack.c,v 1.7 2002/07/18 07:13:57 pjanzen Exp $ */ /* $NetBSD: pack.c,v 1.3 1995/04/22 10:27:54 cgd Exp $ */ /* @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)pack.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: pack.c,v 1.3 1995/04/22 10:27:54 cgd Exp $"; +static const char rcsid[] = "$OpenBSD: pack.c,v 1.7 2002/07/18 07:13:57 pjanzen Exp $"; #endif #endif /* not lint */ @@ -113,18 +113,18 @@ pick_up(row, col, status) *status = 1; if (levitate) { - message("you're floating in the air!", 0); + messagef(0, "you're floating in the air!"); return((object *) 0); } obj = object_at(&level_objects, row, col); if (!obj) { - message("pick_up(): inconsistent", 1); + messagef(1, "pick_up(): inconsistent"); return(obj); } if ( (obj->what_is == SCROL) && (obj->which_kind == SCARE_MONSTER) && obj->picked_up) { - message("the scroll turns to dust as you pick it up", 0); + messagef(0, "the scroll turns to dust as you pick it up"); dungeon[row][col] &= (~OBJECT); vanish(obj, 0, &level_objects); *status = 0; @@ -141,7 +141,7 @@ pick_up(row, col, status) return(obj); /* obj will be free_object()ed in caller */ } if (pack_count(obj) >= MAX_PACK_COUNT) { - message("pack too full", 1); + messagef(1, "pack too full"); return((object *) 0); } dungeon[row][col] &= ~(OBJECT); @@ -159,29 +159,29 @@ drop() char desc[DCOLS]; if (dungeon[rogue.row][rogue.col] & (OBJECT | STAIRS | TRAP)) { - message("there's already something there", 0); + messagef(0, "there's already something there"); return; } if (!rogue.pack.next_object) { - message("you have nothing to drop", 0); + messagef(0, "you have nothing to drop"); return; } if ((ch = pack_letter("drop what?", ALL_OBJECTS)) == CANCEL) { return; } if (!(obj = get_letter_object(ch))) { - message("no such item.", 0); + messagef(0, "no such item."); return; } if (obj->in_use_flags & BEING_WIELDED) { if (obj->is_cursed) { - message(curse_message, 0); + messagef(0, "%s", curse_message); return; } unwield(rogue.weapon); } else if (obj->in_use_flags & BEING_WORN) { if (obj->is_cursed) { - message(curse_message, 0); + messagef(0, "%s", curse_message); return; } mv_aquatars(); @@ -189,7 +189,7 @@ drop() print_stats(STAT_ARMOR); } else if (obj->in_use_flags & ON_EITHER_HAND) { if (obj->is_cursed) { - message(curse_message, 0); + messagef(0, "%s", curse_message); return; } un_put_on(obj); @@ -208,9 +208,8 @@ drop() take_from_pack(obj, &rogue.pack); } place_at(obj, rogue.row, rogue.col); - (void) strcpy(desc, "dropped "); - get_desc(obj, desc+8); - message(desc, 0); + get_desc(obj, desc, sizeof(desc)); + messagef(0, "dropped %s", desc); (void) reg_move(); } @@ -260,7 +259,10 @@ next_avail_ichar() } obj = rogue.pack.next_object; while (obj) { - ichars[(obj->ichar - 'a')] = 1; + if (obj->ichar >= 'a' && obj->ichar <= 'z') + ichars[(obj->ichar - 'a')] = 1; + else + clean_up("next_avail_ichar"); obj = obj->next_object; } for (i = 0; i < 26; i++) { @@ -286,17 +288,17 @@ pack_letter(prompt, mask) unsigned short tmask = mask; if (!mask_pack(&rogue.pack, mask)) { - message("nothing appropriate", 0); + messagef(0, "nothing appropriate"); return(CANCEL); } for (;;) { - message(prompt, 0); + messagef(0, "%s", prompt); for (;;) { ch = rgetchar(); if (!is_pack_letter(&ch, &mask)) { - sound_bell(); + beep(); } else { break; } @@ -323,19 +325,18 @@ take_off() if (rogue.armor) { if (rogue.armor->is_cursed) { - message(curse_message, 0); + messagef(0, "%s", curse_message); } else { mv_aquatars(); obj = rogue.armor; unwear(rogue.armor); - (void) strcpy(desc, "was wearing "); - get_desc(obj, desc+12); - message(desc, 0); + get_desc(obj, desc, sizeof(desc)); + messagef(0, "was wearing %s", desc); print_stats(STAT_ARMOR); (void) reg_move(); } } else { - message("not wearing any", 0); + messagef(0, "not wearing any"); } } @@ -347,7 +348,7 @@ wear() char desc[DCOLS]; if (rogue.armor) { - message("you're already wearing some", 0); + messagef(0, "you're already wearing some"); return; } ch = pack_letter("wear what?", ARMOR); @@ -356,17 +357,17 @@ wear() return; } if (!(obj = get_letter_object(ch))) { - message("no such item.", 0); + messagef(0, "no such item."); return; } if (obj->what_is != ARMOR) { - message("you can't wear that", 0); + messagef(0, "you can't wear that"); return; } obj->identified = 1; (void) strcpy(desc, "wearing "); - get_desc(obj, desc + 8); - message(desc, 0); + get_desc(obj, desc, sizeof(desc)); + messagef(0, "wearing %s", desc); do_wear(obj); print_stats(STAT_ARMOR); (void) reg_move(); @@ -399,7 +400,7 @@ wield() char desc[DCOLS]; if (rogue.weapon && rogue.weapon->is_cursed) { - message(curse_message, 0); + messagef(0, "%s", curse_message); return; } ch = pack_letter("wield what?", WEAPON); @@ -408,22 +409,20 @@ wield() return; } if (!(obj = get_letter_object(ch))) { - message("No such item.", 0); + messagef(0, "No such item."); return; } if (obj->what_is & (ARMOR | RING)) { - sprintf(desc, "you can't wield %s", + messagef(0, "you can't wield %s", ((obj->what_is == ARMOR) ? "armor" : "rings")); - message(desc, 0); return; } if (obj->in_use_flags & BEING_WIELDED) { - message("in use", 0); + messagef(0, "in use"); } else { unwield(rogue.weapon); - (void) strcpy(desc, "wielding "); - get_desc(obj, desc + 9); - message(desc, 0); + get_desc(obj, desc, sizeof(desc)); + messagef(0, "wielding %s", desc); do_wield(obj); (void) reg_move(); } @@ -461,11 +460,11 @@ call_it() return; } if (!(obj = get_letter_object(ch))) { - message("no such item.", 0); + messagef(0, "no such item."); return; } if (!(obj->what_is & (SCROL | POTION | WAND | RING))) { - message("surely you already know what that's called", 0); + messagef(0, "surely you already know what that's called"); return; } id_table = get_id_table(obj); @@ -473,7 +472,8 @@ call_it() if (get_input_line("call it:", "", buf, sizeof(buf), id_table[obj->which_kind].title, 1, 1)) { id_table[obj->which_kind].id_status = CALLED; - (void) strcpy(id_table[obj->which_kind].title, buf); + (void) strlcpy(id_table[obj->which_kind].title, buf, + sizeof(id_table[obj->which_kind].title)); } } @@ -569,23 +569,18 @@ kick_into_pack() { object *obj; char desc[DCOLS]; - short n, stat; + short stat; if (!(dungeon[rogue.row][rogue.col] & OBJECT)) { - message("nothing here", 0); + messagef(0, "nothing here"); } else { if ((obj = pick_up(rogue.row, rogue.col, &stat))) { - get_desc(obj, desc); + get_desc(obj, desc, sizeof(desc)); if (obj->what_is == GOLD) { - message(desc, 0); + messagef(0, "%s", desc); free_object(obj); } else { - n = strlen(desc); - desc[n] = '('; - desc[n+1] = obj->ichar; - desc[n+2] = ')'; - desc[n+3] = 0; - message(desc, 0); + messagef(0, "%s(%c)", desc, obj->ichar); } } if (obj || (!stat)) { -- cgit v1.2.3