Index: trunk/extensions/NativePreprocessor/preprocesstoobj.c |
— | — | @@ -12,18 +12,22 @@ |
13 | 13 | |
14 | 14 | #define PTD_FOR_INCLUSION 1 /* Matches Parser::PTD_FOR_INCLUSION */ |
15 | 15 | |
16 | | -// FIXME: Do not rely on the terminating \0 |
17 | | -#define STRSTR(haystack, needle) strpos(haystack, needle, 0) |
18 | | -int strpos(const char* haystack, const char* needle, int offset) { |
19 | | - char* s = strstr(haystack+offset, needle); |
20 | | - if (!s) return -1; |
21 | | - return s - haystack; |
| 16 | +static int strpos(const char* haystack, int haystack_len, const char* needle, int needle_len, int offset) { |
| 17 | + int i; |
| 18 | + |
| 19 | + for ( i = offset; i < haystack_len - needle_len; i++ ) { |
| 20 | + if ( !memcmp( haystack + i, needle, needle_len ) ) { |
| 21 | + return i; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + return -1; |
22 | 26 | } |
23 | 27 | |
24 | 28 | #define strsize(x) (sizeof(x)-1) |
25 | 29 | #define min(x,y) (((x) < (y)) ? (x) : (y)) |
26 | 30 | |
27 | | -enum internalTags getInternalTag(const char* name, int name_len) { |
| 31 | +static enum internalTags getInternalTag(const char* name, int name_len) { |
28 | 32 | #define CHECK_INTERNAL_TAG(x) if ((sizeof(#x)-1 == name_len) && !strncasecmp(name, #x, sizeof(#x)-1)) return x; |
29 | 33 | if (name[0] == '/') { |
30 | 34 | name++; |
— | — | @@ -52,7 +56,7 @@ |
53 | 57 | #define searchReset() strcpy(search, "[{<\n") // $search = $searchBase; |
54 | 58 | #define addSearch(x) addToSearch(search, sizeof(search), x) // $search .= 'x'; |
55 | 59 | #define MAX_SEARCH_CHARS "[{<\n|=}]" |
56 | | -void addToSearch(char* search, int search_len, char x) { |
| 60 | +static void addToSearch(char* search, int search_len, char x) { |
57 | 61 | int e; |
58 | 62 | assert(strchr(MAX_SEARCH_CHARS, x)); |
59 | 63 | e = strlen(search); |
— | — | @@ -70,7 +74,7 @@ |
71 | 75 | /** |
72 | 76 | * Counts the number of times the character c appears since start, up to length. |
73 | 77 | */ |
74 | | -int chrspn( const char* text, int c, int start, int length ) { |
| 78 | +static int chrspn( const char* text, int c, int start, int length ) { |
75 | 79 | int i; |
76 | 80 | for (i=0; i < length; i++) { |
77 | 81 | if ( text[start+i] != c ) { |
— | — | @@ -81,27 +85,6 @@ |
82 | 86 | } |
83 | 87 | |
84 | 88 | /** |
85 | | - * Return the first index in text that either matches a PCRE \s or a '<' |
86 | | - * Returns -1 if not found. Remember that for PERL compatibility, \s doesn't |
87 | | - * include the Vertical Tab (0x11) |
88 | | - */ |
89 | | -int findSpaceOrAngle(const char* text, int text_len) { |
90 | | - int i; |
91 | | - for (i = 0; i < text_len; i++) { |
92 | | - switch ( text[i] ) { |
93 | | - case '\t': |
94 | | - case '\n': |
95 | | - case '\f': |
96 | | - case '\r': |
97 | | - case ' ': |
98 | | - case '>': |
99 | | - return i; |
100 | | - } |
101 | | - } |
102 | | - return -1; |
103 | | -} |
104 | | - |
105 | | -/** |
106 | 89 | * Locates an end tag for the given tag name. |
107 | 90 | * Matches the regex "/<\/$name\s*>/i" |
108 | 91 | * Doesn't (completely) support tag names which contain '<' |
— | — | @@ -140,7 +123,7 @@ |
141 | 124 | /** |
142 | 125 | * Returns the number of times the character c appears in text, searching backwards from position start |
143 | 126 | */ |
144 | | -int chrrspn( const char* text, int c, int start ) { |
| 127 | +static int chrrspn( const char* text, int c, int start ) { |
145 | 128 | int i = 0; |
146 | 129 | while ( ( start-i >= 0 ) && text[start-i] == c ) { |
147 | 130 | i++; |
— | — | @@ -181,7 +164,7 @@ |
182 | 165 | if ( forInclusion ) { |
183 | 166 | /* $ignoredTags = array( 'includeonly', '/includeonly' ); */ |
184 | 167 | ignoredElement = noinclude; |
185 | | - if ( STRSTR( text, "<onlyinclude>" ) && STRSTR( text, "</onlyinclude>" ) ) { |
| 168 | + if ( strpos( text, text_len, "<onlyinclude>", 13, 0 ) != -1 && strpos( text, text_len, "</onlyinclude>", 14, 0 ) != -1 ) { |
186 | 169 | enableOnlyinclude = true; |
187 | 170 | } |
188 | 171 | } else { |
— | — | @@ -213,7 +196,7 @@ |
214 | 197 | |
215 | 198 | if ( findOnlyinclude ) { |
216 | 199 | // Ignore all input up to the next <onlyinclude> |
217 | | - int startPos = strpos( text, "<onlyinclude>", i ); |
| 200 | + int startPos = strpos( text, text_len, "<onlyinclude>", 13, i ); |
218 | 201 | if ( startPos == -1 ) { |
219 | 202 | // Ignored section runs to the end |
220 | 203 | addNodeWithText(ignore_node, text, i, -1); |
— | — | @@ -323,7 +306,7 @@ |
324 | 307 | // trailing spaces and one of the newlines. |
325 | 308 | |
326 | 309 | // Find the end |
327 | | - int endPos = strpos( text, "-->", i + 4 ); |
| 310 | + int endPos = strpos( text, text_len, "-->", 3, i + 4 ); |
328 | 311 | if ( endPos == -1 ) { |
329 | 312 | // Unclosed comment in input, runs to end |
330 | 313 | addNodeWithText(comment_node, text, i, -1); |