[BUG][STOCK][CODE] prompt for pager in compact mode sometimes overwrites last line of page

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 04/21/01


Note the following code in next_page():

      /* We need to check here and see if we are over the page width,
       * and if so, compensate by going to the begining of the next line.
       */
      else if (col++ > PAGE_WIDTH) {
        col = 1;
        line++;
      }

The unfortunate result of this is that if the last line of the page is
longer than PAGE_WIDTH and the compact flag is set then that portion of
the line displayed at the end of the page will be overwritten by the
prompt (this is because the paging code relies on the \r\n which is
normally at the end of the line but not there in the case when the line
is longer than the page width).  Unless the compact flag is set this
would normally not be a large issue because an extra \r\n is added before
the prompt anyways, but this is not the case if the compact flag is set.

The solution is actually a change in show_string() which checks for a
\r\n at the end of the page (well, it only really tests for the \n if you
want it to do a full check that's possible, but I don't think it will be
an issue and hence it's probably not worth it) and tacks one on if needed
as follows (note, tested to compile, but no running test and diffed
against CVS from today, note that some lines in the diff will be wrapped
by my email client, fix those before applying the patch)...

Index: modify.c
===================================================================
RCS file: /home/circledb/cvs/circle/src/modify.c,v
retrieving revision 1.23
diff -u -p -u -p -r1.23 modify.c
--- modify.c    2001/01/26 00:50:43     1.23
+++ modify.c    2001/04/22 03:23:51
@@ -427,10 +427,26 @@ void show_string(struct descriptor_data
   /* Or if we have more to show.... */
   else {
     diff = d->showstr_vector[d->showstr_page + 1] -
d->showstr_vector[d->showstr_page];
-    if (diff >= MAX_STRING_LENGTH)
-      diff = MAX_STRING_LENGTH - 1;
+    if (diff > MAX_STRING_LENGTH - 3) /* 3=\r\n\0 */
+      diff = MAX_STRING_LENGTH - 3;
     strncpy(buffer, d->showstr_vector[d->showstr_page], diff);
-    buffer[diff] = '\0';
+
+    /*
+     * Fix for prompt overwriting last line in compact mode submitted by
+     * Peter Ajamian <peter@pajamian.dhs.org> on 04/21/2001
+     */
+    if (buffer[diff-2] == '\r' && buffer[diff-1]=='\n')
+      buffer[diff] = '\0';
+    else if (buffer[diff-2] == '\n' && buffer[diff-1] == '\r')
+      /* This is backwards.  Fix it. */
+      strcpy(buffer+diff-2, "\r\n");
+    else if (buffer[diff-1] == '\r' || buffer[diff-1] == '\n')
+      /* Just one of \r\n.  Overwrite it. */
+      strcpy(buffer+diff-1, "\r\n");
+    else
+      /* Tack \r\n onto the end to fix bug with prompt overwriting last
line. */
+      strcpy(buffer+diff, "\r\n");
+
     send_to_char(buffer, d->character);
     d->showstr_page++;
   }

--
   +---------------------------------------------------------------+
   | 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/05/01 PST