Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit f650a5ed authored by Rob Swindell's avatar Rob Swindell 💬

Use reference rather than pointer to make putmsgfrag() more readable.

parent 29163914
......@@ -25,15 +25,15 @@
#include "petdefs.h"
#include "cp437defs.h"
char* sbbs_t::auto_utf8(const char* str, long* mode)
char* sbbs_t::auto_utf8(const char* str, long& mode)
{
if(strncmp(str, "\xEF\xBB\xBF", 3) == 0) {
*mode |= P_UTF8;
mode |= P_UTF8;
return (char*)(str + 3);
}
if((*mode)&P_AUTO_UTF8) {
if(mode & P_AUTO_UTF8) {
if(!str_is_ascii(str) && utf8_str_is_valid(str))
*mode |= P_UTF8;
mode |= P_UTF8;
}
return (char*)str;
}
......@@ -61,7 +61,7 @@ int sbbs_t::bputs(const char *str, long mode)
if(online==ON_LOCAL && console&CON_L_ECHO) /* script running as event */
return(lputs(LOG_INFO, str));
str = auto_utf8(str, &mode);
str = auto_utf8(str, mode);
size_t len = strlen(str);
while(l < len && online) {
switch(str[l]) {
......@@ -137,7 +137,7 @@ int sbbs_t::bputs(const char *str, long mode)
/****************************************************************************/
size_t sbbs_t::bstrlen(const char *str, long mode)
{
str = auto_utf8(str, &mode);
str = auto_utf8(str, mode);
size_t count = 0;
const char* end = str + strlen(str);
while (str < end) {
......
......@@ -131,7 +131,7 @@ bool sbbs_t::printfile(const char* fname, long mode, long org_cols, JSObject* ob
break;
if((mode&P_UTF8) && !term_supports(UTF8))
utf8_normalize_str(buf);
if(putmsgfrag(buf, &mode, org_cols, obj) != '\0') // early-EOF?
if(putmsgfrag(buf, mode, org_cols, obj) != '\0') // early-EOF?
break;
}
free(buf);
......
......@@ -64,7 +64,7 @@ char sbbs_t::putmsg(const char *buf, long mode, long org_cols, JSObject* obj)
if(mode&P_NOPAUSE)
sys_status|=SS_PAUSEOFF;
char ret = putmsgfrag(buf, &mode, org_cols, obj);
char ret = putmsgfrag(buf, mode, org_cols, obj);
if(!(mode&P_SAVEATR)) {
console=orgcon;
attr(tmpatr);
......@@ -84,7 +84,7 @@ char sbbs_t::putmsg(const char *buf, long mode, long org_cols, JSObject* obj)
}
// Print a message fragment, doesn't save/restore any console states (e.g. attributes, auto-pause)
char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* obj)
char sbbs_t::putmsgfrag(const char* buf, long& mode, long org_cols, JSObject* obj)
{
char tmp2[256],tmp3[128];
char* str=(char*)buf;
......@@ -102,13 +102,13 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
size_t len = strlen(str);
long term = term_supports();
if(!((*mode)&P_NOATCODES) && memcmp(str, "@WRAPOFF@", 9) == 0) {
(*mode) &= ~P_WORDWRAP;
if(!(mode&P_NOATCODES) && memcmp(str, "@WRAPOFF@", 9) == 0) {
mode &= ~P_WORDWRAP;
l += 9;
}
if((*mode)&P_WORDWRAP) {
if(mode&P_WORDWRAP) {
char* wrapoff = NULL;
if(!((*mode)&P_NOATCODES)) {
if(!(mode&P_NOATCODES)) {
wrapoff = strstr((char*)str+l, "@WRAPOFF@");
if(wrapoff != NULL)
*wrapoff = 0;
......@@ -117,11 +117,11 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
if(org_cols < TERM_COLS_MIN)
org_cols = TERM_COLS_DEFAULT;
if((wrapped=::wordwrap((char*)str+l, cols - 1, org_cols - 1, /* handle_quotes: */TRUE
,/* is_utf8: */INT_TO_BOOL((*mode)&P_UTF8))) == NULL)
,/* is_utf8: */INT_TO_BOOL(mode&P_UTF8))) == NULL)
errormsg(WHERE,ERR_ALLOC,"wordwrap buffer",0);
else {
truncsp_lines(wrapped);
(*mode) &= ~P_WORDWRAP;
mode &= ~P_WORDWRAP;
putmsgfrag(wrapped, mode);
free(wrapped);
l=strlen(str);
......@@ -130,7 +130,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
}
while(l < len && ((*mode)&P_NOABORT || !msgabort()) && online) {
while(l < len && (mode&P_NOABORT || !msgabort()) && online) {
switch(str[l]) {
case '\r':
case '\n':
......@@ -144,12 +144,12 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
// fallthrough
default: // printing char
if(((*mode) & P_INDENT) && column < col)
if((mode & P_INDENT) && column < col)
cursor_right(col - column);
else if(((*mode)&P_TRUNCATE) && column >= (cols - 1)) {
else if((mode&P_TRUNCATE) && column >= (cols - 1)) {
l++;
continue;
} else if((*mode)&P_WRAP) {
} else if(mode&P_WRAP) {
if(org_cols) {
if(column > (org_cols - 1)) {
CRLF;
......@@ -162,7 +162,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
break;
}
if((*mode) & P_MARKUP) {
if(mode & P_MARKUP) {
const char* marks = "*/_#";
if(((mark == 0) && strchr(marks, str[l]) != NULL) || str[l] == mark) {
char* next = NULL;
......@@ -182,7 +182,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
mark = str[l];
else {
mark = 0;
if(!((*mode) & P_HIDEMARKS))
if(!(mode & P_HIDEMARKS))
outchar(str[l]);
}
switch(str[l]) {
......@@ -199,7 +199,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
attr(((curatr&0x0f) << 4) | ((curatr&0xf0) >> 4));
break;
}
if(mark != 0 && !((*mode) & P_HIDEMARKS))
if(mark != 0 && !(mode & P_HIDEMARKS))
outchar(str[l]);
l++;
continue;
......@@ -207,7 +207,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
}
if(str[l]==CTRL_A && str[l+1]!=0) {
if(str[l+1]=='"' && !(sys_status&SS_NEST_PF) && !((*mode)&P_NOATCODES)) { /* Quote a file */
if(str[l+1]=='"' && !(sys_status&SS_NEST_PF) && !(mode&P_NOATCODES)) { /* Quote a file */
l+=2;
i=0;
while(i<(int)sizeof(tmp2)-1 && IS_PRINTABLE(str[l]) && str[l]!='\\' && str[l]!='/')
......@@ -241,7 +241,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
l+=2;
}
}
else if(!((*mode)&P_NOXATTRS)
else if(!(mode&P_NOXATTRS)
&& (cfg.sys_misc&SM_PCBOARD) && str[l]=='@' && str[l+1]=='X'
&& IS_HEXDIGIT(str[l+2]) && IS_HEXDIGIT(str[l+3])) {
sprintf(tmp2,"%.2s",str+l+2);
......@@ -262,7 +262,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
exatr=1;
l+=4;
}
else if(!((*mode)&P_NOXATTRS)
else if(!(mode&P_NOXATTRS)
&& (cfg.sys_misc&SM_WILDCAT) && str[l]=='@' && str[l+3]=='@'
&& IS_HEXDIGIT(str[l+1]) && IS_HEXDIGIT(str[l+2])) {
sprintf(tmp2,"%.2s",str+l+1);
......@@ -270,7 +270,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
// exatr=1;
l+=4;
}
else if(!((*mode)&P_NOXATTRS)
else if(!(mode&P_NOXATTRS)
&& (cfg.sys_misc&SM_RENEGADE) && str[l]=='|' && IS_DIGIT(str[l+1])
&& IS_DIGIT(str[l+2]) && !(useron.misc&RIP)) {
sprintf(tmp2,"%.2s",str+l+1);
......@@ -286,7 +286,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
exatr=1;
l+=3; /* Skip |xx */
}
else if(!((*mode)&P_NOXATTRS)
else if(!(mode&P_NOXATTRS)
&& (cfg.sys_misc&SM_CELERITY) && str[l]=='|' && IS_ALPHA(str[l+1])
&& !(useron.misc&RIP)) {
switch(str[l+1]) {
......@@ -345,7 +345,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
exatr=1;
l+=2; /* Skip |x */
} /* Skip second digit if it exists */
else if(!((*mode)&P_NOXATTRS)
else if(!(mode&P_NOXATTRS)
&& (cfg.sys_misc&SM_WWIV) && str[l]==CTRL_C && IS_DIGIT(str[l+1])) {
exatr=1;
switch(str[l+1]) {
......@@ -403,7 +403,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
if(str[l]=='!' && str[l+1]=='|' && useron.misc&RIP) /* RIP */
lncntr=0; /* so defeat pause */
if(str[l]=='@' && !((*mode)&P_NOATCODES)) {
if(str[l]=='@' && !(mode&P_NOATCODES)) {
if(memcmp(str+l, "@EOF@", 5) == 0)
break;
if(memcmp(str+l, "@CLEAR@", 7) == 0) {
......@@ -436,17 +436,17 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
if(memcmp(str+l, "@WORDWRAP@", 10) == 0) {
l += 10;
(*mode) |= P_WORDWRAP;
mode |= P_WORDWRAP;
return putmsgfrag(str+l, mode, org_cols);
}
if(memcmp(str+l, "@QON@", 5) == 0) { // Allow the file display to be aborted (PCBoard)
l += 5;
(*mode) &= ~P_NOABORT;
mode &= ~P_NOABORT;
continue;
}
if(memcmp(str+l, "@QOFF@", 6) == 0) { // Do not allow the display of teh file to be aborted (PCBoard)
l += 6;
(*mode) |= P_NOABORT;
mode |= P_NOABORT;
continue;
}
bool was_tos = (row == 0);
......@@ -457,7 +457,7 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
if(i) /* if valid string, go to top */
continue;
}
if((*mode)&P_CPM_EOF && str[l]==CTRL_Z)
if(mode&P_CPM_EOF && str[l]==CTRL_Z)
break;
if(hot_attr) {
if(curatr == hot_attr && str[l] > ' ') {
......@@ -473,12 +473,12 @@ char sbbs_t::putmsgfrag(const char* buf, long* mode, long org_cols, JSObject* ob
}
}
size_t skip = sizeof(char);
if((*mode)&P_PETSCII) {
if(mode&P_PETSCII) {
if(term&PETSCII)
outcom(str[l]);
else
petscii_to_ansibbs(str[l]);
} else if((str[l]&0x80) && ((*mode)&P_UTF8)) {
} else if((str[l]&0x80) && (mode&P_UTF8)) {
if(term&UTF8)
outcom(str[l]);
else
......
......@@ -736,7 +736,7 @@ public:
char* quotes_fname(int xedit, char* buf, size_t len);
char* msg_tmp_fname(int xedit, char* fname, size_t len);
char putmsg(const char *str, long mode, long org_cols = 0, JSObject* obj = NULL);
char putmsgfrag(const char* str, long* mode, long org_cols = 0, JSObject* obj = NULL);
char putmsgfrag(const char* str, long& mode, long org_cols = 0, JSObject* obj = NULL);
bool msgabort(void);
bool email(int usernumber, const char *top = NULL, const char *title = NULL
, long mode = WM_NONE, smb_t* resmb = NULL, smbmsg_t* remsg = NULL);
......@@ -851,7 +851,7 @@ public:
size_t print_utf8_as_cp437(const char*, size_t);
int attr(int); /* Change text color/attributes */
void ctrl_a(char); /* Performs Ctrl-Ax attribute changes */
char* auto_utf8(const char*, long* mode);
char* auto_utf8(const char*, long& mode);
enum output_rate {
output_rate_unlimited,
output_rate_300 = 300,
......
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