Skip to content
Snippets Groups Projects
Commit 0e1c9b2c authored by rswindell's avatar rswindell
Browse files

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.
parent b7aa230a
No related branches found
No related tags found
No related merge requests found
...@@ -37,65 +37,6 @@ ...@@ -37,65 +37,6 @@
#include "sbbs.h" #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 */ /* Redraws str using i as current cursor position and l as length */
/****************************************************************************/ /****************************************************************************/
......
...@@ -482,8 +482,6 @@ public: ...@@ -482,8 +482,6 @@ public:
uint uselect_total, uselect_num[500]; uint uselect_total, uselect_num[500];
void riosync(char abortable); void riosync(char abortable);
bool validattr(char a);
int stripattr(char *str);
void redrwstr(char *strin, int i, int l, long mode); void redrwstr(char *strin, int i, int l, long mode);
void attr(int atr); /* Change local and remote text attributes */ void attr(int atr); /* Change local and remote text attributes */
void ctrl_a(char x); /* Peforms the Ctrl-Ax attribute changes */ void ctrl_a(char x); /* Peforms the Ctrl-Ax attribute changes */
...@@ -777,6 +775,9 @@ extern "C" { ...@@ -777,6 +775,9 @@ extern "C" {
DLLEXPORT char * DLLCALL strip_ctrl(char *str); DLLEXPORT char * DLLCALL strip_ctrl(char *str);
DLLEXPORT char * DLLCALL net_addr(net_t* net); DLLEXPORT char * DLLCALL net_addr(net_t* net);
DLLEXPORT ushort DLLCALL crc16(char *str); DLLEXPORT ushort DLLCALL crc16(char *str);
DLLEXPORT BOOL DLLCALL validattr(char a);
DLLEXPORT size_t DLLCALL strip_invalid_attr(char *str);
/* date_str.c */ /* date_str.c */
DLLEXPORT char * DLLCALL zonestr(short zone); DLLEXPORT char * DLLCALL zonestr(short zone);
......
...@@ -390,3 +390,61 @@ ushort DLLCALL crc16(char *str) ...@@ -390,3 +390,61 @@ ushort DLLCALL crc16(char *str)
return(crc); 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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment