Adjustment to joining to work around server not always including space.
authorEric Mullins <emwine@earthlink.net>
Thu, 15 Oct 2009 22:54:51 +0000 (16:54 -0600)
committerEric Mullins <emwine@earthlink.net>
Thu, 15 Oct 2009 22:54:51 +0000 (16:54 -0600)
This patch implements commit 98aa02bda540f17f1f50be00e494efafe439b004
into the updated joining routine.  This issue seems not to be server
variance, but instead the server electing to omit the space between
words when it occurs at exactly your width setting (-1 actually).

This patch makes the joiner add back the space just like the referenced
commit.  Note: this is just a workaround to a server issue-- the joiner
actually joins correctly before this patch.

backend.c

index 0bbe876..e197f00 100755 (executable)
--- a/backend.c
+++ b/backend.c
@@ -2055,9 +2055,9 @@ read_from_ics(isr, closure, data, count, error)
     static char buf[BUF_SIZE + 1];
     static int firstTime = TRUE, intfSet = FALSE;
     static ColorClass prevColor = ColorNormal;
-    static int savingComment = FALSE;\r
-       static int cmatch = 0; // continuation sequence match\r
-       char *bp;
+    static int savingComment = FALSE;
+    static int cmatch = 0; // continuation sequence match
+    char *bp;
     char str[500];
     int i, oldi;
     int buf_len;
@@ -2088,53 +2088,67 @@ read_from_ics(isr, closure, data, count, error)
              buf[i] = buf[leftover_start + i];
        }
 
-    /* copy new characters into the buffer */\r
-    bp = buf + leftover_len;\r
-    buf_len=leftover_len;\r
-    for (i=0; i<count; i++)\r
-    {\r
-        // ignore these\r
-        if (data[i] == '\r')\r
-            continue;\r
-\r
-        // join lines split by ICS?\r
-        if (!appData.noJoin)\r
-        {\r
-            /*\r
-                Joining just consists of finding matches against the\r
-                continuation sequence, and discarding that sequence\r
-                if found instead of copying it.  So, until a match\r
-                fails, there's nothing to do since it might be the\r
-                complete sequence, and thus, something we don't want\r
-                copied.\r
-            */\r
-            if (data[i] == cont_seq[cmatch])\r
-            {\r
-                cmatch++;\r
-                if (cmatch == strlen(cont_seq))\r
-                    cmatch = 0; // complete match.  just reset the counter\r
-                continue;\r
-            }\r
-            else if (cmatch)\r
-            {\r
-                /*\r
-                    match failed, so we have to copy what matched before\r
-                    falling through and copying this character.  In reality,\r
-                    this will only ever be just the newline character, but\r
-                    it doesn't hurt to be precise.\r
-                */\r
-                strncpy(bp, cont_seq, cmatch);\r
-                bp += cmatch;\r
-                buf_len += cmatch;\r
-                cmatch = 0;\r
-            }\r
-        }\r
-\r
-        // copy this char\r
-        *bp++ = data[i];\r
-        buf_len++;\r
-    }\r
-\r
+    /* copy new characters into the buffer */
+    bp = buf + leftover_len;
+    buf_len=leftover_len;
+    for (i=0; i<count; i++)
+    {
+        // ignore these
+        if (data[i] == '\r')
+            continue;
+
+        // join lines split by ICS?
+        if (!appData.noJoin)
+        {
+            /*
+                Joining just consists of finding matches against the
+                continuation sequence, and discarding that sequence
+                if found instead of copying it.  So, until a match
+                fails, there's nothing to do since it might be the
+                complete sequence, and thus, something we don't want
+                copied.
+            */
+            if (data[i] == cont_seq[cmatch])
+            {
+                cmatch++;
+                if (cmatch == strlen(cont_seq))
+                {
+                    cmatch = 0; // complete match.  just reset the counter
+
+                    /*
+                        it's possible for the ICS to not include the space
+                        at the end of the last word, making our [correct]
+                        join operation fuse two separate words.  the server
+                        does this when the space occurs at the width setting.
+                    */
+                    if (!buf_len || buf[buf_len-1] != ' ')
+                    {
+                        *bp++ = ' ';
+                        buf_len++;
+                    }
+                }
+                continue;
+            }
+            else if (cmatch)
+            {
+                /*
+                    match failed, so we have to copy what matched before
+                    falling through and copying this character.  In reality,
+                    this will only ever be just the newline character, but
+                    it doesn't hurt to be precise.
+                */
+                strncpy(bp, cont_seq, cmatch);
+                bp += cmatch;
+                buf_len += cmatch;
+                cmatch = 0;
+            }
+        }
+
+        // copy this char
+        *bp++ = data[i];
+        buf_len++;
+    }
+
        buf[buf_len] = NULLCHAR;
        next_out = leftover_len;
        leftover_start = 0;