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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_wikidiff2.h"
#include "Wikidiff2.h"
#include "TableDiff.h"
#include "InlineDiff.h"
static int le_wikidiff2;
zend_function_entry wikidiff2_functions[] = {
PHP_FE(wikidiff2_do_diff, NULL)
PHP_FE(wikidiff2_inline_diff, NULL)
{NULL, NULL, NULL}
};
zend_module_entry wikidiff2_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"wikidiff2",
wikidiff2_functions,
PHP_MINIT(wikidiff2),
PHP_MSHUTDOWN(wikidiff2),
PHP_RINIT(wikidiff2),
PHP_RSHUTDOWN(wikidiff2),
PHP_MINFO(wikidiff2),
#if ZEND_MODULE_API_NO >= 20010901
"0.2",
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_WIKIDIFF2
ZEND_GET_MODULE(wikidiff2)
#endif
PHP_MINIT_FUNCTION(wikidiff2)
{
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(wikidiff2)
{
return SUCCESS;
}
PHP_RINIT_FUNCTION(wikidiff2)
{
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(wikidiff2)
{
return SUCCESS;
}
PHP_MINFO_FUNCTION(wikidiff2)
{
php_info_print_table_start();
php_info_print_table_header(2, "wikidiff2 support", "enabled");
php_info_print_table_end();
}
/* {{{ proto string wikidiff2_do_diff(string text1, string text2, int numContextLines)
*
* Warning: the input text must be valid UTF-8! Do not pass user input directly
* to this function.
*/
PHP_FUNCTION(wikidiff2_do_diff)
{
char *text1 = NULL;
char *text2 = NULL;
int argc = ZEND_NUM_ARGS();
int text1_len;
int text2_len;
long numContextLines;
if (zend_parse_parameters(argc TSRMLS_CC, "ssl", &text1, &text1_len, &text2,
&text2_len, &numContextLines) == FAILURE)
{
return;
}
try {
TableDiff wikidiff2;
Wikidiff2::String text1String(text1, text1_len);
Wikidiff2::String text2String(text2, text2_len);
const Wikidiff2::String & ret = wikidiff2.execute(text1String, text2String, numContextLines);
RETURN_STRINGL( const_cast<char*>(ret.data()), ret.size(), 1);
} catch (std::bad_alloc &e) {
zend_error(E_WARNING, "Out of memory in wikidiff2_do_diff().");
} catch (...) {
zend_error(E_WARNING, "Unknown exception in wikidiff2_do_diff().");
}
}
/* {{{ proto string wikidiff2_inline_diff(string text1, string text2, int numContextLines)
*
* Warning: the input text must be valid UTF-8! Do not pass user input directly
* to this function.
*/
PHP_FUNCTION(wikidiff2_inline_diff)
{
char *text1 = NULL;
char *text2 = NULL;
int argc = ZEND_NUM_ARGS();
int text1_len;
int text2_len;
long numContextLines;
if (zend_parse_parameters(argc TSRMLS_CC, "ssl", &text1, &text1_len, &text2,
&text2_len, &numContextLines) == FAILURE)
{
return;
}
try {
InlineDiff wikidiff2;
Wikidiff2::String text1String(text1, text1_len);
Wikidiff2::String text2String(text2, text2_len);
const Wikidiff2::String& ret = wikidiff2.execute(text1String, text2String, numContextLines);
RETURN_STRINGL( const_cast<char*>(ret.data()), ret.size(), 1);
} catch (std::bad_alloc &e) {
zend_error(E_WARNING, "Out of memory in wikidiff2_inline_diff().");
} catch (...) {
zend_error(E_WARNING, "Unknown exception in wikidiff2_inline_diff().");
}
}
/* }}} */
|