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