Re: buf, buf1, buf2, arg: J J & E

From: Juliano Ravasi Ferraz (jferraz@linkway.com.br)
Date: 07/23/01


George Greer said:
> (...)
> So as judge, jury, and executioner, I say good riddance:
>
>         http://www.circlemud.org/~greerga/working/RIPbuffer.patch (~400kB)

I'm very happy with the decision. But there is a few things that I
should suggest, as ideas:


1. The names MAX_STRING_LENGTH, MAX_INPUT_LENGTH, MAX_RAW_INPUT_LENGTH,
among others are a pain to write.  Look to the space they took of the
above line... :-P  What to use some easy-to-write ones, line BUFSZ,
INPUTSZ, etc, with the well-explained comments around each #define?


2. Not a big issue: What to change the name of send_to_char() to
something like ch_printf(), to show up to the programmer that he/she is
using a printf-like function? This can avoid a programmer doing a thing
like this:

ACMD(do_myecho) {
  ...
  send_to_char(tch, argument);
  ...
}


3. A send_to_char()-like function should remain, just in cases like that
(i use this widely on the source code of my mud):

ACMD(do_foo) {
  const char *usage = "Usage: foo [parm] [parm]\r\n";

  ...
  if (!*arg) {
    ch_print(ch, usage);   /* not a printf!! */
    return;
  }
  ...
}

Just to avoid % parsing where they are not expected to happen... My be
just a macro like:  #define ch_print(a, b) send_to_char(a, "%s", b)


4. Use of dynamic buffers (like the one from Peter Ajamin, found on the
contrib), for most things. This will reduce the headache when outputing
lists, and avoid buffer overflows. This avoid the need to check to
overflow on the fixed-size buffers. And, also, the MAX_STRING_LENGTH can
be reduced to 2048, or even less, just because they will be used to just
one-line output format, like:

{
  dynamic_buffer dynbuf;

  bufinit(&dynbuf);

  sprintf(buf, "%s %s\r\n", var, var);
  bufcat(&dynbuf, buf);
  sprintf(buf, "%s %s\r\n", var, var);
  bufcat(&dynbuf, buf);
  ...
}

-> dynamic_buffer is a typedef to the structure used for the dynamic
buffer;
-> bufinit() initiates the structure (ISO C doesn't have constructors..
:-( );
-> bufcat() measures the length of buf, adds to the length of the
dynbuf, reallocates the char array (in increments of a fixed-size) and
catenate the string.
-> page_string() needs a special flag to free the dynamic buffer when
leaving the pager.


Regards,

Juliano Ravasi Ferraz.

--
[Please insert a quarter in Drive A: for the next tagline.]

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST