cvs: php4 /ext/ircg ircg.c
| From: | Sascha Schumann | Date: | Thu, 16 Nov 2000 01:24:25 +0000 |
| Subject: | cvs: php4 /ext/ircg ircg.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-2632@lists.php.net to get a copy of this message | ||
sas Wed Nov 15 17:24:25 2000 EDT
Modified files:
/php4/ext/ircg ircg.c
Log:
Add mIRC-style color handling
http://www.mirc.co.uk/help/color.txt
http://www.ircle.com/colorfaq.html
Index: php4/ext/ircg/ircg.c
diff -u php4/ext/ircg/ircg.c:1.4 php4/ext/ircg/ircg.c:1.5
--- php4/ext/ircg/ircg.c:1.4 Wed Nov 15 15:38:46 2000
+++ php4/ext/ircg/ircg.c Wed Nov 15 17:24:25 2000
@@ -116,12 +116,102 @@
free(conn);
}
+static const char *color_list[] = {
+ "white",
+ "black",
+ "blue",
+ "green",
+ "red",
+ "brown",
+ "purple",
+ "orange",
+ "yellow",
+ "lightgreen",
+ "teal",
+ "lightcyan",
+ "lightblue",
+ "pink",
+ "gray",
+ "lightgrey"
+};
+
+static void mirc_color(const char *input, smart_str *result)
+{
+ int mode = 0;
+ char *p, c;
+ int fg, bg;
+ int font_open = 0;
+
+ for (p = input; (c = *p); p++) {
+ switch (mode) {
+ case 0:
+evaluate_normal:
+ if (c == '') {
+ mode = 1;
+ bg = fg = -1;
+ } else {
+ if (font_open) {
+ smart_str_appends_ex(result, "</FONT>", 1);
+ font_open = 0;
+ }
+ if (fg >= 0 && fg <= 15) {
+ smart_str_appends_ex(result, "<FONT COLOR=\"", 1);
+ smart_str_appends_ex(result, color_list[fg], 1);
+ smart_str_appends_ex(result, "\">", 1);
+ font_open = 1;
+ }
+ smart_str_appendc_ex(result, c, 1);
+ }
+ break;
+ case 1:
+ if (isdigit(c)) {
+ if (fg == -1) fg = 0;
+ fg = fg * 10 + c - '0';
+ if (fg > 10)
+ mode = 2;
+ } else {
+ mode = 0;
+ goto evaluate_normal;
+ }
+ break;
+ case 2:
+ if (c == ',') {
+ mode = 3;
+ } else {
+ mode = 0;
+ goto evaluate_normal;
+ }
+ break;
+ case 3:
+ if (isdigit(c)) {
+ if (bg == -1) bg = 0;
+ bg = bg * 10 + c - '0';
+ if (bg > 10)
+ mode = 0;
+ } else {
+ mode = 0;
+ goto evaluate_normal;
+ }
+ break;
+ }
+ }
+ if (font_open) {
+ smart_str_appends_ex(result, "</FONT>", 1);
+ font_open = 0;
+ }
+}
+
static void format_msg(const char *fmt, const char *channel, const char *to, const char *from,
const char *msg, smart_str *result)
{
const char *p;
char c;
int mode = 0;
+ smart_str new_msg = {0};
+ if (msg) {
+ mirc_color(msg, &new_msg);
+ }
+
for (p = fmt; (c = *p); p++) {
switch (mode) {
case 0:
@@ -148,7 +238,7 @@
smart_str_appends_ex(result, from, 1);
break;
case 'm':
- smart_str_appends_ex(result, msg, 1);
+ smart_str_append_ex(result, &new_msg, 1);
break;
default:
smart_str_appendc_ex(result, '%', 1);
@@ -159,6 +249,10 @@
}
}
+ if (msg) {
+ smart_str_free_ex(&new_msg, 1);
+ }
+
smart_str_0(result);
}