My favorites | Sign in
Project Logo
                
Changes to /trunk/sourcehighlight.cc
r0 vs. r2   Edit
  Compare: vs.   Format:
Revision r2
Go to: 
Project members, sign in to write a code review
/trunk/sourcehighlight.cc /trunk/sourcehighlight.cc   r2
  1 #ifdef HAVE_CONFIG_H
  2 #include "config.h"
  3 #endif
  4
  5 #include <php.h>
  6 #include "php_sourcehighlight.h"
  7
  8 #include <srchilite/sourcehighlight.h>
  9 #include <iostream>
  10 #include <sstream>
  11
  12 extern "C" {
  13 static function_entry sourcehighlight_functions[] = {
  14 PHP_FE(sourcehighlight, NULL)
  15 {NULL, NULL, NULL}
  16 };
  17
  18 zend_module_entry sourcehighlight_module_entry = {
  19 #if ZEND_MODULE_API_NO >= 20010901
  20 STANDARD_MODULE_HEADER,
  21 #endif
  22 PHP_SOURCEHIGHLIGHT_EXTNAME,
  23 sourcehighlight_functions,
  24 NULL,
  25 NULL,
  26 NULL,
  27 NULL,
  28 NULL,
  29 #if ZEND_MODULE_API_NO >= 20010901
  30 PHP_SOURCEHIGHLIGHT_VERSION,
  31 #endif
  32 STANDARD_MODULE_PROPERTIES
  33 };
  34
  35 #ifdef COMPILE_DL_SOURCEHIGHLIGHT
  36 ZEND_GET_MODULE(sourcehighlight)
  37 #endif
  38 }
  39
  40 PHP_FUNCTION(sourcehighlight)
  41 {
  42 char* text;
  43 int text_len;
  44 char* lang;
  45 int lang_len;
  46 char* outlang = "xhtml";
  47 int outlang_len = strlen(outlang);
  48
  49 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  50 "ss|s",
  51 &text, &text_len,
  52 &lang, &lang_len,
  53 &outlang, &outlang_len
  54 ) == FAILURE) {
  55 RETURN_STRING("parameter error", 1);
  56 }
  57
  58 const std::string outputLang = std::string(outlang, outlang_len) + ".outlang";
  59 srchilite::SourceHighlight sourceHighlight(outputLang);
  60
  61 const std::string inputLang = std::string(lang, lang_len) + ".lang";
  62 std::istringstream i(text);
  63 std::ostringstream o("");
  64
  65 sourceHighlight.highlight(i, o, inputLang);
  66
  67 const std::string result = o.str();
  68 char* cstr = (char*) emalloc(result.size()+1);
  69 strcpy((char*) cstr, result.c_str());
  70
  71 RETURN_STRING(cstr, 0);
  72 }
  73
Hosted by Google Code