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,54 +240,7 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
case '\r':
crcount++;
break;
case '\x1f': /* Delete... meaningless... strip. */
break;
case '\b': /* Backspace... handle if possible, but don't go crazy. */
if(l>0) {
if(l>1 && linebuf[l-2]=='\x01') {
if(linebuf[l-1]=='\x01') {
ocol--;
icol--;
}
l-=2;
}
else {
l--;
ocol--;
icol--;
}
}
break;
case '\t': /* TAB */
linebuf[l++]=inbuf[i];
/* Can't ever wrap on whitespace remember. */
icol++;
ocol++;
while(ocol%8)
ocol++;
while(icol%8)
icol++;
break;
case '\x01': /* CTRL-A */
linebuf[l++]=inbuf[i++];
if(inbuf[i]!='\x01') {
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) {
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;
......@@ -361,12 +311,41 @@ char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
}
icol=prefix_len+1;
break;
case '\x1f': /* Delete... meaningless... strip. */
break;
case '\b': /* Backspace... handle if possible, but don't go crazy. */
if(l>0) {
if(l>1 && linebuf[l-2]=='\x01') {
if(linebuf[l-1]=='\x01') {
ocol--;
icol--;
}
l-=2;
}
else {
l--;
ocol--;
icol--;
}
}
break;
case '\t': /* TAB */
linebuf[l++]=inbuf[i];
/* Can't ever wrap on whitespace remember. */
icol++;
ocol++;
while(ocol%8)
ocol++;
while(icol%8)
icol++;
break;
case '\x01': /* CTRL-A */
linebuf[l++]=inbuf[i++];
if(inbuf[i]!='\x01') {
linebuf[l++]=inbuf[i];
break;
}
} // This is where the ugly referenced above finishes.
default:
if(inbuf[i]=='\n')
linebuf[l++]=' ';
else
linebuf[l++]=inbuf[i];
ocol++;
icol++;
......
......@@ -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