X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/a07de2b816b2a6d7b25bffefd1239db80d85f6d7..af314729a412f4936a44bcfabe14d34c3b152a82:/rogue/message.c diff --git a/rogue/message.c b/rogue/message.c index 20d4e3da..e38377de 100644 --- a/rogue/message.c +++ b/rogue/message.c @@ -1,4 +1,4 @@ -/* $NetBSD: message.c,v 1.9 2002/10/01 14:18:57 mrg Exp $ */ +/* $NetBSD: message.c,v 1.14 2009/08/12 08:44:45 dholland Exp $ */ /* * Copyright (c) 1988, 1993 @@ -15,11 +15,7 @@ * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)message.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: message.c,v 1.9 2002/10/01 14:18:57 mrg Exp $"); +__RCSID("$NetBSD: message.c,v 1.14 2009/08/12 08:44:45 dholland Exp $"); #endif #endif /* not lint */ @@ -59,18 +55,23 @@ __RCSID("$NetBSD: message.c,v 1.9 2002/10/01 14:18:57 mrg Exp $"); #include #include +#include #include "rogue.h" +#include "pathnames.h" -char msgs[NMESSAGES][DCOLS] = {"", "", "", "", ""}; -short msg_col = 0, imsg = -1; -boolean msg_cleared = 1, rmsg = 0; +static char msgs[NMESSAGES][DCOLS] = {"", "", "", "", ""}; +static short msg_col = 0, imsg = -1; +static boolean rmsg = 0; + +boolean msg_cleared = 1; char hunger_str[HUNGER_STR_LEN] = ""; const char *more = "-more-"; +static void save_screen(void); + +static void -message(msg, intrpt) - const char *msg; - boolean intrpt; +message(const char *msg, boolean intrpt) { cant_int = 1; @@ -90,7 +91,7 @@ message(msg, intrpt) } if (!rmsg) { imsg = (imsg + 1) % NMESSAGES; - (void) strcpy(msgs[imsg], msg); + (void)strlcpy(msgs[imsg], msg, sizeof(msgs[imsg])); } mvaddstr(MIN_ROW-1, 0, msg); addch(' '); @@ -107,8 +108,20 @@ message(msg, intrpt) } void -remessage(c) - short c; +messagef(boolean intrpt, const char *fmt, ...) +{ + va_list ap; + char buf[DCOLS]; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + message(buf, intrpt); +} + +void +remessage(short c) { if (imsg != -1) { check_message(); @@ -124,7 +137,7 @@ remessage(c) } void -check_message() +check_message(void) { if (msg_cleared) { return; @@ -136,29 +149,27 @@ check_message() } int -get_input_line(prompt, insert, buf, if_cancelled, add_blank, do_echo) - const char *prompt, *insert; - char *buf; - const char *if_cancelled; - boolean add_blank; - boolean do_echo; +get_input_line(const char *prompt, const char *insert, + char *buf, size_t buflen, + const char *if_cancelled, + boolean add_blank, boolean do_echo) { short ch; - short i = 0, n; + size_t i = 0, n; message(prompt, 0); n = strlen(prompt); if (insert[0]) { mvaddstr(0, n + 1, insert); - (void) strcpy(buf, insert); - i = strlen(insert); + (void)strlcpy(buf, insert, buflen); + i = strlen(buf); move(0, (n + i + 1)); refresh(); } while (((ch = rgetchar()) != '\r') && (ch != '\n') && (ch != CANCEL)) { - if ((ch >= ' ') && (ch <= '~') && (i < MAX_TITLE_LENGTH-2)) { + if ((ch >= ' ') && (ch <= '~') && (i < buflen-2)) { if ((ch != ' ') || (i > 0)) { buf[i++] = ch; if (do_echo) { @@ -196,7 +207,7 @@ get_input_line(prompt, insert, buf, if_cancelled, add_blank, do_echo) } int -rgetchar() +rgetchar(void) { int ch; @@ -204,11 +215,11 @@ rgetchar() ch = getchar(); switch(ch) { - case '\022': + case '\022': /* ^R */ wrefresh(curscr); break; #ifdef UNIX_BSD4_2 - case '\032': + case '\032': /* ^Z */ printf("%s", CL); fflush(stdout); tstp(); @@ -229,8 +240,7 @@ Level: 99 Gold: 999999 Hp: 999(999) Str: 99(99) Arm: 99 Exp: 21/10000000 Hungry */ void -print_stats(stat_mask) - int stat_mask; +print_stats(int stat_mask) { char buf[16]; boolean label; @@ -243,9 +253,7 @@ print_stats(stat_mask) mvaddstr(row, 0, "Level: "); } /* max level taken care of in make_level() */ - sprintf(buf, "%d", cur_level); - mvaddstr(row, 7, buf); - pad(buf, 2); + mvprintw(row, 7, "%-2d", cur_level); } if (stat_mask & STAT_GOLD) { if (label) { @@ -254,9 +262,7 @@ print_stats(stat_mask) if (rogue.gold > MAX_GOLD) { rogue.gold = MAX_GOLD; } - sprintf(buf, "%ld", rogue.gold); - mvaddstr(row, 16, buf); - pad(buf, 6); + mvprintw(row, 16, "%-6ld", rogue.gold); } if (stat_mask & STAT_HP) { if (label) { @@ -266,9 +272,9 @@ print_stats(stat_mask) rogue.hp_current -= (rogue.hp_max - MAX_HP); rogue.hp_max = MAX_HP; } - sprintf(buf, "%d(%d)", rogue.hp_current, rogue.hp_max); - mvaddstr(row, 27, buf); - pad(buf, 8); + snprintf(buf, sizeof(buf), "%d(%d)", + rogue.hp_current, rogue.hp_max); + mvprintw(row, 27, "%-8s", buf); } if (stat_mask & STAT_STRENGTH) { if (label) { @@ -278,10 +284,9 @@ print_stats(stat_mask) rogue.str_current -= (rogue.str_max - MAX_STRENGTH); rogue.str_max = MAX_STRENGTH; } - sprintf(buf, "%d(%d)", (rogue.str_current + add_strength), - rogue.str_max); - mvaddstr(row, 41, buf); - pad(buf, 6); + snprintf(buf, sizeof(buf), "%d(%d)", + (rogue.str_current + add_strength), rogue.str_max); + mvprintw(row, 41, "%-6s", buf); } if (stat_mask & STAT_ARMOR) { if (label) { @@ -290,9 +295,7 @@ print_stats(stat_mask) if (rogue.armor && (rogue.armor->d_enchant > MAX_ARMOR)) { rogue.armor->d_enchant = MAX_ARMOR; } - sprintf(buf, "%d", get_armor_class(rogue.armor)); - mvaddstr(row, 53, buf); - pad(buf, 2); + mvprintw(row, 53, "%-2d", get_armor_class(rogue.armor)); } if (stat_mask & STAT_EXP) { if (label) { @@ -304,9 +307,9 @@ print_stats(stat_mask) if (rogue.exp > MAX_EXP_LEVEL) { rogue.exp = MAX_EXP_LEVEL; } - sprintf(buf, "%d/%ld", rogue.exp, rogue.exp_points); - mvaddstr(row, 61, buf); - pad(buf, 11); + snprintf(buf, sizeof(buf), "%d/%ld", + rogue.exp, rogue.exp_points); + mvprintw(row, 61, "%-11s", buf); } if (stat_mask & STAT_HUNGER) { mvaddstr(row, 73, hunger_str); @@ -315,38 +318,22 @@ print_stats(stat_mask) refresh(); } -void -pad(s, n) - const char *s; - short n; -{ - short i; - - for (i = strlen(s); i < n; i++) { - addch(' '); - } -} - -void -save_screen() +static void +save_screen(void) { FILE *fp; short i, j; char buf[DCOLS+2]; - boolean found_non_blank; - if ((fp = fopen("rogue.screen", "w")) != NULL) { + if ((fp = fopen(_PATH_SCREENDUMP, "w")) != NULL) { for (i = 0; i < DROWS; i++) { - found_non_blank = 0; - for (j = (DCOLS - 1); j >= 0; j--) { + for (j=0; j0 && buf[j-1]==' '; j--); + buf[j] = 0; + fputs(buf, fp); putc('\n', fp); } @@ -357,24 +344,20 @@ save_screen() } void -sound_bell() +sound_bell(void) { putchar(7); fflush(stdout); } boolean -is_digit(ch) - short ch; +is_digit(int ch) { return((ch >= '0') && (ch <= '9')); } int -r_index(str, ch, last) - const char *str; - int ch; - boolean last; +r_index(const char *str, int ch, boolean last) { int i = 0;