--- deliantra/server/common/readable.C 2009/10/15 16:00:37 1.42 +++ deliantra/server/common/readable.C 2009/10/15 20:45:01 1.43 @@ -33,7 +33,6 @@ #include #include - /* Define this if you want to archive book titles by contents. * This option should enforce UNIQUE combinations of titles,authors and * msg contents during and *between* game sessions. @@ -572,8 +571,7 @@ /* nstrtok() - simple routine to return the number of list * items in buf1 as separated by the value of buf2 */ - -int +static int nstrtok (const char *buf1, const char *buf2) { char *tbuf, sbuf[12], buf[MAX_BUF]; @@ -596,8 +594,7 @@ * a list of strings delimited by buf2. Then returns a comma * separated string w/ decent punctuation. */ - -char * +static char * strtoktolin (const char *buf1, const char *buf2) { int maxi, i = nstrtok (buf1, buf2); @@ -624,16 +621,14 @@ return (char *) rbuf; } -int +static int book_overflow (const char *buf1, const char *buf2, int booksize) { - if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ || buf_overflow (buf1, buf2, booksize)) return 1; - return 0; - + return 0; } /***************************************************************************** @@ -832,7 +827,6 @@ * this sets book book->name based on msgtype given. What name * is given is based on various criteria */ - static void new_text_name (object *book, int msgtype) { @@ -994,7 +988,7 @@ #define MAX_TITLE_CHECK 20 -void +static void change_book (object *book, int msgtype) { int nbr = sizeof (book_descrpt) / sizeof (char *); @@ -1128,7 +1122,6 @@ * Changed 971225 to be greater than equal to level passed. Also * made choosing by level more random. */ - object * get_random_mon (int level) { @@ -1196,16 +1189,15 @@ * Returns a description of the monster. This really needs to be * redone, as describe_item really gives a pretty internal description. */ - -char * +static const char * mon_desc (const object *mon) { - static char retbuf[HUGE_BUF]; + static dynbuf_text buf; buf.clear (); - sprintf (retbuf, " *** %s ***\n", &mon->name); - strcat (retbuf, describe_item (mon, NULL)); + buf.printf (" *** %s ***\n", &mon->name); + buf << describe_item (mon, 0); - return retbuf; + return buf; } @@ -1213,8 +1205,7 @@ * found, it returns NULL (changed 0.94.3 to do this, since the * calling function (mon_info_msg) seems to expect that. */ - -object * +static object * get_next_mon (object *tmp) { objectlink *mon; @@ -1233,21 +1224,16 @@ } - - /* mon_info_msg() - generate a message detailing the properties * of a randomly selected monster. */ - -char * +static const char * mon_info_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; - char tmpbuf[HUGE_BUF]; - object *tmp; + static dynbuf_text buf; buf.clear (); /*preamble */ - strcpy (retbuf, "This beastiary contains:"); + buf << "This beastiary contains:\n"; /* lets print info on as many monsters as will fit in our * document. @@ -1256,27 +1242,17 @@ * of text! (and flood out the available number of titles * in the archive in a snap!) -b.t. */ - tmp = get_random_mon (level * 3); - while (tmp) + object *tmp = get_random_mon (level * 3); + while (tmp && buf.size () < BOOK_BUF) { /* monster description */ - sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); - - if (!book_overflow (retbuf, tmpbuf, booksize)) - strcat (retbuf, tmpbuf); - else - break; + buf.printf ("\n%s\n", mon_desc (tmp)); /* Note that the value this returns is not based on level */ tmp = get_next_mon (tmp); } -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n mon_info_msg() created string: %d\n", strlen (retbuf)); - LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); -#endif - - return retbuf; + return buf; } @@ -1287,7 +1263,7 @@ /* artifact_msg() - generate a message detailing the properties * of 1-6 artifacts drawn sequentially from the artifact list. */ -const char * +static const char * artifact_msg (int level, int booksize) { artifactlist *al = NULL; @@ -1421,8 +1397,7 @@ * incantations/prayers (and some of their properties) belonging to * a given spellpath. */ - -char * +static char * spellpath_msg (int level, int booksize) { static char retbuf[BOOK_BUF]; @@ -1485,7 +1460,7 @@ /* formula_msg() - generate a message detailing the properties * of a randomly selected alchemical formula. */ -void +static void make_formula_book (object *book, int level) { char retbuf[BOOK_BUF], title[MAX_BUF]; @@ -1615,7 +1590,7 @@ /* god_info_msg() - generate a message detailing the properties * of a random god. Used by the book hack. b.t. */ -const char * +static const char * god_info_msg (int level, int booksize) { static char retbuf[BOOK_BUF];