sas Tue Jun 3 10:16:23 2003 EDT Modified files: (Branch: PHP_4_3) /php4/ext/ircg ircg_scanner.re Log: Add arbitrary color handling Index: php4/ext/ircg/ircg_scanner.re diff -u php4/ext/ircg/ircg_scanner.re:1.18.8.1 php4/ext/ircg/ircg_scanner.re:1.18.8.2 --- php4/ext/ircg/ircg_scanner.re:1.18.8.1 Tue Jan 28 09:33:03 2003 +++ php4/ext/ircg/ircg_scanner.re Tue Jun 3 10:16:23 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg_scanner.re,v 1.18.8.1 2003/01/28 14:33:03 sas Exp $ */ +/* $Id: ircg_scanner.re,v 1.18.8.2 2003/06/03 14:16:23 sas Exp $ */ #include <ext/standard/php_smart_str.h> #include <stdio.h> @@ -36,20 +36,12 @@ "teal", "lightcyan", "lightblue", - "pink", - "gray", + "#ff00ff", + "#bebebe", "lightgrey" }; -enum { - STATE_PLAIN, - STATE_URL, - STATE_COLOR_FG, - STATE_COLOR_COMMA, - STATE_COLOR_BG -}; - typedef struct { int bg_code; int fg_code; @@ -57,6 +49,8 @@ int bold_tag_open; int underline_tag_open; int italic_tag_open; + char fg_color[6]; + char bg_color[6]; smart_str scheme; smart_str *result; @@ -70,12 +64,14 @@ alnum = [a-zA-Z0-9]; digit = [0-9]; scheme = alpha alnum*; -coloresc = ""; -bold = ""; +coloresc = "\003"; +colorhex = "\004"; +bold = "\002"; underline = "\037"; -italic = ""; +italic = "\35"; ircnl = "\036"; winquotes = [\204\223\224]; +hex = [a-fA-F0-9]; */ #define YYFILL(n) do { } while (0) @@ -87,10 +83,13 @@ #define STD_PARA ircg_msg_scanner *ctx, const char *start, const char *YYCURSOR #define STD_ARGS ctx, start, YYCURSOR -static inline void passthru(STD_PARA) -{ - smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); -} +#define passthru(na,nb,nc) do { \ + size_t __len = xp - start; \ + if (__len == 1) \ + smart_str_appendc_ex(mctx.result, start, 1); \ + else \ + smart_str_appendl_ex(mctx.result, start, __len, 1); \ +} while (0) static inline void handle_scheme(STD_PARA) { @@ -131,6 +130,11 @@ } } +static void handle_hex(STD_PARA, int mode) +{ + memcpy(mode == 0 ? ctx->fg_color : ctx->bg_color, start, 6); +} + #define IS_VALID_CODE(n) (n >= 0 && n <= 15) static void finish_color_stuff(STD_PARA) @@ -195,6 +199,18 @@ } } +static void commit_color_hex(STD_PARA) +{ + finish_color_stuff(STD_ARGS); + + if (ctx->fg_color[0] != 0) { + smart_str_appends_ex(ctx->result, "<font color=\"", 1); + smart_str_appendl_ex(ctx->result, ctx->fg_color, 6, 1); + smart_str_appends_ex(ctx->result, "\">", 1); + ctx->font_tag_open = 1; + } +} + static void add_entity(STD_PARA, const char *entity) { smart_str_appends_ex(ctx->result, entity, 1); @@ -221,6 +237,7 @@ /*!re2c scheme "://" { if (auto_links) { handle_scheme(STD_ARGS); goto state_url; } else { passthru(STD_ARGS); goto state_plain; } } coloresc { mctx.fg_code = mctx.bg_code = -1; goto state_color_fg; } + colorhex { mctx.fg_color[0] = mctx.bg_color[0] = 0; goto state_color_hex; } "<" { add_entity(STD_ARGS, "<"); goto state_plain; } ">" { add_entity(STD_ARGS, ">"); goto state_plain; } "&" { add_entity(STD_ARGS, "&"); goto state_plain; } @@ -232,7 +249,31 @@ anynoneof { passthru(STD_ARGS); goto state_plain; } */ -state_url: +statc_color_hex: + start = YYCURSOR; +/*!re2c + hex hex hex hex hex hex { handle_hex(STD_ARGS, 0); goto state_color_hex_bg; } + "," { goto state_color_hex_bg; } + any { finish_color_stuff(STD_ARGS); passthru(STD_ARGS); goto state_plain; } +*/ + + +state_color_hex_comma: + start = YYCURSOR; +/*!re2c + "," { goto state_color_hex_bg; } + any { YYCURSOR--; commit_color_hex(STD_ARGS); goto state_plain; } +*/ + + +state_color_hex_bg: + start = YYCURSOR; +/*!re2c + hex hex hex hex hex hex { handle_hex(STD_ARGS, 1); commit_color_hex(STD_ARGS); goto state_plain; } + any { commit_color_hex(STD_ARGS); passthru(STD_ARGS); goto state_plain; } +*/ + +state_url: start = YYCURSOR; /*!re2c [-a-zA-Z0-9~_?=.@&+/#:;!*'()%,$]+ { handle_url(STD_ARGS); goto state_plain; } @@ -244,23 +285,24 @@ start = YYCURSOR; /*!re2c digit digit? { handle_color_digit(STD_ARGS, 0); goto state_color_comma; } + "," { goto state_color_bg; } any { finish_color_stuff(STD_ARGS); passthru(STD_ARGS); goto state_plain; } */ - + state_color_comma: start = YYCURSOR; /*!re2c "," { goto state_color_bg; } any { YYCURSOR--; commit_color_stuff(STD_ARGS); goto state_plain; } */ - + state_color_bg: start = YYCURSOR; /*!re2c digit digit? { handle_color_digit(STD_ARGS, 1); commit_color_stuff(STD_ARGS); goto state_plain; } - any { commit_color_stuff(STD_ARGS); goto state_plain; } + any { commit_color_stuff(STD_ARGS); passthru(STD_ARGS); goto state_plain; } */ stop:
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php