Commit 48d31b27 authored by rswindell's avatar rswindell
Browse files

Define and use a new getstr() mode flag: K_TRIM, to trim white-space

from both ends of the input string automatically and disallow (ignore)
more than one consecutive space character mid-string.
The returned value is still the non-trimmed string length - perhaps that
should be changed.
parent b127f7c4
......@@ -136,7 +136,7 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
}
if(ch==TAB && (mode&K_TAB || (!(mode&K_WRAP) && history == NULL))) /* TAB same as CR */
break;
if(!i && mode&K_UPRLWR && (ch==' ' || ch==TAB))
if(!i && (mode&(K_UPRLWR|K_TRIM)) && (ch==' ' || ch==TAB))
continue; /* ignore beginning white space if upper/lower */
if(mode&K_E71DETECT && (uchar)ch==(CR|0x80) && l>1) {
if(strstr(str1,"")) {
......@@ -566,6 +566,8 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
return(x);
}
if(i<maxlen && ch>=' ') {
if(ch==' ' && (mode&K_TRIM) && i && str1[i-1] == ' ')
continue;
if(mode&K_UPRLWR) {
if(!i || (i && (str1[i-1]==' ' || str1[i-1]=='-'
|| str1[i-1]=='.' || str1[i-1]=='_')))
......@@ -606,6 +608,8 @@ size_t sbbs_t::getstr(char *strout, size_t maxlen, long mode, const str_list_t h
str1[l]=0;
if(!(sys_status&SS_ABORT)) {
strcpy(strout,str1);
if(mode&K_TRIM)
truncsp(strout);
if((strip_invalid_attr(strout) || console&CON_INSERT) && !(mode&K_NOECHO))
redrwstr(strout,i,l,K_MSG);
}
......
......@@ -141,7 +141,7 @@ BOOL sbbs_t::newuser()
useron.alias[0]=0;
kmode=(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL;
kmode=(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL|K_TRIM;
if(!(cfg.uq&UQ_NOUPRLWR))
kmode|=K_UPRLWR;
......
......@@ -173,7 +173,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
i=FIDO_NAME_LEN-1;
if(cfg.sub[subnum]->misc&(SUB_PNET|SUB_INET))
i=60;
getstr(touser,i,K_LINE|K_EDIT|K_AUTODEL);
getstr(touser,i,K_LINE|K_EDIT|K_AUTODEL|K_TRIM);
if(stricmp(touser,"ALL")
&& !(cfg.sub[subnum]->misc&(SUB_PNET|SUB_FIDO|SUB_QNET|SUB_INET|SUB_ANON))) {
if(cfg.sub[subnum]->misc&SUB_NAME) {
......@@ -350,12 +350,8 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
&& (text[TagMessageQ][0]==0 || !noyes(text[TagMessageQ]))) {
char tags[64] = "";
bputs(text[TagMessagePrompt]);
if(getstr(tags, sizeof(tags)-1, K_LINE)) {
truncsp(tags);
char* p = tags;
SKIP_WHITESPACE(p);
if(*p)
smb_hfield_str(&msg, SMB_TAGS, p);
if(getstr(tags, sizeof(tags)-1, K_LINE|K_TRIM)) {
smb_hfield_str(&msg, SMB_TAGS, tags);
}
}
......
......@@ -732,6 +732,7 @@ typedef enum { /* Values for xtrn_t.event */
#define K_USEOFFSET (1L<<20) /* Use getstr_offset for cursor position */
#define K_NOSPIN (1L<<21) /* Do not honor the user's spinning cursor */
#define K_ANSI_CPR (1L<<22) /* Expect ANSI Cursor Position Report */
#define K_TRIM (1L<<23) /* Trimmed white-space */
/* Bits in 'mode' for putmsg and printfile */
#define P_NOABORT (1<<0) /* Disallows abortion of a message */
......
......@@ -401,7 +401,7 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, long mode,
max_title_len=cols-column-1;
if(max_title_len > LEN_TITLE)
max_title_len = LEN_TITLE;
if(!getstr(subj,max_title_len,mode&WM_FILE ? K_LINE : K_LINE|K_EDIT|K_AUTODEL)
if(!getstr(subj,max_title_len,mode&WM_FILE ? K_LINE|K_TRIM : K_LINE|K_EDIT|K_AUTODEL|K_TRIM)
&& useron_level && useron.logons) {
free(buf);
return(false);
......@@ -958,7 +958,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
free(str[line]);
if(title[0]) {
bputs(text[SubjectPrompt]);
getstr(title,LEN_TITLE,K_LINE|K_EDIT|K_AUTODEL);
getstr(title,LEN_TITLE,K_LINE|K_EDIT|K_AUTODEL|K_TRIM);
SYNC;
CRLF;
}
......
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