| 70 |
|
} |
| 71 |
|
|
| 72 |
|
/* |
| 73 |
– |
* clean_string - clean up a string possibly containing garbage |
| 74 |
– |
* |
| 75 |
– |
* *sigh* Before the kiddies find this new and exciting way of |
| 76 |
– |
* annoying opers, lets clean up what is sent to local opers |
| 77 |
– |
* -Dianora |
| 78 |
– |
*/ |
| 79 |
– |
char * |
| 80 |
– |
clean_string(char* dest, const unsigned char* src, size_t len) |
| 81 |
– |
{ |
| 82 |
– |
char* d = dest; |
| 83 |
– |
assert(0 != dest); |
| 84 |
– |
assert(0 != src); |
| 85 |
– |
|
| 86 |
– |
if(dest == NULL || src == NULL) |
| 87 |
– |
return NULL; |
| 88 |
– |
|
| 89 |
– |
len -= 3; /* allow for worst case, '^A\0' */ |
| 90 |
– |
|
| 91 |
– |
while (*src && (len > 0)) |
| 92 |
– |
{ |
| 93 |
– |
if (*src & 0x80) /* if high bit is set */ |
| 94 |
– |
{ |
| 95 |
– |
*d++ = '.'; |
| 96 |
– |
--len; |
| 97 |
– |
} |
| 98 |
– |
else if (!IsPrint(*src)) /* if NOT printable */ |
| 99 |
– |
{ |
| 100 |
– |
*d++ = '^'; |
| 101 |
– |
--len; |
| 102 |
– |
*d++ = 0x40 + *src; /* turn it into a printable */ |
| 103 |
– |
} |
| 104 |
– |
else |
| 105 |
– |
*d++ = *src; |
| 106 |
– |
++src, --len; |
| 107 |
– |
} |
| 108 |
– |
*d = '\0'; |
| 109 |
– |
return dest; |
| 110 |
– |
} |
| 111 |
– |
|
| 112 |
– |
/* |
| 73 |
|
* strip_tabs(dst, src, length) |
| 74 |
|
* |
| 75 |
|
* Copies src to dst, while converting all \t (tabs) into spaces. |