/* Generated by re2c 0.5 on Wed Jun 18 02:07:15 2003 */ #line 1 "ircg_scanner.re" /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sascha Schumann | +----------------------------------------------------------------------+ */ /* $Id: ircg_scanner.c,v 1.31 2004/01/08 08:15:53 andi Exp $ */ #include #include #include "php_ircg_smart_str.h" #include "php_ircg_alloc.h" static const char *color_list[] = { "white", "black", "blue", "green", "red", "brown", "purple", "orange", "yellow", "lightgreen", "teal", "lightcyan", "lightblue", "#ff00ff", "#bebebe", "lightgrey" }; typedef struct { int bg_code; int fg_code; int font_tag_open; 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; } ircg_msg_scanner; #line 79 #define YYFILL(n) do { } while (0) #define YYCTYPE unsigned char #define YYCURSOR xp #define YYLIMIT end #define YYMARKER q #define STD_PARA ircg_msg_scanner *ctx, const char *start, const char *YYCURSOR #define STD_ARGS ctx, start, YYCURSOR #define PASSTHRU() do { \ smart_str_appendl_ex(mctx.result, start, xp-start, 1); \ } while (0) 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 inline void handle_url(STD_PARA) { smart_str_appends_ex(ctx->result, "result, &ctx->scheme, 1); smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); smart_str_appends_ex(ctx->result, "\">", 1); smart_str_append_ex(ctx->result, &ctx->scheme, 1); smart_str_appendl_ex(ctx->result, start, YYCURSOR - start, 1); smart_str_appends_ex(ctx->result, "", 1); } static void handle_color_digit(STD_PARA, int mode) { int len; int nr; len = YYCURSOR - start; switch (len) { case 2: nr = (start[0] - '0') * 10 + (start[1] - '0'); break; case 1: nr = start[0] - '0'; break; } switch (mode) { case 0: ctx->fg_code = nr; break; case 1: ctx->bg_code = nr; break; } } 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) { if (ctx->font_tag_open) { smart_str_appends_ex(ctx->result, "", 1); ctx->font_tag_open = 0; } } static void handle_bold(STD_PARA, int final) { switch (ctx->bold_tag_open) { case 0: if (!final) smart_str_appends_ex(ctx->result, "", 1); break; case 1: smart_str_appends_ex(ctx->result, "", 1); break; } ctx->bold_tag_open = 1 - ctx->bold_tag_open; } static void handle_underline(STD_PARA, int final) { switch (ctx->underline_tag_open) { case 0: if (!final) smart_str_appends_ex(ctx->result, "", 1); break; case 1: smart_str_appends_ex(ctx->result, "", 1); break; } ctx->underline_tag_open = 1 - ctx->underline_tag_open; } static void handle_italic(STD_PARA, int final) { switch (ctx->italic_tag_open) { case 0: if (!final) smart_str_appends_ex(ctx->result, "", 1); break; case 1: smart_str_appends_ex(ctx->result, "", 1); break; } ctx->italic_tag_open = 1 - ctx->italic_tag_open; } static void commit_color_stuff(STD_PARA) { finish_color_stuff(STD_ARGS); if (IS_VALID_CODE(ctx->fg_code)) { smart_str_appends_ex(ctx->result, "result, color_list[ctx->fg_code], 1); smart_str_appends_ex(ctx->result, "\">", 1); ctx->font_tag_open = 1; } } #define ADD_CONST(entity) do { \ smart_str_appends_ex(result, entity, 1); \ } while (0) static void commit_color_hex(STD_PARA) { finish_color_stuff(STD_ARGS); if (ctx->fg_color[0] != 0) { smart_str_appends_ex(ctx->result, "result, ctx->fg_color, 6, 1); smart_str_appends_ex(ctx->result, "\">", 1); ctx->font_tag_open = 1; } } static void do_reset(STD_PARA) { finish_color_stuff(STD_ARGS); handle_bold(STD_ARGS, 1); handle_underline(STD_ARGS, 1); handle_italic(STD_ARGS, 1); } 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; mctx.result = result; mctx.scheme.c = NULL; mctx.italic_tag_open = mctx.font_tag_open = mctx.bold_tag_open = mctx.underline_tag_open = 0; if (msg_len == -1) msg_len = strlen(msg); end = msg + msg_len; xp = msg; state_plain: if (xp >= end) goto stop; start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy0; yy1: ++YYCURSOR; yy0: if((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; switch(yych){ case '\000': goto yy2; case '\002': goto yy19; case '\003': goto yy5; case '\004': goto yy17; case '\017': goto yy25; case '\035': goto yy23; case '\036': goto yy15; case '\037': goto yy21; case '&': goto yy11; case '<': goto yy7; case '>': goto yy9; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy3; case '\204': case '\223': case '\224': goto yy13; default: goto yy27; } yy2: YYCURSOR = YYMARKER; switch(yyaccept){ case 0: goto yy4; } yy3: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy29; default: goto yy4; } yy4: #line 257 { PASSTHRU(); goto state_plain; } yy5: yych = *++YYCURSOR; yy6: #line 246 { mctx.fg_code = mctx.bg_code = -1; goto state_color_fg; } yy7: yych = *++YYCURSOR; yy8: #line 247 { ADD_CONST("<"); goto state_plain; } yy9: yych = *++YYCURSOR; yy10: #line 248 { ADD_CONST(">"); goto state_plain; } yy11: yych = *++YYCURSOR; yy12: #line 249 { ADD_CONST("&"); goto state_plain; } yy13: yych = *++YYCURSOR; yy14: #line 250 { ADD_CONST("""); goto state_plain; } yy15: yych = *++YYCURSOR; yy16: #line 251 { if (gen_br) ADD_CONST("
"); goto state_plain; } yy17: yych = *++YYCURSOR; yy18: #line 252 { mctx.fg_color[0] = mctx.bg_color[0] = 0; goto state_color_hex; } yy19: yych = *++YYCURSOR; yy20: #line 253 { handle_bold(STD_ARGS, 0); goto state_plain; } yy21: yych = *++YYCURSOR; yy22: #line 254 { handle_underline(STD_ARGS, 0); goto state_plain; } yy23: yych = *++YYCURSOR; yy24: #line 255 { handle_italic(STD_ARGS, 0); goto state_plain; } yy25: yych = *++YYCURSOR; yy26: #line 256 { do_reset(STD_ARGS); goto state_plain; } yy27: yych = *++YYCURSOR; goto yy4; yy28: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy29: switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy28; case ':': goto yy30; default: goto yy2; } yy30: yych = *++YYCURSOR; switch(yych){ case '/': goto yy31; default: goto yy2; } yy31: yych = *++YYCURSOR; switch(yych){ case '/': goto yy32; default: goto yy2; } yy32: yych = *++YYCURSOR; yy33: #line 245 { if (auto_links) { handle_scheme(STD_ARGS); goto state_url; } else { PASSTHRU(); goto state_plain; } } } #line 258 state_color_hex: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy34; yy35: ++YYCURSOR; yy34: if((YYLIMIT - YYCURSOR) < 6) YYFILL(6); yych = *YYCURSOR; switch(yych){ case ',': goto yy38; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy36; default: goto yy40; } yy36: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy41; default: goto yy37; } yy37: #line 265 { finish_color_stuff(STD_ARGS); PASSTHRU(); goto state_plain; } yy38: yych = *++YYCURSOR; yy39: #line 264 { goto state_color_hex_bg; } yy40: yych = *++YYCURSOR; goto yy37; yy41: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy43; default: goto yy42; } yy42: YYCURSOR = YYMARKER; switch(yyaccept){ case 0: goto yy37; } yy43: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy44; default: goto yy42; } yy44: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy45; default: goto yy42; } yy45: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy46; default: goto yy42; } yy46: yych = *++YYCURSOR; yy47: #line 263 { handle_hex(STD_ARGS, 0); goto state_color_hex_bg; } } #line 266 state_color_hex_comma: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy48; yy49: ++YYCURSOR; yy48: if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; switch(yych){ case ',': goto yy50; default: goto yy52; } yy50: yych = *++YYCURSOR; yy51: #line 272 { goto state_color_hex_bg; } yy52: yych = *++YYCURSOR; yy53: #line 273 { YYCURSOR--; commit_color_hex(STD_ARGS); goto state_plain; } } #line 274 state_color_hex_bg: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy54; yy55: ++YYCURSOR; yy54: if((YYLIMIT - YYCURSOR) < 6) YYFILL(6); yych = *YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy56; default: goto yy58; } yy56: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy59; default: goto yy57; } yy57: #line 281 { commit_color_hex(STD_ARGS); PASSTHRU(); goto state_plain; } yy58: yych = *++YYCURSOR; goto yy57; yy59: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy61; default: goto yy60; } yy60: YYCURSOR = YYMARKER; switch(yyaccept){ case 0: goto yy57; } yy61: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy62; default: goto yy60; } yy62: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy63; default: goto yy60; } yy63: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': goto yy64; default: goto yy60; } yy64: yych = *++YYCURSOR; yy65: #line 280 { handle_hex(STD_ARGS, 1); commit_color_hex(STD_ARGS); goto state_plain; } } #line 282 state_url: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy66; yy67: ++YYCURSOR; yy66: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ case '!': case '#': case '$': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case '-': case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '=': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '~': goto yy68; default: goto yy70; } yy68: yych = *++YYCURSOR; goto yy73; yy69: #line 287 { handle_url(STD_ARGS); goto state_plain; } yy70: yych = *++YYCURSOR; yy71: #line 288 { PASSTHRU(); goto state_plain; } yy72: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; yy73: switch(yych){ case '!': case '#': case '$': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case ',': case '-': case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case ':': case ';': case '=': case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '~': goto yy72; default: goto yy69; } } #line 289 state_color_fg: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy74; yy75: ++YYCURSOR; yy74: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ case ',': goto yy78; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': goto yy76; default: goto yy80; } yy76: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': goto yy82; default: goto yy77; } yy77: #line 295 { handle_color_digit(STD_ARGS, 0); goto state_color_comma; } yy78: yych = *++YYCURSOR; yy79: #line 296 { goto state_color_bg; } yy80: yych = *++YYCURSOR; yy81: #line 297 { finish_color_stuff(STD_ARGS); PASSTHRU(); goto state_plain; } yy82: yych = *++YYCURSOR; goto yy77; } #line 298 state_color_comma: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy83; yy84: ++YYCURSOR; yy83: if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; switch(yych){ case ',': goto yy85; default: goto yy87; } yy85: yych = *++YYCURSOR; yy86: #line 304 { goto state_color_bg; } yy87: yych = *++YYCURSOR; yy88: #line 305 { YYCURSOR--; commit_color_stuff(STD_ARGS); goto state_plain; } } #line 306 state_color_bg: start = YYCURSOR; { YYCTYPE yych; unsigned int yyaccept; goto yy89; yy90: ++YYCURSOR; yy89: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': goto yy91; default: goto yy93; } yy91: yych = *++YYCURSOR; switch(yych){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': goto yy95; default: goto yy92; } yy92: #line 312 { handle_color_digit(STD_ARGS, 1); commit_color_stuff(STD_ARGS); goto state_plain; } yy93: yych = *++YYCURSOR; yy94: #line 313 { commit_color_stuff(STD_ARGS); PASSTHRU(); goto state_plain; } yy95: yych = *++YYCURSOR; goto yy92; } #line 314 stop: smart_str_free_ex(&mctx.scheme, 1); do_reset(STD_ARGS); }