(2*) Code Test

From: George (greerga@MIAVX1.ACS.MUOHIO.EDU)
Date: 07/22/97


Here's the current patch I'm working on for (2*) code.  The patch as it is
can handle all the way up to the size of an integer (2.1billion*) without
problems. The only known problem is with color.  If you play without color,
you will not have problems, if you play with color you will experience
minor color bleeding and a phantom (2*) at the end of every room title.

Otherwise:

500H 100M 82V > i
You are carrying:
(30*)a pair of wings
500H 100M 82V >

500H 100M 82V > g all
(7*)A bug: you can't take that!
500H 100M 82V >

500H 100M 82V > drop all
(34*)You drop a pair of wings.
500H 100M 82V >
(12*)Bob gets a pair of wings.
500H 100M 82V >

> wear all
You wear a pair of wings on your head.
(11*)You're already wearing something on your head.
>

etc

The Patch:

diff -uprN -x *.o ../stk/comm.c ./comm.c
--- ../stk/comm.c       Thu Jun 19 00:58:36 1997
+++ ./comm.c    Tue Jul 22 14:39:17 1997
@@ -912,12 +912,40 @@ void flush_queues(struct descriptor_data
 void write_to_output(const char *txt, struct descriptor_data *t)
 {
   int size;
+  char *twox;

   size = strlen(txt);

   /* if we're in the overflow state already, ignore this new output */
-  if (t->bufptr < 0)
+  if (t->bufptr < 0 || !txt || !*txt)
     return;
+
+  if ((twox = strstr(t->output, txt)) && *twox) {
+    if (*(twox - 1) == ')' && *(twox - 2) == '*') { // Already (x*)
+      int number, bufdiff;
+      char *pbegin, *digit = malloc(14);
+      char *new2x = str_dup(twox);
+
+      for (pbegin = twox; *pbegin != '(' && pbegin != t->output; pbegin--);
+      bufdiff = twox - pbegin;
+      sscanf(pbegin, "(%d*)%*s", &number);
+      sprintf(digit, "(%d*)", number + 1);
+      strcpy(pbegin, digit);
+      strcat(pbegin, new2x);
+      bufdiff = strlen(digit) - bufdiff;
+      t->bufspace -= number;
+      t->bufptr += number;
+      free(new2x);
+      free(digit);
+    } else if (*twox) {
+      char *new2x = str_dup(twox);
+      sprintf(twox, "(2*)%s", new2x);
+      t->bufspace -= 4;
+      t->bufptr += 4;
+      free(new2x);
+    }
+    return;
+  }

   /* if we have enough space, just write to buffer and that's it! */
   if (t->bufspace >= size) {


-George

Thanks to Dan Stagner for the motivation.

PS - It has been tested, but there are probly oversights.


     +------------------------------------------------------------+
     | 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/08/00 PST