|
@@ -133,7 +133,7 @@ static void hexspan(char *buf, int bufsize, const char *str) {
|
|
|
}
|
|
|
|
|
|
#define TAG_LEN 40
|
|
|
-static void b(char * const str) {
|
|
|
+static void colorize_noalloc(char * const str) {
|
|
|
char *token = strtok(str, "^");
|
|
|
char c;
|
|
|
while (token) {
|
|
@@ -162,6 +162,16 @@ static void b(char * const str) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void sanitize(char *user_name) {
|
|
|
+ if (user_name == NULL) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ char *pos = user_name;
|
|
|
+ while (pos = strstr(pos, "^^")) {
|
|
|
+ strcpy(pos, (pos + 1));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void print_plname(const char* str) {
|
|
|
//find instance of ^^
|
|
|
//replace with ^
|
|
@@ -169,16 +179,17 @@ void print_plname(const char* str) {
|
|
|
char *copy;
|
|
|
copy = calloc(strlen(str) + 1, sizeof(char));
|
|
|
strcpy(copy, str);
|
|
|
- char *pos = copy;
|
|
|
- while (pos = strstr(pos, "^^")) {
|
|
|
- strcpy(pos, (pos + 1));
|
|
|
- }
|
|
|
- b(copy);
|
|
|
+ sanitize(copy);
|
|
|
+ colorize_noalloc(copy);
|
|
|
fflush(stdout);
|
|
|
free(copy);
|
|
|
}
|
|
|
|
|
|
static char* append_to_str(char *dest, const char *src) {
|
|
|
+ if (dest == NULL || src == NULL) {
|
|
|
+ fprintf(stderr, "append_to_str(): warning - received null ptr" );
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
size_t new_len = strlen(dest) + strlen(src) + 1;
|
|
|
char *new_str = realloc(dest, new_len);
|
|
|
if (new_str != NULL) {
|
|
@@ -222,6 +233,13 @@ char* colorize_name(char *buf, /*int bufsize,*/ char * const str) {
|
|
|
return buf;
|
|
|
}
|
|
|
|
|
|
+/* test:
|
|
|
+
|
|
|
+./colors ^9[^1S^9]^x469Kom^0ier^7
|
|
|
+./colors ^9[^1S^9]^^x469Kom^0ier^7
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
#ifdef COLORS4PYTHON
|
|
|
int main(int argc, const char **argv) {
|
|
|
if (argc < 1) {
|
|
@@ -230,6 +248,7 @@ int main(int argc, const char **argv) {
|
|
|
char *colored = (char*)calloc(strlen(argv[1]) + 1, sizeof(char));
|
|
|
char *player_name = (char*)calloc(strlen(argv[1]) + 1, sizeof(char));
|
|
|
strcpy(player_name, argv[1]);
|
|
|
+ sanitize(player_name);
|
|
|
|
|
|
colored = colorize_name(colored, /*sizeof(colored),*/ player_name);
|
|
|
fprintf(stdout, "%s\n", colored);
|