Page Length

From: John Evans (evansj@HI-LINE.NET)
Date: 02/09/98


A couple of people asked for this, so here it is:
NOTE: Some lines are wrapped because of my mailer. I hand-wrapped them so
that they would make sense, and compile correctly for those of you that
are going to do the copy/paste routine with this code.

Now that I think of it, I'm tempted to stick a mem-leak bug in here just
to screw with those people that copy/paste everything and randomly crash
their MUD. Nah... I'll be nice and not do that. copy/paste away in safety
and brainless coding. No harm (that I know of) will befall your system by
using this code.

To make it so that each person can set their own page lengths, I did:

in act.other.c
---------
ACMD(do_pager)
{
  skip_spaces(&argument);

  if (!*argument) {
    send_to_charf(ch, "Your current page break is at %d lines.\r\n",
                  GET_PAGE_LENGTH(ch));
    return;
  }

  one_argument(argument, arg);

  if (isalpha(*arg)) {
    send_to_char("Usage: pager [number]\r\n", ch);
    return;
  }
  GET_PAGE_LENGTH(ch) = MAX(5, MIN(100, atoi(arg)));
  send_to_charf(ch, "Page break set to %d lines.\r\n",
                GET_PAGE_LENGTH(ch));
}
---------

I prototyped the ACMD() in interpreter.c and added the command 'pager' to
the Master Command List

I changed one of the ubyte spares in the player_special_data_saved to
page_length.

I added the following to utils.h:
#define GET_PAGE_LENGTH(ch)     ((ch)->player_specials->saved.page_length)

in db.c/init_char(), I added a line like so:
  GET_PAGE_LENGTH(ch) = 20;


All of the above let people set their lengths and added to the MUD. The
next step was to use the new data.

All the rest of the changes are in modify.c.

I removed the #define PAGE_LENGTH line. Not needed anymore.

------
Changes to next_page():
Old: char *next_page(char *str)
New: char *next_page(char *str, ubyte page_length)

Old: else if (line > PAGE_LENGTH)
Old: else if (line > page_length)
------
Changes to count_pages()
Old: int count_pages(char *str)
New: int count_pages(char *str, ubyte page_length)

Old: for (pages = 1; (str = next_page(str)); pages++);
New: for (pages = 1; (str = next_page(str, page_length)); pages++);
------
Changes to paginate_string()
Old: str = d->showstr_vector[i] = next_page(str);
New: str = d->showstr_vector[i] = next_page(str,
                                  GET_PAGE_LENGTH(d->character));
------
Changes to page_string()
Old: CREATE(d->showstr_vector, char *,
            d->showstr_count = count_pages(str));
New: CREATE(d->showstr_vector, char *,
     d->showstr_count = count_pages(str, GET_PAGE_LENGTH(d->character)));
------

That should be it!

Highly useful and would suggest sticking it bpl13. *hint, hint*  :)

John Evans <evansj@hi-line.net>  --  http://www.hi-line.net/~evansj/

Any sufficiently advanced technology is indistinguishable from magic.
--Arthur C. Clarke


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST