Commit 62b2e592 authored by rswindell's avatar rswindell
Browse files

At Deuce's request, revert his change:

"Change the last argument of wordwrap() to a flags argument and support
making a bare LF not be ignored."
If soft line breaks (bare LFs) are stored in the message base, they're
expected to wrapped for 80-column terminal only.
parent 765e8141
......@@ -1034,7 +1034,6 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist)
char* outbuf;
JSString* js_str;
jsrefcount rc;
uint32_t flags=0;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -1055,14 +1054,12 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
if(argc>3 && JSVAL_IS_BOOLEAN(argv[3])) {
if(JSVAL_TO_BOOLEAN(argv[3]))
flags |= WORDWRAP_FLAG_QUOTES;
}
if(argc>3 && JSVAL_IS_BOOLEAN(argv[3]))
handle_quotes = JSVAL_TO_BOOLEAN(argv[3]);
rc=JS_SUSPENDREQUEST(cx);
outbuf=wordwrap(inbuf, len, oldlen, flags);
outbuf=wordwrap(inbuf, len, oldlen, handle_quotes);
JS_RESUMEREQUEST(cx, rc);
......
......@@ -67,7 +67,7 @@ char sbbs_t::putmsg(const char *buf, long mode)
putcom("\x02\x02");
if(mode&P_WORDWRAP) {
char *wrapped;
if((wrapped=::wordwrap((char*)buf, cols, 79, WORDWRAP_FLAG_QUOTES)) == NULL)
if((wrapped=::wordwrap((char*)buf, cols, 79, /* handle_quotes: */TRUE)) == NULL)
errormsg(WHERE,ERR_ALLOC,"wordwrap buffer",0);
else {
truncsp_lines(wrapped);
......
......@@ -168,10 +168,8 @@ static int compare_prefix(char *old_prefix, int old_prefix_bytes, const char *ne
return(0);
}
char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
{
BOOL handle_quotes=flags&WORDWRAP_FLAG_QUOTES;
BOOL lf_break=flags&WORDWRAP_FLAG_BARELF;
int l;
int crcount=0;
long i,k,t;
......@@ -181,7 +179,6 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
char* outp;
char* linebuf;
char* prefix=NULL;
char ch;
int prefix_len=0;
int prefix_bytes=0;
int quote_count=0;
......@@ -243,6 +240,77 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
case '\r':
crcount++;
break;
case '\n':
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);
}
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++;
}
}
}
icol=prefix_len+1;
break;
case '\x1f': /* Delete... meaningless... strip. */
break;
case '\b': /* Backspace... handle if possible, but don't go crazy. */
......@@ -277,97 +345,8 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
linebuf[l++]=inbuf[i];
break;
}
if(0) // This is a very ugly thing... figure this out before editing!!!
// See that brace? It's IMPORTANT!
case '\n': {
BOOL ignore=FALSE;
if(!lf_break) {
if(i==0)
break;
if(inbuf[i-1] != '\r') {
if(l==0 || isspace(linebuf[l-1]))
break;
ignore=TRUE;
}
}
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;
}
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);
}
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++;
}
}
}
icol=prefix_len+1;
break;
}
} // This is where the ugly referenced above finishes.
default:
if(inbuf[i]=='\n')
linebuf[l++]=' ';
else
linebuf[l++]=inbuf[i];
linebuf[l++]=inbuf[i];
ocol++;
icol++;
if(ocol>len && !isspace((unsigned char)inbuf[i])) { /* Need to wrap here */
......
......@@ -34,16 +34,11 @@
#ifndef _WORDWRAP_H_
#define _WORDWRAP_H_
#include "gen_defs.h" // uint32_t
#define WORDWRAP_FLAG_QUOTES (1<<0) // Handle quote prefixes
#define WORDWRAP_FLAG_BARELF (1<<1) // Treat bare LFs as a line break
#ifdef __cplusplus
extern "C" {
#endif
char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags);
char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes);
#ifdef __cplusplus
}
......
......@@ -91,7 +91,7 @@ void sbbs_t::quotemsg(smbmsg_t* msg, int tails)
if((buf=smb_getmsgtxt(&smb,msg,tails)) != NULL) {
strip_invalid_attr(buf);
if(useron.xedit && (cfg.xedit[useron.xedit-1]->misc&QUOTEWRAP))
wrapped=::wordwrap(buf, cols-4, cols-1, WORDWRAP_FLAG_QUOTES);
wrapped=::wordwrap(buf, cols-4, cols-1, /* handle_quotes: */TRUE);
if(wrapped!=NULL) {
fputs(wrapped,fp);
free(wrapped);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment