From 0e1c9b2c37687e6c72e839811bb9617124c345eb Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Tue, 6 Aug 2002 03:38:54 +0000 Subject: [PATCH] Moved validattr() and stripattr() [renamed to strip_invalid_attr] from con_hi.cpp to str_util.c. strip_invalid_attr now supports strings up to 1K in length. --- src/sbbs3/con_hi.cpp | 59 -------------------------------------------- src/sbbs3/sbbs.h | 5 ++-- src/sbbs3/str_util.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/sbbs3/con_hi.cpp b/src/sbbs3/con_hi.cpp index b51959f904..fb19c17af1 100644 --- a/src/sbbs3/con_hi.cpp +++ b/src/sbbs3/con_hi.cpp @@ -37,65 +37,6 @@ #include "sbbs.h" -/****************************************************************************/ -/* Returns 1 if a is a valid ctrl-a code, 0 if it isn't. */ -/****************************************************************************/ -bool sbbs_t::validattr(char a) -{ - - switch(toupper(a)) { - case '-': /* clear */ - case '_': /* clear */ - case 'B': /* blue fg */ - case 'C': /* cyan fg */ - case 'G': /* green fg */ - case 'H': /* high fg */ - case 'I': /* blink */ - case 'K': /* black fg */ - case 'L': /* cls */ - case 'M': /* magenta fg */ - case 'N': /* normal */ - case 'P': /* pause */ - case 'R': /* red fg */ - case 'W': /* white fg */ - case 'Y': /* yellow fg */ - case '0': /* black bg */ - case '1': /* red bg */ - case '2': /* green bg */ - case '3': /* brown bg */ - case '4': /* blue bg */ - case '5': /* magenta bg */ - case '6': /* cyan bg */ - case '7': /* white bg */ - return(true); } - return(false); -} - -/****************************************************************************/ -/* Strips invalid Ctrl-Ax sequences from str */ -/* Returns number of ^A's in line */ -/****************************************************************************/ -int sbbs_t::stripattr(char *strin) -{ - char str[256]; - uint a,c,d,e; - - e=strlen(strin); - for(a=c=d=0;c<e && d<sizeof(str)-1;c++) { - if(strin[c]==CTRL_A && strin[c+1]!=0) { - a++; - if(!validattr(strin[c+1])) { - c++; - continue; - } - } - str[d++]=strin[c]; - } - str[d]=0; - strcpy(strin,str); - return(a); -} - /****************************************************************************/ /* Redraws str using i as current cursor position and l as length */ /****************************************************************************/ diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 00a869b74d..0f713ca717 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -482,8 +482,6 @@ public: uint uselect_total, uselect_num[500]; void riosync(char abortable); - bool validattr(char a); - int stripattr(char *str); void redrwstr(char *strin, int i, int l, long mode); void attr(int atr); /* Change local and remote text attributes */ void ctrl_a(char x); /* Peforms the Ctrl-Ax attribute changes */ @@ -777,6 +775,9 @@ extern "C" { DLLEXPORT char * DLLCALL strip_ctrl(char *str); DLLEXPORT char * DLLCALL net_addr(net_t* net); DLLEXPORT ushort DLLCALL crc16(char *str); + DLLEXPORT BOOL DLLCALL validattr(char a); + DLLEXPORT size_t DLLCALL strip_invalid_attr(char *str); + /* date_str.c */ DLLEXPORT char * DLLCALL zonestr(short zone); diff --git a/src/sbbs3/str_util.c b/src/sbbs3/str_util.c index 3d82379f30..2eb16ed489 100644 --- a/src/sbbs3/str_util.c +++ b/src/sbbs3/str_util.c @@ -390,3 +390,61 @@ ushort DLLCALL crc16(char *str) return(crc); } +/****************************************************************************/ +/* Returns 1 if a is a valid ctrl-a code, 0 if it isn't. */ +/****************************************************************************/ +BOOL validattr(char a) +{ + + switch(toupper(a)) { + case '-': /* clear */ + case '_': /* clear */ + case 'B': /* blue fg */ + case 'C': /* cyan fg */ + case 'G': /* green fg */ + case 'H': /* high fg */ + case 'I': /* blink */ + case 'K': /* black fg */ + case 'L': /* cls */ + case 'M': /* magenta fg */ + case 'N': /* normal */ + case 'P': /* pause */ + case 'R': /* red fg */ + case 'W': /* white fg */ + case 'Y': /* yellow fg */ + case '0': /* black bg */ + case '1': /* red bg */ + case '2': /* green bg */ + case '3': /* brown bg */ + case '4': /* blue bg */ + case '5': /* magenta bg */ + case '6': /* cyan bg */ + case '7': /* white bg */ + return(TRUE); + } + return(FALSE); +} + +/****************************************************************************/ +/* Strips invalid Ctrl-Ax sequences from str */ +/* Returns number of ^A's in line */ +/****************************************************************************/ +size_t strip_invalid_attr(char *strin) +{ + char str[1024]; + size_t a,c,d; + + for(a=c=d=0;strin[c] && d<sizeof(str)-1;c++) { + if(strin[c]==CTRL_A && strin[c+1]!=0) { + a++; + if(!validattr(strin[c+1])) { + c++; + continue; + } + } + str[d++]=strin[c]; + } + str[d]=0; + strcpy(strin,str); + return(a); +} -- GitLab