Commit d6d4c993 authored by deuce's avatar deuce
Browse files

Change the last argument of wordwrap() to a flags argument and support

making a bare LF not be ignored.

This effectively breaks the CR counting code... so... yeah.
parent aeaa191f
......@@ -1006,6 +1006,7 @@ 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);
......@@ -1026,12 +1027,14 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
if(argc>3 && JSVAL_IS_BOOLEAN(argv[3]))
handle_quotes=JSVAL_TO_BOOLEAN(argv[3]);
if(argc>3 && JSVAL_IS_BOOLEAN(argv[3])) {
if(JSVAL_TO_BOOLEAN(argv[3]))
flags |= WORDWRAP_FLAG_QUOTES;
}
rc=JS_SUSPENDREQUEST(cx);
outbuf=wordwrap(inbuf, len, oldlen, handle_quotes);
outbuf=wordwrap(inbuf, len, oldlen, flags);
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-4, cols-1, /* handle_quotes */TRUE)) == NULL)
if((wrapped=::wordwrap((char*)buf, cols-4, cols-1, WORDWRAP_FLAG_QUOTES)) == NULL)
errormsg(WHERE,ERR_ALLOC,"wordwrap buffer",0);
else
str=wrapped;
......
......@@ -34,6 +34,7 @@
#include <ctype.h>
#include <genwrap.h>
#include <stdlib.h> /* realloc */
#include <stdbool.h>
#include "wordwrap.h"
static int get_prefix(const char *text, int *bytes, int *len, int maxlen)
......@@ -168,8 +169,10 @@ static int compare_prefix(char *old_prefix, int old_prefix_bytes, const char *ne
return(0);
}
char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
char* wordwrap(char* inbuf, int len, int oldlen, uint32_t flags)
{
bool handle_quotes=flags&WORDWRAP_FLAG_QUOTES;
bool lf_break=flags&WORDWRAP_FLAG_BARELF;
int l;
int crcount=0;
long i,k,t;
......@@ -241,6 +244,12 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
crcount++;
break;
case '\n':
if(!lf_break) {
if(i==0)
break;
if(inbuf[i-1] != '\r')
break;
}
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;
......
......@@ -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, /* handle_quotes */TRUE);
wrapped=::wordwrap(buf, cols-4, cols-1, WORDWRAP_FLAG_QUOTES);
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