Synopsis: Condensing multiple messages. February 97 From erwin@pip.dknet.dk Thu Mar 20 16:46:10 1997 To: MERC/Envy Mailing List Subject: Simple message condensing I have implemented a simple way to condense multiple identical messages that follow each other. Rather than seeing: A cityguard is here. A cityguard is here. You'd see: (x2) A cityguard is here. What I am doing is to remember the length of the last printed line via write_to_buffer: next time write_to_buffer is used, if the line of this new message matches the old one I compare it with the old message, and if it matches, I increase a counter and bail out, not appending the identical string. This works on one-line strings only, that are sent one line at the time: so it wouldn't for example condense two identical lines when a help file is displayed. If the message does not match, and the counter is more than 1, I change the last part of the buffer into "(x%d) %s" where %d is the repeat count and %s is the string. I also check for count > 1 in process_output. This is the rough code; you'll have to modify it to fit with your write_to_buffer: /* Check if we want to repeat */ if (d->last_len && d->last_len == length && d->outtop >= length) /* The strings have the same length: compare last length bytes in outbuf now */ if (!memcmp(buf, d->outbuf + d->outtop - length, length)) { d->last_count++; return; } /* Now that we know we have another string, check if there is an old string that needs to have its count data written */ if (d->last_count > 1) { /* We only allow this if we can do it without expanding the buffer */ if (d->outtop + 16 < d->outsize) { char new_buf[d->last_len + 16]; int len; len = sprintf (new_buf, "(x%d) ", d->last_count); memcpy (new_buf+len, d->outbuf + d->outtop - d->last_len, d->last_len); memcpy (d->outbuf + d->outtop - d->last_len, new_buf, len + d->last_len); d->outtop += len; } } d->last_count = 1; /* Only consider this if the string is not a multiline one */ if (real_len > 10 && newlines == 1) d->last_len = length; else d->last_len = 0; In process output, repeat the if (d->last_count) code and set d->last_len to 0. I should make this into a separate function, but I just added this today :P real_len is the length of the string without color; newlines is the number of \ns there. The variable-size array is gccism; it's not much different from char *new_buf = alloca(d->last_len+16); Tell me if you implement this and find it useful :) ============================================================================== Erwin Andreasen Viby J, Denmark Computer Science Student at Aarhus Business erwin@pip.dknet.dk College ==============================================================================