This repository was archived by the owner on Aug 18, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathphp_wikidiff2.cpp
More file actions
182 lines (156 loc) · 4.35 KB
/
Copy pathphp_wikidiff2.cpp
File metadata and controls
182 lines (156 loc) · 4.35 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* $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"
#if PHP_MAJOR_VERSION >= 7
#define COMPAT_RETURN_STRINGL(s, l) { RETURN_STRINGL(s, l); return; }
#else
#define COMPAT_RETURN_STRINGL(s, l) { RETURN_STRINGL(s, l, 1); return; }
#endif
static int le_wikidiff2;
zend_function_entry wikidiff2_functions[] = {
PHP_FE(wikidiff2_do_diff, NULL)
PHP_FE(wikidiff2_inline_diff, NULL)
PHP_FE(wikidiff2_version, 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
WIKIDIFF2_VERSION_STRING,
#endif
STANDARD_MODULE_PROPERTIES
};
/* {{{ INI Settings */
PHP_INI_BEGIN()
PHP_INI_ENTRY("wikidiff2.change_threshold", WIKIDIFF2_CHANGE_THRESHOLD_DEFAULT, PHP_INI_ALL, NULL)
PHP_INI_ENTRY("wikidiff2.moved_line_threshold", WIKIDIFF2_MOVED_LINE_THRESHOLD_DEFAULT, PHP_INI_ALL, NULL)
PHP_INI_END()
/* }}} */
#ifdef COMPILE_DL_WIKIDIFF2
ZEND_GET_MODULE(wikidiff2)
#endif
PHP_MINIT_FUNCTION(wikidiff2)
{
REGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(wikidiff2)
{
UNREGISTER_INI_ENTRIES();
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_row(2, "wikidiff2 version", WIKIDIFF2_VERSION_STRING);
php_info_print_table_end();
}
/* {{{ proto string wikidiff2_do_diff(string text1, string text2, int numContextLines, int maxMovedLines = 25)
*
* 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();
#if PHP_MAJOR_VERSION >= 7
size_t text1_len;
size_t text2_len;
zend_long numContextLines;
zend_long maxMovedLines = 25;
#else
int text1_len;
int text2_len;
long numContextLines;
long maxMovedLines = 25;
#endif
if (zend_parse_parameters(argc TSRMLS_CC, "ssl|l", &text1, &text1_len, &text2,
&text2_len, &numContextLines, &maxMovedLines) == 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, (int)numContextLines, (int)maxMovedLines);
COMPAT_RETURN_STRINGL( const_cast<char*>(ret.data()), ret.size());
} 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, int maxMovedLines = 25)
*
* 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();
#if PHP_MAJOR_VERSION >= 7
size_t text1_len;
size_t text2_len;
zend_long numContextLines;
zend_long maxMovedLines = 25;
#else
int text1_len;
int text2_len;
long numContextLines;
long maxMovedLines = 25;
#endif
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, (int)numContextLines, 0 /*inlinediff todo*/);
COMPAT_RETURN_STRINGL( const_cast<char*>(ret.data()), ret.size());
} 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().");
}
}
/* {{{ proto string wikidiff2_version()
*/
PHP_FUNCTION(wikidiff2_version)
{
COMPAT_RETURN_STRINGL( const_cast<char*>(WIKIDIFF2_VERSION_STRING), strlen(WIKIDIFF2_VERSION_STRING));
}
/* }}} */