3 unsigned int baeza( char **text
, char **pattern
, int m
, int n
)
5 unsigned int i
, j
, row
, matches
= 0;
9 /* Iterate every m rows (first check lines 0 to m - 1) */
10 for ( row
= m
- 1; row
< n
; row
+= m
) {
12 /* Search the same row for occurences of the different lines of the pattern */
13 for ( i
= 0; i
< m
; i
++ ) {
15 /* In each row start searching from the begining */
20 /* Check text's row against each pattern's row */
21 x
= aho( text
, pattern
, m
, n
, row
, x
, i
, n
);
23 /* If a row is not found procceed to the next row */
26 /* If there is a match at i = 3, check vertically the text above for i = 0-2 and below for 4-m*/
28 /* Check lines above the current */
29 for ( j
= 0; j
< i
; j
++ ) {
30 y
= aho( text
, pattern
, m
, n
, row
- i
+ j
, x
, j
, x
+ m
);
36 /* Check lines below the current */
37 for ( j
= 1; j
< m
- i
; j
++ ) {
39 /* Avoid crashing when x = n or n-1 */
43 y
= aho( text
, pattern
, m
, n
, row
+ j
, x
, i
+ j
, x
+ m
);
49 /* If we reached here we should have a match */
52 /* If a mismatch is found, don't bother searching for the other y lines */
55 /* Now increase counter to continue search in the same row */