Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -1006,6 +1006,7 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1006,6 +1006,7 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist)
char* outbuf; char* outbuf;
JSString* js_str; JSString* js_str;
jsrefcount rc; jsrefcount rc;
uint32_t flags=0;
JS_SET_RVAL(cx, arglist, JSVAL_VOID); JS_SET_RVAL(cx, arglist, JSVAL_VOID);
...@@ -1026,12 +1027,14 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist) ...@@ -1026,12 +1027,14 @@ js_word_wrap(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE; return JS_FALSE;
} }
if(argc>3 && JSVAL_IS_BOOLEAN(argv[3])) if(argc>3 && JSVAL_IS_BOOLEAN(argv[3])) {
handle_quotes=JSVAL_TO_BOOLEAN(argv[3]); if(JSVAL_TO_BOOLEAN(argv[3]))
flags |= WORDWRAP_FLAG_QUOTES;
}
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
outbuf=wordwrap(inbuf, len, oldlen, handle_quotes); outbuf=wordwrap(inbuf, len, oldlen, flags);
JS_RESUMEREQUEST(cx, rc); JS_RESUMEREQUEST(cx, rc);
......
...@@ -67,7 +67,7 @@ char sbbs_t::putmsg(const char *buf, long mode) ...@@ -67,7 +67,7 @@ char sbbs_t::putmsg(const char *buf, long mode)
putcom("\x02\x02"); putcom("\x02\x02");
if(mode&P_WORDWRAP) { if(mode&P_WORDWRAP) {
char *wrapped; 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); errormsg(WHERE,ERR_ALLOC,"wordwrap buffer",0);
else else
str=wrapped; str=wrapped;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <ctype.h> #include <ctype.h>
#include <genwrap.h> #include <genwrap.h>
#include <stdlib.h> /* realloc */ #include <stdlib.h> /* realloc */
#include <stdbool.h>
#include "wordwrap.h" #include "wordwrap.h"
static int get_prefix(const char *text, int *bytes, int *len, int maxlen) 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 ...@@ -168,8 +169,10 @@ static int compare_prefix(char *old_prefix, int old_prefix_bytes, const char *ne
return(0); 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 l;
int crcount=0; int crcount=0;
long i,k,t; long i,k,t;
...@@ -241,6 +244,12 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes) ...@@ -241,6 +244,12 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
crcount++; crcount++;
break; break;
case '\n': 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) { 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 */ /* Move the input pointer offset to the last char of the prefix */
i+=prefix_bytes; i+=prefix_bytes;
......
...@@ -91,7 +91,7 @@ void sbbs_t::quotemsg(smbmsg_t* msg, int tails) ...@@ -91,7 +91,7 @@ void sbbs_t::quotemsg(smbmsg_t* msg, int tails)
if((buf=smb_getmsgtxt(&smb,msg,tails)) != NULL) { if((buf=smb_getmsgtxt(&smb,msg,tails)) != NULL) {
strip_invalid_attr(buf); strip_invalid_attr(buf);
if(useron.xedit && (cfg.xedit[useron.xedit-1]->misc&QUOTEWRAP)) 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) { if(wrapped!=NULL) {
fputs(wrapped,fp); fputs(wrapped,fp);
free(wrapped); free(wrapped);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment