/* match.c - find a match from a string */ #include #include /* LT:n kokeita varten */ #include "own.h" extern int ignore_case; /* don't care about letter cases (up/low) */ extern int line_beginning; /* must match to the beginning of a line */ extern int line_end; /* must match to the end of a line */ /**/ /* Returns the length of the parameter string */ static int length(const char s[]) { int i; for (i=0;s[i];i++); return i; } /* Finds the first beginning index of string 'match' from string 'from'. Handles a special character '.' which can be any char (unless a macroname NO_SPECIAL_CHARACTERS is defined */ static int find_exact_match(const char from[], const char match[], int from_length, int match_length) { int i,j; for (i=0;i from_length) break; /* not found */ else #ifndef NO_SPECIAL_CHARACTERS if (match[j] != '.') #endif { /* SAME is defined in own.h */ if (!SAME(from[i+j],match[j],ignore_case)) break; } } if (j == match_length) return i; /* found */ } return -1; } /* Function match. Returns true if match-string is found somewhere from the from string. It also considers the ignore case and beginning of a line flags */ int match(const char from[], const char match[]) { int index; int from_length, match_length; from_length = length(from); match_length = length(match); index = find_exact_match(from,match,from_length,match_length); if (index < 0) return FALSE; /* not found */ if (index > 0 && line_beginning) return FALSE; /* not in the beginning of the line */ if (from_length - index > match_length && line_end) /**/ return FALSE; /* not in the end of the line */ /**/ return TRUE; }