Projekt

Obecné

Profil

Stáhnout (48.9 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2
/* This software is licensed through a BSD-style License.
3
 * http://www.opensource.org/licenses/bsd-license.php
4

    
5
Copyright (c) 2003, 2004, Jacob D. Cohen
6
All rights reserved.
7

    
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions
10
are met:
11

    
12
Redistributions of source code must retain the above copyright notice,
13
this list of conditions and the following disclaimer.
14
Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in the
16
documentation and/or other materials provided with the distribution.
17
Neither the name of Jacob D. Cohen nor the names of his contributors
18
may be used to endorse or promote products derived from this software
19
without specific prior written permission.
20

    
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32

    
33
*/
34

    
35
function keyword_replace($keywords, $text, $ncs = false)
36
{
37
    $cm = ($ncs)? "i" : "";
38
    foreach ($keywords as $keyword)
39
    {
40
        $search[]  = "/(\\b$keyword\\b)/" . $cm;
41
        $replace[] = '<span class="keyword">\\0</span>';
42
    }
43

    
44
    $search[]  = "/(\\bclass\s)/";
45
    $replace[] = '<span class="keyword">\\0</span>';
46

    
47
    return preg_replace($search, $replace, $text);
48
}
49

    
50

    
51
function preproc_replace($preproc, $text)
52
{
53
    foreach ($preproc as $proc)
54
    {
55
        $search[] = "/(\\s*#\s*$proc\\b)/";
56
        $replace[] = '<span class="keyword">\\0</span>';
57
    }
58

    
59
    return preg_replace($search, $replace, $text);
60
}
61

    
62

    
63
function sch_syntax_helper($text)
64
{
65
    return $text;
66
}
67

    
68

    
69
function syntax_highlight_helper($text, $language)
70
{
71
    $preproc = array();
72
    $preproc["C++"] = array(
73
    "if",    "ifdef",   "ifndef", "elif",  "else",
74
    "endif", "include", "define", "undef", "line",
75
    "error", "pragma");
76
    $preproc["C89"] = & $preproc["C++"];
77
    $preproc["C"] = & $preproc["C89"];
78

    
79
    $keywords = array(
80
    "C++" => array(
81
    "asm",          "auto",      "bool",     "break",            "case",
82
    "catch",        "char",      /*class*/   "const",            "const_cast",
83
    "continue",     "default",   "delete",   "do",               "double",
84
    "dynamic_cast", "else",      "enum",     "explicit",         "export",
85
    "extern",       "false",     "float",    "for",              "friend",
86
    "goto",         "if",        "inline",   "int",              "long",
87
    "mutable",      "namespace", "new",      "operator",         "private",
88
    "protected",    "public",    "register", "reinterpret_cast", "return",
89
    "short",        "signed",    "sizeof",   "static",           "static_cast",
90
    "struct",       "switch",    "template", "this",             "throw", 
91
    "true",         "try",       "typedef",  "typeid",           "typename",
92
    "union",        "unsigned",  "using",    "virtual",          "void",
93
    "volatile",     "wchar_t",   "while"),
94

    
95
    "C89" => array(
96
    "auto",     "break",    "case",     "char",     "const",
97
    "continue", "default",  "do",       "double",   "else",
98
    "enum",     "extern",   "float",    "for",      "goto",
99
    "if",       "int",      "long",     "register", "return",
100
    "short",    "signed",   "sizeof",   "static",   "struct",
101
    "switch",   "typedef",  "union",    "unsigned", "void",
102
    "volatile", "while"),
103

    
104
    "C" => array(
105
    "auto",     "break",    "case",     "char",     "const",
106
    "continue", "default",  "do",       "double",   "else",
107
    "enum",     "extern",   "float",    "for",      "goto",
108
    "if",       "int",      "long",     "register", "return",
109
    "short",    "signed",   "sizeof",   "static",   "struct",
110
    "switch",   "typedef",  "union",    "unsigned", "void",
111
    "volatile", "while",    "__restrict","_Bool"),
112

    
113
    "PHP" => array(
114
    "and",          "or",           "xor",      "__FILE__",     "__LINE__",
115
    "array",        "as",           "break",    "case",         "cfunction",
116
    /*class*/       "const",        "continue", "declare",      "default",
117
    "die",          "do",           "echo",     "else",         "elseif",
118
    "empty",        "enddeclare",   "endfor",   "endforeach",   "endif",
119
    "endswitch",    "endwhile",     "eval",     "exit",         "extends",
120
    "for",          "foreach",      "function", "global",       "if",
121
    "include",      "include_once", "isset",    "list",         "new",
122
    "old_function", "print",        "require",  "require_once", "return",
123
    "static",       "switch",       "unset",    "use",          "var",
124
    "while",        "__FUNCTION__", "__CLASS__"),
125

    
126
    "Perl" => array(
127
    "-A",           "-B",           "-C",       "-M",           "-O",
128
    "-R",           "-S",           "-T",       "-W",           "-X",
129
    "-b",           "-c",           "-d",       "-e",           "-f",
130
    "-g",           "-k",           "-l",       "-o",           "-p",
131
    "-r",           "-s",           "-t",       "-u",           "-w",
132
    "-x",           "-z",           "ARGV",     "DATA",         "ENV",
133
    "SIG",          "STDERR",       "STDIN",    "STDOUT",       "atan2",
134
    "bind",         "binmode",      "bless",    "caller",       "chdir",
135
    "chmod",        "chomp",        "chop",     "chown",        "chr",
136
    "chroot",       "close",        "closedir", "cmp",          "connect",
137
    "continue",     "cos",          "crypt",    "dbmclose",     "dbmopen",
138
    "defined",      "delete",       "die",      "do",           "dump",
139
    "each",         "else",         "elsif",    "endgrent",     "endhostent",
140
    "endnetent",    "endprotent",   "endpwent", "endservent",   "eof",
141
    "eq",           "eval",         "exec",     "exists",       "exit",
142
    "exp",          "fcntl",        "fileno",   "flock",        "for",
143
    "foreach",      "fork",         "format",   "formline",     "ge",
144
    "getc",         "getgrent",     "getgrid",  "getgrnam",     "gethostbyaddr",
145
    "gethostbyname","gethostent",   "getlogin", "getnetbyaddr", "getnetbyname",
146
    "getnetent",    "getpeername",  "getpgrp",  "getppid",      "getpriority",
147
    "getprotobyname","getprotobynumber","getprotoent","getpwent","getpwnam",
148
    "getpwuid",     "getservbyname","getservbyport","getservent","getsockname",
149
    "getsockopt",   "glob",         "gmtime",   "goto",         "grep",
150
    /*gt*/          "hex",          "if",       "import",       "index",
151
    "int",          "ioctl",        "join",     "keys",         "kill",
152
    "last",         "lc",           "lcfirst",  "le",           "length",
153
    "link",         "listen",       "local",    "localtime",    "log",
154
    "lstat",        /*lt*/          "m",        "map",          "mkdir",
155
    "msgctl",       "msgget",       "msgrcv",   "msgsnd",       "my",
156
    "ne",           "next",         "no",       "oct",          "open",
157
    "opendir",      "ord",          "pack",     "package",      "pipe",
158
    "pop",          "pos",          "print",    "printf",       "push",
159
    "q",            "qq",           "quotemeta","qw",           "qx",
160
    "rand",         "read",         "readdir",  "readlink",     "recv",
161
    "redo",         "ref",          "refname",  "require",      "reset",
162
    "return",       "reverse",      "rewinddir","rindex",       "rmdir",
163
    "s",            "scalar",       "seek",     "seekdir",      "select",
164
    "semctl",       "semget",       "semop",    "send",         "setgrent",
165
    "sethostent",   "setnetent",    "setpgrp",  "setpriority",  "setprotoent",
166
    "setpwent",     "setservent",   "setsockopt","shift",       "shmctl",
167
    "shmget",       "shmread",      "shmwrite", "shutdown",     "sin",
168
    "sleep",        "socket",       "socketpair","sort",        "splice",
169
    "split",        "sprintf",      "sqrt",     "srand",        "stat",
170
    "study",        "sub",          "substr",   "symlink",      "syscall",
171
    "sysopen",      "sysread",      "system",   "syswrite",     "tell",
172
    "telldir",      "tie",          "tied",     "time",         "times",
173
    "tr",           "truncate",     "uc",       "ucfirst",      "umask",
174
    "undef",        "unless",       "unlink",   "unpack",       "unshift",
175
    "untie",        "until",        "use",      "utime",        "values",
176
    "vec",          "wait",         "waitpid",  "wantarray",    "warn", 
177
    "while",        "write",        "y",        "or",           "and",
178
    "not"),
179

    
180
    "Java" => array(
181
    "abstract",     "boolean",      "break",    "byte",         "case",
182
    "catch",        "char",         /*class*/   "const",        "continue",
183
    "default",      "do",           "double",   "else",         "extends",
184
    "final",        "finally",      "float",    "for",          "goto",
185
    "if",           "implements",   "import",   "instanceof",   "int",
186
    "interface",    "long",         "native",   "new",          "package",
187
    "private",      "protected",    "public",   "return",       "short",
188
    "static",       "strictfp",     "super",    "switch",       "synchronized",
189
    "this",         "throw",        "throws",   "transient",    "try",
190
    "void",         "volatile",     "while"),
191

    
192
    "VB" => array(
193
    "AddressOf",    "Alias",        "And",      "Any",          "As",
194
    "Binary",       "Boolean",      "ByRef",    "Byte",         "ByVal",
195
    "Call",         "Case",         "CBool",    "CByte",        "CCur",
196
    "CDate",        "CDbl",         "CInt",     "CLng",         "Close",
197
    "Const",        "CSng",         "CStr",     "Currency",     "CVar",
198
    "CVErr",        "Date",         "Debug",    "Declare",      "DefBool",
199
    "DefByte",      "DefCur",       "DefDate",  "DefDbl",       "DefInt",
200
    "DefLng",       "DefObj",       "DefSng",   "DefStr",       "DefVar",
201
    "Dim",          "Do",           "Double",   "Each",         "Else",
202
    "End",          "Enum",         "Eqv",      "Erase",        "Error",
203
    "Event",        "Exit",         "For",      "Friend",       "Function",
204
    "Get",          "Get",          "Global",   "GoSub",        "GoTo",
205
    "If",           "Imp",          "Implements","In",          "Input",
206
    "Integer",      "Is",           "LBound",   "Len",          "Let",
207
    "Lib",          "Like",         "Line",     "Lock",         "Long",
208
    "Loop",         "LSet",         "Mod",      "Name",         "Next",
209
    "Not",          "Nothing",      "Null",     "Object",       "On",
210
    "Open",         "Option Base 1","Option Compare Binary",
211
    "Option Compare Database", "Option Compare Text", "Option Explicit",
212
    "Option Private Module", "Optional",        "Or",           "Output",
213
    "ParamArray",   "Preserve",     "Print",    "Private",      "Property",
214
    "Public",       "Put",          "RaiseEvent","Random",      "Read",
215
    "ReDim",        "Resume",       "Return",   "RSet",         "Seek",
216
    "Select",       "Set",          "Single",   "Spc",          "Static",
217
    "Step",         "Stop",         "String",   "Sub",          "Tab",
218
    "Then",         "To",           "Type",     "UBound",       "Unlock",
219
    "Variant",      "Wend",         "While",    "With",         "WithEvents",
220
    "Write",        "Xor"),
221

    
222
    "C#" => array(
223
    "abstract",     "as",           "base",     "bool",         "break",
224
    "byte",         "case",         "catch",    "char",         "checked",
225
    /*class*/       "const",        "continue", "decimal",      "default",
226
    "delegate",     "do",           "double",   "else",         "enum",
227
    "event",        "explicit",     "extern",   "false",        "finally",
228
    "fixed",        "float",        "for",      "foreach",      "goto",
229
    "if",           "implicit",     "in",       "int",          "interface",
230
    "internal",     "is",           "lock",     "long",         "namespace",
231
    "new",          "null",         "object",   "operator",     "out",
232
    "override",     "params",       "private",  "protected",    "public",
233
    "readonly",     "ref",          "return",   "sbyte",        "sealed",
234
    "short",        "sizeof",       "stackalloc","static",      "string",
235
    "struct",       "switch",       "this",     "throw",        "true",
236
    "try",          "typeof",       "uint",     "ulong",        "unchecked",
237
    "unsafe",       "ushort",       "using",    "virtual",      "volatile",
238
    "void",         "while"),
239
    
240
    "Ruby" => array(
241
    "alias",        "and",          "begin",    "break",        "case",
242
    /*class*/       "def",          "defined",  "do",           "else",
243
    "elsif",        "end",          "ensure",   "false",        "for",
244
    "if",           "in",           "module",   "next",         "module",
245
    "next",         "nil",          "not",      "or",           "redo",
246
    "rescue",       "retry",        "return",   "self",         "super",
247
    "then",         "true",         "undef",    "unless",       "until",
248
    "when",         "while",        "yield"),
249

    
250
    "Python" => array(
251
    "and",          "assert",       "break",    /*"class",*/    "continue",
252
    "def",          "del",          "elif",     "else",         "except",
253
    "exec",         "finally",      "for",      "from",         "global",
254
    "if",           "import",       "in",       "is",           "lambda",
255
    "not",          "or",           "pass",     "print",        "raise",
256
    "return",       "try",          "while",    "yield"),
257

    
258
    "Pascal" => array(
259
    "Absolute",     "Abstract",     "All",      "And",          "And_then",
260
    "Array",        "Asm",          "Begin",    "Bindable",     "Case",
261
    /*"Class",*/    "Const",        "Constructor","Destructor", "Div",
262
    "Do",           "Downto",       "Else",     "End",          "Export",
263
    "File",         "For",          "Function", "Goto",         "If",
264
    "Import",       "Implementation","Inherited","In",          "Inline",
265
    "Interface",    "Is",           "Label",    "Mod",          "Module",
266
    "Nil",          "Not",          "Object",   "Of",           "Only",
267
    "Operator",     "Or",           "Or_else",  "Otherwise",    "Packed",
268
    "Pow",          "Procedure",    "Program",  "Property",     "Protected",
269
    "Qualified",    "Record",       "Repeat",   "Restricted",   "Set",
270
    "Shl",          "Shr",          "Then",     "To",           "Type",
271
    "Unit",         "Until",        "Uses",     "Value",        "Var",
272
    "View",         "Virtual",      "While",    "With",         "Xor"),
273

    
274
    "mIRC" => array(
275
        ),
276

    
277
    "PL/I" => array(
278
    "A",            "ABS",            "ACOS",        "%ACTIVATE",    "ACTUALCOUNT", 
279
    "ADD",            "ADDR",            "ADDREL",    "ALIGNED",        "ALLOCATE", 
280
    "ALLOC",        "ALLOCATION",    "ALLOCN",    "ANY",            "ANYCONDITION", 
281
    "APPEND",        "AREA",            "ASIN",        "ATAN",            "ATAND", 
282
    "ATANH",        "AUTOMATIC",    "AUTO",        "B",            "B1", 
283
    "B2",            "B3",            "B4",        "BACKUP_DATE",    "BASED", 
284
    "BATCH",        "BEGIN",        "BINARY",    "BIN",            "BIT",
285
    "BLOCK_BOUNDARY_FORMAT",        "BLOCK_IO",    "BLOCK_SIZE",    "BOOL",
286
    "BUCKET_SIZE",    "BUILTIN",        "BY",        "BYTE",            "BYTESIZE",
287
    "CALL",            "CANCEL_CONTROL_O",            "CARRIAGE_RETURN_FORMAT",
288
    "CEIL",            "CHAR", "CHARACTER",    "CLOSE",    "COLLATE",        "COLUMN",
289
    "CONDITION",    "CONTIGUOUS",    "CONTIGUOUS_BEST_TRY",        "CONTROLLED",
290
    "CONVERSION",    "COPY",            "COS",        "COSD",            "COSH",
291
    "CREATION_DATE",                "CURRENT_POSITION",            "DATE",
292
    "DATETIME",        "%DEACTIVATE",    "DECIMAL",    "DEC",            "%DECLARE",
293
    "%DCL",            "DECLARE",        "DCL",        "DECODE",        "DEFAULT_FILE_NAME",
294
    "DEFERRED_WRITE",                "DEFINED",    "DEF",            "DELETE",
295
    "DESCRIPTOR",    "%DICTIONARY",    "DIMENSION","DIM",           "DIRECT",
296
    "DISPLAY",        "DIVIDE",        "%DO",        "DO",            "E",
297
    "EDIT",            "%ELSE",        "ELSE",        "EMPTY",        "ENCODE",
298
    "%END",            "END",            "ENDFILE",    "ENDPAGE",        "ENTRY",
299
    "ENVIRONMENT",    "ENV",            "%ERROR",    "ERROR",        "EVERY",
300
    "EXP",            "EXPIRATION_DATE",            "EXTEND",        "EXTENSION_SIZE",
301
    "EXTERNAL",        "EXT",            "F",        "FAST_DELETE",    "%FATAL",
302
    "FILE",            "FILE_ID",        "FILE_ID_TO",                "FILE_SIZE",
303
    "FINISH",        "FIXED",        "FIXEDOVERFLOW",            "FOFL",
304
    "FIXED_CONTROL_FROM",            "FIXED_CONTROL_SIZE",        "FIXED_CONTROL_SIZE_TO",
305
    "FIXED_CONTROL_TO",                "FIXED_LENGTH_RECORDS",        "FLOAT",
306
    "FLOOR",        "FLUSH",        "FORMAT",    "FREE",            "FROM",
307
    "GET",            "GLOBALDEF",    "GLOBALREF",                "%GOTO",
308
    "GOTO",            "GO", "TO",        "GROUP_PROTETION",            "HBOUND",
309
    "HIGH",            "INDENT",        "%IF",        "IF",            "IGNORE_LINE_MARKS",
310
    "IN",            "%INCLUDE",        "INDEX",    "INDEXED",        "INDEX_NUMBER",
311
    "%INFORM",        "INFORM",        "INITIAL",    "INIT",            "INITIAL_FILL",
312
    "INPUT",        "INT",            "INTERNAL",    "INTO",            "KEY",
313
    "KEYED",        "KEYFROM",        "KEYTO",    "LABEL",        "LBOUND",
314
    "LEAVE",        "LENGTH",        "LIKE",        "LINE",            "LINENO",
315
    "LINESIZE",        "%LIST",        "LIST",        "LOCK_ON_READ",    "LOCK_ON_WRITE",
316
    "LOG",            "LOG10",        "LOG2",        "LOW",            "LTRIM",
317
    "MAIN",            "MANUAL_UNLOCKING",            "MATCH_GREATER",
318
    "MATCH_GREATER_EQUAL",            "MATCH_NEXT",                "MATCH_NEXT_EQUAL",
319
    "MAX",            "MAXIMUM_RECORD_NUMBER",    "MAXIMUM_RECORD_SIZE",
320
    "MAXLENGTH",    "MEMBER",        "MIN",        "MOD",            "MULTIBLOCK_COUNT",
321
    "MULTIBUFFER_COUNT",            "MULTIPLY",    "NEXT_VOLUME",    "%NOLIST",
322
    "NOLOCK",        "NONEXISTENT_RECORD",        "NONRECURSIVE",    "NONVARYING",
323
    "NONVAR",        "NORESCAN",        "NO_ECHO",    "NO_FILTER",    "NO_SHARE",
324
    "NULL",            "OFFSET",        "ON",        "ONARGSLIST",    "ONCHAR",
325
    "ONCODE",        "ONFILE",        "ONKEY",    "ONSOURCE",        "OPEN",
326
    "OPTIONAL",        "OPTIONS",        "OTHERWISE","OTHER",        "OUTPUT",
327
    "OVERFLOW",        "OFL",            "OWNER_GROUP",                "OWNER_ID",
328
    "OWNER_MEMBER",    "OWNER_PROTECTION",            "P",            "%PAGE",
329
    "PAGE",            "PAGENO",        "PAGESIZE",    "PARAMETER",    "PARM",
330
    "PICTURE",        "PIC",            "POINTER",    "PTR",            "POSINT",
331
    "POSITION",        "POS",            "PRECISION","PREC",            "PRESENT",
332
    "PRINT",        "PRINTER_FORMAT",            "%PROCEDURE",    "%PROC",
333
    "PROCEDURE",    "PROC",            "PROD",        "PROMPT",        "PURGE_TYPE_AHEAD",
334
    "PUT",            "R",            "RANK",        "READ",            "READONLY",
335
    "READ_AHEAD",    "READ_CHECK",    "READ_REGARDLESS",            "RECORD",
336
    "RECORD_ID",    "RECORD_ID_ACCESS",            "RECORD_ID_TO",    "RECURSIVE",
337
    "REFER",        "REFERENCE",    "RELEASE",    "REPEAT",        "%REPLACE",
338
    "RESCAN",        "RESIGNAL",        "RETRIEVAL_POINTERS",        "%RETURN",
339
    "RETURN",        "RETURNS",        "REVERSE",    "REVERT",        "REVISION_DATE",
340
    "REWIND",        "REWIND_ON_CLOSE",            "REWIND_ON_OPEN",
341
    "REWRITE",        "ROUND",        "RTRIM",    "%SBTTL",        "SCALARVARYING",
342
    "SEARCH",        "SELECT",        "SEQUENTIAL",                "SEQL",
343
    "SET",            "SHARED_READ",    "SHARED_WRITE",                "SIGN",
344
    "SIGNAL",        "SIN",            "SIND",        "SINH",            "SIZE",
345
    "SKIP",            "SNAP",            "SOME",        "SPACEBLOCK",    "SPOOL",
346
    "SQRT",            "STATEMENT",    "STATIC",    "STOP",            "STORAGE",
347
    "STREAM",        "STRING",        "STRINGRANGE",                "STRG",
348
    "STRUCTURE",    "SUBSCRIPTRANGE",            "SUBRG",        "SUBSTR",
349
    "SUBTRACT",        "SUM",            "SUPERCEDE","SYSIN",        "SYSPRINT",
350
    "SYSTEM",        "SYSTEM_PROTECTION",        "TAB",            "TAN",
351
    "TAND",            "TANH",            "TEMPORARY","%THEN",        "THEN",
352
    "TIME",            "TIMEOUT_PERIOD",            "%TITLE",        "TITLE",
353
    "TO",            "TRANSLATE",    "TRIM",        "TRUNC",        "TRUNCATE",
354
    "UNALIGNED",    "UNAL",            "UNDEFINED","UNDF",            "UNDERFLOW",
355
    "UFL",            "UNION",        "UNSPEC",    "UNTIL",        "UPDATE",
356
    "USER_OPEN",    "VALID",        "VALUE",    "VAL",            "VARIABLE",
357
    "VARIANT",        "VARYING",        "VAR",        "VAXCONDITION",    "VERIFY",
358
    "WAIT_FOR_RECORD",                "%WARN",    "WARN",            "WHEN",    
359
    "WHILE",        "WORLD_PROTECTION",            "WRITE",        "WRITE_BEHIND",
360
    "WRITE_CHECK",    "X",            "ZERODIVIDE"),
361

    
362
    "SQL" => array(
363
    "abort", "abs", "absolute", "access",
364
    "action", "ada", "add", "admin",
365
    "after", "aggregate", "alias", "all",
366
    "allocate", "alter", "analyse", "analyze",
367
    "and", "any", "are", "array",
368
    "as", "asc", "asensitive", "assertion",
369
    "assignment", "asymmetric", "at", "atomic",
370
    "authorization", "avg", "backward", "before",
371
    "begin", "between", "bigint", "binary",
372
    "bit", "bitvar", "bit_length", "blob",
373
    "boolean", "both", "breadth", "by",
374
    "c", "cache", "call", "called",
375
    "cardinality", "cascade", "cascaded", "case",
376
    "cast", "catalog", "catalog_name", "chain",
377
    "char", "character", "characteristics", "character_length",
378
    "character_set_catalog", "character_set_name", "character_set_schema", "char_length",
379
    "check", "checked", "checkpoint", /* "class", */
380
    "class_origin", "clob", "close", "cluster",
381
    "coalesce", "cobol", "collate", "collation",
382
    "collation_catalog", "collation_name", "collation_schema", "column",
383
    "column_name", "command_function", "command_function_code", "comment",
384
    "commit", "committed", "completion", "condition_number",
385
    "connect", "connection", "connection_name", "constraint",
386
    "constraints", "constraint_catalog", "constraint_name", "constraint_schema",
387
    "constructor", "contains", "continue", "conversion",
388
    "convert", "copy", "corresponding", "count",
389
    "create", "createdb", "createuser", "cross",
390
    "cube", "current", "current_date", "current_path",
391
    "current_role", "current_time", "current_timestamp", "current_user",
392
    "cursor", "cursor_name", "cycle", "data",
393
    "database", "date", "datetime_interval_code", "datetime_interval_precision",
394
    "day", "deallocate", "dec", "decimal",
395
    "declare", "default", "defaults", "deferrable",
396
    "deferred", "defined", "definer", "delete",
397
    "delimiter", "delimiters", "depth", "deref",
398
    "desc", "describe", "descriptor", "destroy",
399
    "destructor", "deterministic", "diagnostics", "dictionary",
400
    "disconnect", "dispatch", "distinct", "do",
401
    "domain", "double", "drop", "dynamic",
402
    "dynamic_function", "dynamic_function_code", "each", "else",
403
    "encoding", "encrypted", "end", "end-exec",
404
    "equals", "escape", "every", "except",
405
    "exception", "excluding", "exclusive", "exec",
406
    "execute", "existing", "exists", "explain",
407
    "external", "extract", "false", "fetch",
408
    "final", "first", "float", "for",
409
    "force", "foreign", "fortran", "forward",
410
    "found", "free", "freeze", "from",
411
    "full", "function", "g", "general",
412
    "generated", "get", "global", "go",
413
    "goto", "grant", "granted", "group",
414
    "grouping", "handler", "having", "hierarchy",
415
    "hold", "host", "hour", "identity",
416
    "ignore", "ilike", "immediate", "immutable",
417
    "implementation", "implicit", "in", "including",
418
    "increment", "index", "indicator", "infix",
419
    "inherits", "initialize", "initially", "inner",
420
    "inout", "input", "insensitive", "insert",
421
    "instance", "instantiable", "instead", "int",
422
    "integer", "intersect", "interval", "into",
423
    "invoker", "is", "isnull", "isolation",
424
    "iterate", "join", "k", "key",
425
    "key_member", "key_type", "lancompiler", "language",
426
    "large", "last", "lateral", "leading",
427
    "left", "length", "less", "level",
428
    "like", "limit", "listen", "load",
429
    "local", "localtime", "localtimestamp", "location",
430
    "locator", "lock", "lower", "m",
431
    "map", "match", "max", "maxvalue",
432
    "message_length", "message_octet_length", "message_text", "method",
433
    "min", "minute", "minvalue", "mod",
434
    "mode", "modifies", "modify", "module",
435
    "month", "more", "move", "mumps",
436
    "name", "names", "national", "natural",
437
    "nchar", "nclob", "new", "next",
438
    "no", "nocreatedb", "nocreateuser", "none",
439
    "not", "nothing", "notify", "notnull",
440
    "null", "nullable", "nullif", "number",
441
    "numeric", "object", "octet_length", "of",
442
    "off", "offset", "oids", "old",
443
    "on", "only", "open", "operation",
444
    "operator", "option", "options", "or",
445
    "order", "ordinality", "out", "outer",
446
    "output", "overlaps", "overlay", "overriding",
447
    "owner", "pad", "parameter", "parameters",
448
    "parameter_mode", "parameter_name", "parameter_ordinal_position", "parameter_specific_catalog",
449
    "parameter_specific_name", "parameter_specific_schema", "partial", "pascal",
450
    "password", "path", "pendant", "placing",
451
    "pli", "position", "postfix", "precision",
452
    "prefix", "preorder", "prepare", "preserve",
453
    "primary", "prior", "privileges", "procedural",
454
    "procedure", "public", "read", "reads",
455
    "real", "recheck", "recursive", "ref",
456
    "references", "referencing", "reindex", "relative",
457
    "rename", "repeatable", "replace", "reset",
458
    "restart", "restrict", "result", "return",
459
    "returned_length", "returned_octet_length", "returned_sqlstate", "returns",
460
    "revoke", "right", "role", "rollback",
461
    "rollup", "routine", "routine_catalog", "routine_name",
462
    "routine_schema", "row", "rows", "row_count",
463
    "rule", "savepoint", "scale", "schema",
464
    "schema_name", "scope", "scroll", "search",
465
    "second", "section", "security", "select",
466
    "self", "sensitive", "sequence", "serializable",
467
    "server_name", "session", "session_user", "set",
468
    "setof", "sets", "share", "show",
469
    "similar", "simple", "size", "smallint",
470
    "some", "source", "space", "specific",
471
    "specifictype", "specific_name", "sql", "sqlcode",
472
    "sqlerror", "sqlexception", "sqlstate", "sqlwarning",
473
    "stable", "start", "state", "statement",
474
    "static", "statistics", "stdin", "stdout",
475
    "storage", "strict", "structure", "style",
476
    "subclass_origin", "sublist", "substring", "sum",
477
    "symmetric", "sysid", "system", "system_user",
478
    "table", "table_name", "temp", "template",
479
    "temporary", "terminate", "text", "than", "then",
480
    "time", "timestamp", "timezone_hour", "timezone_minute",
481
    "to", "toast", "trailing", "transaction",
482
    "transactions_committed", "transactions_rolled_back", "transaction_active", "transform",
483
    "transforms", "translate", "translation", "treat",
484
    "trigger", "trigger_catalog", "trigger_name", "trigger_schema",
485
    "trim", "true", "truncate", "trusted",
486
    "type", "uncommitted", "under", "unencrypted",
487
    "union", "unique", "unknown", "unlisten",
488
    "unnamed", "unnest", "until", "update",
489
    "upper", "usage", "user", "user_defined_type_catalog",
490
    "user_defined_type_name", "user_defined_type_schema", "using", "vacuum",
491
    "valid", "validator", "value", "values",
492
    "varchar", "variable", "varying", "verbose",
493
    "version", "view", "volatile", "when",
494
    "whenever", "where", "with", "without",
495
    "work", "write", "year", "zone")
496

    
497
    );
498

    
499
    $case_insensitive = array(
500
        "VB" => true,
501
        "Pascal" => true,
502
        "PL/I"   => true,
503
        "SQL"    => true
504
    );
505
    $ncs = false;
506
    if (array_key_exists($language, $case_insensitive))
507
        $ncs = true;
508

    
509
    $text = (array_key_exists($language, $preproc))?
510
        preproc_replace($preproc[$language], $text) :
511
        $text;
512
    $text = (array_key_exists($language, $keywords))?
513
        keyword_replace($keywords[$language], $text, $ncs) :
514
        $text;
515

    
516
    return $text;
517
}
518

    
519

    
520
function rtrim1($span, $lang, $ch)
521
{
522
    return syntax_highlight_helper(substr($span, 0, -1), $lang);
523
}
524

    
525

    
526
function rtrim1_htmlesc($span, $lang, $ch)
527
{
528
    return htmlspecialchars(substr($span, 0, -1));
529
}
530

    
531

    
532
function sch_rtrim1($span, $lang, $ch)
533
{
534
    return sch_syntax_helper(substr($span, 0, -1));
535
}
536

    
537

    
538
function rtrim2($span, $lang, $ch)
539
{
540
    return substr($span, 0, -2);
541
}
542

    
543

    
544
function syn_proc($span, $lang, $ch)
545
{
546
    return syntax_highlight_helper($span, $lang);
547
}
548

    
549
function dash_putback($span, $lang, $ch)
550
{
551
    return syntax_highlight_helper('-' . $span, $lang);
552
}
553

    
554
function slash_putback($span, $lang, $ch)
555
{
556
    return syntax_highlight_helper('/' . $span, $lang);
557
}
558

    
559
function slash_putback_rtrim1($span, $lang, $ch)
560
{
561
    return rtrim1('/' . $span, $lang, $ch);
562
}
563

    
564
function lparen_putback($span, $lang, $ch)
565
{
566
    return syntax_highlight_helper('(' . $span, $lang);
567
}
568

    
569
function lparen_putback_rtrim1($span, $lang, $ch)
570
{
571
    return rtrim1('(' . $span, $lang, $ch);
572
}
573

    
574
function prepend_xml_opentag($span, $lang, $ch) 
575
{                                               
576
    return '<span class="xml_tag">&lt;' . $span;
577
}                                               
578

    
579
function proc_void($span, $lang, $ch)
580
{
581
    return $span;
582
}
583

    
584

    
585
/**
586
 * Syntax highlight function
587
 * Does the bulk of the syntax highlighting by lexing the input
588
 * string, then calling the helper function to highlight keywords.
589
 */
590
function syntax_highlight($text, $language)
591
{
592
    if ($language == "Plain Text") return $text;
593

    
594
    define("normal_text",   1, true);
595
    define("dq_literal",    2, true);
596
    define("dq_escape",     3, true);
597
    define("sq_literal",    4, true);
598
    define("sq_escape",     5, true);
599
    define("slash_begin",   6, true);
600
    define("star_comment",  7, true);
601
    define("star_end",      8, true);
602
    define("line_comment",  9, true);
603
    define("html_entity",  10, true);
604
    define("lc_escape",    11, true);
605
    define("block_comment",12, true);
606
    define("paren_begin",  13, true);
607
    define("dash_begin",   14, true);
608
    define("bt_literal",   15, true);
609
    define("bt_escape",    16, true);
610
    define("xml_tag_begin",17, true);
611
    define("xml_tag",      18, true);
612
    define("xml_pi",       19, true);
613
    define("sch_normal",   20, true);
614
    define("sch_stresc",    21, true);
615
    define("sch_idexpr",   22, true);
616
    define("sch_numlit",   23, true);
617
    define("sch_chrlit",   24, true);
618
    define("sch_strlit",   25, true);
619

    
620
    $initial_state["Scheme"] = sch_normal;
621

    
622
    $sch[sch_normal][0]     = sch_normal;
623
    $sch[sch_normal]['"']   = sch_strlit;
624
    $sch[sch_normal]["#"]   = sch_chrlit;
625
    $sch[sch_normal]["0"]   = sch_numlit;
626
    $sch[sch_normal]["1"]   = sch_numlit;
627
    $sch[sch_normal]["2"]   = sch_numlit;
628
    $sch[sch_normal]["3"]   = sch_numlit;
629
    $sch[sch_normal]["4"]   = sch_numlit;
630
    $sch[sch_normal]["5"]   = sch_numlit;
631
    $sch[sch_normal]["6"]   = sch_numlit;
632
    $sch[sch_normal]["7"]   = sch_numlit;
633
    $sch[sch_normal]["8"]   = sch_numlit;
634
    $sch[sch_normal]["9"]   = sch_numlit;
635

    
636
    $sch[sch_strlit]['"']   = sch_normal;
637
    $sch[sch_strlit]["\n"]  = sch_normal;
638
    $sch[sch_strlit]["\\"]  = sch_stresc;
639
    $sch[sch_strlit][0]     = sch_strlit;
640

    
641
    $sch[sch_chrlit][" "]   = sch_normal;
642
    $sch[sch_chrlit]["\t"]  = sch_normal;
643
    $sch[sch_chrlit]["\n"]  = sch_normal;
644
    $sch[sch_chrlit]["\r"]  = sch_normal;
645
    $sch[sch_chrlit][0]     = sch_chrlit;
646

    
647
    $sch[sch_numlit][" "]   = sch_normal;
648
    $sch[sch_numlit]["\t"]  = sch_normal;
649
    $sch[sch_numlit]["\n"]  = sch_normal;
650
    $sch[sch_numlit]["\r"]  = sch_normal;
651
    $sch[sch_numlit][0]     = sch_numlit;
652

    
653
    //
654
    // State transitions for C
655
    //
656
    $c89[normal_text]["\""] = dq_literal;
657
    $c89[normal_text]["'"]  = sq_literal;
658
    $c89[normal_text]["/"]  = slash_begin;
659
    $c89[normal_text][0]    = normal_text;
660

    
661
    $c89[dq_literal]["\""]  = normal_text;
662
    $c89[dq_literal]["\n"]  = normal_text;
663
    $c89[dq_literal]["\\"]  = dq_escape;
664
    $c89[dq_literal][0]     = dq_literal;
665

    
666
    $c89[dq_escape][0]      = dq_literal;
667

    
668
    $c89[sq_literal]["'"]   = normal_text;
669
    $c89[sq_literal]["\n"]  = normal_text;
670
    $c89[sq_literal]["\\"]  = sq_escape;
671
    $c89[sq_literal][0]     = sq_literal;
672

    
673
    $c89[sq_escape][0]      = sq_literal;
674

    
675
    $c89[slash_begin]["*"]  = star_comment;
676
    $c89[slash_begin][0]    = normal_text;
677

    
678
    $c89[star_comment]["*"] = star_end;
679
    $c89[star_comment][0]   = star_comment;
680

    
681
    $c89[star_end]["/"]     = normal_text;
682
    $c89[star_end]["*"]     = star_end;
683
    $c89[star_end][0]       = star_comment;
684

    
685
    //
686
    // State transitions for C++
687
    // Inherit transitions from C, and add line comment support
688
    //
689
    $cpp = $c89;
690
    $cpp[slash_begin]["/"]   = line_comment;
691
    $cpp[line_comment]["\n"] = normal_text;
692
    $cpp[line_comment]["\\"] = lc_escape;
693
    $cpp[line_comment][0]    = line_comment;
694

    
695
    $cpp[lc_escape]["\r"]    = lc_escape;
696
    $cpp[lc_escape][0]       = line_comment;
697

    
698
    //
699
    // State transitions for C99.
700
    // C99 supports line comments like C++
701
    //
702
    $c99 = $cpp;
703

    
704
    // State transitions for PL/I
705
    // Kinda like C
706
    $pli = $c89;
707

    
708
    //
709
    // State transitions for PHP
710
    // Inherit transitions from C++, and add perl-style line comment support
711
    $php = $cpp;
712
    $php[normal_text]["#"]   = line_comment;
713
    $php[sq_literal]["\n"]   = sq_literal;
714
    $php[dq_literal]["\n"]   = dq_literal;
715

    
716
    //
717
    // State transitions for Perl
718
    $perl[normal_text]["#"]  = line_comment;
719
    $perl[normal_text]["\""] = dq_literal;
720
    $perl[normal_text]["'"]  = sq_literal;
721
    $perl[normal_text][0]    = normal_text;
722

    
723
    $perl[dq_literal]["\""]  = normal_text;
724
    $perl[dq_literal]["\\"]  = dq_escape;
725
    $perl[dq_literal][0]     = dq_literal;
726

    
727
    $perl[dq_escape][0]      = dq_literal;
728

    
729
    $perl[sq_literal]["'"]   = normal_text;
730
    $perl[sq_literal]["\\"]  = sq_escape;
731
    $perl[sq_literal][0]     = sq_literal;
732

    
733
    $perl[sq_escape][0]      = sq_literal;
734

    
735
    $perl[line_comment]["\n"] = normal_text;
736
    $perl[line_comment][0]    = line_comment;
737

    
738
    $mirc[normal_text]["\""] = dq_literal;
739
    $mirc[normal_text][";"]  = line_comment;
740
    $mirc[normal_text][0]    = normal_text;
741

    
742
    $mirc[dq_literal]["\""]  = normal_text;
743
    $mirc[dq_literal]["\\"]  = dq_escape;
744
    $mirc[dq_literal][0]     = dq_literal;
745

    
746
    $mirc[dq_escape][0]      = dq_literal;
747

    
748
    $mirc[line_comment]["\n"] = normal_text;
749
    $mirc[line_comment][0]   = line_comment;
750

    
751
    $ruby = $perl;
752

    
753
    $python = $perl;
754

    
755
    $java = $cpp;
756

    
757
    $vb = $perl;
758
    $vb[normal_text]["#"] = normal_text;
759
    $vb[normal_text]["'"] = line_comment;
760

    
761
    $cs = $java;
762

    
763
    $pascal = $c89;
764
    $pascal[normal_text]["("]  = paren_begin;
765
    $pascal[normal_text]["/"]  = slash_begin;
766
    $pascal[normal_text]["{"]  = block_comment;
767

    
768
    $pascal[paren_begin]["*"]  = star_comment;
769
    $pascal[paren_begin]["'"]  = sq_literal;
770
    $pascal[paren_begin]['"']  = dq_literal;
771
    $pascal[paren_begin][0]    = normal_text;
772

    
773
    $pascal[slash_begin]["'"]  = sq_literal;
774
    $pascal[slash_begin]['"']  = dq_literal;
775
    $pascal[slash_begin]['/']  = line_comment;
776
    $pascal[slash_begin][0]    = normal_text;
777

    
778
    $pascal[star_comment]["*"] = star_end;
779
    $pascal[star_comment][0]   = star_comment;
780

    
781
    $pascal[block_comment]["}"] = normal_text;
782
    $pascal[block_comment][0]   = block_comment;
783

    
784
    $pascal[line_comment]["\n"] = normal_text;
785
    $pascal[line_comment][0]    = line_comment;
786

    
787
    $pascal[star_end][")"]     = normal_text;
788
    $pascal[star_end]["*"]     = star_end;
789
    $pascal[star_end][0]       = star_comment;
790

    
791
    $sql[normal_text]['"']     = dq_literal;
792
    $sql[normal_text]["'"]     = sq_literal;
793
    $sql[normal_text]['`']     = bt_literal;
794
    $sql[normal_text]['-']     = dash_begin;
795
    $sql[normal_text][0]       = normal_text;
796

    
797
    $sql[dq_literal]['"']      = normal_text;
798
    $sql[dq_literal]['\\']     = dq_escape;
799
    $sql[dq_literal][0]        = dq_literal;
800

    
801
    $sql[sq_literal]["'"]      = normal_text;
802
    $sql[sq_literal]['\\']     = sq_escape;
803
    $sql[sq_literal][0]        = sq_literal;
804

    
805
    $sql[bt_literal]['`']      = normal_text;
806
    $sql[bt_literal]['\\']     = bt_escape;
807
    $sql[bt_literal][0]        = bt_literal;
808

    
809
    $sql[dq_escape][0]         = dq_literal;
810
    $sql[sq_escape][0]         = sq_literal;
811
    $sql[bt_escape][0]         = bt_literal;
812

    
813
    $sql[dash_begin]["-"]      = line_comment;
814
    $sql[dash_begin][0]        = normal_text;
815

    
816
    $sql[line_comment]["\n"]   = normal_text;
817
    $sql[line_comment]["\\"]   = lc_escape;
818
    $sql[line_comment][0]      = line_comment;
819

    
820
    $sql[lc_escape]["\r"]      = lc_escape;
821
    $sql[lc_escape][0]         = line_comment;
822

    
823
    $xml[normal_text]["<"]     = xml_tag_begin;               
824
    $xml[normal_text]["&"]     = html_entity;                 
825
    $xml[normal_text][0]       = normal_text;                 
826
    $xml[html_entity][";"]     = normal_text;                 
827
    $xml[html_entity]["<"]     = xml_tag_begin;
828
    $xml[html_entity][0]       = html_entity;                 
829
    $xml[xml_tag_begin]["?"]   = xml_pi;                      
830
    $xml[xml_tag_begin]["!"]   = line_comment;                
831
    $xml[xml_tag_begin][0]     = xml_tag;                     
832
    $xml[xml_tag][">"]         = normal_text;                 
833
    $xml[xml_tag]["\""]        = dq_literal;           
834
    $xml[xml_tag]["'"]         = sq_literal;                   
835
    $xml[xml_tag][0]           = xml_tag;                     
836
    $xml[xml_pi][">"]          = normal_text;                 
837
    $xml[xml_pi][0]            = xml_tag;                     
838
    $xml[line_comment][">"]    = normal_text;                 
839
    $xml[line_comment][0]      = line_comment;                
840
    $xml[dq_literal]["\""]     = xml_tag;                     
841
    $xml[dq_literal]["&"]      = dq_escape;                   
842
    $xml[dq_literal][0]        = dq_literal;                  
843
    $xml[sq_literal]["'"]      = xml_tag;                     
844
    $xml[sq_literal]["&"]      = sq_escape;                   
845
    $xml[sq_literal][0]        = sq_literal;                  
846
    $xml[dq_escape][";"]       = dq_literal;                  
847
    $xml[dq_escape][0]         = dq_escape;                   
848
    
849
    //
850
    // Main state transition table
851
    //
852
    $states = array(
853
        "C89"   => $c89,
854
        "C" => $c99,
855
        "C++" => $cpp,
856
        "PHP" => $php,
857
        "Perl" => $perl,
858
        "Java" => $java,
859
        "VB" => $vb,
860
        "C#" => $cs,
861
        "Ruby" => $ruby,
862
        "Python" => $python,
863
        "Pascal" => $pascal,
864
        "mIRC" => $mirc,
865
        "PL/I" => $pli,
866
        "SQL"  => $sql,
867
        "XML"  => $xml,
868
        "Scheme" => $sch
869
    );
870

    
871

    
872
    //
873
    // Process functions
874
    //
875
    $process["C89"][normal_text][sq_literal] = "rtrim1";
876
    $process["C89"][normal_text][dq_literal] = "rtrim1";
877
    $process["C89"][normal_text][slash_begin] = "rtrim1";
878
    $process["C89"][normal_text][0] = "syn_proc";
879

    
880
    $process["C89"][slash_begin][star_comment] = "rtrim1";
881
    $process["C89"][slash_begin][0] = "slash_putback";
882

    
883
    $process["Scheme"][sch_normal][sch_strlit] = "sch_rtrim1";
884
    $process["Scheme"][sch_normal][sch_chrlit] = "sch_rtrim1";
885
    $process["Scheme"][sch_normal][sch_numlit] = "sch_rtrim1";
886

    
887
    $process["SQL"][normal_text][sq_literal] = "rtrim1";
888
    $process["SQL"][normal_text][dq_literal] = "rtrim1";
889
    $process["SQL"][normal_text][bt_literal] = "rtrim1";
890
    $process["SQL"][normal_text][dash_begin] = "rtrim1";
891
    $process["SQL"][normal_text][0] = "syn_proc";
892

    
893
    $process["SQL"][dash_begin][line_comment] = "rtrim1";
894
    $process["SQL"][dash_begin][0] = "dash_putback";
895

    
896
    $process["PL/I"] = $process["C89"];
897

    
898
    $process["C++"] = $process["C89"];
899
    $process["C++"][slash_begin][line_comment] = "rtrim1";
900

    
901
    $process["C"] = $process["C++"];
902

    
903
    $process["PHP"] = $process["C++"];
904
    $process["PHP"][normal_text][line_comment] = "rtrim1";
905

    
906
    $process["Perl"][normal_text][sq_literal] = "rtrim1";
907
    $process["Perl"][normal_text][dq_literal] = "rtrim1";
908
    $process["Perl"][normal_text][line_comment] = "rtrim1";
909
    $process["Perl"][normal_text][0] = "syn_proc";
910

    
911
    $process["Ruby"] = $process["Perl"];
912
    $process["Python"] = $process["Perl"];
913

    
914
    $process["mIRC"][normal_text][dq_literal] = "rtrim1";
915
    $process["mIRC"][normal_text][line_comment] = "rtrim1";
916
    $process["mIRC"][normal_text][0] = "syn_proc";
917

    
918
    $process["VB"] = $process["Perl"];
919

    
920
    $process["Java"] = $process["C++"];
921

    
922
    $process["C#"] = $process["Java"];
923

    
924
    $process["Pascal"] = $process["C++"];
925
    $process["Pascal"][normal_text][line_comment] = "rtrim1";
926
    $process["Pascal"][normal_text][block_comment] = "rtrim1";
927
    $process["Pascal"][normal_text][paren_begin] = "rtrim1";
928
    $process["Pascal"][slash_begin][sq_literal] = "slash_putback_rtrim1";
929
    $process["Pascal"][slash_begin][dq_literal] = "slash_putback_rtrim1";
930
    $process["Pascal"][slash_begin][0] = "slash_putback";
931
    $process["Pascal"][paren_begin][sq_literal] = "lparen_putback_rtrim1";
932
    $process["Pascal"][paren_begin][dq_literal] = "lparen_putback_rtrim1";
933
    $process["Pascal"][paren_begin][star_comment] = "rtrim1";
934
    $process["Pascal"][paren_begin][0] = "lparen_putback";
935

    
936
    $process["XML"][normal_text][xml_tag_begin] = "rtrim1";
937
    $process["XML"][normal_text][html_entity] = "rtrim1";
938
    $process["XML"][html_entity][xml_tag_begin] = "rtrim1";
939
    $process["XML"][html_entity][0] = "proc_void";
940
    $process["XML"][xml_tag_begin][xml_tag] = "prepend_xml_opentag";
941
    $process["XML"][xml_tag_begin][xml_pi] = "rtrim1";
942
    $process["XML"][xml_tag_begin][line_comment] = "rtrim1";
943
    $process["XML"][line_comment][normal_text] = "rtrim1_htmlesc";
944
    $process["XML"][xml_tag][normal_text] = "rtrim1";
945
    $process["XML"][xml_tag][dq_literal] = "rtrim1";
946
    $process["XML"][dq_literal][xml_tag] = "rtrim1";
947
    $process["XML"][dq_literal][dq_escape] = "rtrim1";
948

    
949
    $process_end["C89"] = "syntax_highlight_helper";
950
    $process_end["C++"] = $process_end["C89"];
951
    $process_end["C"] = $process_end["C89"];
952
    $process_end["PHP"] = $process_end["C89"];
953
    $process_end["Perl"] = $process_end["C89"];
954
    $process_end["Java"] = $process_end["C89"];
955
    $process_end["VB"] = $process_end["C89"];
956
    $process_end["C#"] = $process_end["C89"];
957
    $process_end["Ruby"] = $process_end["C89"];
958
    $process_end["Python"] = $process_end["C89"];
959
    $process_end["Pascal"] = $process_end["C89"];
960
    $process_end["mIRC"] = $process_end["C89"];
961
    $process_end["PL/I"] = $process_end["C89"];
962
    $process_end["SQL"] = $process_end["C89"];
963
    $process_end["Scheme"] = "sch_syntax_helper";
964

    
965

    
966
    $edges["C89"][normal_text .",". dq_literal]   = '<span class="literal">"';
967
    $edges["C89"][normal_text .",". sq_literal]   = '<span class="literal">\'';
968
    $edges["C89"][slash_begin .",". star_comment] = '<span class="comment">/*';
969
    $edges["C89"][dq_literal .",". normal_text]   = '</span>';
970
    $edges["C89"][sq_literal .",". normal_text]   = '</span>';
971
    $edges["C89"][star_end .",". normal_text]     = '</span>';
972

    
973
    $edges["Scheme"][sch_normal .",". sch_strlit] = '<span class="sch_str">"';
974
    $edges["Scheme"][sch_normal .",". sch_numlit] = '<span class="sch_num">';
975
    $edges["Scheme"][sch_normal .",". sch_chrlit] = '<span class="sch_chr">#';
976
    $edges["Scheme"][sch_strlit .",". sch_normal] = '</span>';
977
    $edges["Scheme"][sch_numlit .",". sch_normal] = '</span>';
978
    $edges["Scheme"][sch_chrlit .",". sch_normal] = '</span>';
979

    
980
    $edges["SQL"][normal_text .",". dq_literal]   = '<span class="literal">"';
981
    $edges["SQL"][normal_text .",". sq_literal]   = '<span class="literal">\'';
982
    $edges["SQL"][dash_begin .",". line_comment] = '<span class="comment">--';
983
    $edges["SQL"][normal_text .",". bt_literal]   = '`';
984
    $edges["SQL"][dq_literal .",". normal_text]   = '</span>';
985
    $edges["SQL"][sq_literal .",". normal_text]   = '</span>';
986
    $edges["SQL"][line_comment .",". normal_text] = '</span>';
987

    
988
    $edges["PL/I"] = $edges["C89"];
989

    
990
    $edges["C++"] = $edges["C89"];
991
    $edges["C++"][slash_begin .",". line_comment] = '<span class="comment">//';
992
    $edges["C++"][line_comment .",". normal_text] = '</span>';
993

    
994
    $edges["C"] = $edges["C++"];
995

    
996
    $edges["PHP"] = $edges["C++"];
997
    $edges["PHP"][normal_text .",". line_comment] = '<span class="comment">#';
998

    
999
    $edges["Perl"][normal_text .",". dq_literal]   = '<span class="literal">"';
1000
    $edges["Perl"][normal_text .",". sq_literal]   = '<span class="literal">\'';
1001
    $edges["Perl"][dq_literal .",". normal_text]   = '</span>';
1002
    $edges["Perl"][sq_literal .",". normal_text]   = '</span>';
1003
    $edges["Perl"][normal_text .",". line_comment] = '<span class="comment">#';
1004
    $edges["Perl"][line_comment .",". normal_text] = '</span>';
1005

    
1006
    $edges["Ruby"] = $edges["Perl"];
1007

    
1008
    $edges["Python"] = $edges["Perl"];
1009

    
1010
    $edges["mIRC"][normal_text .",". dq_literal] = '<span class="literal">"';
1011
    $edges["mIRC"][normal_text .",". line_comment] = '<span class="comment">;';
1012
    $edges["mIRC"][dq_literal .",". normal_text] = '</span>';
1013
    $edges["mIRC"][line_comment .",". normal_text] = '</span>';
1014

    
1015
    $edges["VB"] = $edges["Perl"];
1016
    $edges["VB"][normal_text .",". line_comment] = '<span class="comment">\'';
1017

    
1018
    $edges["Java"] = $edges["C++"];
1019

    
1020
    $edges["C#"] = $edges["Java"];
1021

    
1022
    $edges["Pascal"] = $edges["C89"];
1023
    $edges["Pascal"][paren_begin .",". star_comment] = '<span class="comment">(*';
1024
    $edges["Pascal"][paren_begin .",". dq_literal]   = '<span class="literal">"';
1025
    $edges["Pascal"][paren_begin .",". sq_literal]   = '<span class="literal">\'';
1026
    $edges["Pascal"][slash_begin .",". dq_literal]   = '<span class="literal">"';
1027
    $edges["Pascal"][slash_begin .",". sq_literal]   = '<span class="literal">\'';
1028
    $edges["Pascal"][slash_begin .",". line_comment] = '<span class="comment">//';
1029
    $edges["Pascal"][normal_text . "," . block_comment] = '<span class="comment">{';
1030
    $edges["Pascal"][line_comment . "," . normal_text] = '</span>';
1031
    $edges["Pascal"][block_comment . "," . normal_text] = '</span>';
1032

    
1033
    $edges["XML"][normal_text . "," . html_entity] = '<span class="html_entity">&amp;';
1034
    $edges["XML"][html_entity . "," . normal_text] = '</span>';
1035
    $edges["XML"][html_entity . "," . xml_tag_begin] = '</span>';
1036
    $edges["XML"][xml_tag . "," . normal_text] = '&gt;</span>';
1037
    $edges["XML"][xml_tag_begin . "," . xml_pi] = '<span class="xml_pi">&lt;?';
1038
    $edges["XML"][xml_tag_begin . "," . line_comment] = '<span class="comment">&lt;!';
1039
    $edges["XML"][line_comment . "," . normal_text] = '&gt;</span>'; 
1040
    $edges["XML"][xml_tag .",". dq_literal]   = '<span class="literal">"';
1041
    $edges["XML"][dq_literal . "," . xml_tag] = '"</span>';
1042
    $edges["XML"][dq_literal . "," . dq_escape] = '<span class="html_entity">&amp;';
1043
    $edges["XML"][dq_escape . "," . dq_literal] = '</span>';
1044
    $edges["XML"][xml_tag .",". sq_literal]   = '<span class="literal">\'';
1045
    $edges["XML"][sq_literal . "," . xml_tag] = '\'</span>';
1046
    $edges["XML"][sq_literal . "," . sq_escape] = '<span class="html_entity">&amp;'; 
1047
    $edges["XML"][sq_escape . "," . sq_literal] = '</span>'; 
1048

    
1049
    //
1050
    // The State Machine
1051
    //
1052
    if (array_key_exists($language, $initial_state))
1053
        $state = $initial_state[$language];
1054
    else
1055
        $state = normal_text;
1056
    $output = "";
1057
    $span = "";
1058
    while (strlen($text) > 0)
1059
    {
1060
        $ch = substr($text, 0, 1);
1061
        $text = substr($text, 1);
1062

    
1063
        $oldstate = $state;
1064
        $state = (array_key_exists($ch, $states[$language][$state]))?
1065
            $states[$language][$state][$ch] :
1066
            $states[$language][$state][0];
1067

    
1068
        $span .= $ch;
1069

    
1070
        if ($oldstate != $state)
1071
        {
1072
            if (array_key_exists($language, $process) &&
1073
                array_key_exists($oldstate, $process[$language]))
1074
            {
1075
                if (array_key_exists($state, $process[$language][$oldstate]))
1076
                {
1077
                    $pf = $process[$language][$oldstate][$state];
1078
                    $output .= $pf($span, $language, $ch);
1079
                }
1080
                else
1081
                {
1082
                    $pf = $process[$language][$oldstate][0];
1083
                    $output .= $pf($span, $language, $ch);
1084
                }
1085
            }
1086
            else
1087
            {
1088
                $output .= $span;
1089
            }
1090

    
1091
            if (array_key_exists($language, $edges) &&
1092
                array_key_exists("$oldstate,$state", $edges[$language]))
1093
                $output .= $edges[$language]["$oldstate,$state"];
1094

    
1095
            $span = "";
1096
        }
1097
    }
1098

    
1099
    if (array_key_exists($language, $process_end) && $state == normal_text)
1100
        $output .= $process_end[$language]($span, $language);
1101
    else
1102
        $output .= $span;
1103

    
1104
    if ($state != normal_text)
1105
    {
1106
        if (array_key_exists($language, $edges) &&
1107
            array_key_exists("$state," . normal_text, $edges[$language]))
1108
            $output .= $edges[$language]["$state," . normal_text];
1109
    }
1110
                
1111
    return $output;
1112
}
1113

    
1114
?>
(3-3/4)