From 3bf32372e98dc14da37728993831a7ac40dc22f7 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Wed, 2 Nov 2011 23:30:11 +0000 Subject: [PATCH] Created new putmsg() mode flag: P_WORDWRAP and use it in show_msg() to wrap long lines in messages for the user's terminal. May be used for viewing other files with long lines (e.g. G-text files) in the future. --- src/sbbs3/getmsg.cpp | 2 +- src/sbbs3/putmsg.cpp | 14 +++++++++++++- src/sbbs3/sbbsdefs.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sbbs3/getmsg.cpp b/src/sbbs3/getmsg.cpp index 5c19dea0f8..2df549ab0c 100644 --- a/src/sbbs3/getmsg.cpp +++ b/src/sbbs3/getmsg.cpp @@ -188,7 +188,7 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode) if((text=smb_getmsgtxt(&smb,msg,GETMSGTXT_ALL))!=NULL) { truncsp_lines(text); - putmsg(text, mode); + putmsg(text, mode|P_WORDWRAP); smb_freemsgtxt(text); } } diff --git a/src/sbbs3/putmsg.cpp b/src/sbbs3/putmsg.cpp index a6c00acc59..87aef0dd61 100644 --- a/src/sbbs3/putmsg.cpp +++ b/src/sbbs3/putmsg.cpp @@ -47,9 +47,10 @@ /* the attributes prior to diplaying the message are always restored. */ /* Ignores Ctrl-Z's */ /****************************************************************************/ -char sbbs_t::putmsg(const char *str, long mode) +char sbbs_t::putmsg(const char *buf, long mode) { char tmpatr,tmp2[256],tmp3[128]; + char* str=buf; uchar exatr=0; int orgcon=console,i; ulong l=0,sys_status_sav=sys_status; @@ -63,6 +64,14 @@ char sbbs_t::putmsg(const char *str, long mode) sys_status|=SS_PAUSEOFF; if(mode&P_HTML) putcom("\x02\x02"); + if(mode&P_WORDWRAP) { + char *wrapped; + if((wrappped=::wordwrap(buf, cols-4, cols-1, /* handle_quotes */TRUE)) == NULL) + errormsg(WHERE,ERR_ALLOC,"wordwrap buffer",0); + else + str=wrapped; + } + while(str[l] && (mode&P_NOABORT || !msgabort()) && online) { if(str[l]==CTRL_A && str[l+1]!=0) { if(str[l+1]=='"' && !(sys_status&SS_NEST_PF)) { /* Quote a file */ @@ -280,6 +289,9 @@ char sbbs_t::putmsg(const char *str, long mode) pause(); } + if(str!=buf) /* malloc'd copy of buffer */ + free(str); + /* Restore original settings of Forced Pause On/Off */ sys_status&=~(SS_PAUSEOFF|SS_PAUSEON); sys_status|=(sys_status_sav&(SS_PAUSEOFF|SS_PAUSEON)); diff --git a/src/sbbs3/sbbsdefs.h b/src/sbbs3/sbbsdefs.h index 4c63ead0c5..50eb3b973e 100644 --- a/src/sbbs3/sbbsdefs.h +++ b/src/sbbs3/sbbsdefs.h @@ -698,6 +698,7 @@ typedef enum { /* Values for xtrn_t.event */ #define P_NOPAUSE (1<<4) /* Disable screen pause */ #define P_HTML (1<<5) /* Message is HTML */ #define P_NOCRLF (1<<6) /* Don't prepend a CRLF in printfile() */ +#define P_WORDWRAP (1<<7) /* Word-wrap long lines for user's terminal */ /* Bits in 'mode' for listfiles */ #define FL_ULTIME (1<<0) /* List files by upload time */ -- GitLab