diff --git a/src/sbbs3/wordwrap.c b/src/sbbs3/wordwrap.c index f5c753950f3eabf093309349c07f14c272e70bcc..a8be6487bb076223bceb0c714e4cb2ca7209fd2d 100644 --- a/src/sbbs3/wordwrap.c +++ b/src/sbbs3/wordwrap.c @@ -278,6 +278,7 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags) break; } if(0) { // This is a very ugly thing... figure this out before editing!!! + BOOL ignore=FALSE; case '\n': if(!lf_break) { if(i==0) @@ -285,78 +286,81 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags) if(inbuf[i-1] != '\r') { if(l==0 || isspace(linebuf[l-1])) break; + ignore=TRUE; } } - if(handle_quotes && (quote_count=get_prefix(inbuf+i+1, &prefix_bytes, &prefix_len, len*2+2))!=0) { - /* Move the input pointer offset to the last char of the prefix */ - i+=prefix_bytes; - } - if(!inbuf[i+1]) { /* EOF */ - linebuf[l++]='\r'; - linebuf[l++]='\n'; - outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); - l=0; - ocol=1; - } - /* If there's a new prefix, it is a hardcr */ - else if(compare_prefix(prefix, old_prefix_bytes, inbuf+i+1-prefix_bytes, prefix_bytes)!=0) { - if(prefix_len>len/3*2) { - /* This prefix is insane (more than 2/3rds of the new width) hack it down to size */ - /* Since we're hacking it, we will always end up with a hardcr on this line. */ - /* ToDo: Something prettier would be nice. */ - sprintf(prefix," %d> ",quote_count); - prefix_len=strlen(prefix); - prefix_bytes=strlen(prefix); + if(!ignore) { + if(handle_quotes && (quote_count=get_prefix(inbuf+i+1, &prefix_bytes, &prefix_len, len*2+2))!=0) { + /* Move the input pointer offset to the last char of the prefix */ + i+=prefix_bytes; } - else { - memcpy(prefix,inbuf+i+1-prefix_bytes,prefix_bytes); - /* Terminate prefix */ - prefix[prefix_bytes]=0; + if(!inbuf[i+1]) { /* EOF */ + linebuf[l++]='\r'; + linebuf[l++]='\n'; + outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); + l=0; + ocol=1; } - linebuf[l++]='\r'; - linebuf[l++]='\n'; - outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); - memcpy(linebuf,prefix,prefix_bytes); - l=prefix_bytes; - ocol=prefix_len+1; - old_prefix_bytes=prefix_bytes; - } - else if(isspace((unsigned char)inbuf[i+1]) && inbuf[i+1] != '\n' && inbuf[i+1] != '\r') { /* Next line starts with whitespace. This is a "hard" CR. */ - linebuf[l++]='\r'; - linebuf[l++]='\n'; - outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); - l=prefix_bytes; - ocol=prefix_len+1; - } - else { - if(icol < oldlen) { /* If this line is overly long, It's impossible for the next word to fit */ - /* k will equal the length of the first word on the next line */ - for(k=0; inbuf[i+1+k] && (!isspace((unsigned char)inbuf[i+1+k])); k++); - if(icol+k+1 < oldlen) { /* The next word would have fit but isn't here. Must be a hard CR */ - linebuf[l++]='\r'; - linebuf[l++]='\n'; - outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); - if(prefix) - memcpy(linebuf,prefix,prefix_bytes); - l=prefix_bytes; - ocol=prefix_len+1; + /* If there's a new prefix, it is a hardcr */ + else if(compare_prefix(prefix, old_prefix_bytes, inbuf+i+1-prefix_bytes, prefix_bytes)!=0) { + if(prefix_len>len/3*2) { + /* This prefix is insane (more than 2/3rds of the new width) hack it down to size */ + /* Since we're hacking it, we will always end up with a hardcr on this line. */ + /* ToDo: Something prettier would be nice. */ + sprintf(prefix," %d> ",quote_count); + prefix_len=strlen(prefix); + prefix_bytes=strlen(prefix); } - else { /* Not a hard CR... add space if needed */ + else { + memcpy(prefix,inbuf+i+1-prefix_bytes,prefix_bytes); + /* Terminate prefix */ + prefix[prefix_bytes]=0; + } + linebuf[l++]='\r'; + linebuf[l++]='\n'; + outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); + memcpy(linebuf,prefix,prefix_bytes); + l=prefix_bytes; + ocol=prefix_len+1; + old_prefix_bytes=prefix_bytes; + } + else if(isspace((unsigned char)inbuf[i+1]) && inbuf[i+1] != '\n' && inbuf[i+1] != '\r') { /* Next line starts with whitespace. This is a "hard" CR. */ + linebuf[l++]='\r'; + linebuf[l++]='\n'; + outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); + l=prefix_bytes; + ocol=prefix_len+1; + } + else { + if(icol < oldlen) { /* If this line is overly long, It's impossible for the next word to fit */ + /* k will equal the length of the first word on the next line */ + for(k=0; inbuf[i+1+k] && (!isspace((unsigned char)inbuf[i+1+k])); k++); + if(icol+k+1 < oldlen) { /* The next word would have fit but isn't here. Must be a hard CR */ + linebuf[l++]='\r'; + linebuf[l++]='\n'; + outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size); + if(prefix) + memcpy(linebuf,prefix,prefix_bytes); + l=prefix_bytes; + ocol=prefix_len+1; + } + else { /* Not a hard CR... add space if needed */ + if(l<1 || !isspace((unsigned char)linebuf[l-1])) { + linebuf[l++]=' '; + ocol++; + } + } + } + else { /* Not a hard CR... add space if needed */ if(l<1 || !isspace((unsigned char)linebuf[l-1])) { linebuf[l++]=' '; ocol++; } } } - else { /* Not a hard CR... add space if needed */ - if(l<1 || !isspace((unsigned char)linebuf[l-1])) { - linebuf[l++]=' '; - ocol++; - } - } + icol=prefix_len+1; + break; } - icol=prefix_len+1; - break; } // This is where the ugly referenced above finishes. default: if(inbuf[i]=='\n')