cvs: php4 /ext/ircg ircg.c ircg_scanner.c ircg_scanner.re

From: Date: Mon, 13 Aug 2001 21:22:02 +0000
Subject: cvs: php4 /ext/ircg ircg.c ircg_scanner.c ircg_scanner.re
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6788@lists.php.net to get a copy of this message
sas Mon Aug 13 17:22:02 2001 EDT Modified files: /php4/ext/ircg ircg.c ircg_scanner.c ircg_scanner.re Log: do some fancy stuff to optionally: - disable automatic link conversion (placing a link on a web-site makes you a potential target for a lawsuit in Germany, so some users want to disable that selectively) - convert a special character to <br>, so that we can "flatten" the input for transportation through the IRC layer and convert it back to multi-line representation later.

Index: php4/ext/ircg/ircg.c diff -u php4/ext/ircg/ircg.c:1.100 php4/ext/ircg/ircg.c:1.101 --- php4/ext/ircg/ircg.c:1.100 Sat Aug 11 12:39:00 2001 +++ php4/ext/ircg/ircg.c Mon Aug 13 17:22:02 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg.c,v 1.100 2001/08/11 16:39:00 zeev Exp $ */ +/* $Id: ircg.c,v 1.101 2001/08/13 21:22:02 sas Exp $ */ #include <time.h> @@ -160,7 +160,9 @@ P_NICKNAME = 2, P_NICKNAME_JS = 3, P_MIRC = 4, - P_MIRC_JS = 5 + P_MIRC_JS = 5, + P_NOAUTO_LINKS = 8, /* Don't automatically convert links */ + P_CONV_BR = 16 /* Convert a special character to <br> */ }; static php_fmt_msgs_t fmt_msgs_default_compiled; @@ -345,7 +347,7 @@ /* This is an expensive operation in terms of CPU time. We try to spend as little time in it by caching messages which are sent to channels (and hence used multiple times). */ -void ircg_mirc_color(const char *, smart_str *, size_t); +void ircg_mirc_color(const char *, smart_str *, size_t, int, int); #define NR_CACHE_ENTRIES 983 @@ -372,7 +374,7 @@ /* {{{ ircg_mirc_color_cache */ void ircg_mirc_color_cache(smart_str *src, smart_str *result, - smart_str *channel) + smart_str *channel, int auto_links, int gen_br) { channel = (void *) 1; /* We only cache messages in the context of a channel */ @@ -392,7 +394,7 @@ cache_entries[hash].src.len = 0; } cache_entries[hash].result.len = 0; - ircg_mirc_color(src->c, &cache_entries[hash].result, src->len); + ircg_mirc_color(src->c, &cache_entries[hash].result, src->len, auto_links, gen_br); smart_str_append_ex(&cache_entries[hash].src, src, 1); } @@ -450,8 +452,10 @@ next: c = *++q; /* skip '%' and look at next char */ switch (c) { - case '1': mode |= 1; goto next; - case '2': mode |= 2; goto next; + case '1': mode |= P_JS; goto next; + case '2': mode |= P_NICKNAME; goto next; + case '3': mode |= P_NOAUTO_LINKS; goto next; + case '4': mode |= P_CONV_BR; goto next; /* associate mode bits with each command where applicable */ case 'c': NEW_TOKEN(C_CHANNEL, v) = mode; break; @@ -485,7 +489,7 @@ int ntoken = fmt_msg->ntoken; #define IRCG_APPEND(what) \ - switch (t[i].para.v) { \ + switch (t[i].para.v & 7) { \ case P_JS: \ if (!what) break; \ ircg_js_escape(what, result); \ @@ -508,14 +512,20 @@ break; \ case P_MIRC_JS: \ if (!encoded) { \ - ircg_mirc_color_cache(msg, &encoded_msg, channel); \ + ircg_mirc_color_cache(msg, \ + &encoded_msg, channel, \ + !(t[i].para.v & P_NOAUTO_LINKS), \ + t[i].para.v & P_CONV_BR); \ encoded = 1; \ } \ ircg_js_escape(&encoded_msg, result); \ break; \ case P_MIRC: \ if (!encoded) { \ - ircg_mirc_color_cache(msg, &encoded_msg, channel); \ + ircg_mirc_color_cache(msg, \ + &encoded_msg, channel, \ + !(t[i].para.v & P_NOAUTO_LINKS), \ + t[i].para.v & P_CONV_BR); \ encoded = 1; \ } \ smart_str_append_ex(result, &encoded_msg, 1); \ Index: php4/ext/ircg/ircg_scanner.c diff -u php4/ext/ircg/ircg_scanner.c:1.14 php4/ext/ircg/ircg_scanner.c:1.15 --- php4/ext/ircg/ircg_scanner.c:1.14 Thu Jul 26 14:38:47 2001 +++ php4/ext/ircg/ircg_scanner.c Mon Aug 13 17:22:02 2001 @@ -1,5 +1,5 @@ -/* Generated by re2c 0.5 on Thu Jul 26 11:31:00 2001 */ -#line 1 "/home/sas/src/php4/ext/ircg/ircg_scanner.re" +/* Generated by re2c 0.5 on Mon Aug 13 18:20:18 2001 */ +#line 1 "ircg_scanner.re" /* +----------------------------------------------------------------------+ | PHP version 4.0 | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg_scanner.c,v 1.14 2001/07/26 18:38:47 sas Exp $ */ +/* $Id: ircg_scanner.c,v 1.15 2001/08/13 21:22:02 sas Exp $ */ #include <ext/standard/php_smart_str.h> #include <stdio.h> @@ -64,7 +64,7 @@ smart_str *result; } ircg_msg_scanner; -#line 77 +#line 78 #define YYFILL(n) do { } while (0) @@ -76,14 +76,19 @@ #define STD_PARA ircg_msg_scanner *ctx, const char *start, const char *YYCURSOR #define STD_ARGS ctx, start, YYCURSOR -static void handle_scheme(STD_PARA) +static inline void passthru(STD_PARA) +{ + smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); +} + +static inline void handle_scheme(STD_PARA) { ctx->scheme.len = 0; smart_str_appendl_ex(&ctx->scheme, start, YYCURSOR - start, 1); smart_str_0(&ctx->scheme); } -static void handle_url(STD_PARA) +static inline void handle_url(STD_PARA) { smart_str_appends_ex(ctx->result, "<a target=blank href=\"", 1); smart_str_append_ex(ctx->result, &ctx->scheme, 1); @@ -179,17 +184,13 @@ } } -static void passthru(STD_PARA) -{ - smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); -} - static void add_entity(STD_PARA, const char *entity) { smart_str_appends_ex(ctx->result, entity, 1); } -void ircg_mirc_color(const char *msg, smart_str *result, size_t msg_len) { +void ircg_mirc_color(const char *msg, smart_str *result, size_t msg_len, int auto_links, int gen_br) +{ const char *end, *xp, *q, *start; ircg_msg_scanner mctx, *ctx = &mctx; @@ -249,38 +250,42 @@ if((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; if(yych <= '%'){ - if(yych <= '\003'){ - if(yych <= '\000') goto yy2; - if(yych <= '\001') goto yy19; - if(yych <= '\002') goto yy13; - goto yy5; + if(yych <= '\025'){ + if(yych <= '\001'){ + if(yych >= '\001') goto yy21; + } else { + if(yych <= '\002') goto yy15; + if(yych <= '\003') goto yy5; + goto yy21; + } } else { - if(yych <= '\026'){ - if(yych <= '\025') goto yy19; - goto yy17; + if(yych <= '\035'){ + if(yych <= '\026') goto yy19; + goto yy21; } else { - if(yych == '\037') goto yy15; - goto yy19; + if(yych <= '\036') goto yy13; + if(yych <= '\037') goto yy17; + goto yy21; } } } else { if(yych <= '>'){ if(yych <= ';'){ if(yych <= '&') goto yy11; - goto yy19; + goto yy21; } else { if(yych <= '<') goto yy7; - if(yych <= '=') goto yy19; + if(yych <= '=') goto yy21; goto yy9; } } else { if(yych <= 'Z'){ - if(yych <= '@') goto yy19; + if(yych <= '@') goto yy21; goto yy3; } else { - if(yych <= '`') goto yy19; + if(yych <= '`') goto yy21; if(yych <= 'z') goto yy3; - goto yy19; + goto yy21; } } } @@ -292,60 +297,64 @@ yych = *(YYMARKER = ++YYCURSOR); if(yych <= '@'){ if(yych <= '/') goto yy4; - if(yych <= ':') goto yy21; + if(yych <= ':') goto yy23; } else { - if(yych <= 'Z') goto yy21; + if(yych <= 'Z') goto yy23; if(yych <= '`') goto yy4; - if(yych <= 'z') goto yy21; + if(yych <= 'z') goto yy23; } yy4: -#line 227 +#line 230 { passthru(STD_ARGS); goto state_plain; } yy5: yych = *++YYCURSOR; yy6: -#line 220 +#line 222 { mctx.fg_code = mctx.bg_code = -1; goto state_color_fg; } yy7: yych = *++YYCURSOR; yy8: -#line 221 +#line 223 { add_entity(STD_ARGS, "&lt;"); goto state_plain; } yy9: yych = *++YYCURSOR; yy10: -#line 222 +#line 224 { add_entity(STD_ARGS, "&gt;"); goto state_plain; } yy11: yych = *++YYCURSOR; yy12: -#line 223 +#line 225 { add_entity(STD_ARGS, "&amp;"); goto state_plain; } yy13: yych = *++YYCURSOR; yy14: -#line 224 - { handle_bold(STD_ARGS, 0); goto state_plain; } +#line 226 + { if (gen_br) smart_str_appendl_ex(ctx->result, "<br>", 4, 1); goto state_plain; } yy15: yych = *++YYCURSOR; yy16: -#line 225 - { handle_underline(STD_ARGS, 0); goto state_plain; } +#line 227 + { handle_bold(STD_ARGS, 0); goto state_plain; } yy17: yych = *++YYCURSOR; yy18: -#line 226 - { handle_italic(STD_ARGS, 0); goto state_plain; } +#line 228 + { handle_underline(STD_ARGS, 0); goto state_plain; } yy19: yych = *++YYCURSOR; +yy20: +#line 229 + { handle_italic(STD_ARGS, 0); goto state_plain; } +yy21: yych = *++YYCURSOR; goto yy4; -yy20: ++YYCURSOR; +yy22: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy21: if(yybm[0+yych] & 128) goto yy20; +yy23: if(yybm[0+yych] & 128) goto yy22; if(yych != ':') goto yy2; -yy22: yych = *++YYCURSOR; +yy24: yych = *++YYCURSOR; if(yych != '/') goto yy2; -yy23: yych = *++YYCURSOR; +yy25: yych = *++YYCURSOR; if(yych != '/') goto yy2; -yy24: yych = *++YYCURSOR; -yy25: -#line 219 - { handle_scheme(STD_ARGS); goto state_url; } +yy26: yych = *++YYCURSOR; +yy27: +#line 221 + { if (auto_links) { handle_scheme(STD_ARGS); goto state_url; } else { passthru(STD_ARGS); goto state_plain; } } } -#line 228 +#line 231 state_url: @@ -387,43 +396,43 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - goto yy26; -yy27: ++YYCURSOR; -yy26: + goto yy28; +yy29: ++YYCURSOR; +yy28: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; if(yych <= '>'){ if(yych <= '"'){ - if(yych != '!') goto yy30; + if(yych != '!') goto yy32; } else { - if(yych == '<') goto yy30; - if(yych >= '>') goto yy30; + if(yych == '<') goto yy32; + if(yych >= '>') goto yy32; } } else { if(yych <= '`'){ - if(yych <= 'Z') goto yy28; - if(yych != '_') goto yy30; + if(yych <= 'Z') goto yy30; + if(yych != '_') goto yy32; } else { - if(yych <= 'z') goto yy28; - if(yych != '~') goto yy30; + if(yych <= 'z') goto yy30; + if(yych != '~') goto yy32; } } -yy28: yych = *++YYCURSOR; - goto yy33; -yy29: -#line 233 - { handle_url(STD_ARGS); goto state_plain; } yy30: yych = *++YYCURSOR; + goto yy35; yy31: -#line 234 +#line 236 + { handle_url(STD_ARGS); goto state_plain; } +yy32: yych = *++YYCURSOR; +yy33: +#line 237 { passthru(STD_ARGS); goto state_plain; } -yy32: ++YYCURSOR; +yy34: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy33: if(yybm[0+yych] & 128) goto yy32; - goto yy29; +yy35: if(yybm[0+yych] & 128) goto yy34; + goto yy31; } -#line 235 +#line 238 @@ -432,27 +441,27 @@ { YYCTYPE yych; unsigned int yyaccept; - goto yy34; -yy35: ++YYCURSOR; -yy34: + goto yy36; +yy37: ++YYCURSOR; +yy36: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if(yych <= '/') goto yy38; - if(yych >= ':') goto yy38; -yy36: yych = *++YYCURSOR; - if(yych <= '/') goto yy37; - if(yych <= '9') goto yy40; -yy37: -#line 241 - { handle_color_digit(STD_ARGS, 0); goto state_color_comma; } + if(yych <= '/') goto yy40; + if(yych >= ':') goto yy40; yy38: yych = *++YYCURSOR; + if(yych <= '/') goto yy39; + if(yych <= '9') goto yy42; yy39: -#line 242 - { finish_color_stuff(STD_ARGS); passthru(STD_ARGS); goto state_plain; } +#line 244 + { handle_color_digit(STD_ARGS, 0); goto state_color_comma; } yy40: yych = *++YYCURSOR; - goto yy37; +yy41: +#line 245 + { finish_color_stuff(STD_ARGS); passthru(STD_ARGS); goto state_plain; } +yy42: yych = *++YYCURSOR; + goto yy39; } -#line 243 +#line 246 @@ -461,22 +470,22 @@ { YYCTYPE yych; unsigned int yyaccept; - goto yy41; -yy42: ++YYCURSOR; -yy41: + goto yy43; +yy44: ++YYCURSOR; +yy43: if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych != ',') goto yy45; -yy43: yych = *++YYCURSOR; -yy44: -#line 249 - { goto state_color_bg; } + if(yych != ',') goto yy47; yy45: yych = *++YYCURSOR; yy46: -#line 250 +#line 252 + { goto state_color_bg; } +yy47: yych = *++YYCURSOR; +yy48: +#line 253 { YYCURSOR--; commit_color_stuff(STD_ARGS); goto state_plain; } } -#line 251 +#line 254 @@ -485,27 +494,27 @@ { YYCTYPE yych; unsigned int yyaccept; - goto yy47; -yy48: ++YYCURSOR; -yy47: + goto yy49; +yy50: ++YYCURSOR; +yy49: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if(yych <= '/') goto yy51; - if(yych >= ':') goto yy51; -yy49: yych = *++YYCURSOR; - if(yych <= '/') goto yy50; - if(yych <= '9') goto yy53; -yy50: -#line 257 - { handle_color_digit(STD_ARGS, 1); commit_color_stuff(STD_ARGS); goto state_plain; } + if(yych <= '/') goto yy53; + if(yych >= ':') goto yy53; yy51: yych = *++YYCURSOR; + if(yych <= '/') goto yy52; + if(yych <= '9') goto yy55; yy52: -#line 258 - { commit_color_stuff(STD_ARGS); goto state_plain; } +#line 260 + { handle_color_digit(STD_ARGS, 1); commit_color_stuff(STD_ARGS); goto state_plain; } yy53: yych = *++YYCURSOR; - goto yy50; +yy54: +#line 261 + { commit_color_stuff(STD_ARGS); goto state_plain; } +yy55: yych = *++YYCURSOR; + goto yy52; } -#line 259 +#line 262 stop: Index: php4/ext/ircg/ircg_scanner.re diff -u php4/ext/ircg/ircg_scanner.re:1.14 php4/ext/ircg/ircg_scanner.re:1.15 --- php4/ext/ircg/ircg_scanner.re:1.14 Thu Jul 26 14:38:47 2001 +++ php4/ext/ircg/ircg_scanner.re Mon Aug 13 17:22:02 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: ircg_scanner.re,v 1.14 2001/07/26 18:38:47 sas Exp $ */ +/* $Id: ircg_scanner.re,v 1.15 2001/08/13 21:22:02 sas Exp $ */ #include <ext/standard/php_smart_str.h> #include <stdio.h> @@ -74,6 +74,7 @@ bold = ""; underline = "\037"; italic = ""; +ircnl = "\036"; */ #define YYFILL(n) do { } while (0) @@ -85,14 +86,19 @@ #define STD_PARA ircg_msg_scanner *ctx, const char *start, const char *YYCURSOR #define STD_ARGS ctx, start, YYCURSOR -static void handle_scheme(STD_PARA) +static inline void passthru(STD_PARA) +{ + smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); +} + +static inline void handle_scheme(STD_PARA) { ctx->scheme.len = 0; smart_str_appendl_ex(&ctx->scheme, start, YYCURSOR - start, 1); smart_str_0(&ctx->scheme); } -static void handle_url(STD_PARA) +static inline void handle_url(STD_PARA) { smart_str_appends_ex(ctx->result, "<a target=blank href=\"", 1); smart_str_append_ex(ctx->result, &ctx->scheme, 1); @@ -188,17 +194,13 @@ } } -static void passthru(STD_PARA) -{ - smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); -} - static void add_entity(STD_PARA, const char *entity) { smart_str_appends_ex(ctx->result, entity, 1); } -void ircg_mirc_color(const char *msg, smart_str *result, size_t msg_len) { +void ircg_mirc_color(const char *msg, smart_str *result, size_t msg_len, int auto_links, int gen_br) +{ const char *end, *xp, *q, *start; ircg_msg_scanner mctx, *ctx = &mctx; @@ -216,11 +218,12 @@ if (xp >= end) goto stop; start = YYCURSOR; /*!re2c - scheme "://" { handle_scheme(STD_ARGS); goto state_url; } + 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; } "<" { add_entity(STD_ARGS, "&lt;"); goto state_plain; } ">" { add_entity(STD_ARGS, "&gt;"); goto state_plain; } "&" { add_entity(STD_ARGS, "&amp;"); goto state_plain; } + ircnl { if (gen_br) smart_str_appendl_ex(ctx->result, "<br>", 4, 1); goto state_plain; } bold { handle_bold(STD_ARGS, 0); goto state_plain; } underline { handle_underline(STD_ARGS, 0); goto state_plain; } italic { handle_italic(STD_ARGS, 0); goto state_plain; }
« previous php.cvs (#6788) next »