My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <php.h>
#include "php_sourcehighlight.h"

#include <srchilite/sourcehighlight.h>
#include <iostream>
#include <sstream>

extern "C" {
static function_entry sourcehighlight_functions[] = {
PHP_FE(sourcehighlight, NULL)
{NULL, NULL, NULL}
};

zend_module_entry sourcehighlight_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_SOURCEHIGHLIGHT_EXTNAME,
sourcehighlight_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
#if ZEND_MODULE_API_NO >= 20010901
PHP_SOURCEHIGHLIGHT_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_SOURCEHIGHLIGHT
ZEND_GET_MODULE(sourcehighlight)
#endif
}

PHP_FUNCTION(sourcehighlight)
{
char* text;
int text_len;
char* lang;
int lang_len;
char* outlang = "xhtml";
int outlang_len = strlen(outlang);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"ss|s",
&text, &text_len,
&lang, &lang_len,
&outlang, &outlang_len
) == FAILURE) {
RETURN_STRING("parameter error", 1);
}

const std::string outputLang = std::string(outlang, outlang_len) + ".outlang";
srchilite::SourceHighlight sourceHighlight(outputLang);

const std::string inputLang = std::string(lang, lang_len) + ".lang";
std::istringstream i(text);
std::ostringstream o("");

sourceHighlight.highlight(i, o, inputLang);

const std::string result = o.str();
char* cstr = (char*) emalloc(result.size()+1);
strcpy((char*) cstr, result.c_str());

RETURN_STRING(cstr, 0);
}

Show details Hide details

Change log

r2 by pascal.bleser on May 20, 2009   Diff
import first release
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1664 bytes, 73 lines
Hosted by Google Code